diff options
author | Pushkar Joshi | 2012-03-27 15:40:37 -0700 |
---|---|---|
committer | Pushkar Joshi | 2012-03-27 15:40:37 -0700 |
commit | 3fd098981077e40841c013a8ac305036d08a215b (patch) | |
tree | d8b52ee21ef7d9eb4a2d53e831bd526d4f4e0809 | |
parent | 02a34df0ec3201199d209d43f621898b5607c150 (diff) | |
download | ninja-3fd098981077e40841c013a8ac305036d08a215b.tar.gz |
added cursors to the pen tool UI AND change cursor when the user hovers over an anchor point or handles of thte selected anchor
-rw-r--r-- | images/cursors/penCursors/Pen_.png | bin | 0 -> 182 bytes | |||
-rw-r--r-- | images/cursors/penCursors/Pen_anchorSelect.png | bin | 0 -> 268 bytes | |||
-rw-r--r-- | images/cursors/penCursors/Pen_append.png | bin | 0 -> 210 bytes | |||
-rw-r--r-- | images/cursors/penCursors/Pen_closePath.png | bin | 0 -> 211 bytes | |||
-rw-r--r-- | images/cursors/penCursors/Pen_minus.png | bin | 0 -> 204 bytes | |||
-rw-r--r-- | images/cursors/penCursors/Pen_newPath.png | bin | 0 -> 215 bytes | |||
-rw-r--r-- | images/cursors/penCursors/Pen_plus.png | bin | 0 -> 211 bytes | |||
-rw-r--r-- | images/cursors/penCursors/penAdd_OLD.png (renamed from images/cursors/penAdd.png) | bin | 3043 -> 3043 bytes | |||
-rwxr-xr-x | js/lib/geom/sub-path.js | 51 | ||||
-rwxr-xr-x | js/tools/PenTool.js | 11 |
10 files changed, 38 insertions, 24 deletions
diff --git a/images/cursors/penCursors/Pen_.png b/images/cursors/penCursors/Pen_.png new file mode 100644 index 00000000..fea41116 --- /dev/null +++ b/images/cursors/penCursors/Pen_.png | |||
Binary files differ | |||
diff --git a/images/cursors/penCursors/Pen_anchorSelect.png b/images/cursors/penCursors/Pen_anchorSelect.png new file mode 100644 index 00000000..c05c2312 --- /dev/null +++ b/images/cursors/penCursors/Pen_anchorSelect.png | |||
Binary files differ | |||
diff --git a/images/cursors/penCursors/Pen_append.png b/images/cursors/penCursors/Pen_append.png new file mode 100644 index 00000000..1dbb959f --- /dev/null +++ b/images/cursors/penCursors/Pen_append.png | |||
Binary files differ | |||
diff --git a/images/cursors/penCursors/Pen_closePath.png b/images/cursors/penCursors/Pen_closePath.png new file mode 100644 index 00000000..8447ddbc --- /dev/null +++ b/images/cursors/penCursors/Pen_closePath.png | |||
Binary files differ | |||
diff --git a/images/cursors/penCursors/Pen_minus.png b/images/cursors/penCursors/Pen_minus.png new file mode 100644 index 00000000..41fe47d8 --- /dev/null +++ b/images/cursors/penCursors/Pen_minus.png | |||
Binary files differ | |||
diff --git a/images/cursors/penCursors/Pen_newPath.png b/images/cursors/penCursors/Pen_newPath.png new file mode 100644 index 00000000..547731f3 --- /dev/null +++ b/images/cursors/penCursors/Pen_newPath.png | |||
Binary files differ | |||
diff --git a/images/cursors/penCursors/Pen_plus.png b/images/cursors/penCursors/Pen_plus.png new file mode 100644 index 00000000..192c71fe --- /dev/null +++ b/images/cursors/penCursors/Pen_plus.png | |||
Binary files differ | |||
diff --git a/images/cursors/penAdd.png b/images/cursors/penCursors/penAdd_OLD.png index c306cc85..c306cc85 100644 --- a/images/cursors/penAdd.png +++ b/images/cursors/penCursors/penAdd_OLD.png | |||
Binary files differ | |||
diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js index 7046673e..9bd9ad9a 100755 --- a/js/lib/geom/sub-path.js +++ b/js/lib/geom/sub-path.js | |||
@@ -567,37 +567,50 @@ GLSubpath.prototype._isWithinBoundingBox = function(point, ctrlPts, radius) { | |||
567 | return true; | 567 | return true; |
568 | }; | 568 | }; |
569 | 569 | ||
570 | GLSubpath.prototype._checkAnchorIntersection = function(pickX, pickY, pickZ, radSq, anchorIndex, minDistance) { | ||
571 | var distSq = this._Anchors[anchorIndex].getDistanceSq(pickX, pickY, pickZ); | ||
572 | //check the anchor point | ||
573 | if (distSq < radSq && distSq<minDistance) { | ||
574 | return this.SEL_ANCHOR; | ||
575 | } | ||
576 | //check the prev. and next of the selected anchor point | ||
577 | distSq = this._Anchors[anchorIndex].getPrevDistanceSq(pickX, pickY, pickZ); | ||
578 | if (distSq<radSq && distSq<minDistance){ | ||
579 | return this.SEL_PREV; | ||
580 | } | ||
581 | distSq = this._Anchors[anchorIndex].getNextDistanceSq(pickX, pickY, pickZ); | ||
582 | if (distSq<radSq && distSq<minDistance){ | ||
583 | return this.SEL_NEXT; | ||
584 | } | ||
585 | return this.SEL_NONE; | ||
586 | }; | ||
587 | |||
570 | GLSubpath.prototype.pickAnchor = function (pickX, pickY, pickZ, radius) { | 588 | GLSubpath.prototype.pickAnchor = function (pickX, pickY, pickZ, radius) { |
571 | var numAnchors = this._Anchors.length; | 589 | var numAnchors = this._Anchors.length; |
572 | var selAnchorIndex = -1; | 590 | var selAnchorIndex = -1; |
573 | var retCode = this.SEL_NONE; | 591 | var retCode = this.SEL_NONE; |
574 | var radSq = radius * radius; | ||
575 | var minDistance = Infinity; | 592 | var minDistance = Infinity; |
593 | var radSq = radius * radius; | ||
576 | //check if the clicked location is close to the currently selected anchor position | 594 | //check if the clicked location is close to the currently selected anchor position |
577 | if (this._selectedAnchorIndex>=0 && this._selectedAnchorIndex<this._Anchors.length){ | 595 | if (this._selectedAnchorIndex>=0 && this._selectedAnchorIndex<this._Anchors.length){ |
578 | var distSq = this._Anchors[this._selectedAnchorIndex].getDistanceSq(pickX, pickY, pickZ); | 596 | retCode = this._checkAnchorIntersection(pickX, pickY, pickZ, radSq, this._selectedAnchorIndex, minDistance); |
579 | //check the anchor point | 597 | if (retCode!==this.SEL_NONE){ |
580 | if (distSq < minDistance && distSq < radSq) { | 598 | return [this._selectedAnchorIndex, retCode]; |
581 | selAnchorIndex = this._selectedAnchorIndex; | ||
582 | minDistance = distSq; | ||
583 | retCode = retCode | this.SEL_ANCHOR; | ||
584 | } | 599 | } |
585 | } | 600 | } |
586 | //now check if the click location is close to any anchor position | 601 | //now check if the click location is close to any anchor position |
587 | if (selAnchorIndex===-1) { | 602 | for (var i = 0; i < numAnchors; i++) { |
588 | for (var i = 0; i < numAnchors; i++) { | 603 | retCode = this._checkAnchorIntersection(pickX, pickY, pickZ, radSq, i, minDistance); |
589 | var distSq = this._Anchors[i].getDistanceSq(pickX, pickY, pickZ); | 604 | if (retCode!==this.SEL_NONE){ |
590 | //check the anchor point | 605 | selAnchorIndex=i; |
591 | if (distSq < minDistance && distSq < radSq) { | 606 | break; |
592 | selAnchorIndex = i; | 607 | } |
593 | minDistance = distSq; | 608 | }//for every anchor i |
594 | } | 609 | |
595 | }//for every anchor i | 610 | return [selAnchorIndex, retCode]; |
596 | } | ||
597 | return selAnchorIndex; | ||
598 | }; | 611 | }; |
599 | 612 | ||
600 | GLSubpath.prototype.isWithinBBox =function(x,y,z){ | 613 | GLSubpath.prototype.isWithinBBox = function(x,y,z) { |
601 | if (this._BBoxMin[0]>x || this._BBoxMin[1]>y || this._BBoxMin[2]>z){ | 614 | if (this._BBoxMin[0]>x || this._BBoxMin[1]>y || this._BBoxMin[2]>z){ |
602 | return false; | 615 | return false; |
603 | } | 616 | } |
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index 779b7f16..39a1b15a 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js | |||
@@ -348,16 +348,17 @@ exports.PenTool = Montage.create(ShapeTool, { | |||
348 | 348 | ||
349 | var currMousePos = this._getUnsnappedPosition(event.pageX, event.pageY); | 349 | var currMousePos = this._getUnsnappedPosition(event.pageX, event.pageY); |
350 | if (currMousePos && this._selectedSubpath ){ | 350 | if (currMousePos && this._selectedSubpath ){ |
351 | var selAnchor = this._selectedSubpath.pickAnchor(currMousePos[0], currMousePos[1], currMousePos[2], this._PICK_POINT_RADIUS); | 351 | var selAnchorRetCode = this._selectedSubpath.pickAnchor(currMousePos[0], currMousePos[1], currMousePos[2], this._PICK_POINT_RADIUS); |
352 | if (selAnchor >=0) { | 352 | if (selAnchorRetCode[0] >=0) { |
353 | this._hoveredAnchorIndex = selAnchor; | 353 | this._hoveredAnchorIndex = selAnchorRetCode[0]; |
354 | var cursor = "url('images/cursors/penCursors/Pen_anchorSelect.png') 0 0, default"; | ||
355 | this.application.ninja.stage.drawingCanvas.style.cursor = cursor; | ||
354 | } else { | 356 | } else { |
355 | //detect if the current mouse position will hit the path | 357 | //detect if the current mouse position will hit the path |
356 | var pathHitTestData = this._selectedSubpath.pathHitTest(currMousePos[0], currMousePos[1], currMousePos[2], this._PICK_POINT_RADIUS); | 358 | var pathHitTestData = this._selectedSubpath.pathHitTest(currMousePos[0], currMousePos[1], currMousePos[2], this._PICK_POINT_RADIUS); |
357 | if (pathHitTestData[0]!==-1){ | 359 | if (pathHitTestData[0]!==-1){ |
358 | //change the cursor | 360 | //change the cursor |
359 | var cursor = "url('images/cursors/penAdd.png') 10 10,default"; | 361 | |
360 | this.application.ninja.stage.drawingCanvas.style.cursor = cursor; | ||
361 | } | 362 | } |
362 | } | 363 | } |
363 | } | 364 | } |