Complete curve edition (#8106)

This commit is contained in:
3djc
2020-11-22 08:22:12 +01:00
committed by GitHub
parent 88d480e453
commit 462ed53f9a
5 changed files with 60 additions and 45 deletions
+3 -4
View File
@@ -19,8 +19,7 @@
*/ */
#ifndef _CURVE_H_ #pragma once
#define _CURVE_H_
#include "window.h" #include "window.h"
@@ -29,7 +28,8 @@ struct CurvePoint {
LcdFlags flags; LcdFlags flags;
}; };
class Curve: public Window { class Curve: public Window
{
friend class CurveEdit; friend class CurveEdit;
public: public:
@@ -75,4 +75,3 @@ class Curve: public Window {
coord_t getPointY(int y) const; coord_t getPointY(int y) const;
}; };
#endif // _CURVE_H_
+34 -22
View File
@@ -24,9 +24,10 @@
#define SET_DIRTY() storageDirty(EE_MODEL) #define SET_DIRTY() storageDirty(EE_MODEL)
CurveDataEdit::CurveDataEdit(Window * parent, const rect_t & rect, uint8_t index) : CurveDataEdit::CurveDataEdit(Window * parent, const rect_t & rect, uint8_t index, CurveEdit * curveEdit) :
FormGroup(parent, rect, FORM_FORWARD_FOCUS), FormGroup(parent, rect, FORM_FORWARD_FOCUS),
index(index) index(index),
curveEdit(curveEdit)
{ {
update(); update();
} }
@@ -52,30 +53,41 @@ void CurveDataEdit::update()
grid.spacer(rect.h / 3); grid.spacer(rect.h / 3);
// x value // x value
for (uint8_t i = 0; i < curvePointsCount; i++) { if (curve.type == CURVE_TYPE_CUSTOM) {
new StaticText(this, {i * boxWidth, 10 + boxHeight, boxWidth, boxHeight}, std::to_string(-100 + 200 * i / (5 + curve.points - 1)), 0, RIGHT | TEXT_DISABLE_COLOR); // Adjustable points for custom curves
for (uint8_t i = 0; i < curvePointsCount; i++) {
int8_t * points = curveAddress(index);
auto pointEdit = new NumberEdit(this, {coord_t(PAGE_LINE_SPACING + 1 + i * boxWidth), 10 + boxHeight, coord_t(boxWidth - PAGE_LINE_SPACING), boxHeight - 12},
i <= 1 ? -100 : points[curvePointsCount + i - 2],
i >= curvePointsCount - 2 ? 100 : points[curvePointsCount + i],
GET_VALUE(i == 0 ? -100 : i == curvePointsCount - 1 ? 100 : points[curvePointsCount + i - 1]),
[=](int32_t newValue) {
points[curvePointsCount + i - 1] = newValue;
SET_DIRTY();
curveEdit->updatePreview();
}, 0, RIGHT);
if (i == 0 || i == curvePointsCount - 1) {
pointEdit->disable();
}
}
}
else {
for (uint8_t i = 0; i < curvePointsCount; i++) {
new StaticText(this, {i * boxWidth, 10 + boxHeight, boxWidth, boxHeight}, std::to_string(-100 + 200 * i / (5 + curve.points - 1)), 0, RIGHT | TEXT_DISABLE_COLOR);
}
} }
// y value // y value
for (uint8_t i = 0; i < curvePointsCount; i++) { for (uint8_t i = 0; i < curvePointsCount; i++) {
int8_t * points = curveAddress(index); int8_t * points = curveAddress(index);
new NumberEdit(this, {coord_t(PAGE_LINE_SPACING + 1 + i * boxWidth), 10 + 2 * boxHeight, coord_t(boxWidth - PAGE_LINE_SPACING), boxHeight - 12}, -100, 100, GET_SET_DEFAULT(points[i]), 0, RIGHT); new NumberEdit(this, {coord_t(PAGE_LINE_SPACING + 1 + i * boxWidth), 10 + 2 * boxHeight, coord_t(boxWidth - PAGE_LINE_SPACING), boxHeight - 12}, -100, 100,
GET_VALUE(points[i]), [=](int32_t newValue) { points[i] = newValue; SET_DIRTY(); curveEdit->updatePreview(); }, 0, RIGHT);
} }
setInnerWidth(curvePointsCount * boxWidth); setInnerWidth(curvePointsCount * boxWidth);
} }
void CurveDataEdit::checkEvents()
{
Window::checkEvents();
CurveHeader & curve = g_model.curves[index];
uint8_t newValue = 5 + curve.points;
if (previousCurvePointsCount != newValue) {
previousCurvePointsCount = newValue;
update();
}
}
void CurveDataEdit::paint(BitmapBuffer * dc) void CurveDataEdit::paint(BitmapBuffer * dc)
{ {
dc->clear(DEFAULT_BGCOLOR); dc->clear(DEFAULT_BGCOLOR);
@@ -92,7 +104,7 @@ CurveEdit::CurveEdit(Window * parent, const rect_t & rect, uint8_t index) :
index(index), index(index),
current(0) current(0)
{ {
update(); updatePreview();
} }
CurveEdit::~CurveEdit() CurveEdit::~CurveEdit()
@@ -100,7 +112,7 @@ CurveEdit::~CurveEdit()
preview.detach(); preview.detach();
} }
void CurveEdit::update() void CurveEdit::updatePreview()
{ {
preview.clearPoints(); preview.clearPoints();
CurveHeader & curve = g_model.curves[index]; CurveHeader & curve = g_model.curves[index];
@@ -132,7 +144,7 @@ bool CurveEdit::onTouchEnd(coord_t x, coord_t y)
point_t point = getPoint(index, i); point_t point = getPoint(index, i);
if (abs(preview.getPointX(point.x) - x) <= 10 && abs(preview.getPointY(point.y) - y) <= 10) { if (abs(preview.getPointX(point.x) - x) <= 10 && abs(preview.getPointY(point.y) - y) <= 10) {
current = i; current = i;
update(); updatePreview();
break; break;
} }
} }
@@ -152,7 +164,7 @@ void CurveEdit::next()
if (current++ == preview.points.size()) { if (current++ == preview.points.size()) {
current = 0; current = 0;
} }
update(); updatePreview();
} }
void CurveEdit::previous() void CurveEdit::previous()
@@ -160,7 +172,7 @@ void CurveEdit::previous()
if (current-- == 0) { if (current-- == 0) {
current = preview.points.size(); current = preview.points.size();
} }
update(); updatePreview();
} }
void CurveEdit::up() void CurveEdit::up()
@@ -205,7 +217,7 @@ void CurveEdit::left()
} }
} }
bool CurveEdit::isCustomCurve() bool CurveEdit::isCustomCurve() const
{ {
return g_model.curves[index].type == CURVE_TYPE_CUSTOM; return g_model.curves[index].type == CURVE_TYPE_CUSTOM;
} }
+12 -12
View File
@@ -18,37 +18,39 @@
* GNU General Public License for more details. * GNU General Public License for more details.
*/ */
#ifndef _CURVEEDIT_H_ #pragma once
#define _CURVEEDIT_H_
#include "form.h" #include "form.h"
#include "curve.h" #include "curve.h"
class CurveEdit;
class CurveDataEdit : public FormGroup class CurveDataEdit : public FormGroup
{ {
friend class CurveEdit; friend class CurveEdit;
public: public:
CurveDataEdit(Window * parent, const rect_t & rect, uint8_t index); CurveDataEdit(Window * parent, const rect_t & rect, uint8_t index, CurveEdit * curveEdit);
void paint(BitmapBuffer * dc) override; void paint(BitmapBuffer * dc) override;
void checkEvents() override;
void update(); void update();
protected: protected:
uint8_t index; uint8_t index;
uint8_t previousCurvePointsCount; CurveEdit * curveEdit;
}; };
class CurveEdit: public FormField { class CurveEdit: public FormField
{
friend class CurveDataEdit;
public: public:
CurveEdit(Window * parent, const rect_t & rect, uint8_t index); CurveEdit(Window * parent, const rect_t & rect, uint8_t index);
~CurveEdit() override; ~CurveEdit() override;
void update(); void updatePreview();
void onEvent(event_t event) override; void onEvent(event_t event) override;
@@ -68,7 +70,5 @@ class CurveEdit: public FormField {
void down(); void down();
void right(); void right();
void left(); void left();
bool isCustomCurve(); bool isCustomCurve() const;
}; };
#endif // _CURVEEDIT_H_
+10 -6
View File
@@ -24,7 +24,8 @@
#define SET_DIRTY() storageDirty(EE_MODEL) #define SET_DIRTY() storageDirty(EE_MODEL)
class CurveEditWindow : public Page { class CurveEditWindow : public Page
{
public: public:
explicit CurveEditWindow(uint8_t index): explicit CurveEditWindow(uint8_t index):
Page(ICON_MODEL_CURVES), Page(ICON_MODEL_CURVES),
@@ -86,7 +87,9 @@ class CurveEditWindow : public Page {
curve.type = newValue; curve.type = newValue;
} }
SET_DIRTY(); SET_DIRTY();
curveEdit->update(); curveEdit->updatePreview();
curveDataEdit->clear();
curveDataEdit->update();
} }
}); });
@@ -108,8 +111,9 @@ class CurveEditWindow : public Page {
} }
curve.points = newValue; curve.points = newValue;
SET_DIRTY(); SET_DIRTY();
curveEdit->update(); curveEdit->updatePreview();
curveDataEdit->invalidate(); curveDataEdit->clear();
curveDataEdit->update();
} }
}); });
edit->setSuffix(STR_PTS); edit->setSuffix(STR_PTS);
@@ -121,11 +125,11 @@ class CurveEditWindow : public Page {
[=](int32_t newValue) { [=](int32_t newValue) {
g_model.curves[index].smooth = newValue; g_model.curves[index].smooth = newValue;
SET_DIRTY(); SET_DIRTY();
curveEdit->update(); curveEdit->updatePreview();
}); });
grid.nextLine(); grid.nextLine();
curveDataEdit = new CurveDataEdit(window, {0, grid.getWindowHeight(), coord_t(LCD_W - curveWidth - PAGE_PADDING - 1), window->height() - grid.getWindowHeight() - PAGE_PADDING}, index); curveDataEdit = new CurveDataEdit(window, {0, grid.getWindowHeight(), coord_t(LCD_W - curveWidth - PAGE_PADDING - 1), window->height() - grid.getWindowHeight() - PAGE_PADDING}, index, curveEdit);
} }
#else #else
void buildBody(FormWindow * window) void buildBody(FormWindow * window)
+1 -1
View File
@@ -82,7 +82,7 @@ void RadioToolsPage::rebuild(FormWindow * window)
Window::clearFocus(); Window::clearFocus();
// LUA scripts in TOOLS // LUA scripts in TOOLS
#if defined(LUA) || defined(DEBUG) #if defined(LUA)
FILINFO fno; FILINFO fno;
DIR dir; DIR dir;