Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 | /* SPDX-License-Identifier: GPL-2.0+ */ /* * Internal header file for scenes * * Copyright 2022 Google LLC * Written by Simon Glass <sjg@chromium.org> */ #ifndef __SCENE_INTERNAL_H #define __SCENE_INTERNAL_H #include <linux/types.h> struct expo; struct expo_action; struct expo_arrange_info; struct expo_theme; struct scene_obj; struct scene_obj_dims; struct scene_obj_menu; struct scene_obj_textline; struct scene_obj_txtedit; struct scene_txt_generic; struct udevice; struct vidconsole_bbox; enum scene_obj_t; typedef int (*expo_scene_obj_iterator)(struct scene_obj *obj, void *priv); /** * enum scene_bbox_t - Parts of an object which can have a bounding box * * Objects can provide any or all of these bounding boxes * * @SCENEBB_label: Menu-item label * @SCENEBB_key: Menu-item key label * @SCENEBB_desc: Menu-item Description * @SCENEBB_curitem: Current item (pointed to) * @SCENEBB_all: All the above objects combined */ enum scene_bbox_t { SCENEBB_label, SCENEBB_key, SCENEBB_desc, SCENEBB_curitem, SCENEBB_all, SCENEBB_count, }; /** * expo_lookup_scene_id() - Look up a scene ID * * @exp: Expo to use * @id: scene ID to look up * Returns: Scene for that ID, or NULL if none */ struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id); /** * resolve_id() - Automatically allocate an ID if needed * * @exp: Expo to use * @id: ID to use, or 0 to auto-allocate one * Returns: Either @id, or the auto-allocated ID */ uint resolve_id(struct expo *exp, uint id); /** * scene_obj_find() - Find an object in a scene * * Note that @type is used to restrict the search when the object type is known. * If any type is acceptable, set @type to SCENEOBJT_NONE * * @scn: Scene to search * @id: ID of object to find * @type: Type of the object, or SCENEOBJT_NONE to match any type * Returns: Object found, or NULL if not found */ void *scene_obj_find(const struct scene *scn, uint id, enum scene_obj_t type); /** * scene_obj_find_by_name() - Find an object in a scene by name * * @scn: Scene to search * @name: Name to search for */ void *scene_obj_find_by_name(struct scene *scn, const char *name); /** * scene_obj_add() - Add a new object to a scene * * @scn: Scene to update * @name: Name to use (this is allocated by this call) * @id: ID to use for the new object (0 to allocate one) * @type: Type of object to add * @size: Size to allocate for the object, in bytes * @objp: Returns a pointer to the new object (must not be NULL) * Returns: ID number for the object (generally @id), or -ve on error */ int scene_obj_add(struct scene *scn, const char *name, uint id, enum scene_obj_t type, uint size, struct scene_obj **objp); /** * scene_obj_flag_clrset() - Adjust object flags * * @scn: Scene to update * @id: ID of object to update * @clr: Bits to clear in the object's flags * @set: Bits to set in the object's flags * Returns 0 if OK, -ENOENT if the object was not found */ int scene_obj_flag_clrset(struct scene *scn, uint id, uint clr, uint set); /** * scene_sync_bbox() - Apply any requested changes to object positions * * Updates each object's bbox to match the req_bbox using the SCENEOF_SYNC_... * flags * * @scn: Scene to update */ int scene_sync_bbox(struct scene *scn); /** * scene_calc_dims() - Calculate the dimensions of the scene objects * * Updates the width and height of all objects based on their contents * * @scn: Scene to update * Returns 0 if OK, -ENOTSUPP if there is no graphical console */ int scene_calc_dims(struct scene *scn); /** * scene_menu_arrange() - Set the position of things in the menu * * This updates any items associated with a menu to make sure they are * positioned correctly relative to the menu. It also selects the first item * if not already done * * @scn: Scene to update * @arr: Arrangement information * @menu: Menu to process * Returns: 0 if OK, -ve on error */ int scene_menu_arrange(struct scene *scn, struct expo_arrange_info *arr, struct scene_obj_menu *menu); /** * scene_textline_arrange() - Set the position of things in a textline * * This updates any items associated with a textline to make sure they are * positioned correctly relative to the textline. * * @scn: Scene to update * @arr: Arrangement information * @tline: textline to process * Returns: 0 if OK, -ve on error */ int scene_textline_arrange(struct scene *scn, struct expo_arrange_info *arr, struct scene_obj_textline *tline); /** * scene_apply_theme() - Apply a theme to a scene * * @scn: Scene to update * @theme: Theme to apply * Returns: 0 if OK, -ve on error */ int scene_apply_theme(struct scene *scn, struct expo_theme *theme); /** * scene_menu_send_key() - Send a key to a menu for processing * * @scn: Scene to use * @menu: Menu to use * @key: Key code to send (KEY_...) * @event: Place to put any event which is generated by the key * Returns: 0 if OK, -ENOTTY if there is no current menu item, other -ve on other * error */ int scene_menu_send_key(struct scene *scn, struct scene_obj_menu *menu, int key, struct expo_action *event); /** * scene_menu_send_click() - Send a click to a menu for processing * * @scn: Scene to use * @menu: Menu to use * @x: X coordinate of click * @y: Y coordinate of click * @event: Place to put any event which is generated by the click * Returns: 0 if OK, -ENOTTY if there is no menu item at that position */ int scene_menu_send_click(struct scene *scn, struct scene_obj_menu *menu, int x, int y, struct expo_action *event); /** * scene_textline_send_key() - Send a key to a textline for processing * * @scn: Scene to use * @tline: textline to use * @key: Key code to send (KEY_...) * @event: Place to put any event which is generated by the key * Returns: 0 if OK (always) */ int scene_textline_send_key(struct scene *scn, struct scene_obj_textline *tline, int key, struct expo_action *event); /** * scene_menu_destroy() - Destroy a menu in a scene * * @scn: Scene to destroy */ void scene_menu_destroy(struct scene_obj_menu *menu); /** * scene_menu_display() - Display a menu as text * * @menu: Menu to display * Returns: 0 if OK, -ENOENT if @id is invalid */ int scene_menu_display(struct scene_obj_menu *menu); /** * scene_destroy() - Destroy a scene and all its memory * * @scn: Scene to destroy */ void scene_destroy(struct scene *scn); /** * scene_render() - Render a scene * * This is called from expo_render() * * @scn: Scene to render * @dirty_only: If true, only render objects that intersect with dirty areas * Returns: 0 if OK, -ve on error */ int scene_render(struct scene *scn, bool dirty_only); /** * scene_send_key() - set a keypress to a scene * * This processes the key, taking any action that is needed, such as moving * between menu items or editing the text in a textline * * @scn: Scene to receive the key * @key: Key to send (KEYCODE_UP) * @event: Returns resulting event from this keypress * Returns: 0 if OK, -ve on error */ int scene_send_key(struct scene *scn, int key, struct expo_action *event); /** * scene_within() - check if a point is considered within an object ID * * @scn: Scene to check * @id: ID of object to check * @x: X coordinate of the point * @y: Y coordinate of the point * Return: true if the point is considered within the object, false if not */ bool scene_within(const struct scene *scn, uint id, int x, int y); /** * scene_obj_within() - check if a point is considered within an object * * @scn: Scene to check * @menu: Menu to check * @x: X coordinate of the point * @y: Y coordinate of the point * Return: true if the point is considered within the object, false if not */ bool scene_obj_within(const struct scene *scn, struct scene_obj *obj, int x, int y); /** * scene_menu_within() - check if a point is considered within a menu * * @scn: Scene to check * @menu: Menu to check * @x: X coordinate of the point * @y: Y coordinate of the point * Return: item the point is within, or NULL if none */ struct scene_menitem *scene_menu_within(const struct scene *scn, struct scene_obj_menu *menu, int x, int y); /** * scene_textline_within() - check if a point is considered within a textline * * @scn: Scene to check * @tline: Txtline to check * @x: X coordinate of the point * @y: Y coordinate of the point * Return: true if the point is considered within the object, false if not */ bool scene_textline_within(const struct scene *scn, struct scene_obj_textline *tline, int x, int y); /** * scene_send_click() - process a mouse click in a scene * * @scn: Scene to receive the click * @x: X coordinate of the click * @y: Y coordinate of the click * @event: Returns resulting event from this click * Returns: 0 if OK, -ve on error */ int scene_send_click(struct scene *scn, int x, int y, struct expo_action *event); /** * scene_render_deps() - Render an object and its dependencies * * @scn: Scene to render * @id: Object ID to render (or 0 for none) * Returns: 0 if OK, -ve on error */ int scene_render_deps(struct scene *scn, uint id); /** * scene_menu_render_deps() - Render a menu and its dependencies * * Renders the menu and all of its attached objects * * @scn: Scene to render * @menu: Menu to render * Returns: 0 if OK, -ve on error */ int scene_menu_render_deps(struct scene *scn, struct scene_obj_menu *menu); /** * scene_textline_render_deps() - Render a textline and its dependencies * * Renders the textline and all of its attached objects * * @scn: Scene to render * @tline: textline to render * Returns: 0 if OK, -ve on error */ int scene_textline_render_deps(struct scene *scn, struct scene_obj_textline *tline); /** * scene_iter_objs() - Iterate through all scene objects * * @scn: Scene to process * @iter: Iterator to call on each object * @priv: Private data to pass to the iterator, in addition to the object * Return: 0 if OK, -ve on error */ int scene_iter_objs(struct scene *scn, expo_scene_obj_iterator iter, void *priv); /** * expo_iter_scene_objects() - Iterate through all scene objects * * @exp: Expo to process * @iter: Iterator to call on each object * @priv: Private data to pass to the iterator, in addition to the object * Return: 0 if OK, -ve on error */ int expo_iter_scene_objs(struct expo *exp, expo_scene_obj_iterator iter, void *priv); /** * scene_menuitem_find() - Find the menu item for an ID * * Looks up the menu to find the item with the given ID * * @menu: Menu to check * @id: ID to look for * Return: Menu item, or NULL if not found */ struct scene_menitem *scene_menuitem_find(const struct scene_obj_menu *menu, int id); /** * scene_menuitem_find_seq() - Find the menu item at a sequential position * * This numbers the items from 0 and returns the seq'th one * * @menu: Menu to check * @seq: Sequence number to look for * Return: menu item if found, else NULL */ struct scene_menitem *scene_menuitem_find_seq(const struct scene_obj_menu *menu, uint seq); /** * scene_menuitem_find_val() - Find the menu item with a given value * * @menu: Menu to check * @find_val: Value to look for * Return: menu item if found, else NULL */ struct scene_menitem *scene_menuitem_find_val(const struct scene_obj_menu *menu, int val); /** * scene_bbox_join() - update bounding box with a given src bbox * * Updates @dst so that it encompasses the bounding box @src * * @src: Input bounding box * @inset: Amount of inset to use for width * @dst: Bounding box to update * Return: 0 if OK, -ve on error */ int scene_bbox_join(const struct vidconsole_bbox *src, int inset, struct vidconsole_bbox *dst); /** * scene_bbox_union() - update bounding box with the bbox of an object * * Updates @bbox so that it encompasses the bounding box of object @id * * @scn: Scene containing object * @id: Object id * @inset: Amount of inset to use for width * @bbox: Bounding box to update * Return: 0 if OK, -ve on error */ int scene_bbox_union(struct scene *scn, uint id, int inset, struct vidconsole_bbox *bbox); /** * scene_bbox_join() - update dimensions with a given src dimensions * * Updates @dst so that it encompasses the dimensions of @src * * @src: Input dimensions * @dst: Dimensions to update */ void scene_dims_join(struct scene_obj_dims *src, struct scene_obj_dims *dst); /** * scene_dims_union() - update dimensions with the dimensions of an object * * Updates @dims so that it encompasses the dimensions of object @id * * @scn: Scene containing object * @id: Object id * @dims: Dimensions to update * Return: 0 if OK, -ve on error */ int scene_dims_union(struct scene *scn, uint id, struct scene_obj_dims *dims); /** * scene_textline_calc_dims() - Calculate the dimensions of a textline * * Updates the width and height of the textline based on its contents * * @tline: Textline to update * @cons: UCLASS_VIDEO_CONSOLE device (cannot be NULL) * Returns 0 if OK, -ENOTSUPP if there is no graphical console */ int scene_textline_calc_dims(struct scene_obj_textline *tline, struct udevice *cons); /** * scene_menu_calc_bbox() - Calculate bounding boxes for the menu * * @menu: Menu to process * @bbox: List of bounding box to fill in * Return: 0 if OK, -ve on error */ void scene_menu_calc_bbox(struct scene_obj_menu *menu, struct vidconsole_bbox *bbox); /** * scene_textline_calc_bbox() - Calculate bounding box for the textline * * @textline: Menu to process * @bbox: Returns bounding box of textline including prompt * @edit_bbox: Returns bounding box of editable part * Return: 0 if OK, -ve on error */ void scene_textline_calc_bbox(struct scene_obj_textline *menu, struct vidconsole_bbox *bbox, struct vidconsole_bbox *label_bbox); /** * scene_obj_calc_bbox() - Calculate bounding boxes for an object * * @obj: Object to process * @bbox: Returns bounding boxes for object * Return: 0 if OK, -ve on error */ int scene_obj_calc_bbox(struct scene_obj *obj, struct vidconsole_bbox *bbox); /** * scene_textline_open() - Open a textline object * * Set up the text editor ready for use * * @scn: Scene containing the textline * @tline: textline object * Return: 0 if OK, -ve on error */ int scene_textline_open(struct scene *scn, struct scene_obj_textline *tline); /** * scene_textline_close() - Close a textline object * * Close out the text editor after use * * @scn: Scene containing the textline * @tline: textline object * Return: 0 if OK, -ve on error */ int scene_textline_close(struct scene *scn, struct scene_obj_textline *tline); /** * scene_calc_arrange() - Calculate sizes needed to arrange a scene * * Checks the size of some objects and stores this info to help with a later * scene arrangement * * @scn: Scene to check * @arr: Place to put scene-arrangement info * Returns: 0 if OK, -ve on error */ int scene_calc_arrange(struct scene *scn, struct expo_arrange_info *arr); /** * scene_txt_generic_init() - Set up the generic part of a text object * * @exp: Expo containing the object * @gen: Generic text info * @name: Object name * @str_id: String ID for the text * @str: Initial text string for the object, or NULL to just use str_id */ int scene_txt_generic_init(struct expo *exp, struct scene_txt_generic *gen, const char *name, uint str_id, const char *str); /** * scene_flag_name() - Get the name of a scene flag * * @flag: Single-bit flag mask (e.g. BIT(7)) * Return: Flag name, or "(none)" if flag is 0 or out of range */ const char *scene_flag_name(uint flag); /** * scene_obj_type_name() - Get the name of a scene object type * * @type: Object type * Return: Type name, or "unknown" if out of range */ const char *scene_obj_type_name(enum scene_obj_t type); /** * scene_find_obj_within() - Find an object that is within the coords * * @scn: Scene to check * @x: X coordinates of the click * @y: Y coordinate of the click * @reverse: true to search from top to bottom (reverse order), false for * bottom to top * @allow_any: true to allow searching non-highlight objects * Return: object that is being clicked on, NULL if none */ struct scene_obj *scene_find_obj_within(const struct scene *scn, int x, int y, bool reverse, bool allow_any); #endif /* __SCENE_INTERNAL_H */ |