瀏覽代碼

⚡️ Fixes to FTDI Eve Touch UI (#22347)

Marcio T 3 年之前
父節點
當前提交
fa6b01c677
No account linked to committer's email address

+ 15
- 1
Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/command_processor.h 查看文件

@@ -209,11 +209,25 @@ class CommandProcessor : public CLCD::CommandFifo {
209 209
     inline CommandProcessor& rectangle(int16_t x, int16_t y, int16_t w, int16_t h) {
210 210
       using namespace FTDI;
211 211
       CLCD::CommandFifo::cmd(BEGIN(RECTS));
212
-      CLCD::CommandFifo::cmd(VERTEX2F(x * 16, y * 16));
212
+      CLCD::CommandFifo::cmd(VERTEX2F( x      * 16,  y      * 16));
213 213
       CLCD::CommandFifo::cmd(VERTEX2F((x + w) * 16, (y + h) * 16));
214 214
       return *this;
215 215
     }
216 216
 
217
+    inline CommandProcessor& border(int16_t x, int16_t y, int16_t w, int16_t h) {
218
+      using namespace FTDI;
219
+      CLCD::CommandFifo::cmd(BEGIN(LINES));
220
+      CLCD::CommandFifo::cmd(VERTEX2F( x      * 16,  y      * 16));
221
+      CLCD::CommandFifo::cmd(VERTEX2F((x + w) * 16,  y      * 16));
222
+      CLCD::CommandFifo::cmd(VERTEX2F((x + w) * 16,  y      * 16));
223
+      CLCD::CommandFifo::cmd(VERTEX2F((x + w) * 16, (y + h) * 16));
224
+      CLCD::CommandFifo::cmd(VERTEX2F((x + w) * 16, (y + h) * 16));
225
+      CLCD::CommandFifo::cmd(VERTEX2F( x      * 16, (y + h) * 16));
226
+      CLCD::CommandFifo::cmd(VERTEX2F( x      * 16, (y + h) * 16));
227
+      CLCD::CommandFifo::cmd(VERTEX2F( x      * 16,  y      * 16));
228
+      return *this;
229
+    }
230
+
217 231
     template<typename T>
218 232
     FORCEDINLINE CommandProcessor& toggle(int16_t x, int16_t y, int16_t w, int16_t h, T text, bool state, uint16_t options = FTDI::OPT_3D) {
219 233
       CLCD::FontMetrics fm(_font);

+ 43
- 31
Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_box.cpp 查看文件

@@ -29,25 +29,30 @@ namespace FTDI {
29 29
    * be broken so that the display width is less than w. The line will also
30 30
    * be broken after a '\n'. Returns the display width of the line.
31 31
    */
32
-  static uint16_t find_line_break(const FontMetrics &fm, uint16_t w, const char *str, const char *&end) {
33
-    w -= fm.get_char_width(' ');
32
+  static uint16_t find_line_break(const FontMetrics &utf8_fm, const CLCD::FontMetrics &clcd_fm, const uint16_t w, const char *str, const char *&end, bool use_utf8) {
34 33
     const char *p = str;
35 34
     end = str;
36 35
     uint16_t lw = 0, result = 0;
37 36
     for (;;) {
38
-      utf8_char_t c = get_utf8_char_and_inc(p);
39
-      if (c == ' ' || c == '\n' || c == '\0') {
40
-        if (lw < w || end == str) {
41
-          end   = (c == '\0') ? p-1 : p;
37
+      const char *next = p;
38
+      utf8_char_t c = get_utf8_char_and_inc(next);
39
+      // Decide whether to break the string at this location
40
+      if (c == '\n' || c == '\0' || c == ' ') {
41
+        end = p;
42
+        result = lw;
43
+      }
44
+      if (c == '\n' || c == '\0') break;
45
+      // Now add the length of the current character to the tally.
46
+      lw += use_utf8 ? utf8_fm.get_char_width(c) : clcd_fm.char_widths[(uint8_t)c];
47
+      // Stop processing once string exceeds the display width
48
+      if (lw >= w) {
49
+        if (end == str) {
50
+          end = p;
42 51
           result = lw;
43 52
         }
44
-        if (c == '\0' || c == '\n') break;
53
+        break;
45 54
       }
46
-      lw += fm.get_char_width(c);
47
-    }
48
-    if (end == str) {
49
-      end   = p-1;
50
-      result = lw;
55
+      p = next;
51 56
     }
52 57
     return result;
53 58
   }
@@ -55,17 +60,18 @@ namespace FTDI {
55 60
   /**
56 61
    * This function returns a measurements of the word-wrapped text box.
57 62
    */
58
-  static void measure_text_box(const FontMetrics &fm, const char *str, uint16_t &width, uint16_t &height) {
63
+  static void measure_text_box(const FontMetrics &utf8_fm, const CLCD::FontMetrics &clcd_fm, const char *str, uint16_t &width, uint16_t &height, bool use_utf8) {
59 64
     const char *line_start = (const char*)str;
60 65
     const char *line_end;
61 66
     const uint16_t wrap_width = width;
62 67
     width = height = 0;
63 68
     for (;;) {
64
-      uint16_t line_width = find_line_break(fm, wrap_width, line_start, line_end);
65
-      if (line_end == line_start) break;
69
+      uint16_t line_width = find_line_break(utf8_fm, clcd_fm, wrap_width, line_start, line_end, use_utf8);
66 70
       width  = max(width, line_width);
67
-      height += fm.get_height();
71
+      height += utf8_fm.get_height();
68 72
       line_start = line_end;
73
+      if (line_start[0] == '\n' || line_start[0] == ' ') line_start++;
74
+      if (line_start[0] == '\0') break;
69 75
     }
70 76
   }
71 77
 
@@ -73,41 +79,45 @@ namespace FTDI {
73 79
    * This function draws text inside a bounding box, doing word wrapping and using the largest font that will fit.
74 80
    */
75 81
   void draw_text_box(CommandProcessor& cmd, int x, int y, int w, int h, const char *str, uint16_t options, uint8_t font) {
82
+    #if ENABLED(TOUCH_UI_USE_UTF8)
83
+      const bool use_utf8 = has_utf8_chars(str);
84
+    #else
85
+      constexpr bool use_utf8 = false;
86
+    #endif
76 87
     uint16_t box_width, box_height;
77 88
 
78
-    FontMetrics fm(font);
89
+    FontMetrics utf8_fm(font);
90
+    CLCD::FontMetrics clcd_fm;
91
+    clcd_fm.load(font);
79 92
 
80 93
     // Shrink the font until we find a font that fits
81 94
     for (;;) {
82 95
       box_width = w;
83
-      measure_text_box(fm, str, box_width, box_height);
96
+      measure_text_box(utf8_fm, clcd_fm, str, box_width, box_height, use_utf8);
84 97
       if (box_width <= (uint16_t)w && box_height <= (uint16_t)h) break;
85 98
       if (font == 26) break;
86
-      fm.load(--font);
99
+      utf8_fm.load(--font);
100
+      clcd_fm.load(font);
87 101
     }
88 102
 
89 103
     const uint16_t dx = (options & OPT_RIGHTX) ? w :
90
-                        (options & OPT_CENTERX) ? w/2 : 0;
91
-    const uint16_t dy = (options & OPT_BOTTOMY) ? (h - box_height) :
92
-                        (options & OPT_CENTERY) ? (h - box_height)/2 : 0;
104
+                        (options & OPT_CENTERX) ? w / 2 : 0,
105
+                   dy = (options & OPT_BOTTOMY) ? (h - box_height) :
106
+                        (options & OPT_CENTERY) ? (h - box_height) / 2 : 0;
93 107
 
94
-    const char *line_start = str;
95
-    const char *line_end;
108
+    const char *line_start = str, *line_end;
96 109
     for (;;) {
97
-      find_line_break(fm, w, line_start, line_end);
98
-      if (line_end == line_start) break;
110
+      find_line_break(utf8_fm, clcd_fm, w, line_start, line_end, use_utf8);
99 111
 
100 112
       const size_t line_len = line_end - line_start;
101 113
       if (line_len) {
102 114
         char line[line_len + 1];
103 115
         strncpy(line, line_start, line_len);
104 116
         line[line_len] = 0;
105
-        if (line[line_len - 1] == '\n' || line[line_len - 1] == ' ')
106
-          line[line_len - 1] = 0;
107 117
 
108 118
         #if ENABLED(TOUCH_UI_USE_UTF8)
109
-          if (has_utf8_chars(line)) {
110
-            draw_utf8_text(cmd, x + dx, y + dy, line, fm.fs, options & ~(OPT_CENTERY | OPT_BOTTOMY));
119
+          if (use_utf8) {
120
+            draw_utf8_text(cmd, x + dx, y + dy, line, utf8_fm.fs, options & ~(OPT_CENTERY | OPT_BOTTOMY));
111 121
           } else
112 122
         #endif
113 123
           {
@@ -115,9 +125,11 @@ namespace FTDI {
115 125
             cmd.CLCD::CommandFifo::str(line);
116 126
           }
117 127
       }
118
-      y += fm.get_height();
128
+      y += utf8_fm.get_height();
119 129
 
120 130
       line_start = line_end;
131
+      if (line_start[0] == '\n' || line_start[0] == ' ') line_start++;
132
+      if (line_start[0] == '\0') break;
121 133
     }
122 134
   }
123 135
 

+ 2
- 5
Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/about_screen.cpp 查看文件

@@ -44,16 +44,13 @@ void AboutScreen::onRedraw(draw_mode_t) {
44 44
      .cmd(COLOR_RGB(bg_text_enabled))
45 45
      .tag(0);
46 46
 
47
-  #define HEADING_POS BTN_POS(1,2), BTN_SIZE(4,1)
47
+  #define HEADING_POS BTN_POS(1,1), BTN_SIZE(4,2)
48 48
   #define FW_VERS_POS BTN_POS(1,3), BTN_SIZE(4,1)
49 49
   #define FW_INFO_POS BTN_POS(1,4), BTN_SIZE(4,1)
50 50
   #define LICENSE_POS BTN_POS(1,5), BTN_SIZE(4,3)
51 51
   #define STATS_POS   BTN_POS(1,8), BTN_SIZE(2,1)
52 52
   #define BACK_POS    BTN_POS(3,8), BTN_SIZE(2,1)
53 53
 
54
-  #define _INSET_POS(x,y,w,h) x + w/10, y, w - w/5, h
55
-  #define INSET_POS(pos) _INSET_POS(pos)
56
-
57 54
   char about_str[1
58 55
     + strlen_P(GET_TEXT(MSG_ABOUT_TOUCH_PANEL_2))
59 56
     #ifdef TOOLHEAD_NAME
@@ -89,7 +86,7 @@ void AboutScreen::onRedraw(draw_mode_t) {
89 86
   , OPT_CENTER, font_medium);
90 87
   cmd.tag(0);
91 88
   draw_text_box(cmd, FW_INFO_POS, about_str, OPT_CENTER, font_medium);
92
-  draw_text_box(cmd, INSET_POS(LICENSE_POS), GET_TEXT_F(MSG_LICENSE), OPT_CENTER, font_tiny);
89
+  draw_text_box(cmd, LICENSE_POS, GET_TEXT_F(MSG_LICENSE), OPT_CENTER, font_tiny);
93 90
 
94 91
   cmd.font(font_medium);
95 92
   #if ENABLED(PRINTCOUNTER) && defined(FTDI_STATISTICS_SCREEN)

+ 15
- 31
Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/interface_settings_screen.cpp 查看文件

@@ -58,11 +58,7 @@ void InterfaceSettingsScreen::onRedraw(draw_mode_t what) {
58 58
   if (what & BACKGROUND) {
59 59
 
60 60
     #define GRID_COLS 4
61
-    #if ENABLED(TOUCH_UI_PORTRAIT)
62
-      #define GRID_ROWS 7
63
-    #else
64
-      #define GRID_ROWS 6
65
-    #endif
61
+    #define GRID_ROWS TERN(TOUCH_UI_PORTRAIT, 7, 6)
66 62
 
67 63
     cmd.cmd(CLEAR_COLOR_RGB(bg_color))
68 64
        .cmd(CLEAR(true,true,true))
@@ -77,21 +73,19 @@ void InterfaceSettingsScreen::onRedraw(draw_mode_t what) {
77 73
     #if DISABLED(LCD_FYSETC_TFT81050)
78 74
        .text(BTN_POS(1,2), BTN_SIZE(2,1), GET_TEXT_F(MSG_LCD_BRIGHTNESS), OPT_RIGHTX | OPT_CENTERY)
79 75
     #endif
80
-       .text(BTN_POS(1,3), BTN_SIZE(2,1), GET_TEXT_F(MSG_SOUND_VOLUME),   OPT_RIGHTX | OPT_CENTERY)
81
-       .text(BTN_POS(1,4), BTN_SIZE(2,1), GET_TEXT_F(MSG_SCREEN_LOCK),    OPT_RIGHTX | OPT_CENTERY);
76
+       .text(BTN_POS(1,3), BTN_SIZE(2,1), GET_TEXT_F(MSG_SOUND_VOLUME),   OPT_RIGHTX | OPT_CENTERY);
77
+    #if ENABLED(FTDI_LOCK_SCREEN)
78
+      cmd.text(BTN_POS(1,4), BTN_SIZE(2,1), GET_TEXT_F(MSG_SCREEN_LOCK),    OPT_RIGHTX | OPT_CENTERY);
79
+    #endif
82 80
     #if DISABLED(TOUCH_UI_NO_BOOTSCREEN)
83
-    cmd.text(BTN_POS(1,5), BTN_SIZE(2,1), GET_TEXT_F(MSG_BOOT_SCREEN),    OPT_RIGHTX | OPT_CENTERY);
81
+      cmd.text(BTN_POS(1,5), BTN_SIZE(2,1), GET_TEXT_F(MSG_BOOT_SCREEN),    OPT_RIGHTX | OPT_CENTERY);
84 82
     #endif
85 83
     #undef EDGE_R
86 84
   }
87 85
 
88 86
   if (what & FOREGROUND) {
89
-    #if defined(FTDI_LOCK_SCREEN) || DISABLED(TOUCH_UI_NO_BOOTSCREEN)
90
-      #if ENABLED(TOUCH_UI_PORTRAIT)
91
-        constexpr uint8_t w = 2;
92
-      #else
93
-        constexpr uint8_t w = 1;
94
-      #endif
87
+    #if ENABLED(FTDI_LOCK_SCREEN) || DISABLED(TOUCH_UI_NO_BOOTSCREEN)
88
+      constexpr uint8_t w = TERN(TOUCH_UI_PORTRAIT, 2, 1);
95 89
     #endif
96 90
 
97 91
     cmd.font(font_medium)
@@ -101,7 +95,7 @@ void InterfaceSettingsScreen::onRedraw(draw_mode_t what) {
101 95
        .tag(2).slider(BTN_POS(3,2), BTN_SIZE(2,1), mydata.brightness, 128)
102 96
     #endif
103 97
        .tag(3).slider(BTN_POS(3,3), BTN_SIZE(2,1), mydata.volume,     0xFF)
104
-    #ifdef FTDI_LOCK_SCREEN
98
+    #if ENABLED(FTDI_LOCK_SCREEN)
105 99
        .colors(ui_toggle)
106 100
        .tag(4).toggle2(BTN_POS(3,4), BTN_SIZE(w,1), GET_TEXT_F(MSG_NO), GET_TEXT_F(MSG_YES), LockScreen::is_enabled())
107 101
     #endif
@@ -126,7 +120,7 @@ void InterfaceSettingsScreen::onRedraw(draw_mode_t what) {
126 120
 bool InterfaceSettingsScreen::onTouchEnd(uint8_t tag) {
127 121
   switch (tag) {
128 122
     case 1: GOTO_PREVIOUS(); return true;
129
-    #ifdef FTDI_LOCK_SCREEN
123
+    #if ENABLED(FTDI_LOCK_SCREEN)
130 124
       case 4:
131 125
         if (!LockScreen::is_enabled())
132 126
           LockScreen::enable();
@@ -185,8 +179,7 @@ void InterfaceSettingsScreen::onIdle() {
185 179
 }
186 180
 
187 181
 void InterfaceSettingsScreen::failSafeSettings() {
188
-  // Reset settings that may make the printer interface
189
-  // unusable.
182
+  // Reset settings that may make the printer interface unusable.
190 183
   CLCD::mem_write_32(CLCD::REG::ROTATE, 0);
191 184
   CLCD::default_touch_transform();
192 185
   CLCD::default_display_orientation();
@@ -197,9 +190,7 @@ void InterfaceSettingsScreen::failSafeSettings() {
197 190
 }
198 191
 
199 192
 void InterfaceSettingsScreen::defaultSettings() {
200
-  #ifdef FTDI_LOCK_SCREEN
201
-    LockScreen::passcode = 0;
202
-  #endif
193
+  TERN_(FTDI_LOCK_SCREEN, LockScreen::passcode = 0);
203 194
   SoundPlayer::set_volume(255);
204 195
   CLCD::set_brightness(255);
205 196
   UIData::reset_persistent_data();
@@ -218,11 +209,7 @@ void InterfaceSettingsScreen::saveSettings(char *buff) {
218 209
 
219 210
   persistent_data_t eeprom;
220 211
 
221
-  #ifdef FTDI_LOCK_SCREEN
222
-    eeprom.passcode           = LockScreen::passcode;
223
-  #else
224
-    eeprom.passcode           = 0;
225
-  #endif
212
+  eeprom.passcode             = TERN0(FTDI_LOCK_SCREEN, LockScreen::passcode);
226 213
   eeprom.sound_volume         = SoundPlayer::get_volume();
227 214
   eeprom.display_brightness   = CLCD::get_brightness();
228 215
   eeprom.bit_flags            = UIData::get_persistent_data();
@@ -251,7 +238,7 @@ void InterfaceSettingsScreen::loadSettings(const char *buff) {
251 238
 
252 239
   SERIAL_ECHOLNPGM("Loading setting from EEPROM");
253 240
 
254
-  #ifdef FTDI_LOCK_SCREEN
241
+  #if ENABLED(FTDI_LOCK_SCREEN)
255 242
     LockScreen::passcode = eeprom.passcode;
256 243
   #endif
257 244
   SoundPlayer::set_volume(eeprom.sound_volume);
@@ -282,10 +269,7 @@ void InterfaceSettingsScreen::loadSettings(const char *buff) {
282 269
     if (success)
283 270
       success = persistentStore.write_data(0, data, ARCHIM2_SPI_FLASH_EEPROM_BACKUP_SIZE) == PERSISTENT_STORE_SUCCESS;
284 271
 
285
-    if (success)
286
-      StatusScreen::setStatusMessage(GET_TEXT_F(MSG_EEPROM_RESTORED));
287
-    else
288
-      StatusScreen::setStatusMessage(GET_TEXT_F(MSG_EEPROM_RESET));
272
+    StatusScreen::setStatusMessage(success ? GET_TEXT_F(MSG_EEPROM_RESTORED) : GET_TEXT_F(MSG_EEPROM_RESET));
289 273
 
290 274
     return success;
291 275
   }

+ 4
- 0
Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/save_settings_dialog_box.cpp 查看文件

@@ -60,4 +60,8 @@ void SaveSettingsDialogBox::promptToSaveSettings() {
60 60
      GOTO_PREVIOUS(); // No save needed.
61 61
 }
62 62
 
63
+void SaveSettingsDialogBox::promptToSaveAndStay() {
64
+   if (needs_save) GOTO_SCREEN(SaveSettingsDialogBox);
65
+}
66
+
63 67
 #endif // FTDI_SAVE_SETTINGS_DIALOG_BOX

+ 1
- 0
Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/save_settings_dialog_box.h 查看文件

@@ -34,5 +34,6 @@ class SaveSettingsDialogBox : public DialogBoxBaseClass, public UncachedScreen {
34 34
     static bool onTouchEnd(uint8_t tag);
35 35
 
36 36
     static void promptToSaveSettings();
37
+    static void promptToSaveAndStay();
37 38
     static void settingsChanged() {needs_save = true;}
38 39
 };

+ 1
- 1
Marlin/src/lcd/extui/ftdi_eve_touch_ui/theme/fonts.h 查看文件

@@ -55,7 +55,7 @@ namespace Theme {
55 55
     constexpr int16_t  font_small    = 27;
56 56
     constexpr int16_t  font_medium   = 28;
57 57
     constexpr int16_t  font_large    = 30;
58
-    constexpr int16_t  font_xlarge   = 31;
58
+    constexpr int16_t  font_xlarge   = 30;
59 59
     constexpr float    icon_scale    = 0.6;
60 60
     #endif
61 61
   #elif defined(TOUCH_UI_320x240)

Loading…
取消
儲存