[Concept,08/18] expo: Provide a version of scene_within() with takes an obj

Message ID 20251010034255.1099728-9-sjg@u-boot.org
State New
Headers
Series expo: Extend the boot menu |

Commit Message

Simon Glass Oct. 10, 2025, 3:42 a.m. UTC
  From: Simon Glass <sjg@chromium.org>

When the object pointer is already available we don't want to have to
look it up. Provide a new is_within() function which takes an object
pointer instead of an ID.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 boot/scene.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
  

Patch

diff --git a/boot/scene.c b/boot/scene.c
index c2e4d8e1330..c1ecbfcc67a 100644
--- a/boot/scene.c
+++ b/boot/scene.c
@@ -1129,6 +1129,22 @@  int scene_send_key(struct scene *scn, int key, struct expo_action *event)
 	return 0;
 }
 
+/**
+ * is_within() - check if a point is considered within an object ID
+ *
+ * @scn: Scene to check
+ * @obj: object to check
+ * @x: X coordinate of the point
+ * @y: Y coordinate of the point
+ * Return: true if the point is considered within the object, false if not
+ */
+static bool is_within(const struct scene_obj *obj, int x, int y)
+{
+	/* 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);
+}
+
 bool scene_within(const struct scene *scn, uint id, int x, int y)
 {
 	struct scene_obj *obj;
@@ -1141,9 +1157,7 @@  bool scene_within(const struct scene *scn, uint id, int x, int y)
 	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);
+	return is_within(obj, x, y);
 }
 
 bool scene_obj_within(const struct scene *scn, struct scene_obj *obj, int x,