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 | /** |
Simon Glass | 96910ef | 2025-05-02 08:46:34 -0600 | [diff] [blame^] | 17 | * enum scene_bbox_t - Parts of an object which can have a bounding box |
| 18 | * |
| 19 | * Objects can provide any or all of these bounding boxes |
| 20 | * |
| 21 | * @SCENEBB_label: Menu-item label |
| 22 | * @SCENEBB_key: Menu-item key label |
| 23 | * @SCENEBB_desc: Menu-item Description |
| 24 | * @SCENEBB_curitem: Current item (pointed to) |
| 25 | * @SCENEBB_all: All the above objects combined |
| 26 | */ |
| 27 | enum scene_bbox_t { |
| 28 | SCENEBB_label, |
| 29 | SCENEBB_key, |
| 30 | SCENEBB_desc, |
| 31 | SCENEBB_curitem, |
| 32 | SCENEBB_all, |
| 33 | |
| 34 | SCENEBB_count, |
| 35 | }; |
| 36 | |
| 37 | /** |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 38 | * expo_lookup_scene_id() - Look up a scene ID |
| 39 | * |
| 40 | * @exp: Expo to use |
| 41 | * @id: scene ID to look up |
| 42 | * Returns: Scene for that ID, or NULL if none |
| 43 | */ |
| 44 | struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id); |
| 45 | |
| 46 | /** |
| 47 | * resolve_id() - Automatically allocate an ID if needed |
| 48 | * |
| 49 | * @exp: Expo to use |
| 50 | * @id: ID to use, or 0 to auto-allocate one |
Simon Glass | c6e9f4c | 2023-06-01 10:22:26 -0600 | [diff] [blame] | 51 | * Returns: Either @id, or the auto-allocated ID |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 52 | */ |
| 53 | uint resolve_id(struct expo *exp, uint id); |
| 54 | |
| 55 | /** |
| 56 | * scene_obj_find() - Find an object in a scene |
| 57 | * |
| 58 | * Note that @type is used to restrict the search when the object type is known. |
| 59 | * If any type is acceptable, set @type to SCENEOBJT_NONE |
| 60 | * |
| 61 | * @scn: Scene to search |
| 62 | * @id: ID of object to find |
| 63 | * @type: Type of the object, or SCENEOBJT_NONE to match any type |
Simon Glass | c6e9f4c | 2023-06-01 10:22:26 -0600 | [diff] [blame] | 64 | * Returns: Object found, or NULL if not found |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 65 | */ |
Simon Glass | 45ff0bc | 2023-08-14 16:40:21 -0600 | [diff] [blame] | 66 | 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] | 67 | |
| 68 | /** |
Simon Glass | c892511 | 2023-06-01 10:23:02 -0600 | [diff] [blame] | 69 | * scene_obj_find_by_name() - Find an object in a scene by name |
| 70 | * |
| 71 | * @scn: Scene to search |
| 72 | * @name: Name to search for |
| 73 | */ |
| 74 | void *scene_obj_find_by_name(struct scene *scn, const char *name); |
| 75 | |
| 76 | /** |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 77 | * scene_obj_add() - Add a new object to a scene |
| 78 | * |
| 79 | * @scn: Scene to update |
| 80 | * @name: Name to use (this is allocated by this call) |
| 81 | * @id: ID to use for the new object (0 to allocate one) |
| 82 | * @type: Type of object to add |
| 83 | * @size: Size to allocate for the object, in bytes |
| 84 | * @objp: Returns a pointer to the new object (must not be NULL) |
| 85 | * Returns: ID number for the object (generally @id), or -ve on error |
| 86 | */ |
| 87 | int scene_obj_add(struct scene *scn, const char *name, uint id, |
| 88 | enum scene_obj_t type, uint size, struct scene_obj **objp); |
| 89 | |
| 90 | /** |
Simon Glass | 6081b0f | 2023-06-01 10:22:50 -0600 | [diff] [blame] | 91 | * scene_obj_flag_clrset() - Adjust object flags |
| 92 | * |
| 93 | * @scn: Scene to update |
| 94 | * @id: ID of object to update |
| 95 | * @clr: Bits to clear in the object's flags |
| 96 | * @set: Bits to set in the object's flags |
| 97 | * Returns 0 if OK, -ENOENT if the object was not found |
| 98 | */ |
| 99 | int scene_obj_flag_clrset(struct scene *scn, uint id, uint clr, uint set); |
| 100 | |
| 101 | /** |
Simon Glass | 7a96005 | 2023-06-01 10:22:52 -0600 | [diff] [blame] | 102 | * scene_calc_dims() - Calculate the dimensions of the scene objects |
| 103 | * |
| 104 | * Updates the width and height of all objects based on their contents |
| 105 | * |
| 106 | * @scn: Scene to update |
| 107 | * @do_menus: true to calculate only menus, false to calculate everything else |
| 108 | * Returns 0 if OK, -ENOTSUPP if there is no graphical console |
| 109 | */ |
| 110 | int scene_calc_dims(struct scene *scn, bool do_menus); |
| 111 | |
| 112 | /** |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 113 | * scene_menu_arrange() - Set the position of things in the menu |
| 114 | * |
| 115 | * This updates any items associated with a menu to make sure they are |
| 116 | * positioned correctly relative to the menu. It also selects the first item |
| 117 | * if not already done |
| 118 | * |
| 119 | * @scn: Scene to update |
Simon Glass | 377f18e | 2024-10-14 16:31:55 -0600 | [diff] [blame] | 120 | * @arr: Arrangement information |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 121 | * @menu: Menu to process |
Simon Glass | c6e9f4c | 2023-06-01 10:22:26 -0600 | [diff] [blame] | 122 | * Returns: 0 if OK, -ve on error |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 123 | */ |
Simon Glass | 377f18e | 2024-10-14 16:31:55 -0600 | [diff] [blame] | 124 | int scene_menu_arrange(struct scene *scn, struct expo_arrange_info *arr, |
| 125 | struct scene_obj_menu *menu); |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 126 | |
| 127 | /** |
Simon Glass | 0023d18 | 2023-10-01 19:13:34 -0600 | [diff] [blame] | 128 | * scene_textline_arrange() - Set the position of things in a textline |
| 129 | * |
| 130 | * This updates any items associated with a textline to make sure they are |
| 131 | * positioned correctly relative to the textline. |
| 132 | * |
| 133 | * @scn: Scene to update |
Simon Glass | 377f18e | 2024-10-14 16:31:55 -0600 | [diff] [blame] | 134 | * @arr: Arrangement information |
Simon Glass | 0023d18 | 2023-10-01 19:13:34 -0600 | [diff] [blame] | 135 | * @tline: textline to process |
| 136 | * Returns: 0 if OK, -ve on error |
| 137 | */ |
Simon Glass | 377f18e | 2024-10-14 16:31:55 -0600 | [diff] [blame] | 138 | int scene_textline_arrange(struct scene *scn, struct expo_arrange_info *arr, |
| 139 | struct scene_obj_textline *tline); |
Simon Glass | 0023d18 | 2023-10-01 19:13:34 -0600 | [diff] [blame] | 140 | |
| 141 | /** |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 142 | * scene_apply_theme() - Apply a theme to a scene |
| 143 | * |
| 144 | * @scn: Scene to update |
| 145 | * @theme: Theme to apply |
| 146 | * Returns: 0 if OK, -ve on error |
| 147 | */ |
| 148 | int scene_apply_theme(struct scene *scn, struct expo_theme *theme); |
| 149 | |
| 150 | /** |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 151 | * scene_menu_send_key() - Send a key to a menu for processing |
| 152 | * |
| 153 | * @scn: Scene to use |
| 154 | * @menu: Menu to use |
| 155 | * @key: Key code to send (KEY_...) |
| 156 | * @event: Place to put any event which is generated by the key |
Simon Glass | c6e9f4c | 2023-06-01 10:22:26 -0600 | [diff] [blame] | 157 | * 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] | 158 | * error |
| 159 | */ |
| 160 | int scene_menu_send_key(struct scene *scn, struct scene_obj_menu *menu, int key, |
| 161 | struct expo_action *event); |
| 162 | |
| 163 | /** |
Simon Glass | 0023d18 | 2023-10-01 19:13:34 -0600 | [diff] [blame] | 164 | * scene_textline_send_key() - Send a key to a textline for processing |
| 165 | * |
| 166 | * @scn: Scene to use |
| 167 | * @tline: textline to use |
| 168 | * @key: Key code to send (KEY_...) |
| 169 | * @event: Place to put any event which is generated by the key |
| 170 | * Returns: 0 if OK (always) |
| 171 | */ |
| 172 | int scene_textline_send_key(struct scene *scn, struct scene_obj_textline *tline, |
| 173 | int key, struct expo_action *event); |
| 174 | |
| 175 | /** |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 176 | * scene_menu_destroy() - Destroy a menu in a scene |
| 177 | * |
| 178 | * @scn: Scene to destroy |
| 179 | */ |
| 180 | void scene_menu_destroy(struct scene_obj_menu *menu); |
| 181 | |
| 182 | /** |
| 183 | * scene_menu_display() - Display a menu as text |
| 184 | * |
| 185 | * @menu: Menu to display |
Simon Glass | c6e9f4c | 2023-06-01 10:22:26 -0600 | [diff] [blame] | 186 | * Returns: 0 if OK, -ENOENT if @id is invalid |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 187 | */ |
| 188 | int scene_menu_display(struct scene_obj_menu *menu); |
| 189 | |
| 190 | /** |
| 191 | * scene_destroy() - Destroy a scene and all its memory |
| 192 | * |
| 193 | * @scn: Scene to destroy |
| 194 | */ |
| 195 | void scene_destroy(struct scene *scn); |
| 196 | |
| 197 | /** |
| 198 | * scene_render() - Render a scene |
| 199 | * |
| 200 | * This is called from expo_render() |
| 201 | * |
| 202 | * @scn: Scene to render |
| 203 | * Returns: 0 if OK, -ve on error |
| 204 | */ |
| 205 | int scene_render(struct scene *scn); |
| 206 | |
| 207 | /** |
| 208 | * scene_send_key() - set a keypress to a scene |
| 209 | * |
| 210 | * @scn: Scene to receive the key |
| 211 | * @key: Key to send (KEYCODE_UP) |
| 212 | * @event: Returns resulting event from this keypress |
| 213 | * Returns: 0 if OK, -ve on error |
| 214 | */ |
| 215 | int scene_send_key(struct scene *scn, int key, struct expo_action *event); |
| 216 | |
Simon Glass | 7a96005 | 2023-06-01 10:22:52 -0600 | [diff] [blame] | 217 | /** |
Simon Glass | 12f5773 | 2023-06-01 10:22:58 -0600 | [diff] [blame] | 218 | * scene_render_deps() - Render an object and its dependencies |
| 219 | * |
| 220 | * @scn: Scene to render |
| 221 | * @id: Object ID to render (or 0 for none) |
| 222 | * Returns: 0 if OK, -ve on error |
| 223 | */ |
| 224 | int scene_render_deps(struct scene *scn, uint id); |
| 225 | |
| 226 | /** |
| 227 | * scene_menu_render_deps() - Render a menu and its dependencies |
| 228 | * |
| 229 | * Renders the menu and all of its attached objects |
| 230 | * |
| 231 | * @scn: Scene to render |
Simon Glass | db6a051 | 2023-10-01 19:13:23 -0600 | [diff] [blame] | 232 | * @menu: Menu to render |
Simon Glass | 12f5773 | 2023-06-01 10:22:58 -0600 | [diff] [blame] | 233 | * Returns: 0 if OK, -ve on error |
| 234 | */ |
| 235 | int scene_menu_render_deps(struct scene *scn, struct scene_obj_menu *menu); |
| 236 | |
| 237 | /** |
Simon Glass | 0023d18 | 2023-10-01 19:13:34 -0600 | [diff] [blame] | 238 | * scene_textline_render_deps() - Render a textline and its dependencies |
| 239 | * |
| 240 | * Renders the textline and all of its attached objects |
| 241 | * |
| 242 | * @scn: Scene to render |
| 243 | * @tline: textline to render |
| 244 | * Returns: 0 if OK, -ve on error |
| 245 | */ |
| 246 | int scene_textline_render_deps(struct scene *scn, |
| 247 | struct scene_obj_textline *tline); |
| 248 | |
| 249 | /** |
Simon Glass | 7a96005 | 2023-06-01 10:22:52 -0600 | [diff] [blame] | 250 | * scene_menu_calc_dims() - Calculate the dimensions of a menu |
| 251 | * |
| 252 | * Updates the width and height of the menu based on its contents |
| 253 | * |
| 254 | * @menu: Menu to update |
| 255 | * Returns 0 if OK, -ENOTSUPP if there is no graphical console |
| 256 | */ |
| 257 | int scene_menu_calc_dims(struct scene_obj_menu *menu); |
| 258 | |
Simon Glass | e90acd8 | 2023-08-14 16:40:23 -0600 | [diff] [blame] | 259 | /** |
| 260 | * scene_iter_objs() - Iterate through all scene objects |
| 261 | * |
| 262 | * @scn: Scene to process |
| 263 | * @iter: Iterator to call on each object |
| 264 | * @priv: Private data to pass to the iterator, in addition to the object |
| 265 | * Return: 0 if OK, -ve on error |
| 266 | */ |
| 267 | int scene_iter_objs(struct scene *scn, expo_scene_obj_iterator iter, |
| 268 | void *priv); |
| 269 | |
| 270 | /** |
| 271 | * expo_iter_scene_objects() - Iterate through all scene objects |
| 272 | * |
| 273 | * @exp: Expo to process |
| 274 | * @iter: Iterator to call on each object |
| 275 | * @priv: Private data to pass to the iterator, in addition to the object |
| 276 | * Return: 0 if OK, -ve on error |
| 277 | */ |
| 278 | int expo_iter_scene_objs(struct expo *exp, expo_scene_obj_iterator iter, |
| 279 | void *priv); |
| 280 | |
Simon Glass | 5fd4f78 | 2023-08-14 16:40:32 -0600 | [diff] [blame] | 281 | /** |
| 282 | * scene_menuitem_find() - Find the menu item for an ID |
| 283 | * |
| 284 | * Looks up the menu to find the item with the given ID |
| 285 | * |
| 286 | * @menu: Menu to check |
| 287 | * @id: ID to look for |
| 288 | * Return: Menu item, or NULL if not found |
| 289 | */ |
| 290 | struct scene_menitem *scene_menuitem_find(const struct scene_obj_menu *menu, |
| 291 | int id); |
| 292 | |
Simon Glass | 4462fa3 | 2023-08-14 16:40:38 -0600 | [diff] [blame] | 293 | /** |
| 294 | * scene_menuitem_find_seq() - Find the menu item at a sequential position |
| 295 | * |
| 296 | * This numbers the items from 0 and returns the seq'th one |
| 297 | * |
| 298 | * @menu: Menu to check |
| 299 | * @seq: Sequence number to look for |
| 300 | * Return: menu item if found, else NULL |
| 301 | */ |
| 302 | struct scene_menitem *scene_menuitem_find_seq(const struct scene_obj_menu *menu, |
| 303 | uint seq); |
| 304 | |
Simon Glass | f099469 | 2023-10-01 19:13:29 -0600 | [diff] [blame] | 305 | /** |
Simon Glass | 100389f | 2024-10-14 16:31:58 -0600 | [diff] [blame] | 306 | * scene_menuitem_find_val() - Find the menu item with a given value |
| 307 | * |
| 308 | * @menu: Menu to check |
| 309 | * @find_val: Value to look for |
| 310 | * Return: menu item if found, else NULL |
| 311 | */ |
| 312 | struct scene_menitem *scene_menuitem_find_val(const struct scene_obj_menu *menu, |
| 313 | int val); |
| 314 | |
| 315 | /** |
Simon Glass | 96910ef | 2025-05-02 08:46:34 -0600 | [diff] [blame^] | 316 | * scene_bbox_join() - update bouding box with a given src box |
| 317 | * |
| 318 | * Updates @dst so that it encompasses the bounding box @src |
| 319 | * |
| 320 | * @src: Input bounding box |
| 321 | * @inset: Amount of inset to use for width |
| 322 | * @dst: Bounding box to update |
| 323 | * Return: 0 if OK, -ve on error |
| 324 | */ |
| 325 | int scene_bbox_join(const struct vidconsole_bbox *src, int inset, |
| 326 | struct vidconsole_bbox *dst); |
| 327 | |
| 328 | /** |
Simon Glass | f099469 | 2023-10-01 19:13:29 -0600 | [diff] [blame] | 329 | * scene_bbox_union() - update bouding box with the demensions of an object |
| 330 | * |
| 331 | * Updates @bbox so that it encompasses the bounding box of object @id |
| 332 | * |
| 333 | * @snd: Scene containing object |
| 334 | * @id: Object id |
| 335 | * @inset: Amount of inset to use for width |
| 336 | * @bbox: Bounding box to update |
| 337 | * Return: 0 if OK, -ve on error |
| 338 | */ |
| 339 | int scene_bbox_union(struct scene *scn, uint id, int inset, |
| 340 | struct vidconsole_bbox *bbox); |
| 341 | |
| 342 | /** |
Simon Glass | 0023d18 | 2023-10-01 19:13:34 -0600 | [diff] [blame] | 343 | * scene_textline_calc_dims() - Calculate the dimensions of a textline |
| 344 | * |
| 345 | * Updates the width and height of the textline based on its contents |
| 346 | * |
| 347 | * @tline: Textline to update |
| 348 | * Returns 0 if OK, -ENOTSUPP if there is no graphical console |
| 349 | */ |
| 350 | int scene_textline_calc_dims(struct scene_obj_textline *tline); |
| 351 | |
| 352 | /** |
Simon Glass | f099469 | 2023-10-01 19:13:29 -0600 | [diff] [blame] | 353 | * scene_menu_calc_bbox() - Calculate bounding boxes for the menu |
| 354 | * |
| 355 | * @menu: Menu to process |
Simon Glass | 96910ef | 2025-05-02 08:46:34 -0600 | [diff] [blame^] | 356 | * @bbox: List of bounding box to fill in |
Simon Glass | f099469 | 2023-10-01 19:13:29 -0600 | [diff] [blame] | 357 | * Return: 0 if OK, -ve on error |
| 358 | */ |
| 359 | void scene_menu_calc_bbox(struct scene_obj_menu *menu, |
Simon Glass | 96910ef | 2025-05-02 08:46:34 -0600 | [diff] [blame^] | 360 | struct vidconsole_bbox *bbox); |
Simon Glass | f099469 | 2023-10-01 19:13:29 -0600 | [diff] [blame] | 361 | |
| 362 | /** |
Simon Glass | 0023d18 | 2023-10-01 19:13:34 -0600 | [diff] [blame] | 363 | * scene_textline_calc_bbox() - Calculate bounding box for the textline |
| 364 | * |
| 365 | * @textline: Menu to process |
| 366 | * @bbox: Returns bounding box of textline including prompt |
| 367 | * @edit_bbox: Returns bounding box of editable part |
| 368 | * Return: 0 if OK, -ve on error |
| 369 | */ |
| 370 | void scene_textline_calc_bbox(struct scene_obj_textline *menu, |
| 371 | struct vidconsole_bbox *bbox, |
| 372 | struct vidconsole_bbox *label_bbox); |
| 373 | |
| 374 | /** |
Simon Glass | f099469 | 2023-10-01 19:13:29 -0600 | [diff] [blame] | 375 | * scene_obj_calc_bbox() - Calculate bounding boxes for an object |
| 376 | * |
| 377 | * @obj: Object to process |
Simon Glass | 96910ef | 2025-05-02 08:46:34 -0600 | [diff] [blame^] | 378 | * @bbox: Returns bounding boxes for object |
Simon Glass | f099469 | 2023-10-01 19:13:29 -0600 | [diff] [blame] | 379 | * Return: 0 if OK, -ve on error |
| 380 | */ |
Simon Glass | 96910ef | 2025-05-02 08:46:34 -0600 | [diff] [blame^] | 381 | int scene_obj_calc_bbox(struct scene_obj *obj, struct vidconsole_bbox *bbox); |
Simon Glass | f099469 | 2023-10-01 19:13:29 -0600 | [diff] [blame] | 382 | |
Simon Glass | f6a943a | 2023-10-01 19:13:33 -0600 | [diff] [blame] | 383 | /** |
| 384 | * scene_textline_open() - Open a textline object |
| 385 | * |
| 386 | * Set up the text editor ready for use |
| 387 | * |
| 388 | * @scn: Scene containing the textline |
| 389 | * @tline: textline object |
| 390 | * Return: 0 if OK, -ve on error |
| 391 | */ |
| 392 | int scene_textline_open(struct scene *scn, struct scene_obj_textline *tline); |
| 393 | |
| 394 | /** |
| 395 | * scene_textline_close() - Close a textline object |
| 396 | * |
| 397 | * Close out the text editor after use |
| 398 | * |
| 399 | * @scn: Scene containing the textline |
| 400 | * @tline: textline object |
| 401 | * Return: 0 if OK, -ve on error |
| 402 | */ |
| 403 | int scene_textline_close(struct scene *scn, struct scene_obj_textline *tline); |
| 404 | |
Simon Glass | 377f18e | 2024-10-14 16:31:55 -0600 | [diff] [blame] | 405 | /** |
| 406 | * scene_calc_arrange() - Calculate sizes needed to arrange a scene |
| 407 | * |
| 408 | * Checks the size of some objects and stores this info to help with a later |
| 409 | * scene arrangement |
| 410 | * |
| 411 | * @scn: Scene to check |
| 412 | * @arr: Place to put scene-arrangement info |
| 413 | * Returns: 0 if OK, -ve on error |
| 414 | */ |
| 415 | int scene_calc_arrange(struct scene *scn, struct expo_arrange_info *arr); |
| 416 | |
Simon Glass | 0a4d14b | 2023-01-06 08:52:37 -0600 | [diff] [blame] | 417 | #endif /* __SCENE_INTERNAL_H */ |