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