Cosmetics

This commit is contained in:
Bertrand Songis
2019-10-05 14:28:50 +02:00
parent 6504b4f69c
commit f5c60a86a9
24 changed files with 171 additions and 126 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ ConfirmDialog::ConfirmDialog(const char *title, const char *message, std::functi
}
#if defined(HARDWARE_KEYS)
void ConfirmDialog::onKeyEvent(event_t event)
void ConfirmDialog::onEvent(event_t event)
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
+1 -1
View File
@@ -28,7 +28,7 @@ class ConfirmDialog: public Dialog {
ConfirmDialog(const char * title, const char * message, std::function<void(void)> confirmHandler);
#if defined(HARDWARE_KEYS)
void onKeyEvent(event_t event) override;
void onEvent(event_t event) override;
#endif
protected:
+5 -3
View File
@@ -22,17 +22,17 @@
#ifndef _CURVE_H_
#define _CURVE_H_
#include "window.h"
#include "form.h"
struct CurvePoint {
point_t coords;
LcdFlags flags;
};
class Curve: public Window {
class Curve: public FormField {
public:
Curve(Window * parent, const rect_t & rect, std::function<int(int)> function, std::function<int()> position=nullptr):
Window(parent, rect, OPAQUE),
FormField(parent, rect, OPAQUE),
function(std::move(function)),
position(std::move(position))
{
@@ -51,6 +51,8 @@ class Curve: public Window {
if (position) {
invalidate();
}
FormField::checkEvents();
}
void addPoint(const point_t & point, LcdFlags flags);
+44 -11
View File
@@ -22,7 +22,7 @@
#include "keyboard_curve.h"
#include "opentx.h" // TODO for applyCustomCurve
CurveEdit::CurveEdit(Window * parent, const rect_t &rect, uint8_t index) :
CurveEdit::CurveEdit(Window * parent, const rect_t & rect, uint8_t index) :
Curve(parent, rect, [=](int x) -> int {
return applyCustomCurve(x, index);
}),
@@ -54,13 +54,9 @@ bool CurveEdit::onTouchEnd(coord_t x, coord_t y)
{
if (!hasFocus()) {
setFocus();
update();
}
CurveKeyboard * keyboard = CurveKeyboard::instance();
if (keyboard->getField() != this) {
keyboard->setField(this);
}
CurveKeyboard::show(this, isCustomCurve());
CurveInfo & curve = g_model.curves[index];
for (int i=0; i<5 + curve.points; i++) {
@@ -79,13 +75,13 @@ bool CurveEdit::onTouchEnd(coord_t x, coord_t y)
void CurveEdit::onFocusLost()
{
CurveKeyboard::instance()->disable(true);
CurveKeyboard::hide();
}
#endif
void CurveEdit::next()
{
if (++current == points.size()) {
if (current++ == points.size()) {
current = 0;
}
update();
@@ -94,7 +90,7 @@ void CurveEdit::next()
void CurveEdit::previous()
{
if (current-- == 0) {
current = points.size() - 1;
current = points.size();
}
update();
}
@@ -118,7 +114,7 @@ void CurveEdit::down()
void CurveEdit::right()
{
CurveInfo & curve = g_model.curves[index];
if (curve.type == CURVE_TYPE_CUSTOM && current != 0 && current != curve.points - 1) {
if (curve.type == CURVE_TYPE_CUSTOM && current != 0 && current != curve.points + 5 - 1) {
int8_t * points = curveAddress(index);
int8_t * point = &points[5 + curve.points + current - 1];
int8_t xmax = (current == (curve.points - 2) ? +100 : *(point + 1));
@@ -131,7 +127,7 @@ void CurveEdit::right()
void CurveEdit::left()
{
CurveInfo & curve = g_model.curves[index];
if (curve.type == CURVE_TYPE_CUSTOM && current != 0 && current != curve.points - 1) {
if (curve.type == CURVE_TYPE_CUSTOM && current != 0 && current != curve.points + 5 - 1) {
int8_t * points = curveAddress(index);
int8_t * point = &points[5 + curve.points + current - 1];
int8_t xmin = (current == 1 ? -100 : *(point - 1));
@@ -145,3 +141,40 @@ bool CurveEdit::isCustomCurve()
{
return g_model.curves[index].type == CURVE_TYPE_CUSTOM;
}
void CurveEdit::onEvent(event_t event)
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
switch (event) {
#if defined(HARDWARE_TOUCH)
case EVT_VIRTUAL_KEY_LEFT:
left();
break;
case EVT_VIRTUAL_KEY_RIGHT:
right();
break;
case EVT_VIRTUAL_KEY_UP:
up();
break;
case EVT_VIRTUAL_KEY_DOWN:
down();
break;
case EVT_VIRTUAL_KEY_PREVIOUS:
previous();
break;
case EVT_VIRTUAL_KEY_NEXT:
next();
break;
#endif
default:
FormField::onEvent(event);
break;
}
}
+3 -3
View File
@@ -24,18 +24,18 @@
#include "curve.h"
class CurveEdit: public Curve {
friend class CurveKeyboard;
public:
CurveEdit(Window * parent, const rect_t & rect, uint8_t index);
void checkEvents() override
{
// no permanent refresh
Curve::checkEvents();
}
void update();
void onEvent(event_t event) override;
#if defined(HARDWARE_TOUCH)
bool onTouchEnd(coord_t x, coord_t y) override;
+1 -1
View File
@@ -79,7 +79,7 @@ void FullScreenDialog::paint(BitmapBuffer * dc)
}
#if defined(HARDWARE_KEYS)
void FullScreenDialog::onKeyEvent(event_t event)
void FullScreenDialog::onEvent(event_t event)
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
+1 -1
View File
@@ -53,7 +53,7 @@ class FullScreenDialog : public Dialog {
void paint(BitmapBuffer * dc) override;
#if defined(HARDWARE_KEYS)
void onKeyEvent(event_t event) override;
void onEvent(event_t event) override;
#endif
#if defined(HARDWARE_TOUCH)
+24 -36
View File
@@ -19,7 +19,6 @@
*/
#include "keyboard_curve.h"
#include "curveedit.h"
#include "button.h"
#include "lcd.h"
@@ -27,76 +26,65 @@ constexpr coord_t KEYBOARD_HEIGHT = 110;
CurveKeyboard * CurveKeyboard::_instance = nullptr;
CurveKeyboard::CurveKeyboard():
Keyboard<CurveEdit>(KEYBOARD_HEIGHT)
CurveKeyboard::CurveKeyboard() :
Keyboard(KEYBOARD_HEIGHT)
{
// up
new TextButton(this, {LCD_W/2 - 20, 5, 40, 40}, "\200",
new TextButton(this, {LCD_W / 2 - 20, 5, 40, 40}, "\200",
[=]() -> uint8_t {
if (field) {
field->up();
}
return 0;
putEvent(EVT_VIRTUAL_KEY_UP);
return 0;
}, BUTTON_BACKGROUND | BUTTON_NOFOCUS);
// down
new TextButton(this, {LCD_W/2 - 20, 65, 40, 40}, "\201",
new TextButton(this, {LCD_W / 2 - 20, 65, 40, 40}, "\201",
[=]() -> uint8_t {
field->down();
return 0;
putEvent(EVT_VIRTUAL_KEY_DOWN);
return 0;
}, BUTTON_BACKGROUND | BUTTON_NOFOCUS);
// left
left = new TextButton(this, {LCD_W / 2 - 70, 35, 40, 40}, "\177",
[=]() -> uint8_t {
if (field) {
field->left();
}
return 0;
putEvent(EVT_VIRTUAL_KEY_LEFT);
return 0;
}, BUTTON_BACKGROUND | BUTTON_NOFOCUS);
// right
right = new TextButton(this, {LCD_W / 2 + 30, 35, 40, 40}, "\176",
[=]() -> uint8_t {
if (field) {
field->right();
}
return 0;
putEvent(EVT_VIRTUAL_KEY_RIGHT);
return 0;
}, BUTTON_BACKGROUND | BUTTON_NOFOCUS);
// next
new TextButton(this, {LCD_W/2 + 80, 35, 60, 40}, "Next",
new TextButton(this, {LCD_W / 2 + 80, 35, 60, 40}, "Next",
[=]() -> uint8_t {
if (field) {
field->next();
}
return 0;
putEvent(EVT_VIRTUAL_KEY_NEXT);
return 0;
}, BUTTON_BACKGROUND | BUTTON_NOFOCUS);
// previous
new TextButton(this, {LCD_W / 2 - 140, 35, 60, 40}, "Prev",
[=]() -> uint8_t {
if (field) {
field->previous();
}
return 0;
putEvent(EVT_VIRTUAL_KEY_PREVIOUS);
return 0;
}, BUTTON_BACKGROUND | BUTTON_NOFOCUS);
}
void CurveKeyboard::enableRightLeft(bool enable)
{
TRACE("STOP %d", enable);
left->enable(enable);
right->enable(enable);
}
CurveKeyboard::~CurveKeyboard()
{
_instance = nullptr;
}
void CurveKeyboard::setField(CurveEdit * field)
{
Keyboard<CurveEdit>::setField(field);
bool custom = field->isCustomCurve();
left->enable(custom);
right->enable(custom);
}
void CurveKeyboard::paint(BitmapBuffer * dc)
{
lcdSetColor(RGB(0xE0, 0xE0, 0xE0));
+8 -10
View File
@@ -22,17 +22,14 @@
#define _KEYBOARD_CURVE_H_
#include "keyboard_base.h"
#include "curveedit.h"
class Button;
class CurveKeyboard : public Keyboard<CurveEdit> {
friend class CurveEdit;
class CurveKeyboard : public Keyboard {
public:
CurveKeyboard();
~CurveKeyboard();
~CurveKeyboard() override;
#if defined(DEBUG_WINDOWS)
std::string getName() override
@@ -41,15 +38,16 @@ class CurveKeyboard : public Keyboard<CurveEdit> {
}
#endif
static CurveKeyboard * instance()
void enableRightLeft(bool enable);
static void show(FormField * field, bool enableRightLeft)
{
if (!_instance)
_instance = new CurveKeyboard();
return _instance;
_instance->setField(field);
_instance->enableRightLeft(enableRightLeft);
}
void setField(CurveEdit * field);
void paint(BitmapBuffer * dc) override;
protected:
@@ -58,4 +56,4 @@ class CurveKeyboard : public Keyboard<CurveEdit> {
Button * right = nullptr;
};
#endif // _KEYBOARD_CURVE_H_
#endif // _KEYBOARD_CURVE_H_
+1 -1
View File
@@ -249,7 +249,7 @@ class BindWaitDialog: public Dialog {
void checkEvents() override;
#if defined(HARDWARE_KEYS)
void onKeyEvent(event_t event) override
void onEvent(event_t event) override
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
+2 -2
View File
@@ -243,7 +243,7 @@ void RadioCalibrationPage::checkEvents()
}
#if defined(HARDWARE_KEYS)
void RadioCalibrationPage::onKeyEvent(event_t event)
void RadioCalibrationPage::onEvent(event_t event)
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
@@ -257,7 +257,7 @@ void RadioCalibrationPage::onKeyEvent(event_t event)
}
else {
Page::onKeyEvent(event);
Page::onEvent(event);
}
}
#endif
+1 -1
View File
@@ -29,7 +29,7 @@ class RadioCalibrationPage: public Page {
void checkEvents() override;
#if defined(HARDWARE_KEYS)
void onKeyEvent(event_t event) override;
void onEvent(event_t event) override;
#endif
protected:
+2 -2
View File
@@ -67,7 +67,7 @@ class LayoutChoice: public FormField {
}
#if defined(HARDWARE_KEYS)
void onKeyEvent(event_t event) override
void onEvent(event_t event) override
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
@@ -77,7 +77,7 @@ class LayoutChoice: public FormField {
openMenu();
}
else {
FormField::onKeyEvent(event);
FormField::onEvent(event);
}
}
#endif
+3 -2
View File
@@ -113,7 +113,7 @@ void SourceChoice::openMenu()
}
#if defined(HARDWARE_KEYS)
void SourceChoice::onKeyEvent(event_t event)
void SourceChoice::onEvent(event_t event)
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
@@ -123,7 +123,7 @@ void SourceChoice::onKeyEvent(event_t event)
openMenu();
}
else {
FormField::onKeyEvent(event);
FormField::onEvent(event);
}
}
#endif
@@ -133,6 +133,7 @@ bool SourceChoice::onTouchEnd(coord_t, coord_t)
{
openMenu();
setFocus();
setEditMode(true);
return true;
}
#endif
+1 -1
View File
@@ -50,7 +50,7 @@ class SourceChoice : public FormField {
void paint(BitmapBuffer * dc) override;
#if defined(HARDWARE_KEYS)
void onKeyEvent(event_t event) override;
void onEvent(event_t event) override;
#endif
#if defined(HARDWARE_TOUCH)
+3 -2
View File
@@ -97,7 +97,7 @@ void SwitchChoice::openMenu()
}
#if defined(HARDWARE_KEYS)
void SwitchChoice::onKeyEvent(event_t event)
void SwitchChoice::onEvent(event_t event)
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
@@ -107,7 +107,7 @@ void SwitchChoice::onKeyEvent(event_t event)
openMenu();
}
else {
FormField::onKeyEvent(event);
FormField::onEvent(event);
}
}
#endif
@@ -117,6 +117,7 @@ bool SwitchChoice::onTouchEnd(coord_t, coord_t)
{
openMenu();
setFocus();
setEditMode(true);
return true;
}
#endif
+1 -1
View File
@@ -49,7 +49,7 @@ class SwitchChoice : public FormField {
void paint(BitmapBuffer * dc) override;
#if defined(HARDWARE_KEYS)
void onKeyEvent(event_t event) override;
void onEvent(event_t event) override;
#endif
#if defined(HARDWARE_TOUCH)
+7 -7
View File
@@ -45,7 +45,7 @@ void TimeEdit::paint(BitmapBuffer * dc)
#if defined(HARDWARE_KEYS)
// TODO could be moved to BaseNumberEdit
void TimeEdit::onKeyEvent(event_t event)
void TimeEdit::onEvent(event_t event)
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
@@ -70,7 +70,7 @@ void TimeEdit::onKeyEvent(event_t event)
}
}
FormField::onKeyEvent(event);
FormField::onEvent(event);
}
#endif
@@ -81,16 +81,16 @@ bool TimeEdit::onTouchEnd(coord_t x, coord_t y)
setFocus();
}
NumberKeyboard * keyboard = NumberKeyboard::instance();
if (keyboard->getField() != this) {
keyboard->setField(this);
}
// NumberKeyboard * keyboard = NumberKeyboard::instance();
// if (keyboard->getField() != this) {
// keyboard->setField(this);
// }
return true;
}
void TimeEdit::onFocusLost()
{
NumberKeyboard::instance()->disable(true);
// NumberKeyboard::instance()->disable(true);
}
#endif
+1 -1
View File
@@ -37,7 +37,7 @@ class TimeEdit : public BaseNumberEdit {
void paint(BitmapBuffer * dc) override;
#if defined(HARDWARE_KEYS)
void onKeyEvent(event_t event) override;
void onEvent(event_t event) override;
#endif
#if defined(HARDWARE_TOUCH)
+1 -1
View File
@@ -165,7 +165,7 @@ ViewMain::~ViewMain()
}
#if defined(HARDWARE_KEYS)
void ViewMain::onKeyEvent(event_t event)
void ViewMain::onEvent(event_t event)
{
switch (event) {
case EVT_KEY_LONG(KEY_MODEL):
+1 -1
View File
@@ -40,7 +40,7 @@ class ViewMain: public Window {
protected:
#if defined(HARDWARE_KEYS)
void onKeyEvent(event_t event) override;
void onEvent(event_t event) override;
#endif
void paint(BitmapBuffer * dc) override;
void checkEvents() override;