🩹 Fix and clean up E3V2 draw (#23979, #24013)

This commit is contained in:
InsanityAutomation 2022-04-09 20:19:14 -04:00 committed by Scott Lahteine
parent 4fd7d1b056
commit 7f1c5ad7aa
3 changed files with 65 additions and 56 deletions

View file

@ -235,7 +235,6 @@ void DWIN_Frame_AreaMove(uint8_t mode, uint8_t dir, uint16_t dis,
// rlimit: To limit the drawn string length // rlimit: To limit the drawn string length
void DWIN_Draw_String(bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, const char * const string, uint16_t rlimit/*=0xFFFF*/) { void DWIN_Draw_String(bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, const char * const string, uint16_t rlimit/*=0xFFFF*/) {
DWIN_Draw_Rectangle(1, bColor, x, y, x + (fontWidth(size) * strlen_P(string)), y + fontHeight(size)); DWIN_Draw_Rectangle(1, bColor, x, y, x + (fontWidth(size) * strlen_P(string)), y + fontHeight(size));
DWIN_UpdateLCD();
constexpr uint8_t widthAdjust = 0; constexpr uint8_t widthAdjust = 0;
size_t i = 0; size_t i = 0;
DWIN_Byte(i, 0x11); DWIN_Byte(i, 0x11);
@ -250,7 +249,6 @@ void DWIN_Draw_String(bool bShow, uint8_t size, uint16_t color, uint16_t bColor,
DWIN_Word(i, y); DWIN_Word(i, y);
DWIN_Text(i, string, rlimit); DWIN_Text(i, string, rlimit);
DWIN_Send(i); DWIN_Send(i);
DWIN_UpdateLCD();
} }
// Draw a positive integer // Draw a positive integer
@ -297,7 +295,6 @@ void DWIN_Draw_IntValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t
#endif #endif
DWIN_Send(i); DWIN_Send(i);
DWIN_UpdateLCD();
} }
// Draw a floating point number // Draw a floating point number
@ -332,7 +329,6 @@ void DWIN_Draw_FloatValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_
DWIN_Byte(i, fvalue[0]); DWIN_Byte(i, fvalue[0]);
*/ */
DWIN_Send(i); DWIN_Send(i);
DWIN_UpdateLCD();
} }
// Draw a floating point number // Draw a floating point number

View file

@ -181,7 +181,6 @@ void MarlinUI::draw_status_message(const bool blink) {
dwin_font.solid = true; dwin_font.solid = true;
dwin_font.fg = Color_White; dwin_font.fg = Color_White;
dwin_font.bg = Color_Bg_Black; dwin_font.bg = Color_Bg_Black;
DWIN_Draw_Box(1, Color_Bg_Black, 0, (LCD_PIXEL_HEIGHT - (STAT_FONT_HEIGHT) - 1), 272, STAT_FONT_HEIGHT + 1);
lcd_moveto_xy(0, LCD_PIXEL_HEIGHT - (STAT_FONT_HEIGHT) - 1); lcd_moveto_xy(0, LCD_PIXEL_HEIGHT - (STAT_FONT_HEIGHT) - 1);
constexpr uint8_t max_status_chars = (LCD_PIXEL_WIDTH) / (STAT_FONT_WIDTH); constexpr uint8_t max_status_chars = (LCD_PIXEL_WIDTH) / (STAT_FONT_WIDTH);

View file

@ -193,11 +193,11 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater, const uint16_t x
#define HOTEND_STATS 3 #define HOTEND_STATS 3
#elif HOTENDS > 1 #elif HOTENDS > 1
#define HOTEND_STATS 2 #define HOTEND_STATS 2
#elif HAS_HOTEND #else
#define HOTEND_STATS 1 #define HOTEND_STATS 1
#endif #endif
static celsius_t old_temp[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, 500), static celsius_t old_temp[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, 500),
old_target[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, 500); old_target[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, 500);
static bool old_on[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, false); static bool old_on[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, false);
#endif #endif
@ -210,25 +210,27 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater, const uint16_t x
#endif #endif
#if HAS_HOTEND && HAS_HEATED_BED #if HAS_HOTEND && HAS_HEATED_BED
float tc, tt;
bool c_draw, t_draw, i_draw, ta;
const bool isBed = heater < 0; const bool isBed = heater < 0;
const float tc = isBed ? thermalManager.degBed() : thermalManager.degHotend(heater),
tt = isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater);
const bool ta = isBed ? thermalManager.isHeatingBed() : thermalManager.isHeatingHotend(heater);
bool c_draw = tc != (isBed ? old_bed_temp : old_temp[heater]),
t_draw = tt != (isBed ? old_bed_target : old_target[heater]),
i_draw = ta != (isBed ? old_bed_on : old_on[heater]);
if (isBed) { if (isBed) {
#if HAS_LEVELING tc = thermalManager.degBed();
if (!i_draw && planner.leveling_active != old_leveling_on) i_draw = true; tt = thermalManager.degTargetBed();
old_leveling_on = planner.leveling_active; ta = thermalManager.isHeatingBed();
#endif c_draw = tc != old_bed_temp;
t_draw = tt != old_bed_target;
i_draw = ta != old_bed_on;
old_bed_temp = tc; old_bed_temp = tc;
old_bed_target = tt; old_bed_target = tt;
old_bed_on = ta; old_bed_on = ta;
} }
else { else {
tc = thermalManager.degHotend(heater);
tt = thermalManager.degTargetHotend(heater);
ta = thermalManager.isHeatingHotend(heater);
c_draw = tc != old_temp[heater];
t_draw = tt != old_target[heater];
i_draw = ta != old_on[heater];
old_temp[heater] = tc; old_temp[heater] = tc;
old_target[heater] = tt; old_target[heater] = tt;
old_on[heater] = ta; old_on[heater] = ta;
@ -237,31 +239,41 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater, const uint16_t x
constexpr bool isBed = false; constexpr bool isBed = false;
const float tc = thermalManager.degHotend(heater), tt = thermalManager.degTargetHotend(heater); const float tc = thermalManager.degHotend(heater), tt = thermalManager.degTargetHotend(heater);
const uint8_t ta = thermalManager.isHeatingHotend(heater); const uint8_t ta = thermalManager.isHeatingHotend(heater);
const bool c_draw = tc != old_bed_temp, t_draw = tt != old_bed_target, i_draw = ta != old_bed_on; bool c_draw = tc != old_temp[heater], t_draw = tt != old_target[heater], i_draw = ta != old_on[heater];
old_temp[heater] = tc; old_target[heater] = tt; old_on[heater] = ta; old_temp[heater] = tc; old_target[heater] = tt; old_on[heater] = ta;
#elif HAS_HEATED_BED #elif HAS_HEATED_BED
constexpr bool isBed = true; constexpr bool isBed = true;
const float tc = thermalManager.degBed(), tt = thermalManager.degTargetBed(); const float tc = thermalManager.degBed(), tt = thermalManager.degTargetBed();
const uint8_t ta = thermalManager.isHeatingBed(); const uint8_t ta = thermalManager.isHeatingBed();
bool c_draw = tc != old_temp[heater], t_draw = tt != old_target[heater], i_draw = ta != old_on[heater]; bool c_draw = tc != old_bed_temp, t_draw = tt != old_bed_target, i_draw = ta != old_bed_on;
#if HAS_LEVELING
if (!idraw && planner.leveling_active != old_leveling_on) i_draw = true;
old_leveling_on = tl;
#endif
old_bed_temp = tc; old_bed_target = tt; old_bed_on = ta; old_bed_temp = tc; old_bed_target = tt; old_bed_on = ta;
#else
bool c_draw = false, t_draw = false, i_draw = false;
constexpr float tc = 0, tt = 0;
constexpr uint8_t ta = 0;
#endif #endif
#if HAS_HEATED_BED && HAS_LEVELING
if (isBed) {
i_draw |= (planner.leveling_active != old_leveling_on);
old_leveling_on = planner.leveling_active;
}
#endif
// Draw target temperature, if needed
if (!ui.did_first_redraw || t_draw) { if (!ui.did_first_redraw || t_draw) {
dwin_string.set(i16tostr3rj(tt + 0.5)); dwin_string.set(i16tostr3rj(tt + 0.5));
dwin_string.add(LCD_STR_DEGREE); dwin_string.add(LCD_STR_DEGREE);
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y, S(dwin_string.string())); DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y, S(dwin_string.string()));
} }
if (!ui.did_first_redraw || i_draw){ // Draw heater icon with on / off / leveled states
if (!ui.did_first_redraw || i_draw) {
const uint8_t ico = isBed ? (TERN0(HAS_LEVELING, planner.leveling_active) ? ICON_BedLevelOff : ICON_BedOff) : ICON_HotendOff; const uint8_t ico = isBed ? (TERN0(HAS_LEVELING, planner.leveling_active) ? ICON_BedLevelOff : ICON_BedOff) : ICON_HotendOff;
DWIN_ICON_Show(ICON, ico + ta, x, y + STATUS_CHR_HEIGHT + 2); DWIN_ICON_Show(ICON, ico + ta, x, y + STATUS_CHR_HEIGHT + 2);
} }
// Draw current temperature, if needed
if (!ui.did_first_redraw || c_draw) { if (!ui.did_first_redraw || c_draw) {
dwin_string.set(i16tostr3rj(tc + 0.5)); dwin_string.set(i16tostr3rj(tc + 0.5));
dwin_string.add(LCD_STR_DEGREE); dwin_string.add(LCD_STR_DEGREE);
@ -412,43 +424,45 @@ void MarlinUI::draw_status_screen() {
// //
// Progress Bar // Progress Bar
// //
constexpr int16_t pb_margin = 5, #if HAS_PRINT_PROGRESS
pb_left = pb_margin + TERN(DWIN_MARLINUI_PORTRAIT, 0, 90), constexpr int16_t pb_margin = 5,
pb_height = TERN(DWIN_MARLINUI_PORTRAIT, 60, 20), pb_left = pb_margin + TERN(DWIN_MARLINUI_PORTRAIT, 0, 90),
pb_right = LCD_PIXEL_WIDTH - pb_margin, pb_height = TERN(DWIN_MARLINUI_PORTRAIT, 60, 20),
pb_bottom = TERN(DWIN_MARLINUI_PORTRAIT, 410, 220), pb_right = LCD_PIXEL_WIDTH - pb_margin,
pb_top = pb_bottom - pb_height, pb_bottom = TERN(DWIN_MARLINUI_PORTRAIT, 410, 220),
pb_width = pb_right - pb_left; pb_top = pb_bottom - pb_height,
pb_width = pb_right - pb_left;
const progress_t progress = TERN(HAS_PRINT_PROGRESS_PERMYRIAD, get_progress_permyriad, get_progress_percent)(); const progress_t progress = TERN(HAS_PRINT_PROGRESS_PERMYRIAD, get_progress_permyriad, get_progress_percent)();
if (!ui.did_first_redraw) if (!ui.did_first_redraw)
DWIN_Draw_Rectangle(0, Select_Color, pb_left, pb_top, pb_right, pb_bottom); // Outline DWIN_Draw_Rectangle(0, Select_Color, pb_left, pb_top, pb_right, pb_bottom); // Outline
static uint16_t old_solid = 50; static uint16_t old_solid = 50;
const uint16_t pb_solid = (pb_width - 2) * (progress / (PROGRESS_SCALE)) * 0.01f; const uint16_t pb_solid = (pb_width - 2) * (progress / (PROGRESS_SCALE)) * 0.01f;
const bool p_draw = !ui.did_first_redraw || old_solid != pb_solid; const bool p_draw = !ui.did_first_redraw || old_solid != pb_solid;
if (p_draw) { if (p_draw) {
//if (pb_solid) //if (pb_solid)
DWIN_Draw_Rectangle(1, Select_Color, pb_left + 1, pb_top + 1, pb_left + pb_solid, pb_bottom - 1); // Fill the solid part DWIN_Draw_Rectangle(1, Select_Color, pb_left + 1, pb_top + 1, pb_left + pb_solid, pb_bottom - 1); // Fill the solid part
//if (pb_solid < old_solid) //if (pb_solid < old_solid)
DWIN_Draw_Rectangle(1, Color_Bg_Black, pb_left + 1 + pb_solid, pb_top + 1, pb_right - 1, pb_bottom - 1); // Erase the rest DWIN_Draw_Rectangle(1, Color_Bg_Black, pb_left + 1 + pb_solid, pb_top + 1, pb_right - 1, pb_bottom - 1); // Erase the rest
#if ENABLED(SHOW_SD_PERCENT) #if ENABLED(SHOW_SD_PERCENT)
dwin_string.set(TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(progress), ui8tostr3rj(progress / (PROGRESS_SCALE)))); dwin_string.set(TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(progress), ui8tostr3rj(progress / (PROGRESS_SCALE))));
dwin_string.add(PSTR("%")); dwin_string.add(PSTR("%"));
DWIN_Draw_String( DWIN_Draw_String(
false, font16x32, Percent_Color, Color_Bg_Black, false, font16x32, Percent_Color, Color_Bg_Black,
pb_left + (pb_width - dwin_string.length() * 16) / 2, pb_left + (pb_width - dwin_string.length() * 16) / 2,
pb_top + (pb_height - 32) / 2, pb_top + (pb_height - 32) / 2,
S(dwin_string.string()) S(dwin_string.string())
); );
#endif #endif
old_solid = pb_solid; old_solid = pb_solid;
} }
#endif // HAS_PRINT_PROGRESS
// //
// Status Message // Status Message