Skip to content

Commit

Permalink
🐛 Fix JyersUI (#24652)
Browse files Browse the repository at this point in the history
  • Loading branch information
agalakhov authored Aug 22, 2022
1 parent d770272 commit 20c7284
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 81 deletions.
10 changes: 7 additions & 3 deletions Marlin/src/lcd/e3v2/common/dwin_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
150 changes: 72 additions & 78 deletions Marlin/src/lcd/e3v2/jyersui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
}
}

Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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++;
Expand All @@ -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--;
Expand Down

0 comments on commit 20c7284

Please sign in to comment.