xremote_common_view.h 5.6 KB

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