How are you drawing the lines? Straight or curved? If this is in Cocoa you can implement event handlers to get mouse click events, convert the coordinates from window to view and then use some maths to check the coordinates against the line coordinates....
However, my lines can have multiple (straight) segments so how would I handle that best? Do I have to loop through every segment of every line? That would take ages!
However, my lines can have multiple (straight) segments so how would I handle that best? Do I have to loop through every segment of every line? That would take ages!
Yes, although the normal way to speed this up would be to use a bounding box calculation to quickly check if the pointer is even close to the line: basically work out a rectangle that will contain the line then check if the pointer is in that. This should be fast enough to be close to "free". If you have a concept of z so you want to select the topmost line it should be reasonably easy to build a small array of lines that the pointer could have clicked and iterate down them in z order. Unless you have millions of lines to check you should be able to do this quickly.
However, my lines can have multiple (straight) segments so how would I handle that best? Do I have to loop through every segment of every line? That would take ages!
How many line segments are you anticipating? Looping through a couple hundreds segments would be instantaneous on any computer made in the last ten years.