aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/rectangle.js
diff options
context:
space:
mode:
authorEric Guzman2012-03-27 10:22:42 -0700
committerEric Guzman2012-03-27 10:22:42 -0700
commit309b201017da2a4094df4f06adeeff9d396b193a (patch)
tree92257b32855bcd31dd74967b085a6632fd7dbe9b /js/lib/geom/rectangle.js
parentda03585a0b03220281f6d54d9acf0ae0fafaef16 (diff)
parent309dde5a8c4599cef6a1052c1ff9ee1ad8ec5858 (diff)
downloadninja-309b201017da2a4094df4f06adeeff9d396b193a.tar.gz
Merge branch 'refs/heads/master' into PresetsPI
Diffstat (limited to 'js/lib/geom/rectangle.js')
-rwxr-xr-xjs/lib/geom/rectangle.js67
1 files changed, 56 insertions, 11 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js
index a47295e0..e511d5f4 100755
--- a/js/lib/geom/rectangle.js
+++ b/js/lib/geom/rectangle.js
@@ -7,7 +7,6 @@
7var GeomObj = require("js/lib/geom/geom-obj").GeomObj; 7var GeomObj = require("js/lib/geom/geom-obj").GeomObj;
8var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; 8var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive;
9var MaterialsModel = require("js/models/materials-model").MaterialsModel; 9var MaterialsModel = require("js/models/materials-model").MaterialsModel;
10var FlatMaterial = require("js/lib/rdge/materials/flat-material").FlatMaterial;
11 /////////////////////////////////////////////////////////////////////// 10 ///////////////////////////////////////////////////////////////////////
12// Class GLRectangle 11// Class GLRectangle
13// GL representation of a rectangle. 12// GL representation of a rectangle.
@@ -71,16 +70,14 @@ var Rectangle = function GLRectangle() {
71 if(strokeMaterial) { 70 if(strokeMaterial) {
72 this._strokeMaterial = strokeMaterial; 71 this._strokeMaterial = strokeMaterial;
73 } else { 72 } else {
74 this._strokeMaterial = MaterialsModel.exportFlatMaterial(); 73 this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
75 } 74 }
76 75
77 if(fillMaterial) { 76 if(fillMaterial) {
78 this._fillMaterial = fillMaterial; 77 this._fillMaterial = fillMaterial;
79 } else { 78 } else {
80 this._fillMaterial = MaterialsModel.exportFlatMaterial(); 79 this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
81 } 80 }
82
83 this.exportMaterials();
84 }; 81 };
85 82
86 /////////////////////////////////////////////////////////////////////// 83 ///////////////////////////////////////////////////////////////////////
@@ -190,7 +187,8 @@ var Rectangle = function GLRectangle() {
190 /////////////////////////////////////////////////////////////////////// 187 ///////////////////////////////////////////////////////////////////////
191 // Methods 188 // Methods
192 /////////////////////////////////////////////////////////////////////// 189 ///////////////////////////////////////////////////////////////////////
193 this.export = function() { 190 /*
191 this.export = function() {
194 var rtnStr = "type: " + this.geomType() + "\n"; 192 var rtnStr = "type: " + this.geomType() + "\n";
195 193
196 ///////////////////////////////////////////////////////////////////////// 194 /////////////////////////////////////////////////////////////////////////
@@ -230,7 +228,7 @@ var Rectangle = function GLRectangle() {
230 if (this._strokeMaterial) { 228 if (this._strokeMaterial) {
231 rtnStr += this._strokeMaterial.getName(); 229 rtnStr += this._strokeMaterial.getName();
232 } else { 230 } else {
233 rtnStr += "flatMaterial"; 231 rtnStr += MaterialsModel.getDefaultMaterialName();
234 } 232 }
235 rtnStr += "\n"; 233 rtnStr += "\n";
236 234
@@ -238,7 +236,7 @@ var Rectangle = function GLRectangle() {
238 if (this._fillMaterial) { 236 if (this._fillMaterial) {
239 rtnStr += this._fillMaterial.getName(); 237 rtnStr += this._fillMaterial.getName();
240 } else { 238 } else {
241 rtnStr += "flatMaterial"; 239 rtnStr += MaterialsModel.getDefaultMaterialName();
242 } 240 }
243 rtnStr += "\n"; 241 rtnStr += "\n";
244 242
@@ -246,6 +244,54 @@ var Rectangle = function GLRectangle() {
246 244
247 return rtnStr; 245 return rtnStr;
248 }; 246 };
247 */
248
249 // JSON export
250 this.exportJSON = function()
251 {
252 var jObj =
253 {
254 'type' : this.geomType(),
255 'xoff' : this._xOffset,
256 'yoff' : this._yOffset,
257 'width' : this._width,
258 'height' : this._height,
259 'strokeWidth' : this._strokeWidth,
260 'strokeColor' : this._strokeColor,
261 'fillColor' : this._fillColor,
262 'tlRadius' : this._tlRadius,
263 'trRadius' : this._trRadius,
264 'blRadius' : this._blRadius,
265 'brRadius' : this._brRadius,
266 'innerRadius' : this._innerRadius,
267 'strokeStyle' : this._strokeStyle,
268 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(),
269 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(),
270 'materials' : this.exportMaterialsJSON()
271 };
272
273 return jObj;
274 };
275
276 this.importJSON = function( jObj )
277 {
278 this._xOffset = jObj.xoff;
279 this._yOffset = jObj.yoff;
280 this._width = jObj.width;
281 this._height = jObj.height;
282 this._strokeWidth = jObj.strokeWidth;
283 this._strokeColor = jObj.strokeColor;
284 this._fillColor = jObj.fillColor;
285 this._tlRadius = jObj.tlRadius;
286 this._trRadius = jObj.trRadius;
287 this._blRadius = jObj.blRadius;
288 this._brRadius = jObj.brRadius;
289 this._innerRadius = jObj.innerRadius;
290 this._strokeStyle = jObj.strokeStyle;
291 var strokeMaterialName = jObj.strokeMat;
292 var fillMaterialName = jObj.fillMat;
293 this.importMaterialsJSON( jObj.materials );
294 };
249 295
250 this.import = function( importStr ) { 296 this.import = function( importStr ) {
251 this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) ); 297 this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) );
@@ -284,15 +330,14 @@ var Rectangle = function GLRectangle() {
284 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); 330 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName );
285 if (!strokeMat) { 331 if (!strokeMat) {
286 console.log( "object material not found in library: " + strokeMaterialName ); 332 console.log( "object material not found in library: " + strokeMaterialName );
287 strokeMat = MaterialsModel.exportFlatMaterial(); 333 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
288 } 334 }
289
290 this._strokeMaterial = strokeMat; 335 this._strokeMaterial = strokeMat;
291 336
292 var fillMat = MaterialsModel.getMaterial( fillMaterialName ); 337 var fillMat = MaterialsModel.getMaterial( fillMaterialName );
293 if (!fillMat) { 338 if (!fillMat) {
294 console.log( "object material not found in library: " + fillMaterialName ); 339 console.log( "object material not found in library: " + fillMaterialName );
295 fillMat = MaterialsModel.exportFlatMaterial(); 340 fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
296 } 341 }
297 this._fillMaterial = fillMat; 342 this._fillMaterial = fillMat;
298 343