1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Internal header file for scenes
5 * Copyright 2022 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
9 #ifndef __SCENE_INTERNAL_H
10 #define __SCENE_INTERNAL_H
12 struct vidconsole_bbox;
14 typedef int (*expo_scene_obj_iterator)(struct scene_obj *obj, void *priv);
17 * expo_lookup_scene_id() - Look up a scene ID
20 * @id: scene ID to look up
21 * Returns: Scene for that ID, or NULL if none
23 struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id);
26 * resolve_id() - Automatically allocate an ID if needed
29 * @id: ID to use, or 0 to auto-allocate one
30 * Returns: Either @id, or the auto-allocated ID
32 uint resolve_id(struct expo *exp, uint id);
35 * scene_obj_find() - Find an object in a scene
37 * Note that @type is used to restrict the search when the object type is known.
38 * If any type is acceptable, set @type to SCENEOBJT_NONE
40 * @scn: Scene to search
41 * @id: ID of object to find
42 * @type: Type of the object, or SCENEOBJT_NONE to match any type
43 * Returns: Object found, or NULL if not found
45 void *scene_obj_find(const struct scene *scn, uint id, enum scene_obj_t type);
48 * scene_obj_find_by_name() - Find an object in a scene by name
50 * @scn: Scene to search
51 * @name: Name to search for
53 void *scene_obj_find_by_name(struct scene *scn, const char *name);
56 * scene_obj_add() - Add a new object to a scene
58 * @scn: Scene to update
59 * @name: Name to use (this is allocated by this call)
60 * @id: ID to use for the new object (0 to allocate one)
61 * @type: Type of object to add
62 * @size: Size to allocate for the object, in bytes
63 * @objp: Returns a pointer to the new object (must not be NULL)
64 * Returns: ID number for the object (generally @id), or -ve on error
66 int scene_obj_add(struct scene *scn, const char *name, uint id,
67 enum scene_obj_t type, uint size, struct scene_obj **objp);
70 * scene_obj_flag_clrset() - Adjust object flags
72 * @scn: Scene to update
73 * @id: ID of object to update
74 * @clr: Bits to clear in the object's flags
75 * @set: Bits to set in the object's flags
76 * Returns 0 if OK, -ENOENT if the object was not found
78 int scene_obj_flag_clrset(struct scene *scn, uint id, uint clr, uint set);
81 * scene_calc_dims() - Calculate the dimensions of the scene objects
83 * Updates the width and height of all objects based on their contents
85 * @scn: Scene to update
86 * @do_menus: true to calculate only menus, false to calculate everything else
87 * Returns 0 if OK, -ENOTSUPP if there is no graphical console
89 int scene_calc_dims(struct scene *scn, bool do_menus);
92 * scene_menu_arrange() - Set the position of things in the menu
94 * This updates any items associated with a menu to make sure they are
95 * positioned correctly relative to the menu. It also selects the first item
98 * @scn: Scene to update
99 * @menu: Menu to process
100 * Returns: 0 if OK, -ve on error
102 int scene_menu_arrange(struct scene *scn, struct scene_obj_menu *menu);
105 * scene_textline_arrange() - Set the position of things in a textline
107 * This updates any items associated with a textline to make sure they are
108 * positioned correctly relative to the textline.
110 * @scn: Scene to update
111 * @tline: textline to process
112 * Returns: 0 if OK, -ve on error
114 int scene_textline_arrange(struct scene *scn, struct scene_obj_textline *tline);
117 * scene_apply_theme() - Apply a theme to a scene
119 * @scn: Scene to update
120 * @theme: Theme to apply
121 * Returns: 0 if OK, -ve on error
123 int scene_apply_theme(struct scene *scn, struct expo_theme *theme);
126 * scene_menu_send_key() - Send a key to a menu for processing
130 * @key: Key code to send (KEY_...)
131 * @event: Place to put any event which is generated by the key
132 * Returns: 0 if OK, -ENOTTY if there is no current menu item, other -ve on other
135 int scene_menu_send_key(struct scene *scn, struct scene_obj_menu *menu, int key,
136 struct expo_action *event);
139 * scene_textline_send_key() - Send a key to a textline for processing
142 * @tline: textline to use
143 * @key: Key code to send (KEY_...)
144 * @event: Place to put any event which is generated by the key
145 * Returns: 0 if OK (always)
147 int scene_textline_send_key(struct scene *scn, struct scene_obj_textline *tline,
148 int key, struct expo_action *event);
151 * scene_menu_destroy() - Destroy a menu in a scene
153 * @scn: Scene to destroy
155 void scene_menu_destroy(struct scene_obj_menu *menu);
158 * scene_menu_display() - Display a menu as text
160 * @menu: Menu to display
161 * Returns: 0 if OK, -ENOENT if @id is invalid
163 int scene_menu_display(struct scene_obj_menu *menu);
166 * scene_destroy() - Destroy a scene and all its memory
168 * @scn: Scene to destroy
170 void scene_destroy(struct scene *scn);
173 * scene_render() - Render a scene
175 * This is called from expo_render()
177 * @scn: Scene to render
178 * Returns: 0 if OK, -ve on error
180 int scene_render(struct scene *scn);
183 * scene_send_key() - set a keypress to a scene
185 * @scn: Scene to receive the key
186 * @key: Key to send (KEYCODE_UP)
187 * @event: Returns resulting event from this keypress
188 * Returns: 0 if OK, -ve on error
190 int scene_send_key(struct scene *scn, int key, struct expo_action *event);
193 * scene_render_deps() - Render an object and its dependencies
195 * @scn: Scene to render
196 * @id: Object ID to render (or 0 for none)
197 * Returns: 0 if OK, -ve on error
199 int scene_render_deps(struct scene *scn, uint id);
202 * scene_menu_render_deps() - Render a menu and its dependencies
204 * Renders the menu and all of its attached objects
206 * @scn: Scene to render
207 * @menu: Menu to render
208 * Returns: 0 if OK, -ve on error
210 int scene_menu_render_deps(struct scene *scn, struct scene_obj_menu *menu);
213 * scene_textline_render_deps() - Render a textline and its dependencies
215 * Renders the textline and all of its attached objects
217 * @scn: Scene to render
218 * @tline: textline to render
219 * Returns: 0 if OK, -ve on error
221 int scene_textline_render_deps(struct scene *scn,
222 struct scene_obj_textline *tline);
225 * scene_menu_calc_dims() - Calculate the dimensions of a menu
227 * Updates the width and height of the menu based on its contents
229 * @menu: Menu to update
230 * Returns 0 if OK, -ENOTSUPP if there is no graphical console
232 int scene_menu_calc_dims(struct scene_obj_menu *menu);
235 * scene_iter_objs() - Iterate through all scene objects
237 * @scn: Scene to process
238 * @iter: Iterator to call on each object
239 * @priv: Private data to pass to the iterator, in addition to the object
240 * Return: 0 if OK, -ve on error
242 int scene_iter_objs(struct scene *scn, expo_scene_obj_iterator iter,
246 * expo_iter_scene_objects() - Iterate through all scene objects
248 * @exp: Expo to process
249 * @iter: Iterator to call on each object
250 * @priv: Private data to pass to the iterator, in addition to the object
251 * Return: 0 if OK, -ve on error
253 int expo_iter_scene_objs(struct expo *exp, expo_scene_obj_iterator iter,
257 * scene_menuitem_find() - Find the menu item for an ID
259 * Looks up the menu to find the item with the given ID
261 * @menu: Menu to check
262 * @id: ID to look for
263 * Return: Menu item, or NULL if not found
265 struct scene_menitem *scene_menuitem_find(const struct scene_obj_menu *menu,
269 * scene_menuitem_find_seq() - Find the menu item at a sequential position
271 * This numbers the items from 0 and returns the seq'th one
273 * @menu: Menu to check
274 * @seq: Sequence number to look for
275 * Return: menu item if found, else NULL
277 struct scene_menitem *scene_menuitem_find_seq(const struct scene_obj_menu *menu,
281 * scene_bbox_union() - update bouding box with the demensions of an object
283 * Updates @bbox so that it encompasses the bounding box of object @id
285 * @snd: Scene containing object
287 * @inset: Amount of inset to use for width
288 * @bbox: Bounding box to update
289 * Return: 0 if OK, -ve on error
291 int scene_bbox_union(struct scene *scn, uint id, int inset,
292 struct vidconsole_bbox *bbox);
295 * scene_textline_calc_dims() - Calculate the dimensions of a textline
297 * Updates the width and height of the textline based on its contents
299 * @tline: Textline to update
300 * Returns 0 if OK, -ENOTSUPP if there is no graphical console
302 int scene_textline_calc_dims(struct scene_obj_textline *tline);
305 * scene_menu_calc_bbox() - Calculate bounding boxes for the menu
307 * @menu: Menu to process
308 * @bbox: Returns bounding box of menu including prompts
309 * @label_bbox: Returns bounding box of labels
310 * Return: 0 if OK, -ve on error
312 void scene_menu_calc_bbox(struct scene_obj_menu *menu,
313 struct vidconsole_bbox *bbox,
314 struct vidconsole_bbox *label_bbox);
317 * scene_textline_calc_bbox() - Calculate bounding box for the textline
319 * @textline: Menu to process
320 * @bbox: Returns bounding box of textline including prompt
321 * @edit_bbox: Returns bounding box of editable part
322 * Return: 0 if OK, -ve on error
324 void scene_textline_calc_bbox(struct scene_obj_textline *menu,
325 struct vidconsole_bbox *bbox,
326 struct vidconsole_bbox *label_bbox);
329 * scene_obj_calc_bbox() - Calculate bounding boxes for an object
331 * @obj: Object to process
332 * @bbox: Returns bounding box of object including prompts
333 * @label_bbox: Returns bounding box of labels (active area)
334 * Return: 0 if OK, -ve on error
336 int scene_obj_calc_bbox(struct scene_obj *obj, struct vidconsole_bbox *bbox,
337 struct vidconsole_bbox *label_bbox);
340 * scene_textline_open() - Open a textline object
342 * Set up the text editor ready for use
344 * @scn: Scene containing the textline
345 * @tline: textline object
346 * Return: 0 if OK, -ve on error
348 int scene_textline_open(struct scene *scn, struct scene_obj_textline *tline);
351 * scene_textline_close() - Close a textline object
353 * Close out the text editor after use
355 * @scn: Scene containing the textline
356 * @tline: textline object
357 * Return: 0 if OK, -ve on error
359 int scene_textline_close(struct scene *scn, struct scene_obj_textline *tline);
361 #endif /* __SCENE_INTERNAL_H */