|
@@ -26,6 +26,34 @@
|
26
|
26
|
|
27
|
27
|
#ifdef FTDI_FILES_SCREEN
|
28
|
28
|
|
|
29
|
+#if ENABLED(TOUCH_UI_PORTRAIT)
|
|
30
|
+ #define GRID_COLS 6
|
|
31
|
+ #define GRID_ROWS 15
|
|
32
|
+ #define FILES_PER_PAGE 11
|
|
33
|
+ #define PREV_DIR LEFT
|
|
34
|
+ #define NEXT_DIR RIGHT
|
|
35
|
+
|
|
36
|
+ #define PREV_POS BTN_POS(1,1), BTN_SIZE(1,2)
|
|
37
|
+ #define HEAD_POS BTN_POS(2,1), BTN_SIZE(4,2)
|
|
38
|
+ #define NEXT_POS BTN_POS(6,1), BTN_SIZE(1,2)
|
|
39
|
+ #define LIST_POS BTN_POS(1,3), BTN_SIZE(6,FILES_PER_PAGE)
|
|
40
|
+ #define BTN1_POS BTN_POS(1,14), BTN_SIZE(3,2)
|
|
41
|
+ #define BTN2_POS BTN_POS(4,14), BTN_SIZE(3,2)
|
|
42
|
+#else
|
|
43
|
+ #define GRID_COLS 12
|
|
44
|
+ #define GRID_ROWS 8
|
|
45
|
+ #define FILES_PER_PAGE 6
|
|
46
|
+ #define PREV_DIR UP
|
|
47
|
+ #define NEXT_DIR DOWN
|
|
48
|
+
|
|
49
|
+ #define PREV_POS BTN_POS(12,2), BTN_SIZE(1,3)
|
|
50
|
+ #define HEAD_POS BTN_POS( 1,1), BTN_SIZE(12,1)
|
|
51
|
+ #define NEXT_POS BTN_POS(12,5), BTN_SIZE(1,4)
|
|
52
|
+ #define LIST_POS BTN_POS( 1,2), BTN_SIZE(11,FILES_PER_PAGE)
|
|
53
|
+ #define BTN1_POS BTN_POS( 1,8), BTN_SIZE(6,1)
|
|
54
|
+ #define BTN2_POS BTN_POS( 7,8), BTN_SIZE(5,1)
|
|
55
|
+#endif
|
|
56
|
+
|
29
|
57
|
using namespace FTDI;
|
30
|
58
|
using namespace ExtUI;
|
31
|
59
|
using namespace Theme;
|
|
@@ -49,6 +77,7 @@ const char *FilesScreen::getSelectedFilename(bool longName) {
|
49
|
77
|
}
|
50
|
78
|
|
51
|
79
|
void FilesScreen::drawSelectedFile() {
|
|
80
|
+ if(mydata.selected_tag == 0xFF) return;
|
52
|
81
|
FileList files;
|
53
|
82
|
files.seek(getSelectedFileIndex(), true);
|
54
|
83
|
mydata.flags.is_dir = files.isDir();
|
|
@@ -65,122 +94,108 @@ uint16_t FilesScreen::getSelectedFileIndex() {
|
65
|
94
|
}
|
66
|
95
|
|
67
|
96
|
uint16_t FilesScreen::getFileForTag(uint8_t tag) {
|
68
|
|
- return mydata.cur_page * files_per_page + tag - 2;
|
|
97
|
+ return mydata.cur_page * FILES_PER_PAGE + tag - 2;
|
69
|
98
|
}
|
70
|
99
|
|
71
|
|
-#if ENABLED(TOUCH_UI_PORTRAIT)
|
72
|
|
- #define GRID_COLS 6
|
73
|
|
- #define GRID_ROWS (files_per_page + header_h + footer_h)
|
74
|
|
-#else
|
75
|
|
- #define GRID_COLS 6
|
76
|
|
- #define GRID_ROWS (files_per_page + header_h + footer_h)
|
77
|
|
-#endif
|
|
100
|
+void FilesScreen::drawFileButton(int x, int y, int w, int h, const char *filename, uint8_t tag, bool is_dir, bool is_highlighted) {
|
|
101
|
+ #define SUB_COLS 6
|
|
102
|
+ #define SUB_ROWS FILES_PER_PAGE
|
|
103
|
+
|
|
104
|
+ const int bx = SUB_X(1);
|
|
105
|
+ const int by = SUB_Y(getLineForTag(tag)+1);
|
|
106
|
+ const int bw = SUB_W(6);
|
|
107
|
+ const int bh = SUB_H(1);
|
78
|
108
|
|
79
|
|
-void FilesScreen::drawFileButton(const char *filename, uint8_t tag, bool is_dir, bool is_highlighted) {
|
80
|
|
- const uint8_t line = getLineForTag(tag)+1;
|
81
|
109
|
CommandProcessor cmd;
|
82
|
110
|
cmd.tag(tag);
|
83
|
111
|
cmd.cmd(COLOR_RGB(is_highlighted ? fg_action : bg_color));
|
84
|
|
- cmd.font(font_medium)
|
85
|
|
- .rectangle( 0, BTN_Y(header_h+line), display_width, BTN_H(1));
|
|
112
|
+ cmd.font(font_medium).rectangle(bx, by, bw, bh);
|
86
|
113
|
cmd.cmd(COLOR_RGB(is_highlighted ? normal_btn.rgb : bg_text_enabled));
|
87
|
|
- constexpr uint16_t dim[2] = {BTN_SIZE(6,1)};
|
88
|
|
- #define POS_AND_SHORTEN(SHORTEN) BTN_POS(1,header_h+line), dim[0] - (SHORTEN), dim[1]
|
89
|
|
- #define POS_AND_SIZE POS_AND_SHORTEN(0)
|
90
|
114
|
#if ENABLED(SCROLL_LONG_FILENAMES)
|
91
|
115
|
if (is_highlighted) {
|
92
|
116
|
cmd.cmd(SAVE_CONTEXT());
|
|
117
|
+ cmd.cmd(SCISSOR_XY(x,y));
|
|
118
|
+ cmd.cmd(SCISSOR_SIZE(w,h));
|
93
|
119
|
cmd.cmd(MACRO(0));
|
94
|
|
- cmd.text(POS_AND_SIZE, filename, OPT_CENTERY | OPT_NOFIT);
|
|
120
|
+ cmd.text(bx, by, bw, bh, filename, OPT_CENTERY | OPT_NOFIT);
|
95
|
121
|
} else
|
96
|
122
|
#endif
|
97
|
|
- draw_text_with_ellipsis(cmd, POS_AND_SHORTEN(is_dir ? 20 : 0), filename, OPT_CENTERY, font_medium);
|
98
|
|
- if (is_dir && !is_highlighted) {
|
99
|
|
- cmd.text(POS_AND_SIZE, F("> "), OPT_CENTERY | OPT_RIGHTX);
|
100
|
|
- }
|
|
123
|
+ draw_text_with_ellipsis(cmd, bx,by, bw - (is_dir ? 20 : 0), bh, filename, OPT_CENTERY, font_medium);
|
|
124
|
+ if (is_dir && !is_highlighted) cmd.text(bx, by, bw, bh, F("> "), OPT_CENTERY | OPT_RIGHTX);
|
101
|
125
|
#if ENABLED(SCROLL_LONG_FILENAMES)
|
102
|
|
- if (is_highlighted) {
|
103
|
|
- cmd.cmd(RESTORE_CONTEXT());
|
104
|
|
- }
|
|
126
|
+ if (is_highlighted) cmd.cmd(RESTORE_CONTEXT());
|
105
|
127
|
#endif
|
106
|
128
|
}
|
107
|
129
|
|
108
|
130
|
void FilesScreen::drawFileList() {
|
109
|
131
|
FileList files;
|
110
|
|
- mydata.num_page = max(1,ceil(float(files.count()) / files_per_page));
|
|
132
|
+ mydata.num_page = max(1,ceil(float(files.count()) / FILES_PER_PAGE));
|
111
|
133
|
mydata.cur_page = min(mydata.cur_page, mydata.num_page-1);
|
112
|
134
|
mydata.flags.is_root = files.isAtRootDir();
|
113
|
135
|
|
114
|
|
- #undef MARGIN_T
|
115
|
|
- #undef MARGIN_B
|
116
|
|
- #define MARGIN_T 0
|
117
|
|
- #define MARGIN_B 0
|
118
|
|
- uint16_t fileIndex = mydata.cur_page * files_per_page;
|
119
|
|
- for (uint8_t i = 0; i < files_per_page; i++, fileIndex++) {
|
120
|
|
- if (files.seek(fileIndex)) {
|
|
136
|
+ uint16_t fileIndex = mydata.cur_page * FILES_PER_PAGE;
|
|
137
|
+ for (uint8_t i = 0; i < FILES_PER_PAGE; i++, fileIndex++) {
|
|
138
|
+ if (files.seek(fileIndex))
|
121
|
139
|
drawFileButton(files.filename(), getTagForLine(i), files.isDir(), false);
|
122
|
|
- }
|
123
|
|
- else {
|
|
140
|
+ else
|
124
|
141
|
break;
|
125
|
|
- }
|
126
|
142
|
}
|
127
|
143
|
}
|
128
|
144
|
|
129
|
145
|
void FilesScreen::drawHeader() {
|
130
|
|
- const bool prev_enabled = mydata.cur_page > 0;
|
131
|
|
- const bool next_enabled = mydata.cur_page < (mydata.num_page - 1);
|
132
|
|
-
|
133
|
|
- #undef MARGIN_T
|
134
|
|
- #undef MARGIN_B
|
135
|
|
- #define MARGIN_T 0
|
136
|
|
- #define MARGIN_B 2
|
137
|
|
-
|
138
|
146
|
char str[16];
|
139
|
|
- sprintf_P(str, PSTR("Page %d of %d"),
|
140
|
|
- mydata.cur_page + 1, mydata.num_page);
|
|
147
|
+ sprintf_P(str, PSTR("Page %d of %d"), mydata.cur_page + 1, mydata.num_page);
|
141
|
148
|
|
142
|
149
|
CommandProcessor cmd;
|
143
|
150
|
cmd.colors(normal_btn)
|
144
|
151
|
.font(font_small)
|
145
|
|
- .tag(0).button(BTN_POS(2,1), BTN_SIZE(4,header_h), str, OPT_CENTER | OPT_FLAT)
|
146
|
|
- .font(font_medium)
|
147
|
|
- .colors(action_btn)
|
148
|
|
- .tag(241).enabled(prev_enabled).button(BTN_POS(1,1), BTN_SIZE(1,header_h), F("<"))
|
149
|
|
- .tag(242).enabled(next_enabled).button(BTN_POS(6,1), BTN_SIZE(1,header_h), F(">"));
|
|
152
|
+ .tag(0).button(HEAD_POS, str, OPT_CENTER | OPT_FLAT);
|
|
153
|
+}
|
|
154
|
+
|
|
155
|
+void FilesScreen::drawArrows() {
|
|
156
|
+ const bool prev_enabled = mydata.cur_page > 0;
|
|
157
|
+ const bool next_enabled = mydata.cur_page < (mydata.num_page - 1);
|
|
158
|
+
|
|
159
|
+ CommandProcessor cmd;
|
|
160
|
+ cmd.colors(normal_btn);
|
|
161
|
+ cmd.tag(242).enabled(prev_enabled).button(PREV_POS, F("")); if (prev_enabled) drawArrow(PREV_POS, PREV_DIR);
|
|
162
|
+ cmd.tag(243).enabled(next_enabled).button(NEXT_POS, F("")); if (next_enabled) drawArrow(NEXT_POS, NEXT_DIR);
|
150
|
163
|
}
|
151
|
164
|
|
152
|
165
|
void FilesScreen::drawFooter() {
|
153
|
|
- #undef MARGIN_T
|
154
|
|
- #undef MARGIN_B
|
155
|
|
- #if ENABLED(TOUCH_UI_PORTRAIT)
|
156
|
|
- #define MARGIN_T 15
|
157
|
|
- #define MARGIN_B 5
|
158
|
|
- #else
|
159
|
|
- #define MARGIN_T 5
|
160
|
|
- #define MARGIN_B 5
|
161
|
|
- #endif
|
162
|
|
- const bool has_selection = mydata.selected_tag != 0xFF;
|
163
|
|
- const uint8_t back_tag = mydata.flags.is_root ? 240 : 245;
|
164
|
|
- const uint8_t y = GRID_ROWS - footer_h + 1;
|
165
|
|
- const uint8_t h = footer_h;
|
|
166
|
+ const bool has_selection = mydata.selected_tag != 0xFF;
|
166
|
167
|
|
167
|
168
|
CommandProcessor cmd;
|
168
|
169
|
cmd.colors(normal_btn)
|
169
|
170
|
.font(font_medium)
|
170
|
|
- .colors(has_selection ? normal_btn : action_btn)
|
171
|
|
- .tag(back_tag).button(BTN_POS(4,y), BTN_SIZE(3,h), GET_TEXT_F(MSG_BUTTON_DONE))
|
172
|
|
- .enabled(has_selection)
|
|
171
|
+ .colors(has_selection ? normal_btn : action_btn);
|
|
172
|
+
|
|
173
|
+ if (mydata.flags.is_root)
|
|
174
|
+ cmd.tag(240).button(BTN2_POS, GET_TEXT_F(MSG_BUTTON_DONE));
|
|
175
|
+ else
|
|
176
|
+ cmd.tag(245).button(BTN2_POS, F("Up Dir"));
|
|
177
|
+
|
|
178
|
+ cmd.enabled(has_selection)
|
173
|
179
|
.colors(has_selection ? action_btn : normal_btn);
|
174
|
180
|
|
175
|
181
|
if (mydata.flags.is_dir)
|
176
|
|
- cmd.tag(244).button(BTN_POS(1, y), BTN_SIZE(3,h), GET_TEXT_F(MSG_BUTTON_OPEN));
|
|
182
|
+ cmd.tag(244).button(BTN1_POS, GET_TEXT_F(MSG_BUTTON_OPEN));
|
177
|
183
|
else
|
178
|
|
- cmd.tag(243).button(BTN_POS(1, y), BTN_SIZE(3,h), GET_TEXT_F(MSG_BUTTON_PRINT));
|
|
184
|
+ cmd.tag(241).button(BTN1_POS, GET_TEXT_F(MSG_BUTTON_PRINT));
|
|
185
|
+}
|
|
186
|
+
|
|
187
|
+void FilesScreen::drawFileButton(const char *filename, uint8_t tag, bool is_dir, bool is_highlighted) {
|
|
188
|
+ #undef MARGIN_L
|
|
189
|
+ #undef MARGIN_R
|
|
190
|
+ #define MARGIN_L 0
|
|
191
|
+ #define MARGIN_R 0
|
|
192
|
+ drawFileButton(LIST_POS, filename, tag, is_dir, is_highlighted);
|
179
|
193
|
}
|
180
|
194
|
|
181
|
195
|
void FilesScreen::onRedraw(draw_mode_t what) {
|
182
|
196
|
if (what & FOREGROUND) {
|
183
|
197
|
drawHeader();
|
|
198
|
+ drawArrows();
|
184
|
199
|
drawSelectedFile();
|
185
|
200
|
drawFooter();
|
186
|
201
|
}
|
|
@@ -200,48 +215,50 @@ void FilesScreen::gotoPage(uint8_t page) {
|
200
|
215
|
|
201
|
216
|
bool FilesScreen::onTouchEnd(uint8_t tag) {
|
202
|
217
|
switch (tag) {
|
203
|
|
- case 240: GOTO_PREVIOUS(); return true;
|
204
|
|
- case 241:
|
|
218
|
+ case 240: // Done button
|
|
219
|
+ GOTO_PREVIOUS();
|
|
220
|
+ return true;
|
|
221
|
+ case 241: // Print highlighted file
|
|
222
|
+ ConfirmStartPrintDialogBox::show(getSelectedFileIndex());
|
|
223
|
+ return true;
|
|
224
|
+ case 242: // Previous page
|
205
|
225
|
if (mydata.cur_page > 0) {
|
206
|
226
|
gotoPage(mydata.cur_page-1);
|
207
|
227
|
}
|
208
|
228
|
break;
|
209
|
|
- case 242:
|
|
229
|
+ case 243: // Next page
|
210
|
230
|
if (mydata.cur_page < (mydata.num_page-1)) {
|
211
|
231
|
gotoPage(mydata.cur_page+1);
|
212
|
232
|
}
|
213
|
233
|
break;
|
214
|
|
- case 243:
|
215
|
|
- ConfirmStartPrintDialogBox::show(getSelectedFileIndex());
|
216
|
|
- return true;
|
217
|
|
- case 244:
|
|
234
|
+ case 244: // Select directory
|
218
|
235
|
{
|
219
|
236
|
FileList files;
|
220
|
237
|
files.changeDir(getSelectedShortFilename());
|
221
|
238
|
gotoPage(0);
|
222
|
239
|
}
|
223
|
240
|
break;
|
224
|
|
- case 245:
|
|
241
|
+ case 245: // Up directory
|
225
|
242
|
{
|
226
|
243
|
FileList files;
|
227
|
244
|
files.upDir();
|
228
|
245
|
gotoPage(0);
|
229
|
246
|
}
|
230
|
247
|
break;
|
231
|
|
- default:
|
|
248
|
+ default: // File selected
|
232
|
249
|
if (tag < 240) {
|
233
|
250
|
mydata.selected_tag = tag;
|
234
|
251
|
#if ENABLED(SCROLL_LONG_FILENAMES) && (FTDI_API_LEVEL >= 810)
|
|
252
|
+ mydata.scroll_pos = 0;
|
|
253
|
+ mydata.scroll_max = 0;
|
235
|
254
|
if (FTDI::ftdi_chip >= 810) {
|
236
|
255
|
const char *longFilename = getSelectedLongFilename();
|
237
|
256
|
if (longFilename[0]) {
|
238
|
257
|
CommandProcessor cmd;
|
239
|
|
- uint16_t text_width = cmd.font(font_medium).text_width(longFilename);
|
240
|
|
- mydata.scroll_pos = 0;
|
241
|
|
- if (text_width > display_width)
|
242
|
|
- mydata.scroll_max = text_width - display_width + MARGIN_L + MARGIN_R;
|
243
|
|
- else
|
244
|
|
- mydata.scroll_max = 0;
|
|
258
|
+ constexpr int dim[4] = {LIST_POS};
|
|
259
|
+ const uint16_t text_width = cmd.font(font_medium).text_width(longFilename);
|
|
260
|
+ if (text_width > dim[2])
|
|
261
|
+ mydata.scroll_max = text_width - dim[2] + MARGIN_L + MARGIN_R + 10;
|
245
|
262
|
}
|
246
|
263
|
}
|
247
|
264
|
#endif
|