1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright 2022 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
10 #include <linux/list.h>
15 * enum expoact_type - types of actions reported by the expo
17 * @EXPOACT_NONE: no action
18 * @EXPOACT_POINT: menu item was highlighted (@id indicates which)
19 * @EXPOACT_SELECT: menu item was selected (@id indicates which)
20 * @EXPOACT_QUIT: request to exit the menu
30 * struct expo_action - an action report by the expo
32 * @type: Action type (EXPOACT_NONE if there is no action)
33 * @select: Used for EXPOACT_POINT and EXPOACT_SELECT
34 * @id: ID number of the object affected.
37 enum expoact_type type;
46 * struct expo - information about an expo
48 * A group of scenes which can be presented to the user, typically to obtain
49 * input or to make a selection.
51 * @name: Name of the expo (allocated)
52 * @display: Display to use (`UCLASS_VIDEO`), or NULL to use text mode
53 * @scene_id: Current scene ID (0 if none)
54 * @next_id: Next ID number to use, for automatic allocation
55 * @action: Action selected by user. At present only one is supported, with the
56 * type set to EXPOACT_NONE if there is no action
57 * @text_mode: true to use text mode for the menu (no vidconsole)
58 * @priv: Private data for the controller
59 * @scene_head: List of scenes
60 * @str_head: list of strings
64 struct udevice *display;
67 struct expo_action action;
70 struct list_head scene_head;
71 struct list_head str_head;
75 * struct expo_string - a string that can be used in an expo
77 * @id: ID number of the string
79 * @sibling: Node to link this object to its siblings
84 struct list_head sibling;
88 * struct scene - information about a scene in an expo
90 * A collection of text/image/menu items in an expo
92 * @expo: Expo this scene is part of
93 * @name: Name of the scene (allocated)
94 * @id: ID number of the scene
95 * @title: Title of the scene (allocated)
96 * @sibling: Node to link this scene to its siblings
97 * @obj_head: List of objects in the scene
104 struct list_head sibling;
105 struct list_head obj_head;
109 * enum scene_obj_t - type of a scene object
111 * @SCENEOBJT_NONE: Used to indicate that the type does not matter
112 * @SCENEOBJT_IMAGE: Image data to render
113 * @SCENEOBJT_TEXT: Text line to render
114 * @SCENEOBJT_MENU: Menu containing items the user can select
124 * struct scene_obj - information about an object in a scene
126 * @scene: Scene that this object relates to
127 * @name: Name of the object (allocated)
128 * @id: ID number of the object
129 * @type: Type of this object
130 * @x: x position, in pixels from left side
131 * @y: y position, in pixels from top
132 * @hide: true if the object should be hidden
133 * @sibling: Node to link this object to its siblings
139 enum scene_obj_t type;
143 struct list_head sibling;
147 * struct scene_obj_img - information about an image object in a scene
149 * This is a rectangular image which is blitted onto the display
151 * @obj: Basic object information
152 * @data: Image data in BMP format
154 struct scene_obj_img {
155 struct scene_obj obj;
160 * struct scene_obj_txt - information about a text object in a scene
162 * This is a single-line text object
164 * @obj: Basic object information
165 * @str_id: ID of the text string to display
166 * @font_name: Name of font (allocated by caller)
167 * @font_size: Nominal size of font in pixels
169 struct scene_obj_txt {
170 struct scene_obj obj;
172 const char *font_name;
177 * struct scene_obj_menu - information about a menu object in a scene
179 * A menu has a number of items which can be selected by the user
183 * - a text/image object (@pointer_id) which points to the current item
186 * - a preview object which shows an image related to the current item
188 * @obj: Basic object information
189 * @title_id: ID of the title text, or 0 if none
190 * @cur_item_id: ID of the current menu item, or 0 if none
191 * @pointer_id: ID of the object pointing to the current selection
192 * @item_head: List of items in the menu
194 struct scene_obj_menu {
195 struct scene_obj obj;
199 struct list_head item_head;
203 * enum scene_menuitem_flags_t - flags for menu items
205 * @SCENEMIF_GAP_BEFORE: Add a gap before this item
207 enum scene_menuitem_flags_t {
208 SCENEMIF_GAP_BEFORE = 1 << 0,
212 * struct scene_menitem - a menu item in a menu
216 * - text object holding the name (short) and description (can be longer)
217 * - a text object holding the keypress
219 * @name: Name of the item (this is allocated by this call)
220 * @id: ID number of the object
221 * @key_id: ID of text object to use as the keypress to show
222 * @label_id: ID of text object to use as the label text
223 * @desc_id: ID of text object to use as the description text
224 * @preview_id: ID of the preview object, or 0 if none
225 * @flags: Flags for this item
226 * @sibling: Node to link this item to its siblings
228 struct scene_menitem {
236 struct list_head sibling;
240 * expo_new() - create a new expo
242 * Allocates a new expo
244 * @name: Name of expo (this is allocated by this call)
245 * @priv: Private data for the controller
246 * @expp: Returns a pointer to the new expo on success
247 * Returns: 0 if OK, -ENOMEM if out of memory
249 int expo_new(const char *name, void *priv, struct expo **expp);
252 * expo_destroy() - Destroy an expo and free all its memory
254 * @exp: Expo to destroy
256 void expo_destroy(struct expo *exp);
259 * expo_str() - add a new string to an expo
261 * @exp: Expo to update
262 * @name: Name to use (this is allocated by this call)
263 * @id: ID to use for the new object (0 to allocate one)
264 * @str: Pointer to text to display (allocated by caller)
265 * Returns: ID number for the object (typically @id), or -ve on error
267 int expo_str(struct expo *exp, const char *name, uint id, const char *str);
270 * expo_get_str() - Get a string by ID
273 * @id: String ID to look up
274 * @returns string, or NULL if not found
276 const char *expo_get_str(struct expo *exp, uint id);
279 * expo_set_display() - set the display to use for a expo
281 * @exp: Expo to update
282 * @dev: Display to use (`UCLASS_VIDEO`), NULL to use text mode
283 * Returns: 0 (always)
285 int expo_set_display(struct expo *exp, struct udevice *dev);
288 * expo_set_scene_id() - Set the current scene ID
290 * @exp: Expo to update
291 * @scene_id: New scene ID to use (0 to select no scene)
292 * Returns: 0 if OK, -ENOENT if there is no scene with that ID
294 int expo_set_scene_id(struct expo *exp, uint scene_id);
297 * expo_render() - render the expo on the display / console
299 * @exp: Expo to render
301 * Returns: 0 if OK, -ECHILD if there is no current scene, -ENOENT if the
302 * current scene is not found, other error if something else goes wrong
304 int expo_render(struct expo *exp);
307 * exp_set_text_mode() - Controls whether the expo renders in text mode
309 * @exp: Expo to update
310 * @text_mode: true to use text mode, false to use the console
312 void exp_set_text_mode(struct expo *exp, bool text_mode);
315 * scene_new() - create a new scene in a expo
317 * The scene is given the ID @id which must be unique across all scenes, objects
318 * and items. The expo's @next_id is updated to at least @id + 1
320 * @exp: Expo to update
321 * @name: Name to use (this is allocated by this call)
322 * @id: ID to use for the new scene (0 to allocate one)
323 * @scnp: Returns a pointer to the new scene on success
324 * Returns: ID number for the scene (typically @id), or -ve on error
326 int scene_new(struct expo *exp, const char *name, uint id, struct scene **scnp);
329 * expo_lookup_scene_id() - Look up a scene by ID
331 * @exp: Expo to check
332 * @scene_id: Scene ID to look up
333 * @returns pointer to scene if found, else NULL
335 struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id);
338 * scene_title_set() - set the scene title
340 * @scn: Scene to update
341 * @title: Title to set, NULL if none (this is allocated by this call)
342 * Returns: 0 if OK, -ENOMEM if out of memory
344 int scene_title_set(struct scene *scn, const char *title);
347 * scene_obj_count() - Count the number of objects in a scene
349 * @scn: Scene to check
350 * Returns: number of objects in the scene, 0 if none
352 int scene_obj_count(struct scene *scn);
355 * scene_img() - add a new image to a scene
357 * @scn: Scene to update
358 * @name: Name to use (this is allocated by this call)
359 * @id: ID to use for the new object (0 to allocate one)
360 * @data: Pointer to image data
361 * @imgp: If non-NULL, returns the new object
362 * Returns: ID number for the object (typically @id), or -ve on error
364 int scene_img(struct scene *scn, const char *name, uint id, char *data,
365 struct scene_obj_img **imgp);
368 * scene_txt() - add a new text object to a scene
370 * @scn: Scene to update
371 * @name: Name to use (this is allocated by this call)
372 * @id: ID to use for the new object (0 to allocate one)
373 * @str_id: ID of the string to use
374 * @txtp: If non-NULL, returns the new object
375 * Returns: ID number for the object (typically @id), or -ve on error
377 int scene_txt(struct scene *scn, const char *name, uint id, uint str_id,
378 struct scene_obj_txt **txtp);
381 * scene_txt_str() - add a new string to expr and text object to a scene
383 * @scn: Scene to update
384 * @name: Name to use (this is allocated by this call)
385 * @id: ID to use for the new object (0 to allocate one)
386 * @str_id: ID of the string to use
387 * @str: Pointer to text to display (allocated by caller)
388 * @txtp: If non-NULL, returns the new object
389 * Returns: ID number for the object (typically @id), or -ve on error
391 int scene_txt_str(struct scene *scn, const char *name, uint id, uint str_id,
392 const char *str, struct scene_obj_txt **txtp);
395 * scene_menu() - create a menu
397 * @scn: Scene to update
398 * @name: Name to use (this is allocated by this call)
399 * @id: ID to use for the new object (0 to allocate one)
400 * @menup: If non-NULL, returns the new object
401 * Returns: ID number for the object (typically @id), or -ve on error
403 int scene_menu(struct scene *scn, const char *name, uint id,
404 struct scene_obj_menu **menup);
407 * scene_txt_set_font() - Set the font for an object
409 * @scn: Scene to update
410 * @id: ID of object to update
411 * @font_name: Font name to use (allocated by caller)
412 * @font_size: Font size to use (nominal height in pixels)
414 int scene_txt_set_font(struct scene *scn, uint id, const char *font_name,
418 * scene_obj_set_pos() - Set the postion of an object
420 * @scn: Scene to update
421 * @id: ID of object to update
422 * @x: x position, in pixels from left side
423 * @y: y position, in pixels from top
424 * Returns: 0 if OK, -ENOENT if @id is invalid
426 int scene_obj_set_pos(struct scene *scn, uint id, int x, int y);
429 * scene_obj_set_hide() - Set whether an object is hidden
431 * The update happens when the expo is next rendered.
433 * @scn: Scene to update
434 * @id: ID of object to update
435 * @hide: true to hide the object, false to show it
436 * Returns: 0 if OK, -ENOENT if @id is invalid
438 int scene_obj_set_hide(struct scene *scn, uint id, bool hide);
441 * scene_menu_set_title() - Set the title of a menu
443 * @scn: Scene to update
444 * @id: ID of menu object to update
445 * @title_id: ID of text object to use as the title
446 * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @title_id is invalid
448 int scene_menu_set_title(struct scene *scn, uint id, uint title_id);
451 * scene_menu_set_pointer() - Set the item pointer for a menu
453 * This is a visual indicator of the current item, typically a ">" character
454 * which sits next to the current item and moves when the user presses the
457 * @scn: Scene to update
458 * @id: ID of menu object to update
459 * @cur_item_id: ID of text or image object to use as a pointer to the current
461 * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @cur_item_id is invalid
463 int scene_menu_set_pointer(struct scene *scn, uint id, uint cur_item_id);
466 * scene_obj_get_hw() - Get width and height of an object in a scene
468 * @scn: Scene to check
469 * @id: ID of menu object to check
470 * @widthp: If non-NULL, returns width of object in pixels
471 * Returns: Height of object in pixels
473 int scene_obj_get_hw(struct scene *scn, uint id, int *widthp);
476 * scene_menuitem() - Add an item to a menu
478 * @scn: Scene to update
479 * @menu_id: ID of menu object to update
480 * @name: Name to use (this is allocated by this call)
481 * @id: ID to use for the new object (0 to allocate one)
482 * @key_id: ID of text object to use as the keypress to show
483 * @label_id: ID of text object to use as the label text
484 * @desc_id: ID of text object to use as the description text
485 * @preview_id: ID of object to use as the preview (text or image)
486 * @flags: Flags for this item (enum scene_menuitem_flags_t)
487 * @itemp: If non-NULL, returns the new object
488 * Returns: ID number for the item (typically @id), or -ve on error
490 int scene_menuitem(struct scene *scn, uint menu_id, const char *name, uint id,
491 uint key_id, uint label_id, uint desc_id, uint preview_id,
492 uint flags, struct scene_menitem **itemp);
495 * scene_arrange() - Arrange the scene to deal with object sizes
497 * Updates any menus in the scene so that their objects are in the right place.
499 * @scn: Scene to arrange
500 * Returns: 0 if OK, -ve on error
502 int scene_arrange(struct scene *scn);
505 * expo_send_key() - set a keypress to the expo
507 * @exp: Expo to receive the key
508 * @key: Key to send (ASCII or enum bootmenu_key)
509 * Returns: 0 if OK, -ECHILD if there is no current scene
511 int expo_send_key(struct expo *exp, int key);
514 * expo_action_get() - read user input from the expo
516 * @exp: Expo to check
517 * @act: Returns action
518 * Returns: 0 if OK, -EAGAIN if there was no action to return
520 int expo_action_get(struct expo *exp, struct expo_action *act);
522 #endif /*__SCENE_H */