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:
17
boot/scene.c
17
boot/scene.c
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user