Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * Copyright 2022 Google LLC |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
| 5 | */ |
| 6 | |
| 7 | #ifndef __SCENE_H |
| 8 | #define __SCENE_H |
| 9 | |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 10 | #include <dm/ofnode_decl.h> |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | |
| 13 | struct udevice; |
| 14 | |
| 15 | /** |
| 16 | * enum expoact_type - types of actions reported by the expo |
| 17 | * |
| 18 | * @EXPOACT_NONE: no action |
Simon Glass | 719a3c6 | 2023-06-01 10:22:56 -0600 | [diff] [blame^] | 19 | * @EXPOACT_POINT_ITEM: menu item was highlighted (@id indicates which) |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 20 | * @EXPOACT_SELECT: menu item was selected (@id indicates which) |
| 21 | * @EXPOACT_QUIT: request to exit the menu |
| 22 | */ |
| 23 | enum expoact_type { |
| 24 | EXPOACT_NONE, |
Simon Glass | 719a3c6 | 2023-06-01 10:22:56 -0600 | [diff] [blame^] | 25 | EXPOACT_POINT_ITEM, |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 26 | EXPOACT_SELECT, |
| 27 | EXPOACT_QUIT, |
| 28 | }; |
| 29 | |
| 30 | /** |
| 31 | * struct expo_action - an action report by the expo |
| 32 | * |
| 33 | * @type: Action type (EXPOACT_NONE if there is no action) |
Simon Glass | 719a3c6 | 2023-06-01 10:22:56 -0600 | [diff] [blame^] | 34 | * @select: Used for EXPOACT_POINT_ITEM and EXPOACT_SELECT |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 35 | * @id: ID number of the object affected. |
| 36 | */ |
| 37 | struct expo_action { |
| 38 | enum expoact_type type; |
| 39 | union { |
| 40 | struct { |
| 41 | int id; |
| 42 | } select; |
| 43 | }; |
| 44 | }; |
| 45 | |
| 46 | /** |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 47 | * struct expo_theme - theme for the expo |
| 48 | * |
| 49 | * @font_size: Default font size for all text |
| 50 | * @menu_inset: Inset width (on each side and top/bottom) for menu items |
| 51 | * @menuitem_gap_y: Gap between menu items in pixels |
| 52 | */ |
| 53 | struct expo_theme { |
| 54 | u32 font_size; |
| 55 | u32 menu_inset; |
| 56 | u32 menuitem_gap_y; |
| 57 | }; |
| 58 | |
| 59 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 60 | * struct expo - information about an expo |
| 61 | * |
| 62 | * A group of scenes which can be presented to the user, typically to obtain |
| 63 | * input or to make a selection. |
| 64 | * |
| 65 | * @name: Name of the expo (allocated) |
| 66 | * @display: Display to use (`UCLASS_VIDEO`), or NULL to use text mode |
Simon Glass | 67e2af1 | 2023-06-01 10:22:34 -0600 | [diff] [blame] | 67 | * @cons: Console to use (`UCLASS_VIDEO_CONSOLE`), or NULL to use text mode |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 68 | * @scene_id: Current scene ID (0 if none) |
| 69 | * @next_id: Next ID number to use, for automatic allocation |
| 70 | * @action: Action selected by user. At present only one is supported, with the |
| 71 | * type set to EXPOACT_NONE if there is no action |
| 72 | * @text_mode: true to use text mode for the menu (no vidconsole) |
Simon Glass | d353b75 | 2023-06-01 10:22:55 -0600 | [diff] [blame] | 73 | * @popup: true to use popup menus, instead of showing all items |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 74 | * @priv: Private data for the controller |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 75 | * @theme: Information about fonts styles, etc. |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 76 | * @scene_head: List of scenes |
| 77 | * @str_head: list of strings |
| 78 | */ |
| 79 | struct expo { |
| 80 | char *name; |
| 81 | struct udevice *display; |
Simon Glass | 67e2af1 | 2023-06-01 10:22:34 -0600 | [diff] [blame] | 82 | struct udevice *cons; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 83 | uint scene_id; |
| 84 | uint next_id; |
| 85 | struct expo_action action; |
| 86 | bool text_mode; |
Simon Glass | d353b75 | 2023-06-01 10:22:55 -0600 | [diff] [blame] | 87 | bool popup; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 88 | void *priv; |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 89 | struct expo_theme theme; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 90 | struct list_head scene_head; |
| 91 | struct list_head str_head; |
| 92 | }; |
| 93 | |
| 94 | /** |
| 95 | * struct expo_string - a string that can be used in an expo |
| 96 | * |
| 97 | * @id: ID number of the string |
| 98 | * @str: String |
| 99 | * @sibling: Node to link this object to its siblings |
| 100 | */ |
| 101 | struct expo_string { |
| 102 | uint id; |
| 103 | const char *str; |
| 104 | struct list_head sibling; |
| 105 | }; |
| 106 | |
| 107 | /** |
| 108 | * struct scene - information about a scene in an expo |
| 109 | * |
| 110 | * A collection of text/image/menu items in an expo |
| 111 | * |
| 112 | * @expo: Expo this scene is part of |
| 113 | * @name: Name of the scene (allocated) |
| 114 | * @id: ID number of the scene |
Simon Glass | ea274b6 | 2023-06-01 10:22:27 -0600 | [diff] [blame] | 115 | * @title_id: String ID of title of the scene (allocated) |
Simon Glass | d353b75 | 2023-06-01 10:22:55 -0600 | [diff] [blame] | 116 | * @highlight_id: ID of highlighted object, if any |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 117 | * @sibling: Node to link this scene to its siblings |
| 118 | * @obj_head: List of objects in the scene |
| 119 | */ |
| 120 | struct scene { |
| 121 | struct expo *expo; |
| 122 | char *name; |
| 123 | uint id; |
Simon Glass | ea274b6 | 2023-06-01 10:22:27 -0600 | [diff] [blame] | 124 | uint title_id; |
Simon Glass | d353b75 | 2023-06-01 10:22:55 -0600 | [diff] [blame] | 125 | uint highlight_id; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 126 | struct list_head sibling; |
| 127 | struct list_head obj_head; |
| 128 | }; |
| 129 | |
| 130 | /** |
| 131 | * enum scene_obj_t - type of a scene object |
| 132 | * |
| 133 | * @SCENEOBJT_NONE: Used to indicate that the type does not matter |
| 134 | * @SCENEOBJT_IMAGE: Image data to render |
| 135 | * @SCENEOBJT_TEXT: Text line to render |
| 136 | * @SCENEOBJT_MENU: Menu containing items the user can select |
| 137 | */ |
| 138 | enum scene_obj_t { |
| 139 | SCENEOBJT_NONE = 0, |
| 140 | SCENEOBJT_IMAGE, |
| 141 | SCENEOBJT_TEXT, |
| 142 | SCENEOBJT_MENU, |
| 143 | }; |
| 144 | |
| 145 | /** |
Simon Glass | 7b04395 | 2023-06-01 10:22:49 -0600 | [diff] [blame] | 146 | * struct scene_dim - Dimensions of an object |
| 147 | * |
| 148 | * @x: x position, in pixels from left side |
| 149 | * @y: y position, in pixels from top |
| 150 | * @w: width, in pixels |
| 151 | * @h: height, in pixels |
| 152 | */ |
| 153 | struct scene_dim { |
| 154 | int x; |
| 155 | int y; |
| 156 | int w; |
| 157 | int h; |
| 158 | }; |
| 159 | |
| 160 | /** |
Simon Glass | 6081b0f | 2023-06-01 10:22:50 -0600 | [diff] [blame] | 161 | * enum scene_obj_flags_t - flags for objects |
| 162 | * |
| 163 | * @SCENEOF_HIDE: object should be hidden |
Simon Glass | d353b75 | 2023-06-01 10:22:55 -0600 | [diff] [blame] | 164 | * @SCENEOF_POINT: object should be highlighted |
| 165 | * @SCENEOF_OPEN: object should be opened (e.g. menu is opened so that an option |
| 166 | * can be selected) |
Simon Glass | 6081b0f | 2023-06-01 10:22:50 -0600 | [diff] [blame] | 167 | */ |
| 168 | enum scene_obj_flags_t { |
| 169 | SCENEOF_HIDE = 1 << 0, |
Simon Glass | d353b75 | 2023-06-01 10:22:55 -0600 | [diff] [blame] | 170 | SCENEOF_POINT = 1 << 1, |
| 171 | SCENEOF_OPEN = 1 << 2, |
Simon Glass | 6081b0f | 2023-06-01 10:22:50 -0600 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 175 | * struct scene_obj - information about an object in a scene |
| 176 | * |
| 177 | * @scene: Scene that this object relates to |
| 178 | * @name: Name of the object (allocated) |
| 179 | * @id: ID number of the object |
| 180 | * @type: Type of this object |
Simon Glass | 7b04395 | 2023-06-01 10:22:49 -0600 | [diff] [blame] | 181 | * @dim: Dimensions for this object |
Simon Glass | 6081b0f | 2023-06-01 10:22:50 -0600 | [diff] [blame] | 182 | * @flags: Flags for this object |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 183 | * @sibling: Node to link this object to its siblings |
| 184 | */ |
| 185 | struct scene_obj { |
| 186 | struct scene *scene; |
| 187 | char *name; |
| 188 | uint id; |
| 189 | enum scene_obj_t type; |
Simon Glass | 7b04395 | 2023-06-01 10:22:49 -0600 | [diff] [blame] | 190 | struct scene_dim dim; |
Simon Glass | 6081b0f | 2023-06-01 10:22:50 -0600 | [diff] [blame] | 191 | int flags; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 192 | struct list_head sibling; |
| 193 | }; |
| 194 | |
| 195 | /** |
| 196 | * struct scene_obj_img - information about an image object in a scene |
| 197 | * |
| 198 | * This is a rectangular image which is blitted onto the display |
| 199 | * |
| 200 | * @obj: Basic object information |
| 201 | * @data: Image data in BMP format |
| 202 | */ |
| 203 | struct scene_obj_img { |
| 204 | struct scene_obj obj; |
| 205 | char *data; |
| 206 | }; |
| 207 | |
| 208 | /** |
| 209 | * struct scene_obj_txt - information about a text object in a scene |
| 210 | * |
| 211 | * This is a single-line text object |
| 212 | * |
| 213 | * @obj: Basic object information |
| 214 | * @str_id: ID of the text string to display |
| 215 | * @font_name: Name of font (allocated by caller) |
| 216 | * @font_size: Nominal size of font in pixels |
| 217 | */ |
| 218 | struct scene_obj_txt { |
| 219 | struct scene_obj obj; |
| 220 | uint str_id; |
| 221 | const char *font_name; |
| 222 | uint font_size; |
| 223 | }; |
| 224 | |
| 225 | /** |
| 226 | * struct scene_obj_menu - information about a menu object in a scene |
| 227 | * |
| 228 | * A menu has a number of items which can be selected by the user |
| 229 | * |
| 230 | * It also has: |
| 231 | * |
| 232 | * - a text/image object (@pointer_id) which points to the current item |
| 233 | * (@cur_item_id) |
| 234 | * |
| 235 | * - a preview object which shows an image related to the current item |
| 236 | * |
| 237 | * @obj: Basic object information |
| 238 | * @title_id: ID of the title text, or 0 if none |
| 239 | * @cur_item_id: ID of the current menu item, or 0 if none |
| 240 | * @pointer_id: ID of the object pointing to the current selection |
| 241 | * @item_head: List of items in the menu |
| 242 | */ |
| 243 | struct scene_obj_menu { |
| 244 | struct scene_obj obj; |
| 245 | uint title_id; |
| 246 | uint cur_item_id; |
| 247 | uint pointer_id; |
| 248 | struct list_head item_head; |
| 249 | }; |
| 250 | |
| 251 | /** |
| 252 | * enum scene_menuitem_flags_t - flags for menu items |
| 253 | * |
| 254 | * @SCENEMIF_GAP_BEFORE: Add a gap before this item |
| 255 | */ |
| 256 | enum scene_menuitem_flags_t { |
| 257 | SCENEMIF_GAP_BEFORE = 1 << 0, |
| 258 | }; |
| 259 | |
| 260 | /** |
| 261 | * struct scene_menitem - a menu item in a menu |
| 262 | * |
| 263 | * A menu item has: |
| 264 | * |
| 265 | * - text object holding the name (short) and description (can be longer) |
| 266 | * - a text object holding the keypress |
| 267 | * |
| 268 | * @name: Name of the item (this is allocated by this call) |
| 269 | * @id: ID number of the object |
| 270 | * @key_id: ID of text object to use as the keypress to show |
| 271 | * @label_id: ID of text object to use as the label text |
| 272 | * @desc_id: ID of text object to use as the description text |
| 273 | * @preview_id: ID of the preview object, or 0 if none |
| 274 | * @flags: Flags for this item |
| 275 | * @sibling: Node to link this item to its siblings |
| 276 | */ |
| 277 | struct scene_menitem { |
| 278 | char *name; |
| 279 | uint id; |
| 280 | uint key_id; |
| 281 | uint label_id; |
| 282 | uint desc_id; |
| 283 | uint preview_id; |
| 284 | uint flags; |
| 285 | struct list_head sibling; |
| 286 | }; |
| 287 | |
| 288 | /** |
| 289 | * expo_new() - create a new expo |
| 290 | * |
| 291 | * Allocates a new expo |
| 292 | * |
| 293 | * @name: Name of expo (this is allocated by this call) |
| 294 | * @priv: Private data for the controller |
| 295 | * @expp: Returns a pointer to the new expo on success |
| 296 | * Returns: 0 if OK, -ENOMEM if out of memory |
| 297 | */ |
| 298 | int expo_new(const char *name, void *priv, struct expo **expp); |
| 299 | |
| 300 | /** |
| 301 | * expo_destroy() - Destroy an expo and free all its memory |
| 302 | * |
| 303 | * @exp: Expo to destroy |
| 304 | */ |
| 305 | void expo_destroy(struct expo *exp); |
| 306 | |
| 307 | /** |
Simon Glass | 6e9e415 | 2023-06-01 10:22:47 -0600 | [diff] [blame] | 308 | * expo_set_dynamic_start() - Set the start of the 'dynamic' IDs |
| 309 | * |
| 310 | * It is common for a set of 'static' IDs to be used to refer to objects in the |
| 311 | * expo. These typically use an enum so that they are defined in sequential |
| 312 | * order. |
| 313 | * |
| 314 | * Dynamic IDs (for objects not in the enum) are intended to be used for |
| 315 | * objects to which the code does not need to refer. These are ideally located |
| 316 | * above the static IDs. |
| 317 | * |
| 318 | * Use this function to set the start of the dynamic range, making sure that the |
| 319 | * value is higher than all the statically allocated IDs. |
| 320 | * |
| 321 | * @exp: Expo to update |
| 322 | * @dyn_start: Start ID that expo should use for dynamic allocation |
| 323 | */ |
| 324 | void expo_set_dynamic_start(struct expo *exp, uint dyn_start); |
| 325 | |
| 326 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 327 | * expo_str() - add a new string to an expo |
| 328 | * |
| 329 | * @exp: Expo to update |
| 330 | * @name: Name to use (this is allocated by this call) |
| 331 | * @id: ID to use for the new object (0 to allocate one) |
| 332 | * @str: Pointer to text to display (allocated by caller) |
| 333 | * Returns: ID number for the object (typically @id), or -ve on error |
| 334 | */ |
| 335 | int expo_str(struct expo *exp, const char *name, uint id, const char *str); |
| 336 | |
| 337 | /** |
| 338 | * expo_get_str() - Get a string by ID |
| 339 | * |
| 340 | * @exp: Expo to use |
| 341 | * @id: String ID to look up |
| 342 | * @returns string, or NULL if not found |
| 343 | */ |
| 344 | const char *expo_get_str(struct expo *exp, uint id); |
| 345 | |
| 346 | /** |
| 347 | * expo_set_display() - set the display to use for a expo |
| 348 | * |
| 349 | * @exp: Expo to update |
| 350 | * @dev: Display to use (`UCLASS_VIDEO`), NULL to use text mode |
| 351 | * Returns: 0 (always) |
| 352 | */ |
| 353 | int expo_set_display(struct expo *exp, struct udevice *dev); |
| 354 | |
| 355 | /** |
Simon Glass | 7a96005 | 2023-06-01 10:22:52 -0600 | [diff] [blame] | 356 | * expo_calc_dims() - Calculate the dimensions of the objects |
| 357 | * |
| 358 | * Updates the width and height of all objects based on their contents |
| 359 | * |
| 360 | * @exp: Expo to update |
| 361 | * Returns 0 if OK, -ENOTSUPP if there is no graphical console |
| 362 | */ |
| 363 | int expo_calc_dims(struct expo *exp); |
| 364 | |
| 365 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 366 | * expo_set_scene_id() - Set the current scene ID |
| 367 | * |
| 368 | * @exp: Expo to update |
| 369 | * @scene_id: New scene ID to use (0 to select no scene) |
| 370 | * Returns: 0 if OK, -ENOENT if there is no scene with that ID |
| 371 | */ |
| 372 | int expo_set_scene_id(struct expo *exp, uint scene_id); |
| 373 | |
| 374 | /** |
| 375 | * expo_render() - render the expo on the display / console |
| 376 | * |
| 377 | * @exp: Expo to render |
| 378 | * |
| 379 | * Returns: 0 if OK, -ECHILD if there is no current scene, -ENOENT if the |
| 380 | * current scene is not found, other error if something else goes wrong |
| 381 | */ |
| 382 | int expo_render(struct expo *exp); |
| 383 | |
| 384 | /** |
Simon Glass | b2c4034 | 2023-06-01 10:22:37 -0600 | [diff] [blame] | 385 | * expo_set_text_mode() - Controls whether the expo renders in text mode |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 386 | * |
| 387 | * @exp: Expo to update |
| 388 | * @text_mode: true to use text mode, false to use the console |
| 389 | */ |
Simon Glass | b2c4034 | 2023-06-01 10:22:37 -0600 | [diff] [blame] | 390 | void expo_set_text_mode(struct expo *exp, bool text_mode); |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 391 | |
| 392 | /** |
| 393 | * scene_new() - create a new scene in a expo |
| 394 | * |
| 395 | * The scene is given the ID @id which must be unique across all scenes, objects |
| 396 | * and items. The expo's @next_id is updated to at least @id + 1 |
| 397 | * |
| 398 | * @exp: Expo to update |
| 399 | * @name: Name to use (this is allocated by this call) |
| 400 | * @id: ID to use for the new scene (0 to allocate one) |
| 401 | * @scnp: Returns a pointer to the new scene on success |
| 402 | * Returns: ID number for the scene (typically @id), or -ve on error |
| 403 | */ |
| 404 | int scene_new(struct expo *exp, const char *name, uint id, struct scene **scnp); |
| 405 | |
| 406 | /** |
| 407 | * expo_lookup_scene_id() - Look up a scene by ID |
| 408 | * |
| 409 | * @exp: Expo to check |
| 410 | * @scene_id: Scene ID to look up |
| 411 | * @returns pointer to scene if found, else NULL |
| 412 | */ |
| 413 | struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id); |
| 414 | |
| 415 | /** |
| 416 | * scene_title_set() - set the scene title |
| 417 | * |
| 418 | * @scn: Scene to update |
Simon Glass | ea274b6 | 2023-06-01 10:22:27 -0600 | [diff] [blame] | 419 | * @title_id: Title ID to set |
| 420 | * Returns: 0 if OK |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 421 | */ |
Simon Glass | ea274b6 | 2023-06-01 10:22:27 -0600 | [diff] [blame] | 422 | int scene_title_set(struct scene *scn, uint title_id); |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 423 | |
| 424 | /** |
| 425 | * scene_obj_count() - Count the number of objects in a scene |
| 426 | * |
| 427 | * @scn: Scene to check |
| 428 | * Returns: number of objects in the scene, 0 if none |
| 429 | */ |
| 430 | int scene_obj_count(struct scene *scn); |
| 431 | |
| 432 | /** |
| 433 | * scene_img() - add a new image to a scene |
| 434 | * |
| 435 | * @scn: Scene to update |
| 436 | * @name: Name to use (this is allocated by this call) |
| 437 | * @id: ID to use for the new object (0 to allocate one) |
| 438 | * @data: Pointer to image data |
| 439 | * @imgp: If non-NULL, returns the new object |
| 440 | * Returns: ID number for the object (typically @id), or -ve on error |
| 441 | */ |
| 442 | int scene_img(struct scene *scn, const char *name, uint id, char *data, |
| 443 | struct scene_obj_img **imgp); |
| 444 | |
| 445 | /** |
| 446 | * scene_txt() - add a new text object to a scene |
| 447 | * |
| 448 | * @scn: Scene to update |
| 449 | * @name: Name to use (this is allocated by this call) |
| 450 | * @id: ID to use for the new object (0 to allocate one) |
| 451 | * @str_id: ID of the string to use |
| 452 | * @txtp: If non-NULL, returns the new object |
| 453 | * Returns: ID number for the object (typically @id), or -ve on error |
| 454 | */ |
| 455 | int scene_txt(struct scene *scn, const char *name, uint id, uint str_id, |
| 456 | struct scene_obj_txt **txtp); |
| 457 | |
| 458 | /** |
| 459 | * scene_txt_str() - add a new string to expr and text object to a scene |
| 460 | * |
| 461 | * @scn: Scene to update |
| 462 | * @name: Name to use (this is allocated by this call) |
| 463 | * @id: ID to use for the new object (0 to allocate one) |
| 464 | * @str_id: ID of the string to use |
| 465 | * @str: Pointer to text to display (allocated by caller) |
| 466 | * @txtp: If non-NULL, returns the new object |
| 467 | * Returns: ID number for the object (typically @id), or -ve on error |
| 468 | */ |
| 469 | int scene_txt_str(struct scene *scn, const char *name, uint id, uint str_id, |
| 470 | const char *str, struct scene_obj_txt **txtp); |
| 471 | |
| 472 | /** |
| 473 | * scene_menu() - create a menu |
| 474 | * |
| 475 | * @scn: Scene to update |
| 476 | * @name: Name to use (this is allocated by this call) |
| 477 | * @id: ID to use for the new object (0 to allocate one) |
| 478 | * @menup: If non-NULL, returns the new object |
| 479 | * Returns: ID number for the object (typically @id), or -ve on error |
| 480 | */ |
| 481 | int scene_menu(struct scene *scn, const char *name, uint id, |
| 482 | struct scene_obj_menu **menup); |
| 483 | |
| 484 | /** |
| 485 | * scene_txt_set_font() - Set the font for an object |
| 486 | * |
| 487 | * @scn: Scene to update |
| 488 | * @id: ID of object to update |
| 489 | * @font_name: Font name to use (allocated by caller) |
| 490 | * @font_size: Font size to use (nominal height in pixels) |
| 491 | */ |
| 492 | int scene_txt_set_font(struct scene *scn, uint id, const char *font_name, |
| 493 | uint font_size); |
| 494 | |
| 495 | /** |
| 496 | * scene_obj_set_pos() - Set the postion of an object |
| 497 | * |
| 498 | * @scn: Scene to update |
| 499 | * @id: ID of object to update |
| 500 | * @x: x position, in pixels from left side |
| 501 | * @y: y position, in pixels from top |
| 502 | * Returns: 0 if OK, -ENOENT if @id is invalid |
| 503 | */ |
| 504 | int scene_obj_set_pos(struct scene *scn, uint id, int x, int y); |
| 505 | |
| 506 | /** |
Simon Glass | 7a96005 | 2023-06-01 10:22:52 -0600 | [diff] [blame] | 507 | * scene_obj_set_size() - Set the size of an object |
| 508 | * |
| 509 | * @scn: Scene to update |
| 510 | * @id: ID of object to update |
| 511 | * @w: width in pixels |
| 512 | * @h: height in pixels |
| 513 | * Returns: 0 if OK, -ENOENT if @id is invalid |
| 514 | */ |
| 515 | int scene_obj_set_size(struct scene *scn, uint id, int w, int h); |
| 516 | |
| 517 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 518 | * scene_obj_set_hide() - Set whether an object is hidden |
| 519 | * |
| 520 | * The update happens when the expo is next rendered. |
| 521 | * |
| 522 | * @scn: Scene to update |
| 523 | * @id: ID of object to update |
| 524 | * @hide: true to hide the object, false to show it |
| 525 | * Returns: 0 if OK, -ENOENT if @id is invalid |
| 526 | */ |
| 527 | int scene_obj_set_hide(struct scene *scn, uint id, bool hide); |
| 528 | |
| 529 | /** |
| 530 | * scene_menu_set_title() - Set the title of a menu |
| 531 | * |
| 532 | * @scn: Scene to update |
| 533 | * @id: ID of menu object to update |
| 534 | * @title_id: ID of text object to use as the title |
| 535 | * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @title_id is invalid |
| 536 | */ |
| 537 | int scene_menu_set_title(struct scene *scn, uint id, uint title_id); |
| 538 | |
| 539 | /** |
| 540 | * scene_menu_set_pointer() - Set the item pointer for a menu |
| 541 | * |
| 542 | * This is a visual indicator of the current item, typically a ">" character |
| 543 | * which sits next to the current item and moves when the user presses the |
| 544 | * up/down arrow keys |
| 545 | * |
| 546 | * @scn: Scene to update |
| 547 | * @id: ID of menu object to update |
| 548 | * @cur_item_id: ID of text or image object to use as a pointer to the current |
| 549 | * item |
| 550 | * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @cur_item_id is invalid |
| 551 | */ |
| 552 | int scene_menu_set_pointer(struct scene *scn, uint id, uint cur_item_id); |
| 553 | |
| 554 | /** |
| 555 | * scene_obj_get_hw() - Get width and height of an object in a scene |
| 556 | * |
| 557 | * @scn: Scene to check |
| 558 | * @id: ID of menu object to check |
| 559 | * @widthp: If non-NULL, returns width of object in pixels |
| 560 | * Returns: Height of object in pixels |
| 561 | */ |
| 562 | int scene_obj_get_hw(struct scene *scn, uint id, int *widthp); |
| 563 | |
| 564 | /** |
| 565 | * scene_menuitem() - Add an item to a menu |
| 566 | * |
| 567 | * @scn: Scene to update |
| 568 | * @menu_id: ID of menu object to update |
| 569 | * @name: Name to use (this is allocated by this call) |
| 570 | * @id: ID to use for the new object (0 to allocate one) |
| 571 | * @key_id: ID of text object to use as the keypress to show |
| 572 | * @label_id: ID of text object to use as the label text |
| 573 | * @desc_id: ID of text object to use as the description text |
| 574 | * @preview_id: ID of object to use as the preview (text or image) |
| 575 | * @flags: Flags for this item (enum scene_menuitem_flags_t) |
| 576 | * @itemp: If non-NULL, returns the new object |
| 577 | * Returns: ID number for the item (typically @id), or -ve on error |
| 578 | */ |
| 579 | int scene_menuitem(struct scene *scn, uint menu_id, const char *name, uint id, |
| 580 | uint key_id, uint label_id, uint desc_id, uint preview_id, |
| 581 | uint flags, struct scene_menitem **itemp); |
| 582 | |
| 583 | /** |
| 584 | * scene_arrange() - Arrange the scene to deal with object sizes |
| 585 | * |
| 586 | * Updates any menus in the scene so that their objects are in the right place. |
| 587 | * |
| 588 | * @scn: Scene to arrange |
| 589 | * Returns: 0 if OK, -ve on error |
| 590 | */ |
| 591 | int scene_arrange(struct scene *scn); |
| 592 | |
| 593 | /** |
| 594 | * expo_send_key() - set a keypress to the expo |
| 595 | * |
| 596 | * @exp: Expo to receive the key |
| 597 | * @key: Key to send (ASCII or enum bootmenu_key) |
| 598 | * Returns: 0 if OK, -ECHILD if there is no current scene |
| 599 | */ |
| 600 | int expo_send_key(struct expo *exp, int key); |
| 601 | |
| 602 | /** |
| 603 | * expo_action_get() - read user input from the expo |
| 604 | * |
| 605 | * @exp: Expo to check |
| 606 | * @act: Returns action |
| 607 | * Returns: 0 if OK, -EAGAIN if there was no action to return |
| 608 | */ |
| 609 | int expo_action_get(struct expo *exp, struct expo_action *act); |
| 610 | |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 611 | /** |
| 612 | * expo_apply_theme() - Apply a theme to an expo |
| 613 | * |
| 614 | * @exp: Expo to update |
| 615 | * @node: Node containing the theme |
| 616 | */ |
| 617 | int expo_apply_theme(struct expo *exp, ofnode node); |
| 618 | |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 619 | #endif /*__SCENE_H */ |