FTDI Touch UI fix and reorganize (#21487)

This commit is contained in:
Marcio T 2021-03-30 20:23:43 -06:00 committed by GitHub
parent 20d2061f22
commit 7573524a14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 184 additions and 156 deletions

View File

@ -19,10 +19,9 @@
* location: <https://www.gnu.org/licenses/>. *
****************************************************************************/
#include "../ftdi_eve_lib.h"
#include "../extended/grid_layout.h"
#include "ftdi_extended.h"
#include "adjuster_widget.h"
#if ENABLED(FTDI_EXTENDED)
#define SUB_COLS 9
#define SUB_ROWS 1
@ -30,28 +29,32 @@
#define INC_POS SUB_POS(6,1), SUB_SIZE(2,1)
#define DEC_POS SUB_POS(8,1), SUB_SIZE(2,1)
void draw_adjuster_value(CommandProcessor& cmd, int16_t x, int16_t y, int16_t w, int16_t h, float value, progmem_str units, int8_t width, uint8_t precision) {
char str[width + precision + 10 + (units ? strlen_P((const char*) units) : 0)];
if (isnan(value))
strcpy_P(str, PSTR("-"));
else
dtostrf(value, width, precision, str);
namespace FTDI {
void draw_adjuster_value(CommandProcessor& cmd, int16_t x, int16_t y, int16_t w, int16_t h, float value, progmem_str units, int8_t width, uint8_t precision) {
char str[width + precision + 10 + (units ? strlen_P((const char*) units) : 0)];
if (isnan(value))
strcpy_P(str, PSTR("-"));
else
dtostrf(value, width, precision, str);
if (units) {
strcat_P(str, PSTR(" "));
strcat_P(str, (const char*) units);
if (units) {
strcat_P(str, PSTR(" "));
strcat_P(str, (const char*) units);
}
cmd.text(VAL_POS, str);
}
cmd.text(VAL_POS, str);
}
void draw_adjuster(CommandProcessor& cmd, int16_t x, int16_t y, int16_t w, int16_t h, uint8_t tag, float value, progmem_str units, int8_t width, uint8_t precision, draw_mode_t what) {
if (what & BACKGROUND)
cmd.tag(0).button(VAL_POS, F(""), FTDI::OPT_FLAT);
void draw_adjuster(CommandProcessor& cmd, int16_t x, int16_t y, int16_t w, int16_t h, uint8_t tag, float value, progmem_str units, int8_t width, uint8_t precision, draw_mode_t what) {
if (what & BACKGROUND)
cmd.tag(0).button(VAL_POS, F(""), FTDI::OPT_FLAT);
if (what & FOREGROUND) {
draw_adjuster_value(cmd, x, y, w, h, value, units, width, precision);
cmd.tag(tag ).button(INC_POS, F("-"))
.tag(tag+1).button(DEC_POS, F("+"));
if (what & FOREGROUND) {
draw_adjuster_value(cmd, x, y, w, h, value, units, width, precision);
cmd.tag(tag ).button(INC_POS, F("-"))
.tag(tag+1).button(DEC_POS, F("+"));
}
}
}
} // namespace FTDI
#endif // FTDI_EXTENDED

View File

@ -20,20 +20,21 @@
****************************************************************************/
#pragma once
#include "../extended/screen_types.h"
void draw_adjuster_value(
CommandProcessor& cmd,
int16_t x, int16_t y, int16_t w, int16_t h,
float value, progmem_str units = nullptr,
int8_t width = 5, uint8_t precision = 1
);
namespace FTDI {
void draw_adjuster_value(
CommandProcessor& cmd,
int16_t x, int16_t y, int16_t w, int16_t h,
float value, progmem_str units = nullptr,
int8_t width = 5, uint8_t precision = 1
);
void draw_adjuster(
CommandProcessor& cmd,
int16_t x, int16_t y, int16_t w, int16_t h,
uint8_t tag,
float value, progmem_str units = nullptr,
int8_t width = 5, uint8_t precision = 1,
draw_mode_t what = BOTH
);
void draw_adjuster(
CommandProcessor& cmd,
int16_t x, int16_t y, int16_t w, int16_t h,
uint8_t tag,
float value, progmem_str units = nullptr,
int8_t width = 5, uint8_t precision = 1,
draw_mode_t what = BOTH
);
}

View File

@ -0,0 +1,108 @@
/*************************
* circular_progress.cpp *
*************************/
/****************************************************************************
* Written By Marcio Teixeira 2019 - Aleph Objects, Inc. *
* *
* 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: <https://www.gnu.org/licenses/>. *
****************************************************************************/
#include "ftdi_extended.h"
#if ENABLED(FTDI_EXTENDED)
/* This function draws a circular progress "ring" */
namespace FTDI {
void draw_circular_progress(CommandProcessor& cmd, int x, int y, int w, int h, float percent, char *text, uint32_t bgcolor, uint32_t fgcolor) {
const float rim = 0.3;
const float a = percent/100.0*2.0*PI;
const float a1 = min(PI/2, a);
const float a2 = min(PI/2, a-a1);
const float a3 = min(PI/2, a-a1-a2);
const float a4 = min(PI/2, a-a1-a2-a3);
const int ro = min(w,h) * 8;
const int rr = ro * rim;
const int cx = x * 16 + w * 8;
const int cy = y * 16 + h * 8;
// Load a rim shape into stencil buffer
cmd.cmd(SAVE_CONTEXT());
cmd.cmd(TAG_MASK(0));
cmd.cmd(CLEAR(0,1,0));
cmd.cmd(COLOR_MASK(0,0,0,0));
cmd.cmd(STENCIL_OP(STENCIL_OP_KEEP, STENCIL_OP_INVERT));
cmd.cmd(STENCIL_FUNC(STENCIL_FUNC_ALWAYS, 255, 255));
cmd.cmd(BEGIN(POINTS));
cmd.cmd(POINT_SIZE(ro));
cmd.cmd(VERTEX2F(cx, cy));
cmd.cmd(POINT_SIZE(ro - rr));
cmd.cmd(VERTEX2F(cx, cy));
cmd.cmd(RESTORE_CONTEXT());
// Mask further drawing by stencil buffer
cmd.cmd(SAVE_CONTEXT());
cmd.cmd(STENCIL_FUNC(STENCIL_FUNC_NOTEQUAL, 0, 255));
// Fill the background
cmd.cmd(COLOR_RGB(bgcolor));
cmd.cmd(BEGIN(POINTS));
cmd.cmd(POINT_SIZE(ro));
cmd.cmd(VERTEX2F(cx, cy));
cmd.cmd(COLOR_RGB(fgcolor));
// Paint upper-right quadrant
cmd.cmd(BEGIN(EDGE_STRIP_A));
cmd.cmd(VERTEX2F(cx, cy));
cmd.cmd(VERTEX2F(cx + ro*sin(a1) + 16,cy - ro*cos(a1) + 8));
// Paint lower-right quadrant
if (a > PI/2) {
cmd.cmd(BEGIN(EDGE_STRIP_R));
cmd.cmd(VERTEX2F(cx, cy));
cmd.cmd(VERTEX2F(cx + ro*cos(a2),cy + ro*sin(a2) + 16));
}
// Paint lower-left quadrant
if (a > PI) {
cmd.cmd(BEGIN(EDGE_STRIP_B));
cmd.cmd(VERTEX2F(cx, cy));
cmd.cmd(VERTEX2F(cx - ro*sin(a3) - 8,cy + ro*cos(a3)));
}
// Paint upper-left quadrant
if (a > 1.5*PI) {
cmd.cmd(BEGIN(EDGE_STRIP_L));
cmd.cmd(VERTEX2F(cx, cy));
cmd.cmd(VERTEX2F(cx - ro*cos(a4),cy - ro*sin(a4)));
}
cmd.cmd(RESTORE_CONTEXT());
// Draw the text
cmd.cmd(SAVE_CONTEXT());
cmd.cmd(COLOR_RGB(fgcolor));
cmd.text(x,y,w,h,text, OPT_CENTERX | OPT_CENTERY);
cmd.cmd(RESTORE_CONTEXT());
}
void draw_circular_progress(CommandProcessor& cmd, int x, int y, int w, int h, float percent, uint32_t bgcolor, uint32_t fgcolor) {
char str[5];
sprintf(str,"%d\%%",int(percent));
draw_circular_progress(cmd, x, y, w, h, percent, str, bgcolor, fgcolor);
}
} // namespace FTDI
#endif // FTDI_EXTENDED

View File

@ -0,0 +1,27 @@
/***********************
* circular_progress.h *
***********************/
/****************************************************************************
* Written By Marcio Teixeira 2019 - Aleph Objects, Inc. *
* *
* 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: <https://www.gnu.org/licenses/>. *
****************************************************************************/
#pragma once
namespace FTDI {
void draw_circular_progress(CommandProcessor& cmd, int x, int y, int w, int h, float percent, char *text, uint32_t bgcolor, uint32_t fgcolor);
void draw_circular_progress(CommandProcessor& cmd, int x, int y, int w, int h, float percent, uint32_t bgcolor, uint32_t fgcolor);
}

View File

@ -47,6 +47,9 @@
#include "sound_player.h"
#include "sound_list.h"
#include "polygon.h"
#include "poly_ui.h"
#include "text_box.h"
#include "text_ellipsis.h"
#include "adjuster_widget.h"
#include "circular_progress.h"
#endif

View File

@ -1,105 +0,0 @@
/***********************
* circular_progress.h *
***********************/
/****************************************************************************
* Written By Marcio Teixeira 2019 - Aleph Objects, Inc. *
* *
* 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: <https://www.gnu.org/licenses/>. *
****************************************************************************/
#pragma once
/* This function draws a circular progress "ring" */
void draw_circular_progress(CommandProcessor& cmd, int x, int y, int w, int h, float percent, char *text, uint32_t bgcolor, uint32_t fgcolor) {
using namespace FTDI;
const float rim = 0.3;
const float a = percent/100.0*2.0*PI;
const float a1 = min(PI/2, a);
const float a2 = min(PI/2, a-a1);
const float a3 = min(PI/2, a-a1-a2);
const float a4 = min(PI/2, a-a1-a2-a3);
const int ro = min(w,h) * 8;
const int rr = ro * rim;
const int cx = x * 16 + w * 8;
const int cy = y * 16 + h * 8;
// Load a rim shape into stencil buffer
cmd.cmd(SAVE_CONTEXT());
cmd.cmd(TAG_MASK(0));
cmd.cmd(CLEAR(0,1,0));
cmd.cmd(COLOR_MASK(0,0,0,0));
cmd.cmd(STENCIL_OP(STENCIL_OP_KEEP, STENCIL_OP_INVERT));
cmd.cmd(STENCIL_FUNC(STENCIL_FUNC_ALWAYS, 255, 255));
cmd.cmd(BEGIN(POINTS));
cmd.cmd(POINT_SIZE(ro));
cmd.cmd(VERTEX2F(cx, cy));
cmd.cmd(POINT_SIZE(ro - rr));
cmd.cmd(VERTEX2F(cx, cy));
cmd.cmd(RESTORE_CONTEXT());
// Mask further drawing by stencil buffer
cmd.cmd(SAVE_CONTEXT());
cmd.cmd(STENCIL_FUNC(STENCIL_FUNC_NOTEQUAL, 0, 255));
// Fill the background
cmd.cmd(COLOR_RGB(bgcolor));
cmd.cmd(BEGIN(POINTS));
cmd.cmd(POINT_SIZE(ro));
cmd.cmd(VERTEX2F(cx, cy));
cmd.cmd(COLOR_RGB(fgcolor));
// Paint upper-right quadrant
cmd.cmd(BEGIN(EDGE_STRIP_A));
cmd.cmd(VERTEX2F(cx, cy));
cmd.cmd(VERTEX2F(cx + ro*sin(a1) + 16,cy - ro*cos(a1) + 8));
// Paint lower-right quadrant
if (a > PI/2) {
cmd.cmd(BEGIN(EDGE_STRIP_R));
cmd.cmd(VERTEX2F(cx, cy));
cmd.cmd(VERTEX2F(cx + ro*cos(a2),cy + ro*sin(a2) + 16));
}
// Paint lower-left quadrant
if (a > PI) {
cmd.cmd(BEGIN(EDGE_STRIP_B));
cmd.cmd(VERTEX2F(cx, cy));
cmd.cmd(VERTEX2F(cx - ro*sin(a3) - 8,cy + ro*cos(a3)));
}
// Paint upper-left quadrant
if (a > 1.5*PI) {
cmd.cmd(BEGIN(EDGE_STRIP_L));
cmd.cmd(VERTEX2F(cx, cy));
cmd.cmd(VERTEX2F(cx - ro*cos(a4),cy - ro*sin(a4)));
}
cmd.cmd(RESTORE_CONTEXT());
// Draw the text
cmd.cmd(SAVE_CONTEXT());
cmd.cmd(COLOR_RGB(fgcolor));
cmd.text(x,y,w,h,text, OPT_CENTERX | OPT_CENTERY);
cmd.cmd(RESTORE_CONTEXT());
}
void draw_circular_progress(CommandProcessor& cmd, int x, int y, int w, int h, float percent, uint32_t bgcolor, uint32_t fgcolor) {
char str[5];
sprintf(str,"%d\%%",int(percent));
draw_circular_progress(cmd, x, y, w, h, percent, str, bgcolor, fgcolor);
}

View File

@ -25,8 +25,6 @@
#ifdef FTDI_BED_MESH_SCREEN
#include "../ftdi_eve_lib/extras/adjuster_widget.h"
using namespace FTDI;
using namespace Theme;
using namespace ExtUI;

View File

@ -25,8 +25,6 @@
#ifdef FTDI_BIO_PRINTING_DIALOG_BOX
#include "../ftdi_eve_lib/extras/circular_progress.h"
using namespace FTDI;
using namespace ExtUI;
using namespace Theme;

View File

@ -26,8 +26,6 @@
#ifdef FTDI_BIO_STATUS_SCREEN
#include "../ftdi_eve_lib/extras/poly_ui.h"
#if ENABLED(TOUCH_UI_PORTRAIT)
#include "bio_printer_ui_portrait.h"
#else

View File

@ -26,7 +26,6 @@
#ifdef FTDI_BOOT_SCREEN
#include "../ftdi_eve_lib/extras/poly_ui.h"
#include "../archim2-flash/flash_storage.h"
#if ENABLED(SHOW_CUSTOM_BOOTSCREEN)

View File

@ -27,8 +27,6 @@
#ifdef FTDI_COCOA_LOAD_CHOCOLATE_SCREEN
#include "../ftdi_eve_lib/extras/poly_ui.h"
#include "cocoa_press_ui.h"
#define POLY(A) PolyUI::poly_reader_t(A, sizeof(A)/sizeof(A[0]))

View File

@ -25,8 +25,6 @@
#ifdef FTDI_COCOA_PREHEAT_SCREEN
#include "../ftdi_eve_lib/extras/circular_progress.h"
using namespace FTDI;
using namespace ExtUI;
using namespace Theme;

View File

@ -26,8 +26,6 @@
#ifdef FTDI_COCOA_STATUS_SCREEN
#include "../ftdi_eve_lib/extras/poly_ui.h"
#include "cocoa_press_ui.h"
#define POLY(A) PolyUI::poly_reader_t(A, sizeof(A)/sizeof(A[0]))

View File

@ -22,6 +22,8 @@
#pragma once
#if ENABLED(TOUCH_UI_FTDI_EVE)
#include "../ftdi_eve_lib/ftdi_eve_lib.h"
#include "../language/language.h"
#include "../theme/theme.h"
@ -260,3 +262,5 @@ enum {
#if NUM_LANGUAGES > 1
#include "language_menu.h"
#endif
#endif // TOUCH_UI_FTDI_EVE