Code: Select all
x >= minX && x <= maxX && y >= minY && y <= maxY
But testing if I'm clicking on an element becomes more complicated. How do people solve this?
Some ideas I've had:
1) Custom math for every widget. e.g. For a button with curved borders, I could do a basic bounding box test, but then if I fall within the 4 corners where it could be curved, do extra math (distance from the quarter-circle's center point to see that we fall within the curve radius.)
2) Don't care about pixel perfection and just use a rectangular bounding box around everything. Might not be noticable with slight curved edges, although round buttons would be obvious.
3) Have a secondary "click target" buffer, where each pixel isn't a color but a widget index (which could be a pointer), and anytime I draw a widget that is clickable, I make sure to draw the widget in the same shape (with anti-aliasing turned off) to the "click target" buffer in a solid color, where the color is the widget ID. This would give me super fast lookup of whatever is under any pixel on the screen (I'd support arbitrary polygons), but at the expense of more memory and slower drawing.