xremote_common_view.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*!
  2. * @file flipper-xremote/views/xremote_common_view.h
  3. @license This project is released under the GNU GPLv3 License
  4. * @copyright (c) 2023 Sandro Kalatozishvili (s.kalatoz@gmail.com)
  5. *
  6. * @brief Common view and canvas functionality shared between the pages.
  7. */
  8. #pragma once
  9. #include <furi.h>
  10. #include <gui/view.h>
  11. #include <gui/elements.h>
  12. #include <notification/notification.h>
  13. #include <notification/notification_messages.h>
  14. #include <infrared_transmit.h>
  15. #include <xc_icons.h>
  16. #include "../infrared/infrared_remote.h"
  17. #define XREMOTE_BUTTON_COUNT 26
  18. #define XREMOTE_NAME_MAX 16
  19. #define XREMOTE_COMMAND_POWER "Power"
  20. #define XREMOTE_COMMAND_SETUP "Setup"
  21. #define XREMOTE_COMMAND_INPUT "Input"
  22. #define XREMOTE_COMMAND_MENU "Menu"
  23. #define XREMOTE_COMMAND_LIST "List"
  24. #define XREMOTE_COMMAND_INFO "Info"
  25. #define XREMOTE_COMMAND_BACK "Back"
  26. #define XREMOTE_COMMAND_OK "Ok"
  27. #define XREMOTE_COMMAND_UP "Up"
  28. #define XREMOTE_COMMAND_DOWN "Down"
  29. #define XREMOTE_COMMAND_LEFT "Left"
  30. #define XREMOTE_COMMAND_RIGHT "Right"
  31. #define XREMOTE_COMMAND_JUMP_FORWARD "Next"
  32. #define XREMOTE_COMMAND_JUMP_BACKWARD "Prev"
  33. #define XREMOTE_COMMAND_FAST_FORWARD "Fast_fo"
  34. #define XREMOTE_COMMAND_FAST_BACKWARD "Fast_ba"
  35. #define XREMOTE_COMMAND_PLAY_PAUSE "Play_pa"
  36. #define XREMOTE_COMMAND_PAUSE "Pause"
  37. #define XREMOTE_COMMAND_PLAY "Play"
  38. #define XREMOTE_COMMAND_STOP "Stop"
  39. #define XREMOTE_COMMAND_MUTE "Mute"
  40. #define XREMOTE_COMMAND_MODE "Mode"
  41. #define XREMOTE_COMMAND_VOL_UP "Vol_up"
  42. #define XREMOTE_COMMAND_VOL_DOWN "Vol_dn"
  43. #define XREMOTE_COMMAND_NEXT_CHAN "Ch_next"
  44. #define XREMOTE_COMMAND_PREV_CHAN "Ch_prev"
  45. typedef enum {
  46. XRemoteEventReserved = 200,
  47. XRemoteEventSignalReceived,
  48. XRemoteEventSignalFinish,
  49. XRemoteEventSignalSave,
  50. XRemoteEventSignalRetry,
  51. XRemoteEventSignalSend,
  52. XRemoteEventSignalSkip,
  53. XRemoteEventSignalAskExit,
  54. XRemoteEventSignalExit
  55. } XRemoteEvent;
  56. typedef enum {
  57. /* Navigation */
  58. XRemoteIconOk,
  59. XRemoteIconEnter,
  60. XRemoteIconBack,
  61. XRemoteIconArrowUp,
  62. XRemoteIconArrowDown,
  63. XRemoteIconArrowLeft,
  64. XRemoteIconArrowRight,
  65. /* Playback */
  66. XRemoteIconPlay,
  67. XRemoteIconPause,
  68. XRemoteIconStop,
  69. XRemoteIconPlayPause,
  70. XRemoteIconFastForward,
  71. XRemoteIconFastBackward,
  72. XRemoteIconJumpForward,
  73. XRemoteIconJumpBackward
  74. } XRemoteIcon;
  75. typedef struct {
  76. void* context;
  77. bool ok_pressed;
  78. bool back_pressed;
  79. bool up_pressed;
  80. bool down_pressed;
  81. bool left_pressed;
  82. bool right_pressed;
  83. bool hold;
  84. } XRemoteViewModel;
  85. typedef enum {
  86. XRemoteViewNone,
  87. XRemoteViewSignal,
  88. XRemoteViewTextInput,
  89. XRemoteViewDialogExit,
  90. /* Main page */
  91. XRemoteViewSubmenu,
  92. XRemoteViewLearn,
  93. XRemoteViewSaved,
  94. XRemoteViewAnalyzer,
  95. XRemoteViewSettings,
  96. XRemoteViewAbout,
  97. /* Remote app */
  98. XRemoteViewIRSubmenu,
  99. XRemoteViewIRGeneral,
  100. XRemoteViewIRControl,
  101. XRemoteViewIRPlayback,
  102. XRemoteViewIRNavigation,
  103. XRemoteViewIRCustomPage,
  104. XRemoteViewIRCustomEditPage,
  105. XRemoteViewIRAllButtons
  106. } XRemoteViewID;
  107. typedef struct XRemoteView XRemoteView;
  108. typedef void (*XRemoteClearCallback)(void* context);
  109. typedef void (*XRemoteViewDrawFunction)(Canvas*, XRemoteViewModel*);
  110. typedef XRemoteView* (*XRemoteViewAllocator)(void* app_ctx);
  111. typedef XRemoteView* (*XRemoteViewAllocator2)(void* app_ctx, void* model_ctx);
  112. const char* xremote_button_get_name(int index);
  113. int xremote_button_get_index(const char* name);
  114. void xremote_canvas_draw_header(Canvas* canvas, ViewOrientation orient, const char* section);
  115. void xremote_canvas_draw_exit_footer(Canvas* canvas, ViewOrientation orient, const char* text);
  116. void xremote_canvas_draw_icon(Canvas* canvas, uint8_t x, uint8_t y, XRemoteIcon icon);
  117. void xremote_canvas_draw_button(
  118. Canvas* canvas,
  119. bool pressed,
  120. uint8_t x,
  121. uint8_t y,
  122. XRemoteIcon icon);
  123. void xremote_canvas_draw_button_png(
  124. Canvas* canvas,
  125. bool pressed,
  126. uint8_t x,
  127. uint8_t y,
  128. const Icon* icon);
  129. void xremote_canvas_draw_button_wide(
  130. Canvas* canvas,
  131. bool pressed,
  132. uint8_t x,
  133. uint8_t y,
  134. const char* text,
  135. XRemoteIcon icon);
  136. void xremote_canvas_draw_button_size(
  137. Canvas* canvas,
  138. bool pressed,
  139. uint8_t x,
  140. uint8_t y,
  141. uint8_t xy,
  142. char* text,
  143. XRemoteIcon icon);
  144. void xremote_canvas_draw_frame(
  145. Canvas* canvas,
  146. bool pressed,
  147. uint8_t x,
  148. uint8_t y,
  149. uint8_t xl,
  150. const char* text);
  151. XRemoteView*
  152. xremote_view_alloc(void* app_ctx, ViewInputCallback input_cb, ViewDrawCallback draw_cb);
  153. XRemoteView* xremote_view_alloc_empty();
  154. void xremote_view_free(XRemoteView* rview);
  155. InfraredRemoteButton* xremote_view_get_button_by_name(XRemoteView* rview, const char* name);
  156. bool xremote_view_press_button(XRemoteView* rview, InfraredRemoteButton* button);
  157. bool xremote_view_send_ir_msg_by_name(XRemoteView* rview, const char* name);
  158. void xremote_view_model_context_set(XRemoteView* rview, void* model_ctx);
  159. void xremote_view_clear_context(XRemoteView* rview);
  160. void xremote_view_set_app_context(XRemoteView* rview, void* app_ctx);
  161. void xremote_view_set_context(XRemoteView* rview, void* context, XRemoteClearCallback on_clear);
  162. void xremote_view_set_view(XRemoteView* rview, View* view);
  163. void* xremote_view_get_app_context(XRemoteView* rview);
  164. void* xremote_view_get_context(XRemoteView* rview);
  165. View* xremote_view_get_view(XRemoteView* rview);