blob: 695a907dc6af51075d0740e162811540fffa040b [file] [log] [blame]
Simon Glass5e2607a2023-01-06 08:52:37 -06001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Internal header file for scenes
4 *
5 * Copyright 2022 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
7 */
8
9#ifndef __SCENE_INTERNAL_H
10#define __SCENE_INTERNAL_H
11
Simon Glassf2eb6ad2023-08-14 16:40:23 -060012typedef int (*expo_scene_obj_iterator)(struct scene_obj *obj, void *priv);
13
Simon Glass5e2607a2023-01-06 08:52:37 -060014/**
15 * expo_lookup_scene_id() - Look up a scene ID
16 *
17 * @exp: Expo to use
18 * @id: scene ID to look up
19 * Returns: Scene for that ID, or NULL if none
20 */
21struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id);
22
23/**
24 * resolve_id() - Automatically allocate an ID if needed
25 *
26 * @exp: Expo to use
27 * @id: ID to use, or 0 to auto-allocate one
Simon Glassd2043b52023-06-01 10:22:26 -060028 * Returns: Either @id, or the auto-allocated ID
Simon Glass5e2607a2023-01-06 08:52:37 -060029 */
30uint resolve_id(struct expo *exp, uint id);
31
32/**
33 * scene_obj_find() - Find an object in a scene
34 *
35 * Note that @type is used to restrict the search when the object type is known.
36 * If any type is acceptable, set @type to SCENEOBJT_NONE
37 *
38 * @scn: Scene to search
39 * @id: ID of object to find
40 * @type: Type of the object, or SCENEOBJT_NONE to match any type
Simon Glassd2043b52023-06-01 10:22:26 -060041 * Returns: Object found, or NULL if not found
Simon Glass5e2607a2023-01-06 08:52:37 -060042 */
Simon Glass633b3dc2023-08-14 16:40:21 -060043void *scene_obj_find(const struct scene *scn, uint id, enum scene_obj_t type);
Simon Glass5e2607a2023-01-06 08:52:37 -060044
45/**
Simon Glassa0874dc2023-06-01 10:23:02 -060046 * scene_obj_find_by_name() - Find an object in a scene by name
47 *
48 * @scn: Scene to search
49 * @name: Name to search for
50 */
51void *scene_obj_find_by_name(struct scene *scn, const char *name);
52
53/**
Simon Glass5e2607a2023-01-06 08:52:37 -060054 * scene_obj_add() - Add a new object to a scene
55 *
56 * @scn: Scene to update
57 * @name: Name to use (this is allocated by this call)
58 * @id: ID to use for the new object (0 to allocate one)
59 * @type: Type of object to add
60 * @size: Size to allocate for the object, in bytes
61 * @objp: Returns a pointer to the new object (must not be NULL)
62 * Returns: ID number for the object (generally @id), or -ve on error
63 */
64int scene_obj_add(struct scene *scn, const char *name, uint id,
65 enum scene_obj_t type, uint size, struct scene_obj **objp);
66
67/**
Simon Glassce72c9e2023-06-01 10:22:50 -060068 * scene_obj_flag_clrset() - Adjust object flags
69 *
70 * @scn: Scene to update
71 * @id: ID of object to update
72 * @clr: Bits to clear in the object's flags
73 * @set: Bits to set in the object's flags
74 * Returns 0 if OK, -ENOENT if the object was not found
75 */
76int scene_obj_flag_clrset(struct scene *scn, uint id, uint clr, uint set);
77
78/**
Simon Glass699b0ac2023-06-01 10:22:52 -060079 * scene_calc_dims() - Calculate the dimensions of the scene objects
80 *
81 * Updates the width and height of all objects based on their contents
82 *
83 * @scn: Scene to update
84 * @do_menus: true to calculate only menus, false to calculate everything else
85 * Returns 0 if OK, -ENOTSUPP if there is no graphical console
86 */
87int scene_calc_dims(struct scene *scn, bool do_menus);
88
89/**
Simon Glass5e2607a2023-01-06 08:52:37 -060090 * scene_menu_arrange() - Set the position of things in the menu
91 *
92 * This updates any items associated with a menu to make sure they are
93 * positioned correctly relative to the menu. It also selects the first item
94 * if not already done
95 *
96 * @scn: Scene to update
97 * @menu: Menu to process
Simon Glassd2043b52023-06-01 10:22:26 -060098 * Returns: 0 if OK, -ve on error
Simon Glass5e2607a2023-01-06 08:52:37 -060099 */
100int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu);
101
102/**
Simon Glass2e593892023-06-01 10:22:53 -0600103 * scene_apply_theme() - Apply a theme to a scene
104 *
105 * @scn: Scene to update
106 * @theme: Theme to apply
107 * Returns: 0 if OK, -ve on error
108 */
109int scene_apply_theme(struct scene *scn, struct expo_theme *theme);
110
111/**
Simon Glass5e2607a2023-01-06 08:52:37 -0600112 * scene_menu_send_key() - Send a key to a menu for processing
113 *
114 * @scn: Scene to use
115 * @menu: Menu to use
116 * @key: Key code to send (KEY_...)
117 * @event: Place to put any event which is generated by the key
Simon Glassd2043b52023-06-01 10:22:26 -0600118 * Returns: 0 if OK, -ENOTTY if there is no current menu item, other -ve on other
Simon Glass5e2607a2023-01-06 08:52:37 -0600119 * error
120 */
121int scene_menu_send_key(struct scene *scn, struct scene_obj_menu *menu, int key,
122 struct expo_action *event);
123
124/**
125 * scene_menu_destroy() - Destroy a menu in a scene
126 *
127 * @scn: Scene to destroy
128 */
129void scene_menu_destroy(struct scene_obj_menu *menu);
130
131/**
132 * scene_menu_display() - Display a menu as text
133 *
134 * @menu: Menu to display
Simon Glassd2043b52023-06-01 10:22:26 -0600135 * Returns: 0 if OK, -ENOENT if @id is invalid
Simon Glass5e2607a2023-01-06 08:52:37 -0600136 */
137int scene_menu_display(struct scene_obj_menu *menu);
138
139/**
140 * scene_destroy() - Destroy a scene and all its memory
141 *
142 * @scn: Scene to destroy
143 */
144void scene_destroy(struct scene *scn);
145
146/**
147 * scene_render() - Render a scene
148 *
149 * This is called from expo_render()
150 *
151 * @scn: Scene to render
152 * Returns: 0 if OK, -ve on error
153 */
154int scene_render(struct scene *scn);
155
156/**
157 * scene_send_key() - set a keypress to a scene
158 *
159 * @scn: Scene to receive the key
160 * @key: Key to send (KEYCODE_UP)
161 * @event: Returns resulting event from this keypress
162 * Returns: 0 if OK, -ve on error
163 */
164int scene_send_key(struct scene *scn, int key, struct expo_action *event);
165
Simon Glass699b0ac2023-06-01 10:22:52 -0600166/**
Simon Glass756c9552023-06-01 10:22:57 -0600167 * scene_menu_render() - Render the background behind a menu
168 *
169 * @menu: Menu to render
170 */
171void scene_menu_render(struct scene_obj_menu *menu);
172
173/**
Simon Glass4c87e072023-06-01 10:22:58 -0600174 * scene_render_deps() - Render an object and its dependencies
175 *
176 * @scn: Scene to render
177 * @id: Object ID to render (or 0 for none)
178 * Returns: 0 if OK, -ve on error
179 */
180int scene_render_deps(struct scene *scn, uint id);
181
182/**
183 * scene_menu_render_deps() - Render a menu and its dependencies
184 *
185 * Renders the menu and all of its attached objects
186 *
187 * @scn: Scene to render
188 * @menu: Menu render
189 * Returns: 0 if OK, -ve on error
190 */
191int scene_menu_render_deps(struct scene *scn, struct scene_obj_menu *menu);
192
193/**
Simon Glass699b0ac2023-06-01 10:22:52 -0600194 * scene_menu_calc_dims() - Calculate the dimensions of a menu
195 *
196 * Updates the width and height of the menu based on its contents
197 *
198 * @menu: Menu to update
199 * Returns 0 if OK, -ENOTSUPP if there is no graphical console
200 */
201int scene_menu_calc_dims(struct scene_obj_menu *menu);
202
Simon Glassf2eb6ad2023-08-14 16:40:23 -0600203/**
204 * scene_iter_objs() - Iterate through all scene objects
205 *
206 * @scn: Scene to process
207 * @iter: Iterator to call on each object
208 * @priv: Private data to pass to the iterator, in addition to the object
209 * Return: 0 if OK, -ve on error
210 */
211int scene_iter_objs(struct scene *scn, expo_scene_obj_iterator iter,
212 void *priv);
213
214/**
215 * expo_iter_scene_objects() - Iterate through all scene objects
216 *
217 * @exp: Expo to process
218 * @iter: Iterator to call on each object
219 * @priv: Private data to pass to the iterator, in addition to the object
220 * Return: 0 if OK, -ve on error
221 */
222int expo_iter_scene_objs(struct expo *exp, expo_scene_obj_iterator iter,
223 void *priv);
224
Simon Glass6e648fa2023-08-14 16:40:32 -0600225/**
226 * scene_menuitem_find() - Find the menu item for an ID
227 *
228 * Looks up the menu to find the item with the given ID
229 *
230 * @menu: Menu to check
231 * @id: ID to look for
232 * Return: Menu item, or NULL if not found
233 */
234struct scene_menitem *scene_menuitem_find(const struct scene_obj_menu *menu,
235 int id);
236
Simon Glasscfc402d2023-08-14 16:40:38 -0600237/**
238 * scene_menuitem_find_seq() - Find the menu item at a sequential position
239 *
240 * This numbers the items from 0 and returns the seq'th one
241 *
242 * @menu: Menu to check
243 * @seq: Sequence number to look for
244 * Return: menu item if found, else NULL
245 */
246struct scene_menitem *scene_menuitem_find_seq(const struct scene_obj_menu *menu,
247 uint seq);
248
Simon Glass5e2607a2023-01-06 08:52:37 -0600249#endif /* __SCENE_INTERNAL_H */