view_port.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. ViewPortOrientationMAX, /**< Special value, don't use it */
  18. } ViewPortOrientation;
  19. /** ViewPort Draw callback
  20. * @warning called from GUI thread
  21. */
  22. typedef void (*ViewPortDrawCallback)(Canvas* canvas, void* context);
  23. /** ViewPort Input callback
  24. * @warning called from GUI thread
  25. */
  26. typedef void (*ViewPortInputCallback)(InputEvent* event, void* context);
  27. /** ViewPort allocator
  28. *
  29. * always returns view_port or stops system if not enough memory.
  30. *
  31. * @return ViewPort instance
  32. */
  33. ViewPort* view_port_alloc();
  34. /** ViewPort deallocator
  35. *
  36. * Ensure that view_port was unregistered in GUI system before use.
  37. *
  38. * @param view_port ViewPort instance
  39. */
  40. void view_port_free(ViewPort* view_port);
  41. /** Set view_port width.
  42. *
  43. * Will be used to limit canvas drawing area and autolayout feature.
  44. *
  45. * @param view_port ViewPort instance
  46. * @param width wanted width, 0 - auto.
  47. */
  48. void view_port_set_width(ViewPort* view_port, uint8_t width);
  49. uint8_t view_port_get_width(ViewPort* view_port);
  50. /** Set view_port height.
  51. *
  52. * Will be used to limit canvas drawing area and autolayout feature.
  53. *
  54. * @param view_port ViewPort instance
  55. * @param height wanted height, 0 - auto.
  56. */
  57. void view_port_set_height(ViewPort* view_port, uint8_t height);
  58. uint8_t view_port_get_height(ViewPort* view_port);
  59. /** Enable or disable view_port rendering.
  60. *
  61. * @param view_port ViewPort instance
  62. * @param enabled Indicates if enabled
  63. * @warning automatically dispatches update event
  64. */
  65. void view_port_enabled_set(ViewPort* view_port, bool enabled);
  66. bool view_port_is_enabled(ViewPort* view_port);
  67. /** ViewPort event callbacks
  68. *
  69. * @param view_port ViewPort instance
  70. * @param callback appropriate callback function
  71. * @param context context to pass to callback
  72. */
  73. void view_port_draw_callback_set(ViewPort* view_port, ViewPortDrawCallback callback, void* context);
  74. void view_port_input_callback_set(
  75. ViewPort* view_port,
  76. ViewPortInputCallback callback,
  77. void* context);
  78. /** Emit update signal to GUI system.
  79. *
  80. * Rendering will happen later after GUI system process signal.
  81. *
  82. * @param view_port ViewPort instance
  83. */
  84. void view_port_update(ViewPort* view_port);
  85. /** Set ViewPort orientation.
  86. *
  87. * @param view_port ViewPort instance
  88. * @param orientation display orientation, horizontal or vertical.
  89. */
  90. void view_port_set_orientation(ViewPort* view_port, ViewPortOrientation orientation);
  91. ViewPortOrientation view_port_get_orientation(const ViewPort* view_port);
  92. #ifdef __cplusplus
  93. }
  94. #endif