|
@ -204,6 +204,55 @@ bool probe_deployed = false; |
|
|
|
|
|
|
|
|
CrealityDWINClass CrealityDWIN; |
|
|
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 |
|
|
#if HAS_MESH |
|
|
|
|
|
|
|
|
struct Mesh_Settings { |
|
|
struct Mesh_Settings { |
|
@ -689,31 +738,13 @@ void CrealityDWINClass::Draw_Print_Screen() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void CrealityDWINClass::Draw_Print_Filename(const bool reset/*=false*/) { |
|
|
void CrealityDWINClass::Draw_Print_Filename(const bool reset/*=false*/) { |
|
|
static uint8_t namescrl = 0; |
|
|
typedef TextScroller<30> Scroller; |
|
|
if (reset) namescrl = 0; |
|
|
static Scroller scroller; |
|
|
|
|
|
if (reset) scroller.reset(); |
|
|
if (process == Print) { |
|
|
if (process == Print) { |
|
|
constexpr int8_t maxlen = 30; |
|
|
Scroller::Buffer buf; |
|
|
char *outstr = filename; |
|
|
size_t outlen = 0; |
|
|
size_t slen = strlen(filename); |
|
|
const char* outstr = scroller.scroll(outlen, buf, 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++; |
|
|
|
|
|
} |
|
|
|
|
|
DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 50, DWIN_WIDTH - 8, 80); |
|
|
DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 50, DWIN_WIDTH - 8, 80); |
|
|
const int8_t npos = (DWIN_WIDTH - outlen * MENU_CHR_W) / 2; |
|
|
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); |
|
|
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*/) { |
|
|
void CrealityDWINClass::Update_Status_Bar(bool refresh/*=false*/) { |
|
|
|
|
|
typedef TextScroller<30> Scroller; |
|
|
static bool new_msg; |
|
|
static bool new_msg; |
|
|
static uint8_t msgscrl = 0; |
|
|
static Scroller scroller; |
|
|
static char lastmsg[64]; |
|
|
static char lastmsg[64]; |
|
|
if (strcmp(lastmsg, statusmsg) != 0 || refresh) { |
|
|
if (strcmp(lastmsg, statusmsg) != 0 || refresh) { |
|
|
strcpy(lastmsg, statusmsg); |
|
|
strcpy(lastmsg, statusmsg); |
|
|
msgscrl = 0; |
|
|
scroller.reset(); |
|
|
new_msg = true; |
|
|
new_msg = true; |
|
|
} |
|
|
} |
|
|
size_t len = strlen(statusmsg); |
|
|
Scroller::Buffer buf; |
|
|
int8_t pos = len; |
|
|
size_t len = 0; |
|
|
if (pos > 30) { |
|
|
const char* dispmsg = scroller.scroll(len, buf, statusmsg, &new_msg); |
|
|
pos -= msgscrl; |
|
|
if (new_msg) { |
|
|
len = pos; |
|
|
new_msg = false; |
|
|
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'; |
|
|
|
|
|
if (process == Print) { |
|
|
if (process == Print) { |
|
|
DWIN_Draw_Rectangle(1, Color_Grey, 8, 214, DWIN_WIDTH - 8, 238); |
|
|
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); |
|
|
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 219, dispmsg); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 352, DWIN_WIDTH - 8, 376); |
|
|
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); |
|
|
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() { |
|
|
void CrealityDWINClass::File_Control() { |
|
|
|
|
|
typedef TextScroller<MENU_CHAR_LIMIT> Scroller; |
|
|
|
|
|
static Scroller scroller; |
|
|
EncoderState encoder_diffState = Encoder_ReceiveAnalyze(); |
|
|
EncoderState encoder_diffState = Encoder_ReceiveAnalyze(); |
|
|
static uint8_t filescrl = 0; |
|
|
|
|
|
if (encoder_diffState == ENCODER_DIFF_NO) { |
|
|
if (encoder_diffState == ENCODER_DIFF_NO) { |
|
|
if (selection > 0) { |
|
|
if (selection > 0) { |
|
|
card.getfilename_sorted(SD_ORDER(selection - 1, card.get_num_Files())); |
|
|
card.getfilename_sorted(SD_ORDER(selection - 1, card.get_num_Files())); |
|
|
char * const filename = card.longest_filename(); |
|
|
char * const filename = card.longest_filename(); |
|
|
size_t len = strlen(filename); |
|
|
size_t len = strlen(filename); |
|
|
int8_t pos = len; |
|
|
size_t pos = len; |
|
|
if (!card.flag.filenameIsDir) |
|
|
if (!card.flag.filenameIsDir) |
|
|
while (pos && filename[pos] != '.') pos--; |
|
|
while (pos && filename[pos] != '.') pos--; |
|
|
if (pos > MENU_CHAR_LIMIT) { |
|
|
if (pos > MENU_CHAR_LIMIT) { |
|
|
static millis_t time = 0; |
|
|
static millis_t time = 0; |
|
|
if (PENDING(millis(), time)) return; |
|
|
if (PENDING(millis(), time)) return; |
|
|
time = millis() + 200; |
|
|
time = millis() + 200; |
|
|
pos -= filescrl; |
|
|
Scroller::Buffer buf; |
|
|
len = _MIN(pos, MENU_CHAR_LIMIT); |
|
|
const char* const name = scroller.scroll(pos, buf, filename); |
|
|
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'; |
|
|
|
|
|
DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28); |
|
|
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); |
|
|
Draw_Menu_Item(selection - scrollpos, card.flag.filenameIsDir ? ICON_More : ICON_File, name); |
|
|
if (-pos >= MENU_CHAR_LIMIT) filescrl = 0; |
|
|
|
|
|
filescrl++; |
|
|
|
|
|
DWIN_UpdateLCD(); |
|
|
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); |
|
|
DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28); |
|
|
Draw_SD_Item(selection, selection - scrollpos); |
|
|
Draw_SD_Item(selection, selection - scrollpos); |
|
|
} |
|
|
} |
|
|
filescrl = 0; |
|
|
scroller.reset(); |
|
|
selection++; // Select Down
|
|
|
selection++; // Select Down
|
|
|
if (selection > scrollpos + MROWS) { |
|
|
if (selection > scrollpos + MROWS) { |
|
|
scrollpos++; |
|
|
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, 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); |
|
|
DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28); |
|
|
Draw_SD_Item(selection, selection - scrollpos); |
|
|
Draw_SD_Item(selection, selection - scrollpos); |
|
|
filescrl = 0; |
|
|
scroller.reset(); |
|
|
selection--; // Select Up
|
|
|
selection--; // Select Up
|
|
|
if (selection < scrollpos) { |
|
|
if (selection < scrollpos) { |
|
|
scrollpos--; |
|
|
scrollpos--; |
|
|