🐛 Fix JyersUI (#24652)

This commit is contained in:
Alexey Galakhov 2022-08-22 17:11:53 +02:00 committed by Scott Lahteine
parent 37a7da075f
commit d94a41527f
2 changed files with 79 additions and 81 deletions

View File

@ -234,7 +234,7 @@ void DWIN_Frame_AreaMove(uint8_t mode, uint8_t dir, uint16_t dis,
// *string: The string
// 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*/) {
#if DISABLED(DWIN_LCD_PROUI)
#if NONE(DWIN_LCD_PROUI, DWIN_CREALITY_LCD_JYERSUI)
DWIN_Draw_Rectangle(1, bColor, x, y, x + (fontWidth(size) * strlen_P(string)), y + fontHeight(size));
#endif
constexpr uint8_t widthAdjust = 0;
@ -266,7 +266,9 @@ void DWIN_Draw_String(bool bShow, uint8_t size, uint16_t color, uint16_t bColor,
void DWIN_Draw_IntValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
uint16_t bColor, uint8_t iNum, uint16_t x, uint16_t y, uint32_t value) {
size_t i = 0;
DWIN_Draw_Rectangle(1, bColor, x, y, x + fontWidth(size) * iNum + 1, y + fontHeight(size));
#if DISABLED(DWIN_CREALITY_LCD_JYERSUI)
DWIN_Draw_Rectangle(1, bColor, x, y, x + fontWidth(size) * iNum + 1, y + fontHeight(size));
#endif
DWIN_Byte(i, 0x14);
// Bit 7: bshow
// Bit 6: 1 = signed; 0 = unsigned number;
@ -314,7 +316,9 @@ void DWIN_Draw_FloatValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_
uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, int32_t value) {
//uint8_t *fvalue = (uint8_t*)&value;
size_t i = 0;
DWIN_Draw_Rectangle(1, bColor, x, y, x + fontWidth(size) * (iNum+fNum+1), y + fontHeight(size));
#if DISABLED(DWIN_CREALITY_LCD_JYERSUI)
DWIN_Draw_Rectangle(1, bColor, x, y, x + fontWidth(size) * (iNum+fNum+1), y + fontHeight(size));
#endif
DWIN_Byte(i, 0x14);
DWIN_Byte(i, (bShow * 0x80) | (zeroFill * 0x20) | (zeroMode * 0x10) | size);
DWIN_Word(i, color);

View File

@ -204,6 +204,55 @@ bool probe_deployed = false;
CrealityDWINClass CrealityDWIN;
template <unsigned N, unsigned S = N>
class TextScroller {
public:
static const unsigned SIZE = N;
static const unsigned SPACE = S;
typedef char Buffer[SIZE + 1];
inline TextScroller()
: scrollpos(0)
{ }
inline void reset() {
scrollpos = 0;
}
const char* scroll(size_t& pos, Buffer &buf, const char * text, bool *updated = nullptr) {
const size_t len = strlen(text);
if (len > SIZE) {
if (updated) *updated = true;
if (scrollpos >= len + SPACE) scrollpos = 0;
pos = 0;
if (scrollpos < len) {
const size_t n = min(len - scrollpos, SIZE);
memcpy(buf, text + scrollpos, n);
pos += n;
}
if (pos < SIZE) {
const size_t n = min(len + SPACE - scrollpos, SIZE - pos);
memset(buf + pos, ' ', n);
pos += n;
}
if (pos < SIZE) {
const size_t n = SIZE - pos;
memcpy(buf + pos, text, n);
pos += n;
}
buf[pos] = '\0';
++scrollpos;
return buf;
} else {
pos = len;
return text;
}
}
private:
uint16_t scrollpos;
};
#if HAS_MESH
struct Mesh_Settings {
@ -689,31 +738,13 @@ void CrealityDWINClass::Draw_Print_Screen() {
}
void CrealityDWINClass::Draw_Print_Filename(const bool reset/*=false*/) {
static uint8_t namescrl = 0;
if (reset) namescrl = 0;
typedef TextScroller<30> Scroller;
static Scroller scroller;
if (reset) scroller.reset();
if (process == Print) {
constexpr int8_t maxlen = 30;
char *outstr = filename;
size_t slen = strlen(filename);
int8_t outlen = slen;
if (slen > maxlen) {
char dispname[maxlen + 1];
int8_t pos = slen - namescrl, len = maxlen;
if (pos >= 0) {
NOMORE(len, pos);
LOOP_L_N(i, len) dispname[i] = filename[i + namescrl];
}
else {
const int8_t mp = maxlen + pos;
LOOP_L_N(i, mp) dispname[i] = ' ';
LOOP_S_L_N(i, mp, maxlen) dispname[i] = filename[i - mp];
if (mp <= 0) namescrl = 0;
}
dispname[len] = '\0';
outstr = dispname;
outlen = maxlen;
namescrl++;
}
Scroller::Buffer buf;
size_t outlen = 0;
const char* outstr = scroller.scroll(outlen, buf, filename);
DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 50, DWIN_WIDTH - 8, 80);
const int8_t npos = (DWIN_WIDTH - outlen * MENU_CHR_W) / 2;
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, npos, 60, outstr);
@ -973,57 +1004,30 @@ void CrealityDWINClass::Popup_Select() {
}
void CrealityDWINClass::Update_Status_Bar(bool refresh/*=false*/) {
typedef TextScroller<30> Scroller;
static bool new_msg;
static uint8_t msgscrl = 0;
static Scroller scroller;
static char lastmsg[64];
if (strcmp(lastmsg, statusmsg) != 0 || refresh) {
strcpy(lastmsg, statusmsg);
msgscrl = 0;
scroller.reset();
new_msg = true;
}
size_t len = strlen(statusmsg);
int8_t pos = len;
if (pos > 30) {
pos -= msgscrl;
len = pos;
if (len > 30)
len = 30;
char dispmsg[len + 1];
if (pos >= 0) {
LOOP_L_N(i, len) dispmsg[i] = statusmsg[i + msgscrl];
}
else {
LOOP_L_N(i, 30 + pos) dispmsg[i] = ' ';
LOOP_S_L_N(i, 30 + pos, 30) dispmsg[i] = statusmsg[i - (30 + pos)];
}
dispmsg[len] = '\0';
Scroller::Buffer buf;
size_t len = 0;
const char* dispmsg = scroller.scroll(len, buf, statusmsg, &new_msg);
if (new_msg) {
new_msg = false;
if (process == Print) {
DWIN_Draw_Rectangle(1, Color_Grey, 8, 214, DWIN_WIDTH - 8, 238);
const int8_t npos = (DWIN_WIDTH - 30 * MENU_CHR_W) / 2;
const int8_t npos = (DWIN_WIDTH - len * MENU_CHR_W) / 2;
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 219, dispmsg);
}
else {
DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 352, DWIN_WIDTH - 8, 376);
const int8_t npos = (DWIN_WIDTH - 30 * MENU_CHR_W) / 2;
const int8_t npos = (DWIN_WIDTH - len * MENU_CHR_W) / 2;
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 357, dispmsg);
}
if (-pos >= 30) msgscrl = 0;
msgscrl++;
}
else {
if (new_msg) {
new_msg = false;
if (process == Print) {
DWIN_Draw_Rectangle(1, Color_Grey, 8, 214, DWIN_WIDTH - 8, 238);
const int8_t npos = (DWIN_WIDTH - strlen(statusmsg) * MENU_CHR_W) / 2;
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 219, statusmsg);
}
else {
DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 352, DWIN_WIDTH - 8, 376);
const int8_t npos = (DWIN_WIDTH - strlen(statusmsg) * MENU_CHR_W) / 2;
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 357, statusmsg);
}
}
}
}
@ -4168,35 +4172,25 @@ void CrealityDWINClass::Option_Control() {
}
void CrealityDWINClass::File_Control() {
typedef TextScroller<MENU_CHAR_LIMIT> Scroller;
static Scroller scroller;
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
static uint8_t filescrl = 0;
if (encoder_diffState == ENCODER_DIFF_NO) {
if (selection > 0) {
card.getfilename_sorted(SD_ORDER(selection - 1, card.get_num_Files()));
char * const filename = card.longest_filename();
size_t len = strlen(filename);
int8_t pos = len;
size_t pos = len;
if (!card.flag.filenameIsDir)
while (pos && filename[pos] != '.') pos--;
if (pos > MENU_CHAR_LIMIT) {
static millis_t time = 0;
if (PENDING(millis(), time)) return;
time = millis() + 200;
pos -= filescrl;
len = _MIN(pos, MENU_CHAR_LIMIT);
char name[len + 1];
if (pos >= 0) {
LOOP_L_N(i, len) name[i] = filename[i + filescrl];
}
else {
LOOP_L_N(i, MENU_CHAR_LIMIT + pos) name[i] = ' ';
LOOP_S_L_N(i, MENU_CHAR_LIMIT + pos, MENU_CHAR_LIMIT) name[i] = filename[i - (MENU_CHAR_LIMIT + pos)];
}
name[len] = '\0';
Scroller::Buffer buf;
const char* const name = scroller.scroll(pos, buf, filename);
DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28);
Draw_Menu_Item(selection - scrollpos, card.flag.filenameIsDir ? ICON_More : ICON_File, name);
if (-pos >= MENU_CHAR_LIMIT) filescrl = 0;
filescrl++;
DWIN_UpdateLCD();
}
}
@ -4208,7 +4202,7 @@ void CrealityDWINClass::File_Control() {
DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28);
Draw_SD_Item(selection, selection - scrollpos);
}
filescrl = 0;
scroller.reset();
selection++; // Select Down
if (selection > scrollpos + MROWS) {
scrollpos++;
@ -4221,7 +4215,7 @@ void CrealityDWINClass::File_Control() {
DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33);
DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28);
Draw_SD_Item(selection, selection - scrollpos);
filescrl = 0;
scroller.reset();
selection--; // Select Up
if (selection < scrollpos) {
scrollpos--;