diff options
author | hwc487 | 2012-03-16 12:40:50 -0700 |
---|---|---|
committer | hwc487 | 2012-03-16 12:40:50 -0700 |
commit | 2ac5db3bb1bcee887d6dd742e6c0273abb5366bd (patch) | |
tree | 13622390967922f9c1719bf835f2f818867b5b9b /js/lib/geom/rectangle.js | |
parent | a0d23354802ebc6b437698acb4b18d3395d47cd1 (diff) | |
parent | 3e98d9eaf6f691aa0f7a4334983537a4ee3ffd39 (diff) | |
download | ninja-2ac5db3bb1bcee887d6dd742e6c0273abb5366bd.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into integration
Diffstat (limited to 'js/lib/geom/rectangle.js')
-rwxr-xr-x | js/lib/geom/rectangle.js | 102 |
1 files changed, 90 insertions, 12 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index 51fa3fd6..c6bc2d88 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js | |||
@@ -204,8 +204,20 @@ var Rectangle = function GLRectangle() { | |||
204 | rtnStr += "width: " + this._width + "\n"; | 204 | rtnStr += "width: " + this._width + "\n"; |
205 | rtnStr += "height: " + this._height + "\n"; | 205 | rtnStr += "height: " + this._height + "\n"; |
206 | rtnStr += "strokeWidth: " + this._strokeWidth + "\n"; | 206 | rtnStr += "strokeWidth: " + this._strokeWidth + "\n"; |
207 | rtnStr += "strokeColor: " + String(this._strokeColor) + "\n"; | 207 | |
208 | rtnStr += "fillColor: " + String(this._fillColor) + "\n"; | 208 | if(this._strokeColor.gradientMode) { |
209 | rtnStr += "strokeGradientMode: " + this._strokeColor.gradientMode + "\n"; | ||
210 | rtnStr += "strokeColor: " + this.gradientToString(this._strokeColor.color) + "\n"; | ||
211 | } else { | ||
212 | rtnStr += "strokeColor: " + String(this._strokeColor) + "\n"; | ||
213 | } | ||
214 | |||
215 | if(this._fillColor.gradientMode) { | ||
216 | rtnStr += "fillGradientMode: " + this._fillColor.gradientMode + "\n"; | ||
217 | rtnStr += "fillColor: " + this.gradientToString(this._fillColor.color) + "\n"; | ||
218 | } else { | ||
219 | rtnStr += "fillColor: " + String(this._fillColor) + "\n"; | ||
220 | } | ||
209 | rtnStr += "tlRadius: " + this._tlRadius + "\n"; | 221 | rtnStr += "tlRadius: " + this._tlRadius + "\n"; |
210 | rtnStr += "trRadius: " + this._trRadius + "\n"; | 222 | rtnStr += "trRadius: " + this._trRadius + "\n"; |
211 | rtnStr += "blRadius: " + this._blRadius + "\n"; | 223 | rtnStr += "blRadius: " + this._blRadius + "\n"; |
@@ -310,9 +322,25 @@ var Rectangle = function GLRectangle() { | |||
310 | var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr ); | 322 | var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr ); |
311 | var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr ); | 323 | var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr ); |
312 | this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr ); | 324 | this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr ); |
313 | this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" ); | 325 | |
314 | this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" ); | 326 | if(importStr.indexOf("fillGradientMode: ") < 0) { |
315 | this._tlRadius = Number( this.getPropertyFromString( "tlRadius: ", importStr ) ); | 327 | this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" ); |
328 | } else { | ||
329 | this._fillColor = {}; | ||
330 | this._fillColor.gradientMode = this.getPropertyFromString( "fillGradientMode: ", importStr ); | ||
331 | this._fillColor.color = this.stringToGradient(this.getPropertyFromString( "fillColor: ", importStr )); | ||
332 | } | ||
333 | |||
334 | if(importStr.indexOf("strokeGradientMode: ") < 0) | ||
335 | { | ||
336 | this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" ); | ||
337 | } else { | ||
338 | this._strokeColor = {}; | ||
339 | this._strokeColor.gradientMode = this.getPropertyFromString( "strokeGradientMode: ", importStr ); | ||
340 | this._strokeColor.color = this.stringToGradient(this.getPropertyFromString( "strokeColor: ", importStr )); | ||
341 | } | ||
342 | |||
343 | this._tlRadius = Number( this.getPropertyFromString( "tlRadius: ", importStr ) ); | ||
316 | this._trRadius = Number( this.getPropertyFromString( "trRadius: ", importStr ) ); | 344 | this._trRadius = Number( this.getPropertyFromString( "trRadius: ", importStr ) ); |
317 | this._blRadius = Number( this.getPropertyFromString( "blRadius: ", importStr ) ); | 345 | this._blRadius = Number( this.getPropertyFromString( "blRadius: ", importStr ) ); |
318 | this._brRadius = Number( this.getPropertyFromString( "brRadius: ", importStr ) ); | 346 | this._brRadius = Number( this.getPropertyFromString( "brRadius: ", importStr ) ); |
@@ -525,15 +553,44 @@ var Rectangle = function GLRectangle() { | |||
525 | var lw = this._strokeWidth; | 553 | var lw = this._strokeWidth; |
526 | var w = world.getViewportWidth(), | 554 | var w = world.getViewportWidth(), |
527 | h = world.getViewportHeight(); | 555 | h = world.getViewportHeight(); |
528 | 556 | ||
557 | var c, | ||
558 | inset, | ||
559 | gradient, | ||
560 | colors, | ||
561 | len, | ||
562 | n, | ||
563 | position, | ||
564 | cs; | ||
529 | // render the fill | 565 | // render the fill |
530 | ctx.beginPath(); | 566 | ctx.beginPath(); |
531 | if (this._fillColor) { | 567 | if (this._fillColor) { |
532 | var c = "rgba(" + 255*this._fillColor[0] + "," + 255*this._fillColor[1] + "," + 255*this._fillColor[2] + "," + this._fillColor[3] + ")"; | 568 | inset = Math.ceil( lw ) + 0.5; |
533 | ctx.fillStyle = c; | 569 | |
570 | if(this._fillColor.gradientMode) { | ||
571 | if(this._fillColor.gradientMode === "radial") { | ||
572 | gradient = ctx.createRadialGradient(w/2, h/2, 0, w/2, h/2, Math.max(w/2, h/2)-inset); | ||
573 | } else { | ||
574 | gradient = ctx.createLinearGradient(inset, h/2, w-2*inset, h/2); | ||
575 | } | ||
576 | colors = this._fillColor.color; | ||
577 | |||
578 | len = colors.length; | ||
579 | |||
580 | for(n=0; n<len; n++) { | ||
581 | position = colors[n].position/100; | ||
582 | cs = colors[n].value; | ||
583 | gradient.addColorStop(position, "rgba(" + cs.r + "," + cs.g + "," + cs.b + "," + cs.a + ")"); | ||
584 | } | ||
585 | |||
586 | ctx.fillStyle = gradient; | ||
587 | |||
588 | } else { | ||
589 | c = "rgba(" + 255*this._fillColor[0] + "," + 255*this._fillColor[1] + "," + 255*this._fillColor[2] + "," + this._fillColor[3] + ")"; | ||
590 | ctx.fillStyle = c; | ||
591 | } | ||
534 | 592 | ||
535 | ctx.lineWidth = lw; | 593 | ctx.lineWidth = lw; |
536 | var inset = Math.ceil( lw ) + 0.5; | ||
537 | this.renderPath( inset, ctx ); | 594 | this.renderPath( inset, ctx ); |
538 | ctx.fill(); | 595 | ctx.fill(); |
539 | ctx.closePath(); | 596 | ctx.closePath(); |
@@ -542,11 +599,32 @@ var Rectangle = function GLRectangle() { | |||
542 | // render the stroke | 599 | // render the stroke |
543 | ctx.beginPath(); | 600 | ctx.beginPath(); |
544 | if (this._strokeColor) { | 601 | if (this._strokeColor) { |
545 | var c = "rgba(" + 255*this._strokeColor[0] + "," + 255*this._strokeColor[1] + "," + 255*this._strokeColor[2] + "," + this._strokeColor[3] + ")"; | 602 | inset = Math.ceil( 0.5*lw ) + 0.5; |
546 | ctx.strokeStyle = c; | 603 | |
604 | if(this._strokeColor.gradientMode) { | ||
605 | if(this._strokeColor.gradientMode === "radial") { | ||
606 | gradient = ctx.createRadialGradient(w/2, h/2, Math.min(h/2, w/2)-inset, w/2, h/2, Math.max(h/2, w/2)); | ||
607 | } else { | ||
608 | gradient = ctx.createLinearGradient(0, h/2, w, h/2); | ||
609 | } | ||
610 | colors = this._strokeColor.color; | ||
611 | |||
612 | len = colors.length; | ||
613 | |||
614 | for(n=0; n<len; n++) { | ||
615 | position = colors[n].position/100; | ||
616 | cs = colors[n].value; | ||
617 | gradient.addColorStop(position, "rgba(" + cs.r + "," + cs.g + "," + cs.b + "," + cs.a + ")"); | ||
618 | } | ||
619 | |||
620 | ctx.strokeStyle = gradient; | ||
621 | |||
622 | } else { | ||
623 | c = "rgba(" + 255*this._strokeColor[0] + "," + 255*this._strokeColor[1] + "," + 255*this._strokeColor[2] + "," + this._strokeColor[3] + ")"; | ||
624 | ctx.strokeStyle = c; | ||
625 | } | ||
547 | 626 | ||
548 | ctx.lineWidth = lw; | 627 | ctx.lineWidth = lw; |
549 | var inset = Math.ceil( 0.5*lw ) + 0.5; | ||
550 | this.renderPath( inset, ctx ); | 628 | this.renderPath( inset, ctx ); |
551 | ctx.stroke(); | 629 | ctx.stroke(); |
552 | ctx.closePath(); | 630 | ctx.closePath(); |