aboutsummaryrefslogtreecommitdiff
path: root/js/tools/ShapeTool.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/tools/ShapeTool.js')
-rwxr-xr-xjs/tools/ShapeTool.js201
1 files changed, 101 insertions, 100 deletions
diff --git a/js/tools/ShapeTool.js b/js/tools/ShapeTool.js
index dc082303..26ed9c6f 100755
--- a/js/tools/ShapeTool.js
+++ b/js/tools/ShapeTool.js
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, are permitted provided that the following conditions are met:
8 7
9 - Redistributions of source code must retain the above copyright notice, 8* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 10
12 notice, this list of conditions and the following disclaimer in the 11* Redistributions in binary form must reproduce the above copyright notice,
13 documentation and/or other materials provided with the distribution. 12 this list of conditions and the following disclaimer in the documentation
14 - Neither the name of Motorola Mobility nor the names of its contributors 13 and/or other materials provided with the distribution.
15 may be used to endorse or promote products derived from this software 14
16 without specific prior written permission. 15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
17 18
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -40,29 +41,29 @@ var World = require("js/lib/drawing/world").World;
40exports.ShapeTool = Montage.create(DrawingTool, { 41exports.ShapeTool = Montage.create(DrawingTool, {
41 drawingFeedback: { value: { mode: "Draw3D", type: "rectangle" } }, 42 drawingFeedback: { value: { mode: "Draw3D", type: "rectangle" } },
42 43
43 _targetedElement: { value: null, writable: true }, 44 _targetedElement: { value: null, writable: true },
44 45
45 _mouseDownHitRec: { value: null, writable: true, enumerable: true, configurable: true }, 46 _mouseDownHitRec: { value: null, writable: true, enumerable: true, configurable: true },
46 _mouseUpHitRec: { value: null, writable: true, enumerable: true, configurable: true }, 47 _mouseUpHitRec: { value: null, writable: true, enumerable: true, configurable: true },
47 48
48 _canvasCounter: {value: 0, writable: true, enumerable: true, configurable: true }, 49 _canvasCounter: {value: 0, writable: true, enumerable: true, configurable: true },
49 50
50 HandleLeftButtonDown: 51 HandleLeftButtonDown:
51 { 52 {
52 value: function (event) 53 value: function (event)
53 { 54 {
54 if(this._canDraw) { 55 if(this._canDraw) {
55 this._isDrawing = true; 56 this._isDrawing = true;
56 } 57 }
57 58
58 this.startDraw(event); 59 this.startDraw(event);
59 } 60 }
60 }, 61 },
61 62
62 HandleMouseMove: 63 HandleMouseMove:
63 { 64 {
64 value: function (event) 65 value: function (event)
65 { 66 {
66 67
67 /* TAG */ 68 /* TAG */
68 if(this.isDrawing) { 69 if(this.isDrawing) {
@@ -77,7 +78,7 @@ exports.ShapeTool = Montage.create(DrawingTool, {
77 } 78 }
78 }, 79 },
79 80
80 HandleLeftButtonUp: { 81 HandleLeftButtonUp: {
81 value: function (event) { 82 value: function (event) {
82 var canvas, w, h; 83 var canvas, w, h;
83 this.drawData = this.getDrawingData(); 84 this.drawData = this.getDrawingData();
@@ -137,67 +138,67 @@ exports.ShapeTool = Montage.create(DrawingTool, {
137 } 138 }
138 }, 139 },
139 140
140 AddCustomFeedback: { 141 AddCustomFeedback: {
141 value: function (event) { 142 value: function (event) {
142 NJevent("enableStageMove"); 143 NJevent("enableStageMove");
143 144
144 this.application.ninja.stage.stageDeps.snapManager.setupDragPlaneFromPlane( workingPlane ); 145 this.application.ninja.stage.stageDeps.snapManager.setupDragPlaneFromPlane( workingPlane );
145 } 146 }
146 }, 147 },
147 148
148 RemoveCustomFeedback: { 149 RemoveCustomFeedback: {
149 value: function (event) { 150 value: function (event) {
150 if (this._targetedElement) { 151 if (this._targetedElement) {
151 this._targetedElement.classList.remove("active-element-outline"); 152 this._targetedElement.classList.remove("active-element-outline");
152 this._targetedElement = null; 153 this._targetedElement = null;
153 } 154 }
154 155
155 NJevent("disableStageMove"); 156 NJevent("disableStageMove");
156 157
157 this.application.ninja.stage.stageDeps.snapManager.clearDragPlane(); 158 this.application.ninja.stage.stageDeps.snapManager.clearDragPlane();
158 } 159 }
159 }, 160 },
160 161
161 /** Show a border when mousing 162 /** Show a border when mousing
162 * over existing canvas elements to signal to the user that 163 * over existing canvas elements to signal to the user that
163 * the drawing operation will act on the targeted canvas. 164 * the drawing operation will act on the targeted canvas.
164 **/ 165 **/
165 _showFeedbackOnMouseMove: { 166 _showFeedbackOnMouseMove: {
166 value: function (event) { 167 value: function (event) {
167 // TODO - This call is causing the canvas to redraw 3 times per mouse move 168 // TODO - This call is causing the canvas to redraw 3 times per mouse move
168 var targetedObject = this.application.ninja.stage.getElement(event, true); 169 var targetedObject = this.application.ninja.stage.getElement(event, true);
169 170
170 if (targetedObject) { 171 if (targetedObject) {
171 if((targetedObject.nodeName === "CANVAS") && !ShapesController.isElementAShape(targetedObject)) 172 if((targetedObject.nodeName === "CANVAS") && !ShapesController.isElementAShape(targetedObject))
172 { 173 {
173 if (targetedObject !== this._targetedElement) { 174 if (targetedObject !== this._targetedElement) {
174 if(this._targetedElement) 175 if(this._targetedElement)
175 { 176 {
176 this._targetedElement.classList.remove("active-element-outline"); 177 this._targetedElement.classList.remove("active-element-outline");
177 } 178 }
178 this._targetedElement = targetedObject; 179 this._targetedElement = targetedObject;
179 this._targetedElement.classList.add("active-element-outline"); 180 this._targetedElement.classList.add("active-element-outline");
180 } 181 }
181 } 182 }
182 else if (this._targetedElement) { 183 else if (this._targetedElement) {
183 this._targetedElement.classList.remove("active-element-outline"); 184 this._targetedElement.classList.remove("active-element-outline");
184 this._targetedElement = null; 185 this._targetedElement = null;
185 } 186 }
186 } 187 }
187 else if (this._targetedElement) { 188 else if (this._targetedElement) {
188 this._targetedElement.classList.remove("elem-red-outline"); 189 this._targetedElement.classList.remove("elem-red-outline");
189 this._targetedElement = null; 190 this._targetedElement = null;
190 } 191 }
191 } 192 }
192 }, 193 },
193 194
194 RenderShape: 195 RenderShape:
195 { 196 {
196 value: function (w, h, planeMat, midPt) 197 value: function (w, h, planeMat, midPt)
197 { 198 {
198 // Override in subclasses 199 // Override in subclasses
199 } 200 }
200 }, 201 },
201 202
202 getGLWorld: { 203 getGLWorld: {
203 value: function (canvas, use3D) 204 value: function (canvas, use3D)
@@ -214,26 +215,26 @@ exports.ShapeTool = Montage.create(DrawingTool, {
214 } 215 }
215 }, 216 },
216 217
217 // We can draw on an existing canvas unless it has only a single shape object 218 // We can draw on an existing canvas unless it has only a single shape object
218 _useExistingCanvas: { 219 _useExistingCanvas: {
219 value: function() 220 value: function()
220 { 221 {
221 var target; 222 var target;
222 if (this._targetedElement && (this._targetedElement.nodeName === "CANVAS") && !ShapesController.isElementAShape(this._targetedElement)) 223 if (this._targetedElement && (this._targetedElement.nodeName === "CANVAS") && !ShapesController.isElementAShape(this._targetedElement))
223 target = this._targetedElement; 224 target = this._targetedElement;
224 else 225 else
225 { 226 {
226 var container = this.application.ninja.currentDocument.model.domContainer; 227 var container = this.application.ninja.currentDocument.model.domContainer;
227 if (container && (container.nodeName === "CANVAS")) 228 if (container && (container.nodeName === "CANVAS"))
228 { 229 {
229 target = container; 230 target = container;
230 this._targetedElement = target; 231 this._targetedElement = target;
231 } 232 }
232 } 233 }
233 234
234 return target; 235 return target;
235 } 236 }