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.js102
1 files changed, 90 insertions, 12 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js
index 81b385b3..6abaef2f 100755
--- a/js/lib/geom/rectangle.js
+++ b/js/lib/geom/rectangle.js
@@ -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";
@@ -244,9 +256,25 @@ var Rectangle = function GLRectangle() {
244 var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr ); 256 var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr );
245 var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr ); 257 var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr );
246 this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr ); 258 this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr );
247 this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" ); 259
248 this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" ); 260 if(importStr.indexOf("fillGradientMode: ") < 0) {
249 this._tlRadius = Number( this.getPropertyFromString( "tlRadius: ", importStr ) ); 261 this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" );
262 } else {
263 this._fillColor = {};
264 this._fillColor.gradientMode = this.getPropertyFromString( "fillGradientMode: ", importStr );
265 this._fillColor.color = this.stringToGradient(this.getPropertyFromString( "fillColor: ", importStr ));
266 }
267
268 if(importStr.indexOf("strokeGradientMode: ") < 0)
269 {
270 this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" );
271 } else {
272 this._strokeColor = {};
273 this._strokeColor.gradientMode = this.getPropertyFromString( "strokeGradientMode: ", importStr );
274 this._strokeColor.color = this.stringToGradient(this.getPropertyFromString( "strokeColor: ", importStr ));
275 }
276
277 this._tlRadius = Number( this.getPropertyFromString( "tlRadius: ", importStr ) );
250 this._trRadius = Number( this.getPropertyFromString( "trRadius: ", importStr ) ); 278 this._trRadius = Number( this.getPropertyFromString( "trRadius: ", importStr ) );
251 this._blRadius = Number( this.getPropertyFromString( "blRadius: ", importStr ) ); 279 this._blRadius = Number( this.getPropertyFromString( "blRadius: ", importStr ) );
252 this._brRadius = Number( this.getPropertyFromString( "brRadius: ", importStr ) ); 280 this._brRadius = Number( this.getPropertyFromString( "brRadius: ", importStr ) );
@@ -459,15 +487,44 @@ var Rectangle = function GLRectangle() {
459 var lw = this._strokeWidth; 487 var lw = this._strokeWidth;
460 var w = world.getViewportWidth(), 488 var w = world.getViewportWidth(),
461 h = world.getViewportHeight(); 489 h = world.getViewportHeight();
462 490
491 var c,
492 inset,
493 gradient,
494 colors,
495 len,
496 n,
497 position,
498 cs;
463 // render the fill 499 // render the fill
464 ctx.beginPath(); 500 ctx.beginPath();
465 if (this._fillColor) { 501 if (this._fillColor) {
466 var c = "rgba(" + 255*this._fillColor[0] + "," + 255*this._fillColor[1] + "," + 255*this._fillColor[2] + "," + this._fillColor[3] + ")"; 502 inset = Math.ceil( lw ) + 0.5;
467 ctx.fillStyle = c; 503
504 if(this._fillColor.gradientMode) {
505 if(this._fillColor.gradientMode === "radial") {
506 gradient = ctx.createRadialGradient(w/2, h/2, 0, w/2, h/2, Math.max(w/2, h/2)-inset);
507 } else {
508 gradient = ctx.createLinearGradient(inset, h/2, w-2*inset, h/2);
509 }
510 colors = this._fillColor.color;
511
512 len = colors.length;
513
514 for(n=0; n<len; n++) {
515 position = colors[n].position/100;
516 cs = colors[n].value;
517 gradient.addColorStop(position, "rgba(" + cs.r + "," + cs.g + "," + cs.b + "," + cs.a + ")");
518 }
519
520 ctx.fillStyle = gradient;
521
522 } else {
523 c = "rgba(" + 255*this._fillColor[0] + "," + 255*this._fillColor[1] + "," + 255*this._fillColor[2] + "," + this._fillColor[3] + ")";
524 ctx.fillStyle = c;
525 }
468 526
469 ctx.lineWidth = lw; 527 ctx.lineWidth = lw;
470 var inset = Math.ceil( lw ) + 0.5;
471 this.renderPath( inset, ctx ); 528 this.renderPath( inset, ctx );
472 ctx.fill(); 529 ctx.fill();
473 ctx.closePath(); 530 ctx.closePath();
@@ -476,11 +533,32 @@ var Rectangle = function GLRectangle() {
476 // render the stroke 533 // render the stroke
477 ctx.beginPath(); 534 ctx.beginPath();
478 if (this._strokeColor) { 535 if (this._strokeColor) {
479 var c = "rgba(" + 255*this._strokeColor[0] + "," + 255*this._strokeColor[1] + "," + 255*this._strokeColor[2] + "," + this._strokeColor[3] + ")"; 536 inset = Math.ceil( 0.5*lw ) + 0.5;
480 ctx.strokeStyle = c; 537
538 if(this._strokeColor.gradientMode) {
539 if(this._strokeColor.gradientMode === "radial") {
540 gradient = ctx.createRadialGradient(w/2, h/2, Math.min(h/2, w/2)-inset, w/2, h/2, Math.max(h/2, w/2));
541 } else {
542 gradient = ctx.createLinearGradient(0, h/2, w, h/2);
543 }
544 colors = this._strokeColor.color;
545
546 len = colors.length;
547
548 for(n=0; n<len; n++) {
549 position = colors[n].position/100;
550 cs = colors[n].value;
551 gradient.addColorStop(position, "rgba(" + cs.r + "," + cs.g + "," + cs.b + "," + cs.a + ")");
552 }
553
554 ctx.strokeStyle = gradient;
555
556 } else {
557 c = "rgba(" + 255*this._strokeColor[0] + "," + 255*this._strokeColor[1] + "," + 255*this._strokeColor[2] + "," + this._strokeColor[3] + ")";
558 ctx.strokeStyle = c;
559 }
481 560
482 ctx.lineWidth = lw; 561 ctx.lineWidth = lw;
483 var inset = Math.ceil( 0.5*lw ) + 0.5;
484 this.renderPath( inset, ctx ); 562 this.renderPath( inset, ctx );
485 ctx.stroke(); 563 ctx.stroke();
486 ctx.closePath(); 564 ctx.closePath();