Przeglądaj źródła

🐛 Fix FTDI Eve Touch UI (#22500)

Marcio T 2 lat temu
rodzic
commit
092b5942c1
No account linked to committer's email address

+ 1
- 3
Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/command_processor.h Wyświetl plik

@@ -232,13 +232,11 @@ class CommandProcessor : public CLCD::CommandFifo {
232 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 233
       CLCD::FontMetrics fm(_font);
234 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 235
       // The y coordinate of the toggle is the baseline of the text,
238 236
       // so we must introduce a fudge factor based on the line height to
239 237
       // actually center the control.
240 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 240
       CLCD::CommandFifo::str(text);
243 241
       return *this;
244 242
     }

+ 6
- 6
Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_box.cpp Wyświetl plik

@@ -67,12 +67,12 @@ namespace FTDI {
67 67
     width = height = 0;
68 68
     for (;;) {
69 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 70
       width  = max(width, line_width);
72 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 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,7 +109,6 @@ namespace FTDI {
109 109
     const char *line_start = str, *line_end;
110 110
     for (;;) {
111 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 113
       const size_t line_len = line_end - line_start;
115 114
       if (line_len) {
@@ -125,9 +124,10 @@ namespace FTDI {
125 124
       }
126 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 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 Wyświetl plik

@@ -29,30 +29,30 @@ namespace FTDI {
29 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 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 44
     // Compute the total line length, as well as
36 45
     // the location in the string where it can
37 46
     // split and still allow the ellipsis to fit.
38 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 57
     if (lineWidth > w) {
58 58
       *breakPoint = '\0';
@@ -61,7 +61,7 @@ namespace FTDI {
61 61
 
62 62
     cmd.apply_text_alignment(x, y, w, h, options);
63 63
     #if ENABLED(TOUCH_UI_USE_UTF8)
64
-      if (has_utf8_chars(str)) {
64
+      if (use_utf8) {
65 65
         draw_utf8_text(cmd, x, y, str, font_size_t::from_romfont(font), options);
66 66
       } else
67 67
     #endif

+ 1
- 7
Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/dialog_box_base_class.cpp Wyświetl plik

@@ -39,7 +39,7 @@ void DialogBoxBaseClass::drawMessage(T message, int16_t font) {
39 39
      .cmd(CLEAR(true,true,true))
40 40
      .cmd(COLOR_RGB(bg_text_enabled))
41 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 43
   cmd.colors(normal_btn);
44 44
 }
45 45
 
@@ -69,12 +69,6 @@ void DialogBoxBaseClass::drawButton(T label) {
69 69
 template void DialogBoxBaseClass::drawButton(const char *);
70 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 72
 bool DialogBoxBaseClass::onTouchEnd(uint8_t tag) {
79 73
   switch (tag) {
80 74
     case 1: GOTO_PREVIOUS(); return true;

+ 0
- 1
Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/dialog_box_base_class.h Wyświetl plik

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

+ 1
- 1
Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/interface_settings_screen.cpp Wyświetl plik

@@ -104,8 +104,8 @@ void InterfaceSettingsScreen::onRedraw(draw_mode_t what) {
104 104
     #endif
105 105
     #undef EDGE_R
106 106
     #define EDGE_R 0
107
-    #if ENABLED(TOUCH_UI_PORTRAIT)
108 107
        .colors(normal_btn)
108
+    #if ENABLED(TOUCH_UI_PORTRAIT)
109 109
        .tag(6).button (BTN_POS(1,6), BTN_SIZE(4,1), GET_TEXT_F(MSG_SOUNDS))
110 110
        .colors(action_btn)
111 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 Wyświetl plik

@@ -74,8 +74,7 @@ void InterfaceSoundsScreen::onRedraw(draw_mode_t what) {
74 74
     #undef EDGE_R
75 75
     #define EDGE_R 30
76 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 78
               .text      (BTN_POS(1,5), BTN_SIZE(2,1), GET_TEXT_F(MSG_PRINT_STARTING), OPT_RIGHTX | OPT_CENTERY)
80 79
               .text      (BTN_POS(1,6), BTN_SIZE(2,1), GET_TEXT_F(MSG_PRINT_FINISHED), OPT_RIGHTX | OPT_CENTERY)
81 80
               .text      (BTN_POS(1,7), BTN_SIZE(2,1), GET_TEXT_F(MSG_PRINT_ERROR),    OPT_RIGHTX | OPT_CENTERY);
@@ -89,18 +88,16 @@ void InterfaceSoundsScreen::onRedraw(draw_mode_t what) {
89 88
       constexpr uint8_t w = 1;
90 89
     #endif
91 90
 
92
-    cmd.font(font_medium)
93
-       .colors(ui_slider)
91
+    cmd.font(font_small)
94 92
     #define EDGE_R 30
95
-       .tag(2).slider    (BTN_POS(3,2), BTN_SIZE(2,1), screen_data.InterfaceSettingsScreen.volume, 0xFF)
96 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 95
     #undef EDGE_R
99 96
        .colors(normal_btn)
100 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 101
        .colors(action_btn)
105 102
        .tag(1).button    (BTN_POS(1,9), BTN_SIZE(4,1), GET_TEXT_F(MSG_BUTTON_DONE));
106 103
   }
@@ -114,10 +111,10 @@ void InterfaceSoundsScreen::onEntry() {
114 111
 bool InterfaceSoundsScreen::onTouchEnd(uint8_t tag) {
115 112
   switch (tag) {
116 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 118
     default:
122 119
       return false;
123 120
   }
@@ -125,35 +122,4 @@ bool InterfaceSoundsScreen::onTouchEnd(uint8_t tag) {
125 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 125
 #endif // FTDI_INTERFACE_SOUNDS_SCREEN

+ 0
- 2
Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/interface_sounds_screen.h Wyświetl plik

@@ -51,7 +51,5 @@ class InterfaceSoundsScreen : public BaseScreen, public CachedScreen<INTERFACE_S
51 51
 
52 52
     static void onEntry();
53 53
     static void onRedraw(draw_mode_t);
54
-    static bool onTouchStart(uint8_t tag);
55 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 Wyświetl plik

@@ -26,8 +26,12 @@
26 26
 
27 27
 #ifdef FTDI_SPINNER_DIALOG_BOX
28 28
 
29
+#define GRID_COLS 2
30
+#define GRID_ROWS 8
31
+
29 32
 using namespace FTDI;
30 33
 using namespace ExtUI;
34
+using namespace Theme;
31 35
 
32 36
 constexpr static SpinnerDialogBoxData &mydata = screen_data.SpinnerDialogBox;
33 37
 
@@ -35,35 +39,65 @@ void SpinnerDialogBox::onEntry() {
35 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 59
 void SpinnerDialogBox::onRedraw(draw_mode_t) {
39 60
 }
40 61
 
41 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 81
   mydata.auto_hide = false;
47 82
 }
48 83
 
49 84
 void SpinnerDialogBox::hide() {
50
-  CommandProcessor cmd;
51
-  cmd.stop().execute();
52 85
   GOTO_PREVIOUS();
53 86
 }
54 87
 
55 88
 void SpinnerDialogBox::enqueueAndWait(progmem_str message, progmem_str commands) {
56 89
   show(message);
57 90
   ExtUI::injectCommands_P((const char*)commands);
91
+  mydata.auto_hide = true;
58 92
 }
59 93
 
60 94
 void SpinnerDialogBox::enqueueAndWait(progmem_str message, char *commands) {
61 95
   show(message);
62 96
   ExtUI::injectCommands(commands);
97
+  mydata.auto_hide = true;
63 98
 }
64 99
 
65 100
 void SpinnerDialogBox::onIdle() {
66
-  reset_menu_timeout();
67 101
   if (mydata.auto_hide && !commandsInQueue()) {
68 102
     mydata.auto_hide = false;
69 103
     hide();

+ 3
- 1
Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/spinner_dialog_box.h Wyświetl plik

@@ -29,10 +29,12 @@ struct SpinnerDialogBoxData {
29 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 33
   public:
34 34
     static void onEntry();
35
+    static void onExit();
35 36
     static void onRedraw(draw_mode_t);
37
+    static void onRefresh();
36 38
     static void onIdle();
37 39
 
38 40
     static void show(progmem_str);

Ładowanie…
Anuluj
Zapisz