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 | cfb4f2c | 2025-05-02 08:46:42 -0600 | [diff] [blame] | 11 | #include <alist.h> |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 12 | #include <dm/ofnode_decl.h> |
Simon Glass | ebec497 | 2025-05-02 08:46:33 -0600 | [diff] [blame] | 13 | #include <linux/bitops.h> |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 14 | #include <linux/list.h> |
| 15 | |
| 16 | struct udevice; |
| 17 | |
Simon Glass | a968f5f | 2023-10-01 19:13:31 -0600 | [diff] [blame] | 18 | #include <cli.h> |
| 19 | |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 20 | /** |
Simon Glass | 53a0a2f | 2024-10-14 16:31:57 -0600 | [diff] [blame] | 21 | * enum expo_id_t - standard expo IDs |
| 22 | * |
| 23 | * These are assumed to be in use at all times. Expos should use IDs starting |
| 24 | * from EXPOID_BASE_ID, |
| 25 | * |
| 26 | * @EXPOID_NONE: Not used, invalid ID 0 |
| 27 | * @EXPOID_SAVE: User has requested that the expo data be saved |
| 28 | * @EXPOID_DISCARD: User has requested that the expo data be discarded |
| 29 | * @EXPOID_BASE_ID: First ID which can be used for expo objects |
| 30 | */ |
| 31 | enum expo_id_t { |
| 32 | EXPOID_NONE, |
| 33 | |
| 34 | EXPOID_SAVE, |
| 35 | EXPOID_DISCARD, |
| 36 | |
| 37 | EXPOID_BASE_ID = 5, |
| 38 | }; |
| 39 | |
| 40 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 41 | * enum expoact_type - types of actions reported by the expo |
| 42 | * |
| 43 | * @EXPOACT_NONE: no action |
Simon Glass | f0e1e8c | 2023-06-01 10:22:59 -0600 | [diff] [blame] | 44 | * @EXPOACT_POINT_OBJ: object was highlighted (@id indicates which) |
Simon Glass | 719a3c6 | 2023-06-01 10:22:56 -0600 | [diff] [blame] | 45 | * @EXPOACT_POINT_ITEM: menu item was highlighted (@id indicates which) |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 46 | * @EXPOACT_SELECT: menu item was selected (@id indicates which) |
Simon Glass | f0e1e8c | 2023-06-01 10:22:59 -0600 | [diff] [blame] | 47 | * @EXPOACT_OPEN: menu was opened, so an item can be selected (@id indicates |
| 48 | * which menu object) |
| 49 | * @EXPOACT_CLOSE: menu was closed (@id indicates which menu object) |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 50 | * @EXPOACT_QUIT: request to exit the menu |
| 51 | */ |
| 52 | enum expoact_type { |
| 53 | EXPOACT_NONE, |
Simon Glass | f0e1e8c | 2023-06-01 10:22:59 -0600 | [diff] [blame] | 54 | EXPOACT_POINT_OBJ, |
Simon Glass | 719a3c6 | 2023-06-01 10:22:56 -0600 | [diff] [blame] | 55 | EXPOACT_POINT_ITEM, |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 56 | EXPOACT_SELECT, |
Simon Glass | f0e1e8c | 2023-06-01 10:22:59 -0600 | [diff] [blame] | 57 | EXPOACT_OPEN, |
| 58 | EXPOACT_CLOSE, |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 59 | EXPOACT_QUIT, |
| 60 | }; |
| 61 | |
| 62 | /** |
| 63 | * struct expo_action - an action report by the expo |
| 64 | * |
| 65 | * @type: Action type (EXPOACT_NONE if there is no action) |
Simon Glass | 719a3c6 | 2023-06-01 10:22:56 -0600 | [diff] [blame] | 66 | * @select: Used for EXPOACT_POINT_ITEM and EXPOACT_SELECT |
Heinrich Schuchardt | a99e8fe | 2024-09-18 23:58:03 +0200 | [diff] [blame] | 67 | * @select.id: ID number of the object affected. |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 68 | */ |
| 69 | struct expo_action { |
| 70 | enum expoact_type type; |
| 71 | union { |
| 72 | struct { |
| 73 | int id; |
| 74 | } select; |
| 75 | }; |
| 76 | }; |
| 77 | |
| 78 | /** |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 79 | * struct expo_theme - theme for the expo |
| 80 | * |
| 81 | * @font_size: Default font size for all text |
| 82 | * @menu_inset: Inset width (on each side and top/bottom) for menu items |
| 83 | * @menuitem_gap_y: Gap between menu items in pixels |
Simon Glass | 377f18e | 2024-10-14 16:31:55 -0600 | [diff] [blame] | 84 | * @menu_title_margin_x: Gap between right side of menu title and left size of |
| 85 | * menu label |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 86 | */ |
| 87 | struct expo_theme { |
| 88 | u32 font_size; |
| 89 | u32 menu_inset; |
| 90 | u32 menuitem_gap_y; |
Simon Glass | 377f18e | 2024-10-14 16:31:55 -0600 | [diff] [blame] | 91 | u32 menu_title_margin_x; |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 95 | * struct expo - information about an expo |
| 96 | * |
| 97 | * A group of scenes which can be presented to the user, typically to obtain |
| 98 | * input or to make a selection. |
| 99 | * |
| 100 | * @name: Name of the expo (allocated) |
| 101 | * @display: Display to use (`UCLASS_VIDEO`), or NULL to use text mode |
Simon Glass | 67e2af1 | 2023-06-01 10:22:34 -0600 | [diff] [blame] | 102 | * @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] | 103 | * @scene_id: Current scene ID (0 if none) |
| 104 | * @next_id: Next ID number to use, for automatic allocation |
| 105 | * @action: Action selected by user. At present only one is supported, with the |
| 106 | * type set to EXPOACT_NONE if there is no action |
| 107 | * @text_mode: true to use text mode for the menu (no vidconsole) |
Simon Glass | d353b75 | 2023-06-01 10:22:55 -0600 | [diff] [blame] | 108 | * @popup: true to use popup menus, instead of showing all items |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 109 | * @priv: Private data for the controller |
Simon Glass | 527d864 | 2025-05-02 08:46:20 -0600 | [diff] [blame] | 110 | * @done: Indicates that a cedit session is complete and the user has quit |
| 111 | * @save: Indicates that cedit data should be saved, rather than discarded |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 112 | * @theme: Information about fonts styles, etc. |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 113 | * @scene_head: List of scenes |
| 114 | * @str_head: list of strings |
Simon Glass | 683d883 | 2025-05-02 08:46:15 -0600 | [diff] [blame] | 115 | * @cch: Keyboard context for input |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 116 | */ |
| 117 | struct expo { |
| 118 | char *name; |
| 119 | struct udevice *display; |
Simon Glass | 67e2af1 | 2023-06-01 10:22:34 -0600 | [diff] [blame] | 120 | struct udevice *cons; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 121 | uint scene_id; |
| 122 | uint next_id; |
| 123 | struct expo_action action; |
| 124 | bool text_mode; |
Simon Glass | d353b75 | 2023-06-01 10:22:55 -0600 | [diff] [blame] | 125 | bool popup; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 126 | void *priv; |
Simon Glass | 527d864 | 2025-05-02 08:46:20 -0600 | [diff] [blame] | 127 | bool done; |
| 128 | bool save; |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 129 | struct expo_theme theme; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 130 | struct list_head scene_head; |
| 131 | struct list_head str_head; |
Simon Glass | 683d883 | 2025-05-02 08:46:15 -0600 | [diff] [blame] | 132 | struct cli_ch_state cch; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | /** |
| 136 | * struct expo_string - a string that can be used in an expo |
| 137 | * |
| 138 | * @id: ID number of the string |
Simon Glass | da33775 | 2025-05-02 08:46:32 -0600 | [diff] [blame] | 139 | * @buf: String (contains nul terminator) |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 140 | * @sibling: Node to link this object to its siblings |
| 141 | */ |
| 142 | struct expo_string { |
| 143 | uint id; |
Simon Glass | da33775 | 2025-05-02 08:46:32 -0600 | [diff] [blame] | 144 | struct abuf buf; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 145 | struct list_head sibling; |
| 146 | }; |
| 147 | |
| 148 | /** |
| 149 | * struct scene - information about a scene in an expo |
| 150 | * |
| 151 | * A collection of text/image/menu items in an expo |
| 152 | * |
| 153 | * @expo: Expo this scene is part of |
| 154 | * @name: Name of the scene (allocated) |
| 155 | * @id: ID number of the scene |
Simon Glass | ea274b6 | 2023-06-01 10:22:27 -0600 | [diff] [blame] | 156 | * @title_id: String ID of title of the scene (allocated) |
Simon Glass | d353b75 | 2023-06-01 10:22:55 -0600 | [diff] [blame] | 157 | * @highlight_id: ID of highlighted object, if any |
Simon Glass | a968f5f | 2023-10-01 19:13:31 -0600 | [diff] [blame] | 158 | * @cls: cread state to use for input |
| 159 | * @buf: Buffer for input |
| 160 | * @entry_save: Buffer to hold vidconsole text-entry information |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 161 | * @sibling: Node to link this scene to its siblings |
| 162 | * @obj_head: List of objects in the scene |
| 163 | */ |
| 164 | struct scene { |
| 165 | struct expo *expo; |
| 166 | char *name; |
| 167 | uint id; |
Simon Glass | ea274b6 | 2023-06-01 10:22:27 -0600 | [diff] [blame] | 168 | uint title_id; |
Simon Glass | d353b75 | 2023-06-01 10:22:55 -0600 | [diff] [blame] | 169 | uint highlight_id; |
Simon Glass | a968f5f | 2023-10-01 19:13:31 -0600 | [diff] [blame] | 170 | struct cli_line_state cls; |
| 171 | struct abuf buf; |
| 172 | struct abuf entry_save; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 173 | struct list_head sibling; |
| 174 | struct list_head obj_head; |
| 175 | }; |
| 176 | |
| 177 | /** |
| 178 | * enum scene_obj_t - type of a scene object |
| 179 | * |
| 180 | * @SCENEOBJT_NONE: Used to indicate that the type does not matter |
| 181 | * @SCENEOBJT_IMAGE: Image data to render |
Simon Glass | 138a397 | 2025-05-02 08:46:44 -0600 | [diff] [blame] | 182 | * @SCENEOBJT_BOX: Rectangular box |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 183 | * @SCENEOBJT_TEXT: Text line to render |
| 184 | * @SCENEOBJT_MENU: Menu containing items the user can select |
Simon Glass | 6116e76 | 2023-10-01 19:13:32 -0600 | [diff] [blame] | 185 | * @SCENEOBJT_TEXTLINE: Line of text the user can edit |
Simon Glass | 5dc887d | 2025-05-02 08:46:46 -0600 | [diff] [blame] | 186 | * @SCENEOBJT_TEXTEDIT: Simple text editor |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 187 | */ |
| 188 | enum scene_obj_t { |
| 189 | SCENEOBJT_NONE = 0, |
| 190 | SCENEOBJT_IMAGE, |
| 191 | SCENEOBJT_TEXT, |
Simon Glass | 138a397 | 2025-05-02 08:46:44 -0600 | [diff] [blame] | 192 | SCENEOBJT_BOX, |
Simon Glass | 5dc887d | 2025-05-02 08:46:46 -0600 | [diff] [blame] | 193 | SCENEOBJT_TEXTEDIT, |
Simon Glass | 193bfea | 2023-10-01 19:13:27 -0600 | [diff] [blame] | 194 | |
| 195 | /* types from here on can be highlighted */ |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 196 | SCENEOBJT_MENU, |
Simon Glass | 6116e76 | 2023-10-01 19:13:32 -0600 | [diff] [blame] | 197 | SCENEOBJT_TEXTLINE, |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | /** |
Simon Glass | 854ca69 | 2025-05-02 08:46:30 -0600 | [diff] [blame] | 201 | * struct scene_obj_bbox - Dimensions of an object |
Simon Glass | 7b04395 | 2023-06-01 10:22:49 -0600 | [diff] [blame] | 202 | * |
Simon Glass | bc3a15f | 2025-05-02 08:46:31 -0600 | [diff] [blame] | 203 | * @x0: x position, in pixels from left side |
| 204 | * @y0: y position, in pixels from top |
Simon Glass | ebec497 | 2025-05-02 08:46:33 -0600 | [diff] [blame] | 205 | * @x1: x position of right size |
| 206 | * @y1: y position of bottom |
Simon Glass | 7b04395 | 2023-06-01 10:22:49 -0600 | [diff] [blame] | 207 | */ |
Simon Glass | 854ca69 | 2025-05-02 08:46:30 -0600 | [diff] [blame] | 208 | struct scene_obj_bbox { |
Simon Glass | bc3a15f | 2025-05-02 08:46:31 -0600 | [diff] [blame] | 209 | int x0; |
| 210 | int y0; |
Simon Glass | ebec497 | 2025-05-02 08:46:33 -0600 | [diff] [blame] | 211 | int x1; |
| 212 | int y1; |
Simon Glass | 7b04395 | 2023-06-01 10:22:49 -0600 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | /** |
Simon Glass | 5beb057 | 2025-05-02 08:46:45 -0600 | [diff] [blame] | 216 | * struct scene_obj_offset - Offsets for drawing the object |
| 217 | * |
| 218 | * Stores the offset from x0, x1 at which objects are drawn |
| 219 | * |
| 220 | * @xofs: x offset |
| 221 | * @yofs: y offset |
| 222 | */ |
| 223 | struct scene_obj_offset { |
| 224 | int xofs; |
| 225 | int yofs; |
| 226 | }; |
| 227 | |
| 228 | /** |
Simon Glass | ebec497 | 2025-05-02 08:46:33 -0600 | [diff] [blame] | 229 | * struct scene_obj_dims - Dimensions of the object being drawn |
| 230 | * |
| 231 | * Image and text objects have a dimension which can change depending on what |
| 232 | * they contain. For images this stores the size. For text it stores the size as |
| 233 | * rendered on the display |
| 234 | * |
| 235 | * @x: x dimension |
| 236 | * @y: y dimension |
| 237 | */ |
| 238 | struct scene_obj_dims { |
| 239 | int x; |
| 240 | int y; |
| 241 | }; |
| 242 | |
| 243 | /** |
Simon Glass | 5beb057 | 2025-05-02 08:46:45 -0600 | [diff] [blame] | 244 | * enum scene_obj_halign - Horizontal alignment of objects |
| 245 | * |
| 246 | * Objects are normally drawn on the left size of their bounding box. This |
| 247 | * properly allows aligning on the right or having the object centred. |
| 248 | * |
| 249 | * @SCENEOA_LEFT: Left of object is aligned with its x coordinate |
| 250 | * @SCENEOA_RIGHT: Right of object is aligned with x + w |
| 251 | * @SCENEOA_CENTRE: Centre of object is aligned with centre of bounding box |
| 252 | * @SCENEOA_TOP: Left of object is aligned with its x coordinate |
| 253 | * @SCENEOA_BOTTOM: Right of object is aligned with x + w |
| 254 | * |
| 255 | * Note: It would be nice to make this a char type but Sphinx riddles: |
| 256 | * ./include/expo.h:258: error: Cannot parse enum! |
| 257 | * enum scene_obj_align : char { |
| 258 | */ |
| 259 | enum scene_obj_align { |
| 260 | SCENEOA_LEFT, |
| 261 | SCENEOA_RIGHT, |
| 262 | SCENEOA_CENTRE, |
| 263 | SCENEOA_TOP = SCENEOA_LEFT, |
| 264 | SCENEOA_BOTTOM = SCENEOA_RIGHT, |
| 265 | }; |
| 266 | |
| 267 | /** |
Simon Glass | 6081b0f | 2023-06-01 10:22:50 -0600 | [diff] [blame] | 268 | * enum scene_obj_flags_t - flags for objects |
| 269 | * |
| 270 | * @SCENEOF_HIDE: object should be hidden |
Simon Glass | d353b75 | 2023-06-01 10:22:55 -0600 | [diff] [blame] | 271 | * @SCENEOF_POINT: object should be highlighted |
| 272 | * @SCENEOF_OPEN: object should be opened (e.g. menu is opened so that an option |
| 273 | * can be selected) |
Simon Glass | ebec497 | 2025-05-02 08:46:33 -0600 | [diff] [blame] | 274 | * @SCENEOF_SIZE_VALID: object's size (width/height) is valid, so any adjustment |
| 275 | * to x0/y0 should maintain the width/height of the object |
Simon Glass | 6081b0f | 2023-06-01 10:22:50 -0600 | [diff] [blame] | 276 | */ |
| 277 | enum scene_obj_flags_t { |
| 278 | SCENEOF_HIDE = 1 << 0, |
Simon Glass | d353b75 | 2023-06-01 10:22:55 -0600 | [diff] [blame] | 279 | SCENEOF_POINT = 1 << 1, |
| 280 | SCENEOF_OPEN = 1 << 2, |
Simon Glass | ebec497 | 2025-05-02 08:46:33 -0600 | [diff] [blame] | 281 | SCENEOF_SIZE_VALID = BIT(3), |
Simon Glass | 6081b0f | 2023-06-01 10:22:50 -0600 | [diff] [blame] | 282 | }; |
| 283 | |
Simon Glass | a968f5f | 2023-10-01 19:13:31 -0600 | [diff] [blame] | 284 | enum { |
| 285 | /* Maximum number of characters allowed in an line editor */ |
| 286 | EXPO_MAX_CHARS = 250, |
| 287 | }; |
| 288 | |
Simon Glass | 6081b0f | 2023-06-01 10:22:50 -0600 | [diff] [blame] | 289 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 290 | * struct scene_obj - information about an object in a scene |
| 291 | * |
| 292 | * @scene: Scene that this object relates to |
| 293 | * @name: Name of the object (allocated) |
| 294 | * @id: ID number of the object |
| 295 | * @type: Type of this object |
Simon Glass | ebec497 | 2025-05-02 08:46:33 -0600 | [diff] [blame] | 296 | * @bbox: Bounding box for this object |
Simon Glass | 5beb057 | 2025-05-02 08:46:45 -0600 | [diff] [blame] | 297 | * @ofs: Offset from x0, y0 where the object is drawn |
Simon Glass | ebec497 | 2025-05-02 08:46:33 -0600 | [diff] [blame] | 298 | * @dims: Dimensions of the text/image (may be smaller than bbox) |
Simon Glass | 5beb057 | 2025-05-02 08:46:45 -0600 | [diff] [blame] | 299 | * @horiz: Horizonal alignment |
| 300 | * @vert: Vertical alignment |
Simon Glass | 6081b0f | 2023-06-01 10:22:50 -0600 | [diff] [blame] | 301 | * @flags: Flags for this object |
Simon Glass | 2b91ca6 | 2023-08-14 16:40:37 -0600 | [diff] [blame] | 302 | * @bit_length: Number of bits used for this object in CMOS RAM |
| 303 | * @start_bit: Start bit to use for this object in CMOS RAM |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 304 | * @sibling: Node to link this object to its siblings |
| 305 | */ |
| 306 | struct scene_obj { |
| 307 | struct scene *scene; |
| 308 | char *name; |
| 309 | uint id; |
| 310 | enum scene_obj_t type; |
Simon Glass | 854ca69 | 2025-05-02 08:46:30 -0600 | [diff] [blame] | 311 | struct scene_obj_bbox bbox; |
Simon Glass | 5beb057 | 2025-05-02 08:46:45 -0600 | [diff] [blame] | 312 | struct scene_obj_offset ofs; |
Simon Glass | ebec497 | 2025-05-02 08:46:33 -0600 | [diff] [blame] | 313 | struct scene_obj_dims dims; |
Simon Glass | 5beb057 | 2025-05-02 08:46:45 -0600 | [diff] [blame] | 314 | enum scene_obj_align horiz; |
| 315 | enum scene_obj_align vert; |
Simon Glass | 2b91ca6 | 2023-08-14 16:40:37 -0600 | [diff] [blame] | 316 | u8 flags; |
| 317 | u8 bit_length; |
| 318 | u16 start_bit; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 319 | struct list_head sibling; |
| 320 | }; |
| 321 | |
Simon Glass | 193bfea | 2023-10-01 19:13:27 -0600 | [diff] [blame] | 322 | /* object can be highlighted when moving around expo */ |
| 323 | static inline bool scene_obj_can_highlight(const struct scene_obj *obj) |
| 324 | { |
| 325 | return obj->type >= SCENEOBJT_MENU; |
| 326 | } |
| 327 | |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 328 | /** |
| 329 | * struct scene_obj_img - information about an image object in a scene |
| 330 | * |
| 331 | * This is a rectangular image which is blitted onto the display |
| 332 | * |
| 333 | * @obj: Basic object information |
| 334 | * @data: Image data in BMP format |
| 335 | */ |
| 336 | struct scene_obj_img { |
| 337 | struct scene_obj obj; |
| 338 | char *data; |
| 339 | }; |
| 340 | |
| 341 | /** |
Simon Glass | 9ef02aa | 2025-05-02 08:46:37 -0600 | [diff] [blame] | 342 | * struct scene_txt_generic - Generic information common to text objects |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 343 | * |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 344 | * @str_id: ID of the text string to display |
| 345 | * @font_name: Name of font (allocated by caller) |
| 346 | * @font_size: Nominal size of font in pixels |
Simon Glass | cfb4f2c | 2025-05-02 08:46:42 -0600 | [diff] [blame] | 347 | * @lines: alist of struct vidconsole_mline with a separate record for each |
| 348 | * line of text |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 349 | */ |
Simon Glass | 9ef02aa | 2025-05-02 08:46:37 -0600 | [diff] [blame] | 350 | struct scene_txt_generic { |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 351 | uint str_id; |
| 352 | const char *font_name; |
| 353 | uint font_size; |
Simon Glass | cfb4f2c | 2025-05-02 08:46:42 -0600 | [diff] [blame] | 354 | struct alist lines; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 355 | }; |
| 356 | |
| 357 | /** |
Simon Glass | 9ef02aa | 2025-05-02 08:46:37 -0600 | [diff] [blame] | 358 | * struct scene_obj_txt - information about a text object in a scene |
| 359 | * |
| 360 | * This is a single-line text object |
| 361 | * |
| 362 | * @obj: Basic object information |
| 363 | * @gen: Generic information common to all objects which show text |
| 364 | */ |
| 365 | struct scene_obj_txt { |
| 366 | struct scene_obj obj; |
| 367 | struct scene_txt_generic gen; |
| 368 | }; |
| 369 | |
| 370 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 371 | * struct scene_obj_menu - information about a menu object in a scene |
| 372 | * |
| 373 | * A menu has a number of items which can be selected by the user |
| 374 | * |
| 375 | * It also has: |
| 376 | * |
| 377 | * - a text/image object (@pointer_id) which points to the current item |
| 378 | * (@cur_item_id) |
| 379 | * |
| 380 | * - a preview object which shows an image related to the current item |
| 381 | * |
| 382 | * @obj: Basic object information |
| 383 | * @title_id: ID of the title text, or 0 if none |
| 384 | * @cur_item_id: ID of the current menu item, or 0 if none |
| 385 | * @pointer_id: ID of the object pointing to the current selection |
| 386 | * @item_head: List of items in the menu |
| 387 | */ |
| 388 | struct scene_obj_menu { |
| 389 | struct scene_obj obj; |
| 390 | uint title_id; |
| 391 | uint cur_item_id; |
| 392 | uint pointer_id; |
| 393 | struct list_head item_head; |
| 394 | }; |
| 395 | |
| 396 | /** |
| 397 | * enum scene_menuitem_flags_t - flags for menu items |
| 398 | * |
| 399 | * @SCENEMIF_GAP_BEFORE: Add a gap before this item |
| 400 | */ |
| 401 | enum scene_menuitem_flags_t { |
| 402 | SCENEMIF_GAP_BEFORE = 1 << 0, |
| 403 | }; |
| 404 | |
| 405 | /** |
| 406 | * struct scene_menitem - a menu item in a menu |
| 407 | * |
| 408 | * A menu item has: |
| 409 | * |
| 410 | * - text object holding the name (short) and description (can be longer) |
| 411 | * - a text object holding the keypress |
| 412 | * |
| 413 | * @name: Name of the item (this is allocated by this call) |
| 414 | * @id: ID number of the object |
| 415 | * @key_id: ID of text object to use as the keypress to show |
| 416 | * @label_id: ID of text object to use as the label text |
| 417 | * @desc_id: ID of text object to use as the description text |
| 418 | * @preview_id: ID of the preview object, or 0 if none |
| 419 | * @flags: Flags for this item |
Simon Glass | 100389f | 2024-10-14 16:31:58 -0600 | [diff] [blame] | 420 | * @value: Value for this item, or INT_MAX to use sequence |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 421 | * @sibling: Node to link this item to its siblings |
| 422 | */ |
| 423 | struct scene_menitem { |
| 424 | char *name; |
| 425 | uint id; |
| 426 | uint key_id; |
| 427 | uint label_id; |
| 428 | uint desc_id; |
| 429 | uint preview_id; |
| 430 | uint flags; |
Simon Glass | 100389f | 2024-10-14 16:31:58 -0600 | [diff] [blame] | 431 | int value; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 432 | struct list_head sibling; |
| 433 | }; |
| 434 | |
| 435 | /** |
Simon Glass | 6116e76 | 2023-10-01 19:13:32 -0600 | [diff] [blame] | 436 | * struct scene_obj_textline - information about a textline in a scene |
| 437 | * |
| 438 | * A textline has a prompt and a line of editable text |
| 439 | * |
| 440 | * @obj: Basic object information |
| 441 | * @label_id: ID of the label text, or 0 if none |
| 442 | * @edit_id: ID of the editable text |
| 443 | * @max_chars: Maximum number of characters allowed |
| 444 | * @buf: Text buffer containing current text |
| 445 | * @pos: Cursor position |
| 446 | */ |
| 447 | struct scene_obj_textline { |
| 448 | struct scene_obj obj; |
| 449 | uint label_id; |
| 450 | uint edit_id; |
| 451 | uint max_chars; |
| 452 | struct abuf buf; |
| 453 | uint pos; |
| 454 | }; |
| 455 | |
| 456 | /** |
Simon Glass | 138a397 | 2025-05-02 08:46:44 -0600 | [diff] [blame] | 457 | * struct scene_obj_box - information about a box in a scene |
| 458 | * |
| 459 | * A box surrounds a part of the screen with a border |
| 460 | * |
| 461 | * @obj: Basic object information |
| 462 | * @width: Line-width in pixels |
| 463 | */ |
| 464 | struct scene_obj_box { |
| 465 | struct scene_obj obj; |
| 466 | uint width; |
| 467 | }; |
| 468 | |
| 469 | /** |
Simon Glass | 5dc887d | 2025-05-02 08:46:46 -0600 | [diff] [blame] | 470 | * struct scene_obj_txtedit - information about a box in a scene |
| 471 | * |
| 472 | * A text editor which allows users to edit a small text file |
| 473 | * |
| 474 | * @obj: Basic object information |
| 475 | * @gen: Generic information common to all objects which show text |
| 476 | * @buf: Text buffer containing current text |
| 477 | */ |
| 478 | struct scene_obj_txtedit { |
| 479 | struct scene_obj obj; |
| 480 | struct scene_txt_generic gen; |
| 481 | struct abuf buf; |
| 482 | }; |
| 483 | |
| 484 | /** |
Simon Glass | 377f18e | 2024-10-14 16:31:55 -0600 | [diff] [blame] | 485 | * struct expo_arrange_info - Information used when arranging a scene |
| 486 | * |
| 487 | * @label_width: Maximum width of labels in scene |
| 488 | */ |
| 489 | struct expo_arrange_info { |
| 490 | int label_width; |
| 491 | }; |
| 492 | |
| 493 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 494 | * expo_new() - create a new expo |
| 495 | * |
| 496 | * Allocates a new expo |
| 497 | * |
| 498 | * @name: Name of expo (this is allocated by this call) |
| 499 | * @priv: Private data for the controller |
| 500 | * @expp: Returns a pointer to the new expo on success |
| 501 | * Returns: 0 if OK, -ENOMEM if out of memory |
| 502 | */ |
| 503 | int expo_new(const char *name, void *priv, struct expo **expp); |
| 504 | |
| 505 | /** |
| 506 | * expo_destroy() - Destroy an expo and free all its memory |
| 507 | * |
| 508 | * @exp: Expo to destroy |
| 509 | */ |
| 510 | void expo_destroy(struct expo *exp); |
| 511 | |
| 512 | /** |
Simon Glass | 6e9e415 | 2023-06-01 10:22:47 -0600 | [diff] [blame] | 513 | * expo_set_dynamic_start() - Set the start of the 'dynamic' IDs |
| 514 | * |
| 515 | * It is common for a set of 'static' IDs to be used to refer to objects in the |
| 516 | * expo. These typically use an enum so that they are defined in sequential |
| 517 | * order. |
| 518 | * |
| 519 | * Dynamic IDs (for objects not in the enum) are intended to be used for |
| 520 | * objects to which the code does not need to refer. These are ideally located |
| 521 | * above the static IDs. |
| 522 | * |
| 523 | * Use this function to set the start of the dynamic range, making sure that the |
| 524 | * value is higher than all the statically allocated IDs. |
| 525 | * |
| 526 | * @exp: Expo to update |
| 527 | * @dyn_start: Start ID that expo should use for dynamic allocation |
| 528 | */ |
| 529 | void expo_set_dynamic_start(struct expo *exp, uint dyn_start); |
| 530 | |
| 531 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 532 | * expo_str() - add a new string to an expo |
| 533 | * |
| 534 | * @exp: Expo to update |
| 535 | * @name: Name to use (this is allocated by this call) |
| 536 | * @id: ID to use for the new object (0 to allocate one) |
| 537 | * @str: Pointer to text to display (allocated by caller) |
| 538 | * Returns: ID number for the object (typically @id), or -ve on error |
| 539 | */ |
| 540 | int expo_str(struct expo *exp, const char *name, uint id, const char *str); |
| 541 | |
| 542 | /** |
| 543 | * expo_get_str() - Get a string by ID |
| 544 | * |
| 545 | * @exp: Expo to use |
| 546 | * @id: String ID to look up |
| 547 | * @returns string, or NULL if not found |
| 548 | */ |
| 549 | const char *expo_get_str(struct expo *exp, uint id); |
| 550 | |
| 551 | /** |
Simon Glass | c5ae5b1 | 2025-05-02 08:46:40 -0600 | [diff] [blame] | 552 | * expo_edit_str() - Make a string writeable |
| 553 | * |
| 554 | * This allows a string to be updated under the control of the caller. The |
| 555 | * buffer must remain valid while the expo is active. |
| 556 | * |
| 557 | * @exp: Expo to use |
| 558 | * @id: String ID to look up |
| 559 | * @orig: If non-NULL, returns the original buffer, which can be used by the |
| 560 | * caller. It is no-longer used by expo so must be uninited by the caller. |
| 561 | * It contains a snapshot of the string contents |
| 562 | * @copyp: Returns a pointer to the new, writeable buffer |
| 563 | * Return: 0 if OK, -ENOENT if the id was not found, -ENOMEM if out of memory |
| 564 | */ |
| 565 | int expo_edit_str(struct expo *exp, uint id, struct abuf *orig, |
| 566 | struct abuf **copyp); |
| 567 | |
| 568 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 569 | * expo_set_display() - set the display to use for a expo |
| 570 | * |
| 571 | * @exp: Expo to update |
| 572 | * @dev: Display to use (`UCLASS_VIDEO`), NULL to use text mode |
| 573 | * Returns: 0 (always) |
| 574 | */ |
| 575 | int expo_set_display(struct expo *exp, struct udevice *dev); |
| 576 | |
| 577 | /** |
Simon Glass | 7a96005 | 2023-06-01 10:22:52 -0600 | [diff] [blame] | 578 | * expo_calc_dims() - Calculate the dimensions of the objects |
| 579 | * |
| 580 | * Updates the width and height of all objects based on their contents |
| 581 | * |
| 582 | * @exp: Expo to update |
| 583 | * Returns 0 if OK, -ENOTSUPP if there is no graphical console |
| 584 | */ |
| 585 | int expo_calc_dims(struct expo *exp); |
| 586 | |
| 587 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 588 | * expo_set_scene_id() - Set the current scene ID |
| 589 | * |
| 590 | * @exp: Expo to update |
| 591 | * @scene_id: New scene ID to use (0 to select no scene) |
| 592 | * Returns: 0 if OK, -ENOENT if there is no scene with that ID |
| 593 | */ |
| 594 | int expo_set_scene_id(struct expo *exp, uint scene_id); |
| 595 | |
| 596 | /** |
Simon Glass | c892511 | 2023-06-01 10:23:02 -0600 | [diff] [blame] | 597 | * expo_first_scene_id() - Get the ID of the first scene |
| 598 | * |
| 599 | * @exp: Expo to check |
| 600 | * Returns: Scene ID of first scene, or -ENOENT if there are no scenes |
| 601 | */ |
| 602 | int expo_first_scene_id(struct expo *exp); |
| 603 | |
| 604 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 605 | * expo_render() - render the expo on the display / console |
| 606 | * |
| 607 | * @exp: Expo to render |
| 608 | * |
| 609 | * Returns: 0 if OK, -ECHILD if there is no current scene, -ENOENT if the |
| 610 | * current scene is not found, other error if something else goes wrong |
| 611 | */ |
| 612 | int expo_render(struct expo *exp); |
| 613 | |
| 614 | /** |
Simon Glass | b2c4034 | 2023-06-01 10:22:37 -0600 | [diff] [blame] | 615 | * expo_set_text_mode() - Controls whether the expo renders in text mode |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 616 | * |
| 617 | * @exp: Expo to update |
| 618 | * @text_mode: true to use text mode, false to use the console |
| 619 | */ |
Simon Glass | b2c4034 | 2023-06-01 10:22:37 -0600 | [diff] [blame] | 620 | void expo_set_text_mode(struct expo *exp, bool text_mode); |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 621 | |
| 622 | /** |
| 623 | * scene_new() - create a new scene in a expo |
| 624 | * |
| 625 | * The scene is given the ID @id which must be unique across all scenes, objects |
| 626 | * and items. The expo's @next_id is updated to at least @id + 1 |
| 627 | * |
| 628 | * @exp: Expo to update |
| 629 | * @name: Name to use (this is allocated by this call) |
| 630 | * @id: ID to use for the new scene (0 to allocate one) |
| 631 | * @scnp: Returns a pointer to the new scene on success |
| 632 | * Returns: ID number for the scene (typically @id), or -ve on error |
| 633 | */ |
| 634 | int scene_new(struct expo *exp, const char *name, uint id, struct scene **scnp); |
| 635 | |
| 636 | /** |
| 637 | * expo_lookup_scene_id() - Look up a scene by ID |
| 638 | * |
| 639 | * @exp: Expo to check |
| 640 | * @scene_id: Scene ID to look up |
| 641 | * @returns pointer to scene if found, else NULL |
| 642 | */ |
| 643 | struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id); |
| 644 | |
| 645 | /** |
Simon Glass | 01922ec | 2023-06-01 10:22:57 -0600 | [diff] [blame] | 646 | * scene_highlight_first() - Highlight the first item in a scene |
| 647 | * |
| 648 | * This highlights the first item, so that the user can see that it is pointed |
| 649 | * to |
| 650 | * |
| 651 | * @scn: Scene to update |
| 652 | */ |
| 653 | void scene_highlight_first(struct scene *scn); |
| 654 | |
| 655 | /** |
| 656 | * scene_set_highlight_id() - Set the object which is highlighted |
| 657 | * |
| 658 | * Sets a new object to highlight in the scene |
| 659 | * |
| 660 | * @scn: Scene to update |
| 661 | * @id: ID of object to highlight |
| 662 | */ |
| 663 | void scene_set_highlight_id(struct scene *scn, uint id); |
| 664 | |
| 665 | /** |
| 666 | * scene_set_open() - Set whether an item is open or not |
| 667 | * |
| 668 | * @scn: Scene to update |
| 669 | * @id: ID of object to update |
| 670 | * @open: true to open the object, false to close it |
| 671 | * Returns: 0 if OK, -ENOENT if @id is invalid |
| 672 | */ |
| 673 | int scene_set_open(struct scene *scn, uint id, bool open); |
| 674 | |
| 675 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 676 | * scene_obj_count() - Count the number of objects in a scene |
| 677 | * |
| 678 | * @scn: Scene to check |
| 679 | * Returns: number of objects in the scene, 0 if none |
| 680 | */ |
| 681 | int scene_obj_count(struct scene *scn); |
| 682 | |
| 683 | /** |
| 684 | * scene_img() - add a new image to a scene |
| 685 | * |
| 686 | * @scn: Scene to update |
| 687 | * @name: Name to use (this is allocated by this call) |
| 688 | * @id: ID to use for the new object (0 to allocate one) |
| 689 | * @data: Pointer to image data |
| 690 | * @imgp: If non-NULL, returns the new object |
| 691 | * Returns: ID number for the object (typically @id), or -ve on error |
| 692 | */ |
| 693 | int scene_img(struct scene *scn, const char *name, uint id, char *data, |
| 694 | struct scene_obj_img **imgp); |
| 695 | |
| 696 | /** |
| 697 | * scene_txt() - add a new text object to a scene |
| 698 | * |
| 699 | * @scn: Scene to update |
| 700 | * @name: Name to use (this is allocated by this call) |
| 701 | * @id: ID to use for the new object (0 to allocate one) |
| 702 | * @str_id: ID of the string to use |
| 703 | * @txtp: If non-NULL, returns the new object |
| 704 | * Returns: ID number for the object (typically @id), or -ve on error |
| 705 | */ |
| 706 | int scene_txt(struct scene *scn, const char *name, uint id, uint str_id, |
| 707 | struct scene_obj_txt **txtp); |
| 708 | |
| 709 | /** |
Simon Glass | db6a051 | 2023-10-01 19:13:23 -0600 | [diff] [blame] | 710 | * 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] | 711 | * |
| 712 | * @scn: Scene to update |
| 713 | * @name: Name to use (this is allocated by this call) |
| 714 | * @id: ID to use for the new object (0 to allocate one) |
| 715 | * @str_id: ID of the string to use |
| 716 | * @str: Pointer to text to display (allocated by caller) |
| 717 | * @txtp: If non-NULL, returns the new object |
| 718 | * Returns: ID number for the object (typically @id), or -ve on error |
| 719 | */ |
| 720 | int scene_txt_str(struct scene *scn, const char *name, uint id, uint str_id, |
| 721 | const char *str, struct scene_obj_txt **txtp); |
| 722 | |
| 723 | /** |
| 724 | * scene_menu() - create a menu |
| 725 | * |
| 726 | * @scn: Scene to update |
| 727 | * @name: Name to use (this is allocated by this call) |
| 728 | * @id: ID to use for the new object (0 to allocate one) |
| 729 | * @menup: If non-NULL, returns the new object |
| 730 | * Returns: ID number for the object (typically @id), or -ve on error |
| 731 | */ |
| 732 | int scene_menu(struct scene *scn, const char *name, uint id, |
| 733 | struct scene_obj_menu **menup); |
| 734 | |
| 735 | /** |
Simon Glass | 6116e76 | 2023-10-01 19:13:32 -0600 | [diff] [blame] | 736 | * scene_textline() - create a textline |
| 737 | * |
| 738 | * @scn: Scene to update |
| 739 | * @name: Name to use (this is allocated by this call) |
| 740 | * @id: ID to use for the new object (0 to allocate one) |
| 741 | * @max_chars: Maximum length of the textline in characters |
| 742 | * @tlinep: If non-NULL, returns the new object |
| 743 | * Returns: ID number for the object (typically @id), or -ve on error |
| 744 | */ |
| 745 | int scene_textline(struct scene *scn, const char *name, uint id, uint max_chars, |
| 746 | struct scene_obj_textline **tlinep); |
| 747 | |
| 748 | /** |
Simon Glass | 138a397 | 2025-05-02 08:46:44 -0600 | [diff] [blame] | 749 | * scene_box() - create a box |
| 750 | * |
| 751 | * @scn: Scene to update |
| 752 | * @name: Name to use (this is allocated by this call) |
| 753 | * @id: ID to use for the new object (0 to allocate one) |
| 754 | * @width: Line-width in pixels |
| 755 | * @boxp: If non-NULL, returns the new object |
| 756 | * Returns: ID number for the object (typically @id), or -ve on error |
| 757 | */ |
| 758 | int scene_box(struct scene *scn, const char *name, uint id, uint width, |
| 759 | struct scene_obj_box **boxp); |
| 760 | |
| 761 | /** |
Simon Glass | 5dc887d | 2025-05-02 08:46:46 -0600 | [diff] [blame] | 762 | * scene_texted() - create a text editor |
| 763 | * |
| 764 | * @scn: Scene to update |
| 765 | * @name: Name to use (this is allocated by this call) |
| 766 | * @id: ID to use for the new object (0 to allocate one) |
| 767 | * @strid: ID of the string to edit |
| 768 | * @teditp: If non-NULL, returns the new object |
| 769 | * Returns: ID number for the object (typically @id), or -ve on error |
| 770 | */ |
| 771 | int scene_texted(struct scene *scn, const char *name, uint id, uint strid, |
| 772 | struct scene_obj_txtedit **teditp); |
| 773 | |
| 774 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 775 | * scene_txt_set_font() - Set the font for an object |
| 776 | * |
| 777 | * @scn: Scene to update |
| 778 | * @id: ID of object to update |
| 779 | * @font_name: Font name to use (allocated by caller) |
| 780 | * @font_size: Font size to use (nominal height in pixels) |
| 781 | */ |
| 782 | int scene_txt_set_font(struct scene *scn, uint id, const char *font_name, |
| 783 | uint font_size); |
| 784 | |
| 785 | /** |
Simon Glass | 5dc887d | 2025-05-02 08:46:46 -0600 | [diff] [blame] | 786 | * scene_txted_set_font() - Set the font for an object |
| 787 | * |
| 788 | * @scn: Scene to update |
| 789 | * @id: ID of object to update |
| 790 | * @font_name: Font name to use (allocated by caller) |
| 791 | * @font_size: Font size to use (nominal height in pixels) |
| 792 | */ |
| 793 | int scene_txted_set_font(struct scene *scn, uint id, const char *font_name, |
| 794 | uint font_size); |
| 795 | |
| 796 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 797 | * scene_obj_set_pos() - Set the postion of an object |
| 798 | * |
| 799 | * @scn: Scene to update |
| 800 | * @id: ID of object to update |
| 801 | * @x: x position, in pixels from left side |
| 802 | * @y: y position, in pixels from top |
| 803 | * Returns: 0 if OK, -ENOENT if @id is invalid |
| 804 | */ |
| 805 | int scene_obj_set_pos(struct scene *scn, uint id, int x, int y); |
| 806 | |
| 807 | /** |
Simon Glass | 7a96005 | 2023-06-01 10:22:52 -0600 | [diff] [blame] | 808 | * scene_obj_set_size() - Set the size of an object |
| 809 | * |
| 810 | * @scn: Scene to update |
| 811 | * @id: ID of object to update |
| 812 | * @w: width in pixels |
| 813 | * @h: height in pixels |
| 814 | * Returns: 0 if OK, -ENOENT if @id is invalid |
| 815 | */ |
| 816 | int scene_obj_set_size(struct scene *scn, uint id, int w, int h); |
| 817 | |
| 818 | /** |
Simon Glass | c6143dc | 2025-05-02 08:46:35 -0600 | [diff] [blame] | 819 | * scene_obj_set_width() - Set the width of an object |
| 820 | * |
| 821 | * @scn: Scene to update |
| 822 | * @id: ID of object to update |
| 823 | * @w: width in pixels |
| 824 | * Returns: 0 if OK, -ENOENT if @id is invalid |
| 825 | */ |
| 826 | int scene_obj_set_width(struct scene *scn, uint id, int w); |
| 827 | |
| 828 | /** |
| 829 | * scene_obj_set_bbox() - Set the bounding box of an object |
| 830 | * |
| 831 | * @scn: Scene to update |
| 832 | * @id: ID of object to update |
| 833 | * @x0: x position, in pixels from left side |
| 834 | * @y0: y position, in pixels from top |
| 835 | * @x1: ending x position (right side) |
| 836 | * @y1: ending y position (botton side) |
| 837 | * Returns: 0 if OK, -ENOENT if @id is invalid |
| 838 | */ |
| 839 | int scene_obj_set_bbox(struct scene *scn, uint id, int x0, int y0, int x1, |
| 840 | int y1); |
| 841 | |
| 842 | /** |
Simon Glass | 5beb057 | 2025-05-02 08:46:45 -0600 | [diff] [blame] | 843 | * scene_obj_set_halign() - Set the horizontal alignment of an object |
| 844 | * |
| 845 | * @scn: Scene to update |
| 846 | * @id: ID of object to update |
| 847 | * @aln: Horizontal alignment to use |
| 848 | * Returns: 0 if OK, -ENOENT if @id is invalid |
| 849 | */ |
| 850 | int scene_obj_set_halign(struct scene *scn, uint id, enum scene_obj_align aln); |
| 851 | |
| 852 | /** |
| 853 | * scene_obj_set_valign() - Set the vertical alignment of an object |
| 854 | * |
| 855 | * @scn: Scene to update |
| 856 | * @id: ID of object to update |
| 857 | * @aln: Vertical alignment to use |
| 858 | * Returns: 0 if OK, -ENOENT if @id is invalid |
| 859 | */ |
| 860 | int scene_obj_set_valign(struct scene *scn, uint id, enum scene_obj_align aln); |
| 861 | |
| 862 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 863 | * scene_obj_set_hide() - Set whether an object is hidden |
| 864 | * |
| 865 | * The update happens when the expo is next rendered. |
| 866 | * |
| 867 | * @scn: Scene to update |
| 868 | * @id: ID of object to update |
| 869 | * @hide: true to hide the object, false to show it |
| 870 | * Returns: 0 if OK, -ENOENT if @id is invalid |
| 871 | */ |
| 872 | int scene_obj_set_hide(struct scene *scn, uint id, bool hide); |
| 873 | |
| 874 | /** |
| 875 | * scene_menu_set_title() - Set the title of a menu |
| 876 | * |
| 877 | * @scn: Scene to update |
| 878 | * @id: ID of menu object to update |
| 879 | * @title_id: ID of text object to use as the title |
| 880 | * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @title_id is invalid |
| 881 | */ |
| 882 | int scene_menu_set_title(struct scene *scn, uint id, uint title_id); |
| 883 | |
| 884 | /** |
| 885 | * scene_menu_set_pointer() - Set the item pointer for a menu |
| 886 | * |
| 887 | * This is a visual indicator of the current item, typically a ">" character |
| 888 | * which sits next to the current item and moves when the user presses the |
| 889 | * up/down arrow keys |
| 890 | * |
| 891 | * @scn: Scene to update |
| 892 | * @id: ID of menu object to update |
| 893 | * @cur_item_id: ID of text or image object to use as a pointer to the current |
| 894 | * item |
| 895 | * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @cur_item_id is invalid |
| 896 | */ |
| 897 | int scene_menu_set_pointer(struct scene *scn, uint id, uint cur_item_id); |
| 898 | |
| 899 | /** |
Simon Glass | be04b96 | 2025-05-02 08:46:24 -0600 | [diff] [blame] | 900 | * scene_menu_select_item() - move the pointer/highlight to an item |
| 901 | * |
| 902 | * @scn: Scene to update |
| 903 | * @id: ID of menu object to update |
| 904 | * @sel_id: ID of the menuitem to select |
| 905 | * Return 0 on success, -ENOENT if there was no such item |
| 906 | */ |
| 907 | int scene_menu_select_item(struct scene *scn, uint id, uint sel_id); |
| 908 | |
| 909 | /** |
| 910 | * scene_menu_get_cur_item() - get the currently pointed-to item |
| 911 | * |
| 912 | * @scn: Scene to update |
| 913 | * @id: ID of menu object to update |
| 914 | * Return ID of the current item the menu is pointing to, -ENOENT if @id is not |
| 915 | * valid, 0 if no item is pointed to |
| 916 | */ |
| 917 | int scene_menu_get_cur_item(struct scene *scn, uint id); |
| 918 | |
| 919 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 920 | * scene_obj_get_hw() - Get width and height of an object in a scene |
| 921 | * |
| 922 | * @scn: Scene to check |
| 923 | * @id: ID of menu object to check |
| 924 | * @widthp: If non-NULL, returns width of object in pixels |
| 925 | * Returns: Height of object in pixels |
| 926 | */ |
| 927 | int scene_obj_get_hw(struct scene *scn, uint id, int *widthp); |
| 928 | |
| 929 | /** |
| 930 | * scene_menuitem() - Add an item to a menu |
| 931 | * |
| 932 | * @scn: Scene to update |
| 933 | * @menu_id: ID of menu object to update |
| 934 | * @name: Name to use (this is allocated by this call) |
| 935 | * @id: ID to use for the new object (0 to allocate one) |
| 936 | * @key_id: ID of text object to use as the keypress to show |
| 937 | * @label_id: ID of text object to use as the label text |
| 938 | * @desc_id: ID of text object to use as the description text |
| 939 | * @preview_id: ID of object to use as the preview (text or image) |
| 940 | * @flags: Flags for this item (enum scene_menuitem_flags_t) |
| 941 | * @itemp: If non-NULL, returns the new object |
| 942 | * Returns: ID number for the item (typically @id), or -ve on error |
| 943 | */ |
| 944 | int scene_menuitem(struct scene *scn, uint menu_id, const char *name, uint id, |
| 945 | uint key_id, uint label_id, uint desc_id, uint preview_id, |
| 946 | uint flags, struct scene_menitem **itemp); |
| 947 | |
| 948 | /** |
| 949 | * scene_arrange() - Arrange the scene to deal with object sizes |
| 950 | * |
| 951 | * Updates any menus in the scene so that their objects are in the right place. |
| 952 | * |
| 953 | * @scn: Scene to arrange |
| 954 | * Returns: 0 if OK, -ve on error |
| 955 | */ |
| 956 | int scene_arrange(struct scene *scn); |
| 957 | |
| 958 | /** |
| 959 | * expo_send_key() - set a keypress to the expo |
| 960 | * |
| 961 | * @exp: Expo to receive the key |
| 962 | * @key: Key to send (ASCII or enum bootmenu_key) |
| 963 | * Returns: 0 if OK, -ECHILD if there is no current scene |
| 964 | */ |
| 965 | int expo_send_key(struct expo *exp, int key); |
| 966 | |
| 967 | /** |
| 968 | * expo_action_get() - read user input from the expo |
| 969 | * |
| 970 | * @exp: Expo to check |
| 971 | * @act: Returns action |
| 972 | * Returns: 0 if OK, -EAGAIN if there was no action to return |
| 973 | */ |
| 974 | int expo_action_get(struct expo *exp, struct expo_action *act); |
| 975 | |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 976 | /** |
| 977 | * expo_apply_theme() - Apply a theme to an expo |
| 978 | * |
| 979 | * @exp: Expo to update |
| 980 | * @node: Node containing the theme |
| 981 | */ |
| 982 | int expo_apply_theme(struct expo *exp, ofnode node); |
| 983 | |
Simon Glass | 6130072 | 2023-06-01 10:23:01 -0600 | [diff] [blame] | 984 | /** |
| 985 | * expo_build() - Build an expo from an FDT description |
| 986 | * |
| 987 | * Build a complete expo from a description in the provided devicetree. |
| 988 | * |
Massimo Pegorer | c8c7002 | 2023-09-09 12:32:28 +0200 | [diff] [blame] | 989 | * See doc/develop/expo.rst for a description of the format |
Simon Glass | 6130072 | 2023-06-01 10:23:01 -0600 | [diff] [blame] | 990 | * |
| 991 | * @root: Root node for expo description |
| 992 | * @expp: Returns the new expo |
| 993 | * Returns: 0 if OK, -ENOMEM if out of memory, -EINVAL if there is a format |
| 994 | * error, -ENOENT if there is a references to a non-existent string |
| 995 | */ |
| 996 | int expo_build(ofnode root, struct expo **expp); |
| 997 | |
Simon Glass | 3434420 | 2024-10-14 16:32:11 -0600 | [diff] [blame] | 998 | /** |
| 999 | * cb_expo_build() - Build an expo for coreboot CMOS RAM |
| 1000 | * |
| 1001 | * @expp: Returns the expo created |
| 1002 | * Return: 0 if OK, -ve on error |
| 1003 | */ |
| 1004 | int cb_expo_build(struct expo **expp); |
| 1005 | |
Simon Glass | 137b442 | 2025-05-02 08:46:16 -0600 | [diff] [blame] | 1006 | /** |
| 1007 | * expo_poll() - render an expo and see if the user takes an action |
| 1008 | * |
| 1009 | * Thsi calls expo_render() and then checks for a keypress. If there is one, it |
| 1010 | * is processed and the resulting action returned, if any |
| 1011 | * |
| 1012 | * @exp: Expo to poll |
| 1013 | * @act: Returns action on success |
| 1014 | * Return: 0 if an action was obtained, -EAGAIN if not, other error if something |
| 1015 | * went wrong |
| 1016 | */ |
| 1017 | int expo_poll(struct expo *exp, struct expo_action *act); |
| 1018 | |
Simon Glass | 8df4a4e | 2023-08-14 16:40:25 -0600 | [diff] [blame] | 1019 | #endif /*__EXPO_H */ |