aboutsummaryrefslogtreecommitdiff
path: root/js/controllers/elements/shapes-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/controllers/elements/shapes-controller.js')
-rwxr-xr-xjs/controllers/elements/shapes-controller.js124
1 files changed, 95 insertions, 29 deletions
diff --git a/js/controllers/elements/shapes-controller.js b/js/controllers/elements/shapes-controller.js
index 74353454..df6edeb0 100755
--- a/js/controllers/elements/shapes-controller.js
+++ b/js/controllers/elements/shapes-controller.js
@@ -1,7 +1,31 @@
1/* <copyright> 1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/> 2Copyright (c) 2012, Motorola Mobility, Inc
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> 3All Rights Reserved.
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4BSD License.
5
6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met:
8
9 - Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 - Neither the name of Motorola Mobility nor the names of its contributors
15 may be used to endorse or promote products derived from this software
16 without specific prior written permission.
17
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28POSSIBILITY OF SUCH DAMAGE.
5</copyright> */ 29</copyright> */
6 30
7var Montage = require("montage/core/core").Montage, 31var Montage = require("montage/core/core").Montage,
@@ -138,6 +162,10 @@ exports.ShapesController = Montage.create(CanvasController, {
138 this.application.ninja.elementMediator.replaceElement(canvas, el); 162 this.application.ninja.elementMediator.replaceElement(canvas, el);
139 break; 163 break;
140 case "strokeMaterial": 164 case "strokeMaterial":
165 // skip shape types that don't support WebGL
166 if(!el.elementModel.shapeModel.useWebGl) {
167 return;
168 }
141 m = Object.create(MaterialsModel.getMaterial(value)); 169 m = Object.create(MaterialsModel.getMaterial(value));
142 if(m) 170 if(m)
143 { 171 {
@@ -152,6 +180,10 @@ exports.ShapesController = Montage.create(CanvasController, {
152 } 180 }
153 break; 181 break;
154 case "fillMaterial": 182 case "fillMaterial":
183 // skip shape types that don't support WebGL or fill color
184 if(!el.elementModel.shapeModel.GLGeomObj.canFill || !el.elementModel.shapeModel.useWebGl) {
185 return;
186 }
155 m = Object.create(MaterialsModel.getMaterial(value)); 187 m = Object.create(MaterialsModel.getMaterial(value));
156 if(m) 188 if(m)
157 { 189 {
@@ -445,17 +477,17 @@ exports.ShapesController = Montage.create(CanvasController, {
445 477
446 if(gradientM) 478 if(gradientM)
447 { 479 {
448 if(isFill) 480 if(isFill)
449 { 481 {
450 el.elementModel.shapeModel.GLGeomObj.setFillMaterial(gradientM); 482 el.elementModel.shapeModel.GLGeomObj.setFillMaterial(gradientM);
451 } 483 }
452 else 484 else
453 { 485 {
454 el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(gradientM); 486 el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(gradientM);
455 } 487 }
456 el.elementModel.shapeModel.GLGeomObj.buildBuffers(); 488 el.elementModel.shapeModel.GLGeomObj.buildBuffers();
457 } 489 }
458 } 490 }
459 }, 491 },
460 492
461 _setFlatMaterial: { 493 _setFlatMaterial: {
@@ -472,10 +504,13 @@ exports.ShapesController = Montage.create(CanvasController, {
472 } 504 }
473 505
474 if(!m || ((m.getName() === "Linear Gradient") || m.getName() === "Radial Gradient") ) 506 if(!m || ((m.getName() === "Linear Gradient") || m.getName() === "Radial Gradient") )
475 { 507 {
508 // Uber Material also supports solid colors, so don't change from Uber to Flat Material
509 if(m && (m.getName() === "Uber")) { return; }
510
476 flatM = Object.create(MaterialsModel.getMaterial("Flat")); 511 flatM = Object.create(MaterialsModel.getMaterial("Flat"));
477 if(flatM) 512 if(flatM)
478 { 513 {
479 if(isFill) 514 if(isFill)
480 { 515 {
481 el.elementModel.shapeModel.GLGeomObj.setFillMaterial(flatM); 516 el.elementModel.shapeModel.GLGeomObj.setFillMaterial(flatM);
@@ -484,10 +519,10 @@ exports.ShapesController = Montage.create(CanvasController, {
484 { 519 {
485 el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(flatM); 520 el.elementModel.shapeModel.GLGeomObj.setStrokeMaterial(flatM);
486 } 521 }
487 el.elementModel.shapeModel.GLGeomObj.buildBuffers(); 522 el.elementModel.shapeModel.GLGeomObj.buildBuffers();
488 }
489 } 523 }
490 } 524 }
525 }
491 }, 526 },
492 527
493 setColor: { 528 setColor: {
@@ -597,14 +632,31 @@ exports.ShapesController = Montage.create(CanvasController, {
597 632
598 setStroke: { 633 setStroke: {
599 value: function(el, stroke, eventType, source) { 634 value: function(el, stroke, eventType, source) {
600 if(stroke.colorInfo) {
601 this.setColor(el, stroke.colorInfo, false);
602 }
603 if(stroke.shapeInfo) { 635 if(stroke.shapeInfo) {
604 this.setProperty(el, "strokeSize", stroke.shapeInfo.strokeSize + " " + stroke.shapeInfo.strokeUnits, eventType, source); 636 this.setProperty(el, "strokeSize", stroke.shapeInfo.strokeSize + " " + stroke.shapeInfo.strokeUnits, eventType, source);
605 } 637 }
638 var m;
606 if(stroke.webGLInfo) { 639 if(stroke.webGLInfo) {
607 this.setProperty(el, "strokeMaterial", stroke.webGLInfo.material); 640 m = stroke.webGLInfo.material;
641 this.setProperty(el, "strokeMaterial", m);
642 if((m === "Linear Gradient") || (m === "Radial Gradient")) {
643 // Just use the default gradient material values
644 return;
645 }
646 }
647 if(stroke.colorInfo) {
648 if(el.elementModel.shapeModel.useWebGl) {
649 m = el.elementModel.shapeModel.GLGeomObj.getStrokeMaterial().getName();
650 if( ((stroke.colorInfo.mode === "gradient") && (m !== "Linear Gradient") && (m !== "Radial Gradient")) ||
651 ((stroke.colorInfo.mode !== "gradient") && ((m === "Linear Gradient") || (m === "Radial Gradient"))))
652 {
653 return;
654 } else {
655 this.setColor(el, stroke.colorInfo, false);
656 }
657 } else {
658 this.setColor(el, stroke.colorInfo, false);
659 }
608 } 660 }
609 } 661 }
610 }, 662 },
@@ -638,11 +690,28 @@ exports.ShapesController = Montage.create(CanvasController, {
638 690
639 setFill: { 691 setFill: {
640 value: function(el, fill) { 692 value: function(el, fill) {
641 if(fill.colorInfo) { 693 var m;
642 this.setColor(el, fill.colorInfo, true);
643 }
644 if(fill.webGLInfo) { 694 if(fill.webGLInfo) {
645 this.setProperty(el, "fillMaterial", fill.webGLInfo.material); 695 m = fill.webGLInfo.material;
696 this.setProperty(el, "fillMaterial", m);
697 if((m === "Linear Gradient") || (m === "Radial Gradient")) {
698 // Just use the default gradient material values
699 return;
700 }
701 }
702 if(fill.colorInfo) {
703 if(el.elementModel.shapeModel.useWebGl) {
704 m = el.elementModel.shapeModel.GLGeomObj.getFillMaterial().getName();
705 if( ((fill.colorInfo.mode === "gradient") && (m !== "Linear Gradient") && (m !== "Radial Gradient")) ||
706 ((fill.colorInfo.mode !== "gradient") && ((m === "Linear Gradient") || (m === "Radial Gradient"))))
707 {
708 return;
709 } else {
710 this.setColor(el, fill.colorInfo, true);
711 }
712 } else {
713 this.setColor(el, fill.colorInfo, true);
714 }
646 } 715 }
647 } 716 }
648 }, 717 },
@@ -813,15 +882,12 @@ exports.ShapesController = Montage.create(CanvasController, {
813 value: function(m) 882 value: function(m)
814 { 883 {
815 var css, 884 var css,
816 colorObj; 885 colorObj,
817 if(m === "Linear Gradient") 886 material;
818 { 887
819 css = "-webkit-gradient(linear, left top, right top, from(rgb(255, 0, 0)), color-stop(0.3, rgb(0, 255, 0)), color-stop(0.6, rgb(0, 0, 255)), to(rgb(0, 255, 255)))"; 888 material = MaterialsModel.getMaterial(m);
820 } 889
821 else if(m === "Radial Gradient") 890