My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

files_screen.cpp 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /********************
  2. * files_screen.cpp *
  3. ********************/
  4. /****************************************************************************
  5. * Written By Mark Pelletier 2017 - Aleph Objects, Inc. *
  6. * Written By Marcio Teixeira 2018 - Aleph Objects, Inc. *
  7. * *
  8. * This program is free software: you can redistribute it and/or modify *
  9. * it under the terms of the GNU General Public License as published by *
  10. * the Free Software Foundation, either version 3 of the License, or *
  11. * (at your option) any later version. *
  12. * *
  13. * This program is distributed in the hope that it will be useful, *
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  16. * GNU General Public License for more details. *
  17. * *
  18. * To view a copy of the GNU General Public License, go to the following *
  19. * location: <http://www.gnu.org/licenses/>. *
  20. ****************************************************************************/
  21. #include "../config.h"
  22. #if ENABLED(TOUCH_UI_FTDI_EVE)
  23. #include "screens.h"
  24. #include "screen_data.h"
  25. using namespace FTDI;
  26. using namespace ExtUI;
  27. using namespace Theme;
  28. void FilesScreen::onEntry() {
  29. screen_data.FilesScreen.cur_page = 0;
  30. screen_data.FilesScreen.selected_tag = 0xFF;
  31. #if ENABLED(SCROLL_LONG_FILENAMES) && (FTDI_API_LEVEL >= 810)
  32. CLCD::mem_write_32(CLCD::REG::MACRO_0,DL::NOP);
  33. #endif
  34. gotoPage(0);
  35. BaseScreen::onEntry();
  36. }
  37. const char *FilesScreen::getSelectedFilename(bool longName) {
  38. FileList files;
  39. files.seek(getSelectedFileIndex(), true);
  40. return longName ? files.longFilename() : files.shortFilename();
  41. }
  42. void FilesScreen::drawSelectedFile() {
  43. FileList files;
  44. files.seek(getSelectedFileIndex(), true);
  45. screen_data.FilesScreen.flags.is_dir = files.isDir();
  46. drawFileButton(
  47. files.filename(),
  48. screen_data.FilesScreen.selected_tag,
  49. screen_data.FilesScreen.flags.is_dir,
  50. true
  51. );
  52. }
  53. uint16_t FilesScreen::getSelectedFileIndex() {
  54. return getFileForTag(screen_data.FilesScreen.selected_tag);
  55. }
  56. uint16_t FilesScreen::getFileForTag(uint8_t tag) {
  57. return screen_data.FilesScreen.cur_page * files_per_page + tag - 2;
  58. }
  59. #ifdef TOUCH_UI_PORTRAIT
  60. #define GRID_COLS 6
  61. #define GRID_ROWS (files_per_page + header_h + footer_h)
  62. #else
  63. #define GRID_COLS 6
  64. #define GRID_ROWS (files_per_page + header_h + footer_h)
  65. #endif
  66. void FilesScreen::drawFileButton(const char* filename, uint8_t tag, bool is_dir, bool is_highlighted) {
  67. const uint8_t line = getLineForTag(tag)+1;
  68. CommandProcessor cmd;
  69. cmd.tag(tag);
  70. cmd.cmd(COLOR_RGB(is_highlighted ? fg_action : bg_color));
  71. cmd.font(font_medium)
  72. .rectangle( 0, BTN_Y(header_h+line), display_width, BTN_H(1));
  73. cmd.cmd(COLOR_RGB(is_highlighted ? normal_btn.rgb : bg_text_enabled));
  74. #if ENABLED(SCROLL_LONG_FILENAMES)
  75. if (is_highlighted) {
  76. cmd.cmd(SAVE_CONTEXT());
  77. cmd.cmd(MACRO(0));
  78. }
  79. #endif
  80. cmd.text (BTN_POS(1,header_h+line), BTN_SIZE(6,1), filename, OPT_CENTERY
  81. #if ENABLED(SCROLL_LONG_FILENAMES)
  82. | OPT_NOFIT
  83. #endif
  84. );
  85. if (is_dir) {
  86. cmd.text(BTN_POS(1,header_h+line), BTN_SIZE(6,1), F("> "), OPT_CENTERY | OPT_RIGHTX);
  87. }
  88. #if ENABLED(SCROLL_LONG_FILENAMES)
  89. if (is_highlighted) {
  90. cmd.cmd(RESTORE_CONTEXT());
  91. }
  92. #endif
  93. }
  94. void FilesScreen::drawFileList() {
  95. FileList files;
  96. screen_data.FilesScreen.num_page = max(1,(ceil)(float(files.count()) / files_per_page));
  97. screen_data.FilesScreen.cur_page = min(screen_data.FilesScreen.cur_page, screen_data.FilesScreen.num_page-1);
  98. screen_data.FilesScreen.flags.is_root = files.isAtRootDir();
  99. #undef MARGIN_T
  100. #undef MARGIN_B
  101. #define MARGIN_T 0
  102. #define MARGIN_B 0
  103. uint16_t fileIndex = screen_data.FilesScreen.cur_page * files_per_page;
  104. for(uint8_t i = 0; i < files_per_page; i++, fileIndex++) {
  105. if (files.seek(fileIndex)) {
  106. drawFileButton(files.filename(), getTagForLine(i), files.isDir(), false);
  107. } else {
  108. break;
  109. }
  110. }
  111. }
  112. void FilesScreen::drawHeader() {
  113. const bool prev_enabled = screen_data.FilesScreen.cur_page > 0;
  114. const bool next_enabled = screen_data.FilesScreen.cur_page < (screen_data.FilesScreen.num_page - 1);
  115. #undef MARGIN_T
  116. #undef MARGIN_B
  117. #define MARGIN_T 0
  118. #define MARGIN_B 2
  119. char str[16];
  120. sprintf_P(str, PSTR("Page %d of %d"),
  121. screen_data.FilesScreen.cur_page + 1, screen_data.FilesScreen.num_page);
  122. CommandProcessor cmd;
  123. cmd.colors(normal_btn)
  124. .font(font_small)
  125. .tag(0).button( BTN_POS(2,1), BTN_SIZE(4,header_h), str, OPT_CENTER | OPT_FLAT)
  126. .font(font_medium)
  127. .colors(action_btn)
  128. .tag(241).enabled(prev_enabled).button( BTN_POS(1,1), BTN_SIZE(1,header_h), F("<"))
  129. .tag(242).enabled(next_enabled).button( BTN_POS(6,1), BTN_SIZE(1,header_h), F(">"));
  130. }
  131. void FilesScreen::drawFooter() {
  132. #undef MARGIN_T
  133. #undef MARGIN_B
  134. #ifdef TOUCH_UI_PORTRAIT
  135. #define MARGIN_T 15
  136. #define MARGIN_B 5
  137. #else
  138. #define MARGIN_T 5
  139. #define MARGIN_B 5
  140. #endif
  141. const bool has_selection = screen_data.FilesScreen.selected_tag != 0xFF;
  142. const uint8_t back_tag = screen_data.FilesScreen.flags.is_root ? 240 : 245;
  143. const uint8_t y = GRID_ROWS - footer_h + 1;
  144. const uint8_t h = footer_h;
  145. CommandProcessor cmd;
  146. cmd.colors(normal_btn)
  147. .font(font_medium)
  148. .colors(has_selection ? normal_btn : action_btn)
  149. .tag(back_tag).button( BTN_POS(4,y), BTN_SIZE(3,h), GET_TEXT_F(MSG_BACK))
  150. .enabled(has_selection)
  151. .colors(has_selection ? action_btn : normal_btn);
  152. if (screen_data.FilesScreen.flags.is_dir) {
  153. cmd.tag(244).button( BTN_POS(1, y), BTN_SIZE(3,h), GET_TEXT_F(MSG_BUTTON_OPEN));
  154. } else {
  155. cmd.tag(243).button( BTN_POS(1, y), BTN_SIZE(3,h), GET_TEXT_F(MSG_BUTTON_PRINT));
  156. }
  157. }
  158. void FilesScreen::onRedraw(draw_mode_t what) {
  159. if (what & FOREGROUND) {
  160. drawHeader();
  161. drawSelectedFile();
  162. drawFooter();
  163. }
  164. }
  165. void FilesScreen::gotoPage(uint8_t page) {
  166. screen_data.FilesScreen.selected_tag = 0xFF;
  167. screen_data.FilesScreen.cur_page = page;
  168. CommandProcessor cmd;
  169. cmd.cmd(CMD_DLSTART)
  170. .cmd(CLEAR_COLOR_RGB(bg_color))
  171. .cmd(CLEAR(true,true,true))
  172. .colors(normal_btn);
  173. drawFileList();
  174. storeBackground();
  175. }
  176. bool FilesScreen::onTouchEnd(uint8_t tag) {
  177. switch (tag) {
  178. case 240: GOTO_PREVIOUS(); return true;
  179. case 241:
  180. if (screen_data.FilesScreen.cur_page > 0) {
  181. gotoPage(screen_data.FilesScreen.cur_page-1);
  182. }
  183. break;
  184. case 242:
  185. if (screen_data.FilesScreen.cur_page < (screen_data.FilesScreen.num_page-1)) {
  186. gotoPage(screen_data.FilesScreen.cur_page+1);
  187. }
  188. break;
  189. case 243:
  190. ConfirmStartPrintDialogBox::show(getSelectedFileIndex());
  191. return true;
  192. case 244:
  193. {
  194. FileList files;
  195. files.changeDir(getSelectedShortFilename());
  196. gotoPage(0);
  197. }
  198. break;
  199. case 245:
  200. {
  201. FileList files;
  202. files.upDir();
  203. gotoPage(0);
  204. }
  205. break;
  206. default:
  207. if (tag < 240) {
  208. screen_data.FilesScreen.selected_tag = tag;
  209. #if ENABLED(SCROLL_LONG_FILENAMES) && (FTDI_API_LEVEL >= 810)
  210. if (FTDI::ftdi_chip >= 810) {
  211. const char *longFilename = getSelectedLongFilename();
  212. if (longFilename[0]) {
  213. CommandProcessor cmd;
  214. uint16_t text_width = cmd.font(font_medium).text_width(longFilename);
  215. screen_data.FilesScreen.scroll_pos = 0;
  216. if (text_width > display_width)
  217. screen_data.FilesScreen.scroll_max = text_width - display_width + MARGIN_L + MARGIN_R;
  218. else
  219. screen_data.FilesScreen.scroll_max = 0;
  220. }
  221. }
  222. #endif
  223. }
  224. break;
  225. }
  226. return true;
  227. }
  228. void FilesScreen::onIdle() {
  229. #if ENABLED(SCROLL_LONG_FILENAMES) && (FTDI_API_LEVEL >= 810)
  230. if (FTDI::ftdi_chip >= 810) {
  231. CLCD::mem_write_32(CLCD::REG::MACRO_0,
  232. VERTEX_TRANSLATE_X(-int32_t(screen_data.FilesScreen.scroll_pos)));
  233. if (screen_data.FilesScreen.scroll_pos < screen_data.FilesScreen.scroll_max * 16)
  234. screen_data.FilesScreen.scroll_pos++;
  235. }
  236. #endif
  237. }
  238. #endif // TOUCH_UI_FTDI_EVE