From 5b4f6b1618cf571a6bce5a631f976a008e04a64e Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Thu, 29 Mar 2012 15:52:08 -0700 Subject: Updated shapes to always check for its stroke and fill colors and materials instead of relying on the shapeModel cache because it can get out of sync. Signed-off-by: Nivesh Rajbhandari --- js/lib/geom/circle.js | 15 +++++++++ js/lib/geom/geom-obj.js | 82 +++++++++++++++++++++++++----------------------- js/lib/geom/line.js | 8 +++++ js/lib/geom/rectangle.js | 15 +++++++++ 4 files changed, 80 insertions(+), 40 deletions(-) (limited to 'js/lib/geom') diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index d48bf98b..ee3e2abd 100755 --- a/js/lib/geom/circle.js +++ b/js/lib/geom/circle.js @@ -633,6 +633,21 @@ var Circle = function GLCircle() { this._strokeStyle = jObj.strokeStyle; var strokeMaterialName = jObj.strokeMat; var fillMaterialName = jObj.fillMat; + + var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); + if (!strokeMat) { + console.log( "object material not found in library: " + strokeMaterialName ); + strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); + } + this._strokeMaterial = strokeMat; + + var fillMat = MaterialsModel.getMaterial( fillMaterialName ); + if (!fillMat) { + console.log( "object material not found in library: " + fillMaterialName ); + fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); + } + this._fillMaterial = fillMat; + this.importMaterialsJSON( jObj.materials ); }; diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index 3c4e4bbf..df4a018d 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js @@ -141,54 +141,56 @@ var GeomObj = function GLGeomObj() { this.setMaterialColor = function(c, type) { var i = 0, nMats = 0; - if(c.gradientMode) { - // Gradient support - if (this._materialArray && this._materialTypeArray) { - nMats = this._materialArray.length; - } + if(c) { + if(c.gradientMode) { + // Gradient support + if (this._materialArray && this._materialTypeArray) { + nMats = this._materialArray.length; + } - var stops = [], - colors = c.color; + var stops = [], + colors = c.color; - var len = colors.length; - // TODO - Current shaders only support 4 color stops - if(len > 4) { - len = 4; - } + var len = colors.length; + // TODO - Current shaders only support 4 color stops + if(len > 4) { + len = 4; + } - for(var n=0; n --- js/lib/geom/circle.js | 4 ++-- js/lib/geom/line.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'js/lib/geom') diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index ee3e2abd..f74d4e57 100755 --- a/js/lib/geom/circle.js +++ b/js/lib/geom/circle.js @@ -42,8 +42,8 @@ var Circle = function GLCircle() { this._strokeWidth = strokeSize; this._innerRadius = innerRadius; - if (strokeColor) this._strokeColor = strokeColor; - if (fillColor) this._fillColor = fillColor; + this._strokeColor = strokeColor; + this._fillColor = fillColor; this._strokeStyle = strokeStyle; } diff --git a/js/lib/geom/line.js b/js/lib/geom/line.js index 2b2434f5..f3806fac 100755 --- a/js/lib/geom/line.js +++ b/js/lib/geom/line.js @@ -44,7 +44,7 @@ var Line = function GLLine( world, xOffset, yOffset, width, height, slope, strok this._slope = slope; this._strokeWidth = strokeSize; - if (strokeColor) this._strokeColor = strokeColor.slice(); + this._strokeColor = strokeColor; this._strokeStyle = strokeStyle; this._scaleX = (world.getViewportWidth())/(world.getViewportHeight()); -- cgit v1.2.3 From c4e83a61311db75c7a1c307553262e77ecaae662 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Mon, 2 Apr 2012 13:16:27 -0700 Subject: IKNinna-1409 - Should dirty document when changing shape properties. IKNinja-1391 - Shapes need to support no-color. Signed-off-by: Nivesh Rajbhandari --- js/lib/geom/geom-obj.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'js/lib/geom') diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index ce06498d..44daa291 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js @@ -196,6 +196,24 @@ var GeomObj = function GLGeomObj() { } } } + } else { + if (type === "fill") { + this._fillColor = null; + } else { + this._strokeColor = null; + } + + if (this._materialArray && this._materialTypeArray) { + nMats = this._materialArray.length; + if (nMats === this._materialTypeArray.length) { + for (i=0; i