diff options
author | Pushkar Joshi | 2012-04-09 15:55:10 -0700 |
---|---|---|
committer | Pushkar Joshi | 2012-04-09 15:55:10 -0700 |
commit | dae3041e6b8269da3d593a44c09e2288bb434a02 (patch) | |
tree | 495fc661a2e90816706a09b8d7d702550bd7fd8c /js/tools | |
parent | 6cce5e9367676f5b452c28dd7d960aa46f4e464c (diff) | |
download | ninja-dae3041e6b8269da3d593a44c09e2288bb434a02.tar.gz |
snapping feedback for pen tool, correct for subpaths that may lie on rotated canvas, and with a rotated view
Diffstat (limited to 'js/tools')
-rwxr-xr-x | js/tools/PenTool.js | 63 |
1 files changed, 53 insertions, 10 deletions
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index 61a254ea..6c016cab 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js | |||
@@ -119,6 +119,27 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
119 | } | 119 | } |
120 | }, | 120 | }, |
121 | 121 | ||
122 | _getUnsnappedScreenPosition: { | ||
123 | value: function(x,y){ | ||
124 | var elemSnap = snapManager.elementSnapEnabled(); | ||
125 | var gridSnap = snapManager.gridSnapEnabled(); | ||
126 | var alignSnap = snapManager.snapAlignEnabled(); | ||
127 | |||
128 | snapManager.enableElementSnap(false); | ||
129 | snapManager.enableGridSnap(false); | ||
130 | snapManager.enableSnapAlign(false); | ||
131 | |||
132 | var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(x,y)); | ||
133 | var unsnappedpos = (snapManager.snap(point.x, point.y, false)).getScreenPoint(); | ||
134 | this._dragPlane = snapManager.getDragPlane(); | ||
135 | |||
136 | snapManager.enableElementSnap(elemSnap); | ||
137 | snapManager.enableGridSnap(gridSnap); | ||
138 | snapManager.enableSnapAlign(alignSnap); | ||
139 | |||
140 | return unsnappedpos; | ||
141 | } | ||
142 | }, | ||
122 | ShowToolProperties: { | 143 | ShowToolProperties: { |
123 | value: function () { | 144 | value: function () { |
124 | this._penView = PenView.create(); | 145 | this._penView = PenView.create(); |
@@ -351,20 +372,31 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
351 | 372 | ||
352 | //make the subpath dirty so it will get re-drawn | 373 | //make the subpath dirty so it will get re-drawn |
353 | this._selectedSubpath.makeDirty(); | 374 | this._selectedSubpath.makeDirty(); |
354 | //this.DrawSubpathSVG(this._selectedSubpath); | ||
355 | } | ||
356 | //todo temp code only...remove this and uncomment the DrawSubpathSVG above | ||
357 | if (this._selectedSubpath){ | ||
358 | this.DrawSubpathSVG(this._selectedSubpath); | 375 | this.DrawSubpathSVG(this._selectedSubpath); |
359 | } | 376 | } |
360 | |||
361 | } else { //if mouse is not down: | 377 | } else { //if mouse is not down: |
362 | //this.doSnap(event); | 378 | //this.doSnap(event); |
363 | //this.DrawHandles(); | 379 | //this.DrawHandles(); |
364 | 380 | ||
365 | var currMousePos = this._getUnsnappedPosition(event.pageX, event.pageY); | 381 | var currMousePos = this._getUnsnappedPosition(event.pageX, event.pageY); |
366 | if (currMousePos && this._selectedSubpath ){ | 382 | if (currMousePos && this._selectedSubpath ){ |
367 | var selAnchorRetCode = this._selectedSubpath.pickAnchor(currMousePos[0], currMousePos[1], currMousePos[2], this._PICK_POINT_RADIUS); | 383 | /* |
384 | //convert the mouse pos. to local space of the canvas | ||
385 | var widthAdjustment = -snapManager.getStageWidth()*0.5; | ||
386 | var heightAdjustment = -snapManager.getStageHeight()*0.5; */ | ||
387 | |||
388 | |||
389 | var drawingCanvas = this._selectedSubpath.getCanvas(); | ||
390 | if (!drawingCanvas){ | ||
391 | drawingCanvas = ViewUtils.getStageElement(); | ||
392 | } | ||
393 | /*var stageWorldToGlobalMatrix = ViewUtils.getStageWorldToGlobalMatrix(); | ||
394 | var globalMousePos = MathUtils.transformAndDivideHomogeneousPoint([currMousePos[0]+widthAdjustment, currMousePos[1]+heightAdjustment, currMousePos[2]], stageWorldToGlobalMatrix);*/ | ||
395 | var globalMousePos = this._getUnsnappedScreenPosition(event.pageX, event.pageY); | ||
396 | var localMousePos = ViewUtils.globalToLocal(globalMousePos, drawingCanvas); | ||
397 | |||
398 | //var selAnchorRetCode = this._selectedSubpath.pickAnchor(currMousePos[0], currMousePos[1], currMousePos[2], this._PICK_POINT_RADIUS, false); | ||
399 | var selAnchorRetCode = this._selectedSubpath.pickAnchor(localMousePos[0], localMousePos[1], localMousePos[2], this._PICK_POINT_RADIUS, true); | ||
368 | if (selAnchorRetCode[0] >=0) { | 400 | if (selAnchorRetCode[0] >=0) { |
369 | this._hoveredAnchorIndex = selAnchorRetCode[0]; | 401 | this._hoveredAnchorIndex = selAnchorRetCode[0]; |
370 | var lastAnchorIndex = this._selectedSubpath.getNumAnchors()-1; | 402 | var lastAnchorIndex = this._selectedSubpath.getNumAnchors()-1; |
@@ -599,12 +631,23 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
599 | strokeSize = ShapesController.GetValueInPixels(this.options.strokeSize.value, this.options.strokeSize.units); | 631 | strokeSize = ShapesController.GetValueInPixels(this.options.strokeSize.value, this.options.strokeSize.units); |
600 | } | 632 | } |
601 | this._selectedSubpath.setStrokeWidth(strokeSize); | 633 | this._selectedSubpath.setStrokeWidth(strokeSize); |
602 | if (this.application.ninja.colorController.colorToolbar.stroke.webGlColor){ | 634 | |
603 | this._selectedSubpath.setStrokeColor(this.application.ninja.colorController.colorToolbar.stroke.webGlColor); | 635 | var colorArray=[]; |
636 | var color = this.application.ninja.colorController.colorToolbar.stroke.color; | ||
637 | if (color){ | ||
638 | colorArray = [color.r/255, color.g/255, color.b/255, color.a]; | ||
639 | }else { | ||
640 | colorArray = [1,1,1,0]; | ||
604 | } | 641 | } |
605 | if (this.application.ninja.colorController.colorToolbar.fill.webGlColor){ | 642 | this._selectedSubpath.setStrokeColor(colorArray); |
606 | this._selectedSubpath.setFillColor(this.application.ninja.colorController.colorToolbar.fill.webGlColor); | 643 | |
644 | color = this.application.ninja.colorController.colorToolbar.fill.color; | ||
645 | if (color){ | ||
646 | colorArray = [color.r/255, color.g/255, color.b/255, color.a]; | ||
647 | } else { | ||
648 | colorArray = [1,1,1,0]; | ||
607 | } | 649 | } |
650 | this._selectedSubpath.setFillColor(colorArray); | ||
608 | } //if this is a new path being rendered | 651 | } //if this is a new path being rendered |
609 | 652 | ||
610 | this._selectedSubpath.makeDirty(); | 653 | this._selectedSubpath.makeDirty(); |