view_port.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * @file view_port.h
  3. * GUI: ViewPort API
  4. */
  5. #pragma once
  6. #include <input/input.h>
  7. #include "canvas.h"
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. typedef struct ViewPort ViewPort;
  12. typedef enum {
  13. ViewPortOrientationHorizontal,
  14. ViewPortOrientationHorizontalFlip,
  15. ViewPortOrientationVertical,
  16. ViewPortOrientationVerticalFlip,
  17. } ViewPortOrientation;
  18. /** ViewPort Draw callback
  19. * @warning called from GUI thread
  20. */
  21. typedef void (*ViewPortDrawCallback)(Canvas* canvas, void* context);
  22. /** ViewPort Input callback
  23. * @warning called from GUI thread
  24. */
  25. typedef void (*ViewPortInputCallback)(InputEvent* event, void* context);
  26. /** ViewPort allocator
  27. *
  28. * always returns view_port or stops system if not enough memory.
  29. *
  30. * @return ViewPort instance
  31. */
  32. ViewPort* view_port_alloc();
  33. /** ViewPort deallocator
  34. *
  35. * Ensure that view_port was unregistered in GUI system before use.
  36. *
  37. * @param view_port ViewPort instance
  38. */
  39. void view_port_free(ViewPort* view_port);
  40. /** Set view_port width.
  41. *
  42. * Will be used to limit canvas drawing area and autolayout feature.
  43. *
  44. * @param view_port ViewPort instance
  45. * @param width wanted width, 0 - auto.
  46. */
  47. void view_port_set_width(ViewPort* view_port, uint8_t width);
  48. uint8_t view_port_get_width(ViewPort* view_port);
  49. /** Set view_port height.
  50. *
  51. * Will be used to limit canvas drawing area and autolayout feature.
  52. *
  53. * @param view_port ViewPort instance
  54. * @param height wanted height, 0 - auto.
  55. */
  56. void view_port_set_height(ViewPort* view_port, uint8_t height);
  57. uint8_t view_port_get_height(ViewPort* view_port);
  58. /** Enable or disable view_port rendering.
  59. *
  60. * @param view_port ViewPort instance
  61. * @param enabled Indicates if enabled
  62. * @warning automatically dispatches update event
  63. */
  64. void view_port_enabled_set(ViewPort* view_port, bool enabled);
  65. bool view_port_is_enabled(ViewPort* view_port);
  66. /** ViewPort event callbacks
  67. *
  68. * @param view_port ViewPort instance
  69. * @param callback appropriate callback function
  70. * @param context context to pass to callback
  71. */
  72. void view_port_draw_callback_set(ViewPort* view_port, ViewPortDrawCallback callback, void* context);
  73. void view_port_input_callback_set(
  74. ViewPort* view_port,
  75. ViewPortInputCallback callback,
  76. void* context);
  77. /** Emit update signal to GUI system.
  78. *
  79. * Rendering will happen later after GUI system process signal.
  80. *
  81. * @param view_port ViewPort instance
  82. */
  83. void view_port_update(ViewPort* view_port);
  84. /** Set ViewPort orientation.
  85. *
  86. * @param view_port ViewPort instance
  87. * @param orientation display orientation, horizontal or vertical.
  88. */
  89. void view_port_set_orientation(ViewPort* view_port, ViewPortOrientation orientation);
  90. ViewPortOrientation view_port_get_orientation(const ViewPort* view_port);
  91. #ifdef __cplusplus
  92. }
  93. #endif