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