diff options
Diffstat (limited to 'js')
-rwxr-xr-x | js/helper-classes/RDGE/GLAnchorPoint.js | 7 | ||||
-rwxr-xr-x | js/helper-classes/RDGE/GLSubpath.js | 64 | ||||
-rwxr-xr-x | js/mediators/keyboard-mediator.js | 7 | ||||
-rwxr-xr-x | js/tools/PenTool.js | 77 |
4 files changed, 127 insertions, 28 deletions
diff --git a/js/helper-classes/RDGE/GLAnchorPoint.js b/js/helper-classes/RDGE/GLAnchorPoint.js index 716f59d4..c3e95b34 100755 --- a/js/helper-classes/RDGE/GLAnchorPoint.js +++ b/js/helper-classes/RDGE/GLAnchorPoint.js | |||
@@ -133,6 +133,13 @@ GLAnchorPoint.prototype.translateAll = function (x, y, z) { | |||
133 | } | 133 | } |
134 | 134 | ||
135 | 135 | ||
136 | GLAnchorPoint.prototype.scaleAll = function(sx,sy,sz){ | ||
137 | this._x *= sx;this._prevX *= sx;this._nextX *= sx; | ||
138 | this._y *= sy;this._prevY *= sy;this._nextY *= sy; | ||
139 | this._z *= sz;this._prevZ *= sz;this._nextZ *= sz; | ||
140 | } | ||
141 | |||
142 | |||
136 | // ********* getters ********** | 143 | // ********* getters ********** |
137 | GLAnchorPoint.prototype.getPosX = function () { return this._x; } | 144 | GLAnchorPoint.prototype.getPosX = function () { return this._x; } |
138 | GLAnchorPoint.prototype.getPosY = function () { return this._y; } | 145 | GLAnchorPoint.prototype.getPosY = function () { return this._y; } |
diff --git a/js/helper-classes/RDGE/GLSubpath.js b/js/helper-classes/RDGE/GLSubpath.js index 3200cf59..7beb11b9 100755 --- a/js/helper-classes/RDGE/GLSubpath.js +++ b/js/helper-classes/RDGE/GLSubpath.js | |||
@@ -178,6 +178,65 @@ function GLSubpath() { | |||
178 | } //render() | 178 | } //render() |
179 | 179 | ||
180 | this.geomType = function () { return this.GEOM_TYPE_CUBIC_BEZIER; } | 180 | this.geomType = function () { return this.GEOM_TYPE_CUBIC_BEZIER; } |
181 | |||
182 | |||
183 | this.setWidth = function (newW) { | ||
184 | //todo this doesn't work in cases where the newW is zero or if the previous width was 0/1 (i.e. the path had become degenerate in width) | ||
185 | //todo same as above for the setHeight function below | ||
186 | //scale the contents of this subpath to lie within this width | ||
187 | //determine the scale factor by comparing with the old width | ||
188 | var oldWidth = this._BBoxMax[0]-this._BBoxMin[0]; | ||
189 | if (oldWidth<1){ | ||
190 | oldWidth=1; | ||
191 | } | ||
192 | var scaleX = newW/oldWidth; | ||
193 | if (scaleX===1){ | ||
194 | return; //no need to do anything | ||
195 | } | ||
196 | |||
197 | //scale the anchor point positions such that the width of the bbox is the newW | ||
198 | var origX = this._BBoxMin[0]; | ||
199 | var numAnchors = this._Anchors.length; | ||
200 | for (var i=0;i<numAnchors;i++){ | ||
201 | //compute the distance from the bboxMin | ||
202 | var oldW = this._Anchors[i].getPosX() - origX; | ||
203 | var prevW = this._Anchors[i].getPrevX() - origX; | ||
204 | var nextW = this._Anchors[i].getNextX() - origX; | ||
205 | |||
206 | this._Anchors[i].setPos(origX + oldW*scaleX,this._Anchors[i].getPosY(),this._Anchors[i].getPosZ()); | ||
207 | this._Anchors[i].setPrevPos(origX + prevW*scaleX,this._Anchors[i].getPrevY(),this._Anchors[i].getPrevZ()); | ||
208 | this._Anchors[i].setNextPos(origX + nextW*scaleX,this._Anchors[i].getNextY(),this._Anchors[i].getNextZ()); | ||
209 | } | ||
210 | this.makeDirty(); | ||
211 | } | ||
212 | this.setHeight = function (newH) { | ||
213 | //scale the contents of this subpath to lie within this height | ||
214 | //determine the scale factor by comparing with the old height | ||
215 | var oldHeight = this._BBoxMax[1]-this._BBoxMin[1]; | ||
216 | if (oldHeight<1){ | ||
217 | oldHeight=1; | ||
218 | } | ||
219 | var scaleY = newH/oldHeight; | ||
220 | if (scaleY===1){ | ||
221 | return; //no need to do anything | ||
222 | } | ||
223 | |||
224 | //scale the anchor point positions such that the height of the bbox is the newH | ||
225 | var origY = this._BBoxMin[1]; | ||
226 | var numAnchors = this._Anchors.length; | ||
227 | for (var i=0;i<numAnchors;i++){ | ||
228 | //compute the distance from the bboxMin | ||
229 | var oldW = this._Anchors[i].getPosY() - origY; | ||
230 | var prevW = this._Anchors[i].getPrevY() - origY; | ||
231 | var nextW = this._Anchors[i].getNextY() - origY; | ||
232 | |||
233 | this._Anchors[i].setPos(this._Anchors[i].getPosX(), origY + oldW*scaleY,this._Anchors[i].getPosZ()); | ||
234 | this._Anchors[i].setPrevPos(this._Anchors[i].getPrevX(), origY + prevW*scaleY,this._Anchors[i].getPrevZ()); | ||
235 | this._Anchors[i].setNextPos(this._Anchors[i].getNextX(), origY + nextW*scaleY,this._Anchors[i].getNextZ()); | ||
236 | } | ||
237 | this.makeDirty(); | ||
238 | } | ||
239 | |||
181 | } //function GLSubpath ...class definition | 240 | } //function GLSubpath ...class definition |
182 | 241 | ||
183 | 242 | ||
@@ -573,11 +632,6 @@ GLSubpath.prototype.setFillMaterial = function(m){ this._fillMaterial = m;} | |||
573 | GLSubpath.prototype.getFillColor = function() {return this._fillColor;} | 632 | GLSubpath.prototype.getFillColor = function() {return this._fillColor;} |
574 | GLSubpath.prototype.setFillColor = function(c){this._fillColor = c;} | 633 | GLSubpath.prototype.setFillColor = function(c){this._fillColor = c;} |
575 | 634 | ||
576 | GLSubpath.prototype.setWidth = function () {//NO-OP for now | ||
577 | } | ||
578 | GLSubpath.prototype.setHeight = function () {//NO-OP for now | ||
579 | } | ||
580 | |||
581 | GLSubpath.prototype.copyFromSubpath = function (subpath) { | 635 | GLSubpath.prototype.copyFromSubpath = function (subpath) { |
582 | this.clearAllAnchors(); | 636 | this.clearAllAnchors(); |
583 | for (var i = 0; i < subpath.getNumAnchors(); i++) { | 637 | for (var i = 0; i < subpath.getNumAnchors(); i++) { |
diff --git a/js/mediators/keyboard-mediator.js b/js/mediators/keyboard-mediator.js index 5b044f8a..63cffec3 100755 --- a/js/mediators/keyboard-mediator.js +++ b/js/mediators/keyboard-mediator.js | |||
@@ -136,6 +136,13 @@ exports.KeyboardMediator = Montage.create(Component, { | |||
136 | return; | 136 | return; |
137 | } | 137 | } |
138 | 138 | ||
139 | // shortcut for Pen tool is P | ||
140 | if (evt.keyCode === Keyboard.P){ | ||
141 | evt.preventDefault(); | ||
142 | this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[5]}); | ||
143 | return; | ||
144 | } | ||
145 | |||
139 | // Shortcut for Rectangle Tool is R | 146 | // Shortcut for Rectangle Tool is R |
140 | // unless the user is pressing the command key. | 147 | // unless the user is pressing the command key. |
141 | // If the user is pressing the command key, they want to refresh the browser. | 148 | // If the user is pressing the command key, they want to refresh the browser. |
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index 7749d525..bb9c71e7 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js | |||
@@ -955,33 +955,64 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
955 | 955 | ||
956 | handleDelete:{ | 956 | handleDelete:{ |
957 | value: function(event){ | 957 | value: function(event){ |
958 | //clear the selected subpath...the only new additions to this function w.r.t. ToolBase | 958 | var len = this.application.ninja.selectedElements.length; |
959 | if (this._selectedSubpath){ | 959 | if (len===0) { |
960 | if (this._selectedSubpath.getSelectedAnchorIndex()>=0){ | 960 | //clear the selected subpath...the only new additions to this function w.r.t. ToolBase |
961 | this._hoveredAnchorIndex=-1; | 961 | if (this._selectedSubpath){ |
962 | this._selectedSubpath.removeAnchor(this._selectedSubpath.getSelectedAnchorIndex()); | 962 | if (this._selectedSubpath.getSelectedAnchorIndex()>=0){ |
963 | this._selectedSubpath.createSamples(); | 963 | this._hoveredAnchorIndex=-1; |
964 | //clear the canvas | 964 | this._selectedSubpath.removeAnchor(this._selectedSubpath.getSelectedAnchorIndex()); |
965 | this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); | 965 | this._selectedSubpath.createSamples(); |
966 | this.DrawSubpathAnchors(this._selectedSubpath); | 966 | //clear the canvas |
967 | this.ShowSelectedSubpath(); | 967 | this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); |
968 | this.DrawSubpathAnchors(this._selectedSubpath); | ||
969 | this.ShowSelectedSubpath(); | ||
970 | } | ||
971 | else { | ||
972 | this._selectedSubpath.clearAllAnchors(); //perhaps unnecessary | ||
973 | this._selectedSubpath = null; | ||
974 | //clear the canvas | ||
975 | this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); | ||
976 | |||
977 | //undo/redo...go through ElementController and NJEvent | ||
978 | var els = []; | ||
979 | ElementController.removeElement(this._penCanvas); | ||
980 | els.push(this._penCanvas); | ||
981 | NJevent( "deleteSelection", els ); | ||
982 | this._penCanvas = null; | ||
983 | } | ||
984 | } | ||
985 | //do nothing if there was no selected subpath and if there was no selection | ||
986 | } | ||
987 | else { | ||
988 | |||
989 | //undo/redo...go through ElementMediator (see ElementMediator.handleDeleting() from where the much of this function is copied) | ||
990 | //clear the canvas | ||
991 | this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); | ||
992 | var els = []; | ||
993 | for(var i = 0; i<len; i++) { | ||
994 | els.push(this.application.ninja.selectedElements[i]); | ||
968 | } | 995 | } |
969 | else { | 996 | for(i=0; i<len; i++) { |
970 | this._selectedSubpath.clearAllAnchors(); //perhaps unnecessary | 997 | ElementController.removeElement(els[i]._element); |
971 | this._selectedSubpath = null; | ||
972 | //clear the canvas | ||
973 | this.application.ninja.stage.clearDrawingCanvas();//stageManagerModule.stageManager.clearDrawingCanvas(); | ||
974 | |||
975 | //undo/redo...go through ElementController and NJEvent | ||
976 | var els = []; | ||
977 | ElementController.removeElement(this._penCanvas); | ||
978 | els.push(this._penCanvas); | ||
979 | NJevent( "deleteSelection", els ); | ||
980 | this._penCanvas = null; | ||
981 | } | 998 | } |
982 | } | 999 | NJevent( "deleteSelection", els ); |
1000 | |||
1001 | //clear out the selected path if it exists | ||
1002 | if (this._selectedSubpath) { | ||
1003 | this._selectedSubpath.clearAllAnchors(); | ||
1004 | this._selectedSubpath = null; | ||
1005 | if (this._entryEditMode === this.ENTRY_SELECT_PATH){ | ||
1006 | this._entryEditMode = this.ENTRY_SELECT_NONE; | ||
1007 | } | ||
1008 | this._penCanvas = null; | ||
1009 | } | ||
1010 | } | ||
1011 | //redraw the stage to update it | ||
1012 | this.application.ninja.stage.draw(); | ||
983 | } | 1013 | } |
984 | }, | 1014 | }, |
1015 | |||
985 | handleResetPenTool: { | 1016 | handleResetPenTool: { |
986 | value: function (event) { | 1017 | value: function (event) { |
987 | this.Reset(); | 1018 | this.Reset(); |