expo: Provide a way to check if a position is within a menu

To implement mouse clicks we need a way to figure out what the user has
clicked on. As a starting point, create a scene_menu_within() function
which returns the item containing an x, y coordinate.

Provide a helper function in scene.c for use with this. Add a simple
for completeness.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-09-14 17:36:27 -06:00
parent c65b6e50cf
commit 1e65b5e22e
4 changed files with 121 additions and 0 deletions

View File

@@ -1028,6 +1028,23 @@ int scene_send_key(struct scene *scn, int key, struct expo_action *event)
return 0;
}
bool scene_within(const struct scene *scn, uint id, int x, int y)
{
struct scene_obj *obj;
obj = scene_obj_find(scn, id, SCENEOBJT_NONE);
if (!obj) {
log_debug("Cannot find id %d\n", id);
return false;
}
log_debug("- id %d: '%s' bbox x0 %d y0 %d x1 %d y1 %d\n", id, obj->name,
obj->bbox.x0, obj->bbox.y0, obj->bbox.x1, obj->bbox.x1);
/* Check if point (x, y) is within object's bounding box */
return (x >= obj->bbox.x0 && x <= obj->bbox.x1 &&
y >= obj->bbox.y0 && y <= obj->bbox.y1);
}
int scene_obj_calc_bbox(struct scene_obj *obj, struct vidconsole_bbox bbox[])
{
switch (obj->type) {