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.js1132
1 files changed, 566 insertions, 566 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js
index 0d302d50..ec3e25b2 100755
--- a/js/lib/geom/rectangle.js
+++ b/js/lib/geom/rectangle.js
@@ -38,15 +38,15 @@ var MaterialsModel = require("js/models/materials-model").MaterialsModel;
38// Derived from class GeomObj 38// Derived from class GeomObj
39/////////////////////////////////////////////////////////////////////// 39///////////////////////////////////////////////////////////////////////
40exports.Rectangle = Object.create(GeomObj, { 40exports.Rectangle = Object.create(GeomObj, {
41 // CONSTANTS 41 // CONSTANTS
42 N_TRIANGLES: { value : 15, writable: false }, // TODO - This is not being used anywhere. Remove? 42 N_TRIANGLES: { value : 15, writable: false }, // TODO - This is not being used anywhere. Remove?
43 43
44 //if (!MaterialsModel) 44 //if (!MaterialsModel)
45 // MaterialsModel = require("js/models/materials-model").MaterialsModel; 45 // MaterialsModel = require("js/models/materials-model").MaterialsModel;
46 46
47 /////////////////////////////////////////////////////////////////////// 47 ///////////////////////////////////////////////////////////////////////
48 // Instance variables 48 // Instance variables
49 /////////////////////////////////////////////////////////////////////// 49 ///////////////////////////////////////////////////////////////////////
50 _width: { value : 2.0, writable: true }, 50 _width: { value : 2.0, writable: true },
51 _height: { value : 2.0, writable: true }, 51 _height: { value : 2.0, writable: true },
52 _xOffset: { value : 0, writable: true }, 52 _xOffset: { value : 0, writable: true },
@@ -82,7 +82,7 @@ exports.Rectangle = Object.create(GeomObj, {
82 82
83 this._strokeStyle = strokeStyle; 83 this._strokeStyle = strokeStyle;
84 84
85 this._matrix = Matrix.I(4); 85 this._matrix = Matrix.I(4);
86 } 86 }
87 87
88 // the overall radius includes the fill and the stroke. separate the two based on the stroke width 88 // the overall radius includes the fill and the stroke. separate the two based on the stroke width
@@ -101,7 +101,7 @@ exports.Rectangle = Object.create(GeomObj, {
101 } else { 101 } else {
102 this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); 102 this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
103 } 103 }
104 if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor ); 104 if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor );
105 105
106 106
107 if(fillMaterial) { 107 if(fillMaterial) {
@@ -109,11 +109,11 @@ exports.Rectangle = Object.create(GeomObj, {
109 } else { 109 } else {
110 this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); 110 this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
111 } 111 }
112 if (fillColor && this._fillMaterial.hasProperty( "color" )) this._fillMaterial.setProperty( "color", this._fillColor ); 112 if (fillColor && this._fillMaterial.hasProperty( "color" )) this._fillMaterial.setProperty( "color", this._fillColor );
113 } 113 }
114 }, 114 },
115 115
116 /////////////////////////////////////////////////////////////////////// 116 ///////////////////////////////////////////////////////////////////////
117 // Property Accessors 117 // Property Accessors
118 /////////////////////////////////////////////////////////////////////// 118 ///////////////////////////////////////////////////////////////////////
119 // TODO - Use getters/setters in the future 119 // TODO - Use getters/setters in the future
@@ -152,7 +152,7 @@ exports.Rectangle = Object.create(GeomObj, {
152 this._fillMaterial = m; 152 this._fillMaterial = m;
153 } 153 }
154 }, 154 },
155 /////////////////////////////////////////////////////////////////////// 155 ///////////////////////////////////////////////////////////////////////
156 // update the "color of the material 156 // update the "color of the material
157 getFillColor: { 157 getFillColor: {
158 value: function() { 158 value: function() {
@@ -267,31 +267,31 @@ exports.Rectangle = Object.create(GeomObj, {
267 } 267 }
268 }, 268 },
269 269
270 /////////////////////////////////////////////////////////////////////// 270 ///////////////////////////////////////////////////////////////////////
271 // Methods 271 // Methods
272 /////////////////////////////////////////////////////////////////////// 272 ///////////////////////////////////////////////////////////////////////
273 // JSON export 273 // JSON export
274 exportJSON: { 274 exportJSON: {
275 value: function() { 275 value: function() {
276 var jObj = 276 var jObj =
277 { 277 {
278 'type' : this.geomType(), 278 'type' : this.geomType(),
279 'xoff' : this._xOffset, 279 'xoff' : this._xOffset,
280 'yoff' : this._yOffset, 280 'yoff' : this._yOffset,
281 'width' : this._width, 281 'width' : this._width,
282 'height' : this._height, 282 'height' : this._height,
283 'strokeWidth' : this._strokeWidth, 283 'strokeWidth' : this._strokeWidth,
284 'strokeColor' : this._strokeColor, 284 'strokeColor' : this._strokeColor,
285 'fillColor' : this._fillColor, 285 'fillColor' : this._fillColor,
286 'tlRadius' : this._tlRadius, 286 'tlRadius' : this._tlRadius,
287 'trRadius' : this._trRadius, 287 'trRadius' : this._trRadius,
288 'blRadius' : this._blRadius, 288 'blRadius' : this._blRadius,
289 'brRadius' : this._brRadius, 289 'brRadius' : this._brRadius,
290 'innerRadius' : this._innerRadius, 290 'innerRadius' : this._innerRadius,
291 'strokeStyle' : this._strokeStyle, 291 'strokeStyle' : this._strokeStyle,
292 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(), 292 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(),
293 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(), 293 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(),
294 'materials' : this.exportMaterialsJSON() 294 'materials' : this.exportMaterialsJSON()
295 }; 295 };
296 296
297 return jObj; 297 return jObj;
@@ -300,21 +300,21 @@ exports.Rectangle = Object.create(GeomObj, {
300 300
301 importJSON: { 301 importJSON: {
302 value: function(jObj) { 302 value: function(jObj) {
303 this._xOffset = jObj.xoff; 303 this._xOffset = jObj.xoff;
304 this._yOffset = jObj.yoff; 304 this._yOffset = jObj.yoff;
305 this._width = jObj.width; 305 this._width = jObj.width;
306 this._height = jObj.height; 306 this._height = jObj.height;
307 this._strokeWidth = jObj.strokeWidth; 307 this._strokeWidth = jObj.strokeWidth;
308 this._strokeColor = jObj.strokeColor; 308 this._strokeColor = jObj.strokeColor;
309 this._fillColor = jObj.fillColor; 309 this._fillColor = jObj.fillColor;
310 this._tlRadius = jObj.tlRadius; 310 this._tlRadius = jObj.tlRadius;
311 this._trRadius = jObj.trRadius; 311 this._trRadius = jObj.trRadius;
312 this._blRadius = jObj.blRadius; 312 this._blRadius = jObj.blRadius;
313 this._brRadius = jObj.brRadius; 313 this._brRadius = jObj.brRadius;
314 this._innerRadius = jObj.innerRadius; 314 this._innerRadius = jObj.innerRadius;
315 this._strokeStyle = jObj.strokeStyle; 315 this._strokeStyle = jObj.strokeStyle;
316 var strokeMaterialName = jObj.strokeMat; 316 var strokeMaterialName = jObj.strokeMat;
317 var fillMaterialName = jObj.fillMat; 317 var fillMaterialName = jObj.fillMat;
318 318
319 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ).dup(); 319 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ).dup();
320 if (!strokeMat) { 320 if (!strokeMat) {
@@ -322,8 +322,8 @@ exports.Rectangle = Object.create(GeomObj, {
322 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); 322 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
323 } 323 }
324 this._strokeMaterial = strokeMat; 324 this._strokeMaterial = strokeMat;
325 if (this._strokeMaterial.hasProperty( 'color' )) 325 if (this._strokeMaterial.hasProperty( 'color' ))
326 this._strokeMaterial.setProperty( 'color', this._strokeColor ); 326 this._strokeMaterial.setProperty( 'color', this._strokeColor );
327 327
328 var fillMat = MaterialsModel.getMaterial( fillMaterialName ).dup(); 328 var fillMat = MaterialsModel.getMaterial( fillMaterialName ).dup();
329 if (!fillMat) { 329 if (!fillMat) {
@@ -331,8 +331,8 @@ exports.Rectangle = Object.create(GeomObj, {
331 fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); 331 fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
332 } 332 }
333 this._fillMaterial = fillMat; 333 this._fillMaterial = fillMat;
334 if (this._fillMaterial.hasProperty( 'color' )) 334 if (this._fillMaterial.hasProperty( 'color' ))
335 this._fillMaterial.setProperty( 'color', this._fillColor ); 335 this._fillMaterial.setProperty( 'color', this._fillColor );
336 336
337 this.importMaterialsJSON( jObj.materials ); 337 this.importMaterialsJSON( jObj.materials );
338 } 338 }
@@ -409,7 +409,7 @@ exports.Rectangle = Object.create(GeomObj, {
409 // stroke 409 // stroke
410 var strokeMaterial = this.makeStrokeMaterial(); 410 var strokeMaterial = this.makeStrokeMaterial();
411 var strokePrim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial); 411 var strokePrim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial);
412 strokeMaterial.fitToPrimitive( strokePrim ); 412 strokeMaterial.fitToPrimitive( strokePrim );
413 this._primArray.push( strokePrim ); 413 this._primArray.push( strokePrim );
414 this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); 414 this._materialNodeArray.push( strokeMaterial.getMaterialNode() );
415 415
@@ -423,7 +423,7 @@ exports.Rectangle = Object.create(GeomObj, {
423 var fillMaterial = this.makeFillMaterial(); 423 var fillMaterial = this.makeFillMaterial();
424 //console.log( "fillMaterial: " + fillMaterial.getName() ); 424 //console.log( "fillMaterial: " + fillMaterial.getName() );
425 var fillPrim = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial); 425 var fillPrim = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial);
426 fillMaterial.fitToPrimitive( fillPrim ); 426 fillMaterial.fitToPrimitive( fillPrim );
427 this._primArray.push( fillPrim ); 427 this._primArray.push( fillPrim );
428 this._materialNodeArray.push( fillMaterial.getMaterialNode() ); 428 this._materialNodeArray.push( fillMaterial.getMaterialNode() );
429 429
@@ -443,7 +443,7 @@ exports.Rectangle = Object.create(GeomObj, {
443 ctx.quadraticCurveTo( bPts[index][0], bPts[index][1], bPts[index+1][0], bPts[index+1][1] ); 443 ctx.quadraticCurveTo( bPts[index][0], bPts[index][1], bPts[index+1][0], bPts[index+1][1] );
444 index += 2; 444 index += 2;
445 } 445 }
446 } 446 }
447 }, 447 },
448 448
449 renderPath: { 449 renderPath: {
@@ -455,7 +455,7 @@ exports.Rectangle = Object.create(GeomObj, {
455 hw = 0.5*width, 455 hw = 0.5*width,
456 hh = 0.5*height; 456 hh = 0.5*height;
457 457
458 pt = [inset, inset]; // top left corner 458 pt = [inset, inset]; // top left corner
459 459
460 var tlRad = this._tlRadius; //top-left radius 460 var tlRad = this._tlRadius; //top-left radius