feat: Add AABB/hit testing foundation (#138)

C++ additions:
- get_global_bounds(): returns bounds in screen coordinates
- contains_point(x, y): hit test using global bounds

Python properties (on all UIDrawable types):
- bounds: (x, y, w, h) tuple in local coordinates
- global_bounds: (x, y, w, h) tuple in screen coordinates

These enable the mouse event system (#140, #141, #142) by providing
a way to determine which drawable is under the mouse cursor.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
John McCardle 2025-11-27 22:36:08 -05:00
commit 6d5a5e9e16
4 changed files with 236 additions and 0 deletions

View file

@ -97,6 +97,10 @@ public:
static PyObject* get_parent(PyObject* self, void* closure);
static int set_parent(PyObject* self, PyObject* value, void* closure);
static PyObject* get_global_pos(PyObject* self, void* closure);
// Python API for hit testing (#138)
static PyObject* get_bounds_py(PyObject* self, void* closure);
static PyObject* get_global_bounds_py(PyObject* self, void* closure);
// New properties for Phase 1
bool visible = true; // #87 - visibility flag
@ -106,6 +110,10 @@ public:
virtual sf::FloatRect get_bounds() const = 0; // #89 - get bounding box
virtual void move(float dx, float dy) = 0; // #98 - move by offset
virtual void resize(float w, float h) = 0; // #98 - resize to dimensions
// Hit testing (#138)
sf::FloatRect get_global_bounds() const; // Bounds in screen coordinates
bool contains_point(float x, float y) const; // Hit test using global bounds
// Called when position changes to allow derived classes to sync
virtual void onPositionChanged() {}