[Horus] UI continued
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
class GaugeWidget: public Widget
|
||||
{
|
||||
public:
|
||||
GaugeWidget(const WidgetFactory * factory, const Zone & zone, Widget::PersistentData * persistentData):
|
||||
Widget(factory, zone, persistentData)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void create()
|
||||
{
|
||||
persistentData->options[0].unsignedValue = 1;
|
||||
persistentData->options[1].signedValue = -RESX;
|
||||
persistentData->options[2].signedValue = RESX;
|
||||
persistentData->options[3].unsignedValue = RED;
|
||||
}
|
||||
|
||||
void refresh();
|
||||
|
||||
static const ZoneOption options[];
|
||||
};
|
||||
|
||||
const ZoneOption GaugeWidget::options[] = {
|
||||
{ "Source", ZoneOption::Source },
|
||||
{ "Min", ZoneOption::Integer },
|
||||
{ "Max", ZoneOption::Integer },
|
||||
{ "Color", ZoneOption::Color },
|
||||
{ NULL, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
void GaugeWidget::refresh()
|
||||
{
|
||||
mixsrc_t index = persistentData->options[0].unsignedValue;
|
||||
int32_t min = persistentData->options[1].signedValue;
|
||||
int32_t max = persistentData->options[2].signedValue;
|
||||
uint16_t color = persistentData->options[3].unsignedValue;
|
||||
|
||||
getvalue_t value = getValue(index);
|
||||
getvalue_t value_in_range = value;
|
||||
if (value < min)
|
||||
value_in_range = min;
|
||||
else if (value > max)
|
||||
value_in_range;
|
||||
|
||||
int w = divRoundClosest(zone.w * (value_in_range - min), (max - min));
|
||||
int percent = divRoundClosest(100 * (value_in_range - min), (max - min));
|
||||
|
||||
// Gauge label
|
||||
putsMixerSource(zone.x, zone.y + 5, index, SMLSIZE | TEXT_INVERTED_COLOR);
|
||||
|
||||
// Gauge
|
||||
lcdSetColor(color);
|
||||
lcdDrawSolidFilledRect(zone.x, zone.y + 20, zone.w, 16, TEXT_INVERTED_COLOR);
|
||||
lcdDrawNumber(zone.x+zone.w/2+20, zone.y + 21, percent, SMLSIZE | CUSTOM_COLOR, 0, NULL, "%");
|
||||
lcdInvertRect(zone.x + w, zone.y + 20, zone.w - w, 16, CUSTOM_COLOR);
|
||||
}
|
||||
|
||||
BaseWidgetFactory<GaugeWidget> gaugeWidget("Gauge", "", GaugeWidget::options);
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
class ModelPanelWidget: public Widget
|
||||
{
|
||||
public:
|
||||
ModelPanelWidget(const WidgetFactory * factory, const Zone & zone, Widget::PersistentData * persistentData):
|
||||
Widget(factory, zone, persistentData)
|
||||
{
|
||||
}
|
||||
|
||||
void refresh();
|
||||
};
|
||||
|
||||
void ModelPanelWidget::refresh()
|
||||
{
|
||||
if (zone.h >= MODEL_BITMAP_HEIGHT) {
|
||||
lcdDrawFilledRect(zone.x, zone.y, zone.w, zone.h, SOLID, TEXT_BGCOLOR | OPACITY(5));
|
||||
lcdDrawBitmapPattern(zone.x + 6, zone.y + 4, LBM_MODEL_ICON, TITLE_BGCOLOR);
|
||||
lcdDrawSizedText(zone.x + 45, zone.y + 10, g_model.header.name, LEN_MODEL_NAME, ZCHAR | SMLSIZE);
|
||||
lcdDrawSolidHorizontalLine(zone.x + 39, zone.y + 27, zone.w - 48, TITLE_BGCOLOR);
|
||||
int scale = getBitmapScale(modelBitmap, zone.w, zone.h);
|
||||
int width = getBitmapScaledSize(getBitmapWidth(modelBitmap), scale);
|
||||
int height = getBitmapScaledSize(getBitmapHeight(modelBitmap), scale);
|
||||
lcdDrawBitmap(zone.x + (zone.w - width) / 2, zone.y + zone.h - MODEL_BITMAP_HEIGHT / 2 - height / 2, modelBitmap, 0, 0, scale);
|
||||
}
|
||||
else {
|
||||
int scale = getBitmapScale(modelBitmap, zone.w, zone.h);
|
||||
int width = getBitmapScaledSize(getBitmapWidth(modelBitmap), scale);
|
||||
int height = getBitmapScaledSize(getBitmapHeight(modelBitmap), scale);
|
||||
lcdDrawFilledRect(zone.x, zone.y, zone.w, height, SOLID, TEXT_BGCOLOR | OPACITY(5));
|
||||
lcdDrawSizedText(zone.x + 5, zone.y + 10, g_model.header.name, LEN_MODEL_NAME, ZCHAR | SMLSIZE);
|
||||
lcdDrawBitmap(zone.x + zone.w - width, zone.y, modelBitmap, 0, 0, scale);
|
||||
}
|
||||
}
|
||||
|
||||
BaseWidgetFactory<ModelPanelWidget> modelPanelWidget("ModelPanel", "", NULL);
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
class TextWidget: public Widget
|
||||
{
|
||||
public:
|
||||
TextWidget(const WidgetFactory * factory, const Zone & zone, Widget::PersistentData * persistentData):
|
||||
Widget(factory, zone, persistentData)
|
||||
{
|
||||
}
|
||||
|
||||
void create()
|
||||
{
|
||||
str2zchar(persistentData->options[0].stringValue, "Label", sizeof(persistentData->options[0].stringValue));
|
||||
persistentData->options[1].unsignedValue = RED;
|
||||
persistentData->options[2].unsignedValue = 0;
|
||||
}
|
||||
|
||||
void refresh();
|
||||
|
||||
static const ZoneOption options[];
|
||||
};
|
||||
|
||||
const ZoneOption TextWidget::options[] = {
|
||||
{ "Text", ZoneOption::String },
|
||||
{ "Color", ZoneOption::Color },
|
||||
{ "Size", ZoneOption::TextSize },
|
||||
{ NULL, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
void TextWidget::refresh()
|
||||
{
|
||||
lcdSetColor(persistentData->options[1].unsignedValue);
|
||||
LcdFlags fontsize = FONTSIZE(persistentData->options[2].unsignedValue << 8);
|
||||
lcdDrawSizedText(zone.x, zone.y, persistentData->options[0].stringValue, sizeof(persistentData->options[0].stringValue), ZCHAR|fontsize|CUSTOM_COLOR);
|
||||
}
|
||||
|
||||
BaseWidgetFactory<TextWidget> textWidget("Text", "", TextWidget::options);
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
class TimerWidget: public Widget
|
||||
{
|
||||
public:
|
||||
TimerWidget(const WidgetFactory * factory, const Zone & zone, Widget::PersistentData * persistentData):
|
||||
Widget(factory, zone, persistentData)
|
||||
{
|
||||
}
|
||||
|
||||
void refresh();
|
||||
|
||||
static const ZoneOption options[];
|
||||
};
|
||||
|
||||
const ZoneOption TimerWidget::options[] = {
|
||||
{ "Timer source", ZoneOption::Timer },
|
||||
{ NULL, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
void TimerWidget::refresh()
|
||||
{
|
||||
uint32_t index = persistentData->options[0].unsignedValue;
|
||||
|
||||
TimerData & timerData = g_model.timers[index];
|
||||
TimerState & timerState = timersStates[index];
|
||||
lcdDrawBitmapPattern(zone.x, zone.y, LBM_TIMER_BACKGROUND, TEXT_BGCOLOR);
|
||||
if (timerData.start) {
|
||||
lcdDrawBitmapPatternPie(zone.x+2, zone.y+3, LBM_RSCALE, TITLE_BGCOLOR, 0, timerState.val <= 0 ? 360 : 360*(timerData.start-timerState.val)/timerData.start);
|
||||
}
|
||||
else {
|
||||
lcdDrawBitmapPattern(zone.x+3, zone.y+4, LBM_TIMER, TITLE_BGCOLOR);
|
||||
}
|
||||
putsTimer(zone.x+76, zone.y+31, abs(timerState.val), TEXT_COLOR|DBLSIZE|LEFT);
|
||||
if (ZLEN(timerData.name) > 0) {
|
||||
lcdDrawSizedText(zone.x+78, zone.y+20, timerData.name, LEN_TIMER_NAME, ZCHAR|SMLSIZE|TEXT_COLOR);
|
||||
}
|
||||
drawStringWithIndex(zone.x+137, zone.y+17, "TMR", index+1, SMLSIZE|TEXT_COLOR);
|
||||
}
|
||||
|
||||
BaseWidgetFactory<TimerWidget> timerWidget("Timer", "", TimerWidget::options);
|
||||
Reference in New Issue
Block a user