blob: 95927472875624fa0e8e6d4e04bfc23db7f2566f [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 Glass43f45ca2025-05-02 08:46:49 -060012#include <linux/types.h>
13
14struct expo;
15struct expo_action;
16struct expo_arrange_info;
17struct expo_theme;
18struct scene_obj;
19struct scene_obj_menu;
20struct scene_obj_textline;
21struct scene_obj_txtedit;
22struct scene_txt_generic;
Simon Glassf0994692023-10-01 19:13:29 -060023struct vidconsole_bbox;
24
Simon Glass43f45ca2025-05-02 08:46:49 -060025enum scene_obj_t;
26
Simon Glasse90acd82023-08-14 16:40:23 -060027typedef int (*expo_scene_obj_iterator)(struct scene_obj *obj, void *priv);
28
Simon Glass0a4d14b2023-01-06 08:52:37 -060029/**
Simon Glass96910ef2025-05-02 08:46:34 -060030 * enum scene_bbox_t - Parts of an object which can have a bounding box
31 *
32 * Objects can provide any or all of these bounding boxes
33 *
34 * @SCENEBB_label: Menu-item label
35 * @SCENEBB_key: Menu-item key label
36 * @SCENEBB_desc: Menu-item Description
37 * @SCENEBB_curitem: Current item (pointed to)
38 * @SCENEBB_all: All the above objects combined
39 */
40enum scene_bbox_t {
41 SCENEBB_label,
42 SCENEBB_key,
43 SCENEBB_desc,
44 SCENEBB_curitem,
45 SCENEBB_all,
46
47 SCENEBB_count,
48};
49
50/**
Simon Glass0a4d14b2023-01-06 08:52:37 -060051 * expo_lookup_scene_id() - Look up a scene ID
52 *
53 * @exp: Expo to use
54 * @id: scene ID to look up
55 * Returns: Scene for that ID, or NULL if none
56 */
57struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id);
58
59/**
60 * resolve_id() - Automatically allocate an ID if needed
61 *
62 * @exp: Expo to use
63 * @id: ID to use, or 0 to auto-allocate one
Simon Glassc6e9f4c2023-06-01 10:22:26 -060064 * Returns: Either @id, or the auto-allocated ID
Simon Glass0a4d14b2023-01-06 08:52:37 -060065 */
66uint resolve_id(struct expo *exp, uint id);
67
68/**
69 * scene_obj_find() - Find an object in a scene
70 *
71 * Note that @type is used to restrict the search when the object type is known.
72 * If any type is acceptable, set @type to SCENEOBJT_NONE
73 *
74 * @scn: Scene to search
75 * @id: ID of object to find
76 * @type: Type of the object, or SCENEOBJT_NONE to match any type
Simon Glassc6e9f4c2023-06-01 10:22:26 -060077 * Returns: Object found, or NULL if not found
Simon Glass0a4d14b2023-01-06 08:52:37 -060078 */
Simon Glass45ff0bc2023-08-14 16:40:21 -060079void *scene_obj_find(const struct scene *scn, uint id, enum scene_obj_t type);
Simon Glass0a4d14b2023-01-06 08:52:37 -060080
81/**
Simon Glassc8925112023-06-01 10:23:02 -060082 * scene_obj_find_by_name() - Find an object in a scene by name
83 *
84 * @scn: Scene to search
85 * @name: Name to search for
86 */
87void *scene_obj_find_by_name(struct scene *scn, const char *name);
88
89/**
Simon Glass0a4d14b2023-01-06 08:52:37 -060090 * scene_obj_add() - Add a new object to a scene
91 *
92 * @scn: Scene to update
93 * @name: Name to use (this is allocated by this call)
94 * @id: ID to use for the new object (0 to allocate one)
95 * @type: Type of object to add
96 * @size: Size to allocate for the object, in bytes
97 * @objp: Returns a pointer to the new object (must not be NULL)
98 * Returns: ID number for the object (generally @id), or -ve on error
99 */
100int scene_obj_add(struct scene *scn, const char *name, uint id,
101 enum scene_obj_t type, uint size, struct scene_obj **objp);
102
103/**
Simon Glass6081b0f2023-06-01 10:22:50 -0600104 * scene_obj_flag_clrset() - Adjust object flags
105 *
106 * @scn: Scene to update
107 * @id: ID of object to update
108 * @clr: Bits to clear in the object's flags
109 * @set: Bits to set in the object's flags
110 * Returns 0 if OK, -ENOENT if the object was not found
111 */
112int scene_obj_flag_clrset(struct scene *scn, uint id, uint clr, uint set);
113
114/**
Simon Glass7a960052023-06-01 10:22:52 -0600115 * scene_calc_dims() - Calculate the dimensions of the scene objects
116 *
117 * Updates the width and height of all objects based on their contents
118 *
119 * @scn: Scene to update
120 * @do_menus: true to calculate only menus, false to calculate everything else
121 * Returns 0 if OK, -ENOTSUPP if there is no graphical console
122 */
123int scene_calc_dims(struct scene *scn, bool do_menus);
124
125/**
Simon Glass0a4d14b2023-01-06 08:52:37 -0600126 * scene_menu_arrange() - Set the position of things in the menu
127 *
128 * This updates any items associated with a menu to make sure they are
129 * positioned correctly relative to the menu. It also selects the first item
130 * if not already done
131 *
132 * @scn: Scene to update
Simon Glass377f18e2024-10-14 16:31:55 -0600133 * @arr: Arrangement information
Simon Glass0a4d14b2023-01-06 08:52:37 -0600134 * @menu: Menu to process
Simon Glassc6e9f4c2023-06-01 10:22:26 -0600135 * Returns: 0 if OK, -ve on error
Simon Glass0a4d14b2023-01-06 08:52:37 -0600136 */
Simon Glass377f18e2024-10-14 16:31:55 -0600137int scene_menu_arrange(struct scene *scn, struct expo_arrange_info *arr,
138 struct scene_obj_menu *menu);
Simon Glass0a4d14b2023-01-06 08:52:37 -0600139
140/**
Simon Glass0023d182023-10-01 19:13:34 -0600141 * scene_textline_arrange() - Set the position of things in a textline
142 *
143 * This updates any items associated with a textline to make sure they are
144 * positioned correctly relative to the textline.
145 *
146 * @scn: Scene to update
Simon Glass377f18e2024-10-14 16:31:55 -0600147 * @arr: Arrangement information
Simon Glass0023d182023-10-01 19:13:34 -0600148 * @tline: textline to process
149 * Returns: 0 if OK, -ve on error
150 */
Simon Glass377f18e2024-10-14 16:31:55 -0600151int scene_textline_arrange(struct scene *scn, struct expo_arrange_info *arr,
152 struct scene_obj_textline *tline);
Simon Glass0023d182023-10-01 19:13:34 -0600153
154/**
Simon Glassc999e172023-06-01 10:22:53 -0600155 * scene_apply_theme() - Apply a theme to a scene
156 *
157 * @scn: Scene to update
158 * @theme: Theme to apply
159 * Returns: 0 if OK, -ve on error
160 */
161int scene_apply_theme(struct scene *scn, struct expo_theme *theme);
162
163/**
Simon Glass0a4d14b2023-01-06 08:52:37 -0600164 * scene_menu_send_key() - Send a key to a menu for processing
165 *
166 * @scn: Scene to use
167 * @menu: Menu to use
168 * @key: Key code to send (KEY_...)
169 * @event: Place to put any event which is generated by the key
Simon Glassc6e9f4c2023-06-01 10:22:26 -0600170 * Returns: 0 if OK, -ENOTTY if there is no current menu item, other -ve on other
Simon Glass0a4d14b2023-01-06 08:52:37 -0600171 * error
172 */
173int scene_menu_send_key(struct scene *scn, struct scene_obj_menu *menu, int key,
174 struct expo_action *event);
175
176/**
Simon Glass0023d182023-10-01 19:13:34 -0600177 * scene_textline_send_key() - Send a key to a textline for processing
178 *
179 * @scn: Scene to use
180 * @tline: textline to use
181 * @key: Key code to send (KEY_...)
182 * @event: Place to put any event which is generated by the key
183 * Returns: 0 if OK (always)
184 */
185int scene_textline_send_key(struct scene *scn, struct scene_obj_textline *tline,
186 int key, struct expo_action *event);
187
188/**
Simon Glass0a4d14b2023-01-06 08:52:37 -0600189 * scene_menu_destroy() - Destroy a menu in a scene
190 *
191 * @scn: Scene to destroy
192 */
193void scene_menu_destroy(struct scene_obj_menu *menu);
194
195/**
196 * scene_menu_display() - Display a menu as text
197 *
198 * @menu: Menu to display
Simon Glassc6e9f4c2023-06-01 10:22:26 -0600199 * Returns: 0 if OK, -ENOENT if @id is invalid
Simon Glass0a4d14b2023-01-06 08:52:37 -0600200 */
201int scene_menu_display(struct scene_obj_menu *menu);
202
203/**
204 * scene_destroy() - Destroy a scene and all its memory
205 *
206 * @scn: Scene to destroy
207 */
208void scene_destroy(struct scene *scn);
209
210/**
211 * scene_render() - Render a scene
212 *
213 * This is called from expo_render()
214 *
215 * @scn: Scene to render
216 * Returns: 0 if OK, -ve on error
217 */
218int scene_render(struct scene *scn);
219
220/**
221 * scene_send_key() - set a keypress to a scene
222 *
223 * @scn: Scene to receive the key
224 * @key: Key to send (KEYCODE_UP)
225 * @event: Returns resulting event from this keypress
226 * Returns: 0 if OK, -ve on error
227 */
228int scene_send_key(struct scene *scn, int key, struct expo_action *event);
229
Simon Glass7a960052023-06-01 10:22:52 -0600230/**
Simon Glass12f57732023-06-01 10:22:58 -0600231 * scene_render_deps() - Render an object and its dependencies
232 *
233 * @scn: Scene to render
234 * @id: Object ID to render (or 0 for none)
235 * Returns: 0 if OK, -ve on error
236 */
237int scene_render_deps(struct scene *scn, uint id);
238
239/**
240 * scene_menu_render_deps() - Render a menu and its dependencies
241 *
242 * Renders the menu and all of its attached objects
243 *
244 * @scn: Scene to render
Simon Glassdb6a0512023-10-01 19:13:23 -0600245 * @menu: Menu to render
Simon Glass12f57732023-06-01 10:22:58 -0600246 * Returns: 0 if OK, -ve on error
247 */
248int scene_menu_render_deps(struct scene *scn, struct scene_obj_menu *menu);
249
250/**
Simon Glass0023d182023-10-01 19:13:34 -0600251 * scene_textline_render_deps() - Render a textline and its dependencies
252 *
253 * Renders the textline and all of its attached objects
254 *
255 * @scn: Scene to render
256 * @tline: textline to render
257 * Returns: 0 if OK, -ve on error
258 */
259int scene_textline_render_deps(struct scene *scn,
260 struct scene_obj_textline *tline);
261
262/**
Simon Glass7a960052023-06-01 10:22:52 -0600263 * scene_menu_calc_dims() - Calculate the dimensions of a menu
264 *
265 * Updates the width and height of the menu based on its contents
266 *
267 * @menu: Menu to update
268 * Returns 0 if OK, -ENOTSUPP if there is no graphical console
269 */
270int scene_menu_calc_dims(struct scene_obj_menu *menu);
271
Simon Glasse90acd82023-08-14 16:40:23 -0600272/**
273 * scene_iter_objs() - Iterate through all scene objects
274 *
275 * @scn: Scene to process
276 * @iter: Iterator to call on each object
277 * @priv: Private data to pass to the iterator, in addition to the object
278 * Return: 0 if OK, -ve on error
279 */
280int scene_iter_objs(struct scene *scn, expo_scene_obj_iterator iter,
281 void *priv);
282
283/**
284 * expo_iter_scene_objects() - Iterate through all scene objects
285 *
286 * @exp: Expo to process
287 * @iter: Iterator to call on each object
288 * @priv: Private data to pass to the iterator, in addition to the object
289 * Return: 0 if OK, -ve on error
290 */
291int expo_iter_scene_objs(struct expo *exp, expo_scene_obj_iterator iter,
292 void *priv);
293
Simon Glass5fd4f782023-08-14 16:40:32 -0600294/**
295 * scene_menuitem_find() - Find the menu item for an ID
296 *
297 * Looks up the menu to find the item with the given ID
298 *
299 * @menu: Menu to check
300 * @id: ID to look for
301 * Return: Menu item, or NULL if not found
302 */
303struct scene_menitem *scene_menuitem_find(const struct scene_obj_menu *menu,
304 int id);
305
Simon Glass4462fa32023-08-14 16:40:38 -0600306/**
307 * scene_menuitem_find_seq() - Find the menu item at a sequential position
308 *
309 * This numbers the items from 0 and returns the seq'th one
310 *
311 * @menu: Menu to check
312 * @seq: Sequence number to look for
313 * Return: menu item if found, else NULL
314 */
315struct scene_menitem *scene_menuitem_find_seq(const struct scene_obj_menu *menu,
316 uint seq);
317
Simon Glassf0994692023-10-01 19:13:29 -0600318/**
Simon Glass100389f2024-10-14 16:31:58 -0600319 * scene_menuitem_find_val() - Find the menu item with a given value
320 *
321 * @menu: Menu to check
322 * @find_val: Value to look for
323 * Return: menu item if found, else NULL
324 */
325struct scene_menitem *scene_menuitem_find_val(const struct scene_obj_menu *menu,
326 int val);
327
328/**
Simon Glass96910ef2025-05-02 08:46:34 -0600329 * scene_bbox_join() - update bouding box with a given src box
330 *
331 * Updates @dst so that it encompasses the bounding box @src
332 *
333 * @src: Input bounding box
334 * @inset: Amount of inset to use for width
335 * @dst: Bounding box to update
336 * Return: 0 if OK, -ve on error
337 */
338int scene_bbox_join(const struct vidconsole_bbox *src, int inset,
339 struct vidconsole_bbox *dst);
340
341/**
Simon Glassf0994692023-10-01 19:13:29 -0600342 * scene_bbox_union() - update bouding box with the demensions of an object
343 *
344 * Updates @bbox so that it encompasses the bounding box of object @id
345 *
346 * @snd: Scene containing object
347 * @id: Object id
348 * @inset: Amount of inset to use for width
349 * @bbox: Bounding box to update
350 * Return: 0 if OK, -ve on error
351 */
352int scene_bbox_union(struct scene *scn, uint id, int inset,
353 struct vidconsole_bbox *bbox);
354
355/**
Simon Glass0023d182023-10-01 19:13:34 -0600356 * scene_textline_calc_dims() - Calculate the dimensions of a textline
357 *
358 * Updates the width and height of the textline based on its contents
359 *
360 * @tline: Textline to update
361 * Returns 0 if OK, -ENOTSUPP if there is no graphical console
362 */
363int scene_textline_calc_dims(struct scene_obj_textline *tline);
364
365/**
Simon Glassf0994692023-10-01 19:13:29 -0600366 * scene_menu_calc_bbox() - Calculate bounding boxes for the menu
367 *
368 * @menu: Menu to process
Simon Glass96910ef2025-05-02 08:46:34 -0600369 * @bbox: List of bounding box to fill in
Simon Glassf0994692023-10-01 19:13:29 -0600370 * Return: 0 if OK, -ve on error
371 */
372void scene_menu_calc_bbox(struct scene_obj_menu *menu,
Simon Glass96910ef2025-05-02 08:46:34 -0600373 struct vidconsole_bbox *bbox);
Simon Glassf0994692023-10-01 19:13:29 -0600374
375/**
Simon Glass0023d182023-10-01 19:13:34 -0600376 * scene_textline_calc_bbox() - Calculate bounding box for the textline
377 *
378 * @textline: Menu to process
379 * @bbox: Returns bounding box of textline including prompt
380 * @edit_bbox: Returns bounding box of editable part
381 * Return: 0 if OK, -ve on error
382 */
383void scene_textline_calc_bbox(struct scene_obj_textline *menu,
384 struct vidconsole_bbox *bbox,
385 struct vidconsole_bbox *label_bbox);
386
387/**
Simon Glassf0994692023-10-01 19:13:29 -0600388 * scene_obj_calc_bbox() - Calculate bounding boxes for an object
389 *
390 * @obj: Object to process
Simon Glass96910ef2025-05-02 08:46:34 -0600391 * @bbox: Returns bounding boxes for object
Simon Glassf0994692023-10-01 19:13:29 -0600392 * Return: 0 if OK, -ve on error
393 */
Simon Glass96910ef2025-05-02 08:46:34 -0600394int scene_obj_calc_bbox(struct scene_obj *obj, struct vidconsole_bbox *bbox);
Simon Glassf0994692023-10-01 19:13:29 -0600395
Simon Glassf6a943a2023-10-01 19:13:33 -0600396/**
397 * scene_textline_open() - Open a textline object
398 *
399 * Set up the text editor ready for use
400 *
401 * @scn: Scene containing the textline
402 * @tline: textline object
403 * Return: 0 if OK, -ve on error
404 */
405int scene_textline_open(struct scene *scn, struct scene_obj_textline *tline);
406
407/**
408 * scene_textline_close() - Close a textline object
409 *
410 * Close out the text editor after use
411 *
412 * @scn: Scene containing the textline
413 * @tline: textline object
414 * Return: 0 if OK, -ve on error
415 */
416int scene_textline_close(struct scene *scn, struct scene_obj_textline *tline);
417
Simon Glass377f18e2024-10-14 16:31:55 -0600418/**
419 * scene_calc_arrange() - Calculate sizes needed to arrange a scene
420 *
421 * Checks the size of some objects and stores this info to help with a later
422 * scene arrangement
423 *
424 * @scn: Scene to check
425 * @arr: Place to put scene-arrangement info
426 * Returns: 0 if OK, -ve on error
427 */
428int scene_calc_arrange(struct scene *scn, struct expo_arrange_info *arr);
429
Simon Glass5dc887d2025-05-02 08:46:46 -0600430/**
431 * scene_txt_generic_init() - Set up the generic part of a text object
432 *
433 * @exp: Expo containing the object
434 * @gen: Generic text info
435 * @name: Object name
436 * @str_id: String ID for the text
437 * @str: Initial text string for the object, or NULL to just use str_id
438 */
439int scene_txt_generic_init(struct expo *exp, struct scene_txt_generic *gen,
440 const char *name, uint str_id, const char *str);
441
Simon Glass0a4d14b2023-01-06 08:52:37 -0600442#endif /* __SCENE_INTERNAL_H */