From ab03c9a56063c4ae0e27f46a5622ffe1564b0c1b Mon Sep 17 00:00:00 2001 From: Marcio T Date: Sun, 29 Aug 2021 16:03:10 -0600 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Enhance=20and=20fix=20FTDI?= =?UTF-8?q?=20Eve=20Touch=20UI=20file=20select=20(#22651)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ftdi_eve_lib/extended/arrows.cpp | 52 +++++ .../ftdi_eve_lib/extended/arrows.h | 28 +++ .../ftdi_eve_lib/extended/ftdi_extended.h | 1 + .../ftdi_eve_lib/extended/grid_layout.h | 36 ++-- .../generic/bed_mesh_view_screen.cpp | 6 - .../generic/bed_mesh_view_screen.h | 1 - .../generic/files_screen.cpp | 181 ++++++++++-------- .../ftdi_eve_touch_ui/generic/files_screen.h | 12 +- .../generic/leveling_menu.cpp | 5 +- 9 files changed, 209 insertions(+), 113 deletions(-) create mode 100644 Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/arrows.cpp create mode 100644 Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/arrows.h diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/arrows.cpp b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/arrows.cpp new file mode 100644 index 0000000000..0a45c0d339 --- /dev/null +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/arrows.cpp @@ -0,0 +1,52 @@ +/************** + * arrows.cpp * + **************/ + +/**************************************************************************** + * Written By Marcio Teixeira 2021 - SynDaver 3D * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * To view a copy of the GNU General Public License, go to the following * + * location: . * + ****************************************************************************/ + +#include "ftdi_extended.h" + +#if ENABLED(FTDI_EXTENDED) + +#define COORD(X,Y) cx + s*(swapXY ? Y : (flipX ? -X : X)), cy + s*(swapXY ? (flipX ? -X : X) : Y) + +namespace FTDI { + + void drawArrow(int x, int y, int w, int h, Direction direction) { + const bool swapXY = direction == UP || direction == DOWN; + const bool flipX = direction == UP || direction == LEFT; + const int s = min(w,h); + const int cx = (x + w/2)*16; + const int cy = (y + h/2)*16; + + CommandProcessor cmd; + cmd.cmd(SAVE_CONTEXT()) + .cmd(LINE_WIDTH(s/2)) + .cmd(BEGIN(LINES)) + .cmd(VERTEX2F(COORD( 5, 0))) + .cmd(VERTEX2F(COORD( 2,-2))) + .cmd(VERTEX2F(COORD( 5, 0))) + .cmd(VERTEX2F(COORD( 2, 2))) + .cmd(VERTEX2F(COORD( 5, 0))) + .cmd(VERTEX2F(COORD(-5, 0))) + .cmd(RESTORE_CONTEXT()); + } + +} // namespace FTDI + +#endif // FTDI_EXTENDED diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/arrows.h b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/arrows.h new file mode 100644 index 0000000000..e9592d47a0 --- /dev/null +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/arrows.h @@ -0,0 +1,28 @@ +/************ + * arrows.h * + ************/ + +/**************************************************************************** + * Written By Marcio Teixeira 2021 - SynDaver 3D * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * To view a copy of the GNU General Public License, go to the following * + * location: . * + ****************************************************************************/ + +#pragma once + +namespace FTDI { + enum Direction {UP, DOWN, LEFT, RIGHT}; + + void drawArrow(int x, int y, int w, int h, Direction direction); +} diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/ftdi_extended.h b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/ftdi_extended.h index bf9858f6eb..e99c798eea 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/ftdi_extended.h +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/ftdi_extended.h @@ -48,6 +48,7 @@ #include "sound_list.h" #include "polygon.h" #include "poly_ui.h" + #include "arrows.h" #include "text_box.h" #include "text_ellipsis.h" #include "adjuster_widget.h" diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/grid_layout.h b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/grid_layout.h index dd94685c98..813f4f0484 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/grid_layout.h +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/grid_layout.h @@ -54,23 +54,33 @@ #define EDGE_L 0 #define EDGE_R 0 -// GRID_X and GRID_Y computes the positions of the divisions on +// _GRID_X and _GRID_Y computes the positions of the divisions on // the layout grid. -#define GRID_X(x) ((x)*(FTDI::display_width-EDGE_R-EDGE_L)/GRID_COLS+EDGE_L) -#define GRID_Y(y) ((y)*(FTDI::display_height-EDGE_B-EDGE_T)/GRID_ROWS+EDGE_T) +#define _GRID_X(x) ((x)*(FTDI::display_width-EDGE_R-EDGE_L)/GRID_COLS+EDGE_L) +#define _GRID_Y(y) ((y)*(FTDI::display_height-EDGE_B-EDGE_T)/GRID_ROWS+EDGE_T) + +// BOX_X, BOX_Y, BOX_W and BOX_X returns the top-left and width +// and height of position on the grid. + +#define BOX_X(x) (_GRID_X((x)-1)) +#define BOX_Y(y) (_GRID_Y((y)-1)) +#define BOX_W(w) (_GRID_X(w) - _GRID_X(0)) +#define BOX_H(h) (_GRID_Y(h) - _GRID_Y(0)) // BTN_X, BTN_Y, BTN_W and BTN_X returns the top-left and width // and height of a button, taking into account the button margins. -#define BTN_X(x) (GRID_X((x)-1) + MARGIN_L) -#define BTN_Y(y) (GRID_Y((y)-1) + MARGIN_T) -#define BTN_W(w) (GRID_X(w) - GRID_X(0) - MARGIN_L - MARGIN_R) -#define BTN_H(h) (GRID_Y(h) - GRID_Y(0) - MARGIN_T - MARGIN_B) +#define BTN_X(x) (BOX_X(x) + MARGIN_L) +#define BTN_Y(y) (BOX_Y(y) + MARGIN_T) +#define BTN_W(w) (BOX_W(w) - MARGIN_L - MARGIN_R) +#define BTN_H(h) (BOX_H(h) - MARGIN_T - MARGIN_B) -// Abbreviations for common phrases, to allow a button to be -// defined in one line of source. +// Abbreviations for common phrases, to allow a box or button +// to be defined in one line of source. #define BTN_POS(x,y) BTN_X(x), BTN_Y(y) #define BTN_SIZE(w,h) BTN_W(w), BTN_H(h) +#define BOX_POS(x,y) BOX_X(x), BOX_Y(y) +#define BOX_SIZE(w,h) BOX_W(w), BOX_H(h) // Draw a reference grid for ease of spacing out widgets. #define DRAW_LAYOUT_GRID \ @@ -78,13 +88,13 @@ cmd.cmd(LINE_WIDTH(4)); \ for (int i = 1; i <= GRID_COLS; i++) { \ cmd.cmd(BEGIN(LINES)); \ - cmd.cmd(VERTEX2F(GRID_X(i) *16, 0 *16)); \ - cmd.cmd(VERTEX2F(GRID_X(i) *16, FTDI::display_height *16)); \ + cmd.cmd(VERTEX2F(_GRID_X(i) *16, 0 *16)); \ + cmd.cmd(VERTEX2F(_GRID_X(i) *16, FTDI::display_height *16)); \ } \ for (int i = 1; i < GRID_ROWS; i++) { \ cmd.cmd(BEGIN(LINES)); \ - cmd.cmd(VERTEX2F(0 *16, GRID_Y(i) *16)); \ - cmd.cmd(VERTEX2F(FTDI::display_width *16, GRID_Y(i) *16)); \ + cmd.cmd(VERTEX2F(0 *16, _GRID_Y(i) *16)); \ + cmd.cmd(VERTEX2F(FTDI::display_width *16, _GRID_Y(i) *16)); \ } \ cmd.cmd(LINE_WIDTH(16)); \ } diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/bed_mesh_view_screen.cpp b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/bed_mesh_view_screen.cpp index 552cd831ea..8db2d2ef70 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/bed_mesh_view_screen.cpp +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/bed_mesh_view_screen.cpp @@ -157,12 +157,6 @@ void BedMeshViewScreen::doProbe() { injectCommands_P(PSTR(BED_LEVELING_COMMANDS)); } -void BedMeshViewScreen::doMeshValidation() { - mydata.count = 0; - GOTO_SCREEN(StatusScreen); - injectCommands_P(PSTR("G28\nM117 Heating...\nG26 R X0 Y0\nG27")); -} - void BedMeshViewScreen::show() { injectCommands_P(PSTR("G29 L1")); GOTO_SCREEN(BedMeshViewScreen); diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/bed_mesh_view_screen.h b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/bed_mesh_view_screen.h index 0bb88f7f96..90a90c233e 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/bed_mesh_view_screen.h +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/bed_mesh_view_screen.h @@ -43,6 +43,5 @@ class BedMeshViewScreen : public BedMeshBase, public CachedScreen "), OPT_CENTERY | OPT_RIGHTX); - } + draw_text_with_ellipsis(cmd, bx,by, bw - (is_dir ? 20 : 0), bh, filename, OPT_CENTERY, font_medium); + if (is_dir && !is_highlighted) cmd.text(bx, by, bw, bh, F("> "), OPT_CENTERY | OPT_RIGHTX); #if ENABLED(SCROLL_LONG_FILENAMES) - if (is_highlighted) { - cmd.cmd(RESTORE_CONTEXT()); - } + if (is_highlighted) cmd.cmd(RESTORE_CONTEXT()); #endif } void FilesScreen::drawFileList() { FileList files; - mydata.num_page = max(1,ceil(float(files.count()) / files_per_page)); + mydata.num_page = max(1,ceil(float(files.count()) / FILES_PER_PAGE)); mydata.cur_page = min(mydata.cur_page, mydata.num_page-1); mydata.flags.is_root = files.isAtRootDir(); - #undef MARGIN_T - #undef MARGIN_B - #define MARGIN_T 0 - #define MARGIN_B 0 - uint16_t fileIndex = mydata.cur_page * files_per_page; - for (uint8_t i = 0; i < files_per_page; i++, fileIndex++) { - if (files.seek(fileIndex)) { + uint16_t fileIndex = mydata.cur_page * FILES_PER_PAGE; + for (uint8_t i = 0; i < FILES_PER_PAGE; i++, fileIndex++) { + if (files.seek(fileIndex)) drawFileButton(files.filename(), getTagForLine(i), files.isDir(), false); - } - else { + else break; - } } } void FilesScreen::drawHeader() { - const bool prev_enabled = mydata.cur_page > 0; - const bool next_enabled = mydata.cur_page < (mydata.num_page - 1); - - #undef MARGIN_T - #undef MARGIN_B - #define MARGIN_T 0 - #define MARGIN_B 2 - char str[16]; - sprintf_P(str, PSTR("Page %d of %d"), - mydata.cur_page + 1, mydata.num_page); + sprintf_P(str, PSTR("Page %d of %d"), mydata.cur_page + 1, mydata.num_page); CommandProcessor cmd; cmd.colors(normal_btn) .font(font_small) - .tag(0).button(BTN_POS(2,1), BTN_SIZE(4,header_h), str, OPT_CENTER | OPT_FLAT) - .font(font_medium) - .colors(action_btn) - .tag(241).enabled(prev_enabled).button(BTN_POS(1,1), BTN_SIZE(1,header_h), F("<")) - .tag(242).enabled(next_enabled).button(BTN_POS(6,1), BTN_SIZE(1,header_h), F(">")); + .tag(0).button(HEAD_POS, str, OPT_CENTER | OPT_FLAT); +} + +void FilesScreen::drawArrows() { + const bool prev_enabled = mydata.cur_page > 0; + const bool next_enabled = mydata.cur_page < (mydata.num_page - 1); + + CommandProcessor cmd; + cmd.colors(normal_btn); + cmd.tag(242).enabled(prev_enabled).button(PREV_POS, F("")); if (prev_enabled) drawArrow(PREV_POS, PREV_DIR); + cmd.tag(243).enabled(next_enabled).button(NEXT_POS, F("")); if (next_enabled) drawArrow(NEXT_POS, NEXT_DIR); } void FilesScreen::drawFooter() { - #undef MARGIN_T - #undef MARGIN_B - #if ENABLED(TOUCH_UI_PORTRAIT) - #define MARGIN_T 15 - #define MARGIN_B 5 - #else - #define MARGIN_T 5 - #define MARGIN_B 5 - #endif - const bool has_selection = mydata.selected_tag != 0xFF; - const uint8_t back_tag = mydata.flags.is_root ? 240 : 245; - const uint8_t y = GRID_ROWS - footer_h + 1; - const uint8_t h = footer_h; + const bool has_selection = mydata.selected_tag != 0xFF; CommandProcessor cmd; cmd.colors(normal_btn) .font(font_medium) - .colors(has_selection ? normal_btn : action_btn) - .tag(back_tag).button(BTN_POS(4,y), BTN_SIZE(3,h), GET_TEXT_F(MSG_BUTTON_DONE)) - .enabled(has_selection) + .colors(has_selection ? normal_btn : action_btn); + + if (mydata.flags.is_root) + cmd.tag(240).button(BTN2_POS, GET_TEXT_F(MSG_BUTTON_DONE)); + else + cmd.tag(245).button(BTN2_POS, F("Up Dir")); + + cmd.enabled(has_selection) .colors(has_selection ? action_btn : normal_btn); if (mydata.flags.is_dir) - cmd.tag(244).button(BTN_POS(1, y), BTN_SIZE(3,h), GET_TEXT_F(MSG_BUTTON_OPEN)); + cmd.tag(244).button(BTN1_POS, GET_TEXT_F(MSG_BUTTON_OPEN)); else - cmd.tag(243).button(BTN_POS(1, y), BTN_SIZE(3,h), GET_TEXT_F(MSG_BUTTON_PRINT)); + cmd.tag(241).button(BTN1_POS, GET_TEXT_F(MSG_BUTTON_PRINT)); +} + +void FilesScreen::drawFileButton(const char *filename, uint8_t tag, bool is_dir, bool is_highlighted) { + #undef MARGIN_L + #undef MARGIN_R + #define MARGIN_L 0 + #define MARGIN_R 0 + drawFileButton(LIST_POS, filename, tag, is_dir, is_highlighted); } void FilesScreen::onRedraw(draw_mode_t what) { if (what & FOREGROUND) { drawHeader(); + drawArrows(); drawSelectedFile(); drawFooter(); } @@ -200,48 +215,50 @@ void FilesScreen::gotoPage(uint8_t page) { bool FilesScreen::onTouchEnd(uint8_t tag) { switch (tag) { - case 240: GOTO_PREVIOUS(); return true; - case 241: + case 240: // Done button + GOTO_PREVIOUS(); + return true; + case 241: // Print highlighted file + ConfirmStartPrintDialogBox::show(getSelectedFileIndex()); + return true; + case 242: // Previous page if (mydata.cur_page > 0) { gotoPage(mydata.cur_page-1); } break; - case 242: + case 243: // Next page if (mydata.cur_page < (mydata.num_page-1)) { gotoPage(mydata.cur_page+1); } break; - case 243: - ConfirmStartPrintDialogBox::show(getSelectedFileIndex()); - return true; - case 244: + case 244: // Select directory { FileList files; files.changeDir(getSelectedShortFilename()); gotoPage(0); } break; - case 245: + case 245: // Up directory { FileList files; files.upDir(); gotoPage(0); } break; - default: + default: // File selected if (tag < 240) { mydata.selected_tag = tag; #if ENABLED(SCROLL_LONG_FILENAMES) && (FTDI_API_LEVEL >= 810) + mydata.scroll_pos = 0; + mydata.scroll_max = 0; if (FTDI::ftdi_chip >= 810) { const char *longFilename = getSelectedLongFilename(); if (longFilename[0]) { CommandProcessor cmd; - uint16_t text_width = cmd.font(font_medium).text_width(longFilename); - mydata.scroll_pos = 0; - if (text_width > display_width) - mydata.scroll_max = text_width - display_width + MARGIN_L + MARGIN_R; - else - mydata.scroll_max = 0; + constexpr int dim[4] = {LIST_POS}; + const uint16_t text_width = cmd.font(font_medium).text_width(longFilename); + if (text_width > dim[2]) + mydata.scroll_max = text_width - dim[2] + MARGIN_L + MARGIN_R + 10; } } #endif diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/files_screen.h b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/files_screen.h index be75684ceb..bf2b415364 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/files_screen.h +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/files_screen.h @@ -41,16 +41,6 @@ struct FilesScreenData { class FilesScreen : public BaseScreen, public CachedScreen { private: - #if ENABLED(TOUCH_UI_PORTRAIT) - static constexpr uint8_t header_h = 2; - static constexpr uint8_t footer_h = 2; - static constexpr uint8_t files_per_page = 11; - #else - static constexpr uint8_t header_h = 1; - static constexpr uint8_t footer_h = 1; - static constexpr uint8_t files_per_page = 6; - #endif - static uint8_t getTagForLine(uint8_t line) {return line + 2;} static uint8_t getLineForTag(uint8_t tag) {return tag - 2;} static uint16_t getFileForTag(uint8_t tag); @@ -60,9 +50,11 @@ class FilesScreen : public BaseScreen, public CachedScreen