aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/rectangle.js
diff options
context:
space:
mode:
authorJohn Mayhew2012-04-02 16:28:39 -0700
committerJohn Mayhew2012-04-02 16:28:39 -0700
commitb4155fb4c33675a8a7cd37473513718043fdf0ba (patch)
tree3d8c802473f2395d53d599ec9d8b70b60a4db50c /js/lib/geom/rectangle.js
parent5ba9aeac94c86049423fd5d4b37b277263939c13 (diff)
parentc6de22bf42be90b403491b5f87b1818d9020310c (diff)
downloadninja-b4155fb4c33675a8a7cd37473513718043fdf0ba.tar.gz
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into WorkingBranch
Conflicts: js/helper-classes/RDGE/rdge-compiled.js js/helper-classes/RDGE/runtime/GLRuntime.js js/helper-classes/RDGE/src/core/script/MeshManager.js js/helper-classes/RDGE/src/core/script/engine.js js/helper-classes/RDGE/src/core/script/fx/ssao.js js/helper-classes/RDGE/src/core/script/init_state.js js/helper-classes/RDGE/src/core/script/run_state.js js/helper-classes/RDGE/src/core/script/scenegraphNodes.js js/helper-classes/RDGE/src/core/script/utilities.js js/helper-classes/RDGE/src/tools/compile-rdge-core.bat js/helper-classes/RDGE/src/tools/compile-rdge-core.sh js/helper-classes/RDGE/src/tools/rdge-compiled.js js/lib/drawing/world.js js/lib/rdge/materials/bump-metal-material.js js/lib/rdge/materials/deform-material.js js/lib/rdge/materials/flat-material.js js/lib/rdge/materials/fly-material.js js/lib/rdge/materials/julia-material.js js/lib/rdge/materials/keleidoscope-material.js js/lib/rdge/materials/linear-gradient-material.js js/lib/rdge/materials/mandel-material.js js/lib/rdge/materials/plasma-material.js js/lib/rdge/materials/pulse-material.js js/lib/rdge/materials/radial-blur-material.js js/lib/rdge/materials/radial-gradient-material.js js/lib/rdge/materials/relief-tunnel-material.js js/lib/rdge/materials/square-tunnel-material.js js/lib/rdge/materials/star-material.js js/lib/rdge/materials/taper-material.js js/lib/rdge/materials/tunnel-material.js js/lib/rdge/materials/twist-material.js js/lib/rdge/materials/twist-vert-material.js js/lib/rdge/materials/uber-material.js js/lib/rdge/materials/water-material.js js/lib/rdge/materials/z-invert-material.js js/preloader/Preloader.js
Diffstat (limited to 'js/lib/geom/rectangle.js')
-rwxr-xr-xjs/lib/geom/rectangle.js174
1 files changed, 150 insertions, 24 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js
index 98621a98..46876ba7 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,13 +70,13 @@ 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 }; 81 };
83 82
@@ -188,7 +187,8 @@ var Rectangle = function GLRectangle() {
188 /////////////////////////////////////////////////////////////////////// 187 ///////////////////////////////////////////////////////////////////////
189 // Methods 188 // Methods
190 /////////////////////////////////////////////////////////////////////// 189 ///////////////////////////////////////////////////////////////////////
191 this.export = function() { 190 /*
191 this.export = function() {
192 var rtnStr = "type: " + this.geomType() + "\n"; 192 var rtnStr = "type: " + this.geomType() + "\n";
193 193
194 ///////////////////////////////////////////////////////////////////////// 194 /////////////////////////////////////////////////////////////////////////
@@ -203,8 +203,20 @@ var Rectangle = function GLRectangle() {
203 rtnStr += "width: " + this._width + "\n"; 203 rtnStr += "width: " + this._width + "\n";
204 rtnStr += "height: " + this._height + "\n"; 204 rtnStr += "height: " + this._height + "\n";
205 rtnStr += "strokeWidth: " + this._strokeWidth + "\n"; 205 rtnStr += "strokeWidth: " + this._strokeWidth + "\n";
206 rtnStr += "strokeColor: " + String(this._strokeColor) + "\n"; 206
207 rtnStr += "fillColor: " + String(this._fillColor) + "\n"; 207 if(this._strokeColor.gradientMode) {
208 rtnStr += "strokeGradientMode: " + this._strokeColor.gradientMode + "\n";
209 rtnStr += "strokeColor: " + this.gradientToString(this._strokeColor.color) + "\n";
210 } else {
211 rtnStr += "strokeColor: " + String(this._strokeColor) + "\n";
212 }
213
214 if(this._fillColor.gradientMode) {
215 rtnStr += "fillGradientMode: " + this._fillColor.gradientMode + "\n";
216 rtnStr += "fillColor: " + this.gradientToString(this._fillColor.color) + "\n";
217 } else {
218 rtnStr += "fillColor: " + String(this._fillColor) + "\n";
219 }
208 rtnStr += "tlRadius: " + this._tlRadius + "\n"; 220 rtnStr += "tlRadius: " + this._tlRadius + "\n";
209 rtnStr += "trRadius: " + this._trRadius + "\n"; 221 rtnStr += "trRadius: " + this._trRadius + "\n";
210 rtnStr += "blRadius: " + this._blRadius + "\n"; 222 rtnStr += "blRadius: " + this._blRadius + "\n";
@@ -216,22 +228,70 @@ var Rectangle = function GLRectangle() {
216 if (this._strokeMaterial) { 228 if (this._strokeMaterial) {
217 rtnStr += this._strokeMaterial.getName(); 229 rtnStr += this._strokeMaterial.getName();
218 } else { 230 } else {
219 rtnStr += "flatMaterial"; 231 rtnStr += MaterialsModel.getDefaultMaterialName();
220 } 232 }
221
222 rtnStr += "\n"; 233 rtnStr += "\n";
223 234
224 rtnStr += "fillMat: "; 235 rtnStr += "fillMat: ";
225 if (this._fillMaterial) { 236 if (this._fillMaterial) {
226 rtnStr += this._fillMaterial.getName(); 237 rtnStr += this._fillMaterial.getName();
227 } else { 238 } else {
228 rtnStr += "flatMaterial"; 239 rtnStr += MaterialsModel.getDefaultMaterialName();
229 } 240 }
230
231 rtnStr += "\n"; 241 rtnStr += "\n";
232 242
243 rtnStr += this.exportMaterials();
244
233 return rtnStr; 245 return rtnStr;
234 }; 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 };
235 295
236 this.import = function( importStr ) { 296 this.import = function( importStr ) {
237 this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) ); 297 this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) );
@@ -244,9 +304,25 @@ var Rectangle = function GLRectangle() {
244 var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr ); 304 var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr );
245 var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr ); 305 var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr );
246 this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr ); 306 this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr );
247 this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" ); 307
248 this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" ); 308 if(importStr.indexOf("fillGradientMode: ") < 0) {
249 this._tlRadius = Number( this.getPropertyFromString( "tlRadius: ", importStr ) ); 309 this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" );
310 } else {
311 this._fillColor = {};
312 this._fillColor.gradientMode = this.getPropertyFromString( "fillGradientMode: ", importStr );
313 this._fillColor.color = this.stringToGradient(this.getPropertyFromString( "fillColor: ", importStr ));
314 }
315
316 if(importStr.indexOf("strokeGradientMode: ") < 0)
317 {
318 this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" );
319 } else {
320 this._strokeColor = {};
321 this._strokeColor.gradientMode = this.getPropertyFromString( "strokeGradientMode: ", importStr );
322 this._strokeColor.color = this.stringToGradient(this.getPropertyFromString( "strokeColor: ", importStr ));
323 }
324
325 this._tlRadius = Number( this.getPropertyFromString( "tlRadius: ", importStr ) );
250 this._trRadius = Number( this.getPropertyFromString( "trRadius: ", importStr ) ); 326 this._trRadius = Number( this.getPropertyFromString( "trRadius: ", importStr ) );
251 this._blRadius = Number( this.getPropertyFromString( "blRadius: ", importStr ) ); 327 this._blRadius = Number( this.getPropertyFromString( "blRadius: ", importStr ) );
252 this._brRadius = Number( this.getPropertyFromString( "brRadius: ", importStr ) ); 328 this._brRadius = Number( this.getPropertyFromString( "brRadius: ", importStr ) );
@@ -254,18 +330,18 @@ var Rectangle = function GLRectangle() {
254 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); 330 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName );
255 if (!strokeMat) { 331 if (!strokeMat) {
256 console.log( "object material not found in library: " + strokeMaterialName ); 332 console.log( "object material not found in library: " + strokeMaterialName );
257 strokeMat = MaterialsModel.exportFlatMaterial(); 333 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
258 } 334 }
259
260 this._strokeMaterial = strokeMat; 335 this._strokeMaterial = strokeMat;
261 336
262 var fillMat = MaterialsModel.getMaterial( fillMaterialName ); 337 var fillMat = MaterialsModel.getMaterial( fillMaterialName );
263 if (!fillMat) { 338 if (!fillMat) {
264 console.log( "object material not found in library: " + fillMaterialName ); 339 console.log( "object material not found in library: " + fillMaterialName );
265 fillMat = MaterialsModel.exportFlatMaterial(); 340 fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
266 } 341 }
267
268 this._fillMaterial = fillMat; 342 this._fillMaterial = fillMat;
343
344 this.importMaterials( importStr );
269 }; 345 };
270