From ce72c9ec260d18cc127c275daf3ec1d18c230e2a Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 1 Jun 2023 10:22:50 -0600 Subject: expo: Use flags for objects We currently have just a 'hide' property for each object. In preparation for adding more properties, convert the struct to use a flags value, instead of individual booleans. This is more extensible. Signed-off-by: Simon Glass --- boot/scene.c | 17 +++++++++++++++-- boot/scene_internal.h | 11 +++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) (limited to 'boot') diff --git a/boot/scene.c b/boot/scene.c index 8033d77fb2..dd1472d4f9 100644 --- a/boot/scene.c +++ b/boot/scene.c @@ -208,13 +208,26 @@ int scene_obj_set_pos(struct scene *scn, uint id, int x, int y) } int scene_obj_set_hide(struct scene *scn, uint id, bool hide) +{ + int ret; + + ret = scene_obj_flag_clrset(scn, id, SCENEOF_HIDE, + hide ? SCENEOF_HIDE : 0); + if (ret) + return log_msg_ret("flg", ret); + + return 0; +} + +int scene_obj_flag_clrset(struct scene *scn, uint id, uint clr, uint set) { struct scene_obj *obj; obj = scene_obj_find(scn, id, SCENEOBJT_NONE); if (!obj) return log_msg_ret("find", -ENOENT); - obj->hide = hide; + obj->flags &= ~clr; + obj->flags |= set; return 0; } @@ -358,7 +371,7 @@ int scene_render(struct scene *scn) int ret; list_for_each_entry(obj, &scn->obj_head, sibling) { - if (!obj->hide) { + if (!(obj->flags & SCENEOF_HIDE)) { ret = scene_obj_render(obj, exp->text_mode); if (ret && ret != -ENOTSUPP) return log_msg_ret("ren", ret); diff --git a/boot/scene_internal.h b/boot/scene_internal.h index 9f173dd749..24a2ba6a6a 100644 --- a/boot/scene_internal.h +++ b/boot/scene_internal.h @@ -54,6 +54,17 @@ void *scene_obj_find(struct scene *scn, uint id, enum scene_obj_t type); int scene_obj_add(struct scene *scn, const char *name, uint id, enum scene_obj_t type, uint size, struct scene_obj **objp); +/** + * scene_obj_flag_clrset() - Adjust object flags + * + * @scn: Scene to update + * @id: ID of object to update + * @clr: Bits to clear in the object's flags + * @set: Bits to set in the object's flags + * Returns 0 if OK, -ENOENT if the object was not found + */ +int scene_obj_flag_clrset(struct scene *scn, uint id, uint clr, uint set); + /** * scene_menu_arrange() - Set the position of things in the menu * -- cgit v1.2.3