Get the x and y coordinates of the button and the line/rectangle or whatever it cannot pass. Compare these x and y coordinates; do not move the button any further if it is at or past these coordinates.
VernonDozier commented: Good examples +12
darkagn commented: Good explanation of recursive calls with example pseudocode +4
BestJewSinceJC 700 Posting Maven