Alexey Galakhov 1 anno fa
parent
commit
20c72845a0
Nessun account collegato all'indirizzo email del committer

+ 7
- 3
Marlin/src/lcd/e3v2/common/dwin_api.cpp Vedi File

234
 //  *string: The string
234
 //  *string: The string
235
 //  rlimit: To limit the drawn string length
235
 //  rlimit: To limit the drawn string length
236
 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*/) {
236
 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*/) {
237
-  #if DISABLED(DWIN_LCD_PROUI)
237
+  #if NONE(DWIN_LCD_PROUI, DWIN_CREALITY_LCD_JYERSUI)
238
     DWIN_Draw_Rectangle(1, bColor, x, y, x + (fontWidth(size) * strlen_P(string)), y + fontHeight(size));
238
     DWIN_Draw_Rectangle(1, bColor, x, y, x + (fontWidth(size) * strlen_P(string)), y + fontHeight(size));
239
   #endif
239
   #endif
240
   constexpr uint8_t widthAdjust = 0;
240
   constexpr uint8_t widthAdjust = 0;
266
 void DWIN_Draw_IntValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
266
 void DWIN_Draw_IntValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
267
                           uint16_t bColor, uint8_t iNum, uint16_t x, uint16_t y, uint32_t value) {
267
                           uint16_t bColor, uint8_t iNum, uint16_t x, uint16_t y, uint32_t value) {
268
   size_t i = 0;
268
   size_t i = 0;
269
-  DWIN_Draw_Rectangle(1, bColor, x, y, x + fontWidth(size) * iNum + 1, y + fontHeight(size));
269
+  #if DISABLED(DWIN_CREALITY_LCD_JYERSUI)
270
+    DWIN_Draw_Rectangle(1, bColor, x, y, x + fontWidth(size) * iNum + 1, y + fontHeight(size));
271
+  #endif
270
   DWIN_Byte(i, 0x14);
272
   DWIN_Byte(i, 0x14);
271
   // Bit 7: bshow
273
   // Bit 7: bshow
272
   // Bit 6: 1 = signed; 0 = unsigned number;
274
   // Bit 6: 1 = signed; 0 = unsigned number;
314
                           uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, int32_t value) {
316
                           uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, int32_t value) {
315
   //uint8_t *fvalue = (uint8_t*)&value;
317
   //uint8_t *fvalue = (uint8_t*)&value;
316
   size_t i = 0;
318
   size_t i = 0;
317
-  DWIN_Draw_Rectangle(1, bColor, x, y, x + fontWidth(size) * (iNum+fNum+1), y + fontHeight(size));
319
+  #if DISABLED(DWIN_CREALITY_LCD_JYERSUI)
320
+    DWIN_Draw_Rectangle(1, bColor, x, y, x + fontWidth(size) * (iNum+fNum+1), y + fontHeight(size));
321
+  #endif
318
   DWIN_Byte(i, 0x14);
322
   DWIN_Byte(i, 0x14);
319
   DWIN_Byte(i, (bShow * 0x80) | (zeroFill * 0x20) | (zeroMode * 0x10) | size);
323
   DWIN_Byte(i, (bShow * 0x80) | (zeroFill * 0x20) | (zeroMode * 0x10) | size);
320
   DWIN_Word(i, color);
324
   DWIN_Word(i, color);

+ 72
- 78
Marlin/src/lcd/e3v2/jyersui/dwin.cpp Vedi File

204
 
204
 
205
 CrealityDWINClass CrealityDWIN;
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
 #if HAS_MESH
256
 #if HAS_MESH
208
 
257
 
209
   struct Mesh_Settings {
258
   struct Mesh_Settings {
689
 }
738
 }
690
 
739
 
691
 void CrealityDWINClass::Draw_Print_Filename(const bool reset/*=false*/) {
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
   if (process == Print) {
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
     DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 50, DWIN_WIDTH - 8, 80);
748
     DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 50, DWIN_WIDTH - 8, 80);
718
     const int8_t npos = (DWIN_WIDTH - outlen * MENU_CHR_W) / 2;
749
     const int8_t npos = (DWIN_WIDTH - outlen * MENU_CHR_W) / 2;
719
     DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, npos, 60, outstr);
750
     DWIN_Draw_String(false, DWIN_FONT_MENU, Color_White, Color_Bg_Black, npos, 60, outstr);
973
 }
1004
 }
974
 
1005
 
975
 void CrealityDWINClass::Update_Status_Bar(bool refresh/*=false*/) {
1006
 void CrealityDWINClass::Update_Status_Bar(bool refresh/*=false*/) {
1007
+  typedef TextScroller<30> Scroller;
976
   static bool new_msg;
1008
   static bool new_msg;
977
-  static uint8_t msgscrl = 0;
1009
+  static Scroller scroller;
978
   static char lastmsg[64];
1010
   static char lastmsg[64];
979
   if (strcmp(lastmsg, statusmsg) != 0 || refresh) {
1011
   if (strcmp(lastmsg, statusmsg) != 0 || refresh) {
980
     strcpy(lastmsg, statusmsg);
1012
     strcpy(lastmsg, statusmsg);
981
-    msgscrl = 0;
1013
+    scroller.reset();
982
     new_msg = true;
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
     if (process == Print) {
1021
     if (process == Print) {
1001
       DWIN_Draw_Rectangle(1, Color_Grey, 8, 214, DWIN_WIDTH - 8, 238);
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
       DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 219, dispmsg);
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
     else {
1026
     else {
1006
       DWIN_Draw_Rectangle(1, Color_Bg_Black, 8, 352, DWIN_WIDTH - 8, 376);
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
       DWIN_Draw_String(false, DWIN_FONT_MENU, GetColor(eeprom_settings.status_bar_text, Color_White), Color_Bg_Black, npos, 357, dispmsg);
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
 }
4172
 }
4169
 
4173
 
4170
 void CrealityDWINClass::File_Control() {
4174
 void CrealityDWINClass::File_Control() {
4175
+  typedef TextScroller<MENU_CHAR_LIMIT> Scroller;
4176
+  static Scroller scroller;
4171
   EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
4177
   EncoderState encoder_diffState = Encoder_ReceiveAnalyze();
4172
-  static uint8_t filescrl = 0;
4173
   if (encoder_diffState == ENCODER_DIFF_NO) {
4178
   if (encoder_diffState == ENCODER_DIFF_NO) {
4174
     if (selection > 0) {
4179
     if (selection > 0) {
4175
       card.getfilename_sorted(SD_ORDER(selection - 1, card.get_num_Files()));
4180
       card.getfilename_sorted(SD_ORDER(selection - 1, card.get_num_Files()));
4176
       char * const filename = card.longest_filename();
4181
       char * const filename = card.longest_filename();
4177
       size_t len = strlen(filename);
4182
       size_t len = strlen(filename);
4178
-      int8_t pos = len;
4183
+      size_t pos = len;
4179
       if (!card.flag.filenameIsDir)
4184
       if (!card.flag.filenameIsDir)
4180
         while (pos && filename[pos] != '.') pos--;
4185
         while (pos && filename[pos] != '.') pos--;
4181
       if (pos > MENU_CHAR_LIMIT) {
4186
       if (pos > MENU_CHAR_LIMIT) {
4182
         static millis_t time = 0;
4187
         static millis_t time = 0;
4183
         if (PENDING(millis(), time)) return;
4188
         if (PENDING(millis(), time)) return;
4184
         time = millis() + 200;
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
         DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28);
4192
         DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28);
4197
         Draw_Menu_Item(selection - scrollpos, card.flag.filenameIsDir ? ICON_More : ICON_File, name);
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
         DWIN_UpdateLCD();
4194
         DWIN_UpdateLCD();
4201
       }
4195
       }
4202
     }
4196
     }
4208
       DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28);
4202
       DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28);
4209
       Draw_SD_Item(selection, selection - scrollpos);
4203
       Draw_SD_Item(selection, selection - scrollpos);
4210
     }
4204
     }
4211
-    filescrl = 0;
4205
+    scroller.reset();
4212
     selection++; // Select Down
4206
     selection++; // Select Down
4213
     if (selection > scrollpos + MROWS) {
4207
     if (selection > scrollpos + MROWS) {
4214
       scrollpos++;
4208
       scrollpos++;
4221
     DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33);
4215
     DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, MBASE(selection - scrollpos) - 18, 14, MBASE(selection - scrollpos) + 33);
4222
     DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28);
4216
     DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(selection - scrollpos) - 14, 271, MBASE(selection - scrollpos) + 28);
4223
     Draw_SD_Item(selection, selection - scrollpos);
4217
     Draw_SD_Item(selection, selection - scrollpos);
4224
-    filescrl = 0;
4218
+    scroller.reset();
4225
     selection--; // Select Up
4219
     selection--; // Select Up
4226
     if (selection < scrollpos) {
4220
     if (selection < scrollpos) {
4227
       scrollpos--;
4221
       scrollpos--;

Loading…
Annulla
Salva