blob: ac2a36d6e4dadd7c89945092f1314b4aaa9c7c28 [file] [log] [blame]
Simon Glass0a4d14b2023-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 Glassf0994692023-10-01 19:13:29 -060012struct vidconsole_bbox;
13
Simon Glasse90acd82023-08-14 16:40:23 -060014typedef int (*expo_scene_obj_iterator)(struct scene_obj *obj, void *priv);
15
Simon Glass0a4d14b2023-01-06 08:52:37 -060016/**
Simon Glass96910ef2025-05-02 08:46:34 -060017 * enum scene_bbox_t - Parts of an object which can have a bounding box
18 *
19 * Objects can provide any or all of these bounding boxes
20 *
21 * @SCENEBB_label: Menu-item label
22 * @SCENEBB_key: Menu-item key label
23 * @SCENEBB_desc: Menu-item Description
24 * @SCENEBB_curitem: Current item (pointed to)
25 * @SCENEBB_all: All the above objects combined
26 */
27enum scene_bbox_t {
28 SCENEBB_label,
29 SCENEBB_key,
30 SCENEBB_desc,
31 SCENEBB_curitem,
32 SCENEBB_all,
33
34 SCENEBB_count,
35};
36
37/**
Simon Glass0a4d14b2023-01-06 08:52:37 -060038 * expo_lookup_scene_id() - Look up a scene ID
39 *
40 * @exp: Expo to use
41 * @id: scene ID to look up
42 * Returns: Scene for that ID, or NULL if none
43 */
44struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id);
45
46/**
47 * resolve_id() - Automatically allocate an ID if needed
48 *
49 * @exp: Expo to use
50 * @id: ID to use, or 0 to auto-allocate one
Simon Glassc6e9f4c2023-06-01 10:22:26 -060051 * Returns: Either @id, or the auto-allocated ID
Simon Glass0a4d14b2023-01-06 08:52:37 -060052 */
53uint resolve_id(struct expo *exp, uint id);
54
55/**
56 * scene_obj_find() - Find an object in a scene
57 *
58 * Note that @type is used to restrict the search when the object type is known.
59 * If any type is acceptable, set @type to SCENEOBJT_NONE
60 *
61 * @scn: Scene to search
62 * @id: ID of object to find
63 * @type: Type of the object, or SCENEOBJT_NONE to match any type
Simon Glassc6e9f4c2023-06-01 10:22:26 -060064 * Returns: Object found, or NULL if not found
Simon Glass0a4d14b2023-01-06 08:52:37 -060065 */
Simon Glass45ff0bc2023-08-14 16:40:21 -060066void *scene_obj_find(const struct scene *scn, uint id, enum scene_obj_t type);
Simon Glass0a4d14b2023-01-06 08:52:37 -060067
68/**
Simon Glassc8925112023-06-01 10:23:02 -060069 * scene_obj_find_by_name() - Find an object in a scene by name
70 *
71 * @scn: Scene to search
72 * @name: Name to search for
73 */
74void *scene_obj_find_by_name(struct scene *scn, const char *name);
75
76/**
Simon Glass0a4d14b2023-01-06 08:52:37 -060077 * scene_obj_add() - Add a new object to a scene
78 *
79 * @scn: Scene to update
80 * @name: Name to use (this is allocated by this call)
81 * @id: ID to use for the new object (0 to allocate one)
82 * @type: Type of object to add
83 * @size: Size to allocate for the object, in bytes
84 * @objp: Returns a pointer to the new object (must not be NULL)
85 * Returns: ID number for the object (generally @id), or -ve on error
86 */
87int scene_obj_add(struct scene *scn, const char *name, uint id,
88 enum scene_obj_t type, uint size, struct scene_obj **objp);
89
90/**
Simon Glass6081b0f2023-06-01 10:22:50 -060091 * scene_obj_flag_clrset() - Adjust object flags
92 *
93 * @scn: Scene to update
94 * @id: ID of object to update
95 * @clr: Bits to clear in the object's flags
96 * @set: Bits to set in the object's flags
97 * Returns 0 if OK, -ENOENT if the object was not found
98 */
99int scene_obj_flag_clrset(struct scene *scn, uint id, uint clr, uint set);
100
101/**
Simon Glass7a960052023-06-01 10:22:52 -0600102 * scene_calc_dims() - Calculate the dimensions of the scene objects
103 *
104 * Updates the width and height of all objects based on their contents
105 *
106 * @scn: Scene to update
107 * @do_menus: true to calculate only menus, false to calculate everything else
108 * Returns 0 if OK, -ENOTSUPP if there is no graphical console
109 */
110int scene_calc_dims(struct scene *scn, bool do_menus);
111
112/**
Simon Glass0a4d14b2023-01-06 08:52:37 -0600113 * scene_menu_arrange() - Set the position of things in the menu
114 *
115 * This updates any items associated with a menu to make sure they are
116 * positioned correctly relative to the menu. It also selects the first item
117 * if not already done
118 *
119 * @scn: Scene to update
Simon Glass377f18e2024-10-14 16:31:55 -0600120 * @arr: Arrangement information
Simon Glass0a4d14b2023-01-06 08:52:37 -0600121 * @menu: Menu to process
Simon Glassc6e9f4c2023-06-01 10:22:26 -0600122 * Returns: 0 if OK, -ve on error
Simon Glass0a4d14b2023-01-06 08:52:37 -0600123 */
Simon Glass377f18e2024-10-14 16:31:55 -0600124int scene_menu_arrange(struct scene *scn, struct expo_arrange_info *arr,
125 struct scene_obj_menu *menu);
Simon Glass0a4d14b2023-01-06 08:52:37 -0600126
127/**
Simon Glass0023d182023-10-01 19:13:34 -0600128 * scene_textline_arrange() - Set the position of things in a textline
129 *
130 * This updates any items associated with a textline to make sure they are
131 * positioned correctly relative to the textline.
132 *
133 * @scn: Scene to update
Simon Glass377f18e2024-10-14 16:31:55 -0600134 * @arr: Arrangement information
Simon Glass0023d182023-10-01 19:13:34 -0600135 * @tline: textline to process
136 * Returns: 0 if OK, -ve on error
137 */
Simon Glass377f18e2024-10-14 16:31:55 -0600138int scene_textline_arrange(struct scene *scn, struct expo_arrange_info *arr,
139 struct scene_obj_textline *tline);
Simon Glass0023d182023-10-01 19:13:34 -0600140
141/**
Simon Glassc999e172023-06-01 10:22:53 -0600142 * scene_apply_theme() - Apply a theme to a scene
143 *
144 * @scn: Scene to update
145 * @theme: Theme to apply
146 * Returns: 0 if OK, -ve on error
147 */
148int scene_apply_theme(struct scene *scn, struct expo_theme *theme);
149
150/**
Simon Glass0a4d14b2023-01-06 08:52:37 -0600151 * scene_menu_send_key() - Send a key to a menu for processing
152 *
153 * @scn: Scene to use
154 * @menu: Menu to use
155 * @key: Key code to send (KEY_...)
156 * @event: Place to put any event which is generated by the key
Simon Glassc6e9f4c2023-06-01 10:22:26 -0600157 * Returns: 0 if OK, -ENOTTY if there is no current menu item, other -ve on other
Simon Glass0a4d14b2023-01-06 08:52:37 -0600158 * error
159 */
160int scene_menu_send_key(struct scene *scn, struct scene_obj_menu *menu, int key,
161 struct expo_action *event);
162
163/**
Simon Glass0023d182023-10-01 19:13:34 -0600164 * scene_textline_send_key() - Send a key to a textline for processing
165 *
166 * @scn: Scene to use
167 * @tline: textline to use
168 * @key: Key code to send (KEY_...)
169 * @event: Place to put any event which is generated by the key
170 * Returns: 0 if OK (always)
171 */
172int scene_textline_send_key(struct scene *scn, struct scene_obj_textline *tline,
173 int key, struct expo_action *event);
174
175/**
Simon Glass0a4d14b2023-01-06 08:52:37 -0600176 * scene_menu_destroy() - Destroy a menu in a scene
177 *
178 * @scn: Scene to destroy
179 */
180void scene_menu_destroy(struct scene_obj_menu *menu);
181
182/**
183 * scene_menu_display() - Display a menu as text
184 *
185 * @menu: Menu to display
Simon Glassc6e9f4c2023-06-01 10:22:26 -0600186 * Returns: 0 if OK, -ENOENT if @id is invalid
Simon Glass0a4d14b2023-01-06 08:52:37 -0600187 */
188int scene_menu_display(struct scene_obj_menu *menu);
189
190/**
191 * scene_destroy() - Destroy a scene and all its memory
192 *
193 * @scn: Scene to destroy
194 */
195void scene_destroy(struct scene *scn);
196
197/**
198 * scene_render() - Render a scene
199 *
200 * This is called from expo_render()
201 *
202 * @scn: Scene to render
203 * Returns: 0 if OK, -ve on error
204 */
205int scene_render(struct scene *scn);
206
207/**
208 * scene_send_key() - set a keypress to a scene
209 *
210 * @scn: Scene to receive the key
211 * @key: Key to send (KEYCODE_UP)
212 * @event: Returns resulting event from this keypress
213 * Returns: 0 if OK, -ve on error
214 */
215int scene_send_key(struct scene *scn, int key, struct expo_action *event);
216
Simon Glass7a960052023-06-01 10:22:52 -0600217/**
Simon Glass12f57732023-06-01 10:22:58 -0600218 * scene_render_deps() - Render an object and its dependencies
219 *
220 * @scn: Scene to render
221 * @id: Object ID to render (or 0 for none)
222 * Returns: 0 if OK, -ve on error
223 */
224int scene_render_deps(struct scene *scn, uint id);
225
226/**
227 * scene_menu_render_deps() - Render a menu and its dependencies
228 *
229 * Renders the menu and all of its attached objects
230 *
231 * @scn: Scene to render
Simon Glassdb6a0512023-10-01 19:13:23 -0600232 * @menu: Menu to render
Simon Glass12f57732023-06-01 10:22:58 -0600233 * Returns: 0 if OK, -ve on error
234 */
235int scene_menu_render_deps(struct scene *scn, struct scene_obj_menu *menu);
236
237/**
Simon Glass0023d182023-10-01 19:13:34 -0600238 * scene_textline_render_deps() - Render a textline and its dependencies
239 *
240 * Renders the textline and all of its attached objects
241 *
242 * @scn: Scene to render
243 * @tline: textline to render
244 * Returns: 0 if OK, -ve on error
245 */
246int scene_textline_render_deps(struct scene *scn,
247 struct scene_obj_textline *tline);
248
249/**
Simon Glass7a960052023-06-01 10:22:52 -0600250 * scene_menu_calc_dims() - Calculate the dimensions of a menu
251 *
252 * Updates the width and height of the menu based on its contents
253 *
254 * @menu: Menu to update
255 * Returns 0 if OK, -ENOTSUPP if there is no graphical console
256 */
257int scene_menu_calc_dims(struct scene_obj_menu *menu);
258
Simon Glasse90acd82023-08-14 16:40:23 -0600259/**
260 * scene_iter_objs() - Iterate through all scene objects
261 *
262 * @scn: Scene to process
263 * @iter: Iterator to call on each object
264 * @priv: Private data to pass to the iterator, in addition to the object
265 * Return: 0 if OK, -ve on error
266 */
267int scene_iter_objs(struct scene *scn, expo_scene_obj_iterator iter,
268 void *priv);
269
270/**
271 * expo_iter_scene_objects() - Iterate through all scene objects
272 *
273 * @exp: Expo to process
274 * @iter: Iterator to call on each object
275 * @priv: Private data to pass to the iterator, in addition to the object
276 * Return: 0 if OK, -ve on error
277 */
278int expo_iter_scene_objs(struct expo *exp, expo_scene_obj_iterator iter,
279 void *priv);
280
Simon Glass5fd4f782023-08-14 16:40:32 -0600281/**
282 * scene_menuitem_find() - Find the menu item for an ID
283 *
284 * Looks up the menu to find the item with the given ID
285 *
286 * @menu: Menu to check
287 * @id: ID to look for
288 * Return: Menu item, or NULL if not found
289 */
290struct scene_menitem *scene_menuitem_find(const struct scene_obj_menu *menu,
291 int id);
292
Simon Glass4462fa32023-08-14 16:40:38 -0600293/**
294 * scene_menuitem_find_seq() - Find the menu item at a sequential position
295 *
296 * This numbers the items from 0 and returns the seq'th one
297 *
298 * @menu: Menu to check
299 * @seq: Sequence number to look for
300 * Return: menu item if found, else NULL
301 */
302struct scene_menitem *scene_menuitem_find_seq(const struct scene_obj_menu *menu,
303 uint seq);
304
Simon Glassf0994692023-10-01 19:13:29 -0600305/**
Simon Glass100389f2024-10-14 16:31:58 -0600306 * scene_menuitem_find_val() - Find the menu item with a given value
307 *
308 * @menu: Menu to check
309 * @find_val: Value to look for
310 * Return: menu item if found, else NULL
311 */
312struct scene_menitem *scene_menuitem_find_val(const struct scene_obj_menu *menu,
313 int val);
314
315/**
Simon Glass96910ef2025-05-02 08:46:34 -0600316 * scene_bbox_join() - update bouding box with a given src box
317 *
318 * Updates @dst so that it encompasses the bounding box @src
319 *
320 * @src: Input bounding box
321 * @inset: Amount of inset to use for width
322 * @dst: Bounding box to update
323 * Return: 0 if OK, -ve on error
324 */
325int scene_bbox_join(const struct vidconsole_bbox *src, int inset,
326 struct vidconsole_bbox *dst);
327
328/**
Simon Glassf0994692023-10-01 19:13:29 -0600329 * scene_bbox_union() - update bouding box with the demensions of an object
330 *
331 * Updates @bbox so that it encompasses the bounding box of object @id
332 *
333 * @snd: Scene containing object
334 * @id: Object id
335 * @inset: Amount of inset to use for width
336 * @bbox: Bounding box to update
337 * Return: 0 if OK, -ve on error
338 */
339int scene_bbox_union(struct scene *scn, uint id, int inset,
340 struct vidconsole_bbox *bbox);
341
342/**
Simon Glass0023d182023-10-01 19:13:34 -0600343 * scene_textline_calc_dims() - Calculate the dimensions of a textline
344 *
345 * Updates the width and height of the textline based on its contents
346 *
347 * @tline: Textline to update
348 * Returns 0 if OK, -ENOTSUPP if there is no graphical console
349 */
350int scene_textline_calc_dims(struct scene_obj_textline *tline);
351
352/**
Simon Glassf0994692023-10-01 19:13:29 -0600353 * scene_menu_calc_bbox() - Calculate bounding boxes for the menu
354 *
355 * @menu: Menu to process
Simon Glass96910ef2025-05-02 08:46:34 -0600356 * @bbox: List of bounding box to fill in
Simon Glassf0994692023-10-01 19:13:29 -0600357 * Return: 0 if OK, -ve on error
358 */
359void scene_menu_calc_bbox(struct scene_obj_menu *menu,
Simon Glass96910ef2025-05-02 08:46:34 -0600360 struct vidconsole_bbox *bbox);
Simon Glassf0994692023-10-01 19:13:29 -0600361
362/**
Simon Glass0023d182023-10-01 19:13:34 -0600363 * scene_textline_calc_bbox() - Calculate bounding box for the textline
364 *
365 * @textline: Menu to process
366 * @bbox: Returns bounding box of textline including prompt
367 * @edit_bbox: Returns bounding box of editable part
368 * Return: 0 if OK, -ve on error
369 */
370void scene_textline_calc_bbox(struct scene_obj_textline *menu,
371 struct vidconsole_bbox *bbox,
372 struct vidconsole_bbox *label_bbox);
373
374/**
Simon Glassf0994692023-10-01 19:13:29 -0600375 * scene_obj_calc_bbox() - Calculate bounding boxes for an object
376 *
377 * @obj: Object to process
Simon Glass96910ef2025-05-02 08:46:34 -0600378 * @bbox: Returns bounding boxes for object
Simon Glassf0994692023-10-01 19:13:29 -0600379 * Return: 0 if OK, -ve on error
380 */
Simon Glass96910ef2025-05-02 08:46:34 -0600381int scene_obj_calc_bbox(struct scene_obj *obj, struct vidconsole_bbox *bbox);
Simon Glassf0994692023-10-01 19:13:29 -0600382
Simon Glassf6a943a2023-10-01 19:13:33 -0600383/**
384 * scene_textline_open() - Open a textline object
385 *
386 * Set up the text editor ready for use
387 *
388 * @scn: Scene containing the textline
389 * @tline: textline object
390 * Return: 0 if OK, -ve on error
391 */
392int scene_textline_open(struct scene *scn, struct scene_obj_textline *tline);
393
394/**
395 * scene_textline_close() - Close a textline object
396 *
397 * Close out the text editor after use
398 *
399 * @scn: Scene containing the textline
400 * @tline: textline object
401 * Return: 0 if OK, -ve on error
402 */
403int scene_textline_close(struct scene *scn, struct scene_obj_textline *tline);
404
Simon Glass377f18e2024-10-14 16:31:55 -0600405/**
406 * scene_calc_arrange() - Calculate sizes needed to arrange a scene
407 *
408 * Checks the size of some objects and stores this info to help with a later
409 * scene arrangement
410 *
411 * @scn: Scene to check
412 * @arr: Place to put scene-arrangement info
413 * Returns: 0 if OK, -ve on error
414 */
415int scene_calc_arrange(struct scene *scn, struct expo_arrange_info *arr);
416
Simon Glass0a4d14b2023-01-06 08:52:37 -0600417#endif /* __SCENE_INTERNAL_H */