|
@@ -204,6 +204,55 @@ bool probe_deployed = false;
|
204
|
204
|
|
205
|
205
|
CrealityDWINClass CrealityDWIN;
|
206
|
206
|
|
|
207
|
+template <unsigned N, unsigned S = N>
|
|
208
|
+class TextScroller {
|
|
209
|
+public:
|
|
210
|
+ static const unsigned SIZE = N;
|
|
211
|
+ static const unsigned SPACE = S;
|
|
212
|
+ typedef char Buffer[SIZE + 1];
|
|
213
|
+
|
|
214
|
+ inline TextScroller()
|
|
215
|
+ : scrollpos(0)
|
|
216
|
+ { }
|
|
217
|
+
|
|
218
|
+ inline void reset() {
|
|
219
|
+ scrollpos = 0;
|
|
220
|
+ }
|
|
221
|
+
|
|
222
|
+ const char* scroll(size_t& pos, Buffer &buf, const char * text, bool *updated = nullptr) {
|
|
223
|
+ const size_t len = strlen(text);
|
|
224
|
+ if (len > SIZE) {
|
|
225
|
+ if (updated) *updated = true;
|
|
226
|
+ if (scrollpos >= len + SPACE) scrollpos = 0;
|
|
227
|
+ pos = 0;
|
|
228
|
+ if (scrollpos < len) {
|
|
229
|
+ const size_t n = min(len - scrollpos, SIZE);
|
|
230
|
+ memcpy(buf, text + scrollpos, n);
|
|
231
|
+ pos += n;
|
|
232
|
+ }
|
|
233
|
+ if (pos < SIZE) {
|
|
234
|
+ const size_t n = min(len + SPACE - scrollpos, SIZE - pos);
|
|
235
|
+ memset(buf + pos, ' ', n);
|
|
236
|
+ pos += n;
|
|
237
|
+ }
|
|
238
|
+ if (pos < SIZE) {
|
|
239
|
+ const size_t n = SIZE - pos;
|
|
240
|
+ memcpy(buf + pos, text, n);
|
|
241
|
+ pos += n;
|
|
242
|
+ }
|
|
243
|
+ buf[pos] = '\0';
|
|
244
|
+ ++scrollpos;
|
|
245
|
+ return buf;
|
|
246
|
+ } else {
|
|
247
|
+ pos = len;
|
|
248
|
+ return text;
|
|
249
|
+ }
|
|
250
|
+ }
|
|
251
|
+
|
|
252
|
+private:
|
|
253
|
+ uint16_t scrollpos;
|
|
254
|
+};
|
|
255
|
+
|
207
|
256
|
#if HAS_MESH
|
208
|
257
|
|
209
|
258
|
struct Mesh_Settings {
|
|
@@ -689,31 +738,13 @@ void CrealityDWINClass::Draw_Print_Screen() {
|
689
|
738
|
}
|
690
|
739
|
|
691
|
740
|
void CrealityDWINClass::Draw_Print_Filename(const bool reset/*=false*/) {
|
692
|
|
- static uint8_t namescrl = 0;
|
693
|
|
- if (reset) namescrl = 0;
|
|
741
|
+ typedef TextScroller<30> Scroller;
|
|
742
|
+ static Scroller scroller;
|
|
743
|
+ if (reset) scroller.reset();
|
694
|
744
|
if (process == Print) {
|
695
|
|
- constexpr int8_t maxlen = 30;
|
696
|
|
- char *outstr = filename;
|
697
|
|
- size_t slen = strlen(filename);
|
698
|
|
- int8_t outlen = slen;
|
699
|
|
- if (slen > maxlen) {
|
700
|
|
- char dispname[maxlen + 1];
|
701
|
|
- int8_t pos = slen - namescrl, len = maxlen;
|
702
|
|
- if (pos >= 0) {
|
703
|
|
- NOMORE(len, pos);
|
704
|
|
- LOOP_L_N(i, len) dispname[i] = filename[i + namescrl];
|
705
|
|
- }
|
706
|
|
- else {
|
707
|
|
- const int8_t mp = maxlen + pos;
|
708
|
|
- LOOP_L_N(i, mp) dispname[i] = ' ';
|
709
|
|
- LOOP_S_L_N(i, mp, maxlen) dispname[i] = filename[i - mp];
|
710
|
|
- if (mp <= 0) namescrl = 0;
|
711
|
|
- }
|
712
|
|
- dispname[len] = '\0';
|
713
|
|
- outstr = dispname;
|
714
|
|
- outlen = maxlen;
|
715
|
|
- namescrl++;
|
716
|
|
- }
|
|
745
|
+ Scroller::Buffer buf;
|
|
746
|
+ size_t outlen = 0;
|
|
747
|
+ const char* outstr = scroller.scroll(outlen, buf, filename);
|
717
|
748
|
DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 50, DWIN_WIDTH - 8, 80);
|
718
|
749
|
const int8_t npos = (DWIN_WIDTH - outlen * MENU_CHR_W) / 2;
|
719
|
750
|
DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, npos, 60, outstr);
|
|
@@ -973,57 +1004,30 @@ void CrealityDWINClass::Popup_Select() {
|
973
|
1004
|
}
|
974
|
1005
|
|
975
|
1006
|
void CrealityDWINClass::Update_Status_Bar(bool refresh/*=false*/) {
|
|
1007
|
+ typedef TextScroller<30> Scroller;
|
976
|
1008
|
static bool new_msg;
|
977
|
|
- static uint8_t msgscrl = 0;
|
|
1009
|
+ static Scroller scroller;
|
978
|
1010
|
static char lastmsg[64];
|
979
|
1011
|
if (strcmp(lastmsg, statusmsg) != 0 || refresh) {
|
980
|
1012
|
strcpy(lastmsg, statusmsg);
|
981
|
|
- msgscrl = 0;
|
|
1013
|
+ scroller.reset();
|
982
|
1014
|
new_msg = true;
|
983
|
1015
|
}
|
984
|
|
- size_t len = strlen(statusmsg);
|
985
|
|
- int8_t pos = len;
|
986
|
|
- if (pos > 30) {
|
987
|
|
- pos -= msgscrl;
|
988
|
|
- len = pos;
|
989
|
|
- if (len > 30)
|
990
|
|
- len = 30;
|
991
|
|
- char dispmsg[len + 1];
|
992
|
|
- if (pos >= 0) {
|
993
|
|
- LOOP_L_N(i, len) dispmsg[i] = statusmsg[i + msgscrl];
|
994
|
|
- }
|
995
|
|
- else {
|
996
|
|
- LOOP_L_N(i, 30 + pos) dispmsg[i] = ' ';
|
997
|
|
- LOOP_S_L_N(i, 30 + pos, 30) dispmsg[i] = statusmsg[i - (30 + pos)];
|
998
|
|
- }
|
999
|
|
- dispmsg[len] = '\0';
|
|
1016
|
+ Scroller::Buffer buf;
|
|
1017
|
+ size_t len = 0;
|
|
1018
|
+ const char* dispmsg = scroller.scroll(len, buf, statusmsg, &new_msg);
|
|
1019
|
+ if (new_msg) {
|
|
1020
|
+ new_msg = false;
|
1000
|
1021
|
if (process == Print) {
|
1001
|
1022
|
DWIN_Draw_Rectangle(1, Color_Grey, 8, 214, DWIN_WIDTH - 8, 238);
|
1002
|
|
- const int8_t npos = (DWIN_WIDTH - 30 * MENU_CHR_W) / 2;
|
|
1023
|
+ const int8_t npos = (DWIN_WIDTH - len * MENU_CHR_W) / 2;
|
1003
|
1024
|
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 219, dispmsg);
|
1004
|
1025
|
}
|
1005
|
1026
|
else {
|
1006
|
1027
|
DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 352, DWIN_WIDTH - 8, 376);
|
1007
|
|
- const int8_t npos = (DWIN_WIDTH - 30 * MENU_CHR_W) / 2;
|
|
1028
|
+ const int8_t npos = (DWIN_WIDTH - len * MENU_CHR_W) / 2;
|
1008
|
1029
|
DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 357, dispmsg);
|
1009
|
1030
|
}
|
1010
|
|
- if (-pos >= 30) msgscrl = 0;
|
1011
|
|
- msgscrl++;
|
1012
|
|
- }
|
1013
|
|
- else {
|
1014
|
|
- if (new_msg) {
|
1015
|
|
- new_msg = false;
|
1016
|
|
- if (process == Print) {
|
1017
|
|
- DWIN_Draw_Rectangle(1, Color_Grey, 8, 214, DWIN_WIDTH - 8, 238);
|
1018
|
|
- const int8_t npos = (DWIN_WIDTH - strlen(statusmsg) * MENU_CHR_W) / 2;
|
1019
|
|
- DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 219, statusmsg);
|
1020
|
|
- }
|
1021
|
|
- else {
|
1022
|
|
- DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 352, DWIN_WIDTH - 8, 376);
|
1023
|
|
- const int8_t npos = (DWIN_WIDTH - strlen(statusmsg) * MENU_CHR_W) / 2;
|
1024
|
|
- DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 357, statusmsg);
|
1025
|
|
- }
|
1026
|
|
- }
|
1027
|
1031
|
}
|
1028
|
1032
|
}
|
1029
|
1033
|
|
|
@@ -4168,35 +4172,25 @@ void CrealityDWINClass::Option_Control() {
|
4168
|
4172
|
}
|
4169
|
4173
|
|
4170
|
4174
|
void CrealityDWINClass::File_Control() {
|
|
4175
|
+ typedef TextScroller<MENU_CHAR_LIMIT> Scroller;
|
|
4176
|
+ static Scroller scroller;
|
4171
|
4177
|
EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
|
4172
|
|
- static uint8_t filescrl = 0;
|
4173
|
4178
|
if (encoder_diffState == ENCODER_DIFF_NO) {
|
4174
|
4179
|
if (selection > 0) {
|
4175
|
4180
|
card.getfilename_sorted(SD_ORDER(selection - 1, card.get_num_Files()));
|
4176
|
4181
|
char * const filename = card.longest_filename();
|
4177
|
4182
|
size_t len = strlen(filename);
|
4178
|
|
- int8_t pos = len;
|
|
4183
|
+ size_t pos = len;
|
4179
|
4184
|
if (!card.flag.filenameIsDir)
|
4180
|
4185
|
while (pos && filename[pos] != '.') pos--;
|
4181
|
4186
|
if (pos > MENU_CHAR_LIMIT) {
|
4182
|
4187
|
static millis_t time = 0;
|
4183
|
4188
|
if (PENDING(millis(), time)) return;
|
4184
|
4189
|
time = millis() + 200;
|
4185
|
|
- pos -= filescrl;
|
4186
|
|
- len = _MIN(pos, MENU_CHAR_LIMIT);
|
4187
|
|
- char name[len + 1];
|
4188
|
|
- if (pos >= 0) {
|
4189
|
|
- LOOP_L_N(i, len) name[i] = filename[i + filescrl];
|
4190
|
|
- }
|
4191
|
|
- else {
|
4192
|
|
- LOOP_L_N(i, MENU_CHAR_LIMIT + pos) name[i] = ' ';
|
4193
|
|
- LOOP_S_L_N(i, MENU_CHAR_LIMIT + pos, MENU_CHAR_LIMIT) name[i] = filename[i - (MENU_CHAR_LIMIT + pos)];
|
4194
|
|
- }
|
4195
|
|
- name[len] = '\0';
|
|
4190
|
+ Scroller::Buffer buf;
|
|
4191
|
+ const char* const name = scroller.scroll(pos, buf, filename);
|
4196
|
4192
|
DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28);
|
4197
|
4193
|
Draw_Menu_Item(selection - scrollpos, card.flag.filenameIsDir ? ICON_More : ICON_File, name);
|
4198
|
|
- if (-pos >= MENU_CHAR_LIMIT) filescrl = 0;
|
4199
|
|
- filescrl++;
|
4200
|
4194
|
DWIN_UpdateLCD();
|
4201
|
4195
|
}
|
4202
|
4196
|
}
|
|
@@ -4208,7 +4202,7 @@ void CrealityDWINClass::File_Control() {
|
4208
|
4202
|
DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28);
|
4209
|
4203
|
Draw_SD_Item(selection, selection - scrollpos);
|
4210
|
4204
|
}
|
4211
|
|
- filescrl = 0;
|
|
4205
|
+ scroller.reset();
|
4212
|
4206
|
selection++; // Select Down
|
4213
|
4207
|
if (selection > scrollpos + MROWS) {
|
4214
|
4208
|
scrollpos++;
|
|
@@ -4221,7 +4215,7 @@ void CrealityDWINClass::File_Control() {
|
4221
|
4215
|
DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33);
|
4222
|
4216
|
DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28);
|
4223
|
4217
|
Draw_SD_Item(selection, selection - scrollpos);
|
4224
|
|
- filescrl = 0;
|
|
4218
|
+ scroller.reset();
|
4225
|
4219
|
selection--; // Select Up
|
4226
|
4220
|
if (selection < scrollpos) {
|
4227
|
4221
|
scrollpos--;
|