diff options
Diffstat (limited to 'js/tools/ShapeTool.js')
-rwxr-xr-x | js/tools/ShapeTool.js | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/js/tools/ShapeTool.js b/js/tools/ShapeTool.js index d3a36163..f3b5e92d 100755 --- a/js/tools/ShapeTool.js +++ b/js/tools/ShapeTool.js | |||
@@ -6,10 +6,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
6 | 6 | ||
7 | var Montage = require("montage/core/core").Montage, | 7 | var Montage = require("montage/core/core").Montage, |
8 | DrawingTool = require("js/tools/drawing-tool").DrawingTool, | 8 | DrawingTool = require("js/tools/drawing-tool").DrawingTool, |
9 | viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils, | ||
10 | drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils, | ||
11 | NJUtils = require("js/lib/NJUtils").NJUtils, | 9 | NJUtils = require("js/lib/NJUtils").NJUtils, |
12 | ElementMediator = require("js/mediators/element-mediator").ElementMediator, | ||
13 | ShapesController = require("js/controllers/elements/shapes-controller").ShapesController, | 10 | ShapesController = require("js/controllers/elements/shapes-controller").ShapesController, |
14 | ShapeModel = require("js/models/shape-model").ShapeModel, | 11 | ShapeModel = require("js/models/shape-model").ShapeModel, |
15 | TagTool = require("js/tools/TagTool").TagTool; | 12 | TagTool = require("js/tools/TagTool").TagTool; |
@@ -62,30 +59,24 @@ exports.ShapeTool = Montage.create(DrawingTool, { | |||
62 | { | 59 | { |
63 | var drawData; | 60 | var drawData; |
64 | 61 | ||
65 | drawData = this.getDrawingData(); | 62 | drawData = this.getDrawingData(); |
66 | 63 | ||
67 | if(drawData) { | 64 | if(drawData) { |
68 | var canvas; | 65 | var canvas; |
69 | if(!this._useExistingCanvas()) | 66 | if(!this._useExistingCanvas()) { |
70 | { | ||
71 | canvas = NJUtils.makeNJElement("canvas", "Canvas", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); | 67 | canvas = NJUtils.makeNJElement("canvas", "Canvas", "shape", {"data-RDGE-id": NJUtils.generateRandom()}, true); |
72 | var elementModel = TagTool.makeElement(~~drawData.width, ~~drawData.height, | 68 | var elementModel = TagTool.makeElement(~~drawData.width, ~~drawData.height, |
73 | drawData.planeMat, drawData.midPt, canvas); | 69 | drawData.planeMat, drawData.midPt, canvas, true); |
74 | 70 | ||
75 | ElementMediator.addElement(canvas, elementModel.data, true); | ||
76 | canvas.elementModel.isShape = true; | 71 | canvas.elementModel.isShape = true; |
77 | } | 72 | this.application.ninja.elementMediator.addElements(canvas, elementModel.data); |
78 | else | 73 | } else { |
79 | { | ||
80 | canvas = this._targetedElement; | 74 | canvas = this._targetedElement; |
81 | canvas.elementModel.controller = ShapesController; | 75 | canvas.elementModel.controller = ShapesController; |
82 | if(!canvas.elementModel.shapeModel) | 76 | if(!canvas.elementModel.shapeModel) { |
83 | { | ||
84 | canvas.elementModel.shapeModel = Montage.create(ShapeModel); | 77 | canvas.elementModel.shapeModel = Montage.create(ShapeModel); |
85 | } | 78 | } |
86 | } | 79 | } |
87 | this.RenderShape(drawData.width, drawData.height, drawData.planeMat, drawData.midPt, canvas); | ||
88 | NJevent("elementAdded", canvas); | ||
89 | } | 80 | } |
90 | 81 | ||
91 | this.endDraw(event); | 82 | this.endDraw(event); |
@@ -93,17 +84,28 @@ exports.ShapeTool = Montage.create(DrawingTool, { | |||
93 | this._isDrawing = false; | 84 | this._isDrawing = false; |
94 | this._hasDraw=false; | 85 | this._hasDraw=false; |
95 | 86 | ||
96 | |||
97 | this.DrawHandles(); | 87 | this.DrawHandles(); |
98 | } | 88 | } |
99 | }, | 89 | }, |
100 | 90 | ||
91 | onAddElements: { | ||
92 | value: function(el) { | ||
93 | var drawData; | ||
94 | |||
95 | if(drawData = this.getDrawingData()) { | ||
96 | this.RenderShape(drawData.width, drawData.height, drawData.planeMat, drawData.midPt, el); | ||
97 | } | ||
98 | } | ||
99 | }, | ||
100 | |||
101 | Configure: { | 101 | Configure: { |
102 | value: function(wasSelected) { | 102 | value: function(wasSelected) { |
103 | if(wasSelected) { | 103 | if(wasSelected) { |
104 | this.AddCustomFeedback(); | 104 | this.AddCustomFeedback(); |
105 | this.application.ninja.elementMediator.addDelegate = this; | ||
105 | } else { | 106 | } else { |
106 | this.RemoveCustomFeedback(); | 107 | this.RemoveCustomFeedback(); |
108 | this.application.ninja.elementMediator.addDelegate = null; | ||
107 | } | 109 | } |
108 | } | 110 | } |
109 | }, | 111 | }, |
@@ -119,7 +121,7 @@ exports.ShapeTool = Montage.create(DrawingTool, { | |||
119 | RemoveCustomFeedback: { | 121 | RemoveCustomFeedback: { |
120 | value: function (event) { | 122 | value: function (event) { |
121 | if (this._targetedElement) { | 123 | if (this._targetedElement) { |
122 | this._targetedElement.classList.remove("elem-red-outline"); | 124 | this._targetedElement.classList.remove("active-element-outline"); |
123 | this._targetedElement = null; | 125 | this._targetedElement = null; |
124 | } | 126 | } |
125 | 127 | ||
@@ -136,23 +138,22 @@ exports.ShapeTool = Montage.create(DrawingTool, { | |||
136 | _showFeedbackOnMouseMove: { | 138 | _showFeedbackOnMouseMove: { |
137 | value: function (event) { | 139 | value: function (event) { |
138 | // TODO - This call is causing the canvas to redraw 3 times per mouse move | 140 | // TODO - This call is causing the canvas to redraw 3 times per mouse move |
139 | var targetedObject = this.application.ninja.stage.GetElement(event); | 141 | var targetedObject = this.application.ninja.stage.GetSelectableElement(event); |
140 | 142 | ||
141 | if (targetedObject) { | 143 | if (targetedObject) { |
142 | // TODO - Clean this up | ||
143 | if((targetedObject.nodeName === "CANVAS") && !ShapesController.isElementAShape(targetedObject)) | 144 | if((targetedObject.nodeName === "CANVAS") && !ShapesController.isElementAShape(targetedObject)) |
144 | { | 145 | { |
145 | if (targetedObject !== this._targetedElement) { | 146 | if (targetedObject !== this._targetedElement) { |
146 | if(this._targetedElement) | 147 | if(this._targetedElement) |
147 | { | 148 | { |
148 | this._targetedElement.classList.remove("elem-red-outline"); | 149 | this._targetedElement.classList.remove("active-element-outline"); |
149 | } | 150 | } |
150 | this._targetedElement = targetedObject; | 151 | this._targetedElement = targetedObject; |
151 | this._targetedElement.classList.add("elem-red-outline"); | 152 | this._targetedElement.classList.add("active-element-outline"); |
152 | } | 153 | } |
153 | } | 154 | } |
154 | else if (this._targetedElement) { | 155 | else if (this._targetedElement) { |
155 | this._targetedElement.classList.remove("elem-red-outline"); | 156 | this._targetedElement.classList.remove("active-element-outline"); |
156 | this._targetedElement = null; | 157 | this._targetedElement = null; |
157 | } | 158 | } |
158 | } | 159 | } |
@@ -174,12 +175,12 @@ exports.ShapeTool = Montage.create(DrawingTool, { | |||
174 | getGLWorld: { | 175 | getGLWorld: { |
175 | value: function (canvas, use3D) | 176 | value: function (canvas, use3D) |
176 | { | 177 | { |
177 | var world = ElementMediator.getShapeProperty(canvas, "GLWorld"); | 178 | var world = this.application.ninja.elementMediator.getShapeProperty(canvas, "GLWorld"); |
178 | if(!world) | 179 | if(!world) |
179 | { | 180 | { |
180 | // create all the GL stuff | 181 | // create all the GL stuff |
181 | var world = new World(canvas, use3D); | 182 | var world = new World(canvas, use3D); |
182 | ElementMediator.setShapeProperty(canvas, "GLWorld", world); | 183 | this.application.ninja.elementMediator.setShapeProperty(canvas, "GLWorld", world); |
183 | } | 184 | } |
184 | 185 | ||
185 | return world; | 186 | return world; |
@@ -196,7 +197,7 @@ exports.ShapeTool = Montage.create(DrawingTool, { | |||
196 | 'top' : top + 'px', | 197 | 'top' : top + 'px', |
197 | 'left' : left + 'px', | 198 | 'left' : left + 'px', |
198 | '-webkit-transform-style' : 'preserve-3d', | 199 | '-webkit-transform-style' : 'preserve-3d', |
199 | '-webkit-transform' : 'perspective(1400) matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' | 200 | '-webkit-transform' : 'matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)' |
200 | }; | 201 | }; |
201 | 202 | ||
202 | tmpDiv.width = w; | 203 | tmpDiv.width = w; |
@@ -206,8 +207,6 @@ exports.ShapeTool = Montage.create(DrawingTool, { | |||
206 | } | 207 | } |
207 | }, | 208 | }, |
208 | 209 | ||
209 | |||
210 | |||
211 | // We can draw on an existing canvas unless it has only a single shape object | 210 | // We can draw on an existing canvas unless it has only a single shape object |
212 | _useExistingCanvas: { | 211 | _useExistingCanvas: { |
213 | value: function() | 212 | value: function() |