-
-
Save danieljfarrell/4561386 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSPoint ConstrainPointInsideRect(CGPoint freePoint, NSRect boundaryRect) | |
{ | |
//NSPoint constrainedViewPoint = DFConstrainPointToRect(viewPoint, boundaryRect); | |
// Make sure the handle cannot be dragged outside of the plot range | |
if (NSPointInRect(freePoint, boundaryRect)) { | |
return freePoint; | |
} | |
NSPoint cp = freePoint; | |
NSRect br = boundaryRect; | |
if (freePoint.x <= NSMinX(br) && freePoint.y <= NSMinY(br) ) { | |
cp.x = br.origin.x; cp.y = br.origin.y; } | |
else if (freePoint.x <= NSMinX(br) && freePoint.y >= NSMaxY(br)) { | |
cp.x = NSMinX(br); cp.y = NSMaxY(br); } | |
else if (freePoint.x >= NSMaxX(br) && freePoint.y <= NSMinY(br)) { | |
cp.x = NSMaxX(br); cp.y = NSMinY(br); } | |
else if (freePoint.x >= NSMaxX(br) && freePoint.y >= NSMaxY(br)) { | |
cp.x = NSMaxX(br); cp.y = NSMaxY(br); } | |
else if (freePoint.x <= NSMinX(br)) | |
cp.x = NSMinX(br); | |
else if (freePoint.x > NSMaxX(br)) | |
cp.x = NSMaxX(br); | |
else if (freePoint.y <= NSMinY(br)) | |
cp.y = NSMinY(br); | |
else // y > NSMaxY | |
cp.y = NSMaxY(br); | |
return cp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment