aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/rectangle.js
diff options
context:
space:
mode:
authorhwc4872012-03-22 15:47:11 -0700
committerhwc4872012-03-22 15:47:11 -0700
commite927e4702d7dbd4a878f6979b3f56b46758f93de (patch)
treee6bb8951374a6504bd6c745ce7233da5cd4869dc /js/lib/geom/rectangle.js
parent00cd98e49c959906d7c44bb6adcdef1f3d5148ae (diff)
parent31e924e1b8b8da8342b3ff2341c8284915486c0b (diff)
downloadninja-e927e4702d7dbd4a878f6979b3f56b46758f93de.tar.gz
Merge branch 'integration' of github.com:ericmueller/ninja-internal into Textures
Diffstat (limited to 'js/lib/geom/rectangle.js')
-rwxr-xr-xjs/lib/geom/rectangle.js63
1 files changed, 53 insertions, 10 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js
index a47295e0..38e428bd 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 ///////////////////////////////////////////////////////////////////////
@@ -230,7 +227,7 @@ var Rectangle = function GLRectangle() {
230 if (this._strokeMaterial) { 227 if (this._strokeMaterial) {
231 rtnStr += this._strokeMaterial.getName(); 228 rtnStr += this._strokeMaterial.getName();
232 } else { 229 } else {
233 rtnStr += "flatMaterial"; 230 rtnStr += MaterialsModel.getDefaultMaterialName();
234 } 231 }
235 rtnStr += "\n"; 232 rtnStr += "\n";
236 233
@@ -238,7 +235,7 @@ var Rectangle = function GLRectangle() {
238 if (this._fillMaterial) { 235 if (this._fillMaterial) {
239 rtnStr += this._fillMaterial.getName(); 236 rtnStr += this._fillMaterial.getName();
240 } else { 237 } else {
241 rtnStr += "flatMaterial"; 238 rtnStr += MaterialsModel.getDefaultMaterialName();
242 } 239 }
243 rtnStr += "\n"; 240 rtnStr += "\n";
244 241
@@ -247,6 +244,53 @@ var Rectangle = function GLRectangle() {
247 return rtnStr; 244 return rtnStr;
248 }; 245 };
249 246
247 // JSON export
248 this.exportJSON = function()
249 {
250 var jObj =
251 {
252 'type' : this.geomType(),
253 'xoff' : this._xOffset,
254 'yoff' : this._yOffset,
255 'width' : this._width,
256 'height' : this._height,
257 'strokeWidth' : this._strokeWidth,
258 'strokeColor' : this._strokeColor,
259 'fillColor' : this._fillColor,
260 'tlRadius' : this._tlRadius,
261 'trRadius' : this._trRadius,
262 'blRadius' : this._blRadius,
263 'brRadius' : this._brRadius,
264 'innerRadius' : this._innerRadius,
265 'strokeStyle' : this._strokeStyle,
266 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(),
267 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(),
268 'materials' : this.exportMaterialsJSON()
269 };
270
271 return jObj;
272 };
273
274 this.importJSON = function( jObj )
275 {
276 this._xOffset = jObj.xoff;
277 this._yOffset = jObj.yoff;
278 this._width = jObj.width;
279 this._height = jObj.height;
280 this._strokeWidth = jObj.strokeWidth;
281 this._strokeColor = jObj.strokeColor;
282 this._fillColor = jObj.fillColor;
283 this._tlRadius = jObj.tlRadius;
284 this._trRadius = jObj.trRadius;
285 this._blRadius = jObj.blRadius;
286 this._brRadius = jObj.brRadius;
287 this._innerRadius = jObj.innerRadius;
288 this._strokeStyle = jObj.strokeStyle;
289 var strokeMaterialName = jObj.strokeMat;
290 var fillMaterialName = jObj.fillMat;
291 this.importMaterialsJSON( jObj.materials );
292 };
293
250 this.import = function( importStr ) { 294 this.import = function( importStr ) {
251 this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) ); 295 this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) );
252 this._yOffset = Number( this.getPropertyFromString( "yoff: ", importStr ) ); 296 this._yOffset = Number( this.getPropertyFromString( "yoff: ", importStr ) );
@@ -284,15 +328,14 @@ var Rectangle = function GLRectangle() {
284 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); 328 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName );
285 if (!strokeMat) { 329 if (!strokeMat) {
286 console.log( "object material not found in library: " + strokeMaterialName ); 330 console.log( "object material not found in library: " + strokeMaterialName );
287 strokeMat = MaterialsModel.exportFlatMaterial(); 331 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
288 } 332 }
289
290 this._strokeMaterial = strokeMat; 333 this._strokeMaterial = strokeMat;
291 334
292 var fillMat = MaterialsModel.getMaterial( fillMaterialName ); 335 var fillMat = MaterialsModel.getMaterial( fillMaterialName );
293 if (!fillMat) { 336 if (!fillMat) {
294 console.log( "object material not found in library: " + fillMaterialName ); 337 console.log( "object material not found in library: " + fillMaterialName );
295 fillMat = MaterialsModel.exportFlatMaterial(); 338 fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
296 } 339 }
297 this._fillMaterial = fillMat; 340 this._fillMaterial = fillMat;
298 341