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 22KB

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