aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/rectangle.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom/rectangle.js')
-rwxr-xr-xjs/lib/geom/rectangle.js1210
1 files changed, 649 insertions, 561 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js
index 0d302d50..f1da4918 100755
--- a/js/lib/geom/rectangle.js
+++ b/js/lib/geom/rectangle.js
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, are permitted provided that the following conditions are met:
8 7
9 - Redistributions of source code must retain the above copyright notice, 8* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 10
12 notice, this list of conditions and the following disclaimer in the 11* Redistributions in binary form must reproduce the above copyright notice,
13 documentation and/or other materials provided with the distribution. 12 this list of conditions and the following disclaimer in the documentation
14 - Neither the name of Motorola Mobility nor the names of its contributors 13 and/or other materials provided with the distribution.
15 may be used to endorse or promote products derived from this software 14
16 without specific prior written permission. 15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
17 18
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -38,15 +39,15 @@ var MaterialsModel = require("js/models/materials-model").MaterialsModel;
38// Derived from class GeomObj 39// Derived from class GeomObj
39/////////////////////////////////////////////////////////////////////// 40///////////////////////////////////////////////////////////////////////
40exports.Rectangle = Object.create(GeomObj, { 41exports.Rectangle = Object.create(GeomObj, {
41 // CONSTANTS 42 // CONSTANTS
42 N_TRIANGLES: { value : 15, writable: false }, // TODO - This is not being used anywhere. Remove? 43 N_TRIANGLES: { value : 15, writable: false }, // TODO - This is not being used anywhere. Remove?
43 44
44 //if (!MaterialsModel) 45 //if (!MaterialsModel)
45 // MaterialsModel = require("js/models/materials-model").MaterialsModel; 46 // MaterialsModel = require("js/models/materials-model").MaterialsModel;
46 47
47 /////////////////////////////////////////////////////////////////////// 48 ///////////////////////////////////////////////////////////////////////
48 // Instance variables 49 // Instance variables
49 /////////////////////////////////////////////////////////////////////// 50 ///////////////////////////////////////////////////////////////////////
50 _width: { value : 2.0, writable: true }, 51 _width: { value : 2.0, writable: true },
51 _height: { value : 2.0, writable: true }, 52 _height: { value : 2.0, writable: true },
52 _xOffset: { value : 0, writable: true }, 53 _xOffset: { value : 0, writable: true },
@@ -82,7 +83,7 @@ exports.Rectangle = Object.create(GeomObj, {
82 83
83 this._strokeStyle = strokeStyle; 84 this._strokeStyle = strokeStyle;
84 85
85 this._matrix = Matrix.I(4); 86 this._matrix = Matrix.I(4);
86 } 87 }
87 88
88 // the overall radius includes the fill and the stroke. separate the two based on the stroke width 89 // the overall radius includes the fill and the stroke. separate the two based on the stroke width
@@ -101,19 +102,32 @@ exports.Rectangle = Object.create(GeomObj, {
101 } else { 102 } else {
102 this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); 103 this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
103 } 104 }
104 if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor );
105 105
106 if(strokeColor) {
107 if(this._strokeMaterial.hasProperty("color")) {
108 this._strokeMaterial.setProperty( "color", this._strokeColor );
109 } else if (this._strokeMaterial && (this._strokeMaterial.gradientType === this._strokeColor.gradientMode)) {
110 this._strokeMaterial.setGradientData(this._strokeColor.color);
111 }
112 }
106 113
107 if(fillMaterial) { 114 if(fillMaterial) {
108 this._fillMaterial = fillMaterial.dup(); 115 this._fillMaterial = fillMaterial.dup();
109 } else { 116 } else {
110 this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); 117 this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
111 } 118 }
112 if (fillColor && this._fillMaterial.hasProperty( "color" )) this._fillMaterial.setProperty( "color", this._fillColor ); 119
120 if(fillColor) {
121 if(this._fillMaterial.hasProperty("color")) {
122 this._fillMaterial.setProperty( "color", this._fillColor );
123 } else if (this._fillMaterial && (this._fillMaterial.gradientType === this._fillColor.gradientMode)) {
124 this._fillMaterial.setGradientData(this._fillColor.color);
125 }
126 }
113 } 127 }
114 }, 128 },
115 129
116 /////////////////////////////////////////////////////////////////////// 130 ///////////////////////////////////////////////////////////////////////
117 // Property Accessors 131 // Property Accessors
118 /////////////////////////////////////////////////////////////////////// 132 ///////////////////////////////////////////////////////////////////////
119 // TODO - Use getters/setters in the future 133 // TODO - Use getters/setters in the future
@@ -152,7 +166,7 @@ exports.Rectangle = Object.create(GeomObj, {
152 this._fillMaterial = m; 166 this._fillMaterial = m;
153 } 167 }
154 }, 168 },
155 /////////////////////////////////////////////////////////////////////// 169 ///////////////////////////////////////////////////////////////////////
156 // update the "color of the material 170 // update the "color of the material
157 getFillColor: { 171 getFillColor: {
158 value: function() { 172 value: function() {
@@ -267,31 +281,31 @@ exports.Rectangle = Object.create(GeomObj, {
267 } 281 }
268 }, 282 },
269 283
270 /////////////////////////////////////////////////////////////////////// 284 ///////////////////////////////////////////////////////////////////////
271 // Methods 285 // Methods
272 /////////////////////////////////////////////////////////////////////// 286 ///////////////////////////////////////////////////////////////////////
273 // JSON export 287 // JSON export
274 exportJSON: { 288 exportJSON: {
275 value: function() { 289 value: function() {
276 var jObj = 290 var jObj =
277 { 291 {
278 'type' : this.geomType(), 292 'type' : this.geomType(),
279 'xoff' : this._xOffset, 293 'xoff' : this._xOffset,
280 'yoff' : this._yOffset, 294 'yoff' : this._yOffset,
281 'width' : this._width, 295 'width' : this._width,
282 'height' : this._height, 296 'height' : this._height,
283 'strokeWidth' : this._strokeWidth, 297 'strokeWidth' : this._strokeWidth,
284 'strokeColor' : this._strokeColor, 298 'strokeColor' : this._strokeColor,
285 'fillColor' : this._fillColor, 299 'fillColor' : this._fillColor,
286 'tlRadius' : this._tlRadius, 300 'tlRadius' : this._tlRadius,
287 'trRadius' : this._trRadius, 301 'trRadius' : this._trRadius,
288 'blRadius' : this._blRadius, 302 'blRadius' : this._blRadius,
289 'brRadius' : this._brRadius, 303 'brRadius' : this._brRadius,
290 'innerRadius' : this._innerRadius, 304 'innerRadius' : this._innerRadius,
291 'strokeStyle' : this._strokeStyle, 305 'strokeStyle' : this._strokeStyle,
292 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(), 306 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(),
293 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(), 307 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(),
294 'materials' : this.exportMaterialsJSON() 308 'materials' : this.exportMaterialsJSON()
295 }; 309 };
296 310
297 return jObj; 311 return jObj;
@@ -300,21 +314,21 @@ exports.Rectangle = Object.create(GeomObj, {
300 314
301 importJSON: { 315 importJSON: {
302 value: function(jObj) { 316 value: function(jObj) {
303 this._xOffset = jObj.xoff; 317 this._xOffset = jObj.xoff;
304 this._yOffset = jObj.yoff; 318 this._yOffset = jObj.yoff;
305 this._width = jObj.width; 319 this._width = jObj.width;
306 this._height = jObj.height; 320 this._height = jObj.height;
307 this._strokeWidth = jObj.strokeWidth; 321 this._strokeWidth = jObj.strokeWidth;
308 this._strokeColor = jObj.strokeColor; 322 this._strokeColor = jObj.strokeColor;
309 this._fillColor = jObj.fillColor; 323 this._fillColor = jObj.fillColor;
310 this._tlRadius = jObj.tlRadius; 324 this._tlRadius = jObj.tlRadius;
311 this._trRadius = jObj.trRadius; 325 this._trRadius = jObj.trRadius;
312 this._blRadius = jObj.blRadius; 326 this._blRadius = jObj.blRadius;
313 this._brRadius = jObj.brRadius; 327 this._brRadius = jObj.brRadius;
314 this._innerRadius = jObj.innerRadius; 328 this._innerRadius = jObj.innerRadius;
315 this._strokeStyle = jObj.strokeStyle; 329 this._strokeStyle = jObj.strokeStyle;
316 var strokeMaterialName = jObj.strokeMat; 330 var strokeMaterialName = jObj.strokeMat;
317 var fillMaterialName = jObj.fillMat; 331 var fillMaterialName = jObj.fillMat;
318 332
319 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ).dup(); 333 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ).dup();
320 if (!strokeMat) { 334 if (!strokeMat) {
@@ -322,8 +336,8 @@ exports.Rectangle = Object.create(GeomObj, {
322 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); 336 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
323 } 337 }
324 this._strokeMaterial = strokeMat; 338 this._strokeMaterial = strokeMat;
325 if (this._strokeMaterial.hasProperty( 'color' )) 339 if (this._strokeMaterial.hasProperty( 'color' ))
326 this._strokeMaterial.setProperty( 'color', this._strokeColor ); 340 this._strokeMaterial.setProperty( 'color', this._strokeColor );
327 341
328 var fillMat = MaterialsModel.getMaterial( fillMaterialName ).dup(); 342 var fillMat = MaterialsModel.getMaterial( fillMaterialName ).dup();
329 if (!fillMat) { 343 if (!fillMat) {
@@ -331,8 +345,8 @@ exports.Rectangle = Object.create(GeomObj, {
331 fillMat = MaterialsModel