aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/rectangle.js
diff options
context:
space:
mode:
authorhwc4872012-05-22 16:40:42 -0700
committerhwc4872012-05-22 16:40:42 -0700
commit08851078e89e9d4cb8fa341fa697a91be8de8ab9 (patch)
treefee8c0d38c1c540ef00c33e728346d765a4e699c /js/lib/geom/rectangle.js
parent50ede4afa801f53caff7939dad0408f9a0a8b744 (diff)
parent862ee363584dfba4bdd9abacbc3a3244c7ec66b5 (diff)
downloadninja-08851078e89e9d4cb8fa341fa697a91be8de8ab9.tar.gz
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into Textures
Conflicts: js/lib/geom/shape-primitive.js js/lib/rdge/materials/linear-gradient-material.js
Diffstat (limited to 'js/lib/geom/rectangle.js')
-rwxr-xr-xjs/lib/geom/rectangle.js190
1 files changed, 94 insertions, 96 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js
index ab0d7022..42d51e74 100755
--- a/js/lib/geom/rectangle.js
+++ b/js/lib/geom/rectangle.js
@@ -59,8 +59,6 @@ exports.Rectangle = Object.create(GeomObj, {
59 this._strokeStyle = strokeStyle; 59 this._strokeStyle = strokeStyle;
60 60
61 this._matrix = Matrix.I(4); 61 this._matrix = Matrix.I(4);
62 //this._matrix[12] = xoffset;
63 //this._matrix[13] = yoffset;
64 } 62 }
65 63
66 // the overall radius includes the fill and the stroke. separate the two based on the stroke width 64 // the overall radius includes the fill and the stroke. separate the two based on the stroke width
@@ -127,7 +125,6 @@ exports.Rectangle = Object.create(GeomObj, {
127 this._fillMaterial = m; 125 this._fillMaterial = m;
128 } 126 }
129 }, 127 },
130
131 /////////////////////////////////////////////////////////////////////// 128 ///////////////////////////////////////////////////////////////////////
132 // update the "color of the material 129 // update the "color of the material
133 getFillColor: { 130 getFillColor: {
@@ -141,7 +138,6 @@ exports.Rectangle = Object.create(GeomObj, {
141// this._fillColor = c; 138// this._fillColor = c;
142// } 139// }
143// }, 140// },
144
145 getStrokeColor: { 141 getStrokeColor: {
146 value: function() { 142 value: function() {
147 return this._strokeColor; 143 return this._strokeColor;
@@ -382,6 +378,7 @@ exports.Rectangle = Object.create(GeomObj, {
382 // stroke 378 // stroke
383 var strokeMaterial = this.makeStrokeMaterial(); 379 var strokeMaterial = this.makeStrokeMaterial();
384 var strokePrim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial); 380 var strokePrim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial);
381 strokeMaterial.fitToPrimitive( strokePrim );
385 this._primArray.push( strokePrim ); 382 this._primArray.push( strokePrim );
386 this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); 383 this._materialNodeArray.push( strokeMaterial.getMaterialNode() );
387 384
@@ -395,6 +392,7 @@ exports.Rectangle = Object.create(GeomObj, {
395 var fillMaterial = this.makeFillMaterial(); 392 var fillMaterial = this.makeFillMaterial();
396 //console.log( "fillMaterial: " + fillMaterial.getName() ); 393 //console.log( "fillMaterial: " + fillMaterial.getName() );
397 var fillPrim = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial); 394 var fillPrim = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial);
395 fillMaterial.fitToPrimitive( fillPrim );
398 this._primArray.push( fillPrim ); 396 this._primArray.push( fillPrim );
399 this._materialNodeArray.push( fillMaterial.getMaterialNode() ); 397 this._materialNodeArray.push( fillMaterial.getMaterialNode() );
400 398
@@ -512,98 +510,98 @@ exports.Rectangle = Object.create(GeomObj, {
512 } 510 }
513 }, 511 },
514 512
515 render: { 513 render: {
516 value: function() { 514 value: function() {
517 // get the world 515 // get the world
518 var world = this.getWorld(); 516 var world = this.getWorld();
519 if (!world) throw( "null world in rectangle render" ); 517 if (!world) throw( "null world in rectangle render" );
520 518
521 // get the context 519 // get the context
522 var ctx = world.get2DContext(); 520 var ctx = world.get2DContext();
523 if (!ctx) return; 521 if (!ctx) return;
524 522
525 // get some dimensions 523 // get some dimensions
526 var lw = this._strokeWidth; 524 var lw = this._strokeWidth;
527 var w = world.getViewportWidth(), 525 var w = world.getViewportWidth(),
528 h = world.getViewportHeight(); 526 h = world.getViewportHeight();
529 527
530 var c, 528 var c,
531 inset, 529 inset,
532 gradient, 530 gradient,
533 colors, 531 colors,
534 len, 532 len,
535 n, 533 n,
536 position, 534 position,
537 cs; 535 cs;
538 // render the fill 536 // render the fill
539 ctx.beginPath(); 537 ctx.beginPath();
540 if (this._fillColor) { 538 if (this._fillColor) {
541 inset = Math.ceil( lw ) - 0.5; 539 inset = Math.ceil( lw ) - 0.5;
542 540
543 if(this._fillColor.gradientMode) { 541 if(this._fillColor.gradientMode) {
544 if(this._fillColor.gradientMode === "radial") { 542 if(this._fillColor.gradientMode === "radial") {
545 gradient = ctx.createRadialGradient(w/2, h/2, 0, w/2, h/2, Math.max(w, h)/2); 543 var ww = w - 2*lw, hh = h - 2*lw;
546 } else { 544 gradient = ctx.createRadialGradient(w/2, h/2, 0, w/2, h/2, Math.max(ww, hh)/2);
547 gradient = ctx.createLinearGradient(inset/2, h/2, w-inset, h/2); 545 } else {
548 } 546 gradient = ctx.createLinearGradient(inset, h/2, w-inset, h/2);
549 colors = this._fillColor.color; 547 }
550 548 colors = this._fillColor.color;
551 len = colors.length; 549
552 550 len = colors.length;
553 for(n=0; n<len; n++) { 551
554 position = colors[n].position/100; 552 for(n=0; n<len; n++) {
555 cs = colors[n].value; 553 position = colors[n].position/100;
556 gradient.addColorStop(position, "rgba(" + cs.r + "," + cs.g + "," + cs.b + "," + cs.a + ")"); 554 cs = colors[n].value;
557 } 555 gradient.addColorStop(position, "rgba(" + cs.r + "," + cs.g + "," + cs.b + "," + cs.a + ")");
558 556 }
559 ctx.fillStyle = gradient; 557
560 558 ctx.fillStyle = gradient;
561 } else { 559
562 c = "rgba(" + 255*this._fillColor[0] + "," + 255*this._fillColor[1] + "," + 255*this._fillColor[2] + "," + this._fillColor[3] + ")"; 560 } else {
563 ctx.fillStyle = c; 561 c = "rgba(" + 255*this._fillColor[0] + "," + 255*this._fillColor[1] + "," + 255*this._fillColor[2] + "," + this._fillColor[3] + ")";
564 } 562 ctx.fillStyle = c;
565 563 }
566 ctx.lineWidth = lw; 564
567 this.renderPath( inset, ctx ); 565 ctx.lineWidth = lw;
568 ctx.fill(); 566 this.renderPath( inset, ctx );
569 ctx.closePath(); 567 ctx.fill();
570 } 568 ctx.closePath();
571 569 }
572 // render the stroke 570
573 ctx.beginPath(); 571 // render the stroke
574 if (this._strokeColor) { 572 ctx.beginPath();
575 inset = Math.ceil( 0.5*lw ) - 0.5; 573 if (this._strokeColor) {
576 574 inset = Math.ceil( 0.5*lw ) - 0.5;
577 if(this._strokeColor.gradientMode) { 575
578 if(this._strokeColor.gradientMode === "radial") { 576 if(this._strokeColor.gradientMode) {
579 gradient = ctx.createRadialGradient(w/2, h/2, Math.min(h, w)/2-inset, w/2, h/2, Math.max(h, w)/2); 577 if(this._strokeColor.gradientMode === "radial")
580 } else { 578 gradient = ctx.createRadialGradient(w/2, h/2, 0, w/2, h/2, Math.max(h, w)/2);
581 gradient = ctx.createLinearGradient(0, h/2, w, h/2); 579 else
582 } 580 gradient = ctx.createLinearGradient(0, h/2, w, h/2);
583 colors = this._strokeColor.color; 581 colors = this._strokeColor.color;
584 582
585 len = colors.length; 583 len = colors.length;
586 584
587 for(n=0; n<len; n++) { 585 for(n=0; n<len; n++) {
588 position = colors[n].position/100; 586 position = colors[n].position/100;
589 cs = colors[n].value; 587 cs = colors[n].value;
590 gradient.addColorStop(position, "rgba(" + cs.r + "," + cs.g + "," + cs.b + "," + cs.a + ")"); 588 gradient.addColorStop(position, "rgba(" + cs.r + "," + cs.g + "," + cs.b + "," + cs.a + ")");
591 } 589 }
592 590
593 ctx.strokeStyle = gradient; 591 ctx.strokeStyle = gradient;
594 592
595 } else { 593 } else {
596 c = "rgba(" + 255*this._strokeColor[0] + "," + 255*this._strokeColor[1] + "," + 255*this._strokeColor[2] + "," + this._strokeColor[3] + ")"; 594 c = "rgba(" + 255*this._strokeColor[0] + "," + 255*this._strokeColor[1] + "," + 255*this._strokeColor[2] + "," + this._strokeColor[3] + ")";
597 ctx.strokeStyle = c; 595 ctx.strokeStyle = c;
598 } 596 }
599 597
600 ctx.lineWidth = lw; 598 ctx.lineWidth = lw;
601 this.renderPath( inset, ctx ); 599 this.renderPath( inset, ctx );
602 ctx.stroke(); 600 ctx.stroke();
603 ctx.closePath(); 601 ctx.closePath();
604 } 602 }
605 } 603 }
606 },