mirror of
https://github.com/opentx/opentx.git
synced 2025-07-16 21:05:26 +03:00
[Horus] Options in widgets can now have a min and a max defined
This commit is contained in:
parent
3940716b5d
commit
5822cfded1
9 changed files with 50 additions and 36 deletions
|
@ -78,7 +78,7 @@ bool editZoneOption(coord_t y, const ZoneOption * option, ZoneOptionValue * valu
|
|||
else if (option->type == ZoneOption::Integer) {
|
||||
lcdDrawNumber(SCREENS_SETUP_2ND_COLUMN, y, value->signedValue, attr | LEFT);
|
||||
if (attr) {
|
||||
CHECK_INCDEC_MODELVAR(event, value->signedValue, -30000, 30000); // TODO i_flags
|
||||
CHECK_INCDEC_MODELVAR(event, value->signedValue, option->min.signedValue, option->max.signedValue); // TODO i_flags
|
||||
}
|
||||
}
|
||||
else if (option->type == ZoneOption::String) {
|
||||
|
@ -129,8 +129,8 @@ bool editZoneOption(coord_t y, const ZoneOption * option, ZoneOptionValue * valu
|
|||
COLOR_SPLIT(value->unsignedValue, r, g, b);
|
||||
|
||||
lcdSetColor(value->unsignedValue);
|
||||
lcdDrawSolidFilledRect(SCREENS_SETUP_2ND_COLUMN-1, y-1, 42, 17, TEXT_COLOR);
|
||||
lcdDrawSolidFilledRect(SCREENS_SETUP_2ND_COLUMN, y, 40, 15, CUSTOM_COLOR);
|
||||
lcdDrawSolidFilledRect(SCREENS_SETUP_2ND_COLUMN-1, y+1, 42, 17, TEXT_COLOR);
|
||||
lcdDrawSolidFilledRect(SCREENS_SETUP_2ND_COLUMN, y+2, 40, 15, CUSTOM_COLOR);
|
||||
|
||||
lcdDrawText(SCREENS_SETUP_2ND_COLUMN + 50, y, "R:", TEXT_COLOR);
|
||||
lcdDrawNumber(SCREENS_SETUP_2ND_COLUMN + 70, y, r << 3, LEFT|TEXT_COLOR|((attr && menuHorizontalPosition == 0) ? attr : 0));
|
||||
|
@ -273,7 +273,7 @@ bool menuWidgetChoice(evt_t event)
|
|||
lcdDrawBitmapPattern(zone.x-10, zone.y+zone.h/2-10, LBM_SWIPE_LEFT, TEXT_INVERTED_COLOR);
|
||||
lcdDrawBitmapPattern(zone.x+zone.w-9, zone.y+zone.h/2-10, LBM_SWIPE_CIRCLE, TEXT_INVERTED_BGCOLOR);
|
||||
lcdDrawBitmapPattern(zone.x+zone.w-9, zone.y+zone.h/2-10, LBM_SWIPE_RIGHT, TEXT_INVERTED_COLOR);
|
||||
lcdDrawText(zone.x + zone.w, zone.y, currentWidget->getFactory()->getName(), RIGHT | TEXT_COLOR | INVERS);
|
||||
lcdDrawText(zone.x + zone.w, zone.y-1, currentWidget->getFactory()->getName(), RIGHT | TEXT_COLOR | SMLSIZE | INVERS);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
#include "opentx.h"
|
||||
|
||||
const ZoneOption OPTIONS_THEME_DEFAULT[] = {
|
||||
{ "Background color", ZoneOption::Color, OPTION_DEFAULT_VALUE_UNSIGNED(WHITE) },
|
||||
{ "Main color", ZoneOption::Color, OPTION_DEFAULT_VALUE_UNSIGNED(RED) },
|
||||
{ "Background color", ZoneOption::Color, OPTION_VALUE_UNSIGNED(WHITE) },
|
||||
{ "Main color", ZoneOption::Color, OPTION_VALUE_UNSIGNED(RED) },
|
||||
{ NULL, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
|
|
|
@ -41,15 +41,15 @@ union ZoneOptionValue
|
|||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define OPTION_DEFAULT_VALUE_UNSIGNED(x) uint32_t(x)
|
||||
#define OPTION_DEFAULT_VALUE_SIGNED(x) uint32_t(x)
|
||||
#define OPTION_DEFAULT_VALUE_BOOL(x) uint32_t(x)
|
||||
#define OPTION_DEFAULT_VALUE_STRING(...) *(ZoneOptionValue *)(const char *)__VA_ARGS__
|
||||
#define OPTION_VALUE_UNSIGNED(x) uint32_t(x)
|
||||
#define OPTION_VALUE_SIGNED(x) uint32_t(x)
|
||||
#define OPTION_VALUE_BOOL(x) uint32_t(x)
|
||||
#define OPTION_VALUE_STRING(...) *(ZoneOptionValue *)(const char *)__VA_ARGS__
|
||||
#else
|
||||
#define OPTION_DEFAULT_VALUE_UNSIGNED(x) { .unsignedValue = (x) }
|
||||
#define OPTION_DEFAULT_VALUE_SIGNED(x) { .signedValue = (x) }
|
||||
#define OPTION_DEFAULT_VALUE_BOOL(x) { .boolValue = (x) }
|
||||
#define OPTION_DEFAULT_VALUE_STRING(...) *(ZoneOptionValue *)(const char *)__VA_ARGS__
|
||||
#define OPTION_VALUE_UNSIGNED(x) { .unsignedValue = (x) }
|
||||
#define OPTION_VALUE_SIGNED(x) { .signedValue = (x) }
|
||||
#define OPTION_VALUE_BOOL(x) { .boolValue = (x) }
|
||||
#define OPTION_VALUE_STRING(...) *(ZoneOptionValue *)(const char *)__VA_ARGS__
|
||||
#endif
|
||||
|
||||
struct ZoneOption
|
||||
|
@ -69,6 +69,8 @@ struct ZoneOption
|
|||
const char * name;
|
||||
Type type;
|
||||
ZoneOptionValue deflt;
|
||||
ZoneOptionValue min;
|
||||
ZoneOptionValue max;
|
||||
};
|
||||
|
||||
class WidgetFactory;
|
||||
|
|
|
@ -34,10 +34,10 @@ class GaugeWidget: public Widget
|
|||
};
|
||||
|
||||
const ZoneOption GaugeWidget::options[] = {
|
||||
{ "Source", ZoneOption::Source, OPTION_DEFAULT_VALUE_UNSIGNED(1) },
|
||||
{ "Min", ZoneOption::Integer, OPTION_DEFAULT_VALUE_SIGNED(-RESX) },
|
||||
{ "Max", ZoneOption::Integer, OPTION_DEFAULT_VALUE_SIGNED(RESX) },
|
||||
{ "Color", ZoneOption::Color, OPTION_DEFAULT_VALUE_UNSIGNED(RED) },
|
||||
{ "Source", ZoneOption::Source, OPTION_VALUE_UNSIGNED(1) },
|
||||
{ "Min", ZoneOption::Integer, OPTION_VALUE_SIGNED(-RESX), OPTION_VALUE_SIGNED(-RESX), OPTION_VALUE_SIGNED(RESX) },
|
||||
{ "Max", ZoneOption::Integer, OPTION_VALUE_SIGNED(RESX), OPTION_VALUE_SIGNED(-RESX), OPTION_VALUE_SIGNED(RESX) },
|
||||
{ "Color", ZoneOption::Color, OPTION_VALUE_UNSIGNED(RED) },
|
||||
{ NULL, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
#define RECT_OFFSET 80
|
||||
#define RECT_WIDTH (w - RECT_OFFSET)
|
||||
#define ROW_HEIGHT 20
|
||||
#define ROW_HEIGHT 17
|
||||
|
||||
class OutputsWidget: public Widget
|
||||
{
|
||||
|
@ -37,26 +37,28 @@ class OutputsWidget: public Widget
|
|||
uint8_t drawChannels(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t firstChan)
|
||||
{
|
||||
char chanString[] = "CH32";
|
||||
uint8_t lastChan = firstChan + h / ROW_HEIGHT;
|
||||
uint8_t numChan = h / ROW_HEIGHT;
|
||||
uint8_t row_height = (h - numChan * ROW_HEIGHT >= numChan ? ROW_HEIGHT + 1 : ROW_HEIGHT);
|
||||
uint8_t lastChan = firstChan + numChan;
|
||||
|
||||
for (uint8_t curChan = firstChan; curChan <= lastChan && curChan < 33; curChan++) {
|
||||
for (uint8_t curChan = firstChan; curChan < lastChan && curChan < 33; curChan++) {
|
||||
int16_t chanVal = calcRESXto100(channelOutputs[curChan-1]);
|
||||
strAppend(chanString, "CH");
|
||||
strAppendSigned(&chanString[2], curChan, 2);
|
||||
lcdDrawText(x, y + (curChan - firstChan) * ROW_HEIGHT, chanString, SMLSIZE | TEXT_COLOR | LEFT);
|
||||
lcdDrawText(x, y + (curChan - firstChan) * row_height + 1, chanString, SMLSIZE | TEXT_COLOR | LEFT);
|
||||
strAppendSigned(chanString, chanVal);
|
||||
lcdDrawText(x + RECT_OFFSET - 2, y + (curChan - firstChan) * ROW_HEIGHT, chanString, SMLSIZE | TEXT_COLOR | RIGHT);
|
||||
lcdDrawText(x + RECT_OFFSET - 2, y + (curChan - firstChan) * row_height + 1, chanString, SMLSIZE | TEXT_COLOR | RIGHT);
|
||||
if (chanVal > 0) {
|
||||
lcdDrawSolidFilledRect(x + RECT_OFFSET + RECT_WIDTH / 2, y + (curChan -firstChan) * ROW_HEIGHT, divRoundClosest(RECT_WIDTH * chanVal, 200), ROW_HEIGHT, MAINVIEW_GRAPHICS_COLOR);
|
||||
lcdDrawSolidFilledRect(x + RECT_OFFSET + RECT_WIDTH / 2, y + (curChan -firstChan) * row_height, divRoundClosest(RECT_WIDTH * chanVal, 200), row_height, MAINVIEW_GRAPHICS_COLOR);
|
||||
}
|
||||
else if (chanVal < 0) {
|
||||
uint16_t startpoint = x + RECT_OFFSET;
|
||||
uint16_t endpoint = startpoint + RECT_WIDTH / 2;
|
||||
uint16_t size = divRoundClosest(- RECT_WIDTH * chanVal, 200);
|
||||
lcdDrawSolidFilledRect(endpoint - size, y + (curChan - firstChan) * ROW_HEIGHT, size, ROW_HEIGHT, MAINVIEW_GRAPHICS_COLOR);
|
||||
lcdDrawSolidFilledRect(endpoint - size, y + (curChan - firstChan) * row_height, size, row_height, MAINVIEW_GRAPHICS_COLOR);
|
||||
}
|
||||
lcdDrawRect(x + RECT_OFFSET, y + (curChan -firstChan) * ROW_HEIGHT, RECT_WIDTH, ROW_HEIGHT);
|
||||
lcd->drawSolidVerticalLine(x + RECT_OFFSET + RECT_WIDTH / 2, y + (curChan - firstChan) * ROW_HEIGHT, ROW_HEIGHT, MAINVIEW_GRAPHICS_COLOR);
|
||||
lcdDrawRect(x + RECT_OFFSET, y + (curChan - firstChan) * row_height, RECT_WIDTH, row_height+1);
|
||||
lcd->drawSolidVerticalLine(x + RECT_OFFSET + RECT_WIDTH / 2, y + (curChan - firstChan) * row_height, row_height, MAINVIEW_GRAPHICS_COLOR);
|
||||
}
|
||||
return lastChan;
|
||||
}
|
||||
|
@ -76,7 +78,7 @@ class OutputsWidget: public Widget
|
|||
};
|
||||
|
||||
const ZoneOption OutputsWidget::options[] = {
|
||||
{ "First", ZoneOption::Integer, OPTION_DEFAULT_VALUE_UNSIGNED(1) },
|
||||
{ "First channel", ZoneOption::Integer, OPTION_VALUE_UNSIGNED(1), OPTION_VALUE_UNSIGNED(1), OPTION_VALUE_UNSIGNED(32) },
|
||||
{ NULL, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
|
|
|
@ -34,9 +34,9 @@ class TextWidget: public Widget
|
|||
};
|
||||
|
||||
const ZoneOption TextWidget::options[] = {
|
||||
{ "Text", ZoneOption::String, OPTION_DEFAULT_VALUE_STRING("\015\347\0\14\377\376\373\364") },
|
||||
{ "Color", ZoneOption::Color, OPTION_DEFAULT_VALUE_UNSIGNED(RED) },
|
||||
{ "Size", ZoneOption::TextSize, OPTION_DEFAULT_VALUE_UNSIGNED(0) },
|
||||
{ "Text", ZoneOption::String, OPTION_VALUE_STRING("\015\347\0\14\377\376\373\364") },
|
||||
{ "Color", ZoneOption::Color, OPTION_VALUE_UNSIGNED(RED) },
|
||||
{ "Size", ZoneOption::TextSize, OPTION_VALUE_UNSIGNED(0) },
|
||||
{ NULL, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class TimerWidget: public Widget
|
|||
};
|
||||
|
||||
const ZoneOption TimerWidget::options[] = {
|
||||
{ "Timer source", ZoneOption::Timer, OPTION_DEFAULT_VALUE_UNSIGNED(0) },
|
||||
{ "Timer source", ZoneOption::Timer, OPTION_VALUE_UNSIGNED(0) },
|
||||
{ NULL, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class ValueWidget: public Widget
|
|||
};
|
||||
|
||||
const ZoneOption ValueWidget::options[] = {
|
||||
{ "Source", ZoneOption::Source, OPTION_DEFAULT_VALUE_UNSIGNED(MIXSRC_Rud) },
|
||||
{ "Source", ZoneOption::Source, OPTION_VALUE_UNSIGNED(MIXSRC_Rud) },
|
||||
{ NULL, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
|
|
|
@ -807,6 +807,16 @@ ZoneOption * createOptionsArray(int reference)
|
|||
luaL_checktype(L, -1, LUA_TNUMBER); // value is number
|
||||
option->deflt.signedValue = lua_tointeger(L, -1);
|
||||
break;
|
||||
case 3:
|
||||
luaL_checktype(L, -2, LUA_TNUMBER); // key is number
|
||||
luaL_checktype(L, -1, LUA_TNUMBER); // value is number
|
||||
option->min.signedValue = lua_tointeger(L, -1);
|
||||
break;
|
||||
case 4:
|
||||
luaL_checktype(L, -2, LUA_TNUMBER); // key is number
|
||||
luaL_checktype(L, -1, LUA_TNUMBER); // value is number
|
||||
option->max.signedValue = lua_tointeger(L, -1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
option++;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue