Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * Internal header file for scenes |
| 4 | * |
| 5 | * Copyright 2022 Google LLC |
| 6 | * Written by Simon Glass <sjg@chromium.org> |
| 7 | */ |
| 8 | |
| 9 | #ifndef __SCENE_INTERNAL_H |
| 10 | #define __SCENE_INTERNAL_H |
| 11 | |
Simon Glass | f099469 | 2023-10-01 19:13:29 -0600 | [diff] [blame^] | 12 | struct vidconsole_bbox; |
| 13 | |
Simon Glass | e90acd8 | 2023-08-14 16:40:23 -0600 | [diff] [blame] | 14 | typedef int (*expo_scene_obj_iterator)(struct scene_obj *obj, void *priv); |
| 15 | |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 16 | /** |
| 17 | * expo_lookup_scene_id() - Look up a scene ID |
| 18 | * |
| 19 | * @exp: Expo to use |
| 20 | * @id: scene ID to look up |
| 21 | * Returns: Scene for that ID, or NULL if none |
| 22 | */ |
| 23 | struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id); |
| 24 | |
| 25 | /** |
| 26 | * resolve_id() - Automatically allocate an ID if needed |
| 27 | * |
| 28 | * @exp: Expo to use |
| 29 | * @id: ID to use, or 0 to auto-allocate one |
Simon Glass | c6e9f4c | 2023-06-01 10:22:26 -0600 | [diff] [blame] | 30 | * Returns: Either @id, or the auto-allocated ID |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 31 | */ |
| 32 | uint resolve_id(struct expo *exp, uint id); |
| 33 | |
| 34 | /** |
| 35 | * scene_obj_find() - Find an object in a scene |
| 36 | * |
| 37 | * Note that @type is used to restrict the search when the object type is known. |
| 38 | * If any type is acceptable, set @type to SCENEOBJT_NONE |
| 39 | * |
| 40 | * @scn: Scene to search |
| 41 | * @id: ID of object to find |
| 42 | * @type: Type of the object, or SCENEOBJT_NONE to match any type |
Simon Glass | c6e9f4c | 2023-06-01 10:22:26 -0600 | [diff] [blame] | 43 | * Returns: Object found, or NULL if not found |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 44 | */ |
Simon Glass | 45ff0bc | 2023-08-14 16:40:21 -0600 | [diff] [blame] | 45 | void *scene_obj_find(const struct scene *scn, uint id, enum scene_obj_t type); |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 46 | |
| 47 | /** |
Simon Glass | c892511 | 2023-06-01 10:23:02 -0600 | [diff] [blame] | 48 | * scene_obj_find_by_name() - Find an object in a scene by name |
| 49 | * |
| 50 | * @scn: Scene to search |
| 51 | * @name: Name to search for |
| 52 | */ |
| 53 | void *scene_obj_find_by_name(struct scene *scn, const char *name); |
| 54 | |
| 55 | /** |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 56 | * scene_obj_add() - Add a new object to a scene |
| 57 | * |
| 58 | * @scn: Scene to update |
| 59 | * @name: Name to use (this is allocated by this call) |
| 60 | * @id: ID to use for the new object (0 to allocate one) |
| 61 | * @type: Type of object to add |
| 62 | * @size: Size to allocate for the object, in bytes |
| 63 | * @objp: Returns a pointer to the new object (must not be NULL) |
| 64 | * Returns: ID number for the object (generally @id), or -ve on error |
| 65 | */ |
| 66 | int scene_obj_add(struct scene *scn, const char *name, uint id, |
| 67 | enum scene_obj_t type, uint size, struct scene_obj **objp); |
| 68 | |
| 69 | /** |
Simon Glass | 6081b0f | 2023-06-01 10:22:50 -0600 | [diff] [blame] | 70 | * scene_obj_flag_clrset() - Adjust object flags |
| 71 | * |
| 72 | * @scn: Scene to update |
| 73 | * @id: ID of object to update |
| 74 | * @clr: Bits to clear in the object's flags |
| 75 | * @set: Bits to set in the object's flags |
| 76 | * Returns 0 if OK, -ENOENT if the object was not found |
| 77 | */ |
| 78 | int scene_obj_flag_clrset(struct scene *scn, uint id, uint clr, uint set); |
| 79 | |
| 80 | /** |
Simon Glass | 7a96005 | 2023-06-01 10:22:52 -0600 | [diff] [blame] | 81 | * scene_calc_dims() - Calculate the dimensions of the scene objects |
| 82 | * |
| 83 | * Updates the width and height of all objects based on their contents |
| 84 | * |
| 85 | * @scn: Scene to update |
| 86 | * @do_menus: true to calculate only menus, false to calculate everything else |
| 87 | * Returns 0 if OK, -ENOTSUPP if there is no graphical console |
| 88 | */ |
| 89 | int scene_calc_dims(struct scene *scn, bool do_menus); |
| 90 | |
| 91 | /** |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 92 | * scene_menu_arrange() - Set the position of things in the menu |
| 93 | * |
| 94 | * This updates any items associated with a menu to make sure they are |
| 95 | * positioned correctly relative to the menu. It also selects the first item |
| 96 | * if not already done |
| 97 | * |
| 98 | * @scn: Scene to update |
| 99 | * @menu: Menu to process |
Simon Glass | c6e9f4c | 2023-06-01 10:22:26 -0600 | [diff] [blame] | 100 | * Returns: 0 if OK, -ve on error |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 101 | */ |
| 102 | int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu); |
| 103 | |
| 104 | /** |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 105 | * scene_apply_theme() - Apply a theme to a scene |
| 106 | * |
| 107 | * @scn: Scene to update |
| 108 | * @theme: Theme to apply |
| 109 | * Returns: 0 if OK, -ve on error |
| 110 | */ |
| 111 | int scene_apply_theme(struct scene *scn, struct expo_theme *theme); |
| 112 | |
| 113 | /** |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 114 | * scene_menu_send_key() - Send a key to a menu for processing |
| 115 | * |
| 116 | * @scn: Scene to use |
| 117 | * @menu: Menu to use |
| 118 | * @key: Key code to send (KEY_...) |
| 119 | * @event: Place to put any event which is generated by the key |
Simon Glass | c6e9f4c | 2023-06-01 10:22:26 -0600 | [diff] [blame] | 120 | * Returns: 0 if OK, -ENOTTY if there is no current menu item, other -ve on other |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 121 | * error |
| 122 | */ |
| 123 | int scene_menu_send_key(struct scene *scn, struct scene_obj_menu *menu, int key, |
| 124 | struct expo_action *event); |
| 125 | |
| 126 | /** |
| 127 | * scene_menu_destroy() - Destroy a menu in a scene |
| 128 | * |
| 129 | * @scn: Scene to destroy |
| 130 | */ |
| 131 | void scene_menu_destroy(struct scene_obj_menu *menu); |
| 132 | |
| 133 | /** |
| 134 | * scene_menu_display() - Display a menu as text |
| 135 | * |
| 136 | * @menu: Menu to display |
Simon Glass | c6e9f4c | 2023-06-01 10:22:26 -0600 | [diff] [blame] | 137 | * Returns: 0 if OK, -ENOENT if @id is invalid |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 138 | */ |
| 139 | int scene_menu_display(struct scene_obj_menu *menu); |
| 140 | |
| 141 | /** |
| 142 | * scene_destroy() - Destroy a scene and all its memory |
| 143 | * |
| 144 | * @scn: Scene to destroy |
| 145 | */ |
| 146 | void scene_destroy(struct scene *scn); |
| 147 | |
| 148 | /** |
| 149 | * scene_render() - Render a scene |
| 150 | * |
| 151 | * This is called from expo_render() |
| 152 | * |
| 153 | * @scn: Scene to render |
| 154 | * Returns: 0 if OK, -ve on error |
| 155 | */ |
| 156 | int scene_render(struct scene *scn); |
| 157 | |
| 158 | /** |
| 159 | * scene_send_key() - set a keypress to a scene |
| 160 | * |
| 161 | * @scn: Scene to receive the key |
| 162 | * @key: Key to send (KEYCODE_UP) |
| 163 | * @event: Returns resulting event from this keypress |
| 164 | * Returns: 0 if OK, -ve on error |
| 165 | */ |
| 166 | int scene_send_key(struct scene *scn, int key, struct expo_action *event); |
| 167 | |
Simon Glass | 7a96005 | 2023-06-01 10:22:52 -0600 | [diff] [blame] | 168 | /** |
Simon Glass | 01922ec | 2023-06-01 10:22:57 -0600 | [diff] [blame] | 169 | * scene_menu_render() - Render the background behind a menu |
| 170 | * |
| 171 | * @menu: Menu to render |
| 172 | */ |
| 173 | void scene_menu_render(struct scene_obj_menu *menu); |
| 174 | |
| 175 | /** |
Simon Glass | 12f5773 | 2023-06-01 10:22:58 -0600 | [diff] [blame] | 176 | * scene_render_deps() - Render an object and its dependencies |
| 177 | * |
| 178 | * @scn: Scene to render |
| 179 | * @id: Object ID to render (or 0 for none) |
| 180 | * Returns: 0 if OK, -ve on error |
| 181 | */ |
| 182 | int scene_render_deps(struct scene *scn, uint id); |
| 183 | |
| 184 | /** |
| 185 | * scene_menu_render_deps() - Render a menu and its dependencies |
| 186 | * |
| 187 | * Renders the menu and all of its attached objects |
| 188 | * |
| 189 | * @scn: Scene to render |
Simon Glass | db6a051 | 2023-10-01 19:13:23 -0600 | [diff] [blame] | 190 | * @menu: Menu to render |
Simon Glass | 12f5773 | 2023-06-01 10:22:58 -0600 | [diff] [blame] | 191 | * Returns: 0 if OK, -ve on error |
| 192 | */ |
| 193 | int scene_menu_render_deps(struct scene *scn, struct scene_obj_menu *menu); |
| 194 | |
| 195 | /** |
Simon Glass | 7a96005 | 2023-06-01 10:22:52 -0600 | [diff] [blame] | 196 | * scene_menu_calc_dims() - Calculate the dimensions of a menu |
| 197 | * |
| 198 | * Updates the width and height of the menu based on its contents |
| 199 | * |
| 200 | * @menu: Menu to update |
| 201 | * Returns 0 if OK, -ENOTSUPP if there is no graphical console |
| 202 | */ |
| 203 | int scene_menu_calc_dims(struct scene_obj_menu *menu); |
| 204 | |
Simon Glass | e90acd8 | 2023-08-14 16:40:23 -0600 | [diff] [blame] | 205 | /** |
| 206 | * scene_iter_objs() - Iterate through all scene objects |
| 207 | * |
| 208 | * @scn: Scene to process |
| 209 | * @iter: Iterator to call on each object |
| 210 | * @priv: Private data to pass to the iterator, in addition to the object |
| 211 | * Return: 0 if OK, -ve on error |
| 212 | */ |
| 213 | int scene_iter_objs(struct scene *scn, expo_scene_obj_iterator iter, |
| 214 | void *priv); |
| 215 | |
| 216 | /** |
| 217 | * expo_iter_scene_objects() - Iterate through all scene objects |
| 218 | * |
| 219 | * @exp: Expo to process |
| 220 | * @iter: Iterator to call on each object |
| 221 | * @priv: Private data to pass to the iterator, in addition to the object |
| 222 | * Return: 0 if OK, -ve on error |
| 223 | */ |
| 224 | int expo_iter_scene_objs(struct expo *exp, expo_scene_obj_iterator iter, |
| 225 | void *priv); |
| 226 | |
Simon Glass | 5fd4f78 | 2023-08-14 16:40:32 -0600 | [diff] [blame] | 227 | /** |
| 228 | * scene_menuitem_find() - Find the menu item for an ID |
| 229 | * |
| 230 | * Looks up the menu to find the item with the given ID |
| 231 | * |
| 232 | * @menu: Menu to check |
| 233 | * @id: ID to look for |
| 234 | * Return: Menu item, or NULL if not found |
| 235 | */ |
| 236 | struct scene_menitem *scene_menuitem_find(const struct scene_obj_menu *menu, |
| 237 | int id); |
| 238 | |
Simon Glass | 4462fa3 | 2023-08-14 16:40:38 -0600 | [diff] [blame] | 239 | /** |
| 240 | * scene_menuitem_find_seq() - Find the menu item at a sequential position |
| 241 | * |
| 242 | * This numbers the items from 0 and returns the seq'th one |
| 243 | * |
| 244 | * @menu: Menu to check |
| 245 | * @seq: Sequence number to look for |
| 246 | * Return: menu item if found, else NULL |
| 247 | */ |
| 248 | struct scene_menitem *scene_menuitem_find_seq(const struct scene_obj_menu *menu, |
| 249 | uint seq); |
| 250 | |
Simon Glass | f099469 | 2023-10-01 19:13:29 -0600 | [diff] [blame^] | 251 | /** |
| 252 | * scene_bbox_union() - update bouding box with the demensions of an object |
| 253 | * |
| 254 | * Updates @bbox so that it encompasses the bounding box of object @id |
| 255 | * |
| 256 | * @snd: Scene containing object |
| 257 | * @id: Object id |
| 258 | * @inset: Amount of inset to use for width |
| 259 | * @bbox: Bounding box to update |
| 260 | * Return: 0 if OK, -ve on error |
| 261 | */ |
| 262 | int scene_bbox_union(struct scene *scn, uint id, int inset, |
| 263 | struct vidconsole_bbox *bbox); |
| 264 | |
| 265 | /** |
| 266 | * scene_menu_calc_bbox() - Calculate bounding boxes for the menu |
| 267 | * |
| 268 | * @menu: Menu to process |
| 269 | * @bbox: Returns bounding box of menu including prompts |
| 270 | * @label_bbox: Returns bounding box of labels |
| 271 | * Return: 0 if OK, -ve on error |
| 272 | */ |
| 273 | void scene_menu_calc_bbox(struct scene_obj_menu *menu, |
| 274 | struct vidconsole_bbox *bbox, |
| 275 | struct vidconsole_bbox *label_bbox); |
| 276 | |
| 277 | /** |
| 278 | * scene_obj_calc_bbox() - Calculate bounding boxes for an object |
| 279 | * |
| 280 | * @obj: Object to process |
| 281 | * @bbox: Returns bounding box of object including prompts |
| 282 | * @label_bbox: Returns bounding box of labels (active area) |
| 283 | * Return: 0 if OK, -ve on error |
| 284 | */ |
| 285 | int scene_obj_calc_bbox(struct scene_obj *obj, struct vidconsole_bbox *bbox, |
| 286 | struct vidconsole_bbox *label_bbox); |
| 287 | |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 288 | #endif /* __SCENE_INTERNAL_H */ |