aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/GLRectangle.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/GLRectangle.js')
-rw-r--r--js/helper-classes/RDGE/GLRectangle.js215
1 files changed, 74 insertions, 141 deletions
diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js
index 1334d7e6..2899e476 100644
--- a/js/helper-classes/RDGE/GLRectangle.js
+++ b/js/helper-classes/RDGE/GLRectangle.js
@@ -33,14 +33,6 @@ function GLRectangle()
33 33
34 this._strokeWidth = 0.25; 34 this._strokeWidth = 0.25;
35 35
36 // stroke and fill colors
37 this._strokeColor;
38 this._fillColor;
39
40 // stroke and fill materials
41 this._fillMaterial;
42 this._strokeMaterial;
43
44 this._strokeStyle = "Solid"; 36 this._strokeStyle = "Solid";
45 this.init = function(world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor, 37 this.init = function(world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor,
46 tlRadius, trRadius, blRadius, brRadius, strokeMaterial, fillMaterial, strokeStyle) 38 tlRadius, trRadius, blRadius, brRadius, strokeMaterial, fillMaterial, strokeStyle)
@@ -80,13 +72,14 @@ function GLRectangle()
80 this._materialSpecular = [0.4, 0.4, 0.4, 1.0]; 72 this._materialSpecular = [0.4, 0.4, 0.4, 1.0];
81 73
82 if(strokeMaterial) 74 if(strokeMaterial)
83 {
84 this._strokeMaterial = strokeMaterial; 75 this._strokeMaterial = strokeMaterial;
85 } 76 else
77 this._strokeMaterial = new FlatMaterial();
78
86 if(fillMaterial) 79 if(fillMaterial)
87 {
88 this._fillMaterial = fillMaterial; 80 this._fillMaterial = fillMaterial;
89 } 81 else
82 this._fillMaterial = new FlatMaterial();
90 } 83 }
91 84
92 /////////////////////////////////////////////////////////////////////// 85 ///////////////////////////////////////////////////////////////////////
@@ -185,8 +178,8 @@ function GLRectangle()
185 this._strokeWidth = Number( this.getPropertyFromString( "strokeWidth: ", importStr ) ); 178 this._strokeWidth = Number( this.getPropertyFromString( "strokeWidth: ", importStr ) );
186 this._innerRadius = Number( this.getPropertyFromString( "innerRadius: ", importStr ) ); 179 this._innerRadius = Number( this.getPropertyFromString( "innerRadius: ", importStr ) );
187 this._strokeStyle = Number( this.getPropertyFromString( "strokeStyle: ", importStr ) ); 180 this._strokeStyle = Number( this.getPropertyFromString( "strokeStyle: ", importStr ) );
188 var strokeMaterialName = Number( this.getPropertyFromString( "strokeMat: ", importStr ) ); 181 var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr );
189 var fillMaterialName = Number( this.getPropertyFromString( "fillMat: ", importStr ) ); 182 var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr );
190 this._strokeStyle = Number( this.getPropertyFromString( "strokeColor: ", importStr ) ); 183 this._strokeStyle = Number( this.getPropertyFromString( "strokeColor: ", importStr ) );
191 this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" ); 184 this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" );
192 this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" ); 185 this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" );
@@ -279,8 +272,8 @@ function GLRectangle()
279 272
280 // stroke 273 // stroke
281 var strokeMaterial = this.makeStrokeMaterial(); 274 var strokeMaterial = this.makeStrokeMaterial();
282 prim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial) 275 var strokePrim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial);
283 this._primArray.push( prim ); 276 this._primArray.push( strokePrim );
284 this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); 277 this._materialNodeArray.push( strokeMaterial.getMaterialNode() );
285 278
286 // fill 279 // fill
@@ -291,60 +284,13 @@ function GLRectangle()
291 xFill -= strokeSize; 284 xFill -= strokeSize;
292 yFill -= strokeSize; 285 yFill -= strokeSize;
293 var fillMaterial = this.makeFillMaterial(); 286 var fillMaterial = this.makeFillMaterial();
294 prim = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial) 287 var fillPrim = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial);
295 this._primArray.push( prim ); 288 this._primArray.push( fillPrim );
296 this._materialNodeArray.push( fillMaterial.getMaterialNode() ); 289 this._materialNodeArray.push( fillMaterial.getMaterialNode() );
297 290
298 world.updateObject(this); 291 world.updateObject(this);
299 } 292 }
300 293
301 this.makeStrokeMaterial = function()
302 {
303 var strokeMaterial;
304 if (this.getStrokeMaterial())
305 strokeMaterial = this.getStrokeMaterial().dup();
306 else
307 strokeMaterial = new FlatMaterial();
308
309 if (strokeMaterial)
310 {
311 strokeMaterial.init( this.getWorld() );
312 if(this._strokeColor)
313 {
314 strokeMaterial.setProperty("color", this._strokeColor);
315 }
316 }
317
318 this._materialArray.push( strokeMaterial );
319 this._materialTypeArray.push( "stroke" );
320
321 return strokeMaterial;
322 }
323
324 this.makeFillMaterial = function()
325 {
326 var fillMaterial;
327 if (this.getFillMaterial())
328 fillMaterial = this.getFillMaterial().dup();
329 else
330 fillMaterial = new FlatMaterial();
331
332 if (fillMaterial)
333 {
334 fillMaterial.init( this.getWorld() );
335 //if(!this.getFillMaterial() && this._fillColor)
336 if (this._fillColor)
337 {
338 fillMaterial.setProperty("color", this._fillColor);
339 }
340 }
341
342 this._materialArray.push( fillMaterial );
343 this._materialTypeArray.push( "fill" );
344
345 return fillMaterial;
346 }
347
348 this.renderQuadraticBezier = function( bPts, ctx ) 294 this.renderQuadraticBezier = function( bPts, ctx )
349 { 295 {
350 if (!bPts) return; 296 if (!bPts) return;
@@ -367,72 +313,71 @@ function GLRectangle()
367 var width = Math.round(this.getWidth()), 313 var width = Math.round(this.getWidth()),
368 height = Math.round(this.getHeight()); 314 height = Math.round(this.getHeight());
369 315
370 // get the top left point
371 pt = [inset, inset]; // top left corner 316 pt = [inset, inset]; // top left corner
372 rad = this.getTLRadius() - inset;
373 if (rad < 0) rad = 0;
374 pt[1] += rad;
375 if (MathUtils.fpSign(rad) == 0) pt[1] = 0;
376 ctx.moveTo( pt[0], pt[1] );
377
378 // get the bottom left point
379 pt = [inset, height - inset];
380 rad = this.getBLRadius() - inset;
381 if (rad < 0) rad = 0;
382 pt[1] -= rad;
383 ctx.lineTo( pt[0], pt[1] );
384
385 // get the bottom left arc
386 if (MathUtils.fpSign(rad) > 0)
387 {
388 ctr = [ this.getBLRadius(), height - this.getBLRadius() ];
389 //this.renderQuadraticBezier( MathUtils.circularArcToBezier( ctr, pt, -0.5*Math.PI ), ctx );
390 ctx.arc( ctr[0], ctr[1], rad, Math.PI, 0.5*Math.PI, true );
391 }
392
393 // do the bottom of the rectangle
394 pt = [width - inset, height - inset];
395 rad = this.getBRRadius() - inset;
396 if (rad < 0) rad = 0;
397 pt[0] -= rad;
398 ctx.lineTo( pt[0], pt[1] );
399 317
400 // get the bottom right arc 318 var tlRad = this._tlRadius; //top-left radius
401 if (MathUtils.fpSign(rad) > 0) 319 var trRad = this._trRadius;
402 { 320 var blRad = this._blRadius;
403 ctr = [width - this.getBRRadius(), height - this.getBRRadius()]; 321 var brRad = this._brRadius;
404 //this.renderQuadraticBezier( MathUtils.circularArcToBezier( ctr, pt, -0.5*Math.PI ), ctx );
405 ctx.arc( ctr[0], ctr[1], rad, 0.5*Math.PI, 0.0, true );
406 }
407 322
408 // get the right of the rectangle 323 if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0))
409 pt = [width - inset, inset];
410 rad = this.getTRRadius() - inset;
411 if (rad < 0) rad = 0;
412 pt[1] += rad;
413 ctx.lineTo( pt[0], pt[1] );
414
415 // do the top right corner
416 if (MathUtils.fpSign(rad) > 0)
417 { 324 {
418 ctr = [width - this.getTRRadius(), this.getTRRadius()]; 325 ctx.rect(pt[0], pt[1], width - 2*inset, height - 2*inset);
419 //this.renderQuadraticBezier( MathUtils.circularArcToBezier( ctr, pt, -0.5*Math.PI ), ctx );
420 ctx.arc( ctr[0], ctr[1], rad, 0.0, -0.5*Math.PI, true );
421 } 326 }
422 327 else
423 // do the top of the rectangle
424 pt = [inset, inset]
425 rad = this.getTLRadius() - inset;
426 if (rad < 0) rad = 0;
427 pt[0] += rad;
428 ctx.lineTo( pt[0], pt[1] );
429
430 // do the top left corner
431 if (MathUtils.fpSign(rad) > 0)
432 { 328 {
433 ctr = [this.getTLRadius(), this.getTLRadius()]; 329 // get the top left point
434 //this.renderQuadraticBezier( MathUtils.circularArcToBezier( ctr, pt, -0.5*Math.PI ), ctx ); 330 rad = tlRad - inset;
435 ctx.arc( ctr[0], ctr[1], rad, -0.5*Math.PI, Math.PI, true ); 331 if (rad < 0) rad = 0;
332 pt[1] += rad;
333 if (MathUtils.fpSign(rad) == 0) pt[1] = inset;
334 ctx.moveTo( pt[0], pt[1] );
335