aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/sub-path.js
diff options
context:
space:
mode:
authorPushkar Joshi2012-03-27 15:40:37 -0700
committerPushkar Joshi2012-03-27 15:40:37 -0700
commit3fd098981077e40841c013a8ac305036d08a215b (patch)
treed8b52ee21ef7d9eb4a2d53e831bd526d4f4e0809 /js/lib/geom/sub-path.js
parent02a34df0ec3201199d209d43f621898b5607c150 (diff)
downloadninja-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
Diffstat (limited to 'js/lib/geom/sub-path.js')
-rwxr-xr-xjs/lib/geom/sub-path.js51
1 files changed, 32 insertions, 19 deletions
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
570GLSubpath.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
570GLSubpath.prototype.pickAnchor = function (pickX, pickY, pickZ, radius) { 588GLSubpath.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
600GLSubpath.prototype.isWithinBBox =function(x,y,z){ 613GLSubpath.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 }