From 8b2da344832af6ab975e875ce546e810ae657218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 16 May 2011 16:57:52 +0100 Subject: [PATCH 01/39] Remove reference to inexisting Request.js file. --- src/paper.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/paper.js b/src/paper.js index 4b2d7cb5..df9bbbec 100644 --- a/src/paper.js +++ b/src/paper.js @@ -92,7 +92,6 @@ var paper = new function() { //#include "browser/DomElement.js" //#include "browser/DomEvent.js" -//#include "browser/Request.js" //#include "ui/Event.js" //#include "ui/KeyEvent.js" From da670b4171132f9ab0107f1946bbfdea2aa6e8ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 16 May 2011 18:29:53 +0100 Subject: [PATCH 02/39] Improve comments. --- src/item/PathStyle.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/item/PathStyle.js b/src/item/PathStyle.js index 1b789ba1..f0d9d027 100644 --- a/src/item/PathStyle.js +++ b/src/item/PathStyle.js @@ -30,6 +30,8 @@ var PathStyle = this.PathStyle = Base.extend(new function() { initialize: function(style) { if (style) { + // Note: This relies on bean setters that get implicetly + // called when setting values on this[key]. for (var i = 0, l = keys.length; i < l; i++) { var key = keys[i], value = style[key]; @@ -46,6 +48,9 @@ var PathStyle = this.PathStyle = Base.extend(new function() { statics: { create: function(item, other) { var style = new PathStyle(PathStyle.dont); + // We need _item to be set before calling initialize(), since + // it is setting bean properties that propagate changes through + // all of item's children. style._item = item; style.initialize(other); return style; @@ -101,8 +106,8 @@ var PathStyle = this.PathStyle = Base.extend(new function() { } }; - // 'this' = the Base.each() side-car = the object that is injected into - // Item above: + // 'this' = the Base.each() side-car = the object that is returned from + // Base.each and injected into Item above: this[set] = function(value) { this._style[set](value); return this; From c8c47bf641ab8fba8d26ad23974c2e1b95768930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 16 May 2011 18:57:47 +0100 Subject: [PATCH 03/39] get styles directly from _style object rather than passing through getters on Item. --- src/path/Path.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/path/Path.js b/src/path/Path.js index 4bb1e4ac..bed45460 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -746,7 +746,7 @@ var Path = this.Path = PathItem.extend({ _setStyles: function(ctx) { for (var i in styles) { - var style = this[i](); + var style = this._style[i](); if (style) ctx[styles[i]] = style; } From 34110fa82da09381512b636ceffa9ac857fc7612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 16 May 2011 19:19:18 +0100 Subject: [PATCH 04/39] Move #_setStyle() closer to the related styles hash. --- src/path/Path.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/path/Path.js b/src/path/Path.js index bed45460..551e527a 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -643,8 +643,14 @@ var Path = this.Path = PathItem.extend({ }; return { - beans: true, - + _setStyles: function(ctx) { + for (var i in styles) { + var style = this._style[i](); + if (style) + ctx[styles[i]] = style; + } + }, + smooth: function() { // This code is based on the work by Oleg V. Polikarpotchkin, // http://ov-p.spaces.live.com/blog/cns!39D56F0C7A08D703!147.entry @@ -742,14 +748,6 @@ var Path = this.Path = PathItem.extend({ var segment = this._segments[0]; segment.setHandleIn(handleIn.subtract(segment._point)); } - }, - - _setStyles: function(ctx) { - for (var i in styles) { - var style = this._style[i](); - if (style) - ctx[styles[i]] = style; - } } }; }, new function() { // PostScript-style drawing commands From 05c0eb0e5196d434b46215c682c10e63b7322d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 16 May 2011 19:20:32 +0100 Subject: [PATCH 05/39] Simplify PathStyle#initialize(). --- src/item/PathStyle.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/item/PathStyle.js b/src/item/PathStyle.js index f0d9d027..5e0d0977 100644 --- a/src/item/PathStyle.js +++ b/src/item/PathStyle.js @@ -29,15 +29,13 @@ var PathStyle = this.PathStyle = Base.extend(new function() { beans: true, initialize: function(style) { - if (style) { - // Note: This relies on bean setters that get implicetly - // called when setting values on this[key]. - for (var i = 0, l = keys.length; i < l; i++) { - var key = keys[i], - value = style[key]; - if (value !== undefined) - this[key] = value; - } + // Note: This relies on bean setters that get implicetly + // called when setting values on this[key]. + for (var i = 0, l = style && keys.length; i < l; i++) { + var key = keys[i], + value = style[key]; + if (value !== undefined) + this[key] = value; } }, From c4203fe1748bc7e08a5d36830aec4738ee442912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 16 May 2011 19:21:36 +0100 Subject: [PATCH 06/39] Change the way associated PathStyles are created and updated. --- src/item/Item.js | 3 ++- src/item/PathStyle.js | 6 +----- src/project/Project.js | 4 ++-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index 7b28fcfd..6dc33785 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -19,6 +19,7 @@ var Item = this.Item = Base.extend({ initialize: function() { paper.project.activeLayer.appendTop(this); + this._style = PathStyle.create(this); this.setStyle(this._project.getCurrentStyle()); }, @@ -629,7 +630,7 @@ var Item = this.Item = Base.extend({ }, setStyle: function(style) { - this._style = PathStyle.create(this, style); + this._style.initialize(style); }, // TODO: toString diff --git a/src/item/PathStyle.js b/src/item/PathStyle.js index 5e0d0977..6f80d6d7 100644 --- a/src/item/PathStyle.js +++ b/src/item/PathStyle.js @@ -44,13 +44,9 @@ var PathStyle = this.PathStyle = Base.extend(new function() { }, statics: { - create: function(item, other) { + create: function(item) { var style = new PathStyle(PathStyle.dont); - // We need _item to be set before calling initialize(), since - // it is setting bean properties that propagate changes through - // all of item's children. style._item = item; - style.initialize(other); return style; } } diff --git a/src/project/Project.js b/src/project/Project.js index 38b90ec3..932d5554 100644 --- a/src/project/Project.js +++ b/src/project/Project.js @@ -33,7 +33,7 @@ var Project = this.Project = Base.extend({ this.activeView = canvas ? new ProjectView(canvas) : null; this._selectedItems = {}; this._selectedItemCount = 0; - this.setCurrentStyle(null); + this._currentStyle = PathStyle.create(null); }, getCurrentStyle: function() { @@ -41,7 +41,7 @@ var Project = this.Project = Base.extend({ }, setCurrentStyle: function(style) { - this._currentStyle = PathStyle.create(null, style); + this._currentStyle.initialize(style); }, activate: function() { From 00b5f6a6bbc72ba06fc522ff5b684cecb04aff39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 16 May 2011 19:21:44 +0100 Subject: [PATCH 07/39] Improve Group tests. --- test/tests/Group.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/tests/Group.js b/test/tests/Group.js index 0ed50c6a..163ceab8 100644 --- a/test/tests/Group.js +++ b/test/tests/Group.js @@ -23,16 +23,17 @@ test('Group bounds', function() { strokeWidth: 5, strokeColor: 'black' }; + var path = new Path.Circle([150, 150], 60); var secondPath = new Path.Circle([175, 175], 85); var group = new Group([path, secondPath]); - compareRectangles(group.bounds, { x: 90, y: 90, width: 170, height: 170 }); - compareRectangles(group.strokeBounds, { x: 87.5, y: 87.5, width: 175, height: 175 }); + compareRectangles(group.bounds, { x: 90, y: 90, width: 170, height: 170 }, 'group.bounds'); + compareRectangles(group.strokeBounds, { x: 87.5, y: 87.5, width: 175, height: 175 }, 'group.strokeBounds'); group.rotate(20); - compareRectangles(group.bounds, { x: 89.97681, y: 82.94095, width: 170.04639, height: 177.08224 }); - compareRectangles(group.strokeBounds, { x: 87.47681, y: 80.44095, width: 175.04639, height: 182.08224 }); + compareRectangles(group.bounds, { x: 89.97681, y: 82.94095, width: 170.04639, height: 177.08224 }, 'group.bounds'); + compareRectangles(group.strokeBounds, { x: 87.47681, y: 80.44095, width: 175.04639, height: 182.08224 }, 'group.strokeBounds'); group.rotate(20, new Point(50, 50)); - compareRectangles(group.bounds, { x: 39.70692, y: 114.99196, width: 170.00412, height: 180.22401 }); - compareRectangles(group.strokeBounds, { x: 37.20692, y: 112.49196, width: 175.00412, height: 185.22401 }); + compareRectangles(group.bounds, { x: 39.70692, y: 114.99196, width: 170.00412, height: 180.22401 }, 'group.bounds'); + compareRectangles(group.strokeBounds, { x: 37.20692, y: 112.49196, width: 175.00412, height: 185.22401 }, 'group.strokeBounds'); }); \ No newline at end of file From 75b0fa3596d7c427118805f92b5dbd0a15335a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 16 May 2011 19:34:57 +0100 Subject: [PATCH 08/39] Add Item#removeChildren() and #setChildren(). --- src/item/Item.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/item/Item.js b/src/item/Item.js index 6dc33785..213b5b36 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -239,7 +239,12 @@ var Item = this.Item = Base.extend({ return this._children; }, - // TODO: #setChildren() + setChildren: function(children) { + this.removeChildren(); + for (var i = 0, l = children && children.length; i < l; i++) + this.appendBottom(children[i]); + }, + /** * Reverses the order of this item's children @@ -253,6 +258,18 @@ var Item = this.Item = Base.extend({ } }, + /** + * Removes all of the item's children, if it has any + */ + removeChildren: function() { + var removed = false; + if (this._children) { + for (var i = this._children.length; i >= 0 i--) + removed = this._children[i].remove() || removed; + } + return removed; + }, + /** * The first item contained within this item. */ From d535a1f6fc676370c98590cabc6c06d66362cca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 16 May 2011 19:35:09 +0100 Subject: [PATCH 09/39] Clean up method sequence in Item. --- src/item/Item.js | 99 ++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index 213b5b36..a0edce91 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -44,24 +44,6 @@ var Item = this.Item = Base.extend({ } return this._id; }, - - _removeFromNamed: function() { - var children = this._parent._children, - namedChildren = this._parent._namedChildren, - name = this._name, - namedArray = namedChildren[name]; - if (children[name] = this) - delete children[name]; - namedArray.splice(namedArray.indexOf(this), 1); - // If there are any items left in the named array, set - // the last of them to be this.parent.children[this.name] - if (namedArray.length) { - children[name] = namedArray[namedArray.length - 1]; - } else { - // Otherwise delete the empty array - delete namedChildren[name]; - } - }, /** * The name of the item. @@ -87,6 +69,47 @@ var Item = this.Item = Base.extend({ delete children[name]; } }, + + _removeFromNamed: function() { + var children = this._parent._children, + namedChildren = this._parent._namedChildren, + name = this._name, + namedArray = namedChildren[name]; + if (children[name] = this) + delete children[name]; + namedArray.splice(namedArray.indexOf(this), 1); + // If there are any items left in the named array, set + // the last of them to be this.parent.children[this.name] + if (namedArray.length) { + children[name] = namedArray[namedArray.length - 1]; + } else { + // Otherwise delete the empty array + delete namedChildren[name]; + } + }, + + /** + * Removes the item from its parent's children list. + */ + _removeFromParent: function() { + if (this._parent) { + if (this._name) + this._removeFromNamed(); + var res = Base.splice(this._parent._children, null, this._index, 1); + this._parent = null; + return !!res.length; + } + return false; + }, + + /** + * Removes the item. + */ + remove: function() { + if (this.isSelected()) + this.setSelected(false); + return this._removeFromParent(); + }, /** * When passed a project, copies the item to the project, @@ -245,6 +268,14 @@ var Item = this.Item = Base.extend({ this.appendBottom(children[i]); }, + /** + * Checks if the item contains any children items. + * + * @return true if it has one or more children, false otherwise. + */ + hasChildren: function() { + return this._children && this._children.length > 0; + }, /** * Reverses the order of this item's children @@ -299,38 +330,6 @@ var Item = this.Item = Base.extend({ return this._parent && this._parent._children[this._index - 1] || null; }, - /** - * Removes the item from its parent's children list. - */ - _removeFromParent: function() { - if (this._parent) { - if (this._name) - this._removeFromNamed(); - var res = Base.splice(this._parent._children, null, this._index, 1); - this._parent = null; - return !!res.length; - } - return false; - }, - - /** - * Removes the item. - */ - remove: function() { - if (this.isSelected()) - this.setSelected(false); - return this._removeFromParent(); - }, - - /** - * Checks if the item contains any children items. - * - * @return true if it has one or more children, false otherwise. - */ - hasChildren: function() { - return this._children && this._children.length > 0; - }, - /** * Checks whether the item is editable. * From 97c4435d87f6116eb5577793996f950bc44cc56f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 16 May 2011 19:35:42 +0100 Subject: [PATCH 10/39] Fix typo. --- src/item/Item.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/item/Item.js b/src/item/Item.js index a0edce91..e1ef8a0b 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -295,7 +295,7 @@ var Item = this.Item = Base.extend({ removeChildren: function() { var removed = false; if (this._children) { - for (var i = this._children.length; i >= 0 i--) + for (var i = this._children.length; i >= 0; i--) removed = this._children[i].remove() || removed; } return removed; From f12ed7234a24aab03d6ff053b35559216ee3487f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 16 May 2011 19:44:46 +0100 Subject: [PATCH 11/39] Shorten code. --- src/item/Item.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index e1ef8a0b..a0264155 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -39,9 +39,8 @@ var Item = this.Item = Base.extend({ * The unique id of the item. */ getId: function() { - if (this._id == null) { + if (this._id == null) this._id = Item._id = (Item._id || 0) + 1; - } return this._id; }, From 8a449b0e76a223bbc016546302cc60c746dca0eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 16 May 2011 20:14:49 +0100 Subject: [PATCH 12/39] Remove deprecated Item#appendChild(). --- src/item/Item.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index a0264155..de468530 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -797,15 +797,6 @@ var Item = this.Item = Base.extend({ */ appendBottom: append(false), - /** - * A link to {@link #appendTop} - * - * @deprecated use {@link #appendTop} or {@link #appendBottom} instead. - */ - appendChild: function(item) { - return this.appendTop(item); - }, - /** * Moves this item above the specified item. * From baf35ea18ce7aca9a836ae6cc9bb411e0a461859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 16 May 2011 20:15:16 +0100 Subject: [PATCH 13/39] Rename parameter. --- src/item/Item.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/item/Item.js b/src/item/Item.js index de468530..2778fa71 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -261,10 +261,10 @@ var Item = this.Item = Base.extend({ return this._children; }, - setChildren: function(children) { + setChildren: function(items) { this.removeChildren(); - for (var i = 0, l = children && children.length; i < l; i++) - this.appendBottom(children[i]); + for (var i = 0, l = items && items.length; i < l; i++) + this.appendTop(items[i]); }, /** From 889b1687f99be5b1cb0f304a7259a5c33dfe9090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 16 May 2011 20:16:27 +0100 Subject: [PATCH 14/39] Use #setChildren() in Group constructor and allow passing of children both as arguments and inside an array. --- src/item/Group.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/item/Group.js b/src/item/Group.js index 60bb6389..dcf37d3e 100644 --- a/src/item/Group.js +++ b/src/item/Group.js @@ -21,12 +21,9 @@ var Group = this.Group = Item.extend({ this.base(); this._children = []; this._namedChildren = {}; - if (items) { - for (var i = 0, l = items.length; i < l; i++) { - this.appendTop(items[i]); - } - } this._clipped = false; + this.setChildren(!items || !Array.isArray(items) + || typeof items[0] !== 'object' ? arguments : items); }, /** From 4d0858c6bfe13f8e1d91c2c33e1d5683065eb078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 16 May 2011 20:16:51 +0100 Subject: [PATCH 15/39] Add more CompounPath tests. --- test/tests/CompoundPath.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/tests/CompoundPath.js b/test/tests/CompoundPath.js index 2f6dbf21..3dbb3afa 100644 --- a/test/tests/CompoundPath.js +++ b/test/tests/CompoundPath.js @@ -37,10 +37,14 @@ test('clockwise', function() { return path3.clockwise; }, true); - new CompoundPath([ - path1, path2, path3 - ]); + var compound = new CompoundPath(path1, path2, path3); + equals(function() { + return compound.lastChild == path3; + }, true); + equals(function() { + return compound.firstChild == path1; + }, true); equals(function() { return path1.clockwise; }, true); From eafc0d202e6a83a7c694b97d021b3229d5949169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 16 May 2011 20:17:14 +0100 Subject: [PATCH 16/39] Add comment about #clockwise magic happening in #append*() methods. --- src/path/CompoundPath.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/path/CompoundPath.js b/src/path/CompoundPath.js index 8d6103d2..53f274d5 100644 --- a/src/path/CompoundPath.js +++ b/src/path/CompoundPath.js @@ -28,6 +28,7 @@ var CompoundPath = this.CompoundPath = PathItem.extend({ // clockwise orientation when creating a compound path, so that they // appear as holes, but only if their orientation was not already // specified before (= _clockwise is defined). + // TODO: This should really be handled in appendTop / Bottom, right? if (path._clockwise === undefined) path.setClockwise(i < l - 1); this.appendTop(path); From 1c12c82df1bed7961e2f55a21a6f9bd500ee29db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 17 May 2011 13:08:36 +0100 Subject: [PATCH 17/39] Rename unit test file Document.js to Project.js. --- test/tests/{Document.js => Project.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/tests/{Document.js => Project.js} (100%) diff --git a/test/tests/Document.js b/test/tests/Project.js similarity index 100% rename from test/tests/Document.js rename to test/tests/Project.js From 515dbbb151f163b03c4d8d37eac947efc7106223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 17 May 2011 13:09:10 +0100 Subject: [PATCH 18/39] Fix error in Item#removeChildren(). --- src/item/Item.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/item/Item.js b/src/item/Item.js index 2778fa71..31311b14 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -294,7 +294,7 @@ var Item = this.Item = Base.extend({ removeChildren: function() { var removed = false; if (this._children) { - for (var i = this._children.length; i >= 0; i--) + for (var i = this._children.length - 1; i >= 0; i--) removed = this._children[i].remove() || removed; } return removed; From 4be0e55dc51c9cec0650af8c45bd41aeb7a485b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 17 May 2011 13:09:35 +0100 Subject: [PATCH 19/39] Use #appendTop() instead of the remove #appendChild() in tests. --- test/tests/Item.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/tests/Item.js b/test/tests/Item.js index ecc646ab..46d54057 100644 --- a/test/tests/Item.js +++ b/test/tests/Item.js @@ -42,10 +42,10 @@ test('clone()', function() { }, true); }); -test('appendChild(item)', function() { +test('appendTop(item)', function() { var proj = paper.project; var path = new Path(); - proj.activeLayer.appendChild(path); + proj.activeLayer.appendTop(path); equals(function() { return proj.activeLayer.children.length; }, 1); @@ -55,7 +55,7 @@ test('item.parent / item.isChild / item.isParent', function() { var proj = paper.project; var secondDoc = new Project(); var path = new Path(); - proj.activeLayer.appendChild(path); + proj.activeLayer.appendTop(path); equals(function() { return proj.activeLayer.children.indexOf(path) != -1; }, true); From e5198fea40ab93f1f1ba02e0d0b41efeffd9f9e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 17 May 2011 13:10:22 +0100 Subject: [PATCH 20/39] Remove unused code that seems to stem from PointText. --- src/text/TextItem.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/text/TextItem.js b/src/text/TextItem.js index 444c4ff0..f63f2de6 100644 --- a/src/text/TextItem.js +++ b/src/text/TextItem.js @@ -19,7 +19,6 @@ var TextItem = this.TextItem = Item.extend({ initialize: function() { this.base(); - point = Point.read(arguments, 0, 1); this.content = null; this.setCharacterStyle(this._project.getCurrentStyle()); this.setParagraphStyle(); From 41dd9eb1315f1e158a643ada4301c2864262962e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 17 May 2011 13:10:57 +0100 Subject: [PATCH 21/39] Point.read() always returns an object even if nothing is provided, no need to have a default value. --- src/text/PointText.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/text/PointText.js b/src/text/PointText.js index 369ba428..cab7a0d8 100644 --- a/src/text/PointText.js +++ b/src/text/PointText.js @@ -19,8 +19,7 @@ var PointText = this.PointText = TextItem.extend({ initialize: function(point) { this.base(); - point = Point.read(arguments, 0, 1); - this._point = point || new Point(); + this._point = Point.read(arguments, 0); this.matrix = new Matrix().translate(this._point); }, From 5369b251ae1390d5e3c69c7d29f55ad4332b546f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 17 May 2011 13:11:09 +0100 Subject: [PATCH 22/39] Move comment. --- src/text/PointText.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/text/PointText.js b/src/text/PointText.js index cab7a0d8..11718c4e 100644 --- a/src/text/PointText.js +++ b/src/text/PointText.js @@ -36,13 +36,13 @@ var PointText = this.PointText = TextItem.extend({ } }, + // TODO: position should be the center point of the bounds + // but we currently don't support bounds for PointText. getPosition: function() { return this._point; }, setPosition: function(point) { - // TODO: position should be the center point of the bounds - // but we currently don't support bounds for PointText. this.setPoint.apply(this, arguments); }, From 7d1d6fa9da33c3ee13578d4a58265d49a3545cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 17 May 2011 13:12:19 +0100 Subject: [PATCH 23/39] Define Base.initialize() as a general purpose way to initialize a newly created object with values from a provided object and default values from another, in case they are not provided. --- src/core/Base.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/core/Base.js b/src/core/Base.js index 22bdab1d..c11782d7 100644 --- a/src/core/Base.js +++ b/src/core/Base.js @@ -43,6 +43,14 @@ Base.inject({ return res; }, + initialize: function(object, values, defaults) { + if (!values) + values = defaults; + return Base.each(defaults, function(value, key) { + this[key] = values[key] || value; + }, object); + }, + /** * Utility function for adding and removing items from a list of which * each entry keeps a reference to its index in the list in the private From 6427bca46eaf6b83efeabf38cf237272d524e03f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 17 May 2011 13:12:44 +0100 Subject: [PATCH 24/39] No beans required in ParagraphStyle yet. --- src/text/ParagraphStyle.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/text/ParagraphStyle.js b/src/text/ParagraphStyle.js index d1a49515..57135d45 100644 --- a/src/text/ParagraphStyle.js +++ b/src/text/ParagraphStyle.js @@ -15,8 +15,6 @@ */ var ParagraphStyle = this.ParagraphStyle = Base.extend({ - beans: true, - initialize: function(style) { this.justification = (style && style.justification) || 'left'; }, From 2c03cb1ccb65937c7e3d024ae13c9ca9fe09ab86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 17 May 2011 13:13:24 +0100 Subject: [PATCH 25/39] Use Base.initialize() in both ParagraphStyle and CharacterStyle's #initialize(). --- src/text/CharacterStyle.js | 6 ++++-- src/text/ParagraphStyle.js | 8 +++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/text/CharacterStyle.js b/src/text/CharacterStyle.js index 9367700a..76502100 100644 --- a/src/text/CharacterStyle.js +++ b/src/text/CharacterStyle.js @@ -16,8 +16,10 @@ var CharacterStyle = this.CharacterStyle = PathStyle.extend({ initialize: function(style) { - this.fontSize = style.fontSize || 10; - this.font = style.font || 'sans-serif'; + Base.initialize(this, style, { + fontSize: 10, + font: 'sans-serif' + }); this.base(style); }, diff --git a/src/text/ParagraphStyle.js b/src/text/ParagraphStyle.js index 57135d45..6241858b 100644 --- a/src/text/ParagraphStyle.js +++ b/src/text/ParagraphStyle.js @@ -16,11 +16,9 @@ var ParagraphStyle = this.ParagraphStyle = Base.extend({ initialize: function(style) { - this.justification = (style && style.justification) || 'left'; - }, - - clone: function() { - return new PathStyle(this); + Base.initialize(this, style, { + justification: 'left' + }); }, statics: { From c07f9b438e62e4e72839dc5576d1e31f675292dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 17 May 2011 13:14:04 +0100 Subject: [PATCH 26/39] Use same modification in static create() method of ParagraphStyle and CharacterStyle as was used in PathStyle. --- src/text/CharacterStyle.js | 5 ++--- src/text/ParagraphStyle.js | 5 ++--- src/text/TextItem.js | 6 ++++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/text/CharacterStyle.js b/src/text/CharacterStyle.js index 76502100..d44e683d 100644 --- a/src/text/CharacterStyle.js +++ b/src/text/CharacterStyle.js @@ -22,12 +22,11 @@ var CharacterStyle = this.CharacterStyle = PathStyle.extend({ }); this.base(style); }, - + statics: { - create: function(item, other) { + create: function(item) { var style = new CharacterStyle(CharacterStyle.dont); style._item = item; - style.initialize(other); return style; } } diff --git a/src/text/ParagraphStyle.js b/src/text/ParagraphStyle.js index 6241858b..5381328b 100644 --- a/src/text/ParagraphStyle.js +++ b/src/text/ParagraphStyle.js @@ -22,10 +22,9 @@ var ParagraphStyle = this.ParagraphStyle = Base.extend({ }, statics: { - create: function(item, other) { - var style = new ParagraphStyle(PathStyle.dont); + create: function(item) { + var style = new CharacterStyle(CharacterStyle.dont); style._item = item; - style.initialize(other); return style; } } diff --git a/src/text/TextItem.js b/src/text/TextItem.js index f63f2de6..6ebc6d19 100644 --- a/src/text/TextItem.js +++ b/src/text/TextItem.js @@ -20,7 +20,9 @@ var TextItem = this.TextItem = Item.extend({ initialize: function() { this.base(); this.content = null; + this._characterStyle = CharacterStyle.create(this); this.setCharacterStyle(this._project.getCurrentStyle()); + this._paragraphStyle = ParagraphStyle.create(this); this.setParagraphStyle(); }, @@ -29,7 +31,7 @@ var TextItem = this.TextItem = Item.extend({ }, setCharacterStyle: function(style) { - this._characterStyle = CharacterStyle.create(this, style); + this._characterStyle.initialize(style); }, getParagraphStyle: function() { @@ -37,6 +39,6 @@ var TextItem = this.TextItem = Item.extend({ }, setParagraphStyle: function(style) { - this._paragraphStyle = ParagraphStyle.create(this, style); + this._paragraphStyle.initialize(style); } }); From e5f8ee04645d1e65d98075afbb02011709c2f2f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 17 May 2011 13:14:23 +0100 Subject: [PATCH 27/39] Write comment about calling base() from Layer#initialize(). --- src/item/Layer.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/item/Layer.js b/src/item/Layer.js index 700d0e0b..7df19d49 100644 --- a/src/item/Layer.js +++ b/src/item/Layer.js @@ -18,6 +18,8 @@ var Layer = this.Layer = Group.extend({ beans: true, initialize: function() { + // TODO: Isn't there a way to call this.base() here and then move the + // layer into layers instead? this._children = []; this._namedChildren = {}; this._project = paper.project; From 7b4dd222ac0e3c8ed90f8a375ae0d9e2846deb48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 17 May 2011 13:25:46 +0100 Subject: [PATCH 28/39] Completely decouple ProjectView from Project. --- src/core/PaperScope.js | 20 +++++++------------- src/core/PaperScript.js | 11 ++++++----- src/project/Project.js | 15 ++++++--------- src/project/ProjectView.js | 22 ++++++++-------------- 4 files changed, 27 insertions(+), 41 deletions(-) diff --git a/src/core/PaperScope.js b/src/core/PaperScope.js index d13938b5..4439fc6a 100644 --- a/src/core/PaperScope.js +++ b/src/core/PaperScope.js @@ -19,27 +19,18 @@ * global paper object, which simply is a pointer to the currently active scope. */ var PaperScope = this.PaperScope = Base.extend({ - beans: true, initialize: function(id) { this.project = null; this.projects = []; + this.view = null; + this.views = []; + this.tool = null; this.tools = []; this.id = id; PaperScope._scopes[id] = this; }, - /** - * A short-cut to the currently active view of the active project. - */ - getView: function() { - return this.project.activeView; - }, - - getViews: function() { - return this.project.views; - }, - evaluate: function(code) { return PaperScript.evaluate(code, this); }, @@ -60,9 +51,12 @@ var PaperScope = this.PaperScope = Base.extend({ }, clear: function() { - // Remove all projects and tools. + // Remove all projects, views and tools. for (var i = this.projects.length - 1; i >= 0; i--) this.projects[i].remove(); + // This also removes the installed event handlers. + for (var i = this.views.length - 1; i >= 0; i--) + this.views[i].remove(); for (var i = this.tools.length - 1; i >= 0; i--) this.tools[i].remove(); }, diff --git a/src/core/PaperScript.js b/src/core/PaperScript.js index 5284a6ab..f06acf1e 100644 --- a/src/core/PaperScript.js +++ b/src/core/PaperScript.js @@ -137,11 +137,12 @@ var PaperScript = this.PaperScript = new function() { // so the active project is defined. var canvas = code.getAttribute('canvas'); if (canvas = canvas && document.getElementById(canvas)) { - // Create a Project for this canvas, using the right scope + // Create an empty Project for this scope, and a view for the + // canvas, both using the right paper scope paper = scope; - // XXX: Do not pass canvas to Project. - // Create ProjectView here instead. - new Project(canvas); + new Project(); + // Activate the newly created view straight away + new ProjectView(canvas).activate(); } if (code.src) { // If we're loading from a source, request that first and then @@ -154,7 +155,7 @@ var PaperScript = this.PaperScript = new function() { } //#endif // BROWSER var proj = scope.project, - view = proj.activeView, + view = scope.view, // TODO: Add support for multiple tools tool = scope.tool = /on(?:Key|Mouse)(?:Up|Down|Move|Drag)/.test(code) && new Tool(null, scope), diff --git a/src/project/Project.js b/src/project/Project.js index 932d5554..ba2e4900 100644 --- a/src/project/Project.js +++ b/src/project/Project.js @@ -17,8 +17,8 @@ var Project = this.Project = Base.extend({ beans: true, - // XXX: Add arguments to define pages, but do not pass canvas here - initialize: function(canvas) { + // TODO: Add arguments to define pages + initialize: function() { // Store reference to the currently active global paper scope: this._scope = paper; // Push it onto this._scope.projects and set index: @@ -27,10 +27,8 @@ var Project = this.Project = Base.extend({ // Layer and DoumentView constructors. this.activate(); this.layers = []; - this.views = []; this.symbols = []; this.activeLayer = new Layer(); - this.activeView = canvas ? new ProjectView(canvas) : null; this._selectedItems = {}; this._selectedItemCount = 0; this._currentStyle = PathStyle.create(null); @@ -55,9 +53,6 @@ var Project = this.Project = Base.extend({ remove: function() { var res = Base.splice(this._scope.projects, null, this._index, 1); this._scope = null; - // Remove all views. This also removes the installed event handlers. - for (var i = this.views.length - 1; i >= 0; i--) - this.views[i].remove(); return !!res.length; }, @@ -130,8 +125,10 @@ var Project = this.Project = Base.extend({ } }, + /** + * @deprecated + */ redraw: function() { - for (var i = 0, l = this.views.length; i < l; i++) - this.views[i].draw(); + this._scope.view.draw(); } }); diff --git a/src/project/ProjectView.js b/src/project/ProjectView.js index 19ddafa4..e0a25228 100644 --- a/src/project/ProjectView.js +++ b/src/project/ProjectView.js @@ -21,12 +21,10 @@ var ProjectView = this.ProjectView = Base.extend({ // Find a good name for these bounds, since #bounds is already the artboard // bounds of the visible area. initialize: function(canvas) { - // To go with the convention of never passing project to constructors, - // in all items, associate the view with the currently active project. - this._project = paper.project; - this._scope = this._project._scope; + // Associate this view with the active paper scope. + this._scope = paper; // Push it onto project.views and set index: - this._index = this._project.views.push(this) - 1; + this._index = this._scope.views.push(this) - 1; // Handle canvas argument var size; if (canvas && canvas instanceof HTMLCanvasElement) { @@ -90,10 +88,6 @@ var ProjectView = this.ProjectView = Base.extend({ ProjectView.focused = this; }, - getProject: function() { - return this._project; - }, - getViewBounds: function() { return this._viewBounds; }, @@ -170,20 +164,20 @@ var ProjectView = this.ProjectView = Base.extend({ this._context.clearRect(bounds._x, bounds._y, // TODO: +1... what if we have multiple views in one canvas? bounds._width + 1, bounds._height + 1); - this._project.draw(this._context); + // Just draw the active project for now + this._scope.project.draw(this._context); }, activate: function() { - this._project.activeView = this; + this._scope.view = this; }, remove: function() { - var res = Base.splice(this._project.views, null, this._index, 1); + var res = Base.splice(this._scope.views, null, this._index, 1); // Uninstall event handlers again for this view. DomEvent.remove(this._canvas, this._events); - this._project = this._scope = this._canvas = this._events = null; // Clearing _onFrame makes the frame handler stop automatically. - this._onFrame = null; + this._scope = this._canvas = this._events = this._onFrame = null; return !!res.length; }, From 26269d394acf08cdd24bb2df1585a29c9cf308fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 17 May 2011 13:29:07 +0100 Subject: [PATCH 29/39] Rename project/ProjectView -> ui/View. --- src/core/PaperScript.js | 2 +- src/item/Item.js | 2 +- src/load.js | 2 +- src/paper.js | 2 +- src/ui/Key.js | 2 +- src/{project/ProjectView.js => ui/View.js} | 8 ++++---- 6 files changed, 9 insertions(+), 9 deletions(-) rename src/{project/ProjectView.js => ui/View.js} (98%) diff --git a/src/core/PaperScript.js b/src/core/PaperScript.js index f06acf1e..45299e6e 100644 --- a/src/core/PaperScript.js +++ b/src/core/PaperScript.js @@ -142,7 +142,7 @@ var PaperScript = this.PaperScript = new function() { paper = scope; new Project(); // Activate the newly created view straight away - new ProjectView(canvas).activate(); + new View(canvas).activate(); } if (code.src) { // If we're loading from a source, request that first and then diff --git a/src/item/Item.js b/src/item/Item.js index 31311b14..7aba445a 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -665,7 +665,7 @@ var Item = this.Item = Base.extend({ } }, - // TODO: Implement ProjectView into the drawing + // TODO: Implement View into the drawing // TODO: Optimize temporary canvas drawing to ignore parts that are // outside of the visible view. draw: function(item, ctx, param) { diff --git a/src/load.js b/src/load.js index 61a8d393..b34b89ba 100644 --- a/src/load.js +++ b/src/load.js @@ -35,7 +35,6 @@ var sources = [ 'src/basic/Matrix.js', 'src/basic/Line.js', - 'src/project/ProjectView.js', 'src/project/Project.js', 'src/project/Symbol.js', @@ -73,6 +72,7 @@ var sources = [ 'src/browser/DomElement.js', 'src/browser/DomEvent.js', + 'src/ui/View.js', 'src/ui/Event.js', 'src/ui/KeyEvent.js', 'src/ui/Key.js', diff --git a/src/paper.js b/src/paper.js index df9bbbec..6b887cb9 100644 --- a/src/paper.js +++ b/src/paper.js @@ -52,7 +52,6 @@ var paper = new function() { //#include "basic/Matrix.js" //#include "basic/Line.js" -//#include "project/ProjectView.js" //#include "project/Project.js" //#include "project/Symbol.js" @@ -93,6 +92,7 @@ var paper = new function() { //#include "browser/DomElement.js" //#include "browser/DomEvent.js" +//#include "ui/View.js" //#include "ui/Event.js" //#include "ui/KeyEvent.js" //#include "ui/Key.js" diff --git a/src/ui/Key.js b/src/ui/Key.js index b3439c74..a88953f3 100644 --- a/src/ui/Key.js +++ b/src/ui/Key.js @@ -65,7 +65,7 @@ var Key = this.Key = new function() { var character = String.fromCharCode(charCode), key = keys[keyCode] || character.toLowerCase(), handler = down ? 'onKeyDown' : 'onKeyUp', - scope = ProjectView.focused && ProjectView.focused._scope, + scope = View.focused && View.focused._scope, tool = scope && scope.tool; keyMap[key] = down; if (tool && tool[handler]) { diff --git a/src/project/ProjectView.js b/src/ui/View.js similarity index 98% rename from src/project/ProjectView.js rename to src/ui/View.js index e0a25228..64399af4 100644 --- a/src/project/ProjectView.js +++ b/src/ui/View.js @@ -14,7 +14,7 @@ * All rights reserved. */ -var ProjectView = this.ProjectView = Base.extend({ +var View = this.View = Base.extend({ beans: true, // TODO: Add bounds parameter that defines position within canvas? @@ -84,8 +84,8 @@ var ProjectView = this.ProjectView = Base.extend({ this._events = this._createEvents(); DomEvent.add(this._canvas, this._events); // Make sure the first view is focused for keyboard input straight away - if (!ProjectView.focused) - ProjectView.focused = this; + if (!View.focused) + View.focused = this; }, getViewBounds: function() { @@ -273,7 +273,7 @@ var ProjectView = this.ProjectView = Base.extend({ function mousedown(event) { // Tell the Key class which view should receive keyboard input. - ProjectView.focused = that; + View.focused = that; if (!(tool = that._scope.tool)) return; curPoint = viewToArtwork(event); From 2f63127b021b76af298a78a2be27bacd21a90ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 17 May 2011 13:41:42 +0100 Subject: [PATCH 30/39] Simplify and fix View#setZoom(). --- src/ui/View.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ui/View.js b/src/ui/View.js index 64399af4..b0038d8b 100644 --- a/src/ui/View.js +++ b/src/ui/View.js @@ -144,9 +144,7 @@ var View = this.View = Base.extend({ setZoom: function(zoom) { // TODO: Clamp the view between 1/32 and 64, just like Illustrator? - var mx = new Matrix(); - mx.scale(zoom / this._zoom, this._center); - this.transform(mx); + this.transform(new Matrix().scale(zoom / this._zoom, this.getCenter())); this._zoom = zoom; }, From ac364014da204e690e6c4d1e8225c9e77df6f1fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 17 May 2011 13:42:20 +0100 Subject: [PATCH 31/39] Actually use matrix when drawing view. --- src/ui/View.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ui/View.js b/src/ui/View.js index b0038d8b..fdce8e72 100644 --- a/src/ui/View.js +++ b/src/ui/View.js @@ -158,12 +158,17 @@ var View = this.View = Base.extend({ // Initial tests conclude that clearing the canvas using clearRect // is always faster than setting canvas.width = canvas.width // http://jsperf.com/clearrect-vs-setting-width/7 - var bounds = this._viewBounds; - this._context.clearRect(bounds._x, bounds._y, + var ctx =this._context, + bounds = this._viewBounds; + ctx.clearRect(bounds._x, bounds._y, // TODO: +1... what if we have multiple views in one canvas? bounds._width + 1, bounds._height + 1); + + ctx.save(); + this._matrix.applyToContext(ctx); // Just draw the active project for now - this._scope.project.draw(this._context); + this._scope.project.draw(ctx); + ctx.restore(); }, activate: function() { From f3f551576302e27353b12c218fdea7a816eadbca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 17 May 2011 13:42:45 +0100 Subject: [PATCH 32/39] Add comment about potential renaming of artworkToView -> projectToView? --- src/ui/View.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ui/View.js b/src/ui/View.js index fdce8e72..0f653682 100644 --- a/src/ui/View.js +++ b/src/ui/View.js @@ -203,6 +203,8 @@ var View = this.View = Base.extend({ // TODO: getShowGrid // TODO: getMousePoint // TODO: artworkToView(rect) + + // TODO: Consider naming these projectToView, viewToProject artworkToView: function(point) { return this._matrix._transformPoint(Point.read(arguments)); }, From 160f3d55c7fe0ddb07fbb309e96d3f216d073817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 17 May 2011 13:43:10 +0100 Subject: [PATCH 33/39] Make View#transform() private. --- src/ui/View.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ui/View.js b/src/ui/View.js index 0f653682..1ba91e7a 100644 --- a/src/ui/View.js +++ b/src/ui/View.js @@ -144,12 +144,12 @@ var View = this.View = Base.extend({ setZoom: function(zoom) { // TODO: Clamp the view between 1/32 and 64, just like Illustrator? - this.transform(new Matrix().scale(zoom / this._zoom, this.getCenter())); + this._transform(new Matrix().scale(zoom / this._zoom, this.getCenter())); this._zoom = zoom; }, scrollBy: function(point) { - this.transform(new Matrix().translate(Point.read(arguments).negate())); + this._transform(new Matrix().translate(Point.read(arguments).negate())); }, draw: function() { @@ -184,7 +184,7 @@ var View = this.View = Base.extend({ return !!res.length; }, - transform: function(matrix, flags) { + _transform: function(matrix, flags) { this._matrix.preConcatenate(matrix); // Force recalculation of these values next time they are requested. this._bounds = null; From fc52944ee8a9e8a6fd02a97e278e3f1c89846995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 17 May 2011 13:43:45 +0100 Subject: [PATCH 34/39] Change method sequence a bit. --- src/ui/View.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/ui/View.js b/src/ui/View.js index 1ba91e7a..4332de0d 100644 --- a/src/ui/View.js +++ b/src/ui/View.js @@ -152,6 +152,13 @@ var View = this.View = Base.extend({ this._transform(new Matrix().translate(Point.read(arguments).negate())); }, + _transform: function(matrix, flags) { + this._matrix.preConcatenate(matrix); + // Force recalculation of these values next time they are requested. + this._bounds = null; + this._inverse = null; + }, + draw: function() { if (this._stats) this._stats.update(); @@ -184,19 +191,6 @@ var View = this.View = Base.extend({ return !!res.length; }, - _transform: function(matrix, flags) { - this._matrix.preConcatenate(matrix); - // Force recalculation of these values next time they are requested. - this._bounds = null; - this._inverse = null; - }, - - _getInverse: function() { - if (!this._inverse) - this._inverse = this._matrix.createInverse(); - return this._inverse; - }, - // TODO: getInvalidBounds // TODO: invalidate(rect) // TODO: style: artwork / preview / raster / opaque / ink @@ -213,6 +207,12 @@ var View = this.View = Base.extend({ return this._getInverse()._transformPoint(Point.read(arguments)); }, + _getInverse: function() { + if (!this._inverse) + this._inverse = this._matrix.createInverse(); + return this._inverse; + }, + /** * Handler to be called whenever a view gets resized. */ From eb6b838cf4eedadb11c59ce8922c508508f7832b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 18 May 2011 09:38:20 +0100 Subject: [PATCH 35/39] Simplify GradientStop#setRampPoint(). --- src/color/GradientStop.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/color/GradientStop.js b/src/color/GradientStop.js index 08c0220e..faef7006 100644 --- a/src/color/GradientStop.js +++ b/src/color/GradientStop.js @@ -28,7 +28,7 @@ var GradientStop = this.GradientStop = Base.extend({ }, setRampPoint: function(rampPoint) { - this._rampPoint = rampPoint !== null ? rampPoint : 0; + this._rampPoint = rampPoint || 0; }, getColor: function() { From 8b2709f5d81b0b1bf3453d4afabeef4c1260e6a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 18 May 2011 09:38:45 +0100 Subject: [PATCH 36/39] Replace accidental beans access with direct access of internal property. --- src/color/GradientColor.js | 2 +- src/color/GradientStop.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/color/GradientColor.js b/src/color/GradientColor.js index a25611df..8e5ba00e 100644 --- a/src/color/GradientColor.js +++ b/src/color/GradientColor.js @@ -79,7 +79,7 @@ var GradientColor = this.GradientColor = Color.extend({ } for (var i = 0, l = this.gradient._stops.length; i < l; i++) { var stop = this.gradient._stops[i]; - gradient.addColorStop(stop._rampPoint, stop.color.toCssString()); + gradient.addColorStop(stop._rampPoint, stop._color.toCssString()); } return gradient; }, diff --git a/src/color/GradientStop.js b/src/color/GradientStop.js index faef7006..653fec33 100644 --- a/src/color/GradientStop.js +++ b/src/color/GradientStop.js @@ -44,7 +44,7 @@ var GradientStop = this.GradientStop = Base.extend({ return true; } else if (stop instanceof GradientStop) { return this._color.equals(stop._color) - && rampPoint == stop.rampPoint; + && rampPoint == stop._rampPoint; } return false; } From 57eabed8748728628a5386ca41006ad2aff85ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 18 May 2011 09:40:03 +0100 Subject: [PATCH 37/39] Simplify GradientStop#equals(). --- src/color/GradientStop.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/color/GradientStop.js b/src/color/GradientStop.js index 653fec33..5878a64c 100644 --- a/src/color/GradientStop.js +++ b/src/color/GradientStop.js @@ -38,14 +38,10 @@ var GradientStop = this.GradientStop = Base.extend({ setColor: function(color) { this._color = Color.read(arguments); }, - + equals: function(stop) { - if (stop == this) { - return true; - } else if (stop instanceof GradientStop) { - return this._color.equals(stop._color) + return stop == this || stop instanceof GradientStop + && this._color.equals(stop._color) && rampPoint == stop._rampPoint; - } - return false; } }); From 88332d763d4153f0f97cdd6f10723171de0a222a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 18 May 2011 09:42:09 +0100 Subject: [PATCH 38/39] Simplify GradientColor#equals(). --- src/color/GradientColor.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/color/GradientColor.js b/src/color/GradientColor.js index 8e5ba00e..d17f795f 100644 --- a/src/color/GradientColor.js +++ b/src/color/GradientColor.js @@ -92,12 +92,10 @@ var GradientColor = this.GradientColor = Color.extend({ * @return true if the GrayColor is the same, false otherwise. */ equals: function(color) { - if (color && color._colorType === this._colorType) { - return this.gradient.equals(color.gradient) - && this._origin.equals(color._origin) - && this._destination.equals(color._destination); - } - return false; + return color == this || color && color._colorType === this._colorType + && this.gradient.equals(color.gradient) + && this._origin.equals(color._origin) + && this._destination.equals(color._destination); }, transform: function(matrix) { From db1a25933aaee6300a5f1628a8eda91c52cbbe8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 18 May 2011 09:43:32 +0100 Subject: [PATCH 39/39] Replace accidental beans access with direct access of internal property. --- src/color/GradientColor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/color/GradientColor.js b/src/color/GradientColor.js index d17f795f..91df299a 100644 --- a/src/color/GradientColor.js +++ b/src/color/GradientColor.js @@ -71,7 +71,7 @@ var GradientColor = this.GradientColor = Color.extend({ var gradient; if (this.gradient.type === 'linear') { gradient = ctx.createLinearGradient(this._origin.x, this._origin.y, - this.destination.x, this.destination.y); + this._destination.x, this._destination.y); } else { var origin = this._hilite || this._origin; gradient = ctx.createRadialGradient(origin.x, origin.y,