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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  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_CacheToN(1, 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_MENU
  214. #include "../../menu/menu.h"
  215. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  216. void MarlinUI::draw_hotend_status(const uint8_t row, const uint8_t extruder) {
  217. dwin_font.solid = false;
  218. dwin_font.fg = Color_White;
  219. dwin_string.set("E");
  220. dwin_string.add('1' + extruder);
  221. dwin_string.add(' ');
  222. dwin_string.add(i16tostr3rj(thermalManager.degHotend(extruder)));
  223. dwin_string.add('/');
  224. if (get_blink() || !thermalManager.heater_idle[thermalManager.idle_index_for_id(extruder)].timed_out)
  225. dwin_string.add(i16tostr3rj(thermalManager.degTargetHotend(extruder)));
  226. else
  227. dwin_string.add(PSTR(" "));
  228. lcd_moveto(LCD_WIDTH - dwin_string.length(), row);
  229. lcd_put_dwin_string();
  230. }
  231. #endif
  232. // Set the colors for a menu item based on whether it is selected
  233. static bool mark_as_selected(const uint8_t row, const bool sel, const bool is_static=false) {
  234. const dwin_coord_t y = row * (MENU_LINE_HEIGHT) + 1;
  235. if (y >= LCD_PIXEL_HEIGHT) return false;
  236. if (is_static && sel)
  237. DWIN_Draw_Box(1, Color_Bg_Heading, 0, y, LCD_PIXEL_WIDTH, MENU_LINE_HEIGHT - 1);
  238. else {
  239. #if ENABLED(MENU_HOLLOW_FRAME)
  240. DWIN_Draw_Box(1, Color_Bg_Black, 0, y, LCD_PIXEL_WIDTH, MENU_LINE_HEIGHT - 1);
  241. if (sel) DWIN_Draw_Box(0, Select_Color, 0, y, LCD_PIXEL_WIDTH, MENU_LINE_HEIGHT - 1);
  242. #else
  243. DWIN_Draw_Box(1, sel ? Select_Color : Color_Bg_Black, 0, y, LCD_PIXEL_WIDTH, MENU_LINE_HEIGHT - 1);
  244. #endif
  245. }
  246. return true;
  247. }
  248. // Draw a static line of text in the same idiom as a menu item
  249. void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
  250. // Call mark_as_selected to draw a bigger selection box
  251. // and draw the text without a background
  252. if (mark_as_selected(row, (bool)(style & SS_INVERT), true)) {
  253. ui.set_font(DWIN_FONT_MENU);
  254. dwin_font.solid = false;
  255. dwin_font.fg = Color_White;
  256. dwin_string.set();
  257. const int8_t plen = pstr ? utf8_strlen_P(pstr) : 0,
  258. vlen = vstr ? utf8_strlen(vstr) : 0;
  259. if (style & SS_CENTER) {
  260. int8_t pad = (LCD_WIDTH - 1 - plen - vlen) / 2;
  261. while (--pad) dwin_string.add(' ');
  262. }
  263. if (plen) dwin_string.add((uint8_t*)pstr, itemIndex, (uint8_t*)itemString);
  264. if (vlen) dwin_string.add((uint8_t*)vstr);
  265. if (style & SS_CENTER) {
  266. int8_t pad = (LCD_WIDTH - 1 - plen - vlen) / 2;
  267. while (--pad) dwin_string.add(' ');
  268. }
  269. lcd_moveto(1, row);
  270. lcd_put_dwin_string();
  271. }
  272. }
  273. // Draw a generic menu item
  274. void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char, const char post_char) {
  275. if (mark_as_selected(row, sel)) {
  276. ui.set_font(DWIN_FONT_MENU);
  277. dwin_font.solid = false;
  278. dwin_font.fg = Color_White;
  279. dwin_string.set(pstr, itemIndex, itemString);
  280. pixel_len_t n = LCD_WIDTH - 1 - dwin_string.length();
  281. while (--n > 1) dwin_string.add(' ');
  282. dwin_string.add(post_char);
  283. lcd_moveto(1, row);
  284. lcd_put_dwin_string();
  285. }
  286. }
  287. //
  288. // Draw a menu item with an editable value
  289. //
  290. void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm) {
  291. if (mark_as_selected(row, sel)) {
  292. ui.set_font(DWIN_FONT_MENU);
  293. dwin_font.solid = false;
  294. dwin_font.fg = Color_White;
  295. const uint8_t vallen = (pgm ? utf8_strlen_P(data) : utf8_strlen(S(data)));
  296. dwin_string.set(pstr, itemIndex, itemString);
  297. if (vallen) dwin_string.add(':');
  298. lcd_moveto(1, row);
  299. lcd_put_dwin_string();
  300. if (vallen) {
  301. dwin_font.fg = Color_Yellow;
  302. dwin_string.set(data);
  303. lcd_moveto(LCD_WIDTH - vallen - 1, row);
  304. lcd_put_dwin_string();
  305. }
  306. }
  307. }
  308. //
  309. // Draw an edit screen with label and current value
  310. //
  311. void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) {
  312. ui.encoder_direction_normal();
  313. const dwin_coord_t labellen = utf8_strlen_P(pstr), vallen = utf8_strlen(value);
  314. dwin_string.set();
  315. dwin_string.add((uint8_t*)pstr, itemIndex);
  316. if (vallen) dwin_string.add(':'); // If a value is included, add a colon
  317. // Assume the label is alpha-numeric (with a descender)
  318. const uint16_t row = (LCD_HEIGHT / 2) - 1;
  319. dwin_font.fg = Color_White;
  320. dwin_font.solid = true;
  321. lcd_moveto((LCD_WIDTH - labellen + !!vallen) / 2, row);
  322. lcd_put_dwin_string();
  323. // If a value is included, print the value in larger text below the label
  324. if (vallen) {
  325. dwin_string.set();
  326. dwin_string.add(value);
  327. const dwin_coord_t by = (row * MENU_LINE_HEIGHT) + MENU_FONT_HEIGHT + EXTRA_ROW_HEIGHT / 2;
  328. DWIN_Draw_String(true, font16x32, Color_Yellow, Color_Bg_Black, (LCD_PIXEL_WIDTH - vallen * 16) / 2, by, S(dwin_string.string()));
  329. extern screenFunc_t _manual_move_func_ptr;
  330. if (ui.currentScreen != _manual_move_func_ptr && !ui.external_control) {
  331. const dwin_coord_t slider_length = LCD_PIXEL_WIDTH - TERN(DWIN_MARLINUI_LANDSCAPE, 120, 20),
  332. slider_height = 16,
  333. slider_x = (LCD_PIXEL_WIDTH - slider_length) / 2,
  334. slider_y = by + 32 + 4,
  335. amount = ui.encoderPosition * slider_length / maxEditValue;
  336. 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);
  337. if (amount > 0)
  338. DWIN_Draw_Box(1, BarFill_Color, slider_x, slider_y, amount, slider_height);
  339. if (amount < slider_length)
  340. DWIN_Draw_Box(1, Color_Bg_Black, slider_x + amount, slider_y, slider_length - amount, slider_height);
  341. }
  342. }
  343. }
  344. inline void draw_boxed_string(const bool yesopt, PGM_P const pstr, const bool inv) {
  345. const uint8_t len = utf8_strlen_P(pstr),
  346. mar = TERN(DWIN_MARLINUI_PORTRAIT, 1, 4),
  347. col = yesopt ? LCD_WIDTH - mar - len : mar,
  348. row = (LCD_HEIGHT >= 8 ? LCD_HEIGHT / 2 + 3 : LCD_HEIGHT - 1);
  349. lcd_moveto(col, row);
  350. 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);
  351. lcd_put_u8str_P(col, row, pstr);
  352. }
  353. void MenuItem_confirm::draw_select_screen(
  354. PGM_P const yes, PGM_P const no, const bool yesno,
  355. PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/
  356. ) {
  357. ui.set_font(DWIN_FONT_MENU);
  358. dwin_font.solid = false;
  359. dwin_font.fg = Color_White;
  360. ui.draw_select_screen_prompt(pref, string, suff);
  361. draw_boxed_string(false, no, !yesno);
  362. draw_boxed_string(true, yes, yesno);
  363. }
  364. #if ENABLED(SDSUPPORT)
  365. void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) {
  366. if (mark_as_selected(row, sel)) {
  367. dwin_string.set();
  368. uint8_t maxlen = LCD_WIDTH - 1;
  369. if (isDir) {
  370. dwin_string.add(LCD_STR_FOLDER " ");
  371. maxlen -= 2;
  372. }
  373. dwin_string.add((uint8_t*)ui.scrolled_filename(theCard, maxlen, row, sel), maxlen);
  374. uint8_t n = maxlen - dwin_string.length();
  375. while (n > 0) { dwin_string.add(' '); --n; }
  376. lcd_moveto(1, row);
  377. lcd_put_dwin_string();
  378. }
  379. }
  380. #endif // SDSUPPORT
  381. #if ENABLED(AUTO_BED_LEVELING_UBL)
  382. /**
  383. * UBL LCD "radar" map data
  384. */
  385. #define MAP_UPPER_LEFT_CORNER_X 5 // These probably should be moved to the .h file But for now,
  386. #define MAP_UPPER_LEFT_CORNER_Y 5 // it is easier to play with things having them here
  387. #define MAP_MAX_PIXELS_X 262 // 272 - 10
  388. #define MAP_MAX_PIXELS_Y 262
  389. void MarlinUI::ubl_plot(const uint8_t x_plot, const uint8_t y_plot) {
  390. // Scale the box pixels appropriately
  391. dwin_coord_t x_map_pixels = ((MAP_MAX_PIXELS_X - 4) / (GRID_MAX_POINTS_X)) * (GRID_MAX_POINTS_X),
  392. y_map_pixels = ((MAP_MAX_PIXELS_Y - 4) / (GRID_MAX_POINTS_Y)) * (GRID_MAX_POINTS_Y),
  393. pixels_per_x_mesh_pnt = x_map_pixels / (GRID_MAX_POINTS_X),
  394. pixels_per_y_mesh_pnt = y_map_pixels / (GRID_MAX_POINTS_Y),
  395. x_offset = MAP_UPPER_LEFT_CORNER_X + 1 + (MAP_MAX_PIXELS_X - x_map_pixels - 2) / 2,
  396. y_offset = MAP_UPPER_LEFT_CORNER_Y + 1 + (MAP_MAX_PIXELS_Y - y_map_pixels - 2) / 2;
  397. // Clear the Mesh Map
  398. // First draw the bigger box in White so we have a border around the mesh map box
  399. DWIN_Draw_Rectangle(1, Color_White, x_offset - 2, y_offset - 2, x_offset + 2 + x_map_pixels, y_offset + 2 + y_map_pixels);
  400. // Now actually clear the mesh map box
  401. DWIN_Draw_Rectangle(1, Color_Bg_Black, x_offset, y_offset, x_offset + x_map_pixels, y_offset + y_map_pixels);
  402. // Fill in the Specified Mesh Point
  403. 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
  404. // invert the Y to get it to plot in the right location.
  405. const dwin_coord_t by = y_offset + y_plot_inv * pixels_per_y_mesh_pnt;
  406. DWIN_Draw_Rectangle(1, Select_Color,
  407. x_offset + (x_plot * pixels_per_x_mesh_pnt), by,
  408. x_offset + (x_plot * pixels_per_x_mesh_pnt) + pixels_per_x_mesh_pnt, by + pixels_per_y_mesh_pnt
  409. );
  410. // Display Mesh Point Locations
  411. const dwin_coord_t sx = x_offset + pixels_per_x_mesh_pnt / 2;
  412. dwin_coord_t y = y_offset + pixels_per_y_mesh_pnt / 2;
  413. for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++, y += pixels_per_y_mesh_pnt)
  414. for (uint8_t i = 0, x = sx; i < GRID_MAX_POINTS_X; i++, x += pixels_per_x_mesh_pnt)
  415. DWIN_Draw_Point(Color_White, 1, 1, x, y);
  416. // Put Relevant Text on Display
  417. // Show X and Y positions at top of screen
  418. dwin_font.fg = Color_White;
  419. dwin_font.solid = true;
  420. const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) },
  421. lpos = pos.asLogical();
  422. lcd_moveto(
  423. TERN(DWIN_MARLINUI_LANDSCAPE, ((x_offset + x_map_pixels) / MENU_FONT_WIDTH) + 2, 1),
  424. TERN(DWIN_MARLINUI_LANDSCAPE, 1, ((y_offset + y_map_pixels) / MENU_LINE_HEIGHT) + 1)
  425. );
  426. lcd_put_u8str_P(X_LBL);
  427. lcd_put_u8str(ftostr52(lpos.x));
  428. lcd_moveto(
  429. TERN(DWIN_MARLINUI_LANDSCAPE, ((x_offset + x_map_pixels) / MENU_FONT_WIDTH) + 2, 1),
  430. TERN(DWIN_MARLINUI_LANDSCAPE, 3, ((y_offset + y_map_pixels) / MENU_LINE_HEIGHT) + 2)
  431. );
  432. lcd_put_u8str_P(Y_LBL);
  433. lcd_put_u8str(ftostr52(lpos.y));
  434. // Print plot position
  435. dwin_string.set("(");
  436. dwin_string.add(i8tostr3rj(x_plot));
  437. dwin_string.add(",");
  438. dwin_string.add(i8tostr3rj(y_plot));
  439. dwin_string.add(")");
  440. lcd_moveto(
  441. TERN(DWIN_MARLINUI_LANDSCAPE, ((x_offset + x_map_pixels) / MENU_FONT_WIDTH) + 2, LCD_WIDTH - dwin_string.length()),
  442. TERN(DWIN_MARLINUI_LANDSCAPE, LCD_HEIGHT - 2, ((y_offset + y_map_pixels) / MENU_LINE_HEIGHT) + 1)
  443. );
  444. lcd_put_dwin_string();
  445. // Show the location value
  446. dwin_string.set(Z_LBL);
  447. if (!isnan(ubl.z_values[x_plot][y_plot]))
  448. dwin_string.add(ftostr43sign(ubl.z_values[x_plot][y_plot]));
  449. else
  450. dwin_string.add(PSTR(" -----"));
  451. lcd_moveto(
  452. TERN(DWIN_MARLINUI_LANDSCAPE, ((x_offset + x_map_pixels) / MENU_FONT_WIDTH) + 2, LCD_WIDTH - dwin_string.length()),
  453. TERN(DWIN_MARLINUI_LANDSCAPE, LCD_HEIGHT - 1, ((y_offset + y_map_pixels) / MENU_LINE_HEIGHT) + 2)
  454. );
  455. lcd_put_dwin_string();
  456. }
  457. #endif // AUTO_BED_LEVELING_UBL
  458. #if ANY(BABYSTEP_ZPROBE_GFX_OVERLAY, MESH_EDIT_GFX_OVERLAY, BABYSTEP_GFX_OVERLAY)
  459. void _lcd_zoffset_overlay_gfx(const float zvalue) {
  460. // Determine whether the user is raising or lowering the nozzle.
  461. static int8_t dir;
  462. static float old_zvalue;
  463. if (zvalue != old_zvalue) {
  464. dir = zvalue ? zvalue < old_zvalue ? -1 : 1 : 0;
  465. old_zvalue = zvalue;
  466. }
  467. const int rot_up = TERN(OVERLAY_GFX_REVERSE, ICON_RotateCCW, ICON_RotateCW),
  468. rot_down = TERN(OVERLAY_GFX_REVERSE, ICON_RotateCW, ICON_RotateCCW);
  469. const int nozzle = (LCD_PIXEL_WIDTH / 2) - 20;
  470. // Draw a representation of the nozzle
  471. 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
  472. DWIN_ICON_Show(ICON, ICON_HotendOff, nozzle + 3, 10 - dir);
  473. DWIN_ICON_Show(ICON, ICON_BedLine, nozzle, 10 + 36);
  474. // Draw cw/ccw indicator and up/down arrows
  475. const int arrow_y = LCD_PIXEL_HEIGHT / 2 - 24;
  476. DWIN_ICON_Show(ICON, ICON_DownArrow, 0, arrow_y - dir);
  477. DWIN_ICON_Show(ICON, rot_down, 48, arrow_y);
  478. DWIN_ICON_Show(ICON, ICON_UpArrow, LCD_PIXEL_WIDTH - 10 - (48*2), arrow_y - dir);
  479. DWIN_ICON_Show(ICON, rot_up, LCD_PIXEL_WIDTH - 10 - 48, arrow_y);
  480. }
  481. #endif // BABYSTEP_ZPROBE_GFX_OVERLAY || MESH_EDIT_GFX_OVERLAY
  482. #endif // HAS_LCD_MENU
  483. #endif // IS_DWIN_MARLINUI