From 23f6f34748d9197f6706128a09fb0287186013ab Mon Sep 17 00:00:00 2001 From: mkwiser Date: Fri, 17 Oct 2014 00:17:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20cover=20layer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/editor/group/ShapesGroup.js | 23 ++++++++++++++--------- src/editor/mode/shapes.js | 6 ++++++ src/render/Layer.js | 8 ++++---- src/render/Painter.js | 8 ++++---- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/editor/group/ShapesGroup.js b/src/editor/group/ShapesGroup.js index 8c55276..4002b4e 100644 --- a/src/editor/group/ShapesGroup.js +++ b/src/editor/group/ShapesGroup.js @@ -96,14 +96,21 @@ define( * 设置操作的shapes */ ShapesGroup.prototype.setShapes = function(shapes) { - if(this.shapes) { - this.shapes.length = 0; - this.shapes = null; - } - this.shapes = shapes; var coverLayer = this.editor.coverLayer; - coverLayer.clearShapes(); + + if(this.shapes) { + this.shapes = null; + } + + if (this.coverShapes) { + this.coverShapes.forEach(function(shape) { + coverLayer.removeShape(shape); + }); + this.coverShapes = null; + } + + this.shapes = shapes; this.coverShapes = lang.clone(this.shapes); this.coverShapes.forEach(function(shape) { @@ -163,9 +170,7 @@ define( this.editor.coverLayer.clearShapes(); this.editor.coverLayer.refresh(); - this.shapes.length = 0; - this.controls.length = 0; - this.shapes = this.controls = this.editor = null; + this.shapes = this.coverShapes = this.controls = this.editor = null; }; return ShapesGroup; diff --git a/src/editor/mode/shapes.js b/src/editor/mode/shapes.js index 462fb8a..766d2ef 100644 --- a/src/editor/mode/shapes.js +++ b/src/editor/mode/shapes.js @@ -74,17 +74,23 @@ define( } else if (command == 'rotate_left') { this.execCommand('rotateleft', shapes); + this.currentGroup.setShapes(shapes); this.currentGroup.refresh(); } else if (command == 'rotate_right') { this.execCommand('rotateright', shapes); + this.currentGroup.setShapes(shapes); this.currentGroup.refresh(); } else if (command == 'reverse_shapes') { this.execCommand('reverseshapes', shapes); + this.currentGroup.setShapes(shapes); + this.currentGroup.refresh(); } else if (command == 'mirror_shapes') { this.execCommand('mirrorshapes', shapes); + this.currentGroup.setShapes(shapes); + this.currentGroup.refresh(); } else if (command == 'add_referenceline') { var bound = this.currentGroup.getBound(); diff --git a/src/render/Layer.js b/src/render/Layer.js index 6a85d53..a5e4c6e 100644 --- a/src/render/Layer.js +++ b/src/render/Layer.js @@ -206,12 +206,12 @@ define( id = this.shapes.indexOf(shape); } else if(typeof shape === 'string') { - this.shapes.forEach(function(item, i) { - if(item.id === shape) { + for (var i = 0, l = this.shapes.length; i < l; i++) { + if (shape == this.shapes[i].id) { id = i; - return false; + break; } - }); + } } else if(typeof shape === 'number') { id = shape; diff --git a/src/render/Painter.js b/src/render/Painter.js index 2ec98c0..5b332b1 100644 --- a/src/render/Painter.js +++ b/src/render/Painter.js @@ -168,12 +168,12 @@ define( id = this.layers.indexOf(layer); } else if(typeof layer === 'string') { - this.layers.forEach(function(item, i) { - if(item.id === layer) { + for (var i = 0, l = this.layers.length; i < l; i++) { + if (layer == this.layers[i].id) { id = i; - return false; + break; } - }); + } } else if(typeof id === 'number') { id = id;