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