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.

ui_common.cpp 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  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. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../../inc/MarlinConfigPre.h"
  23. #if IS_DWIN_MARLINUI
  24. #include "marlinui_dwin.h"
  25. #include "dwin_lcd.h"
  26. #include "dwin_string.h"
  27. //#include "../../lcdprint.h"
  28. #include "lcdprint_dwin.h"
  29. #include "../../fontutils.h"
  30. #include "../../../libs/numtostr.h"
  31. #include "../../marlinui.h"
  32. #include "../../../sd/cardreader.h"
  33. #include "../../../module/motion.h"
  34. #include "../../../module/temperature.h"
  35. #include "../../../module/printcounter.h"
  36. #if ENABLED(SDSUPPORT)
  37. #include "../../../libs/duration_t.h"
  38. #endif
  39. #if ENABLED(AUTO_BED_LEVELING_UBL)
  40. #include "../../../feature/bedlevel/bedlevel.h"
  41. #endif
  42. // DWIN printing specifies the font on each string operation
  43. // but we'll make the font modal for Marlin
  44. dwin_font_t dwin_font = { font8x16, 8, 16, Color_White, Color_Bg_Black, true };
  45. void MarlinUI::set_font(const uint8_t font_nr) {
  46. if (font_nr != dwin_font.index) {
  47. dwin_font.index = font_nr;
  48. uint8_t w, h;
  49. switch (font_nr) {
  50. default:
  51. case font6x12: w = 6; h = 12; break;
  52. case font8x16: w = 8; h = 16; break;
  53. case font10x20: w = 10; h = 20; break;
  54. case font12x24: w = 12; h = 24; break;
  55. case font14x28: w = 14; h = 28; break;
  56. case font16x32: w = 16; h = 32; break;
  57. case font20x40: w = 20; h = 40; break;
  58. case font24x48: w = 24; h = 48; break;
  59. case font28x56: w = 28; h = 56; break;
  60. case font32x64: w = 32; h = 64; break;
  61. }
  62. dwin_font.width = w;
  63. dwin_font.height = h;
  64. // TODO: Array with dimensions, auto fit menu items,
  65. // update char width / height of the screen based on
  66. // new (fixed-width) font size.
  67. }
  68. }
  69. // This display is always detected
  70. bool MarlinUI::detected() { return true; }
  71. // Initialize or re-initialize the LCD
  72. void MarlinUI::init_lcd() { DWIN_Startup(); }
  73. // This LCD should clear where it will draw anew
  74. void MarlinUI::clear_lcd() {
  75. DWIN_ICON_AnimationControl(0x0000); // disable all icon animations
  76. DWIN_Frame_Clear(Color_Bg_Black);
  77. DWIN_UpdateLCD();
  78. did_first_redraw = false;
  79. }
  80. #if ENABLED(SHOW_BOOTSCREEN)
  81. void MarlinUI::show_bootscreen() {
  82. clear_lcd();
  83. dwin_string.set(F(SHORT_BUILD_VERSION));
  84. #if ENABLED(DWIN_MARLINUI_PORTRAIT)
  85. #define LOGO_CENTER ((LCD_PIXEL_WIDTH) / 2)
  86. #define INFO_CENTER LOGO_CENTER
  87. #define VERSION_Y 330
  88. DWIN_ICON_Show(BOOT_ICON, ICON_MarlinBoot, LOGO_CENTER - 266 / 2, 15);
  89. DWIN_ICON_Show(BOOT_ICON, ICON_OpenSource, LOGO_CENTER - 174 / 2, 280);
  90. DWIN_ICON_Show(BOOT_ICON, ICON_GitHubURL, LOGO_CENTER - 180 / 2, 420);
  91. DWIN_ICON_Show(BOOT_ICON, ICON_MarlinURL, LOGO_CENTER - 100 / 2, 440);
  92. DWIN_ICON_Show(BOOT_ICON, ICON_Copyright, LOGO_CENTER - 126 / 2, 460);
  93. #else
  94. #define LOGO_CENTER (280 / 2)
  95. #define INFO_CENTER ((LCD_PIXEL_WIDTH) - 200 / 2)
  96. #define VERSION_Y 84
  97. DWIN_ICON_Show(BOOT_ICON, ICON_MarlinBoot, LOGO_CENTER - 266 / 2, 15);
  98. DWIN_ICON_Show(BOOT_ICON, ICON_OpenSource, INFO_CENTER - 174 / 2, 60);
  99. DWIN_ICON_Show(BOOT_ICON, ICON_GitHubURL, INFO_CENTER - 180 / 2, 130);
  100. DWIN_ICON_Show(BOOT_ICON, ICON_MarlinURL, INFO_CENTER - 100 / 2, 152);
  101. DWIN_ICON_Show(BOOT_ICON, ICON_Copyright, INFO_CENTER - 126 / 2, 200);
  102. #endif
  103. DWIN_Draw_String(false, font10x20, Color_Yellow, Color_Bg_Black, INFO_CENTER - (dwin_string.length() * 10) / 2, VERSION_Y, S(dwin_string.string()));
  104. DWIN_UpdateLCD();
  105. }
  106. void MarlinUI::bootscreen_completion(const millis_t sofar) {
  107. if ((BOOTSCREEN_TIMEOUT) > sofar) safe_delay((BOOTSCREEN_TIMEOUT) - sofar);
  108. clear_lcd();
  109. }
  110. #endif
  111. // The kill screen is displayed for unrecoverable conditions
  112. void MarlinUI::draw_kill_screen() {
  113. set_font(DWIN_FONT_ALERT);
  114. DWIN_Frame_Clear(Color_Bg_Black);
  115. dwin_font.fg = Color_Error_Red;
  116. dwin_font.solid = false;
  117. DWIN_Draw_Rectangle(1, Color_Bg_Window, 20, 20, LCD_PIXEL_WIDTH - 20, LCD_PIXEL_HEIGHT - 20);
  118. // make the frame a few pixels thick
  119. DWIN_Draw_Rectangle(0, Color_Yellow, 20, 20, LCD_PIXEL_WIDTH - 20, LCD_PIXEL_HEIGHT - 20);
  120. DWIN_Draw_Rectangle(0, Color_Yellow, 21, 21, LCD_PIXEL_WIDTH - 21, LCD_PIXEL_HEIGHT - 21);
  121. DWIN_Draw_Rectangle(0, Color_Yellow, 22, 22, LCD_PIXEL_WIDTH - 22, LCD_PIXEL_HEIGHT - 22);
  122. uint8_t cx = (LCD_PIXEL_WIDTH / dwin_font.width / 2),
  123. cy = (LCD_PIXEL_HEIGHT / dwin_font.height / 2);
  124. #if ENABLED(DWIN_MARLINUI_LANDSCAPE)
  125. cx += (96 / 2 / dwin_font.width);
  126. DWIN_ICON_Show(ICON, ICON_Halted, 40, (LCD_PIXEL_HEIGHT - 96) / 2);
  127. #else
  128. DWIN_ICON_Show(ICON, ICON_Halted, (LCD_PIXEL_WIDTH - 96) / 2, 40);
  129. #endif
  130. uint8_t slen = utf8_strlen(status_message);
  131. lcd_moveto(cx - (slen / 2), cy - 1);
  132. lcd_put_u8str(status_message);
  133. slen = utf8_strlen(S(GET_TEXT_F(MSG_HALTED)));
  134. lcd_moveto(cx - (slen / 2), cy);
  135. lcd_put_u8str(GET_TEXT_F(MSG_HALTED));
  136. slen = utf8_strlen(S(GET_TEXT_F(MSG_HALTED)));
  137. lcd_moveto(cx - (slen / 2), cy + 1);
  138. lcd_put_u8str(GET_TEXT_F(MSG_HALTED));
  139. }
  140. //
  141. // Status Message
  142. //
  143. void MarlinUI::draw_status_message(const bool blink) {
  144. set_font(DWIN_FONT_STAT);
  145. dwin_font.solid = true;
  146. dwin_font.fg = Color_White;
  147. dwin_font.bg = Color_Bg_Black;
  148. lcd_moveto_xy(0, LCD_PIXEL_HEIGHT - (STAT_FONT_HEIGHT) - 1);
  149. constexpr uint8_t max_status_chars = (LCD_PIXEL_WIDTH) / (STAT_FONT_WIDTH);
  150. auto status_changed = []{
  151. static uint16_t old_hash = 0x0000;
  152. uint16_t hash = 0x0000;
  153. for (uint8_t i = 0; i < MAX_MESSAGE_LENGTH; i++) {
  154. const char c = ui.status_message[i];
  155. if (!c) break;
  156. hash = ((hash << 1) | (hash >> 15)) ^ c;
  157. }
  158. const bool hash_changed = hash != old_hash;
  159. old_hash = hash;
  160. return hash_changed || !ui.did_first_redraw;
  161. };
  162. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  163. static bool last_blink = false;
  164. // Get the UTF8 character count of the string
  165. uint8_t slen = utf8_strlen(status_message);
  166. // If the string fits into the LCD, just print it and do not scroll it
  167. if (slen <= max_status_chars) {
  168. if (status_changed()) {
  169. // The string isn't scrolling and may not fill the screen
  170. lcd_put_u8str(status_message);
  171. // Fill the rest with spaces
  172. while (slen < max_status_chars) { lcd_put_wchar(' '); ++slen; }
  173. }
  174. }
  175. else {
  176. // String is larger than the available line space
  177. // Get a pointer to the next valid UTF8 character
  178. // and the string remaining length
  179. uint8_t rlen;
  180. const char *stat = status_and_len(rlen);
  181. lcd_put_u8str_max(stat, max_status_chars);
  182. // If the string doesn't completely fill the line...
  183. if (rlen < max_status_chars) {
  184. lcd_put_wchar('.'); // Always at 1+ spaces left, draw a dot
  185. uint8_t chars = max_status_chars - rlen; // Amount of space left in characters
  186. if (--chars) { // Draw a second dot if there's space
  187. lcd_put_wchar('.');
  188. if (--chars)
  189. lcd_put_u8str_max(status_message, chars); // Print a second copy of the message
  190. }
  191. }
  192. if (last_blink != blink) {
  193. last_blink = blink;
  194. advance_status_scroll();
  195. }
  196. }
  197. #else
  198. UNUSED(blink);
  199. if (status_changed()) {
  200. // Get the UTF8 character count of the string
  201. uint8_t slen = utf8_strlen(status_message);
  202. // Just print the string to the LCD
  203. lcd_put_u8str_max(status_message, max_status_chars);
  204. // Fill the rest with spaces if there are missing spaces
  205. while (slen < max_status_chars) { lcd_put_wchar(' '); ++slen; }
  206. }
  207. #endif
  208. }
  209. #if HAS_LCD_BRIGHTNESS
  210. void MarlinUI::_set_brightness() { DWIN_LCD_Brightness(backlight ? brightness : 0); }
  211. #endif
  212. #if HAS_MARLINUI_MENU
  213. #include "../../menu/menu.h"
  214. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  215. void MarlinUI::draw_hotend_status(const uint8_t row, const uint8_t extruder) {
  216. dwin_font.solid = false;
  217. dwin_font.fg = Color_White;
  218. dwin_string.set("E");
  219. dwin_string.add('1' + extruder);
  220. dwin_string.add(' ');
  221. dwin_string.add(i16tostr3rj(thermalManager.degHotend(extruder)));
  222. dwin_string.add('/');
  223. if (get_blink() || !thermalManager.heater_idle[thermalManager.idle_index_for_id(extruder)].timed_out)
  224. dwin_string.add(i16tostr3rj(thermalManager.degTargetHotend(extruder)));
  225. else
  226. dwin_string.add(PSTR(" "));
  227. lcd_moveto(LCD_WIDTH - dwin_string.length(), row);
  228. lcd_put_dwin_string();
  229. }
  230. #endif
  231. // Set the colors for a menu item based on whether it is selected
  232. static bool mark_as_selected(const uint8_t row, const bool sel, const bool is_static=false) {
  233. const dwin_coord_t y = row * (MENU_LINE_HEIGHT) + 1;
  234. if (y >= LCD_PIXEL_HEIGHT) return false;
  235. if (is_static && sel)
  236. DWIN_Draw_Box(1, Color_Bg_Heading, 0, y, LCD_PIXEL_WIDTH, MENU_LINE_HEIGHT - 1);
  237. else {
  238. #if ENABLED(MENU_HOLLOW_FRAME)
  239. DWIN_Draw_Box(1, Color_Bg_Black, 0, y, LCD_PIXEL_WIDTH, MENU_LINE_HEIGHT - 1);
  240. if (sel) DWIN_Draw_Box(0, Select_Color, 0, y, LCD_PIXEL_WIDTH, MENU_LINE_HEIGHT - 1);
  241. #else
  242. DWIN_Draw_Box(1, sel ? Select_Color : Color_Bg_Black, 0, y, LCD_PIXEL_WIDTH, MENU_LINE_HEIGHT - 1);
  243. #endif
  244. }
  245. return true;
  246. }
  247. // Draw a static line of text in the same idiom as a menu item
  248. void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
  249. // Call mark_as_selected to draw a bigger selection box
  250. // and draw the text without a background
  251. if (mark_as_selected(row, (bool)(style & SS_INVERT), true)) {
  252. ui.set_font(DWIN_FONT_MENU);
  253. dwin_font.solid = false;
  254. dwin_font.fg = Color_White;
  255. dwin_string.set();
  256. const int8_t plen = pstr ? utf8_strlen_P(pstr) : 0,
  257. vlen = vstr ? utf8_strlen(vstr) : 0;
  258. if (style & SS_CENTER) {
  259. int8_t pad = (LCD_WIDTH - 1 - plen - vlen) / 2;
  260. while (--pad) dwin_string.add(' ');
  261. }
  262. if (plen) dwin_string.add((uint8_t*)pstr, itemIndex, (uint8_t*)itemString);
  263. if (vlen) dwin_string.add((uint8_t*)vstr);
  264. if (style & SS_CENTER) {
  265. int8_t pad = (LCD_WIDTH - 1 - plen - vlen) / 2;
  266. while (--pad) dwin_string.add(' ');
  267. }
  268. lcd_moveto(1, row);
  269. lcd_put_dwin_string();
  270. }
  271. }
  272. // Draw a generic menu item
  273. void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char, const char post_char) {
  274. if (mark_as_selected(row, sel)) {
  275. ui.set_font(DWIN_FONT_MENU);
  276. dwin_font.solid = false;
  277. dwin_font.fg = Color_White;
  278. dwin_string.set(pstr, itemIndex, itemString);
  279. pixel_len_t n = LCD_WIDTH - 1 - dwin_string.length();
  280. while (--n > 1) dwin_string.add(' ');
  281. dwin_string.add(post_char);
  282. lcd_moveto(1, row);
  283. lcd_put_dwin_string();
  284. }
  285. }
  286. //
  287. // Draw a menu item with an editable value
  288. //
  289. void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm) {
  290. if (mark_as_selected(row, sel)) {
  291. ui.set_font(DWIN_FONT_MENU);
  292. dwin_font.solid = false;
  293. dwin_font.fg = Color_White;
  294. const uint8_t vallen = (pgm ? utf8_strlen_P(data) : utf8_strlen(S(data)));
  295. dwin_string.set(pstr, itemIndex, itemString);
  296. if (vallen) dwin_string.add(':');
  297. lcd_moveto(1, row);
  298. lcd_put_dwin_string();
  299. if (vallen) {
  300. dwin_font.fg = Color_Yellow;
  301. dwin_string.set(data);
  302. lcd_moveto(LCD_WIDTH - vallen - 1, row);
  303. lcd_put_dwin_string();
  304. }
  305. }
  306. }
  307. //
  308. // Draw an edit screen with label and current value
  309. //
  310. void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) {
  311. ui.encoder_direction_normal();
  312. const dwin_coord_t labellen = utf8_strlen_P(pstr), vallen = utf8_strlen(value);
  313. dwin_string.set();
  314. dwin_string.add((uint8_t*)pstr, itemIndex);
  315. if (vallen) dwin_string.add(':'); // If a value is included, add a colon
  316. // Assume the label is alpha-numeric (with a descender)
  317. const uint16_t row = (LCD_HEIGHT / 2) - 1;
  318. dwin_font.fg = Color_White;
  319. dwin_font.solid = true;
  320. lcd_moveto((LCD_WIDTH - labellen + !!vallen) / 2, row);
  321. lcd_put_dwin_string();
  322. // If a value is included, print the value in larger text below the label
  323. if (vallen) {
  324. dwin_string.set();
  325. dwin_string.add(value);
  326. const dwin_coord_t by = (row * MENU_LINE_HEIGHT) + MENU_FONT_HEIGHT + EXTRA_ROW_HEIGHT / 2;
  327. DWIN_Draw_String(true, font16x32, Color_Yellow, Color_Bg_Black, (LCD_PIXEL_WIDTH - vallen * 16) / 2, by, S(dwin_string.string()));
  328. extern screenFunc_t _manual_move_func_ptr;
  329. if (ui.currentScreen != _manual_move_func_ptr && !ui.external_control) {
  330. const dwin_coord_t slider_length = LCD_PIXEL_WIDTH - TERN(DWIN_MARLINUI_LANDSCAPE, 120, 20),
  331. slider_height = 16,
  332. slider_x = (LCD_PIXEL_WIDTH - slider_length) / 2,
  333. slider_y = by + 32 + 4,
  334. amount = ui.encoderPosition * slider_length / maxEditValue;
  335. DWIN_Draw_Rectangle(1, Color_Bg_Window, slider_x - 1, slider_y - 1, slider_x - 1 + slider_length + 2 - 1, slider_y - 1 + slider_height + 2 - 1);
  336. if (amount > 0)
  337. DWIN_Draw_Box(1, BarFill_Color, slider_x, slider_y, amount, slider_height);
  338. if (amount < slider_length)
  339. DWIN_Draw_Box(1, Color_Bg_Black, slider_x + amount, slider_y, slider_length - amount, slider_height);
  340. }
  341. }
  342. }
  343. inline void draw_boxed_string(const bool yesopt, PGM_P const pstr, const bool inv) {
  344. const uint8_t len = utf8_strlen_P(pstr),
  345. mar = TERN(DWIN_MARLINUI_PORTRAIT, 1, 4),
  346. col = yesopt ? LCD_WIDTH - mar - len : mar,
  347. row = (LCD_HEIGHT >= 8 ? LCD_HEIGHT / 2 + 3 : LCD_HEIGHT - 1);
  348. lcd_moveto(col, row);
  349. DWIN_Draw_Box(1, inv ? Select_Color : Color_Bg_Black, cursor.x - dwin_font.width, cursor.y + 1, dwin_font.width * (len + 2), dwin_font.height + 2);
  350. lcd_put_u8str_P(col, row, pstr);
  351. }
  352. void MenuItem_confirm::draw_select_screen(
  353. PGM_P const yes, PGM_P const no, const bool yesno,
  354. PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/
  355. ) {
  356. ui.set_font(DWIN_FONT_MENU);
  357. dwin_font.solid = false;
  358. dwin_font.fg = Color_White;
  359. ui.draw_select_screen_prompt(pref, string, suff);
  360. draw_boxed_string(false, no, !yesno);
  361. draw_boxed_string(true, yes, yesno);
  362. }
  363. #if ENABLED(SDSUPPORT)
  364. void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) {
  365. if (mark_as_selected(row, sel)) {
  366. dwin_string.set();
  367. uint8_t maxlen = LCD_WIDTH - 1;
  368. if (isDir) {
  369. dwin_string.add(LCD_STR_FOLDER " ");
  370. maxlen -= 2;
  371. }
  372. dwin_string.add((uint8_t*)ui.scrolled_filename(theCard, maxlen, row, sel), maxlen);
  373. uint8_t n = maxlen - dwin_string.length();
  374. while (n > 0) { dwin_string.add(' '); --n; }
  375. lcd_moveto(1, row);
  376. lcd_put_dwin_string();
  377. }
  378. }
  379. #endif // SDSUPPORT
  380. #if ENABLED(AUTO_BED_LEVELING_UBL)
  381. /**
  382. * UBL LCD "radar" map data
  383. */
  384. #define MAP_UPPER_LEFT_CORNER_X 5 // These probably should be moved to the .h file But for now,
  385. #define MAP_UPPER_LEFT_CORNER_Y 5 // it is easier to play with things having them here
  386. #define MAP_MAX_PIXELS_X 262 // 272 - 10
  387. #define MAP_MAX_PIXELS_Y 262
  388. void MarlinUI::ubl_plot(const uint8_t x_plot, const uint8_t y_plot) {
  389. // Scale the box pixels appropriately
  390. dwin_coord_t x_map_pixels = ((MAP_MAX_PIXELS_X - 4) / (GRID_MAX_POINTS_X)) * (GRID_MAX_POINTS_X),
  391. y_map_pixels = ((MAP_MAX_PIXELS_Y - 4) / (GRID_MAX_POINTS_Y)) * (GRID_MAX_POINTS_Y),
  392. pixels_per_x_mesh_pnt = x_map_pixels / (GRID_MAX_POINTS_X),
  393. pixels_per_y_mesh_pnt = y_map_pixels / (GRID_MAX_POINTS_Y),
  394. x_offset = MAP_UPPER_LEFT_CORNER_X + 1 + (MAP_MAX_PIXELS_X - x_map_pixels - 2) / 2,
  395. y_offset = MAP_UPPER_LEFT_CORNER_Y + 1 + (MAP_MAX_PIXELS_Y - y_map_pixels - 2) / 2;
  396. // Clear the Mesh Map
  397. // First draw the bigger box in White so we have a border around the mesh map box
  398. DWIN_Draw_Rectangle(1, Color_White, x_offset - 2, y_offset - 2, x_offset + 2 + x_map_pixels, y_offset + 2 + y_map_pixels);
  399. // Now actually clear the mesh map box
  400. DWIN_Draw_Rectangle(1, Color_Bg_Black, x_offset, y_offset, x_offset + x_map_pixels, y_offset + y_map_pixels);
  401. // Fill in the Specified Mesh Point
  402. const uint8_t y_plot_inv = (GRID_MAX_POINTS_Y - 1) - y_plot; // The origin is typically in the lower right corner. We need to
  403. // invert the Y to get it to plot in the right location.
  404. const dwin_coord_t by = y_offset + y_plot_inv * pixels_per_y_mesh_pnt;
  405. DWIN_Draw_Rectangle(1, Select_Color,
  406. x_offset + (x_plot * pixels_per_x_mesh_pnt), by,
  407. x_offset + (x_plot * pixels_per_x_mesh_pnt) + pixels_per_x_mesh_pnt, by + pixels_per_y_mesh_pnt
  408. );
  409. // Display Mesh Point Locations
  410. const dwin_coord_t sx = x_offset + pixels_per_x_mesh_pnt / 2;
  411. dwin_coord_t y = y_offset + pixels_per_y_mesh_pnt / 2;
  412. for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++, y += pixels_per_y_mesh_pnt)
  413. for (uint8_t i = 0, x = sx; i < GRID_MAX_POINTS_X; i++, x += pixels_per_x_mesh_pnt)
  414. DWIN_Draw_Point(Color_White, 1, 1, x, y);
  415. // Put Relevant Text on Display
  416. // Show X and Y positions at top of screen
  417. dwin_font.fg = Color_White;
  418. dwin_font.solid = true;
  419. const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) },
  420. lpos = pos.asLogical();
  421. lcd_moveto(
  422. TERN(DWIN_MARLINUI_LANDSCAPE, ((x_offset + x_map_pixels) / MENU_FONT_WIDTH) + 2, 1),
  423. TERN(DWIN_MARLINUI_LANDSCAPE, 1, ((y_offset + y_map_pixels) / MENU_LINE_HEIGHT) + 1)
  424. );
  425. lcd_put_u8str_P(X_LBL);
  426. lcd_put_u8str(ftostr52(lpos.x));
  427. lcd_moveto(
  428. TERN(DWIN_MARLINUI_LANDSCAPE, ((x_offset + x_map_pixels) / MENU_FONT_WIDTH) + 2, 1),
  429. TERN(DWIN_MARLINUI_LANDSCAPE, 3, ((y_offset + y_map_pixels) / MENU_LINE_HEIGHT) + 2)
  430. );
  431. lcd_put_u8str_P(Y_LBL);
  432. lcd_put_u8str(ftostr52(lpos.y));
  433. // Print plot position
  434. dwin_string.set("(");
  435. dwin_string.add(i8tostr3rj(x_plot));
  436. dwin_string.add(",");
  437. dwin_string.add(i8tostr3rj(y_plot));
  438. dwin_string.add(")");
  439. lcd_moveto(
  440. TERN(DWIN_MARLINUI_LANDSCAPE, ((x_offset + x_map_pixels) / MENU_FONT_WIDTH) + 2, LCD_WIDTH - dwin_string.length()),
  441. TERN(DWIN_MARLINUI_LANDSCAPE, LCD_HEIGHT - 2, ((y_offset + y_map_pixels) / MENU_LINE_HEIGHT) + 1)
  442. );
  443. lcd_put_dwin_string();
  444. // Show the location value
  445. dwin_string.set(Z_LBL);
  446. if (!isnan(Z_VALUES_ARR[x_plot][y_plot]))
  447. dwin_string.add(ftostr43sign(Z_VALUES_ARR[x_plot][y_plot]));
  448. else
  449. dwin_string.add(PSTR(" -----"));
  450. lcd_moveto(
  451. TERN(DWIN_MARLINUI_LANDSCAPE, ((x_offset + x_map_pixels) / MENU_FONT_WIDTH) + 2, LCD_WIDTH - dwin_string.length()),
  452. TERN(DWIN_MARLINUI_LANDSCAPE, LCD_HEIGHT - 1, ((y_offset + y_map_pixels) / MENU_LINE_HEIGHT) + 2)
  453. );
  454. lcd_put_dwin_string();
  455. }
  456. #endif // AUTO_BED_LEVELING_UBL
  457. #if ANY(BABYSTEP_ZPROBE_GFX_OVERLAY, MESH_EDIT_GFX_OVERLAY)
  458. void MarlinUI::zoffset_overlay(const int8_t dir) {
  459. const int rot_up = TERN(OVERLAY_GFX_REVERSE, ICON_RotateCCW, ICON_RotateCW),
  460. rot_down = TERN(OVERLAY_GFX_REVERSE, ICON_RotateCW, ICON_RotateCCW);
  461. const int nozzle = (LCD_PIXEL_WIDTH / 2) - 20;
  462. // Draw a representation of the nozzle
  463. DWIN_Draw_Box(1, Color_Bg_Black, nozzle + 3, 8, 48, 52); // 'clear' the area where the nozzle is drawn in case it was moved up/down
  464. DWIN_ICON_Show(ICON, ICON_HotendOff, nozzle + 3, 10 - dir);
  465. DWIN_ICON_Show(ICON, ICON_BedLine, nozzle, 10 + 36);
  466. // Draw cw/ccw indicator and up/down arrows
  467. const int arrow_y = LCD_PIXEL_HEIGHT / 2 - 24;
  468. DWIN_ICON_Show(ICON, ICON_DownArrow, 0, arrow_y - dir);
  469. DWIN_ICON_Show(ICON, rot_down, 48, arrow_y);
  470. DWIN_ICON_Show(ICON, ICON_UpArrow, LCD_PIXEL_WIDTH - 10 - (48*2), arrow_y - dir);
  471. DWIN_ICON_Show(ICON, rot_up, LCD_PIXEL_WIDTH - 10 - 48, arrow_y);
  472. }
  473. #endif // BABYSTEP_ZPROBE_GFX_OVERLAY || MESH_EDIT_GFX_OVERLAY
  474. #endif // HAS_MARLINUI_MENU
  475. #endif // IS_DWIN_MARLINUI