view_port.h 2.3 KB

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