瀏覽代碼

🐛 Fix FTDI Eve Touch UI (#22500)

Marcio T 3 年之前
父節點
當前提交
092b5942c1
沒有連結到貢獻者的電子郵件帳戶。

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

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) {
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) {
233
       CLCD::FontMetrics fm(_font);
233
       CLCD::FontMetrics fm(_font);
234
       const int16_t widget_h = fm.height * 20.0 / 16;
234
       const int16_t widget_h = fm.height * 20.0 / 16;
235
-      //const int16_t outer_bar_r = widget_h / 2;
236
-      //const int16_t knob_r      = outer_bar_r - 1.5;
237
       // The y coordinate of the toggle is the baseline of the text,
235
       // The y coordinate of the toggle is the baseline of the text,
238
       // so we must introduce a fudge factor based on the line height to
236
       // so we must introduce a fudge factor based on the line height to
239
       // actually center the control.
237
       // actually center the control.
240
       const int16_t fudge_y = fm.height * 5 / 16;
238
       const int16_t fudge_y = fm.height * 5 / 16;
241
-      CLCD::CommandFifo::toggle(x + h / 2, y + (h - widget_h) / 2 + fudge_y, w - h, _font, options, state);
239
+      CLCD::CommandFifo::toggle(x + widget_h, y + (h - widget_h) / 2 + fudge_y, w - widget_h, _font, options, state);
242
       CLCD::CommandFifo::str(text);
240
       CLCD::CommandFifo::str(text);
243
       return *this;
241
       return *this;
244
     }
242
     }

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

67
     width = height = 0;
67
     width = height = 0;
68
     for (;;) {
68
     for (;;) {
69
       const uint16_t line_width = find_line_break(utf8_fm, clcd_fm, wrap_width, line_start, line_end, use_utf8);
69
       const uint16_t line_width = find_line_break(utf8_fm, clcd_fm, wrap_width, line_start, line_end, use_utf8);
70
-      if (line_end == line_start) break;
71
       width  = max(width, line_width);
70
       width  = max(width, line_width);
72
       height += utf8_fm.get_height();
71
       height += utf8_fm.get_height();
72
+      if (*line_end == '\n' || *line_end == ' ') line_end++;
73
+      if (*line_end == '\0') break;
74
+      if (line_end == line_start) break;
73
       line_start = line_end;
75
       line_start = line_end;
74
-      if (*line_start == '\n' || *line_start == ' ') line_start++;
75
-      if (*line_start == '\0') break;
76
     }
76
     }
77
   }
77
   }
78
 
78
 
109
     const char *line_start = str, *line_end;
109
     const char *line_start = str, *line_end;
110
     for (;;) {
110
     for (;;) {
111
       find_line_break(utf8_fm, clcd_fm, w, line_start, line_end, use_utf8);
111
       find_line_break(utf8_fm, clcd_fm, w, line_start, line_end, use_utf8);
112
-      if (line_end == line_start) break;
113
 
112
 
114
       const size_t line_len = line_end - line_start;
113
       const size_t line_len = line_end - line_start;
115
       if (line_len) {
114
       if (line_len) {
125
       }
124
       }
126
       y += utf8_fm.get_height();
125
       y += utf8_fm.get_height();
127
 
126
 
127
+      if (*line_end == '\n' || *line_end == ' ') line_end++;
128
+      if (*line_end == '\0') break;
129
+      if (line_end == line_start) break;
128
       line_start = line_end;
130
       line_start = line_end;
129
-      if (*line_start == '\n' || *line_start == ' ') line_start++;
130
-      if (*line_start == '\0') break;
131
     }
131
     }
132
   }
132
   }
133
 
133
 

+ 20
- 20
Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_ellipsis.cpp 查看文件

29
    * Helper function for drawing text with ellipses. The str buffer may be modified and should have space for up to two extra characters.
29
    * Helper function for drawing text with ellipses. The str buffer may be modified and should have space for up to two extra characters.
30
    */
30
    */
31
   static void _draw_text_with_ellipsis(CommandProcessor& cmd, int16_t x, int16_t y, int16_t w, int16_t h, char *str, uint16_t options, uint8_t font) {
31
   static void _draw_text_with_ellipsis(CommandProcessor& cmd, int16_t x, int16_t y, int16_t w, int16_t h, char *str, uint16_t options, uint8_t font) {
32
-    FontMetrics fm(font);
33
-    const int16_t ellipsisWidth = fm.get_char_width('.') * 3;
32
+    #if ENABLED(TOUCH_UI_USE_UTF8)
33
+      const bool use_utf8 = has_utf8_chars(str);
34
+      #define CHAR_WIDTH(c) use_utf8 ? utf8_fm.get_char_width(c) : clcd_fm.char_widths[(uint8_t)c]
35
+    #else
36
+      #define CHAR_WIDTH(c) utf8_fm.get_char_width(c)
37
+      constexpr bool use_utf8 = false;
38
+    #endif
39
+    FontMetrics utf8_fm(font);
40
+    CLCD::FontMetrics clcd_fm;
41
+    clcd_fm.load(font);
42
+    const int16_t ellipsisWidth = utf8_fm.get_char_width('.') * 3;
34
 
43
 
35
     // Compute the total line length, as well as
44
     // Compute the total line length, as well as
36
     // the location in the string where it can
45
     // the location in the string where it can
37
     // split and still allow the ellipsis to fit.
46
     // split and still allow the ellipsis to fit.
38
     int16_t lineWidth = 0;
47
     int16_t lineWidth = 0;
39
-    char *breakPoint   = str;
40
-    #ifdef TOUCH_UI_USE_UTF8
41
-      char *tstr = str;
42
-      while (*tstr) {
43
-        breakPoint = tstr;
44
-        const utf8_char_t c = get_utf8_char_and_inc(tstr);
45
-        lineWidth += fm.get_char_width(c);
46
-        if (lineWidth + ellipsisWidth < w)
47
-          break;
48
-      }
49
-    #else
50
-      for (char *c = str; *c; c++) {
51
-        lineWidth += fm.get_char_width(*c);
52
-        if (lineWidth + ellipsisWidth < w)
53
-          breakPoint = c;
54
-      }
55
-    #endif
48
+    char *breakPoint = str;
49
+    char *next = str;
50
+    while (*next) {
51
+      const utf8_char_t c = get_utf8_char_and_inc(next);
52
+      lineWidth += CHAR_WIDTH(c);
53
+      if (lineWidth + ellipsisWidth < w)
54
+        breakPoint = next;
55
+    }
56
 
56
 
57
     if (lineWidth > w) {
57
     if (lineWidth > w) {
58
       *breakPoint = '\0';
58
       *breakPoint = '\0';
61
 
61
 
62
     cmd.apply_text_alignment(x, y, w, h, options);
62
     cmd.apply_text_alignment(x, y, w, h, options);
63
     #if ENABLED(TOUCH_UI_USE_UTF8)
63
     #if ENABLED(TOUCH_UI_USE_UTF8)
64
-      if (has_utf8_chars(str)) {
64
+      if (use_utf8) {
65
         draw_utf8_text(cmd, x, y, str, font_size_t::from_romfont(font), options);
65
         draw_utf8_text(cmd, x, y, str, font_size_t::from_romfont(font), options);
66
       } else
66
       } else
67
     #endif
67
     #endif

+ 1
- 7
Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/dialog_box_base_class.cpp 查看文件

39
      .cmd(CLEAR(true,true,true))
39
      .cmd(CLEAR(true,true,true))
40
      .cmd(COLOR_RGB(bg_text_enabled))
40
      .cmd(COLOR_RGB(bg_text_enabled))
41
      .tag(0);
41
      .tag(0);
42
-  draw_text_box(cmd, BTN_POS(1,1), BTN_SIZE(2,3), message, OPT_CENTER, font ? font : font_large);
42
+  draw_text_box(cmd, BTN_POS(1,1), BTN_SIZE(2,6), message, OPT_CENTER, font ? font : font_large);
43
   cmd.colors(normal_btn);
43
   cmd.colors(normal_btn);
44
 }
44
 }
45
 
45
 
69
 template void DialogBoxBaseClass::drawButton(const char *);
69
 template void DialogBoxBaseClass::drawButton(const char *);
70
 template void DialogBoxBaseClass::drawButton(progmem_str);
70
 template void DialogBoxBaseClass::drawButton(progmem_str);
71
 
71
 
72
-void DialogBoxBaseClass::drawSpinner() {
73
-  CommandProcessor cmd;
74
-  cmd.cmd(COLOR_RGB(bg_text_enabled))
75
-     .spinner(BTN_POS(1,4), BTN_SIZE(2,3)).execute();
76
-}
77
-
78
 bool DialogBoxBaseClass::onTouchEnd(uint8_t tag) {
72
 bool DialogBoxBaseClass::onTouchEnd(uint8_t tag) {
79
   switch (tag) {
73
   switch (tag) {
80
     case 1: GOTO_PREVIOUS(); return true;
74
     case 1: GOTO_PREVIOUS(); return true;

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

31
     template<typename T> static void drawButton(T);
31
     template<typename T> static void drawButton(T);
32
     static void drawYesNoButtons(uint8_t default_btn = 0);
32
     static void drawYesNoButtons(uint8_t default_btn = 0);
33
     static void drawOkayButton();
33
     static void drawOkayButton();
34
-    static void drawSpinner();
35
 
34
 
36
     static void onRedraw(draw_mode_t) {};
35
     static void onRedraw(draw_mode_t) {};
37
   public:
36
   public:

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

104
     #endif
104
     #endif
105
     #undef EDGE_R
105
     #undef EDGE_R
106
     #define EDGE_R 0
106
     #define EDGE_R 0
107
-    #if ENABLED(TOUCH_UI_PORTRAIT)
108
        .colors(normal_btn)
107
        .colors(normal_btn)
108
+    #if ENABLED(TOUCH_UI_PORTRAIT)
109
        .tag(6).button (BTN_POS(1,6), BTN_SIZE(4,1), GET_TEXT_F(MSG_SOUNDS))
109
        .tag(6).button (BTN_POS(1,6), BTN_SIZE(4,1), GET_TEXT_F(MSG_SOUNDS))
110
        .colors(action_btn)
110
        .colors(action_btn)
111
        .tag(1).button (BTN_POS(1,7), BTN_SIZE(4,1), GET_TEXT_F(MSG_BUTTON_DONE));
111
        .tag(1).button (BTN_POS(1,7), BTN_SIZE(4,1), GET_TEXT_F(MSG_BUTTON_DONE));

+ 10
- 44
Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/interface_sounds_screen.cpp 查看文件

74
     #undef EDGE_R
74
     #undef EDGE_R
75
     #define EDGE_R 30
75
     #define EDGE_R 30
76
        .font(font_small)
76
        .font(font_small)
77
-       .tag(0).text      (BTN_POS(1,2), BTN_SIZE(2,1), GET_TEXT_F(MSG_SOUND_VOLUME),   OPT_RIGHTX | OPT_CENTERY)
78
-              .text      (BTN_POS(1,3), BTN_SIZE(2,1), GET_TEXT_F(MSG_CLICK_SOUNDS),   OPT_RIGHTX | OPT_CENTERY)
77
+       .tag(0).text      (BTN_POS(1,3), BTN_SIZE(2,1), GET_TEXT_F(MSG_CLICK_SOUNDS),   OPT_RIGHTX | OPT_CENTERY)
79
               .text      (BTN_POS(1,5), BTN_SIZE(2,1), GET_TEXT_F(MSG_PRINT_STARTING), OPT_RIGHTX | OPT_CENTERY)
78
               .text      (BTN_POS(1,5), BTN_SIZE(2,1), GET_TEXT_F(MSG_PRINT_STARTING), OPT_RIGHTX | OPT_CENTERY)
80
               .text      (BTN_POS(1,6), BTN_SIZE(2,1), GET_TEXT_F(MSG_PRINT_FINISHED), OPT_RIGHTX | OPT_CENTERY)
79
               .text      (BTN_POS(1,6), BTN_SIZE(2,1), GET_TEXT_F(MSG_PRINT_FINISHED), OPT_RIGHTX | OPT_CENTERY)
81
               .text      (BTN_POS(1,7), BTN_SIZE(2,1), GET_TEXT_F(MSG_PRINT_ERROR),    OPT_RIGHTX | OPT_CENTERY);
80
               .text      (BTN_POS(1,7), BTN_SIZE(2,1), GET_TEXT_F(MSG_PRINT_ERROR),    OPT_RIGHTX | OPT_CENTERY);
89
       constexpr uint8_t w = 1;
88
       constexpr uint8_t w = 1;
90
     #endif
89
     #endif
91
 
90
 
92
-    cmd.font(font_medium)
93
-       .colors(ui_slider)
91
+    cmd.font(font_small)
94
     #define EDGE_R 30
92
     #define EDGE_R 30
95
-       .tag(2).slider    (BTN_POS(3,2), BTN_SIZE(2,1), screen_data.InterfaceSettingsScreen.volume, 0xFF)
96
        .colors(ui_toggle)
93
        .colors(ui_toggle)
97
-       .tag(3).toggle2   (BTN_POS(3,3), BTN_SIZE(w,1), GET_TEXT_F(MSG_NO), GET_TEXT_F(MSG_YES), UIData::touch_sounds_enabled())
94
+       .tag(2).toggle2   (BTN_POS(3,3), BTN_SIZE(w,1), GET_TEXT_F(MSG_NO), GET_TEXT_F(MSG_YES), UIData::touch_sounds_enabled())
98
     #undef EDGE_R
95
     #undef EDGE_R
99
        .colors(normal_btn)
96
        .colors(normal_btn)
100
     #define EDGE_R 0
97
     #define EDGE_R 0
101
-       .tag(4).button    (BTN_POS(3,5), BTN_SIZE(2,1), getSoundSelection(PRINTING_STARTED))
102
-       .tag(5).button    (BTN_POS(3,6), BTN_SIZE(2,1), getSoundSelection(PRINTING_FINISHED))
103
-       .tag(6).button    (BTN_POS(3,7), BTN_SIZE(2,1), getSoundSelection(PRINTING_FAILED))
98
+       .tag(3).button    (BTN_POS(3,5), BTN_SIZE(2,1), getSoundSelection(PRINTING_STARTED))
99
+       .tag(4).button    (BTN_POS(3,6), BTN_SIZE(2,1), getSoundSelection(PRINTING_FINISHED))
100
+       .tag(5).button    (BTN_POS(3,7), BTN_SIZE(2,1), getSoundSelection(PRINTING_FAILED))
104
        .colors(action_btn)
101
        .colors(action_btn)
105
        .tag(1).button    (BTN_POS(1,9), BTN_SIZE(4,1), GET_TEXT_F(MSG_BUTTON_DONE));
102
        .tag(1).button    (BTN_POS(1,9), BTN_SIZE(4,1), GET_TEXT_F(MSG_BUTTON_DONE));
106
   }
103
   }
114
 bool InterfaceSoundsScreen::onTouchEnd(uint8_t tag) {
111
 bool InterfaceSoundsScreen::onTouchEnd(uint8_t tag) {
115
   switch (tag) {
112
   switch (tag) {
116
     case 1: GOTO_PREVIOUS();                                              return true;
113
     case 1: GOTO_PREVIOUS();                                              return true;
117
-    case 3: UIData::enable_touch_sounds(!UIData::touch_sounds_enabled()); break;
118
-    case 4: toggleSoundSelection(PRINTING_STARTED);                       break;
119
-    case 5: toggleSoundSelection(PRINTING_FINISHED);                      break;
120
-    case 6: toggleSoundSelection(PRINTING_FAILED);                        break;
114
+    case 2: UIData::enable_touch_sounds(!UIData::touch_sounds_enabled()); break;
115
+    case 3: toggleSoundSelection(PRINTING_STARTED);                       break;
116
+    case 4: toggleSoundSelection(PRINTING_FINISHED);                      break;
117
+    case 5: toggleSoundSelection(PRINTING_FAILED);                        break;
121
     default:
118
     default:
122
       return false;
119
       return false;
123
   }
120
   }
125
   return true;
122
   return true;
126
 }
123
 }
127
 
124
 
128
-bool InterfaceSoundsScreen::onTouchStart(uint8_t tag) {
129
-  CommandProcessor cmd;
130
-  #undef EDGE_R
131
-  #define EDGE_R 30
132
-  switch (tag) {
133
-    case 2: cmd.track_linear(BTN_POS(3,2), BTN_SIZE(2,1), 2).execute(); break;
134
-    default: break;
135
-  }
136
-  return true;
137
-}
138
-
139
-void InterfaceSoundsScreen::onIdle() {
140
-  if (refresh_timer.elapsed(TOUCH_UPDATE_INTERVAL)) {
141
-    refresh_timer.start();
142
-
143
-    uint16_t value;
144
-    CommandProcessor cmd;
145
-    switch (cmd.track_tag(value)) {
146
-      case 2:
147
-        screen_data.InterfaceSettingsScreen.volume = value >> 8;
148
-        SoundPlayer::set_volume(screen_data.InterfaceSettingsScreen.volume);
149
-        SaveSettingsDialogBox::settingsChanged();
150
-        break;
151
-      default:
152
-        return;
153
-    }
154
-    onRefresh();
155
-  }
156
-  BaseScreen::onIdle();
157
-}
158
-
159
 #endif // FTDI_INTERFACE_SOUNDS_SCREEN
125
 #endif // FTDI_INTERFACE_SOUNDS_SCREEN

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

51
 
51
 
52
     static void onEntry();
52
     static void onEntry();
53
     static void onRedraw(draw_mode_t);
53
     static void onRedraw(draw_mode_t);
54
-    static bool onTouchStart(uint8_t tag);
55
     static bool onTouchEnd(uint8_t tag);
54
     static bool onTouchEnd(uint8_t tag);
56
-    static void onIdle();
57
 };
55
 };

+ 41
- 7
Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/spinner_dialog_box.cpp 查看文件

26
 
26
 
27
 #ifdef FTDI_SPINNER_DIALOG_BOX
27
 #ifdef FTDI_SPINNER_DIALOG_BOX
28
 
28
 
29
+#define GRID_COLS 2
30
+#define GRID_ROWS 8
31
+
29
 using namespace FTDI;
32
 using namespace FTDI;
30
 using namespace ExtUI;
33
 using namespace ExtUI;
34
+using namespace Theme;
31
 
35
 
32
 constexpr static SpinnerDialogBoxData &mydata = screen_data.SpinnerDialogBox;
36
 constexpr static SpinnerDialogBoxData &mydata = screen_data.SpinnerDialogBox;
33
 
37
 
35
   mydata.auto_hide = true;
39
   mydata.auto_hide = true;
36
 }
40
 }
37
 
41
 
42
+void SpinnerDialogBox::onExit() {
43
+  CommandProcessor cmd;
44
+  cmd.stop().execute();
45
+}
46
+
47
+void SpinnerDialogBox::onRefresh() {
48
+  using namespace FTDI;
49
+  DLCache dlcache(SPINNER_CACHE);
50
+  CommandProcessor cmd;
51
+  cmd.cmd(CMD_DLSTART);
52
+  if (dlcache.has_data())
53
+    dlcache.append();
54
+  else
55
+    dlcache.store(SPINNER_DL_SIZE);
56
+  cmd.spinner(BTN_POS(1,4), BTN_SIZE(2,3)).execute();
57
+}
58
+
38
 void SpinnerDialogBox::onRedraw(draw_mode_t) {
59
 void SpinnerDialogBox::onRedraw(draw_mode_t) {
39
 }
60
 }
40
 
61
 
41
 void SpinnerDialogBox::show(progmem_str message) {
62
 void SpinnerDialogBox::show(progmem_str message) {
42
-  drawMessage(message);
43
-  drawSpinner();
44
-  storeBackground();
45
-  GOTO_SCREEN(SpinnerDialogBox);
63
+  CommandProcessor cmd;
64
+  if (AT_SCREEN(SpinnerDialogBox)) cmd.stop().execute();
65
+  cmd.cmd(CMD_DLSTART)
66
+     .cmd(CLEAR_COLOR_RGB(bg_color))
67
+     .cmd(CLEAR(true,true,true))
68
+     .cmd(COLOR_RGB(bg_text_enabled))
69
+     .tag(0);
70
+  draw_text_box(cmd, BTN_POS(1,1), BTN_SIZE(2,3), message, OPT_CENTER, font_large);
71
+  DLCache dlcache(SPINNER_CACHE);
72
+  if (!dlcache.store(SPINNER_DL_SIZE)) {
73
+    SERIAL_ECHO_MSG("CachedScreen::storeBackground() failed: not enough DL cache space");
74
+    cmd.cmd(CMD_DLSTART).cmd(CLEAR(true,true,true));
75
+    dlcache.store(SPINNER_DL_SIZE);
76
+  }
77
+  if (AT_SCREEN(SpinnerDialogBox))
78
+    cmd.spinner(BTN_POS(1,4), BTN_SIZE(2,3)).execute();
79
+  else
80
+    GOTO_SCREEN(SpinnerDialogBox);
46
   mydata.auto_hide = false;
81
   mydata.auto_hide = false;
47
 }
82
 }
48
 
83
 
49
 void SpinnerDialogBox::hide() {
84
 void SpinnerDialogBox::hide() {
50
-  CommandProcessor cmd;
51
-  cmd.stop().execute();
52
   GOTO_PREVIOUS();
85
   GOTO_PREVIOUS();
53
 }
86
 }
54
 
87
 
55
 void SpinnerDialogBox::enqueueAndWait(progmem_str message, progmem_str commands) {
88
 void SpinnerDialogBox::enqueueAndWait(progmem_str message, progmem_str commands) {
56
   show(message);
89
   show(message);
57
   ExtUI::injectCommands_P((const char*)commands);
90
   ExtUI::injectCommands_P((const char*)commands);
91
+  mydata.auto_hide = true;
58
 }
92
 }
59
 
93
 
60
 void SpinnerDialogBox::enqueueAndWait(progmem_str message, char *commands) {
94
 void SpinnerDialogBox::enqueueAndWait(progmem_str message, char *commands) {
61
   show(message);
95
   show(message);
62
   ExtUI::injectCommands(commands);
96
   ExtUI::injectCommands(commands);
97
+  mydata.auto_hide = true;
63
 }
98
 }
64
 
99
 
65
 void SpinnerDialogBox::onIdle() {
100
 void SpinnerDialogBox::onIdle() {
66
-  reset_menu_timeout();
67
   if (mydata.auto_hide && !commandsInQueue()) {
101
   if (mydata.auto_hide && !commandsInQueue()) {
68
     mydata.auto_hide = false;
102
     mydata.auto_hide = false;
69
     hide();
103
     hide();

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

29
   bool auto_hide;
29
   bool auto_hide;
30
 };
30
 };
31
 
31
 
32
-class SpinnerDialogBox : public DialogBoxBaseClass, public CachedScreen<SPINNER_CACHE,SPINNER_DL_SIZE> {
32
+class SpinnerDialogBox : public BaseScreen {
33
   public:
33
   public:
34
     static void onEntry();
34
     static void onEntry();
35
+    static void onExit();
35
     static void onRedraw(draw_mode_t);
36
     static void onRedraw(draw_mode_t);
37
+    static void onRefresh();
36
     static void onIdle();
38
     static void onIdle();
37
 
39
 
38
     static void show(progmem_str);
40
     static void show(progmem_str);

Loading…
取消
儲存