Browse Source

🎨 MarlinUI for E3V2 tweaks

vanilla_fb_2.0.x
Scott Lahteine 3 years ago
parent
commit
03344a0947
  1. 10
      Marlin/src/lcd/e3v2/creality/dwin.cpp
  2. 1
      Marlin/src/lcd/e3v2/marlinui/dwin_lcd.h
  3. 10
      Marlin/src/lcd/e3v2/marlinui/dwin_string.cpp
  4. 18
      Marlin/src/lcd/e3v2/marlinui/dwin_string.h
  5. 16
      Marlin/src/lcd/e3v2/marlinui/lcdprint_dwin.cpp

10
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) { 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, value < 0 ? F("-") : F(" "));
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 < 0 ? -value : value);
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);
}
} }
void Draw_Edit_Integer3(const uint8_t row, const uint16_t value, const bool active=false) { void Draw_Edit_Integer3(const uint8_t row, const uint16_t value, const bool active=false) {

1
Marlin/src/lcd/e3v2/marlinui/dwin_lcd.h

@ -67,7 +67,6 @@
#define DWIN_FONT_MENU font10x20 #define DWIN_FONT_MENU font10x20
#define DWIN_FONT_STAT font14x28 #define DWIN_FONT_STAT font14x28
#define DWIN_FONT_HEAD font10x20
#define DWIN_FONT_ALERT font14x28 #define DWIN_FONT_ALERT font14x28
// Color // Color

10
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 '1'....'11' for indexes 0 - 10
* * displays 'E1'...'E11' for indexes 0 - 10 (By default. Uses LCD_FIRST_TOOL) * * 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; wchar_t wchar;
while (*string) { while (*string) {
@ -127,7 +127,7 @@ void DWIN_String::add(wchar_t character) {
if (str[1]) add_character(str[1]); 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) { if (len < MAX_STRING_LENGTH) {
data[len] = character; data[len] = character;
len++; 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) { while (len) {
if (data[len - 1] == 0x20 || data[len - 1] == character) { if (data[len - 1] == 0x20 || data[len - 1] == character) {
len--; 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; uint16_t i, j;
for (i = 0; (i < len) && (data[i] == 0x20 || data[i] == character); i++) { for (i = 0; (i < len) && (data[i] == 0x20 || data[i] == character); i++) {
//span -= glyph(data[i])->DWidth; //span -= glyph(data[i])->DWidth;
@ -158,7 +158,7 @@ void DWIN_String::ltrim(uint8_t character) {
eol(); eol();
} }
void DWIN_String::trim(uint8_t character) { void DWIN_String::trim(const uint8_t character) {
rtrim(character); rtrim(character);
ltrim(character); ltrim(character);
} }

18
Marlin/src/lcd/e3v2/marlinui/dwin_string.h

@ -46,7 +46,7 @@ class DWIN_String {
static uint16_t span; // in pixels static uint16_t span; // in pixels
static uint8_t len; // in characters 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; } static void eol() { data[len] = 0x00; }
public: public:
@ -62,7 +62,7 @@ class DWIN_String {
//static void add(uint8_t character) { add_character(character); eol(); } //static void add(uint8_t character) { add_character(character); eol(); }
static void add(wchar_t character); 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, 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(uint8_t *string) { set(); add(string); }
static void set(wchar_t character) { set(); add(character); } 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); } static void set(uint8_t *string, int8_t index, const char *itemString=nullptr) { set(); add(string, index, (uint8_t *)itemString); }
@ -71,15 +71,15 @@ 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 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 inline void add(const char *string) { add((uint8_t *)string); }
static void trim(uint8_t character=0x20); static void trim(const uint8_t character=0x20);
static void rtrim(uint8_t character=0x20); static void rtrim(const uint8_t character=0x20);
static void ltrim(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 void truncate(uint8_t maxlen) { if (len > maxlen) { len = maxlen; eol(); } }
static uint8_t length() { return len; } static inline uint8_t length() { return len; }
static uint16_t width() { return span; } static inline uint16_t width() { return span; }
static uint8_t *string() { return data; } static inline uint8_t *string() { return data; }
static uint16_t center(uint16_t width) { return span > width ? 0 : (width - span) / 2; } static uint16_t center(uint16_t width) { return span > width ? 0 : (width - span) / 2; }
}; };
@ -664,7 +664,7 @@ const dwin_charmap_t g_dwin_charmap_device[] PROGMEM = {
#endif #endif
}; };
// the plain ASCII replacement for various char // ASCII replacement for various characters
const dwin_charmap_t g_dwin_charmap_common[] PROGMEM = { const dwin_charmap_t g_dwin_charmap_common[] PROGMEM = {
{IV('¡'), 'i', 0}, // A1 {IV('¡'), 'i', 0}, // A1
{IV('¢'), 'c', 0}, // A2 {IV('¢'), 'c', 0}, // A2

16
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_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) { void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) {
cursor.x = col * dwin_font.width; lcd_moveto_xy(col * dwin_font.width, row * (dwin_font.height + EXTRA_ROW_HEIGHT) + EXTRA_ROW_HEIGHT / 2);
cursor.y = (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) { void lcd_put_int(const int i) {
// TODO: Draw an int at the cursor position, advance the cursor // 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() { 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()); 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 dwin_string.length();
} }
// return < 0 on error // return < 0 on error
// return the advanced cols // return the advanced cols
int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) { int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) {
dwin_string.set(); dwin_string.set(c);
dwin_string.add(c);
dwin_string.truncate(max_length); dwin_string.truncate(max_length);
// Draw the char(s) at the cursor and advance the cursor // 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()); 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 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_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()); 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 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.add((uint8_t*)pstr, ind, (uint8_t*)inStr);
dwin_string.truncate(maxlen); 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()); 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 dwin_string.length();
} }

Loading…
Cancel
Save