diff options
author | Nivesh Rajbhandari | 2012-03-29 15:52:08 -0700 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-03-29 17:04:06 -0700 |
commit | 5b4f6b1618cf571a6bce5a631f976a008e04a64e (patch) | |
tree | d073038b08d14884f87c7776e9e192256d414cfb /js/models | |
parent | 6b61de58f0733b40f64ed996933ac89927e922a1 (diff) | |
download | ninja-5b4f6b1618cf571a6bce5a631f976a008e04a64e.tar.gz |
Updated shapes to always check for its stroke and fill colors and materials instead of relying on the shapeModel cache because it can get out of sync.
Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'js/models')
-rwxr-xr-x | js/models/color-model.js | 56 | ||||
-rwxr-xr-x | js/models/shape-model.js | 7 |
2 files changed, 46 insertions, 17 deletions
diff --git a/js/models/color-model.js b/js/models/color-model.js index 4189fbef..764feeb5 100755 --- a/js/models/color-model.js +++ b/js/models/color-model.js | |||
@@ -589,18 +589,54 @@ exports.ColorModel = Montage.create(Component, { | |||
589 | } | 589 | } |
590 | }, | 590 | }, |
591 | //////////////////////////////////////////////////////////////////// | 591 | //////////////////////////////////////////////////////////////////// |
592 | //Returns CSS string given a WebGL color array in [r, g, b, a] format where the values are [0,1] | 592 | //Returns a color object given a WebGL color array/object with gradient stops |
593 | webGlToCss: { | 593 | webGlToColor: { |
594 | enumerable: true, | 594 | enumerable: true, |
595 | value: function (color) { | 595 | value: function (c) { |
596 | if(color && (color.length === 4)) | 596 | if(c) { |
597 | { | 597 | if(c.gradientMode) { |
598 | return 'rgba(' + color[0]*255 + ', ' + color[1]*255 + ', ' + color[2]*255 + ', ' + color[3] +')'; | 598 | // Gradient |
599 | } | 599 | var i = 0, |
600 | else | 600 | len, |
601 | { | 601 | css, |
602 | return null; | 602 | stops = c.color, |
603 | gradient; | ||
604 | |||
605 | // Create the CSS string | ||
606 | if (c.gradientMode === 'radial') { | ||
607 | css = '-webkit-radial-gradient(center, ellipse cover'; | ||
608 | } else { | ||
609 | css = '-webkit-gradient(linear, left top, right top'; | ||
610 | } | ||
611 | |||
612 | //Sorting array (must be sorted for radial gradients, at least in Chrome | ||
613 | stops.sort(function(a,b){return a.position - b.position}); | ||
614 | //Looping through stops in gradient to create CSS | ||
615 | |||
616 | len = stops.length; | ||
617 | for (i=0; i < len; i++) { | ||
618 | //Adding to CSS String | ||
619 | if (c.gradientMode === 'radial' && stops[i].value) { | ||
620 | css += ', '+stops[i].value.css+' '+stops[i].position+'% '; | ||
621 | } else if (stops[i].value){ | ||
622 | css += ', color-stop('+stops[i].position+'%,'+stops[i].value.css+')'; | ||
623 | } | ||
624 | } | ||
625 | //Closing the CSS strings | ||
626 | css += ')'; | ||
627 | |||
628 | gradient = {stops: c.color, mode: c.gradientMode, gradientMode: c.gradientMode, css: css}; | ||
629 | return {mode: 'gradient', value: gradient, color: gradient}; | ||
630 | } else if(c.length === 4) { | ||
631 | // CSS | ||
632 | return this.application.ninja.colorController.getColorObjFromCss('rgba(' + c[0]*255 + ', ' | ||
633 | + c[1]*255 + ', ' | ||
634 | + c[2]*255 + ', ' | ||
635 | + c[3] +')'); | ||
636 | } | ||
603 | } | 637 | } |
638 | |||
639 | return null; | ||
604 | } | 640 | } |
605 | } | 641 | } |
606 | //////////////////////////////////////////////////////////////////// | 642 | //////////////////////////////////////////////////////////////////// |
diff --git a/js/models/shape-model.js b/js/models/shape-model.js index ea8c2cfc..ff69ae3c 100755 --- a/js/models/shape-model.js +++ b/js/models/shape-model.js | |||
@@ -17,15 +17,8 @@ exports.ShapeModel = Montage.create(Component, { | |||
17 | GLGeomObj: { value: null }, | 17 | GLGeomObj: { value: null }, |
18 | 18 | ||
19 | strokeSize: { value: null }, | 19 | strokeSize: { value: null }, |
20 | stroke: { value: null }, | ||
21 | strokeMaterial: { value: null }, | ||
22 | strokeStyle: { value: null }, | 20 | strokeStyle: { value: null }, |
23 | strokeStyleIndex: { value: null }, | 21 | strokeStyleIndex: { value: null }, |
24 | border: { value: null }, // Store css value for ColorController | ||
25 | |||
26 | fill: { value: null }, | ||
27 | fillMaterial: { value: null }, | ||
28 | background: { value: null }, // Store css value for ColorController | ||
29 | 22 | ||
30 | // Line-specific | 23 | // Line-specific |
31 | slope: { value: null }, | 24 | slope: { value: null }, |