From 03344a094739670074e3220564bd16a902df0fca Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 27 Aug 2021 16:12:08 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20MarlinUI=20for=20E3V2=20tweaks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/lcd/e3v2/creality/dwin.cpp | 10 ++-------- Marlin/src/lcd/e3v2/marlinui/dwin_lcd.h | 1 - Marlin/src/lcd/e3v2/marlinui/dwin_string.cpp | 10 +++++----- Marlin/src/lcd/e3v2/marlinui/dwin_string.h | 20 +++++++++---------- .../src/lcd/e3v2/marlinui/lcdprint_dwin.cpp | 16 +++++++-------- 5 files changed, 24 insertions(+), 33 deletions(-) diff --git a/Marlin/src/lcd/e3v2/creality/dwin.cpp b/Marlin/src/lcd/e3v2/creality/dwin.cpp index a6218609df..d14d6f10dd 100644 --- a/Marlin/src/lcd/e3v2/creality/dwin.cpp +++ b/Marlin/src/lcd/e3v2/creality/dwin.cpp @@ -579,14 +579,8 @@ void DWIN_Draw_Label(const uint8_t row, const __FlashStringHelper *title) { } void DWIN_Draw_Signed_Float(uint8_t size, uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, long value) { - if (value < 0) { - DWIN_Draw_String(true, size, Color_White, bColor, x - 8, y, F("-")); - DWIN_Draw_FloatValue(true, true, 0, size, Color_White, bColor, iNum, fNum, x, y, -value); - } - else { - DWIN_Draw_String(true, size, Color_White, bColor, x - 8, y, F(" ")); - DWIN_Draw_FloatValue(true, true, 0, size, Color_White, bColor, iNum, fNum, x, y, value); - } + DWIN_Draw_String(true, size, Color_White, bColor, x - 8, y, value < 0 ? F("-") : F(" ")); + DWIN_Draw_FloatValue(true, true, 0, size, Color_White, bColor, iNum, fNum, x, y, value < 0 ? -value : value); } void Draw_Edit_Integer3(const uint8_t row, const uint16_t value, const bool active=false) { diff --git a/Marlin/src/lcd/e3v2/marlinui/dwin_lcd.h b/Marlin/src/lcd/e3v2/marlinui/dwin_lcd.h index 09d7b5ddd2..4d8e670e1c 100644 --- a/Marlin/src/lcd/e3v2/marlinui/dwin_lcd.h +++ b/Marlin/src/lcd/e3v2/marlinui/dwin_lcd.h @@ -67,7 +67,6 @@ #define DWIN_FONT_MENU font10x20 #define DWIN_FONT_STAT font14x28 -#define DWIN_FONT_HEAD font10x20 #define DWIN_FONT_ALERT font14x28 // Color diff --git a/Marlin/src/lcd/e3v2/marlinui/dwin_string.cpp b/Marlin/src/lcd/e3v2/marlinui/dwin_string.cpp index c7b37319c4..89e001b29c 100644 --- a/Marlin/src/lcd/e3v2/marlinui/dwin_string.cpp +++ b/Marlin/src/lcd/e3v2/marlinui/dwin_string.cpp @@ -47,7 +47,7 @@ uint8_t read_byte(uint8_t *byte) { return *byte; } * ~ displays '1'....'11' for indexes 0 - 10 * * displays 'E1'...'E11' for indexes 0 - 10 (By default. Uses LCD_FIRST_TOOL) */ -void DWIN_String::add(uint8_t *string, int8_t index, uint8_t *itemString) { +void DWIN_String::add(uint8_t *string, const int8_t index, uint8_t *itemString/*=nullptr*/) { wchar_t wchar; while (*string) { @@ -127,7 +127,7 @@ void DWIN_String::add(wchar_t character) { if (str[1]) add_character(str[1]); } -void DWIN_String::add_character(uint8_t character) { +void DWIN_String::add_character(const uint8_t character) { if (len < MAX_STRING_LENGTH) { data[len] = character; len++; @@ -135,7 +135,7 @@ void DWIN_String::add_character(uint8_t character) { } } -void DWIN_String::rtrim(uint8_t character) { +void DWIN_String::rtrim(const uint8_t character) { while (len) { if (data[len - 1] == 0x20 || data[len - 1] == character) { len--; @@ -147,7 +147,7 @@ void DWIN_String::rtrim(uint8_t character) { } } -void DWIN_String::ltrim(uint8_t character) { +void DWIN_String::ltrim(const uint8_t character) { uint16_t i, j; for (i = 0; (i < len) && (data[i] == 0x20 || data[i] == character); i++) { //span -= glyph(data[i])->DWidth; @@ -158,7 +158,7 @@ void DWIN_String::ltrim(uint8_t character) { eol(); } -void DWIN_String::trim(uint8_t character) { +void DWIN_String::trim(const uint8_t character) { rtrim(character); ltrim(character); } diff --git a/Marlin/src/lcd/e3v2/marlinui/dwin_string.h b/Marlin/src/lcd/e3v2/marlinui/dwin_string.h index d78d774095..08566407b7 100644 --- a/Marlin/src/lcd/e3v2/marlinui/dwin_string.h +++ b/Marlin/src/lcd/e3v2/marlinui/dwin_string.h @@ -46,7 +46,7 @@ class DWIN_String { static uint16_t span; // in pixels static uint8_t len; // in characters - static void add_character(uint8_t character); + static void add_character(const uint8_t character); static void eol() { data[len] = 0x00; } public: @@ -62,7 +62,7 @@ class DWIN_String { //static void add(uint8_t character) { add_character(character); eol(); } static void add(wchar_t character); static void add(uint8_t *string, uint8_t max_len=MAX_STRING_LENGTH); - static void add(uint8_t *string, int8_t index, uint8_t *itemString=nullptr); + static void add(uint8_t *string, const int8_t index, uint8_t *itemString=nullptr); static void set(uint8_t *string) { set(); add(string); } static void set(wchar_t character) { set(); add(character); } static void set(uint8_t *string, int8_t index, const char *itemString=nullptr) { set(); add(string, index, (uint8_t *)itemString); } @@ -71,20 +71,20 @@ class DWIN_String { static inline void set(const char *string, int8_t index, const char *itemString=nullptr) { set((uint8_t *)string, index, itemString); } static inline void add(const char *string) { add((uint8_t *)string); } - static void trim(uint8_t character=0x20); - static void rtrim(uint8_t character=0x20); - static void ltrim(uint8_t character=0x20); + static void trim(const uint8_t character=0x20); + static void rtrim(const uint8_t character=0x20); + static void ltrim(const uint8_t character=0x20); static void truncate(uint8_t maxlen) { if (len > maxlen) { len = maxlen; eol(); } } - static uint8_t length() { return len; } - static uint16_t width() { return span; } - static uint8_t *string() { return data; } + static inline uint8_t length() { return len; } + static inline uint16_t width() { return span; } + static inline uint8_t *string() { return data; } static uint16_t center(uint16_t width) { return span > width ? 0 : (width - span) / 2; } }; int dwin_charmap_compare(dwin_charmap_t *v1, dwin_charmap_t *v2); -int pf_bsearch_cb_comp_dwinmap_pgm(void *userdata, size_t idx, void * data_pin); +int pf_bsearch_cb_comp_dwinmap_pgm(void *userdata, size_t idx, void *data_pin); extern DWIN_String dwin_string; @@ -664,7 +664,7 @@ const dwin_charmap_t g_dwin_charmap_device[] PROGMEM = { #endif }; -// the plain ASCII replacement for various char +// ASCII replacement for various characters const dwin_charmap_t g_dwin_charmap_common[] PROGMEM = { {IV('¡'), 'i', 0}, // A1 {IV('¢'), 'c', 0}, // A2 diff --git a/Marlin/src/lcd/e3v2/marlinui/lcdprint_dwin.cpp b/Marlin/src/lcd/e3v2/marlinui/lcdprint_dwin.cpp index 20b3727dbc..069272f6c1 100644 --- a/Marlin/src/lcd/e3v2/marlinui/lcdprint_dwin.cpp +++ b/Marlin/src/lcd/e3v2/marlinui/lcdprint_dwin.cpp @@ -46,11 +46,10 @@ extern dwin_font_t dwin_font; void lcd_moveto_xy(const lcd_uint_t x, const lcd_uint_t y) { cursor.x = x; cursor.y = y; } void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) { - cursor.x = col * dwin_font.width; - cursor.y = (row * (dwin_font.height + EXTRA_ROW_HEIGHT)) + (EXTRA_ROW_HEIGHT / 2); + lcd_moveto_xy(col * dwin_font.width, row * (dwin_font.height + EXTRA_ROW_HEIGHT) + EXTRA_ROW_HEIGHT / 2); } -inline void lcd_advance_cursor() { cursor.x += dwin_font.width; } +inline void lcd_advance_cursor(const uint8_t len=1) { cursor.x += len * dwin_font.width; } void lcd_put_int(const int i) { // TODO: Draw an int at the cursor position, advance the cursor @@ -58,19 +57,18 @@ void lcd_put_int(const int i) { int lcd_put_dwin_string() { DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, (char*)dwin_string.string()); - cursor.x += dwin_string.length() * dwin_font.width; + lcd_advance_cursor(dwin_string.length()); return dwin_string.length(); } // return < 0 on error // return the advanced cols int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) { - dwin_string.set(); - dwin_string.add(c); + dwin_string.set(c); dwin_string.truncate(max_length); // Draw the char(s) at the cursor and advance the cursor DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, (char*)dwin_string.string()); - cursor.x += dwin_string.length() * dwin_font.width; + lcd_advance_cursor(dwin_string.length()); return dwin_string.length(); } @@ -95,7 +93,7 @@ static int lcd_put_u8str_max_cb(const char * utf8_str, uint8_t (*cb_read_byte)(u dwin_string.add(ch); } DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, (char*)dwin_string.string()); - cursor.x += dwin_string.length() * dwin_font.width; + lcd_advance_cursor(dwin_string.length()); return dwin_string.length(); } @@ -112,7 +110,7 @@ lcd_uint_t lcd_put_u8str_ind_P(PGM_P const pstr, const int8_t ind, PGM_P const i dwin_string.add((uint8_t*)pstr, ind, (uint8_t*)inStr); dwin_string.truncate(maxlen); DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, (char*)dwin_string.string()); - cursor.x += dwin_string.length() * dwin_font.width; + lcd_advance_cursor(dwin_string.length()); return dwin_string.length(); }