xremote_common_view.h 5.3 KB

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