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.

base_numeric_adjustment_screen.cpp 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /**************************************
  2. * base_numeric_adjustment_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 Theme;
  27. #ifdef TOUCH_UI_PORTRAIT
  28. #define GRID_COLS 13
  29. #define GRID_ROWS 10
  30. #define LAYOUT_FONT font_small
  31. #else
  32. #define GRID_COLS 18
  33. #define GRID_ROWS 7
  34. #define LAYOUT_FONT font_medium
  35. #endif
  36. BaseNumericAdjustmentScreen::widgets_t::widgets_t(draw_mode_t what) : _what(what) {
  37. CommandProcessor cmd;
  38. if (what & BACKGROUND) {
  39. cmd.cmd(CLEAR_COLOR_RGB(bg_color))
  40. .cmd(CLEAR(true,true,true))
  41. .colors(normal_btn)
  42. .cmd(COLOR_RGB(bg_text_enabled))
  43. .tag(0);
  44. }
  45. cmd.font(font_medium);
  46. _button(cmd, 1,
  47. #ifdef TOUCH_UI_PORTRAIT
  48. BTN_POS(1,10), BTN_SIZE(13,1),
  49. #else
  50. BTN_POS(15,7), BTN_SIZE(4,1),
  51. #endif
  52. GET_TEXT_F(MSG_BACK), true, true
  53. );
  54. _line = 1;
  55. _units = F("");
  56. }
  57. /**
  58. * Speed optimization for changing button style.
  59. */
  60. void BaseNumericAdjustmentScreen::widgets_t::_button_style(CommandProcessor &cmd, BaseNumericAdjustmentScreen::widgets_t::style_t style) {
  61. if (_style != style) {
  62. const btn_colors *old_colors = &normal_btn;
  63. const btn_colors *new_colors = &normal_btn;
  64. switch(_style) {
  65. case BTN_ACTION: old_colors = &action_btn; break;
  66. case BTN_TOGGLE: old_colors = &ui_toggle; break;
  67. case BTN_DISABLED: old_colors = &disabled_btn; break;
  68. default: break;
  69. }
  70. switch(style) {
  71. case BTN_ACTION: new_colors = &action_btn; break;
  72. case BTN_TOGGLE: new_colors = &ui_toggle; break;
  73. case BTN_DISABLED: new_colors = &disabled_btn; break;
  74. default: break;
  75. }
  76. const bool rgb_changed = (old_colors->rgb != new_colors->rgb) ||
  77. (_style == TEXT_LABEL && style != TEXT_LABEL) ||
  78. (_style != TEXT_LABEL && style == TEXT_LABEL);
  79. const bool grad_changed = old_colors->grad != new_colors->grad;
  80. const bool fg_changed = (old_colors->fg != new_colors->fg) || (_style == TEXT_AREA);
  81. const bool bg_changed = old_colors->bg != new_colors->bg;
  82. if (rgb_changed) cmd.cmd(COLOR_RGB(style == TEXT_LABEL ? bg_text_enabled : new_colors->rgb));
  83. if (grad_changed) cmd.gradcolor(new_colors->grad);
  84. if (fg_changed) cmd.fgcolor(new_colors->fg);
  85. if (bg_changed) cmd.bgcolor(new_colors->bg);
  86. _style = style;
  87. }
  88. }
  89. /**
  90. * Speed optimization for drawing buttons. Draw all unpressed buttons in the
  91. * background layer and draw only the pressed button in the foreground layer.
  92. */
  93. void BaseNumericAdjustmentScreen::widgets_t::_button(CommandProcessor &cmd, uint8_t tag, int16_t x, int16_t y, int16_t w, int16_t h, progmem_str text, bool enabled, bool highlight) {
  94. if (_what & BACKGROUND) enabled = true;
  95. if ((_what & BACKGROUND) || buttonIsPressed(tag) || highlight || !enabled) {
  96. _button_style(cmd, (!enabled) ? BTN_DISABLED : (highlight ? BTN_ACTION : BTN_NORMAL));
  97. cmd.tag(enabled ? tag : 0).button(x, y, w, h, text);
  98. }
  99. }
  100. BaseNumericAdjustmentScreen::widgets_t &BaseNumericAdjustmentScreen::widgets_t::precision(uint8_t decimals, precision_default_t initial) {
  101. _decimals = decimals;
  102. if (screen_data.BaseNumericAdjustmentScreen.increment == 0) {
  103. screen_data.BaseNumericAdjustmentScreen.increment = 243 + (initial - DEFAULT_LOWEST) - _decimals;
  104. }
  105. return *this;
  106. }
  107. void BaseNumericAdjustmentScreen::widgets_t::heading(progmem_str label) {
  108. if (_what & BACKGROUND) {
  109. CommandProcessor cmd;
  110. _button_style(cmd, TEXT_LABEL);
  111. cmd.font(font_medium)
  112. .tag(0)
  113. .text(
  114. #ifdef TOUCH_UI_PORTRAIT
  115. BTN_POS(1, _line), BTN_SIZE(12,1),
  116. #else
  117. BTN_POS(5, _line), BTN_SIZE(8,1),
  118. #endif
  119. label
  120. );
  121. }
  122. _line++;
  123. }
  124. #ifdef TOUCH_UI_PORTRAIT
  125. #ifdef TOUCH_UI_800x480
  126. #undef EDGE_R
  127. #define EDGE_R 20
  128. #else
  129. #undef EDGE_R
  130. #define EDGE_R 10
  131. #endif
  132. #endif
  133. void BaseNumericAdjustmentScreen::widgets_t::_draw_increment_btn(CommandProcessor &cmd, uint8_t, const uint8_t tag) {
  134. const char *label = PSTR("?");
  135. uint8_t pos;
  136. uint8_t & increment = screen_data.BaseNumericAdjustmentScreen.increment;
  137. if (increment == 0) {
  138. increment = tag; // Set the default value to be the first.
  139. }
  140. switch (tag) {
  141. case 240: label = PSTR( ".001"); pos = _decimals - 3; break;
  142. case 241: label = PSTR( ".01" ); pos = _decimals - 2; break;
  143. case 242: label = PSTR( "0.1" ); pos = _decimals - 1; break;
  144. case 243: label = PSTR( "1" ); pos = _decimals + 0; break;
  145. case 244: label = PSTR( "10" ); pos = _decimals + 1; break;
  146. default: label = PSTR("100" ); pos = _decimals + 2; break;
  147. }
  148. const bool highlight = (_what & FOREGROUND) && (increment == tag);
  149. switch (pos) {
  150. #ifdef TOUCH_UI_PORTRAIT
  151. case 0: _button(cmd, tag, BTN_POS(5,_line), BTN_SIZE(2,1), progmem_str(label), true, highlight); break;
  152. case 1: _button(cmd, tag, BTN_POS(7,_line), BTN_SIZE(2,1), progmem_str(label), true, highlight); break;
  153. case 2: _button(cmd, tag, BTN_POS(9,_line), BTN_SIZE(2,1), progmem_str(label), true, highlight); break;
  154. #else
  155. case 0: _button(cmd, tag, BTN_POS(15,2), BTN_SIZE(4,1), progmem_str(label), true, highlight); break;
  156. case 1: _button(cmd, tag, BTN_POS(15,3), BTN_SIZE(4,1), progmem_str(label), true, highlight); break;
  157. case 2: _button(cmd, tag, BTN_POS(15,4), BTN_SIZE(4,1), progmem_str(label), true, highlight); break;
  158. #endif
  159. }
  160. }
  161. void BaseNumericAdjustmentScreen::widgets_t::increments() {
  162. CommandProcessor cmd;
  163. cmd.font(LAYOUT_FONT);
  164. if (_what & BACKGROUND) {
  165. _button_style(cmd, TEXT_LABEL);
  166. cmd.tag(0).text(
  167. #ifdef TOUCH_UI_PORTRAIT
  168. BTN_POS(1, _line), BTN_SIZE(4,1),
  169. #else
  170. BTN_POS(15, 1), BTN_SIZE(4,1),
  171. #endif
  172. GET_TEXT_F(MSG_INCREMENT)
  173. );
  174. }
  175. _draw_increment_btn(cmd, _line+1, 245 - _decimals);
  176. _draw_increment_btn(cmd, _line+1, 244 - _decimals);
  177. _draw_increment_btn(cmd, _line+1, 243 - _decimals);
  178. #ifdef TOUCH_UI_PORTRAIT
  179. _line++;
  180. #endif
  181. }
  182. void BaseNumericAdjustmentScreen::widgets_t::adjuster_sram_val(uint8_t tag, progmem_str label, const char *value, bool is_enabled) {
  183. CommandProcessor cmd;
  184. if (_what & BACKGROUND) {
  185. _button_style(cmd, TEXT_LABEL);
  186. cmd.tag(0)
  187. .font(font_small)
  188. .text( BTN_POS(1,_line), BTN_SIZE(4,1), label);
  189. _button_style(cmd, TEXT_AREA);
  190. cmd.fgcolor(_color).button( BTN_POS(5,_line), BTN_SIZE(5,1), F(""), OPT_FLAT);
  191. }
  192. cmd.font(font_medium);
  193. _button(cmd, tag, BTN_POS(10,_line), BTN_SIZE(2,1), F("-"), is_enabled);
  194. _button(cmd, tag + 1, BTN_POS(12,_line), BTN_SIZE(2,1), F("+"), is_enabled);
  195. if ((_what & FOREGROUND) && is_enabled) {
  196. _button_style(cmd, BTN_NORMAL);
  197. cmd.tag(0)
  198. .font(font_small)
  199. .text(BTN_POS(5,_line), BTN_SIZE(5,1), value);
  200. }
  201. _line++;
  202. }
  203. void BaseNumericAdjustmentScreen::widgets_t::adjuster(uint8_t tag, progmem_str label, const char *value, bool is_enabled) {
  204. if (_what & BACKGROUND) {
  205. adjuster_sram_val(tag, label, nullptr);
  206. }
  207. if (_what & FOREGROUND) {
  208. char b[strlen_P(value)+1];
  209. strcpy_P(b,value);
  210. adjuster_sram_val(tag, label, b, is_enabled);
  211. }
  212. }
  213. void BaseNumericAdjustmentScreen::widgets_t::adjuster(uint8_t tag, progmem_str label, float value, bool is_enabled) {
  214. if (_what & BACKGROUND) {
  215. adjuster_sram_val(tag, label, nullptr);
  216. }
  217. if (_what & FOREGROUND) {
  218. char b[32];
  219. dtostrf(value, 5, _decimals, b);
  220. strcat_P(b, PSTR(" "));
  221. strcat_P(b, (const char*) _units);
  222. adjuster_sram_val(tag, label, b, is_enabled);
  223. }
  224. }
  225. void BaseNumericAdjustmentScreen::widgets_t::button(uint8_t tag, progmem_str label, bool is_enabled) {
  226. CommandProcessor cmd;
  227. cmd.font(LAYOUT_FONT);
  228. _button(cmd, tag, BTN_POS(5,_line), BTN_SIZE(9,1), label, is_enabled);
  229. _line++;
  230. }
  231. void BaseNumericAdjustmentScreen::widgets_t::text_field(uint8_t tag, progmem_str label, const char *value, bool is_enabled) {
  232. CommandProcessor cmd;
  233. if (_what & BACKGROUND) {
  234. _button_style(cmd, TEXT_LABEL);
  235. cmd.enabled(1)
  236. .tag(0)
  237. .font(font_small)
  238. .text( BTN_POS(1,_line), BTN_SIZE(4,1), label);
  239. _button_style(cmd, TEXT_AREA);
  240. cmd.fgcolor(_color)
  241. .tag(tag)
  242. .button( BTN_POS(5,_line), BTN_SIZE(9,1), F(""), OPT_FLAT);
  243. }
  244. if (_what & FOREGROUND) {
  245. cmd.font(font_small).text( BTN_POS(5,_line), BTN_SIZE(9,1), is_enabled ? value : "-");
  246. }
  247. _line++;
  248. }
  249. void BaseNumericAdjustmentScreen::widgets_t::two_buttons(uint8_t tag1, progmem_str label1, uint8_t tag2, progmem_str label2, bool is_enabled) {
  250. CommandProcessor cmd;
  251. cmd.font(LAYOUT_FONT);
  252. _button(cmd, tag1, BTN_POS(5,_line), BTN_SIZE(4.5,1), label1, is_enabled);
  253. _button(cmd, tag2, BTN_POS(9.5,_line), BTN_SIZE(4.5,1), label2, is_enabled);
  254. _line++;
  255. }
  256. void BaseNumericAdjustmentScreen::widgets_t::toggle(uint8_t tag, progmem_str label, bool value, bool is_enabled) {
  257. CommandProcessor cmd;
  258. if (_what & BACKGROUND) {
  259. _button_style(cmd, TEXT_LABEL);
  260. cmd.font(font_small)
  261. .text(
  262. #ifdef TOUCH_UI_PORTRAIT
  263. BTN_POS(1, _line), BTN_SIZE( 8,1),
  264. #else
  265. BTN_POS(1, _line), BTN_SIZE(10,1),
  266. #endif
  267. label
  268. );
  269. }
  270. if (_what & FOREGROUND) {
  271. _button_style(cmd, BTN_TOGGLE);
  272. cmd.tag(is_enabled ? tag : 0)
  273. .enabled(is_enabled)
  274. .font(font_small)
  275. .toggle2(
  276. #ifdef TOUCH_UI_PORTRAIT
  277. BTN_POS( 9,_line), BTN_SIZE(5,1),
  278. #else
  279. BTN_POS(10,_line), BTN_SIZE(4,1),
  280. #endif
  281. GET_TEXT_F(MSG_NO), GET_TEXT_F(MSG_YES), value
  282. );
  283. }
  284. _line++;
  285. }
  286. void BaseNumericAdjustmentScreen::widgets_t::home_buttons(uint8_t tag) {
  287. CommandProcessor cmd;
  288. if (_what & BACKGROUND) {
  289. _button_style(cmd, TEXT_LABEL);
  290. cmd.font(font_small)
  291. .text(BTN_POS(1, _line), BTN_SIZE(4,1), GET_TEXT_F(MSG_HOME));
  292. }
  293. cmd.font(LAYOUT_FONT);
  294. _button(cmd, tag+0, BTN_POS(5,_line), BTN_SIZE(2,1), GET_TEXT_F(MSG_AXIS_X));
  295. _button(cmd, tag+1, BTN_POS(7,_line), BTN_SIZE(2,1), GET_TEXT_F(MSG_AXIS_Y));
  296. _button(cmd, tag+2, BTN_POS(9,_line), BTN_SIZE(2,1), GET_TEXT_F(MSG_AXIS_Z));
  297. _button(cmd, tag+3, BTN_POS(11,_line), BTN_SIZE(3,1), GET_TEXT_F(MSG_AXIS_ALL));
  298. _line++;
  299. }
  300. void BaseNumericAdjustmentScreen::onEntry() {
  301. screen_data.BaseNumericAdjustmentScreen.increment = 0; // This will force the increment to be picked while drawing.
  302. BaseScreen::onEntry();
  303. CommandProcessor cmd;
  304. cmd.set_button_style_callback(nullptr);
  305. }
  306. bool BaseNumericAdjustmentScreen::onTouchEnd(uint8_t tag) {
  307. switch (tag) {
  308. case 1: GOTO_PREVIOUS(); return true;
  309. case 240 ... 245: screen_data.BaseNumericAdjustmentScreen.increment = tag; break;
  310. default: return current_screen.onTouchHeld(tag);
  311. }
  312. return true;
  313. }
  314. float BaseNumericAdjustmentScreen::getIncrement() {
  315. switch (screen_data.BaseNumericAdjustmentScreen.increment) {
  316. case 240: return 0.001;
  317. case 241: return 0.01;
  318. case 242: return 0.1;
  319. case 243: return 1.0;
  320. case 244: return 10.0;
  321. case 245: return 100.0;
  322. default: return 0.0;
  323. }
  324. }
  325. #endif // TOUCH_UI_FTDI_EVE