Now uses the external libopenui

This commit is contained in:
Bertrand Songis
2019-10-02 14:41:52 +02:00
parent 5b568cd40c
commit 3e2cb83991
250 changed files with 76326 additions and 11869 deletions
+23 -7
View File
@@ -2,6 +2,7 @@ include_directories(
${RADIO_SRC_DIRECTORY}/gui/colorlcd
${RADIO_SRC_DIRECTORY}/gui/colorlcd/layouts
${RADIO_SRC_DIRECTORY}/fonts/truetype
${RADIO_SRC_DIRECTORY}/thirdparty/libopenui/src
)
file(GLOB THEMES_SRC RELATIVE ${RADIO_SRC_DIRECTORY}/gui/colorlcd ${RADIO_SRC_DIRECTORY}/gui/colorlcd/themes/*.cpp)
@@ -18,12 +19,11 @@ set(GUI_SRC
theme.cpp
# topbar.cpp
# layout.cpp
layout.cpp
# widget.cpp
${THEMES_SRC}
# ${LAYOUTS_SRC}
${LAYOUTS_SRC}
# ${WIDGETS_SRC}
rle.cpp
# popups.cpp
draw_functions.cpp
# menus.cpp
@@ -48,6 +48,9 @@ set(GUI_SRC
radio_hardware.cpp
radio_calibration.cpp
view_main.cpp
menu_screen.cpp
screen_setup.cpp
# view_statistics.cpp
)
@@ -75,17 +78,30 @@ if(LUA STREQUAL YES)
# TODO set(GUI_SRC ${GUI_SRC} model_custom_scripts.cpp)
endif()
# gui/${GUI_DIR}/modelslist.cpp
set(SRC
${SRC}
stubs.cpp
)
# includes libopenui
include(gui/libopenui/CMakeLists.txt)
include(${RADIO_SRC_DIRECTORY}/thirdparty/libopenui/src/CMakeLists.txt)
include_directories(gui/libopenui)
add_definitions(-DLIBOPENUI)
foreach(LIBOPENUI_FILE ${LIBOPENUI_SRC})
set(SRC ${SRC} gui/libopenui/${LIBOPENUI_FILE})
set(SRC ${SRC} thirdparty/libopenui/src/${LIBOPENUI_FILE})
endforeach()
add_gui_src(fullscreen_dialog.cpp)
add_gui_src(confirm_dialog.cpp)
add_gui_src(message_dialog.cpp)
add_gui_src(timeedit.cpp)
add_gui_src(curve.cpp)
add_gui_src(sourcechoice.cpp)
add_gui_src(switchchoice.cpp)
add_gui_src(curveedit.cpp)
if(HARDWARE_TOUCH)
add_gui_src(keyboard_curve.cpp)
endif()
# gui/${GUI_DIR}/modelslist.cpp
+2 -73
View File
@@ -21,12 +21,7 @@
#ifndef _COLORS_H_
#define _COLORS_H_
// remove windows default definitions
#undef OPAQUE
#undef RGB
#define RGB(r, g, b) (uint16_t)((((r) & 0xF8) << 8) + (((g) & 0xFC) << 3) + (((b) & 0xF8) >> 3))
#define ARGB(a, r, g, b) (uint16_t)((((a) & 0xF0) << 8) + (((r) & 0xF0) << 4) + (((g) & 0xF0) << 0) + (((b) & 0xF0) >> 4))
#include "libopenui_config.h"
#define WHITE RGB(0xFF, 0xFF, 0xFF)
#define BLACK RGB(0, 0, 0)
@@ -40,49 +35,6 @@
#define DARKRED RGB(160, 0, 6)
#define GREEN RGB(25, 150, 50)
#define OPACITY_MAX 0x0F
#define OPACITY(x) ((x)<<24)
enum LcdColorIndex
{
TEXT_COLOR_INDEX,
TEXT_BGCOLOR_INDEX,
TEXT_INVERTED_COLOR_INDEX,
TEXT_INVERTED_BGCOLOR_INDEX,
TEXT_STATUSBAR_COLOR_INDEX,
LINE_COLOR_INDEX,
SCROLLBOX_COLOR_INDEX,
MENU_TITLE_BGCOLOR_INDEX,
MENU_TITLE_COLOR_INDEX,
MENU_TITLE_DISABLE_COLOR_INDEX,
HEADER_COLOR_INDEX,
ALARM_COLOR_INDEX,
WARNING_COLOR_INDEX,
TEXT_DISABLE_COLOR_INDEX,
CURVE_AXIS_COLOR_INDEX,
CURVE_COLOR_INDEX,
CURVE_CURSOR_COLOR_INDEX,
HEADER_BGCOLOR_INDEX,
HEADER_ICON_BGCOLOR_INDEX,
HEADER_CURRENT_BGCOLOR_INDEX,
TITLE_BGCOLOR_INDEX,
TRIM_BGCOLOR_INDEX,
TRIM_SHADOW_COLOR_INDEX,
MAINVIEW_PANES_COLOR_INDEX,
MAINVIEW_GRAPHICS_COLOR_INDEX,
OVERLAY_COLOR_INDEX,
CUSTOM_COLOR_INDEX,
BARGRAPH1_COLOR_INDEX,
BARGRAPH2_COLOR_INDEX,
BARGRAPH_BGCOLOR_INDEX,
LCD_COLOR_COUNT
};
extern uint16_t lcdColorTable[LCD_COLOR_COUNT];
#define COLOR(index) LcdFlags((index) << 16)
#define COLOR_IDX(att) uint8_t((att) >> 16)
#define TEXT_COLOR COLOR(TEXT_COLOR_INDEX)
#define TEXT_BGCOLOR COLOR(TEXT_BGCOLOR_INDEX)
#define TEXT_INVERTED_COLOR COLOR(TEXT_INVERTED_COLOR_INDEX)
@@ -106,7 +58,7 @@ extern uint16_t lcdColorTable[LCD_COLOR_COUNT];
#define TRIM_SHADOW_COLOR COLOR(TRIM_SHADOW_COLOR_INDEX)
#define HEADER_BGCOLOR COLOR(HEADER_BGCOLOR_INDEX)
#define HEADER_ICON_BGCOLOR COLOR(HEADER_ICON_BGCOLOR_INDEX)
constexpr LcdFlags HEADER_CURRENT_BGCOLOR = COLOR(HEADER_CURRENT_BGCOLOR_INDEX);
#define HEADER_CURRENT_BGCOLOR COLOR(HEADER_CURRENT_BGCOLOR_INDEX)
#define MAINVIEW_PANES_COLOR COLOR(MAINVIEW_PANES_COLOR_INDEX)
#define MAINVIEW_GRAPHICS_COLOR COLOR(MAINVIEW_GRAPHICS_COLOR_INDEX)
#define OVERLAY_COLOR COLOR(OVERLAY_COLOR_INDEX)
@@ -115,27 +67,4 @@ constexpr LcdFlags HEADER_CURRENT_BGCOLOR = COLOR(HEADER_CURRENT_BGCOLOR_INDEX)
#define BARGRAPH_BGCOLOR COLOR(BARGRAPH_BGCOLOR_INDEX)
#define CUSTOM_COLOR COLOR(CUSTOM_COLOR_INDEX)
#define ARGB_SPLIT(color, a, r, g, b) \
uint16_t a = ((color) & 0xF000) >> 12; \
uint16_t r = ((color) & 0x0F00) >> 8; \
uint16_t g = ((color) & 0x00F0) >> 4; \
uint16_t b = ((color) & 0x000F)
#define RGB_SPLIT(color, r, g, b) \
uint16_t r = ((color) & 0xF800) >> 11; \
uint16_t g = ((color) & 0x07E0) >> 5; \
uint16_t b = ((color) & 0x001F)
#define RGB_JOIN(r, g, b) \
(((r) << 11) + ((g) << 5) + (b))
#define GET_RED(color) \
(((color) & 0xF800) >> 8)
#define GET_GREEN(color) \
(((color) & 0x07E0) >> 3)
#define GET_BLUE(color) \
(((color) & 0x001F) << 3)
#endif // _COLORS_H_
+44
View File
@@ -0,0 +1,44 @@
/*
* 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 "confirm_dialog.h"
#include "static.h"
ConfirmDialog::ConfirmDialog(const char *title, const char *message, std::function<void(void)> confirmHandler) :
Dialog(title, {50, 73, LCD_W - 100, LCD_H - 146}),
confirmHandler(std::move(confirmHandler))
{
new StaticText(this, {0, height() / 2, width(), PAGE_LINE_HEIGHT}, message, CENTERED);
}
#if defined(HARDWARE_KEYS)
void ConfirmDialog::onKeyEvent(event_t event)
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
if (event == EVT_KEY_BREAK(KEY_ENTER)) {
confirmHandler();
deleteLater();
}
else if (event == EVT_KEY_BREAK(KEY_EXIT)) {
deleteLater();
}
}
#endif
+38
View File
@@ -0,0 +1,38 @@
/*
* 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.
*/
#ifndef _CONFIRM_DIALOG_H_
#define _CONFIRM_DIALOG_H_
#include "dialog.h"
class ConfirmDialog: public Dialog {
public:
ConfirmDialog(const char * title, const char * message, std::function<void(void)> confirmHandler);
#if defined(HARDWARE_KEYS)
void onKeyEvent(event_t event) override;
#endif
protected:
std::function<void(void)> confirmHandler;
};
#endif // _CONFIRM_DIALOG_H_
+136
View File
@@ -0,0 +1,136 @@
/*
* 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"
#include "curve.h"
#include "lcd.h"
#include "bitmaps.h"
#include "strhelpers.h"
#include "font.h"
void Curve::drawBackground(BitmapBuffer * dc)
{
lcdSetColor(RGB(0xE0, 0xE0, 0xE0));
dc->clear(CUSTOM_COLOR);
// Axis
dc->drawSolidHorizontalLine(0, height()/2, width(), CURVE_AXIS_COLOR);
dc->drawSolidVerticalLine(width()/2, 0, height(), CURVE_AXIS_COLOR);
// Extra lines
dc->drawVerticalLine(width()/4, 0, height(), STASHED, CURVE_AXIS_COLOR);
dc->drawVerticalLine(width()*3/4, 0, height(), STASHED, CURVE_AXIS_COLOR);
dc->drawHorizontalLine(0, height()/4, width(), STASHED, CURVE_AXIS_COLOR);
dc->drawHorizontalLine(0, height()*3/4, width(), STASHED, CURVE_AXIS_COLOR);
// Outside border
// dc->drawSolidRect(0, 0, width(), height(), 1, TEXT_COLOR);
}
coord_t Curve::getPointX(int x)
{
return limit<coord_t>(0,
width() / 2 + divRoundClosest(x * width() / 2, RESX),
width() - 1);
}
coord_t Curve::getPointY(int y)
{
return limit<coord_t>(0,
height() / 2 - divRoundClosest(y * height() / 2, RESX),
height() - 1);
}
void Curve::drawCurve(BitmapBuffer * dc)
{
auto prev = (coord_t) -1;
for (int x = 0; x < width(); x++) {
coord_t y = getPointY(function(divRoundClosest((x - width() / 2) * RESX, width() / 2)));
if (prev >= 0) {
if (prev < y) {
for (int tmp = prev; tmp <= y; tmp++) {
dc->drawBitmapPattern(x - 2, tmp - 2, LBM_POINT, TEXT_COLOR);
}
}
else {
for (int tmp = y; tmp <= prev; tmp++) {
dc->drawBitmapPattern(x - 2, tmp - 2, LBM_POINT, TEXT_COLOR);
}
}
}
prev = y;
}
}
void Curve::drawPosition(BitmapBuffer * dc)
{
int valueX = position();
int valueY = function(valueX);
coord_t x = getPointX(valueX);
coord_t y = getPointY(valueY);
// the 2 lines
dc->drawSolidHorizontalLine(0, y, width(), CURVE_CURSOR_COLOR);
dc->drawSolidVerticalLine(x, 0, height(), CURVE_CURSOR_COLOR);
// the point (white inside)
dc->drawBitmapPattern(x-4, y-4, LBM_CURVE_POINT, CURVE_CURSOR_COLOR);
dc->drawBitmapPattern(x-4, y-4, LBM_CURVE_POINT_CENTER, TEXT_BGCOLOR);
char coords[16];
strAppendSigned(strAppend(strAppendSigned(coords, calcRESXto100(valueX)), ","), calcRESXto100(valueY));
dc->drawSolidFilledRect(10, 11, 1 + getTextWidth(coords, 0, SMLSIZE), 17, CURVE_CURSOR_COLOR);
dc->drawText(11, 10, coords, SMLSIZE|TEXT_BGCOLOR);
}
void Curve::drawPoint(BitmapBuffer * dc, const CurvePoint & point)
{
coord_t x = getPointX(point.coords.x);
coord_t y = getPointY(point.coords.y);
dc->drawBitmapPattern(x-4, y-4, LBM_CURVE_POINT, point.flags);
dc->drawBitmapPattern(x-4, y-4, LBM_CURVE_POINT_CENTER, TEXT_BGCOLOR);
}
void Curve::paint(BitmapBuffer * dc)
{
drawBackground(dc);
drawCurve(dc);
for (auto point: points) {
drawPoint(dc, point);
}
if (position) {
drawPosition(dc);
}
}
void Curve::addPoint(const point_t & point, LcdFlags flags)
{
points.push_back({point, flags});
invalidate();
}
void Curve::clearPoints()
{
points.clear();
invalidate();
}
+74
View File
@@ -0,0 +1,74 @@
/*
* 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.
*/
#ifndef _CURVE_H_
#define _CURVE_H_
#include "window.h"
struct CurvePoint {
point_t coords;
LcdFlags flags;
};
class Curve: public Window {
public:
Curve(Window * parent, const rect_t & rect, std::function<int(int)> function, std::function<int()> position=nullptr):
Window(parent, rect, OPAQUE),
function(std::move(function)),
position(std::move(position))
{
}
#if defined(DEBUG_WINDOWS)
std::string getName() override
{
return "Curve";
}
#endif
void checkEvents() override
{
// will always force a full window refresh
if (position) {
invalidate();
}
}
void addPoint(const point_t & point, LcdFlags flags);
void clearPoints();
void paint(BitmapBuffer * dc) override;
protected:
std::function<int(int)> function;
std::function<int()> position;
std::list<CurvePoint> points;
void drawBackground(BitmapBuffer * dc);
void drawCurve(BitmapBuffer * dc);
void drawPosition(BitmapBuffer * dc);
void drawPoint(BitmapBuffer * dc, const CurvePoint & point);
coord_t getPointX(int x);
coord_t getPointY(int y);
};
#endif // _CURVE_H_
+147
View File
@@ -0,0 +1,147 @@
/*
* 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 "curveedit.h"
#include "keyboard_curve.h"
#include "opentx.h" // TODO for applyCustomCurve
CurveEdit::CurveEdit(Window * parent, const rect_t &rect, uint8_t index) :
Curve(parent, rect, [=](int x) -> int {
return applyCustomCurve(x, index);
}),
index(index),
current(0)
{
update();
}
void CurveEdit::update()
{
clearPoints();
CurveInfo & curve = g_model.curves[index];
for (uint8_t i = 0; i < 5 + curve.points; i++) {
if (hasFocus() && current == i) {
position = [=] () -> int {
return getPoint(index, i).x;
};
}
else {
addPoint(getPoint(index, i), TEXT_COLOR);
}
}
invalidate();
}
#if defined(HARDWARE_TOUCH)
bool CurveEdit::onTouchEnd(coord_t x, coord_t y)
{
if (!hasFocus()) {
setFocus();
update();
}
CurveKeyboard * keyboard = CurveKeyboard::instance();
if (keyboard->getField() != this) {
keyboard->setField(this);
}
CurveInfo & curve = g_model.curves[index];
for (int i=0; i<5 + curve.points; i++) {
if (i != current) {
point_t point = getPoint(index, i);
if (abs(getPointX(point.x) - x) <= 10 && abs(getPointY(point.y) - y) <= 10) {
current = i;
update();
break;
}
}
}
return true;
}
void CurveEdit::onFocusLost()
{
CurveKeyboard::instance()->disable(true);
}
#endif
void CurveEdit::next()
{
if (++current == points.size()) {
current = 0;
}
update();
}
void CurveEdit::previous()
{
if (current-- == 0) {
current = points.size() - 1;
}
update();
}
void CurveEdit::up()
{
int8_t & point = curveAddress(index)[current];
point = min<int8_t>(100, ++point);
storageDirty(EE_MODEL);
invalidate();
}
void CurveEdit::down()
{
int8_t & point = curveAddress(index)[current];
point = max<int8_t>(-100, --point);
storageDirty(EE_MODEL);
invalidate();
}
void CurveEdit::right()
{
CurveInfo & curve = g_model.curves[index];
if (curve.type == CURVE_TYPE_CUSTOM && current != 0 && current != curve.points - 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));
*point = min<int8_t>(*point + 1, xmax-1);
storageDirty(EE_MODEL);
invalidate();
}
}
void CurveEdit::left()
{
CurveInfo & curve = g_model.curves[index];
if (curve.type == CURVE_TYPE_CUSTOM && current != 0 && current != curve.points - 1) {
int8_t * points = curveAddress(index);
int8_t * point = &points[5 + curve.points + current - 1];
int8_t xmin = (current == 1 ? -100 : *(point - 1));
*point = max<int8_t>(xmin+1, *point - 1);
storageDirty(EE_MODEL);
invalidate();
}
}
bool CurveEdit::isCustomCurve()
{
return g_model.curves[index].type == CURVE_TYPE_CUSTOM;
}
+57
View File
@@ -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.
*/
#ifndef _CURVEEDIT_H_
#define _CURVEEDIT_H_
#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
}
void update();
#if defined(HARDWARE_TOUCH)
bool onTouchEnd(coord_t x, coord_t y) override;
void onFocusLost() override;
#endif
protected:
uint8_t index;
uint8_t current;
void next();
void previous();
void up();
void down();
void right();
void left();
bool isCustomCurve();
};
#endif // _CURVEEDIT_H_
+25 -24
View File
@@ -19,32 +19,33 @@
*/
#include "opentx.h"
#include "font.h"
coord_t getCurveYCoord(FnFuncP fn, int x, int width)
{
return limit(-width, -divRoundClosest(fn(divRoundClosest(x * RESX, width)) * width, RESX), +width);
}
void drawFunction(FnFuncP fn, int x, int y, int width)
void drawFunction(BitmapBuffer * dc, FnFuncP fn, int x, int y, int width)
{
int left = x - width;
int right = x + width;
// Axis
lcdDrawSolidHorizontalLine(left, y, width*2+1, CURVE_AXIS_COLOR);
lcdDrawSolidVerticalLine(x, y-width, width*2, CURVE_AXIS_COLOR);
dc->drawSolidHorizontalLine(left, y, width*2+1, CURVE_AXIS_COLOR);
dc->drawSolidVerticalLine(x, y-width, width*2, CURVE_AXIS_COLOR);
// Extra lines
lcdDrawVerticalLine(left+width/2, y-width, width*2, STASHED, CURVE_AXIS_COLOR);
lcdDrawVerticalLine(right-width/2, y-width, width*2, STASHED, CURVE_AXIS_COLOR);
lcdDrawHorizontalLine(left, y-width/2, width*2+1, STASHED, CURVE_AXIS_COLOR);
lcdDrawHorizontalLine(left, y+width/2, width*2+1, STASHED, CURVE_AXIS_COLOR);
dc->drawVerticalLine(left+width/2, y-width, width*2, STASHED, CURVE_AXIS_COLOR);
dc->drawVerticalLine(right-width/2, y-width, width*2, STASHED, CURVE_AXIS_COLOR);
dc->drawHorizontalLine(left, y-width/2, width*2+1, STASHED, CURVE_AXIS_COLOR);
dc->drawHorizontalLine(left, y+width/2, width*2+1, STASHED, CURVE_AXIS_COLOR);
// Outside border
lcdDrawSolidVerticalLine(left, y-width, width*2, TEXT_COLOR);
lcdDrawSolidVerticalLine(right, y-width, width*2, TEXT_COLOR);
lcdDrawSolidHorizontalLine(left, y-width, width*2+1, TEXT_COLOR);
lcdDrawSolidHorizontalLine(left, y+width, width*2+1, TEXT_COLOR);
dc->drawSolidVerticalLine(left, y-width, width*2, TEXT_COLOR);
dc->drawSolidVerticalLine(right, y-width, width*2, TEXT_COLOR);
dc->drawSolidHorizontalLine(left, y-width, width*2+1, TEXT_COLOR);
dc->drawSolidHorizontalLine(left, y+width, width*2+1, TEXT_COLOR);
coord_t prev_yv = (coord_t)-1;
@@ -53,12 +54,12 @@ void drawFunction(FnFuncP fn, int x, int y, int width)
if (prev_yv != (coord_t)-1) {
if (prev_yv < yv) {
for (int y=prev_yv; y<=yv; y+=1) {
lcdDrawBitmapPattern(x+xv-2, y-2, LBM_POINT, TEXT_COLOR);
dc->drawBitmapPattern(x+xv-2, y-2, LBM_POINT, TEXT_COLOR);
}
}
else {
for (int y=yv; y<=prev_yv; y+=1) {
lcdDrawBitmapPattern(x+xv-2, y-2, LBM_POINT, TEXT_COLOR);
dc->drawBitmapPattern(x+xv-2, y-2, LBM_POINT, TEXT_COLOR);
}
}
}
@@ -66,31 +67,31 @@ void drawFunction(FnFuncP fn, int x, int y, int width)
}
}
void drawCurveVerticalScale(int x)
void drawCurveVerticalScale(BitmapBuffer * dc, int x)
{
for (int i=0; i<=20; i++) {
lcdDrawSolidHorizontalLine(x, CURVE_CENTER_Y-CURVE_SIDE_WIDTH+i*CURVE_SIDE_WIDTH/10, 10, TEXT_COLOR);
dc->drawSolidHorizontalLine(x, CURVE_CENTER_Y-CURVE_SIDE_WIDTH+i*CURVE_SIDE_WIDTH/10, 10, TEXT_COLOR);
}
}
void drawCurveHorizontalScale()
void drawCurveHorizontalScale(BitmapBuffer * dc)
{
for (int i=0; i<=20; i++) {
lcdDrawSolidVerticalLine(CURVE_CENTER_X-CURVE_SIDE_WIDTH+i*CURVE_SIDE_WIDTH/10, CURVE_CENTER_Y+CURVE_SIDE_WIDTH+5, 10, TEXT_COLOR);
dc->drawSolidVerticalLine(CURVE_CENTER_X-CURVE_SIDE_WIDTH+i*CURVE_SIDE_WIDTH/10, CURVE_CENTER_Y+CURVE_SIDE_WIDTH+5, 10, TEXT_COLOR);
}
}
void drawCurveCoord(int x, int y, const char * text, bool active)
void drawCurveCoord(BitmapBuffer * dc, int x, int y, const char * text, bool active)
{
lcd->drawSolidFilledRect(x, y, CURVE_COORD_WIDTH, CURVE_COORD_HEIGHT, CURVE_CURSOR_COLOR);
lcdDrawText(x+3+(CURVE_COORD_WIDTH-1-getTextWidth(text, SMLSIZE))/2, y+1, text, LEFT|SMLSIZE|TEXT_BGCOLOR);
dc->drawSolidFilledRect(x, y, CURVE_COORD_WIDTH, CURVE_COORD_HEIGHT, CURVE_CURSOR_COLOR);
dc->drawText(x+3+(CURVE_COORD_WIDTH-1-getTextWidth(text, SMLSIZE))/2, y+1, text, LEFT|SMLSIZE|TEXT_BGCOLOR);
if (active) {
lcdDrawBitmapPattern(x, y, LBM_CURVE_COORD_SHADOW, TEXT_COLOR);
dc->drawBitmapPattern(x, y, LBM_CURVE_COORD_SHADOW, TEXT_COLOR);
}
}
void drawCurvePoint(int x, int y, LcdFlags color)
void drawCurvePoint(BitmapBuffer * dc, int x, int y, LcdFlags color)
{
lcdDrawBitmapPattern(x, y, LBM_CURVE_POINT, color);
lcdDrawBitmapPattern(x, y, LBM_CURVE_POINT_CENTER, TEXT_BGCOLOR);
dc->drawBitmapPattern(x, y, LBM_CURVE_POINT, color);
dc->drawBitmapPattern(x, y, LBM_CURVE_POINT_CENTER, TEXT_BGCOLOR);
}
@@ -0,0 +1,83 @@
/*
* 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 "choice.h"
#include "menu.h"
#include "draw_functions.h"
#include "strhelpers.h"
#include "opentx.h"
extern const uint8_t LBM_DROPDOWN[];
CustomCurveChoice::CustomCurveChoice(Window * parent, const rect_t &rect, int16_t vmin, int16_t vmax,
std::function<int16_t()> getValue, std::function<void(int16_t)> setValue, LcdFlags flags) :
FormField(parent, rect),
vmin(vmin),
vmax(vmax),
getValue(std::move(getValue)),
setValue(std::move(setValue)),
flags(flags)
{
}
void CustomCurveChoice::paint(BitmapBuffer * dc)
{
bool hasFocus = this->hasFocus();
char s[8];
int16_t value = getValue();
LcdFlags textColor = 0;
LcdFlags lineColor = CURVE_AXIS_COLOR;
if (hasFocus) {
textColor = TEXT_INVERTED_BGCOLOR;
lineColor = TEXT_INVERTED_BGCOLOR;
}
dc->drawText(3, 2, getCurveString(s, value), flags | textColor);
dc->drawSolidRect(0, 0, rect.w, rect.h, 1, lineColor);
dc->drawBitmapPattern(rect.w - 14, (rect.h - 5) / 2, LBM_DROPDOWN, lineColor);
}
#if defined(HARDWARE_TOUCH)
bool CustomCurveChoice::onTouchEnd(coord_t x, coord_t y)
{
auto menu = new Menu();
auto value = getValue();
int count = 0;
int current = -1;
char s[8];
for (int i = vmin; i <= vmax; ++i) {
menu->addLine(getCurveString(s, i), [=]() {
setValue(i);
});
if (value == i) {
current = count;
}
++count;
}
if (current >= 0) {
menu->select(current);
}
setFocus();
return true;
}
#endif
@@ -0,0 +1,52 @@
/*
* 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.
*/
#ifndef _CHOICE_H_
#define _CHOICE_H_
#include "form.h"
#include <string>
class CustomCurveChoice : public FormField {
public:
CustomCurveChoice(Window * parent, const rect_t & rect, int16_t vmin, int16_t vmax, std::function<int16_t()> getValue, std::function<void(int16_t)> setValue, LcdFlags flags = 0);
#if defined(DEBUG_WINDOWS)
std::string getName() override
{
return "CustomCurveChoice";
}
#endif
void paint(BitmapBuffer * dc) override;
#if defined(HARDWARE_TOUCH)
bool onTouchEnd(coord_t x, coord_t y) override;
#endif
protected:
int16_t vmin;
int16_t vmax;
std::function<int16_t()> getValue;
std::function<void(int16_t)> setValue;
LcdFlags flags;
};
#endif // _CHOICE_H_
+106 -107
View File
@@ -20,99 +20,99 @@
#include "opentx.h"
void drawStatusText(const char * text)
void drawStatusText(BitmapBuffer * dc, const char * text)
{
lcdDrawText(MENUS_MARGIN_LEFT, MENU_FOOTER_TOP, text, TEXT_STATUSBAR_COLOR);
dc->drawText(MENUS_MARGIN_LEFT, MENU_FOOTER_TOP, text, TEXT_STATUSBAR_COLOR);
}
void drawColumnHeader(const char * const * headers, const char * const * descriptions, uint8_t index)
void drawColumnHeader(BitmapBuffer * dc, const char * const * headers, const char * const * descriptions, uint8_t index)
{
lcdDrawText(LCD_W-MENUS_MARGIN_LEFT, MENU_TITLE_TOP + 2, headers[index], RIGHT | SMLSIZE | MENU_TITLE_COLOR);
dc->drawText(LCD_W-MENUS_MARGIN_LEFT, MENU_TITLE_TOP + 2, headers[index], RIGHT | SMLSIZE | MENU_TITLE_COLOR);
if (descriptions) {
drawStatusText(descriptions[index]);
drawStatusText(dc, descriptions[index]);
}
}
void drawCheckBox(coord_t x, coord_t y, uint8_t value, LcdFlags attr)
void drawCheckBox(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t value, LcdFlags attr)
{
if (attr) {
lcdDrawSolidFilledRect(x-1, y+3, 14, 14, TEXT_INVERTED_BGCOLOR);
lcdDrawSolidFilledRect(x+1, y+5, 10, 10, TEXT_BGCOLOR);
dc->drawSolidFilledRect(x-1, y+3, 14, 14, TEXT_INVERTED_BGCOLOR);
dc->drawSolidFilledRect(x+1, y+5, 10, 10, TEXT_BGCOLOR);
if (value) {
lcdDrawSolidFilledRect(x+2, y+6, 8, 8, TEXT_INVERTED_BGCOLOR);
dc->drawSolidFilledRect(x+2, y+6, 8, 8, TEXT_INVERTED_BGCOLOR);
}
}
else {
if (value) {
lcdDrawSolidFilledRect(x+2, y+6, 8, 8, SCROLLBOX_COLOR);
lcdDrawSolidRect(x, y+4, 12, 12, 1, LINE_COLOR);
dc->drawSolidFilledRect(x+2, y+6, 8, 8, SCROLLBOX_COLOR);
dc->drawSolidRect(x, y+4, 12, 12, 1, LINE_COLOR);
}
else {
lcdDrawSolidRect(x, y+4, 12, 12, 1, LINE_COLOR);
dc->drawSolidRect(x, y+4, 12, 12, 1, LINE_COLOR);
}
}
}
void drawVerticalScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t count, uint8_t visible)
void drawVerticalScrollbar(BitmapBuffer * dc, coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t count, uint8_t visible)
{
if (visible < count) {
lcdDrawSolidVerticalLine(x, y, h, LINE_COLOR);
dc->drawSolidVerticalLine(x, y, h, LINE_COLOR);
coord_t yofs = (h*offset + count/2) / count;
coord_t yhgt = (h*visible + count/2) / count;
if (yhgt + yofs > h)
yhgt = h - yofs;
lcdDrawSolidFilledRect(x-1, y + yofs, 3, yhgt, SCROLLBOX_COLOR);
dc->drawSolidFilledRect(x-1, y + yofs, 3, yhgt, SCROLLBOX_COLOR);
}
}
void drawTrimSquare(coord_t x, coord_t y)
void drawTrimSquare(BitmapBuffer * dc, coord_t x, coord_t y)
{
lcdDrawSolidFilledRect(x-2, y, 15, 15, TRIM_BGCOLOR);
lcdDrawBitmapPattern(x-2, y, LBM_TRIM_SHADOW, TRIM_SHADOW_COLOR);
dc->drawSolidFilledRect(x-2, y, 15, 15, TRIM_BGCOLOR);
dc->drawBitmapPattern(x-2, y, LBM_TRIM_SHADOW, TRIM_SHADOW_COLOR);
}
void drawHorizontalTrimPosition(coord_t x, coord_t y, int16_t dir)
void drawHorizontalTrimPosition(BitmapBuffer * dc, coord_t x, coord_t y, int16_t dir)
{
drawTrimSquare(x, y);
drawTrimSquare(dc, x, y);
if (dir >= 0) {
lcdDrawSolidVerticalLine(x+8, y+3, 9, TEXT_INVERTED_COLOR);
dc->drawSolidVerticalLine(x+8, y+3, 9, TEXT_INVERTED_COLOR);
}
if (dir <= 0) {
lcdDrawSolidVerticalLine(x+2, y+3, 9, TEXT_INVERTED_COLOR);
dc->drawSolidVerticalLine(x+2, y+3, 9, TEXT_INVERTED_COLOR);
}
// if (exttrim) {
// lcdDrawSolidVerticalLine(xm, ym, 9, TEXT_INVERTED_COLOR);
// }
}
void drawVerticalTrimPosition(coord_t x, coord_t y, int16_t dir)
void drawVerticalTrimPosition(BitmapBuffer * dc, coord_t x, coord_t y, int16_t dir)
{
drawTrimSquare(x, y);
drawTrimSquare(dc, x, y);
if (dir >= 0) {
lcdDrawSolidHorizontalLine(x+1, y+4, 9, TEXT_INVERTED_COLOR);
dc->drawSolidHorizontalLine(x+1, y+4, 9, TEXT_INVERTED_COLOR);
}
if (dir <= 0) {
lcdDrawSolidHorizontalLine(x+1, y+10, 9, TEXT_INVERTED_COLOR);
dc->drawSolidHorizontalLine(x+1, y+10, 9, TEXT_INVERTED_COLOR);
}
// if (exttrim) {
// lcdDrawSolidHorizontalLine(xm-1, ym, 3, TEXT_INVERTED_COLOR);
// }
}
void drawVerticalSlider(coord_t x, coord_t y, int len, int val, int min, int max, uint8_t steps, uint32_t options)
void drawVerticalSlider(BitmapBuffer * dc, coord_t x, coord_t y, int len, int val, int min, int max, uint8_t steps, uint32_t options)
{
val = limit(min, val, max);
if (steps) {
int delta = len / steps;
for (int i = 0; i <= len; i += delta) {
if ((options & OPTION_SLIDER_BIG_TICKS) && (i == 0 || i == len / 2 || i == len))
lcdDrawSolidHorizontalLine(x, y + i, 13, TEXT_COLOR);
dc->drawSolidHorizontalLine(x, y + i, 13, TEXT_COLOR);
else
lcdDrawSolidHorizontalLine(x + 2, y + i, 9, TEXT_COLOR);
dc->drawSolidHorizontalLine(x + 2, y + i, 9, TEXT_COLOR);
}
}
else {
lcdDrawBitmapPattern(x + 1, y, LBM_VTRIM_FRAME, TEXT_COLOR);
dc->drawBitmapPattern(x + 1, y, LBM_VTRIM_FRAME, TEXT_COLOR);
/* if (g_model.displayTrims != DISPLAY_TRIMS_NEVER && trim != 0) {
if (g_model.displayTrims == DISPLAY_TRIMS_ALWAYS || (trimsDisplayTimer > 0 && (trimsDisplayMask & (1<<i)))) {
lcdDrawNumber((stickIndex==0 ? TRIM_LH_X : TRIM_RH_X)+(trim>0 ? -20 : 50), ym+1, trim, TINSIZE);
@@ -121,18 +121,18 @@ void drawVerticalSlider(coord_t x, coord_t y, int len, int val, int min, int max
}
y += len - divRoundClosest(len * (val - min), max - min) - 5;
if (options & OPTION_SLIDER_TRIM_BUTTON) {
drawVerticalTrimPosition(x, y - 2, val);
drawVerticalTrimPosition(dc, x, y - 2, val);
}
else if (options & OPTION_SLIDER_NUMBER_BUTTON) {
drawTrimSquare(x, y - 2);
lcdDrawChar(x + 2, y - 1, '0' + val, SMLSIZE | TEXT_INVERTED_COLOR);
drawTrimSquare(dc, x, y - 2);
// TODO lcdDrawChar(x + 2, y - 1, '0' + val, SMLSIZE | TEXT_INVERTED_COLOR);
}
else {
drawTrimSquare(x, y - 2);
drawTrimSquare(dc, x, y - 2);
}
}
void drawHorizontalSlider(coord_t x, coord_t y, int len, int val, int min, int max, uint8_t steps, uint32_t options)
void drawHorizontalSlider(BitmapBuffer * dc, coord_t x, coord_t y, int len, int val, int min, int max, uint8_t steps, uint32_t options)
{
val = limit(min, val, max);
int w = divRoundClosest(len * (val - min), max - min);
@@ -141,27 +141,27 @@ void drawHorizontalSlider(coord_t x, coord_t y, int len, int val, int min, int m
int delta = len / steps;
for (int i = 0; i <= len; i += delta) {
if ((options & OPTION_SLIDER_BIG_TICKS) && (i == 0 || i == len / 2 || i == len))
lcdDrawSolidVerticalLine(x + i, y, 13, TEXT_COLOR);
dc->drawSolidVerticalLine(x + i, y, 13, TEXT_COLOR);
else
lcdDrawSolidVerticalLine(x + i, y + 2, 9, TEXT_COLOR);
dc->drawSolidVerticalLine(x + i, y + 2, 9, TEXT_COLOR);
}
}
}
else if (options & OPTION_SLIDER_EMPTY_BAR) {
lcdDrawBitmapPattern(x, y + 1, LBM_HTRIM_FRAME, TEXT_COLOR);
dc->drawBitmapPattern(x, y + 1, LBM_HTRIM_FRAME, TEXT_COLOR);
}
else if (options & OPTION_SLIDER_DBL_COLOR) {
lcdDrawBitmapPattern(x, y + 8, LBM_SLIDER_BAR_LEFT, w <= 0 ? LINE_COLOR : TEXT_INVERTED_BGCOLOR);
dc->drawBitmapPattern(x, y + 8, LBM_SLIDER_BAR_LEFT, w <= 0 ? LINE_COLOR : TEXT_INVERTED_BGCOLOR);
if (w > 4)
lcdDrawSolidFilledRect(x + 4, y + 8, w - 4, 4, TEXT_INVERTED_BGCOLOR);
dc->drawSolidFilledRect(x + 4, y + 8, w - 4, 4, TEXT_INVERTED_BGCOLOR);
if (w < len - 4)
lcdDrawSolidFilledRect(x + w, y + 8, len - w - 4, 4, LINE_COLOR);
lcdDrawBitmapPattern(x + len - 4, y + 8, LBM_SLIDER_BAR_RIGHT, w >= len ? TEXT_INVERTED_BGCOLOR : LINE_COLOR);
dc->drawSolidFilledRect(x + w, y + 8, len - w - 4, 4, LINE_COLOR);
dc->drawBitmapPattern(x + len - 4, y + 8, LBM_SLIDER_BAR_RIGHT, w >= len ? TEXT_INVERTED_BGCOLOR : LINE_COLOR);
}
else {
lcdDrawBitmapPattern(x, y + 8, LBM_SLIDER_BAR_LEFT, LINE_COLOR);
lcdDrawSolidFilledRect(x + 4, y + 8, len - 8, 4, LINE_COLOR);
lcdDrawBitmapPattern(x + len - 4, y + 8, LBM_SLIDER_BAR_RIGHT, LINE_COLOR);
dc->drawBitmapPattern(x, y + 8, LBM_SLIDER_BAR_LEFT, LINE_COLOR);
dc->drawSolidFilledRect(x + 4, y + 8, len - 8, 4, LINE_COLOR);
dc->drawBitmapPattern(x + len - 4, y + 8, LBM_SLIDER_BAR_RIGHT, LINE_COLOR);
//
/* if (g_model.displayTrims != DISPLAY_TRIMS_NEVER && trim != 0) {
if (g_model.displayTrims == DISPLAY_TRIMS_ALWAYS || (trimsDisplayTimer > 0 && (trimsDisplayMask & (1<<i)))) {
@@ -171,21 +171,21 @@ void drawHorizontalSlider(coord_t x, coord_t y, int len, int val, int min, int m
}
x += w - 5;
if (options & OPTION_SLIDER_TRIM_BUTTON) {
drawHorizontalTrimPosition(x, y - 1, val);
drawHorizontalTrimPosition(dc, x, y - 1, val);
}
else if (options & OPTION_SLIDER_NUMBER_BUTTON) {
drawTrimSquare(x+2, y - 1);
drawTrimSquare(dc, x+2, y - 1);
char text[] = { (char)('0' + val), '\0' };
lcdDrawText(x + 7, y - 1, text, SMLSIZE | CENTERED | TEXT_INVERTED_COLOR);
dc->drawText(x + 7, y - 1, text, SMLSIZE | CENTERED | TEXT_INVERTED_COLOR);
}
else if (options & OPTION_SLIDER_SQUARE_BUTTON) {
drawTrimSquare(x, y - 1);
drawTrimSquare(dc, x, y - 1);
}
else {
lcdDrawBitmapPattern(x, y + 2, LBM_SLIDER_POINT_OUT, TEXT_COLOR);
lcdDrawBitmapPattern(x, y + 2, LBM_SLIDER_POINT_MID, TEXT_BGCOLOR);
dc->drawBitmapPattern(x, y + 2, LBM_SLIDER_POINT_OUT, TEXT_COLOR);
dc->drawBitmapPattern(x, y + 2, LBM_SLIDER_POINT_MID, TEXT_BGCOLOR);
if ((options & INVERS) && (!(options & BLINK) || !BLINK_ON_PHASE))
lcdDrawBitmapPattern(x, y + 2, LBM_SLIDER_POINT_IN, TEXT_INVERTED_BGCOLOR);
dc->drawBitmapPattern(x, y + 2, LBM_SLIDER_POINT_IN, TEXT_INVERTED_BGCOLOR);
}
}
@@ -248,7 +248,7 @@ int16_t editGVarFieldValue(coord_t x, coord_t y, int16_t value, int16_t min, int
#else
void drawValueOrGVar(BitmapBuffer * dc, coord_t x, coord_t y, gvar_t value, LcdFlags flags)
{
drawNumber(dc, x, y, value, flags, 0, nullptr, "%");
dc->drawNumber(x, y, value, flags, 0, nullptr, "%");
}
#endif
@@ -258,7 +258,7 @@ void drawSleepBitmap()
lcd->clearClippingRect();
lcd->clear();
const BitmapBuffer * bitmap = BitmapBuffer::load(getThemePath("sleep.bmp"));
const BitmapBuffer * bitmap = BitmapBuffer::load(static_cast<ThemeBase *>(theme)->getFilePath("sleep.bmp"));
if (bitmap) {
lcd->drawBitmap((LCD_W-bitmap->getWidth())/2, (LCD_H-bitmap->getHeight())/2, bitmap);
delete bitmap;
@@ -274,21 +274,21 @@ void drawShutdownAnimation(uint32_t duration, uint32_t totalDuration, const char
return;
static uint32_t lastDuration = 0xffffffff;
static const BitmapBuffer * shutdown = BitmapBuffer::load(getThemePath("shutdown.bmp"));
static const BitmapBuffer * shutdown = BitmapBuffer::load(static_cast<ThemeBase *>(theme)->getFilePath("shutdown.bmp"));
if (shutdown) {
if (duration < lastDuration) {
theme->drawBackground(lcd);
static_cast<ThemeBase *>(theme)->drawBackground(lcd);
lcd->drawBitmap((LCD_W-shutdown->getWidth())/2, (LCD_H-shutdown->getHeight())/2, shutdown);
lcdStoreBackupBuffer();
}
else {
lcdRestoreBackupBuffer();
int quarter = duration / (totalDuration / 5);
if (quarter >= 1) lcdDrawBitmapPattern(LCD_W/2, (LCD_H-SHUTDOWN_CIRCLE_DIAMETER)/2, LBM_SHUTDOWN_CIRCLE, TEXT_COLOR, 0, SHUTDOWN_CIRCLE_DIAMETER/2);
if (quarter >= 2) lcdDrawBitmapPattern(LCD_W/2, LCD_H/2, LBM_SHUTDOWN_CIRCLE, TEXT_COLOR, SHUTDOWN_CIRCLE_DIAMETER/2, SHUTDOWN_CIRCLE_DIAMETER/2);
if (quarter >= 3) lcdDrawBitmapPattern((LCD_W-SHUTDOWN_CIRCLE_DIAMETER)/2, LCD_H/2, LBM_SHUTDOWN_CIRCLE, TEXT_COLOR, SHUTDOWN_CIRCLE_DIAMETER, SHUTDOWN_CIRCLE_DIAMETER/2);
if (quarter >= 4) lcdDrawBitmapPattern((LCD_W-SHUTDOWN_CIRCLE_DIAMETER)/2, (LCD_H-SHUTDOWN_CIRCLE_DIAMETER)/2, LBM_SHUTDOWN_CIRCLE, TEXT_COLOR, SHUTDOWN_CIRCLE_DIAMETER*3/2, SHUTDOWN_CIRCLE_DIAMETER/2);
if (quarter >= 1) lcd->drawBitmapPattern(LCD_W/2, (LCD_H-SHUTDOWN_CIRCLE_DIAMETER)/2, LBM_SHUTDOWN_CIRCLE, TEXT_COLOR, 0, SHUTDOWN_CIRCLE_DIAMETER/2);
if (quarter >= 2) lcd->drawBitmapPattern(LCD_W/2, LCD_H/2, LBM_SHUTDOWN_CIRCLE, TEXT_COLOR, SHUTDOWN_CIRCLE_DIAMETER/2, SHUTDOWN_CIRCLE_DIAMETER/2);
if (quarter >= 3) lcd->drawBitmapPattern((LCD_W-SHUTDOWN_CIRCLE_DIAMETER)/2, LCD_H/2, LBM_SHUTDOWN_CIRCLE, TEXT_COLOR, SHUTDOWN_CIRCLE_DIAMETER, SHUTDOWN_CIRCLE_DIAMETER/2);
if (quarter >= 4) lcd->drawBitmapPattern((LCD_W-SHUTDOWN_CIRCLE_DIAMETER)/2, (LCD_H-SHUTDOWN_CIRCLE_DIAMETER)/2, LBM_SHUTDOWN_CIRCLE, TEXT_COLOR, SHUTDOWN_CIRCLE_DIAMETER*3/2, SHUTDOWN_CIRCLE_DIAMETER/2);
}
}
else {
@@ -320,7 +320,7 @@ void drawCurveRef(BitmapBuffer * dc, coord_t x, coord_t y, const CurveRef & curv
break;
case CURVE_REF_FUNC:
drawTextAtIndex(dc, x, y, STR_VCURVEFUNC, curve.value, flags);
dc->drawTextAtIndex(x, y, STR_VCURVEFUNC, curve.value, flags);
break;
case CURVE_REF_CUSTOM:
@@ -330,13 +330,13 @@ void drawCurveRef(BitmapBuffer * dc, coord_t x, coord_t y, const CurveRef & curv
}
}
void putsStickName(coord_t x, coord_t y, uint8_t idx, LcdFlags att)
void drawStickName(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t idx, LcdFlags att)
{
uint8_t length = STR_VSRCRAW[0];
lcdDrawSizedText(x, y, STR_VSRCRAW+2+length*(idx+1), length-1, att);
dc->drawSizedText(x, y, STR_VSRCRAW+2+length*(idx+1), length-1, att);
}
void putsModelName(coord_t x, coord_t y, char * name, uint8_t id, LcdFlags att)
void drawModelName(BitmapBuffer * dc, coord_t x, coord_t y, char * name, uint8_t id, LcdFlags att)
{
uint8_t len = sizeof(g_model.header.name);
while (len>0 && !name[len-1]) --len;
@@ -344,15 +344,15 @@ void putsModelName(coord_t x, coord_t y, char * name, uint8_t id, LcdFlags att)
drawStringWithIndex(x, y, STR_MODEL, id+1, att|LEADING0);
}
else {
lcdDrawSizedText(x, y, name, sizeof(g_model.header.name), ZCHAR|att);
dc->drawSizedText(x, y, name, sizeof(g_model.header.name), att);
}
}
void drawCurveName(coord_t x, coord_t y, int8_t idx, LcdFlags flags)
void drawCurveName(BitmapBuffer * dc, coord_t x, coord_t y, int8_t idx, LcdFlags flags)
{
char s[8];
getCurveString(s, idx);
lcdDrawText(x, y, s, flags);
dc->drawText(x, y, s, flags);
}
void drawSource(BitmapBuffer * dc, coord_t x, coord_t y, mixsrc_t idx, LcdFlags flags)
@@ -390,33 +390,33 @@ void drawDate(BitmapBuffer * dc, coord_t x, coord_t y, TelemetryItem & telemetry
if (att & DBLSIZE) {
x -= 42;
att &= ~FONTSIZE_MASK;
lcdDrawNumber(x, y, telemetryItem.datetime.day, att|LEADING0|LEFT, 2);
lcdDrawChar(lcdNextPos-1, y, '-', att);
lcdDrawNumber(lcdNextPos-1, y, telemetryItem.datetime.month, att|LEFT, 2);
lcdDrawChar(lcdNextPos-1, y, '-', att);
lcdDrawNumber(lcdNextPos-1, y, telemetryItem.datetime.year-2000, att|LEFT);
dc->drawNumber(x, y, telemetryItem.datetime.day, att|LEADING0|LEFT, 2);
dc->drawText(lcdNextPos-1, y, "-", att);
dc->drawNumber(lcdNextPos-1, y, telemetryItem.datetime.month, att|LEFT, 2);
dc->drawText(lcdNextPos-1, y, "-", att);
dc->drawNumber(lcdNextPos-1, y, telemetryItem.datetime.year-2000, att|LEFT);
y += FH;
lcdDrawNumber(x, y, telemetryItem.datetime.hour, att|LEADING0|LEFT, 2);
lcdDrawChar(lcdNextPos, y, ':', att);
lcdDrawNumber(lcdNextPos, y, telemetryItem.datetime.min, att|LEADING0|LEFT, 2);
lcdDrawChar(lcdNextPos, y, ':', att);
lcdDrawNumber(lcdNextPos, y, telemetryItem.datetime.sec, att|LEADING0|LEFT, 2);
dc->drawNumber(x, y, telemetryItem.datetime.hour, att|LEADING0|LEFT, 2);
dc->drawText(lcdNextPos, y, ":", att);
dc->drawNumber(lcdNextPos, y, telemetryItem.datetime.min, att|LEADING0|LEFT, 2);
dc->drawText(lcdNextPos, y, ":", att);
dc->drawNumber(lcdNextPos, y, telemetryItem.datetime.sec, att|LEADING0|LEFT, 2);
}
else {
lcdDrawNumber(x, y, telemetryItem.datetime.day, att|LEADING0|LEFT, 2);
lcdDrawChar(lcdNextPos-1, y, '-', att);
lcdDrawNumber(lcdNextPos, y, telemetryItem.datetime.month, att|LEFT, 2);
lcdDrawChar(lcdNextPos-1, y, '-', att);
lcdDrawNumber(lcdNextPos, y, telemetryItem.datetime.year-2000, att|LEFT);
lcdDrawNumber(lcdNextPos+11, y, telemetryItem.datetime.hour, att|LEADING0|LEFT, 2);
lcdDrawChar(lcdNextPos, y, ':', att);
lcdDrawNumber(lcdNextPos, y, telemetryItem.datetime.min, att|LEADING0|LEFT, 2);
lcdDrawChar(lcdNextPos, y, ':', att);
lcdDrawNumber(lcdNextPos, y, telemetryItem.datetime.sec, att|LEADING0|LEFT, 2);
dc->drawNumber(x, y, telemetryItem.datetime.day, att|LEADING0|LEFT, 2);
dc->drawText(lcdNextPos-1, y, "-", att);
dc->drawNumber(lcdNextPos, y, telemetryItem.datetime.month, att|LEFT, 2);
dc->drawText(lcdNextPos-1, y, "-", att);
dc->drawNumber(lcdNextPos, y, telemetryItem.datetime.year-2000, att|LEFT);
dc->drawNumber(lcdNextPos+11, y, telemetryItem.datetime.hour, att|LEADING0|LEFT, 2);
dc->drawText(lcdNextPos, y, ":", att);
dc->drawNumber(lcdNextPos, y, telemetryItem.datetime.min, att|LEADING0|LEFT, 2);
dc->drawText(lcdNextPos, y, ":", att);
dc->drawNumber(lcdNextPos, y, telemetryItem.datetime.sec, att|LEADING0|LEFT, 2);
}
}
void drawGPSCoord(coord_t x, coord_t y, int32_t value, const char * direction, LcdFlags flags, bool seconds=true)
void drawGPSCoord(BitmapBuffer * dc, coord_t x, coord_t y, int32_t value, const char * direction, LcdFlags flags, bool seconds=true)
{
char s[32];
uint32_t absvalue = abs(value);
@@ -445,27 +445,26 @@ void drawGPSCoord(coord_t x, coord_t y, int32_t value, const char * direction, L
}
*tmp++ = direction[value>=0 ? 0 : 1];
*tmp = '\0';
lcdDrawText(x, y, s, flags);
dc->drawText(x, y, s, flags);
}
void drawGPSPosition(coord_t x, coord_t y, int32_t longitude, int32_t latitude, LcdFlags flags)
void drawGPSPosition(BitmapBuffer * dc, coord_t x, coord_t y, int32_t longitude, int32_t latitude, LcdFlags flags)
{
if (flags & EXPANDED) {
drawGPSCoord(x, y, latitude, "NS", flags, true);
drawGPSCoord(x, y + FH, longitude, "EW", flags, true);
drawGPSCoord(dc, x, y, latitude, "NS", flags, true);
drawGPSCoord(dc, x, y + FH, longitude, "EW", flags, true);
}
else {
drawGPSCoord(x, y, latitude, "NS", flags, false);
drawGPSCoord(lcdNextPos+5, y, longitude, "EW", flags, false);
drawGPSCoord(dc, x, y, latitude, "NS", flags, false);
drawGPSCoord(dc, lcdNextPos+5, y, longitude, "EW", flags, false);
}
}
void drawGPSSensorValue(coord_t x, coord_t y, TelemetryItem & telemetryItem, LcdFlags flags)
void drawGPSSensorValue(BitmapBuffer * dc, coord_t x, coord_t y, TelemetryItem & telemetryItem, LcdFlags flags)
{
drawGPSPosition(x, y, telemetryItem.gps.longitude, telemetryItem.gps.latitude, flags);
drawGPSPosition(dc, x, y, telemetryItem.gps.longitude, telemetryItem.gps.latitude, flags);
}
void drawSensorCustomValue(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t sensor, int32_t value, LcdFlags flags)
{
if (sensor >= MAX_TELEMETRY_SENSORS) {
@@ -480,14 +479,14 @@ void drawSensorCustomValue(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t sens
drawDate(dc, x, y, telemetryItem, flags);
}
else if (telemetrySensor.unit == UNIT_GPS) {
drawGPSSensorValue(x, y, telemetryItem, flags);
drawGPSSensorValue(dc, x, y, telemetryItem, flags);
}
else if (telemetrySensor.unit == UNIT_BITFIELD) {
if (IS_FRSKY_SPORT_PROTOCOL()) {
if (telemetrySensor.id >= RBOX_STATE_FIRST_ID && telemetrySensor.id <= RBOX_STATE_LAST_ID) {
if (telemetrySensor.subId == 0) {
if (value == 0) {
lcdDrawText(x, y, "OK", flags);
dc->drawText(x, y, "OK", flags);
}
else {
for (uint8_t i=0; i<16; i++) {
@@ -551,7 +550,7 @@ void drawSourceCustomValue(BitmapBuffer * dc, coord_t x, coord_t y, source_t sou
// TODO drawTimer(dc, x, y, value, flags);
}
else if (source == MIXSRC_TX_VOLTAGE) {
lcdDrawNumber(x, y, value, flags|PREC1);
dc->drawNumber(x, y, value, flags|PREC1);
}
#if defined(INTERNAL_GPS)
else if (source == MIXSRC_TX_GPS) {
@@ -560,7 +559,7 @@ void drawSourceCustomValue(BitmapBuffer * dc, coord_t x, coord_t y, source_t sou
}
else {
lcdDrawText(x, y, "sats: ", flags);
lcdDrawNumber(lcdNextPos, y, gpsData.numSat, flags);
dc->drawNumber(lcdNextPos, y, gpsData.numSat, flags);
}
}
#endif
@@ -570,26 +569,26 @@ void drawSourceCustomValue(BitmapBuffer * dc, coord_t x, coord_t y, source_t sou
}
#endif
else if (source < MIXSRC_FIRST_CH) {
lcdDrawNumber(x, y, calcRESXto100(value), flags);
dc->drawNumber(x, y, calcRESXto100(value), flags);
}
else if (source <= MIXSRC_LAST_CH) {
#if defined(PPM_UNIT_PERCENT_PREC1)
lcdDrawNumber(x, y, calcRESXto1000(value), flags|PREC1);
dc->drawNumber(x, y, calcRESXto1000(value), flags|PREC1);
#else
lcdDrawNumber(x, y, calcRESXto100(value), flags);
dc->drawNumber(x, y, calcRESXto100(value), flags);
#endif
}
else {
lcdDrawNumber(x, y, value, flags);
dc->drawNumber(x, y, value, flags);
}
}
void drawValueWithUnit(BitmapBuffer * dc, coord_t x, coord_t y, int val, uint8_t unit, LcdFlags flags)
{
// convertUnit(val, unit);
drawNumber(dc, x, y, val, flags & (~NO_UNIT));
dc->drawNumber(x, y, val, flags & (~NO_UNIT));
if (!(flags & NO_UNIT) && unit != UNIT_RAW) {
drawTextAtIndex(dc, lcdNextPos/*+1*/, y, STR_VTELEMUNIT, unit, 0);
dc->drawTextAtIndex(lcdNextPos/*+1*/, y, STR_VTELEMUNIT, unit, 0);
}
}
+29 -11
View File
@@ -21,7 +21,8 @@
#ifndef _DRAW_FUNCTIONS_H_
#define _DRAW_FUNCTIONS_H_
#include "opentx.h"
#include "dataconstants.h"
#include "telemetry/telemetry_sensors.h"
#include <stdio.h>
#define OPTION_MENU_NO_FOOTER 0x01
@@ -39,16 +40,33 @@
#define OPTION_SLIDER_NUMBER_BUTTON 0x100
#define OPTION_SLIDER_SQUARE_BUTTON 0x200
void drawStatusText(const char * text);
void drawColumnHeader(const char * const * headers, const char * const * descriptions, uint8_t index);
void drawCheckBox(coord_t x, coord_t y, uint8_t value, LcdFlags attr);
void drawVerticalScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t count, uint8_t visible);
void drawProgressScreen(const char * title, const char * message, int num, int den);
void drawTrimSquare(coord_t x, coord_t y);
void drawHorizontalTrimPosition(coord_t x, coord_t y, int16_t dir);
void drawVerticalTrimPosition(coord_t x, coord_t y, int16_t dir);
void drawVerticalSlider(coord_t x, coord_t y, int len, int val, int min, int max, uint8_t steps, uint32_t options);
void drawHorizontalSlider(coord_t x, coord_t y, int len, int val, int min, int max, uint8_t steps, uint32_t options);
void drawStringWithIndex(coord_t x, coord_t y, const char * str, int idx, LcdFlags flags, const char * prefix, const char * suffix);
void drawValueWithUnit(coord_t x, coord_t y, int val, uint8_t unit, LcdFlags att);
//int editChoice(coord_t x, coord_t y, const char * values, int value, int min, int max, LcdFlags attr, event_t event, IsValueAvailable isValueAvailable=nullptr);
//uint8_t editCheckBox(uint8_t value, coord_t x, coord_t y, LcdFlags attr, event_t event);
//swsrc_t editSwitch(coord_t x, coord_t y, swsrc_t value, LcdFlags attr, event_t event);
void drawFatalErrorScreen(const char * message);
void runFatalErrorScreen(const char * message);
void drawPower(coord_t x, coord_t y, int8_t dBm, LcdFlags att);
//void lcdDrawMMM(coord_t x, coord_t y, LcdFlags flags);
void drawSource(BitmapBuffer * dc, coord_t x, coord_t y, mixsrc_t idx, LcdFlags flags=0);
void drawSwitch(BitmapBuffer * dc, coord_t x, coord_t y, int32_t idx, LcdFlags flags=0);
void drawTrimMode(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t phase, uint8_t idx, LcdFlags flags = 0);
#if defined(FLIGHT_MODES)
void drawFlightMode(coord_t x, coord_t y, int8_t idx, LcdFlags att);
#endif
void drawStatusText(BitmapBuffer * dc, const char * text);
void drawColumnHeader(BitmapBuffer * dc, const char * const * headers, const char * const * descriptions, uint8_t index);
void drawCheckBox(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t value, LcdFlags attr);
void drawVerticalScrollbar(BitmapBuffer * dc, coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t count, uint8_t visible);
void drawProgressScreen(BitmapBuffer * dc, const char * title, const char * message, int num, int den);
void drawTrimSquare(BitmapBuffer * dc, coord_t x, coord_t y);
void drawHorizontalTrimPosition(BitmapBuffer * dc, coord_t x, coord_t y, int16_t dir);
void drawVerticalTrimPosition(BitmapBuffer * dc, coord_t x, coord_t y, int16_t dir);
void drawVerticalSlider(BitmapBuffer * dc, coord_t x, coord_t y, int len, int val, int min, int max, uint8_t steps, uint32_t options);
void drawHorizontalSlider(BitmapBuffer * dc, coord_t x, coord_t y, int len, int val, int min, int max, uint8_t steps, uint32_t options);
void drawSlider(coord_t x, coord_t y, int len, int val, int min, int max, uint8_t steps, uint32_t options);
void drawValueOrGVar(BitmapBuffer * dc, coord_t x, coord_t y, gvar_t gvar, LcdFlags flags = 0);
void drawGVarValue(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t gvar, gvar_t value, LcdFlags flags = 0);
+29 -12
View File
@@ -19,7 +19,6 @@
*/
#include "opentx.h"
#include "rle.h"
const uint16_t font_tinsize_specs[] = {
#include "font_9.specs"
@@ -30,6 +29,14 @@ const unsigned char font_tinsize[] = {
};
#if defined(HARDWARE_TOUCH)
const uint16_t font_stdsize_en_specs[] = {
#include "font_17en.specs"
};
const unsigned char font_stdsize_en[] = {
#include "font_17en.lbm"
};
const uint16_t font_smlsize_specs[] = {
#include "font_15.specs"
};
@@ -54,6 +61,14 @@ const unsigned char font_stdsizebold[] = {
#include "font_bold17.lbm"
};
#else
const uint16_t font_stdsize_en_specs[] = {
#include "font_16en.specs"
};
const unsigned char font_stdsize_en[] = {
#include "font_16en.lbm"
};
const uint16_t font_smlsize_specs[] = {
#include "font_13.specs"
};
@@ -103,7 +118,10 @@ const unsigned char font_xxlsize[] = {
#include "font_64.lbm"
};
#if !defined(BOOT)
#if defined(BOOT)
const uint16_t * const fontspecsTable[1] = { font_stdsize_en_specs };
const uint8_t * fontsTable[1] = { font_stdsize_en };
#else
const uint16_t * const fontspecsTable[16] = {
font_stdsize_specs, font_tinsize_specs, font_smlsize_specs, font_midsize_specs, font_dblsize_specs, font_xxlsize_specs, font_stdsize_specs, font_stdsize_specs,
font_stdsizebold_specs, font_tinsize_specs, font_smlsize_specs, font_midsize_specs, font_dblsize_specs, font_xxlsize_specs, font_stdsize_specs, font_stdsize_specs
@@ -113,9 +131,6 @@ const uint8_t * fontsTable[16] = {
font_stdsize, font_tinsize, font_smlsize, font_midsize, font_dblsize, font_xxlsize, font_stdsize, font_stdsize,
font_stdsizebold, font_tinsize, font_smlsize, font_midsize, font_dblsize, font_xxlsize, font_stdsize, font_stdsize
};
#else
const uint16_t * const fontspecsTable[1] = { font_stdsize_specs };
const uint8_t * fontsTable[1] = { font_stdsize };
#endif
uint8_t * decompressFont(const uint8_t * font)
@@ -127,9 +142,9 @@ uint8_t * decompressFont(const uint8_t * font)
uint8_t* dec_buf = (uint8_t*)malloc(font_size + 4);
// copy width / height
memcpy(dec_buf,font,4);
memcpy(dec_buf, font,4);
rle_decode_8bit(dec_buf+4, font_size, font+4);
RLEBitmap::decode(dec_buf+4, font_size, font+4);
return dec_buf;
}
@@ -139,12 +154,14 @@ void loadFonts()
if (fonts_loaded) return;
#if !defined(BOOT)
int i=0;
for (; i<9; i++)
int i = 0;
for (; i < 9; i++) {
fontsTable[i] = decompressFont(fontsTable[i]);
for (; i<16; i++)
fontsTable[i] = fontsTable[i-9];
}
for (; i < 16; i++) {
// the next fonts don't exist in BOLD today
fontsTable[i] = fontsTable[i - 9];
}
#else
fontsTable[0] = decompressFont(fontsTable[0]);
#endif
@@ -0,0 +1,156 @@
/*
* 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 "fullscreen_dialog.h"
#include "mainwindow.h"
#include "opentx.h"
FullScreenDialog::FullScreenDialog(uint8_t type, std::string title, std::string message, std::string action, std::function<void(void)> confirmHandler):
Dialog(title, {0, 0, LCD_W, LCD_H}),
type(type),
message(std::move(message)),
action(std::move(action)),
confirmHandler(confirmHandler)
{
#if defined(HARDWARE_TOUCH)
new FabIconButton(this, LCD_W - 50, ALERT_BUTTON_TOP, ICON_NEXT,
[=]() -> uint8_t {
if (confirmHandler)
confirmHandler();
return 0;
});
#endif
}
FullScreenDialog::~FullScreenDialog()
{
}
void FullScreenDialog::paint(BitmapBuffer * dc)
{
static_cast<ThemeBase *>(theme)->drawBackground(dc);
dc->drawFilledRect(0, ALERT_FRAME_TOP, LCD_W, ALERT_FRAME_HEIGHT, SOLID, TEXT_INVERTED_COLOR | OPACITY(8));
if (type == WARNING_TYPE_ALERT || type == WARNING_TYPE_ASTERISK)
dc->drawBitmap(ALERT_BITMAP_LEFT, ALERT_BITMAP_TOP, static_cast<ThemeBase *>(theme)->asterisk);
else if (type == WARNING_TYPE_INFO)
dc->drawBitmap(ALERT_BITMAP_LEFT, ALERT_BITMAP_TOP, static_cast<ThemeBase *>(theme)->busy);
else // confirmation
dc->drawBitmap(ALERT_BITMAP_LEFT, ALERT_BITMAP_TOP, static_cast<ThemeBase *>(theme)->question);
if (type == WARNING_TYPE_ALERT) {
#if defined(TRANSLATIONS_FR) || defined(TRANSLATIONS_IT) || defined(TRANSLATIONS_CZ)
dc->drawText(ALERT_TITLE_LEFT, ALERT_TITLE_TOP, STR_WARNING, ALARM_COLOR|DBLSIZE);
dc->drawText(ALERT_TITLE_LEFT, ALERT_TITLE_TOP + ALERT_TITLE_LINE_HEIGHT, title, ALARM_COLOR|DBLSIZE);
#else
dc->drawText(ALERT_TITLE_LEFT, ALERT_TITLE_TOP, title.c_str(), ALARM_COLOR|DBLSIZE);
dc->drawText(ALERT_TITLE_LEFT, ALERT_TITLE_TOP + ALERT_TITLE_LINE_HEIGHT, STR_WARNING, ALARM_COLOR|DBLSIZE);
#endif
}
else if (!title.empty()) {
dc->drawText(ALERT_TITLE_LEFT, ALERT_TITLE_TOP, title.c_str(), ALARM_COLOR|DBLSIZE);
}
if (!message.empty()) {
dc->drawText(ALERT_MESSAGE_LEFT, ALERT_MESSAGE_TOP, message.c_str(), BOLD);
}
if (!action.empty()) {
dc->drawText(LCD_W / 2, ALERT_ACTION_TOP, action.c_str(), CENTERED | BOLD);
}
}
#if defined(HARDWARE_KEYS)
void FullScreenDialog::onKeyEvent(event_t event)
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
if (event == EVT_KEY_BREAK(KEY_ENTER)) {
deleteLater();
if (confirmHandler)
confirmHandler();
}
else if (event == EVT_KEY_BREAK(KEY_EXIT)) {
deleteLater();
}
}
#endif
#if defined(HARDWARE_TOUCH)
bool FullScreenDialog::onTouchEnd(coord_t x, coord_t y)
{
Window::onTouchEnd(x, y);
deleteLater();
return true;
}
#endif
void FullScreenDialog::checkEvents()
{
Window::checkEvents();
if (closeCondition && closeCondition()) {
deleteLater();
}
}
void FullScreenDialog::deleteLater()
{
if (previousFocus) {
previousFocus->setFocus();
}
if (running) {
running = false;
}
else {
Window::deleteLater();
}
}
void FullScreenDialog::runForever()
{
running = true;
while (running) {
auto check = pwrCheck();
if (check == e_power_off) {
boardOff();
}
else if (check == e_power_press) {
RTOS_WAIT_MS(20);
continue;
}
checkBacklight();
wdt_reset();
RTOS_WAIT_MS(20);
mainWindow.run(false);
}
Window::deleteLater();
}
void raiseAlert(const char * title, const char * msg, const char * action, uint8_t sound)
{
AUDIO_ERROR_MESSAGE(sound);
auto dialog = new FullScreenDialog(WARNING_TYPE_ALERT, title ? title : "", msg ? msg : "", action ? action : "");
dialog->runForever();
}
@@ -0,0 +1,83 @@
/*
* 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.
*/
#ifndef _FULLSCREEN_DIALOG_H_
#define _FULLSCREEN_DIALOG_H_
#include "dialog.h"
enum DialogType {
WARNING_TYPE_ALERT,
WARNING_TYPE_ASTERISK,
WARNING_TYPE_CONFIRM,
WARNING_TYPE_INPUT,
WARNING_TYPE_INFO
};
class FullScreenDialog : public Dialog {
public:
FullScreenDialog(uint8_t type, std::string title, std::string message = "", std::string action = "", std::function<void(void)> confirmHandler = nullptr);
~FullScreenDialog() override;
#if defined(DEBUG_WINDOWS)
std::string getName() override
{
return "FullScreenDialog";
}
#endif
void setMessage(std::string text)
{
message = std::move(text);
invalidate();
}
void paint(BitmapBuffer * dc) override;
#if defined(HARDWARE_KEYS)
void onKeyEvent(event_t event) override;
#endif
#if defined(HARDWARE_TOUCH)
bool onTouchEnd(coord_t x, coord_t y) override;
#endif
void deleteLater();
void checkEvents() override;
void setCloseCondition(std::function<bool(void)> handler)
{
closeCondition = std::move(handler);
}
void runForever();
protected:
uint8_t type;
std::string message;
std::string action;
bool running = false;
std::function<bool(void)> closeCondition;
std::function<void(void)> confirmHandler;
};
#endif // _FULLSCREEN_DIALOG_H_
+43
View File
@@ -0,0 +1,43 @@
/*
* 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.
*/
#ifndef _GETSET_HELPERS_H_
#define _GETSET_HELPERS_H_
#define GET_VALUE(value) [=] { return value; }
#define GET_DEFAULT(value) [=] { return value; }
#define GET_INVERTED(value) [=] { return !value; }
#define GET_VALUE_WITH_OFFSET(value, offset) [=] { return value + offset; }
#define GET_VALUE_WITH_BF(value, offset, bits) [=] { return bfGet(value, offset, bits); }
#define SET_VALUE(value, _newValue) [=](int32_t newValue) { value = _newValue; SET_DIRTY(); }
#define SET_DEFAULT(value) [=](int32_t newValue) { value = newValue; SET_DIRTY(); }
#define SET_INVERTED(value) [=](uint8_t newValue) { value = !newValue; SET_DIRTY(); }
#define SET_VALUE_WITH_OFFSET(value, offset) [=](int32_t newValue) { value = newValue - offset; SET_DIRTY(); }
#define SET_VALUE_WITH_BF(value, offset, bits) [=](uint16_t newValue) { bfSet<uint16_t>(value, newValue, offset, bits); SET_DIRTY(); }
#define GET_SET_DEFAULT(value) GET_DEFAULT(value), SET_DEFAULT(value)
#define GET_SET_INVERTED(value) GET_INVERTED(value), SET_INVERTED(value)
#define GET_SET_VALUE_WITH_OFFSET(value, offset) GET_VALUE_WITH_OFFSET(value, offset), SET_VALUE_WITH_OFFSET(value, offset)
#define GET_SET_WITH_OFFSET(value, offset) GET_VALUE_WITH_OFFSET(value, offset), SET_VALUE_WITH_OFFSET(value, offset)
#define GET_SET_BF(value, offset, bits) GET_VALUE_WITH_BF(value, offset, bits), SET_VALUE_WITH_BF(value, offset, bits)
#endif // _GETSET_HELPERS_H_
+104
View File
@@ -0,0 +1,104 @@
/*
* 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 "keyboard_curve.h"
#include "curveedit.h"
#include "button.h"
#include "lcd.h"
constexpr coord_t KEYBOARD_HEIGHT = 110;
CurveKeyboard * CurveKeyboard::_instance = nullptr;
CurveKeyboard::CurveKeyboard():
Keyboard<CurveEdit>(KEYBOARD_HEIGHT)
{
// up
new TextButton(this, {LCD_W/2 - 20, 5, 40, 40}, "\200",
[=]() -> uint8_t {
if (field) {
field->up();
}
return 0;
}, BUTTON_BACKGROUND | BUTTON_NOFOCUS);
// down
new TextButton(this, {LCD_W/2 - 20, 65, 40, 40}, "\201",
[=]() -> uint8_t {
field->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;
}, 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;
}, BUTTON_BACKGROUND | BUTTON_NOFOCUS);
// next
new TextButton(this, {LCD_W/2 + 80, 35, 60, 40}, "Next",
[=]() -> uint8_t {
if (field) {
field->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;
}, BUTTON_BACKGROUND | BUTTON_NOFOCUS);
}
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));
dc->clear(CUSTOM_COLOR);
}
+61
View File
@@ -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.
*/
#ifndef _KEYBOARD_CURVE_H_
#define _KEYBOARD_CURVE_H_
#include "keyboard_base.h"
#include "curveedit.h"
class Button;
class CurveKeyboard : public Keyboard<CurveEdit> {
friend class CurveEdit;
public:
CurveKeyboard();
~CurveKeyboard();
#if defined(DEBUG_WINDOWS)
std::string getName() override
{
return "CurveKeyboard";
}
#endif
static CurveKeyboard * instance()
{
if (!_instance)
_instance = new CurveKeyboard();
return _instance;
}
void setField(CurveEdit * field);
void paint(BitmapBuffer * dc) override;
protected:
static CurveKeyboard * _instance;
Button * left = nullptr;
Button * right = nullptr;
};
#endif // _KEYBOARD_CURVE_H_
+6 -6
View File
@@ -28,7 +28,7 @@ std::list<const LayoutFactory *> & getRegisteredLayouts()
void registerLayout(const LayoutFactory * factory)
{
TRACE("register layout %s", factory->getName());
TRACE("register layout %s", factory->getId());
getRegisteredLayouts().push_back(factory);
}
@@ -36,7 +36,7 @@ const LayoutFactory * getLayoutFactory(const char * name)
{
std::list<const LayoutFactory *>::const_iterator it = getRegisteredLayouts().cbegin();
for (; it != getRegisteredLayouts().cend(); ++it) {
if (!strcmp(name, (*it)->getName())) {
if (!strcmp(name, (*it)->getId())) {
return (*it);
}
}
@@ -54,7 +54,7 @@ Layout * loadLayout(const char * name, Layout::PersistentData * persistentData)
void loadCustomScreens()
{
for (unsigned int i=0; i<MAX_CUSTOM_SCREENS; i++) {
for (unsigned int i = 0; i < MAX_CUSTOM_SCREENS; i++) {
delete customScreens[i];
char name[LAYOUT_NAME_LEN + 1];
memset(name, 0, sizeof(name));
@@ -66,7 +66,7 @@ void loadCustomScreens()
customScreens[0] = getRegisteredLayouts().front()->create(&g_model.screenData[0].layoutData);
}
if (topbar) {
topbar->load();
}
// if (topbar) {
// topbar->load();
// }
}
+12 -9
View File
@@ -59,18 +59,21 @@ void registerLayout(const LayoutFactory * factory);
class LayoutFactory
{
public:
LayoutFactory(const char * name):
LayoutFactory(const char * id, const char * name):
id(id),
name(name)
{
registerLayout(this);
}
const char * getId() const { return id; }
const char * getName() const { return name; }
virtual void drawThumb(uint16_t x, uint16_t y, uint32_t flags) const = 0;
virtual void drawThumb(BitmapBuffer * dc, uint16_t x, uint16_t y, LcdFlags flags) const = 0;
virtual const ZoneOption * getOptions() const = 0;
virtual Layout * create(Layout::PersistentData * persistentData) const = 0;
virtual Layout * load(Layout::PersistentData * persistentData) const = 0;
protected:
const char * id;
const char * name;
};
@@ -78,24 +81,24 @@ template<class T>
class BaseLayoutFactory: public LayoutFactory
{
public:
BaseLayoutFactory(const char * name, const uint8_t * bitmap, const ZoneOption * options):
LayoutFactory(name),
BaseLayoutFactory(const char * id, const char * name, const uint8_t * bitmap, const ZoneOption * options):
LayoutFactory(id, name),
bitmap(bitmap),
options(options)
{
}
virtual void drawThumb(uint16_t x, uint16_t y, uint32_t flags) const
void drawThumb(BitmapBuffer * dc, uint16_t x, uint16_t y, uint32_t flags) const override
{
lcdDrawBitmapPattern(x, y, bitmap, flags);
dc->drawBitmapPattern(x, y, bitmap, flags);
}
virtual const ZoneOption * getOptions() const
const ZoneOption * getOptions() const override
{
return options;
}
virtual Layout * create(Layout::PersistentData * persistentData) const
Layout * create(Layout::PersistentData * persistentData) const override
{
Layout * layout = new T(this, persistentData);
if (layout) {
@@ -104,7 +107,7 @@ class BaseLayoutFactory: public LayoutFactory
return layout;
}
virtual Layout * load(Layout::PersistentData * persistentData) const
Layout * load(Layout::PersistentData * persistentData) const override
{
Layout * layout = new T(this, persistentData);
if (layout) {
+25 -25
View File
@@ -38,19 +38,19 @@ class Layout1x1: public Layout
{
}
virtual void create()
void create() override
{
Layout::create();
persistentData->options[0].boolValue = true;
persistentData->options[1].boolValue = true;
}
virtual unsigned int getZonesCount() const
unsigned int getZonesCount() const override
{
return 1;
}
virtual Zone getZone(unsigned int index) const
Zone getZone(unsigned int index) const override
{
Zone zone = { 10, 10, LCD_W - 2*10, LCD_H - 2*10 };
if (persistentData->options[0].boolValue) {
@@ -65,28 +65,28 @@ class Layout1x1: public Layout
return zone;
}
virtual void refresh();
// virtual void refresh();
};
void Layout1x1::refresh()
{
theme->drawBackground();
//void Layout1x1::refresh()
//{
// theme->drawBackground();
//
// if (persistentData->options[0].boolValue) {
// drawTopBar();
// }
//
// if (persistentData->options[1].boolValue) {
// // Sliders + Trims + Flight mode
// lcdDrawSizedText(LCD_W / 2 - getTextWidth(g_model.flightModeData[mixerCurrentFlightMode].name, sizeof(g_model.flightModeData[mixerCurrentFlightMode].name), ZCHAR | SMLSIZE) / 2,
// 232,
// g_model.flightModeData[mixerCurrentFlightMode].name,
// sizeof(g_model.flightModeData[mixerCurrentFlightMode].name), ZCHAR | SMLSIZE);
// drawMainPots();
// drawTrims(mixerCurrentFlightMode);
// }
//
// Layout::refresh();
//}
if (persistentData->options[0].boolValue) {
drawTopBar();
}
if (persistentData->options[1].boolValue) {
// Sliders + Trims + Flight mode
lcdDrawSizedText(LCD_W / 2 - getTextWidth(g_model.flightModeData[mixerCurrentFlightMode].name, sizeof(g_model.flightModeData[mixerCurrentFlightMode].name), ZCHAR | SMLSIZE) / 2,
232,
g_model.flightModeData[mixerCurrentFlightMode].name,
sizeof(g_model.flightModeData[mixerCurrentFlightMode].name), ZCHAR | SMLSIZE);
drawMainPots();
drawTrims(mixerCurrentFlightMode);
}
Layout::refresh();
}
BaseLayoutFactory<Layout1x1> layout1x1("Layout1x1", LBM_LAYOUT_1x1, OPTIONS_LAYOUT_1x1);
BaseLayoutFactory<Layout1x1> layout1x1("Layout1x1", "Fullscreen", LBM_LAYOUT_1x1, OPTIONS_LAYOUT_1x1);
+36 -36
View File
@@ -29,7 +29,7 @@ const ZoneOption OPTIONS_LAYOUT_2P1[] = {
{ "Flight mode", ZoneOption::Bool },
{ "Sliders", ZoneOption::Bool },
{ "Trims", ZoneOption::Bool },
{ NULL, ZoneOption::Bool }
{ nullptr, ZoneOption::Bool }
};
const Zone ZONES_LAYOUT_2P1[3] = {
@@ -46,7 +46,7 @@ class Layout2P1: public Layout
{
}
virtual void create()
void create() override
{
Layout::create();
persistentData->options[0].boolValue = true;
@@ -55,49 +55,49 @@ class Layout2P1: public Layout
persistentData->options[3].boolValue = true;
}
virtual unsigned int getZonesCount() const
unsigned int getZonesCount() const override
{
return DIM(ZONES_LAYOUT_2P1);
}
virtual Zone getZone(unsigned int index) const
Zone getZone(unsigned int index) const override
{
return ZONES_LAYOUT_2P1[index];
}
virtual void refresh();
// virtual void refresh();
};
void Layout2P1::refresh()
{
theme->drawBackground();
//void Layout2P1::refresh()
//{
// theme->drawBackground();
//
// if (persistentData->options[0].boolValue) {
// drawTopBar();
// }
//
// if (persistentData->options[1].boolValue) {
// // Flight mode
// lcdDrawSizedText(LCD_W / 2 - getTextWidth(g_model.flightModeData[mixerCurrentFlightMode].name,
// sizeof(g_model.flightModeData[mixerCurrentFlightMode].name),
// ZCHAR | SMLSIZE) / 2,
// 232,
// g_model.flightModeData[mixerCurrentFlightMode].name,
// sizeof(g_model.flightModeData[mixerCurrentFlightMode].name), ZCHAR | SMLSIZE);
// }
//
// if (persistentData->options[2].boolValue) {
// // Pots and rear sliders positions
// drawMainPots();
// }
//
// if (persistentData->options[3].boolValue) {
// // Trims
// drawTrims(mixerCurrentFlightMode);
// }
//
// Layout::refresh();
//}
if (persistentData->options[0].boolValue) {
drawTopBar();
}
if (persistentData->options[1].boolValue) {
// Flight mode
lcdDrawSizedText(LCD_W / 2 - getTextWidth(g_model.flightModeData[mixerCurrentFlightMode].name,
sizeof(g_model.flightModeData[mixerCurrentFlightMode].name),
ZCHAR | SMLSIZE) / 2,
232,
g_model.flightModeData[mixerCurrentFlightMode].name,
sizeof(g_model.flightModeData[mixerCurrentFlightMode].name), ZCHAR | SMLSIZE);
}
if (persistentData->options[2].boolValue) {
// Pots and rear sliders positions
drawMainPots();
}
if (persistentData->options[3].boolValue) {
// Trims
drawTrims(mixerCurrentFlightMode);
}
Layout::refresh();
}
BaseLayoutFactory<Layout2P1> layout2P1("Layout2P1", LBM_LAYOUT_2P1, OPTIONS_LAYOUT_2P1);
BaseLayoutFactory<Layout2P1> layout2P1("Layout2P1", "2 + 1", LBM_LAYOUT_2P1, OPTIONS_LAYOUT_2P1);
const LayoutFactory * defaultLayout = &layout2P1;
+15 -15
View File
@@ -37,18 +37,18 @@ class Layout2x1: public Layout
{
}
virtual void create()
void create() override
{
Layout::create();
persistentData->options[0].boolValue = true;
}
virtual unsigned int getZonesCount() const
unsigned int getZonesCount() const override
{
return 4;
}
virtual Zone getZone(unsigned int index) const
Zone getZone(unsigned int index) const override
{
Zone zone;
zone.w = (LCD_W-3*10) / 2;
@@ -64,18 +64,18 @@ class Layout2x1: public Layout
return zone;
}
virtual void refresh();
// virtual void refresh();
};
void Layout2x1::refresh()
{
theme->drawBackground();
//void Layout2x1::refresh()
//{
// theme->drawBackground();
//
// if (persistentData->options[0].boolValue) {
// drawTopBar();
// }
//
// Layout::refresh();
//}
if (persistentData->options[0].boolValue) {
drawTopBar();
}
Layout::refresh();
}
BaseLayoutFactory<Layout2x1> Layout2x1("Layout2x1", LBM_LAYOUT_2x1, OPTIONS_LAYOUT_2x1);
BaseLayoutFactory<Layout2x1> Layout2x1("Layout2x1", "2 x 1", LBM_LAYOUT_2x1, OPTIONS_LAYOUT_2x1);
+16 -16
View File
@@ -26,7 +26,7 @@ const uint8_t LBM_LAYOUT_2x2[] = {
const ZoneOption OPTIONS_LAYOUT_2x2[] = {
{ "Top bar", ZoneOption::Bool },
{ NULL, ZoneOption::Bool }
{ nullptr, ZoneOption::Bool }
};
class Layout2x2: public Layout
@@ -37,18 +37,18 @@ class Layout2x2: public Layout
{
}
virtual void create()
void create() override
{
Layout::create();
persistentData->options[0].boolValue = true;
}
virtual unsigned int getZonesCount() const
unsigned int getZonesCount() const override
{
return 4;
}
virtual Zone getZone(unsigned int index) const
Zone getZone(unsigned int index) const override
{
Zone zone;
zone.w = (LCD_W-3*10) / 2;
@@ -67,18 +67,18 @@ class Layout2x2: public Layout
return zone;
}
virtual void refresh();
// virtual void refresh();
};
void Layout2x2::refresh()
{
theme->drawBackground();
//void Layout2x2::refresh()
//{
// theme->drawBackground();
//
// if (persistentData->options[0].boolValue) {
// drawTopBar();
// }
//
// Layout::refresh();
//}
if (persistentData->options[0].boolValue) {
drawTopBar();
}
Layout::refresh();
}
BaseLayoutFactory<Layout2x2> layout2x2("Layout2x2", LBM_LAYOUT_2x2, OPTIONS_LAYOUT_2x2);
BaseLayoutFactory<Layout2x2> layout2x2("Layout2x2", "2 x 2", LBM_LAYOUT_2x2, OPTIONS_LAYOUT_2x2);
+45 -45
View File
@@ -44,7 +44,7 @@ class Layout2x4: public Layout
{
}
virtual void create()
void create() override
{
Layout::create();
persistentData->options[0].boolValue = true;
@@ -57,12 +57,12 @@ class Layout2x4: public Layout
persistentData->options[7].unsignedValue = RGB(77, 112, 203);
}
virtual unsigned int getZonesCount() const
unsigned int getZonesCount() const override
{
return 8;
}
virtual Zone getZone(unsigned int index) const
Zone getZone(unsigned int index) const override
{
Zone zone;
zone.x = (index >= 4) ? 260 : 60;
@@ -72,48 +72,48 @@ class Layout2x4: public Layout
return zone;
}
virtual void refresh();
// virtual void refresh();
};
void Layout2x4::refresh()
{
theme->drawBackground();
//void Layout2x4::refresh()
//{
// theme->drawBackground();
//
// if (persistentData->options[0].boolValue) {
// drawTopBar();
// }
//
// if (persistentData->options[1].boolValue) {
// // Flight mode
// lcdDrawSizedText(LCD_W / 2 - getTextWidth(g_model.flightModeData[mixerCurrentFlightMode].name,
// sizeof(g_model.flightModeData[mixerCurrentFlightMode].name),
// ZCHAR | SMLSIZE) / 2,
// 232,
// g_model.flightModeData[mixerCurrentFlightMode].name,
// sizeof(g_model.flightModeData[mixerCurrentFlightMode].name), ZCHAR | SMLSIZE);
// }
//
// if (persistentData->options[2].boolValue) {
// // Pots and rear sliders positions
// drawMainPots();
// }
//
// if (persistentData->options[3].boolValue) {
// // Trims
// drawTrims(mixerCurrentFlightMode);
// }
//
// if (persistentData->options[4].boolValue) {
// lcdSetColor(persistentData->options[5].unsignedValue);
// lcdDrawSolidFilledRect(50, 50, 180, 170, CUSTOM_COLOR);
// }
//
// if (persistentData->options[6].boolValue) {
// lcdSetColor(persistentData->options[7].unsignedValue);
// lcdDrawSolidFilledRect(250, 50, 180, 170, CUSTOM_COLOR);
// }
//
// Layout::refresh();
//}
if (persistentData->options[0].boolValue) {
drawTopBar();
}
if (persistentData->options[1].boolValue) {
// Flight mode
lcdDrawSizedText(LCD_W / 2 - getTextWidth(g_model.flightModeData[mixerCurrentFlightMode].name,
sizeof(g_model.flightModeData[mixerCurrentFlightMode].name),
ZCHAR | SMLSIZE) / 2,
232,
g_model.flightModeData[mixerCurrentFlightMode].name,
sizeof(g_model.flightModeData[mixerCurrentFlightMode].name), ZCHAR | SMLSIZE);
}
if (persistentData->options[2].boolValue) {
// Pots and rear sliders positions
drawMainPots();
}
if (persistentData->options[3].boolValue) {
// Trims
drawTrims(mixerCurrentFlightMode);
}
if (persistentData->options[4].boolValue) {
lcdSetColor(persistentData->options[5].unsignedValue);
lcdDrawSolidFilledRect(50, 50, 180, 170, CUSTOM_COLOR);
}
if (persistentData->options[6].boolValue) {
lcdSetColor(persistentData->options[7].unsignedValue);
lcdDrawSolidFilledRect(250, 50, 180, 170, CUSTOM_COLOR);
}
Layout::refresh();
}
BaseLayoutFactory<Layout2x4> layout2x4("Layout2x4", LBM_LAYOUT_2x4, OPTIONS_LAYOUT_2x4);
BaseLayoutFactory<Layout2x4> layout2x4("Layout2x4", "2 x 4", LBM_LAYOUT_2x4, OPTIONS_LAYOUT_2x4);
Binary file not shown.

Before

Width:  |  Height:  |  Size: 169 B

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 233 B

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 178 B

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 208 B

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 212 B

After

Width:  |  Height:  |  Size: 3.9 KiB

+29 -82
View File
@@ -18,17 +18,13 @@
* GNU General Public License for more details.
*/
#include <math.h>
#include <stdio.h>
#include "opentx.h"
#include "strhelpers.h"
#if defined(SIMU)
display_t displayBuf[DISPLAY_BUFFER_SIZE];
pixel_t displayBuf[DISPLAY_BUFFER_SIZE];
#endif
uint16_t lcdColorTable[LCD_COLOR_COUNT];
coord_t lcdNextPos;
uint8_t getMappedChar(uint8_t c)
@@ -73,15 +69,19 @@ uint8_t getMappedChar(uint8_t c)
result = 207 + c - 0x80;
}
#endif
else if (c == 0x21) // !
result = 0;
else if (c < 0xC0)
result = c - 0x20;
result = c - 0x20 - 2;
else
result = c - 0xC0 + 96;
// TRACE("getMappedChar '%c' (%d) = %d", c, c, result);
result = c - 0xC0 + 96 - 2;
// TRACE("getMappedChar '%c' (%x) = %d", c, c, result);
return result;
}
int getFontPatternWidth(const uint16_t * spec, uint8_t index)
int getFontPatternWidth(const uint16_t * spec, int index)
{
return spec[index + 2] - spec[index + 1];
}
@@ -91,23 +91,6 @@ int getCharWidth(uint8_t c, const uint16_t * spec)
return getFontPatternWidth(spec, getMappedChar(c));
}
void lcdPutFontPattern(coord_t x, coord_t y, const uint8_t * font, const uint16_t * spec, int index, LcdFlags flags)
{
coord_t offset = spec[index + 1];
coord_t width = spec[index + 2] - offset;
if (width > 0)
lcdDrawBitmapPattern(x, y, font, flags, offset, width);
lcdNextPos = x + width;
}
void lcdDrawChar(coord_t x, coord_t y, char c, LcdFlags flags)
{
uint32_t fontindex = FONTINDEX(flags);
const unsigned char * font = fontsTable[fontindex];
const uint16_t * fontspecs = fontspecsTable[fontindex];
lcdPutFontPattern(x, y, font, fontspecs, getMappedChar(c), flags);
}
uint8_t getFontHeight(LcdFlags flags)
{
uint32_t fontindex = FONTINDEX(flags);
@@ -119,68 +102,32 @@ int getTextWidth(const char * s, int len, LcdFlags flags)
const uint16_t * specs = fontspecsTable[FONTINDEX(flags)];
int result = 0;
for (int i=0; len==0 || i<len; ++i) {
#if !defined(BOOT)
char c = (flags & ZCHAR) ? zchar2char(*s) : *s;
#else
char c = *s;
#endif
if (c == '\0')
for (int i=0; len == 0 || i < len; ++i) {
unsigned int c = uint8_t(*s);
if (!c) {
break;
result += getCharWidth(c, specs);
}
else if (c == 0x20) {
result += 4;
}
else if (c >= 0xFE) {
s++;
c = uint8_t(*s) + ((c & 0x01) << 8) - 1;
if (c >= 0x101)
c -= 1;
c += 187;
result += getFontPatternWidth(specs, c);
}
else if (c >= 0x20) {
result += getCharWidth(c, specs);
}
++s;
}
return result;
}
void lcdDrawTextAtIndex(coord_t x, coord_t y, const char * s, uint8_t idx, LcdFlags flags)
{
uint8_t length;
length = *(s++);
lcdDrawSizedText(x, y, s+length*idx, length, flags & ~ZCHAR);
}
void lcdDrawNumber(coord_t x, coord_t y, int32_t val, LcdFlags flags, uint8_t len, const char * prefix, const char * suffix)
{
char str[48+1]; // max=16 for the prefix, 16 chars for the number, 16 chars for the suffix
char *s = str+32;
*s = '\0';
int idx = 0;
int mode = MODE(flags);
bool neg = false;
if (val < 0) {
val = -val;
neg = true;
}
do {
*--s = '0' + (val % 10);
++idx;
val /= 10;
if (mode!=0 && idx==mode) {
mode = 0;
*--s = '.';
if (val==0)
*--s = '0';
}
} while (val!=0 || mode>0 || (mode==MODE(LEADING0) && idx<len));
if (neg) *--s = '-';
// TODO needs check on all string lengths ...
if (prefix) {
int len = strlen(prefix);
if (len <= 16) {
s -= len;
strncpy(s, prefix, len);
}
}
if (suffix) {
strncpy(&str[32], suffix, 16);
}
flags &= ~LEADING0;
lcdDrawText(x, y, s, flags);
}
void lcdSetContrast()
{
lcdSetRefVolt(g_eeGeneral.contrast);
+2 -116
View File
@@ -23,6 +23,7 @@
#include "bitmapbuffer.h"
#include "opentx_types.h"
#include "libopenui_globals.h"
#if LCD_W >= 480
#define LCD_COLS 40
@@ -48,8 +49,6 @@
#define PREC2 0x30
#define MODE(flags) ((((int8_t)(flags) & 0x30) - 0x10) >> 4)
#define ZCHAR 0x10
/* rect, square flags */
#define ROUND 0x04
@@ -67,7 +66,7 @@
#define DISPLAY_BUFFER_SIZE (DISPLAY_PIXELS_COUNT)
#if defined(SIMU)
extern display_t displayBuf[DISPLAY_BUFFER_SIZE];
extern pixel_t displayBuf[DISPLAY_BUFFER_SIZE];
#else
#define displayBuf lcd->getData()
#endif
@@ -78,136 +77,23 @@ extern display_t displayBuf[DISPLAY_BUFFER_SIZE];
extern coord_t lcdNextPos;
void lcdNextLayer();
void lcdDrawChar(coord_t x, coord_t y, char c, LcdFlags flags=0);
void lcdDrawTextAtIndex(coord_t x, coord_t y, const char * s, uint8_t idx, LcdFlags flags=0);
inline void lcdClear()
{
lcd->clear();
}
inline void lcdDrawText(coord_t x, coord_t y, const char * s, LcdFlags attr=0)
{
lcd->drawText(x, y, s, attr);
}
inline void lcdDrawCenteredText(coord_t y, const char * s, LcdFlags attr=0)
{
lcd->drawText(LCD_W/2, y, s, attr | CENTERED);
}
inline void lcdDrawSizedText(coord_t x, coord_t y, const char * s, uint8_t len, LcdFlags attr=0)
{
lcd->drawSizedText(x, y, s, len, attr);
}
void lcdDrawNumber(coord_t x, coord_t y, int32_t val, LcdFlags flags=0, uint8_t len=0, const char * prefix=NULL, const char * suffix=NULL);
#define SOLID 0xff
#define DOTTED 0x55
#define STASHED 0x33
#if defined(PCBX10) && !defined(SIMU)
#define PIXEL_PTR(x, y) &displayBuf[(LCD_H*LCD_W-1) - (y)*LCD_W - (x)]
#else
#define PIXEL_PTR(x, y) &displayBuf[(y)*LCD_W + (x)]
#endif
void lcdDrawAlphaPixel(display_t * p, uint8_t opacity, uint16_t color);
void lcdDrawPoint(coord_t x, coord_t y, LcdFlags att=0);
inline void lcdDrawSolidHorizontalLine(coord_t x, coord_t y, coord_t w, LcdFlags att)
{
lcd->drawSolidHorizontalLine(x, y, w, att);
}
inline void lcdDrawSolidVerticalLine(coord_t x, coord_t y, coord_t h, LcdFlags att)
{
lcd->drawSolidVerticalLine(x, y, h, att);
}
inline void lcdDrawSolidFilledRect(coord_t x, coord_t y, coord_t w, coord_t h, LcdFlags flags)
{
lcd->drawSolidFilledRect(x, y, w, h, flags);
}
inline void lcdDrawHorizontalLine(coord_t x, coord_t y, coord_t w, uint8_t pat, LcdFlags att=0)
{
lcd->drawHorizontalLine(x, y, w, pat, att);
}
inline void lcdDrawVerticalLine(coord_t x, coord_t y, coord_t h, uint8_t pat, LcdFlags att=0)
{
lcd->drawVerticalLine(x, y, h, pat, att);
}
void lcdDrawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat=SOLID, LcdFlags att=0);
inline void lcdDrawAlphaPixel(coord_t x, coord_t y, uint8_t opacity, uint16_t color)
{
display_t * p = PIXEL_PTR(x, y);
lcdDrawAlphaPixel(p, opacity, color);
}
inline void lcdSetColor(uint16_t color)
{
lcdColorTable[CUSTOM_COLOR_INDEX] = color;
}
inline void lcdDrawSolidRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t thickness=1, LcdFlags att=0)
{
lcd->drawSolidFilledRect(x, y, thickness, h, att);
lcd->drawSolidFilledRect(x+w-thickness, y, thickness, h, att);
lcd->drawSolidFilledRect(x, y, w, thickness, att);
lcd->drawSolidFilledRect(x, y+h-thickness, w, thickness, att);
}
inline void lcdDrawFilledRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t pat, LcdFlags att=0)
{
lcd->drawFilledRect(x, y, w, h, pat, att);
}
void lcdDrawBlackOverlay();
inline void lcdDrawRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t thickness=1, uint8_t pat=SOLID, LcdFlags att=0)
{
lcd->drawRect(x, y, w, h, thickness, pat, att);
}
void lcdDrawCircle(int x0, int y0, int radius);
void lcdDrawPie(int x0, int y0, int radius, int angle1=0, int angle2=360);
void lcdDrawBitmapPie(int x0, int y0, const uint16_t * img, int startAngle, int endAngle);
inline void lcdDrawBitmapPatternPie(coord_t x0, coord_t y0, const uint8_t * bmp, LcdFlags flags=0, int startAngle=0, int endAngle=360)
{
lcd->drawBitmapPatternPie(x0, y0, bmp, flags, startAngle, endAngle);
}
inline void lcdDrawSquare(coord_t x, coord_t y, coord_t w, LcdFlags att=0)
{
lcdDrawSolidRect(x, y, w, w, att);
}
inline int getBitmapWidth(const uint8_t * bmp)
{
return *((const uint16_t *)bmp);
}
inline int getBitmapHeight(const uint8_t * bmp)
{
return *(((const uint16_t *)bmp)+1);
}
uint8_t getMappedChar(uint8_t c);
int getCharWidth(uint8_t c, const uint16_t * spec);
uint8_t getFontHeight(LcdFlags flags);
int getTextWidth(const char * s, int len=0, LcdFlags flags=0);
inline void lcdDrawBitmapPattern(coord_t x, coord_t y, const uint8_t * img, LcdFlags flags=0, coord_t offset=0, coord_t width=0)
{
lcd->drawBitmapPattern(x, y, img, flags, offset, width);
}
#if defined(BOOT)
#define BLINK_ON_PHASE (0)
+58
View File
@@ -0,0 +1,58 @@
/*
* 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.
*/
#ifndef _LIBOPENUI_H_
#define _LIBOPENUI_H_
#include "libopenui_config.h"
#include "libopenui_file.h"
#include "font.h"
#include "window.h"
#include "mainwindow.h"
#include "static.h"
#include "button.h"
#include "checkbox.h"
#include "numberedit.h"
#include "timeedit.h"
#include "choice.h"
#include "sourcechoice.h"
#include "switchchoice.h"
#include "filechoice.h"
#include "textedit.h"
#include "slider.h"
#include "progress.h"
#include "keyboard_text.h"
#include "keyboard_number.h"
#include "keyboard_curve.h"
#include "tabsgroup.h"
#include "page.h"
#include "menu.h"
#include "dialog.h"
#include "fullscreen_dialog.h"
#include "message_dialog.h"
#include "confirm_dialog.h"
#include "dialog.h"
#include "gridlayout.h"
#include "getset_helpers.h"
#include "curveedit.h"
#include "coloredit.h"
#include "draw_functions.h"
#endif // _LIBOPENUI_H_
+200
View File
@@ -0,0 +1,200 @@
class Window
{
public:
Window(coord_t x, coord_t y, coord_t width, coord_t height):
x(x),
y(y),
width(width),
height(height),
offsetX(0),
offsetY(0),
innerWidth(width),
innerHeight(height),
focusX(-1),
focusY(-1)
{
}
coord_t x, y, width, height, offsetX, offsetY, innerWidth, innerHeight, focusX, focusY;
void scroll() {
if (touchState.Event == TE_SLIDE) {
if (innerHeight > height && touchState.startX >= this->x && touchState.startX <= this->x + this->width) {
this->offsetY = limit<coord_t>(-innerHeight + height, this->offsetY + touchState.Y - touchState.startY, 0);
touchState.startY = touchState.Y;
}
if (innerWidth > width && touchState.startY >= this->y && touchState.startY <= this->y + this->height) {
this->offsetX = limit<coord_t>(-innerWidth + width, this->offsetX + touchState.X - touchState.startX, 0);
touchState.startX = touchState.X;
}
}
}
bool touchPressed(coord_t x, coord_t y, coord_t w, coord_t h) {
return ::touchPressed(this->x + this->offsetX + x, this->y + this->offsetY + y, w, h);
}
void setHeight(coord_t height) {
this->height = height;
}
void setInnerWidth(coord_t value) {
innerWidth = value;
}
void setInnerHeight(coord_t value) {
innerHeight = value;
}
void setFocus(coord_t x, coord_t y) {
focusX = x;
focusY = y;
}
void clearFocus() {
setFocus(-1, -1);
}
bool hasFocus(coord_t x, coord_t y) {
return (x == focusX && y == focusY);
}
void drawVerticalScrollbar();
void drawSolidFilledRect(coord_t x, coord_t y, coord_t w, coord_t h, LcdFlags flags)
{
setClippingRect();
lcd->drawSolidFilledRect(this->x + this->offsetX + x, this->y + this->offsetY + y, w, h, flags);
clearLcdLimits();
}
template<class T>
void drawBitmap(coord_t x, coord_t y, const T * bmp, coord_t srcx=0, coord_t srcy=0, coord_t w=0, coord_t h=0, float scale=0) {
if (this->offsetX + x >= this->width || this->offsetY + y >= this->height) {
return;
}
setClippingRect();
lcd->drawBitmap(this->x + this->offsetX + x, this->y + this->offsetY + y, bmp, srcx, srcy, w, h, scale);
clearLcdLimits();
}
inline void setClippingRect() {
lcd->setClippingRect(this->x, this->x + this->width, this->y, this->y + this->height);
}
inline void clearLcdLimits() {
lcd->clearClippingRect();
}
void drawSizedText(coord_t x, coord_t y, const char * s, uint8_t len, LcdFlags flags) {
setClippingRect();
lcd->drawSizedText(this->x + this->offsetX + x, this->y + this->offsetY + y, s, len, flags);
clearLcdLimits();
}
};
template <class W>
bool Subtitle(W * window, rect_t & rect, const char * label)
{
rect.h = 14;
drawText(window, rect.x, rect.y, label, BOLD);
}
template <class W>
bool CheckBox(W * window, rect_t & rect, const char * label, uint8_t & value, LcdFlags flags=0)
{
rect.h = 30;
bool hasFocus = (flags & HAS_FOCUS) || window->hasFocus(rect.x, rect.y);
drawText(window, rect.x, rect.y+4, label);
coord_t x = rect.x + rect.w - 20;
if (hasFocus) {
window->drawSolidFilledRect(x-1, rect.y+8, 14, 14, TEXT_INVERTED_BGCOLOR);
window->drawSolidFilledRect(x+1, rect.y+10, 10, 10, TEXT_BGCOLOR);
if (value) {
window->drawSolidFilledRect(x+2, rect.y+11, 8, 8, TEXT_INVERTED_BGCOLOR);
}
}
else {
if (value) {
window->drawSolidFilledRect(x+2, rect.y+11, 8, 8, SCROLLBOX_COLOR);
drawSolidRect(window, x, rect.y+9, 12, 12, 1, LINE_COLOR);
}
else {
drawSolidRect(window, x, rect.y+9, 12, 12, 1, LINE_COLOR);
}
}
if (window->touchPressed(rect.x, rect.y, rect.w, rect.h)) {
value ^= 1;
window->setFocus(rect.x, rect.y);
return true;
}
else {
return false;
}
}
template <class W>
void drawWidgetLabel(W * window, rect_t & rect, const char * label) {
drawText(window, rect.x, rect.y, label, TINSIZE);
}
template <class W>
void drawWidgetLine(W * window, rect_t & rect, LcdFlags color) {
window->drawSolidFilledRect(rect.x, rect.y + rect.h, rect.w, 1, color);
}
template <class W>
bool Choice(W * window, rect_t & rect, const char * label, const char * values, uint8_t & value, uint8_t vmin, uint8_t vmax, LcdFlags flags=0)
{
rect.h = 30;
bool hasFocus = (flags & HAS_FOCUS) || window->hasFocus(rect.x, rect.y);
LcdFlags textColor = 0;
LcdFlags lineColor = CURVE_AXIS_COLOR;
if (hasFocus) {
textColor = TEXT_INVERTED_BGCOLOR;
lineColor = TEXT_INVERTED_BGCOLOR;
}
drawTextAtIndex(window, rect.x, rect.y + 9, values, value, textColor);
drawWidgetLine(window, rect, lineColor);
drawWidgetLabel(window, rect, label);
if (window->touchPressed(rect.x, rect.y, rect.w, rect.h)) {
// value ^= 1;
window->setFocus(rect.x, rect.y);
return true;
}
else {
return false;
}
}
template <class W>
bool TextEdit(W * window, rect_t & rect, const char * label, char * value, uint8_t length, LcdFlags flags=0)
{
rect.h = 30;
bool hasFocus = (flags & HAS_FOCUS) || window->hasFocus(rect.x, rect.y);
LcdFlags textColor = 0;
LcdFlags lineColor = CURVE_AXIS_COLOR;
if (hasFocus) {
textColor = TEXT_INVERTED_BGCOLOR;
lineColor = TEXT_INVERTED_BGCOLOR;
}
if (!hasFocus && zlen(value, length) == 0)
menuBodyWindow.drawSizedText(rect.x, rect.y + 9, "---", length, textColor);
else
menuBodyWindow.drawSizedText(rect.x, rect.y + 9, value, length, ZCHAR | textColor);
drawWidgetLine(window, rect, lineColor);
drawWidgetLabel(window, rect, label);
if (window->touchPressed(rect.x, rect.y, rect.w, rect.h)) {
// value ^= 1;
window->setFocus(rect.x, rect.y);
return true;
}
else {
return false;
}
}
#define CHECKBOX(X, label, value) { rect.x = X; rect.w = LCD_W - (X) - 20; uint8_t _value = value; CheckBox(window, rect, label, _value); value = _value; rect.y += rect.h + 10; }
#define CHECKBOX_INVERTED(X, label, value) { rect.x = X; rect.w = LCD_W - (X) - 20; uint8_t _value = !value; CheckBox(window, rect, label, _value); value = !_value; rect.y += rect.h + 10; }
#endif
+44
View File
@@ -0,0 +1,44 @@
/*
* 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"
#include "menu_screen.h"
#include "screen_setup.h"
ScreenMenu::ScreenMenu():
TabsGroup(ICON_THEME)
{
updateTabs();
}
void ScreenMenu::updateTabs()
{
removeAllTabs();
for (int index = 0; index < MAX_CUSTOM_SCREENS; index++) {
if (customScreens[index]) {
addTab(new ScreenSetupPage(this, index));
}
else {
addTab(new ScreenAddPage(this, index));
break;
}
}
}
+36
View File
@@ -0,0 +1,36 @@
/*
* 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.
*/
#ifndef _MENU_SCREEN_H_
#define _MENU_SCREEN_H_
#include "tabsgroup.h"
class ScreenMenu: public TabsGroup {
friend class ScreenSetupPage;
public:
ScreenMenu();
protected:
void updateTabs();
};
#endif // _MENU_SCREEN_H_
+39
View File
@@ -0,0 +1,39 @@
/*
* 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 "message_dialog.h"
#include "static.h"
MessageDialog::MessageDialog(const char * title, const char * message):
Dialog(title, {50, 73, LCD_W - 100, LCD_H - 146})
{
new StaticText(this, {0, height() / 2, width(), PAGE_LINE_HEIGHT}, message, CENTERED);
}
#if defined(HARDWARE_KEYS)
void MessageDialog::onKeyEvent(event_t event)
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
if (event == EVT_KEY_BREAK(KEY_EXIT) || event == EVT_KEY_BREAK(KEY_ENTER)) {
deleteLater();
}
}
#endif
+40
View File
@@ -0,0 +1,40 @@
/*
* 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.
*/
#ifndef _MESSAGE_DIALOG_H_
#define _MESSAGE_DIALOG_H_
#include "dialog.h"
class MessageDialog: public Dialog {
public:
MessageDialog(const char * title, const char * message);
#if defined(HARDWARE_KEYS)
void onKeyEvent(event_t event) override;
#endif
};
inline void POPUP_INFORMATION(const char * str)
{
new MessageDialog("Message", str);
}
#endif // _MESSAGE_DIALOG_H_
+3 -3
View File
@@ -153,13 +153,13 @@ class CurveButton : public Button {
void paint(BitmapBuffer * dc) override
{
// bounding rect
drawSolidRect(dc, 0, 0, rect.w, rect.h, 2, hasFocus() ? SCROLLBOX_COLOR : CURVE_AXIS_COLOR);
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, hasFocus() ? SCROLLBOX_COLOR : CURVE_AXIS_COLOR);
// curve characteristics
if (isCurveFilled(index)) {
CurveInfo &curve = g_model.curves[index];
drawNumber(dc, 130, 5, 5 + curve.points, LEFT, 0, nullptr, STR_PTS);
drawTextAtIndex(dc, 130, 25, STR_CURVE_TYPES, curve.type);
dc->drawNumber(130, 5, 5 + curve.points, LEFT, 0, nullptr, STR_PTS);
dc->drawTextAtIndex(130, 25, STR_CURVE_TYPES, curve.type);
if (curve.smooth)
dc->drawText(130, 45, "Smooth");
}
+2 -2
View File
@@ -310,7 +310,7 @@ void CommonInputOrMixButton::paint(BitmapBuffer * dc)
if (active)
dc->drawSolidFilledRect(2, 2, rect.w - 4, rect.h - 4, WARNING_COLOR);
paintBody(dc);
drawSolidRect(dc, 0, 0, rect.w, rect.h, 2, hasFocus() ? SCROLLBOX_COLOR : CURVE_AXIS_COLOR);
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, hasFocus() ? SCROLLBOX_COLOR : CURVE_AXIS_COLOR);
}
class InputLineButton : public CommonInputOrMixButton {
@@ -339,7 +339,7 @@ class InputLineButton : public CommonInputOrMixButton {
if (line.name[0]) {
dc->drawBitmap(146, 2 + FIELD_PADDING_TOP, mixerSetupLabelBitmap);
dc->drawSizedText(166, FIELD_PADDING_TOP, line.name, sizeof(line.name), ZCHAR);
dc->drawSizedText(166, FIELD_PADDING_TOP, line.name, sizeof(line.name));
}
// second line ...
@@ -24,19 +24,19 @@
#define SET_DIRTY() storageDirty(EE_MODEL)
void putsEdgeDelayParam(coord_t x, coord_t y, LogicalSwitchData * ls)
{
lcdDrawChar(x, y, '[');
lcdDrawNumber(lcdNextPos+2, y, lswTimerValue(ls->v2), LEFT|PREC1);
lcdDrawChar(lcdNextPos, y, ':');
if (ls->v3 < 0)
lcdDrawText(lcdNextPos+3, y, "<<");
else if (ls->v3 == 0)
lcdDrawText(lcdNextPos+3, y, "--");
else
lcdDrawNumber(lcdNextPos+3, y, lswTimerValue(ls->v2+ls->v3), LEFT|PREC1);
lcdDrawChar(lcdNextPos, y, ']');
}
//void putsEdgeDelayParam(coord_t x, coord_t y, LogicalSwitchData * ls)
//{
// lcdDrawChar(x, y, '[');
// lcdDrawNumber(lcdNextPos+2, y, lswTimerValue(ls->v2), LEFT|PREC1);
// lcdDrawChar(lcdNextPos, y, ':');
// if (ls->v3 < 0)
// lcdDrawText(lcdNextPos+3, y, "<<");
// else if (ls->v3 == 0)
// lcdDrawText(lcdNextPos+3, y, "--");
// else
// lcdDrawNumber(lcdNextPos+3, y, lswTimerValue(ls->v2+ls->v3), LEFT|PREC1);
// lcdDrawChar(lcdNextPos, y, ']');
//}
class LogicalSwitchEditWindow: public Page {
public:
@@ -102,7 +102,7 @@ class LogicalSwitchEditWindow: public Page {
edit2->invalidate();
});
edit1->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
drawNumber(dc, 2, 2, lswTimerValue(value), flags | PREC1);
dc->drawNumber(2, 2, lswTimerValue(value), flags | PREC1);
});
edit2->setDisplayHandler([=](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
if (value < 0)
@@ -110,7 +110,7 @@ class LogicalSwitchEditWindow: public Page {
else if (value == 0)
dc->drawText(2, 2, "--", flags);
else
drawNumber(dc, 2, 2, lswTimerValue(cs->v2 + value), flags | PREC1);
dc->drawNumber(2, 2, lswTimerValue(cs->v2 + value), flags | PREC1);
});
grid.nextLine();
}
@@ -127,14 +127,14 @@ class LogicalSwitchEditWindow: public Page {
new StaticText(logicalSwitchOneWindow, grid.getLabelSlot(), STR_V1);
auto timer = new NumberEdit(logicalSwitchOneWindow, grid.getFieldSlot(), -128, 122, GET_SET_DEFAULT(cs->v1));
timer->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
drawNumber(dc, 2, 2, lswTimerValue(value), flags | PREC1);
dc->drawNumber(2, 2, lswTimerValue(value), flags | PREC1);
});
grid.nextLine();
new StaticText(logicalSwitchOneWindow, grid.getLabelSlot(), STR_V2);
timer = new NumberEdit(logicalSwitchOneWindow, grid.getFieldSlot(), -128, 122, GET_SET_DEFAULT(cs->v2));
timer->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
drawNumber(dc, 2, 2, lswTimerValue(value), flags | PREC1);
dc->drawNumber(2, 2, lswTimerValue(value), flags | PREC1);
});
grid.nextLine();
}
@@ -265,10 +265,10 @@ class LogicalSwitchButton : public Button {
dc->drawSolidFilledRect(2, 2, rect.w-4, rect.h-4, WARNING_COLOR);
// The bounding rect
drawSolidRect(dc, 0, 0, rect.w, rect.h, 2, hasFocus() ? SCROLLBOX_COLOR : CURVE_AXIS_COLOR);
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, hasFocus() ? SCROLLBOX_COLOR : CURVE_AXIS_COLOR);
// CSW func
lcdDrawTextAtIndex(col1, line1, STR_VCSWFUNC, ls->func);
dc->drawTextAtIndex(col1, line1, STR_VCSWFUNC, ls->func);
// CSW params
if (lsFamily == LS_FAMILY_BOOL || lsFamily == LS_FAMILY_STICKY) {
@@ -277,15 +277,15 @@ class LogicalSwitchButton : public Button {
}
else if (lsFamily == LS_FAMILY_EDGE) {
drawSwitch(dc, col1, line2, ls->v1);
putsEdgeDelayParam(col2, line2, ls);
// TODO putsEdgeDelayParam(col2, line2, ls);
}
else if (lsFamily == LS_FAMILY_COMP) {
drawSource(dc, col2, line1, ls->v1, 0);
drawSource(dc, col3, line1, ls->v2, 0);
}
else if (lsFamily == LS_FAMILY_TIMER) {
lcdDrawNumber(col2, line1, lswTimerValue(ls->v1), LEFT|PREC1);
lcdDrawNumber(col3, line1, lswTimerValue(ls->v2), LEFT|PREC1);
dc->drawNumber(col2, line1, lswTimerValue(ls->v1), LEFT|PREC1);
dc->drawNumber(col3, line1, lswTimerValue(ls->v2), LEFT|PREC1);
}
else {
drawSource(dc, col2, line1, ls->v1, 0);
@@ -297,12 +297,12 @@ class LogicalSwitchButton : public Button {
// CSW duration
if (ls->duration > 0) {
drawNumber(dc, col2, (lsFamily == LS_FAMILY_EDGE) ? line3 : line2, ls->duration, PREC1 | LEFT);
dc->drawNumber(col2, (lsFamily == LS_FAMILY_EDGE) ? line3 : line2, ls->duration, PREC1 | LEFT);
}
// CSW delay
if (lsFamily != LS_FAMILY_EDGE && ls->delay > 0) {
drawNumber(dc, col3, (lsFamily == LS_FAMILY_EDGE) ? line3 : line2, ls->delay, PREC1 | LEFT);
dc->drawNumber(col3, (lsFamily == LS_FAMILY_EDGE) ? line3 : line2, ls->delay, PREC1 | LEFT);
}
}
+1 -1
View File
@@ -252,7 +252,7 @@ class MixLineButton : public CommonInputOrMixButton {
if (line.name[0]) {
dc->drawBitmap(146, FIELD_PADDING_TOP, mixerSetupLabelBitmap);
dc->drawSizedText(166, FIELD_PADDING_TOP, line.name, sizeof(line.name), ZCHAR);
dc->drawSizedText(166, FIELD_PADDING_TOP, line.name, sizeof(line.name));
}
// second line ...
+7 -7
View File
@@ -121,15 +121,15 @@ class OutputLineButton : public Button {
void paint(BitmapBuffer * dc) override
{
// first line
drawNumber(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, output->min - 1000, PREC1);
drawNumber(dc, 68, FIELD_PADDING_TOP, output->max + 1000, PREC1);
drawNumber(dc, 132, FIELD_PADDING_TOP, output->offset, PREC1);
drawNumber(dc, 226, FIELD_PADDING_TOP, PPM_CENTER + output->ppmCenter, RIGHT);
dc->drawNumber(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, output->min - 1000, PREC1);
dc->drawNumber(68, FIELD_PADDING_TOP, output->max + 1000, PREC1);
dc->drawNumber(132, FIELD_PADDING_TOP, output->offset, PREC1);
dc->drawNumber(226, FIELD_PADDING_TOP, PPM_CENTER + output->ppmCenter, RIGHT);
dc->drawText(228, FIELD_PADDING_TOP - 3, output->symetrical ? "=" : "\306");
// second line
if (output->revert) {
drawTextAtIndex(dc, 4, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, STR_MMMINV, output->revert);
dc->drawTextAtIndex(4, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, STR_MMMINV, output->revert);
}
if (output->curve) {
dc->drawBitmap(68, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, mixerSetupCurveBitmap);
@@ -137,11 +137,11 @@ class OutputLineButton : public Button {
}
if (output->name[0]) {
dc->drawBitmap(146, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, mixerSetupLabelBitmap);
dc->drawSizedText(166, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, output->name, sizeof(output->name), ZCHAR);
dc->drawSizedText(166, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, output->name, sizeof(output->name));
}
// bounding rect
drawSolidRect(dc, 0, 0, rect.w, rect.h, 2, hasFocus() ? SCROLLBOX_COLOR : CURVE_AXIS_COLOR);
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, hasFocus() ? SCROLLBOX_COLOR : CURVE_AXIS_COLOR);
}
protected:
+13 -13
View File
@@ -46,7 +46,7 @@ class ChannelFailsafeBargraph: public Window {
const int lim = (g_model.extendedLimits ? (512 * LIMIT_EXT_PERCENT / 100) : 512) * 2;
coord_t x = 0;
lcdDrawRect(x, 0, width(), height());
dc->drawRect(x, 0, width(), height());
const coord_t lenChannel = limit((uint8_t) 1, uint8_t((abs(channelValue) * width() / 2 + lim / 2) / lim),
uint8_t(width() / 2));
const coord_t lenFailsafe = limit((uint8_t) 1, uint8_t((abs(failsafeValue) * width() / 2 + lim / 2) / lim),
@@ -54,8 +54,8 @@ class ChannelFailsafeBargraph: public Window {
x += width() / 2;
const coord_t xChannel = (channelValue > 0) ? x : x + 1 - lenChannel;
const coord_t xFailsafe = (failsafeValue > 0) ? x : x + 1 - lenFailsafe;
lcdDrawSolidFilledRect(xChannel, + 2, lenChannel, (height() / 2) - 3, TEXT_COLOR);
lcdDrawSolidFilledRect(xFailsafe, (height() / 2) + 1, lenFailsafe, (height() / 2) - 3, ALARM_COLOR);
dc->drawSolidFilledRect(xChannel, + 2, lenChannel, (height() / 2) - 3, TEXT_COLOR);
dc->drawSolidFilledRect(xFailsafe, (height() / 2) + 1, lenFailsafe, (height() / 2) - 3, ALARM_COLOR);
}
protected:
@@ -130,7 +130,7 @@ class FailSafeFooter : public Window {
class FailSafePage : public PageTab {
public:
FailSafePage(uint8_t moduleIdx) :
explicit FailSafePage(uint8_t moduleIdx) :
PageTab("FAILSAFE", ICON_STATS_ANALOGS),
moduleIdx(moduleIdx)
{
@@ -155,7 +155,7 @@ FailSafeMenu::FailSafeMenu(uint8_t moduleIdx) :
class RegisterDialog: public Dialog {
public:
RegisterDialog(uint8_t moduleIdx):
explicit RegisterDialog(uint8_t moduleIdx):
Dialog(STR_REGISTER, {50, 73, LCD_W - 100, LCD_H - 146}),
moduleIdx(moduleIdx)
{
@@ -272,7 +272,7 @@ class BindRxChoiceMenu: public Menu {
moduleIdx(moduleIdx),
receiverIdx(receiverIdx)
{
uint8_t receiversCount = min<uint8_t>(reusableBuffer.moduleSetup.bindInformation.candidateReceiversCount, PXX2_MAX_RECEIVERS_PER_MODULE);
auto receiversCount = min<uint8_t>(reusableBuffer.moduleSetup.bindInformation.candidateReceiversCount, PXX2_MAX_RECEIVERS_PER_MODULE);
for (uint8_t i = 0; i < receiversCount; i++) {
const char * receiverName = reusableBuffer.moduleSetup.bindInformation.candidateReceiversNames[i];
addLine(receiverName, [=]() {
@@ -437,7 +437,7 @@ class ModuleWindow : public Window {
update();
}
~ModuleWindow()
~ModuleWindow() override
{
deleteChildren();
}
@@ -452,7 +452,7 @@ class ModuleWindow : public Window {
TextButton * registerButton = nullptr;
Choice * failSafeChoice = nullptr;
void addChannelRange(FormGridLayout &grid, uint8_t moduleIdx)
void addChannelRange(FormGridLayout &grid)
{
new StaticText(this, grid.getLabelSlot(true), STR_CHANNELRANGE);
auto channelStart = new NumberEdit(this, grid.getFieldSlot(2, 0), 1,
@@ -658,7 +658,7 @@ class ModuleWindow : public Window {
// Channel Range
if (g_model.moduleData[moduleIdx].type != MODULE_TYPE_NONE) {
addChannelRange(grid, moduleIdx); //TODO XJT2 should only set channel count of 8/16/24
addChannelRange(grid); //TODO XJT2 should only set channel count of 8/16/24
grid.nextLine();
}
@@ -787,13 +787,13 @@ class ModuleWindow : public Window {
// R9M Power
if (isModuleR9M_FCC(moduleIdx)) {
new StaticText(this, grid.getLabelSlot(true), STR_RFPOWER);
new StaticText(this, grid.getLabelSlot(true), STR_RF_POWER);
new Choice(this, grid.getFieldSlot(), STR_R9M_FCC_POWER_VALUES, 0, R9M_FCC_POWER_MAX,
GET_SET_DEFAULT(g_model.moduleData[moduleIdx].pxx.power));
}
if (isModuleR9M_LBT(moduleIdx)) {
new StaticText(this, grid.getLabelSlot(true), STR_RFPOWER);
new StaticText(this, grid.getLabelSlot(true), STR_RF_POWER);
new Choice(this, grid.getFieldSlot(), STR_R9M_LBT_POWER_VALUES, 0, R9M_LBT_POWER_MAX,
GET_DEFAULT(min<uint8_t>(g_model.moduleData[moduleIdx].pxx.power, R9M_LBT_POWER_MAX)),
SET_DEFAULT(g_model.moduleData[moduleIdx].pxx.power));
@@ -820,7 +820,7 @@ class ModuleWindow : public Window {
};
ModelSetupPage::ModelSetupPage() :
PageTab(STR_MENUSETUP, ICON_MODEL_SETUP)
PageTab(STR_MENU_MODEL_SETUP, ICON_MODEL_SETUP)
{
}
@@ -994,7 +994,7 @@ void ModelSetupPage::build(FormWindow * window)
grid.nextLine();
// Throttle warning
new StaticText(window, grid.getLabelSlot(true), STR_THROTTLEWARNING);
new StaticText(window, grid.getLabelSlot(true), STR_THROTTLE_WARNING);
new CheckBox(window, grid.getFieldSlot(), GET_SET_INVERTED(g_model.disableThrottleWarning));
grid.nextLine();
+7 -7
View File
@@ -77,9 +77,9 @@ class SensorButton : public Button {
dc->drawSolidFilledRect(2, 2, rect.w - 4, rect.h - 4, WARNING_COLOR);
}
drawNumber(dc, 2, 1, number, LEFT, 0, NULL, ":");
dc->drawNumber(2, 1, number, LEFT, 0, NULL, ":");
lcdDrawSizedText(SENSOR_COL1, line1, g_model.telemetrySensors[index].label, TELEM_LABEL_LEN, ZCHAR);
dc->drawSizedText(SENSOR_COL1, line1, g_model.telemetrySensors[index].label, TELEM_LABEL_LEN);
if (telemetryItem.isAvailable()) {
LcdFlags color = telemetryItem.isOld() ? ALARM_COLOR : TEXT_COLOR;
@@ -94,9 +94,9 @@ class SensorButton : public Button {
drawHexNumber(dc, SENSOR_COL3, line1, sensor->id, LEFT);
}
else if (sensor->type == TELEM_TYPE_CUSTOM && !g_model.ignoreSensorIds) {
drawNumber(dc, SENSOR_COL3, line1, sensor->instance, LEFT);
dc->drawNumber(SENSOR_COL3, line1, sensor->instance, LEFT);
}
drawSolidRect(dc, 0, 0, rect.w, rect.h, 2, hasFocus() ? SCROLLBOX_COLOR : CURVE_AXIS_COLOR);
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, hasFocus() ? SCROLLBOX_COLOR : CURVE_AXIS_COLOR);
}
protected:
@@ -409,7 +409,7 @@ void ModelTelemetryPage::build(FormWindow * window, int8_t focusSensorIndex)
new StaticText(window, grid.getLabelSlot(true), STR_LOWALARM);
auto edit = new NumberEdit(window, grid.getFieldSlot(), -30, 30, GET_SET_DEFAULT(g_model.rssiAlarms.warning));
edit->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
drawNumber(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, g_model.rssiAlarms.getWarningRssi(), flags);
dc->drawNumber(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, g_model.rssiAlarms.getWarningRssi(), flags);
});
window->setFirstField(edit);
grid.nextLine();
@@ -417,7 +417,7 @@ void ModelTelemetryPage::build(FormWindow * window, int8_t focusSensorIndex)
new StaticText(window, grid.getLabelSlot(true), STR_CRITICALALARM);
edit = new NumberEdit(window, grid.getFieldSlot(), -30, 30, GET_SET_DEFAULT(g_model.rssiAlarms.critical));
edit->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
drawNumber(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, g_model.rssiAlarms.getCriticalRssi(), flags);
dc->drawNumber(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, g_model.rssiAlarms.getCriticalRssi(), flags);
});
grid.nextLine();
@@ -514,7 +514,7 @@ void ModelTelemetryPage::build(FormWindow * window, int8_t focusSensorIndex)
// Delete all sensors button
new TextButton(window, grid.getFieldSlot(), STR_DELETE_ALL_SENSORS,
[]() -> uint8_t {
new FullScreenDialog(WARNING_TYPE_CONFIRM, STR_CONFIRMDELETE, "", [=]() {
new FullScreenDialog(WARNING_TYPE_CONFIRM, STR_CONFIRMDELETE, "", "", [=]() {
for (int i = 0; i < MAX_TELEMETRY_SENSORS; i++) {
delTelemetryIndex(i);
}
+3 -3
View File
@@ -64,7 +64,7 @@ class MultiPosCalibrationWindow: public Window {
virtual void paint(BitmapBuffer * dc)
{
drawHorizontalSlider(5, 8, rect.w - 18, 1 + (potsPos[potIndex] & 0x0f), 1, XPOTS_MULTIPOS_COUNT+1, XPOTS_MULTIPOS_COUNT, OPTION_SLIDER_TICKS | OPTION_SLIDER_BIG_TICKS | OPTION_SLIDER_NUMBER_BUTTON);
drawHorizontalSlider(dc, 5, 8, rect.w - 18, 1 + (potsPos[potIndex] & 0x0f), 1, XPOTS_MULTIPOS_COUNT+1, XPOTS_MULTIPOS_COUNT, OPTION_SLIDER_TICKS | OPTION_SLIDER_BIG_TICKS | OPTION_SLIDER_NUMBER_BUTTON);
}
protected:
@@ -89,9 +89,9 @@ class PotCalibrationWindow: public Window {
virtual void paint(BitmapBuffer * dc)
{
if(rect.h > rect.w)
drawVerticalSlider(5, 8, rect.h - 18, calibratedAnalogs[potIndex], -RESX, RESX, 40, OPTION_SLIDER_TICKS | OPTION_SLIDER_BIG_TICKS | OPTION_SLIDER_SQUARE_BUTTON);
drawVerticalSlider(dc, 5, 8, rect.h - 18, calibratedAnalogs[potIndex], -RESX, RESX, 40, OPTION_SLIDER_TICKS | OPTION_SLIDER_BIG_TICKS | OPTION_SLIDER_SQUARE_BUTTON);
else
drawHorizontalSlider(5, 8, rect.w - 18, calibratedAnalogs[potIndex], -RESX, RESX, 40, OPTION_SLIDER_TICKS | OPTION_SLIDER_BIG_TICKS | OPTION_SLIDER_SQUARE_BUTTON);
drawHorizontalSlider(dc, 5, 8, rect.w - 18, calibratedAnalogs[potIndex], -RESX, RESX, 40, OPTION_SLIDER_TICKS | OPTION_SLIDER_BIG_TICKS | OPTION_SLIDER_SQUARE_BUTTON);
}
protected:
+2 -2
View File
@@ -152,7 +152,7 @@ void RadioHardwarePage::build(FormWindow * window)
new StaticText(window, grid.getLabelSlot(), STR_BATT_CALIB);
auto batCal = new NumberEdit(window, grid.getFieldSlot(), -127, 127, GET_SET_DEFAULT(g_eeGeneral.txVoltageCalibration));
batCal->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
drawNumber(dc, 2, 0, getBatteryVoltage(), flags | PREC2, 0, nullptr, "V");
dc->drawNumber(2, 0, getBatteryVoltage(), flags | PREC2, 0, nullptr, "V");
});
batCal->setWindowFlags(REFRESH_ALWAYS);
grid.nextLine();
@@ -160,7 +160,7 @@ void RadioHardwarePage::build(FormWindow * window)
// Factory reset
new TextButton(window, grid.getFieldSlot(), STR_FACTORYRESET,
[=]() -> int8_t {
new FullScreenDialog(WARNING_TYPE_CONFIRM, STR_CONFIRMRESET, STR_POPUPS_ENTER_EXIT, [=]() {
new FullScreenDialog(WARNING_TYPE_CONFIRM, STR_CONFIRMRESET, STR_POPUPS_ENTER_EXIT, "", [=]() {
storageEraseAll(false);
NVIC_SystemReset();
return 0;
+16 -16
View File
@@ -88,7 +88,7 @@ class DateTimeWindow : public Window {
SET_LOAD_DATETIME(&t);
});
month->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
drawNumber(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, flags | LEADING0, 2);
dc->drawNumber(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, flags | LEADING0, 2);
});
/* TODO dynamic max instead of 31 ...
@@ -110,7 +110,7 @@ class DateTimeWindow : public Window {
SET_LOAD_DATETIME(&t);
});
day->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
drawNumber(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, flags | LEADING0, 2);
dc->drawNumber(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, flags | LEADING0, 2);
});
grid.nextLine();
@@ -130,7 +130,7 @@ class DateTimeWindow : public Window {
SET_LOAD_DATETIME(&t);
});
hour->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
drawNumber(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, flags | LEADING0, 2);
dc->drawNumber(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, flags | LEADING0, 2);
});
auto minutes = new NumberEdit(this, grid.getFieldSlot(3, 1), 0, 59,
@@ -146,7 +146,7 @@ class DateTimeWindow : public Window {
SET_LOAD_DATETIME(&t);
});
minutes->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
drawNumber(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, flags | LEADING0, 2);
dc->drawNumber(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, flags | LEADING0, 2);
});
auto seconds = new NumberEdit(this, grid.getFieldSlot(3, 2), 0, 59,
@@ -162,7 +162,7 @@ class DateTimeWindow : public Window {
SET_LOAD_DATETIME(&t);
});
seconds->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
drawNumber(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, flags | LEADING0, 2);
dc->drawNumber(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, flags | LEADING0, 2);
});
grid.nextLine();
getParent()->moveWindowsTop(top(), adjustHeight());
@@ -170,7 +170,7 @@ class DateTimeWindow : public Window {
};
RadioSetupPage::RadioSetupPage():
PageTab(STR_MENURADIOSETUP, ICON_RADIO_SETUP)
PageTab(STR_RADIO_SETUP, ICON_RADIO_SETUP)
{
}
@@ -213,7 +213,7 @@ void RadioSetupPage::build(FormWindow * window)
grid.nextLine();
// Main volume
new StaticText(window, grid.getLabelSlot(true), STR_SPEAKER_VOLUME);
new StaticText(window, grid.getLabelSlot(true), STR_VOLUME);
new Slider(window, grid.getFieldSlot(), -VOLUME_LEVEL_DEF, VOLUME_LEVEL_MAX-VOLUME_LEVEL_DEF, GET_SET_DEFAULT(g_eeGeneral.speakerVolume));
grid.nextLine();
@@ -238,7 +238,7 @@ void RadioSetupPage::build(FormWindow * window)
grid.nextLine();
// Beeps pitch
new StaticText(window, grid.getLabelSlot(true), STR_SPKRPITCH);
new StaticText(window, grid.getLabelSlot(true), STR_BEEP_PITCH);
auto edit = new NumberEdit(window, grid.getFieldSlot(), 0, 300,
GET_DEFAULT(15 * g_eeGeneral.speakerPitch),
[=](int32_t newValue) {
@@ -255,7 +255,7 @@ void RadioSetupPage::build(FormWindow * window)
grid.nextLine();
// Vario volume
new StaticText(window, grid.getLabelSlot(true), TR_SPEAKER_VOLUME);
new StaticText(window, grid.getLabelSlot(true), TR_VOLUME);
new Slider(window, grid.getFieldSlot(), -2, +2, GET_SET_DEFAULT(g_eeGeneral.varioVolume));
grid.nextLine();
@@ -285,7 +285,7 @@ void RadioSetupPage::build(FormWindow * window)
grid.nextLine();
// Haptic strength
new StaticText(window, grid.getLabelSlot(true), STR_HAPTICSTRENGTH);
new StaticText(window, grid.getLabelSlot(true), STR_STRENGTH);
new Slider(window, grid.getFieldSlot(), -2, +2, GET_SET_DEFAULT(g_eeGeneral.hapticStrength));
grid.nextLine();
}
@@ -308,7 +308,7 @@ void RadioSetupPage::build(FormWindow * window)
grid.nextLine();
// RSSI shutdown alarm
new StaticText(window, grid.getLabelSlot(true), STR_RSSISHUTDOWNALARM);
new StaticText(window, grid.getLabelSlot(true), STR_RSSI_SHUTDOWN_ALARM);
new CheckBox(window, grid.getFieldSlot(), GET_SET_INVERTED(g_eeGeneral.disableRssiPoweroffAlarm));
grid.nextLine();
@@ -375,7 +375,7 @@ void RadioSetupPage::build(FormWindow * window)
grid.nextLine();
// GPS format
new StaticText(window, grid.getLabelSlot(true), STR_GPSCOORD);
new StaticText(window, grid.getLabelSlot(true), STR_GPS_COORDS_FORMAT);
new Choice(window, grid.getFieldSlot(), STR_GPSFORMAT, 0, 1, GET_SET_DEFAULT(g_eeGeneral.gpsFormat));
grid.nextLine();
}
@@ -388,12 +388,12 @@ void RadioSetupPage::build(FormWindow * window)
#endif
// Country code
new StaticText(window, grid.getLabelSlot(), STR_COUNTRYCODE);
new Choice(window, grid.getFieldSlot(), STR_COUNTRYCODES, 0, 2, GET_SET_DEFAULT(g_eeGeneral.countryCode));
new StaticText(window, grid.getLabelSlot(), STR_COUNTRY_CODE);
new Choice(window, grid.getFieldSlot(), STR_COUNTRY_CODES, 0, 2, GET_SET_DEFAULT(g_eeGeneral.countryCode));
grid.nextLine();
// Audio language
new StaticText(window, grid.getLabelSlot(), STR_VOICELANG);
new StaticText(window, grid.getLabelSlot(), STR_VOICE_LANGUAGE);
auto choice = new Choice(window, grid.getFieldSlot(), nullptr, 0, DIM(languagePacks) - 2, GET_VALUE(currentLanguagePackIdx),
[](uint8_t newValue) {
currentLanguagePackIdx = newValue;
@@ -406,7 +406,7 @@ void RadioSetupPage::build(FormWindow * window)
grid.nextLine();
// Imperial units
new StaticText(window, grid.getLabelSlot(), STR_UNITSSYSTEM);
new StaticText(window, grid.getLabelSlot(), STR_UNITS_SYSTEM);
new Choice(window, grid.getFieldSlot(), STR_VUNITSSYSTEM, 0, 1, GET_SET_DEFAULT(g_eeGeneral.imperial));
grid.nextLine();
@@ -50,7 +50,7 @@ class SpectrumWindow : public Window
}
coord_t y = max<coord_t>(FH, SPECTRUM_HEIGHT - peak_y - FH);
drawNumber(dc, min<coord_t>(100, peak_x), y, ((reusableBuffer.spectrumAnalyser.freq - reusableBuffer.spectrumAnalyser.span / 2) + peak_x * (reusableBuffer.spectrumAnalyser.span / 128)) / 1000000, TINSIZE);
dc->drawNumber(min<coord_t>(100, peak_x), y, ((reusableBuffer.spectrumAnalyser.freq - reusableBuffer.spectrumAnalyser.span / 2) + peak_x * (reusableBuffer.spectrumAnalyser.span / 128)) / 1000000, TINSIZE);
dc->drawText(lcdNextPos, y, "M", TINSIZE);
}
+1 -1
View File
@@ -59,7 +59,7 @@ void RadioTrainerPage::build(FormWindow * window)
new StaticText(window, grid.getLabelSlot(), STR_MULTIPLIER);
auto multiplier = new NumberEdit(window, grid.getFieldSlot(3, 0), -10, 40, GET_SET_DEFAULT(g_eeGeneral.PPM_Multiplier));
multiplier->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
drawNumber(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value+10, flags | PREC1, 0);
dc->drawNumber(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value+10, flags | PREC1, 0);
});
grid.nextLine();
grid.nextLine();
-38
View File
@@ -1,38 +0,0 @@
#include "rle.h"
#include "debug.h"
#include <string.h>
int rle_decode_8bit(unsigned char* dest, unsigned int dest_size, const unsigned char* src)
{
//unsigned char count = 0;
unsigned char prev_byte = 0;
bool prev_byte_valid = false;
const unsigned char* dest_end = dest + dest_size;
unsigned char* d = dest;
while(d < dest_end) {
*d++ = *src;
if (prev_byte_valid && (*src == prev_byte)) {
src++;
if (d + *src > dest + dest_size) {
TRACE("rle_decode_8bit: destination overflow!\n");
return -1;
}
memset(d, prev_byte, *src);
d += *src++;
prev_byte_valid = false;
}
else {
prev_byte = *src++;
prev_byte_valid = true;
}
}
return d - dest;
}
-7
View File
@@ -1,7 +0,0 @@
#ifndef _rle_h_
#define _rle_h_
int rle_decode_8bit(unsigned char* dest, unsigned int dest_size, const unsigned char* src);
#endif
+207
View File
@@ -0,0 +1,207 @@
/*
* 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 <algorithm>
#include "screen_setup.h"
#include "opentx.h"
#define SET_DIRTY() storageDirty(EE_MODEL)
ScreenAddPage::ScreenAddPage(ScreenMenu * menu, uint8_t pageIndex):
PageTab("", ICON_THEME_ADD_VIEW),
menu(menu),
pageIndex(pageIndex)
{
setTitle(STR_ADD_MAIN_VIEW);
}
void ScreenAddPage::build(FormWindow * window)
{
auto button = new TextButton(window, {LCD_W / 2 - 100, (window->height() - 24) / 2, 200, 24}, STR_ADD_MAIN_VIEW);
button->setPressHandler([=]() {
const LayoutFactory * factory = getRegisteredLayouts().front();
customScreens[pageIndex] = factory->create(&g_model.screenData[pageIndex].layoutData);
strncpy(g_model.screenData[pageIndex].layoutName, factory->getId(), sizeof(g_model.screenData[pageIndex].layoutName));
menu->removeTab(pageIndex);
menu->addTab(new ScreenSetupPage(menu, pageIndex));
menu->setCurrentTab(pageIndex);
if (pageIndex < MAX_CUSTOM_SCREENS - 1) {
menu->addTab(new ScreenAddPage(menu, pageIndex + 1));
}
storageDirty(EE_MODEL);
return 0;
});
}
class LayoutChoice: public FormField {
public:
LayoutChoice(Window * parent, const rect_t & rect, std::function<const LayoutFactory *()> getValue, std::function<void(const LayoutFactory *)> setValue):
FormField(parent, {rect.x, rect.y, 59, 33}),
getValue(std::move(getValue)),
setValue(std::move(setValue))
{
}
void paint(BitmapBuffer * dc) override
{
FormField::paint(dc);
auto layout = getValue();
layout->drawThumb(dc, 4, 4, editMode ? TEXT_INVERTED_COLOR : LINE_COLOR);
}
#if defined(HARDWARE_KEYS)
void onKeyEvent(event_t event) override
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
if (event == EVT_KEY_BREAK(KEY_ENTER)) {
editMode = true;
invalidate();
openMenu();
}
else {
FormField::onKeyEvent(event);
}
}
#endif
void openMenu()
{
auto menu = new Menu();
for (auto layout: getRegisteredLayouts()) {
menu->addLine([=](BitmapBuffer *dc, coord_t x, coord_t y, LcdFlags flags) {
layout->drawThumb(dc, x + 2, y + 2, flags);
dc->drawText(65, y + 5, layout->getName(), flags);
}, [=]() {
setValue(layout);
});
}
auto it = std::find(getRegisteredLayouts().begin(), getRegisteredLayouts().end(), getValue());
menu->select(std::distance(getRegisteredLayouts().begin(), it));
menu->setCloseHandler([=]() {
editMode = false;
setFocus();
});
}
protected:
std::function<const LayoutFactory *()> getValue;
std::function<void(const LayoutFactory *)> setValue;
};
ScreenSetupPage::ScreenSetupPage(ScreenMenu * menu, uint8_t pageIndex):
PageTab("", ICON_THEME_VIEW1 + pageIndex),
menu(menu),
pageIndex(pageIndex)
{
char title[] = "Main view X";
title[sizeof(title) - 2] = '1' + pageIndex;
setTitle(title);
}
void ScreenSetupPage::build(FormWindow * window)
{
FormGridLayout grid;
grid.spacer(PAGE_PADDING);
// Layout choice...
new StaticText(window, grid.getLabelSlot(false), STR_LAYOUT);
auto layoutSlot = grid.getFieldSlot();
layoutSlot.h = 2 * PAGE_LINE_HEIGHT - 1;
layoutChoice = new LayoutChoice(window, layoutSlot, GET_VALUE(customScreens[pageIndex]->getFactory()), [=](const LayoutFactory *factory) {
delete customScreens[pageIndex];
customScreens[pageIndex] = factory->create(&g_model.screenData[pageIndex].layoutData);
strncpy(g_model.screenData[pageIndex].layoutName, factory->getId(), sizeof(g_model.screenData[pageIndex].layoutName));
SET_DIRTY();
updateLayoutOptions();
});
grid.nextLine(layoutChoice->height());
// Setup widgets button...
setupWidgetsButton = new TextButton(window, grid.getFieldSlot(), STR_SETUP_WIDGETS);
setupWidgetsButton->setPressHandler([=]() {
// auto setupWidgetsPage = new SetupWidgetsPage();
// setupWidgetsPage->setCloseHandler([=]() {
// setupWidgetsButton->setFocus();
// });
return 0;
});
grid.nextLine();
// Dynamic options window...
optionsWindow = new Window(window, {0, grid.getWindowHeight(), LCD_W, 0}, FORWARD_SCROLL);
grid.addWindow(optionsWindow);
updateLayoutOptions();
}
void ScreenSetupPage::updateLayoutOptions()
{
FormGridLayout grid;
optionsWindow->clear();
FormField::setCurrentField(setupWidgetsButton); // next field will be linked to this button
auto screen = customScreens[pageIndex];
// Layout options...
int index = 0;
for (auto * option = screen->getFactory()->getOptions(); option->name; option++, index++) {
ZoneOptionValue * value = screen->getOptionValue(index);
// Option label
new StaticText(optionsWindow, grid.getLabelSlot(false), option->name);
// Option value
switch (option->type) {
case ZoneOption::Bool:
new CheckBox(optionsWindow, grid.getFieldSlot(), GET_SET_DEFAULT(value->boolValue));
break;
case ZoneOption::Color:
new ColorEdit(optionsWindow, grid.getFieldSlot(), GET_SET_DEFAULT(value->unsignedValue));
break;
default:
break;
}
grid.nextLine();
}
if (pageIndex > 0 || customScreens[1]) {
auto button = new TextButton(optionsWindow, grid.getFieldSlot(), STR_REMOVE_SCREEN);
button->setPressHandler([=]() {
if (pageIndex < MAX_CUSTOM_SCREENS - 1) {
memmove(&g_model.screenData[pageIndex], &g_model.screenData[pageIndex + 1], sizeof(CustomScreenData) * (MAX_CUSTOM_SCREENS - pageIndex - 1));
}
memset(&g_model.screenData[MAX_CUSTOM_SCREENS - 1], 0, sizeof(CustomScreenData));
loadCustomScreens();
menu->updateTabs();
storageDirty(EE_MODEL);
return 0;
});
}
optionsWindow->adjustHeight();
optionsWindow->getParent()->adjustInnerHeight();
FormField::link(FormField::getCurrentField(), layoutChoice);
}
+48
View File
@@ -0,0 +1,48 @@
/*
* 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 "menu_screen.h"
class ScreenAddPage: public PageTab {
public:
ScreenAddPage(ScreenMenu * menu, uint8_t pageIndex);
void build(FormWindow * window) override;
protected:
ScreenMenu * menu;
uint8_t pageIndex;
};
class ScreenSetupPage: public PageTab {
public:
ScreenSetupPage(ScreenMenu * menu, uint8_t pageIndex);
void build(FormWindow * window) override;
protected:
ScreenMenu * menu;
uint8_t pageIndex;
Window * optionsWindow = nullptr;
TextButton * setupWidgetsButton = nullptr;
FormField * layoutChoice = nullptr;
void updateLayoutOptions();
};
@@ -684,6 +684,6 @@ bool menuScreenAdd(event_t event)
return false;
}
SIMPLE_MENU_WITH_OPTIONS(STR_ADDMAINVIEW, THEME_ICONS, menuTabScreensSetup, menuPageCount, menuPageCount-1, 0);
SIMPLE_MENU_WITH_OPTIONS(STR_ADD_MAIN_VIEW, THEME_ICONS, menuTabScreensSetup, menuPageCount, menuPageCount-1, 0);
return true;
}
+138
View File
@@ -0,0 +1,138 @@
/*
* 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 "libopenui_config.h"
#include "sourcechoice.h"
#include "menutoolbar.h"
#include "menu.h"
#include "dataconstants.h"
#include "lcd.h"
#include "strhelpers.h"
#include "draw_functions.h"
class SourceChoiceMenuToolbar : public MenuToolbar<SourceChoice> {
public:
SourceChoiceMenuToolbar(SourceChoice * choice, Menu * menu):
MenuToolbar<SourceChoice>(choice, menu)
{
addButton(char('\314'), MIXSRC_FIRST_INPUT, MIXSRC_LAST_INPUT);
#if defined(LUA_MODEL_SCRIPTS)
addButton(char('\322'), MIXSRC_LAST_LUA, MIXSRC_FIRST_LUA);
#endif
addButton(char('\307'), MIXSRC_FIRST_STICK, MIXSRC_LAST_STICK);
addButton(char('\310'), MIXSRC_FIRST_POT, MIXSRC_LAST_POT);
addButton(char('\315'), MIXSRC_MAX, MIXSRC_MAX);
#if defined(HELI)
addButton(char('\316'), MIXSRC_FIRST_HELI, MIXSRC_LAST_HELI);
#endif
addButton(char('\313'), MIXSRC_FIRST_TRIM, MIXSRC_LAST_TRIM);
addButton(char('\312'), MIXSRC_FIRST_SWITCH, MIXSRC_LAST_SWITCH);
addButton(char('\317'), MIXSRC_FIRST_TRAINER, MIXSRC_LAST_TRAINER);
addButton(char('\320'), MIXSRC_FIRST_CH, MIXSRC_LAST_CH);
#if defined(GVARS)
addButton(char('\311'), MIXSRC_LAST_GVAR, MIXSRC_FIRST_GVAR);
#endif
addButton(char('\321'), MIXSRC_FIRST_TELEM, MIXSRC_LAST_TELEM);
}
};
void SourceChoice::paint(BitmapBuffer * dc)
{
FormField::paint(dc);
unsigned value = getValue();
LcdFlags textColor;
if (editMode)
textColor = TEXT_INVERTED_COLOR;
else if (hasFocus())
textColor = TEXT_INVERTED_BGCOLOR;
else if (value == 0)
textColor = CURVE_AXIS_COLOR;
else
textColor = 0;
drawSource(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, textColor);
}
void SourceChoice::fillMenu(Menu * menu, std::function<bool(int16_t)> filter)
{
auto value = getValue();
int count = 0;
#if defined(HARDWARE_TOUCH)
int current = -1;
#else
int current = 0;
#endif
menu->removeLines();
for (int i = vmin; i <= vmax; ++i) {
if (filter && !filter(i))
continue;
if (isValueAvailable && !isValueAvailable(i))
continue;
menu->addLine(getSourceString(i), [=]() {
setValue(i);
});
if (value == i) {
current = count;
}
++count;
}
if (current >= 0) {
menu->select(current);
}
}
void SourceChoice::openMenu()
{
auto menu = new Menu();
fillMenu(menu);
menu->setToolbar(new SourceChoiceMenuToolbar(this, menu));
menu->setCloseHandler([=]() {
editMode = false;
setFocus();
});
}
#if defined(HARDWARE_KEYS)
void SourceChoice::onKeyEvent(event_t event)
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
if (event == EVT_KEY_BREAK(KEY_ENTER)) {
editMode = true;
invalidate();
openMenu();
}
else {
FormField::onKeyEvent(event);
}
}
#endif
#if defined(HARDWARE_TOUCH)
bool SourceChoice::onTouchEnd(coord_t, coord_t)
{
openMenu();
setFocus();
return true;
}
#endif
+75
View File
@@ -0,0 +1,75 @@
/*
* 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.
*/
#ifndef _SOURCECHOICE_H_
#define _SOURCECHOICE_H_
#include "form.h"
class Menu;
bool isSourceAvailable(int source);
class SourceChoice : public FormField {
template <class T> friend class MenuToolbar;
public:
SourceChoice(Window * parent, const rect_t & rect, int16_t vmin, int16_t vmax, std::function<int16_t()> getValue, std::function<void(int16_t)> setValue):
FormField(parent, rect),
vmin(vmin),
vmax(vmax),
getValue(std::move(getValue)),
setValue(std::move(setValue))
{
}
#if defined(DEBUG_WINDOWS)
std::string getName() override
{
return "SourceChoice";
}
#endif
void paint(BitmapBuffer * dc) override;
#if defined(HARDWARE_KEYS)
void onKeyEvent(event_t event) override;
#endif
#if defined(HARDWARE_TOUCH)
bool onTouchEnd(coord_t x, coord_t y) override;
#endif
void setAvailableHandler(std::function<bool(int)> handler)
{
isValueAvailable = std::move(handler);
}
protected:
int16_t vmin;
int16_t vmax;
std::function<int16_t()> getValue;
std::function<void(int16_t)> setValue;
std::function<bool(int)> isValueAvailable = isSourceAvailable;
void fillMenu(Menu * menu, std::function<bool(int16_t)> condition=nullptr);
void openMenu();
};
#endif // _SOURCECHOICE_H_
+21 -21
View File
@@ -109,7 +109,7 @@ class SpecialFunctionEditPage : public Page {
break;
case FUNC_VOLUME:
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_SPEAKER_VOLUME);
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_VOLUME);
new SourceChoice(specialFunctionOneWindow, grid.getFieldSlot(), 0, MIXSRC_LAST_CH, GET_SET_DEFAULT(CFN_PARAM(cfn)));
grid.nextLine();
break;
@@ -176,7 +176,7 @@ class SpecialFunctionEditPage : public Page {
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_VALUE);
auto edit = new NumberEdit(specialFunctionOneWindow, grid.getFieldSlot(), 0, 255, GET_SET_DEFAULT(CFN_PARAM(cfn)));
edit->setDisplayHandler([=](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
lcdDrawNumber(2, 2, CFN_PARAM(cfn), PREC1, sizeof(CFN_PARAM(cfn)), nullptr, "s");
dc->drawNumber(2, 2, CFN_PARAM(cfn), PREC1, sizeof(CFN_PARAM(cfn)), nullptr, "s");
});
break;
}
@@ -192,11 +192,11 @@ class SpecialFunctionEditPage : public Page {
auto repeat = new NumberEdit(specialFunctionOneWindow, grid.getFieldSlot(2, 1), -1, 60/CFN_PLAY_REPEAT_MUL, GET_SET_DEFAULT(CFN_PLAY_REPEAT(cfn)));
repeat->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
if (value == 0)
lcdDrawText(3, 0, "1x", flags);
dc->drawText(3, 0, "1x", flags);
else if (value == CFN_PLAY_REPEAT_NOSTART)
lcdDrawText(3, 0, "!1x", flags);
dc->drawText(3, 0, "!1x", flags);
else
drawNumber(dc, 3, 0, value * CFN_PLAY_REPEAT_MUL, flags, 0, nullptr, "s");
dc->drawNumber(3, 0, value * CFN_PLAY_REPEAT_MUL, flags, 0, nullptr, "s");
});
}
@@ -297,7 +297,7 @@ class SpecialFunctionButton : public Button {
if (CFN_EMPTY(cfn))
return;
lcdDrawTextAtIndex(col2, line1, STR_VFSWFUNC, func, 0);
dc->drawTextAtIndex(col2, line1, STR_VFSWFUNC, func, 0);
int16_t val_min = 0;
int16_t val_max = 255;
@@ -305,7 +305,7 @@ class SpecialFunctionButton : public Button {
case FUNC_OVERRIDE_CHANNEL:
drawChn(dc, col1, line2, CFN_CH_INDEX(cfn) + 1, 0);
getMixSrcRange(MIXSRC_FIRST_CH, val_min, val_max);
lcdDrawNumber(col2, line2, CFN_PARAM(cfn));
dc->drawNumber(col2, line2, CFN_PARAM(cfn));
break;
case FUNC_TRAINER:
@@ -314,11 +314,11 @@ class SpecialFunctionButton : public Button {
case FUNC_RESET:
if (CFN_PARAM(cfn) < FUNC_RESET_PARAM_FIRST_TELEM) {
lcdDrawTextAtIndex(col1, line2, STR_VFSWRESET, CFN_PARAM(cfn));
dc->drawTextAtIndex(col1, line2, STR_VFSWRESET, CFN_PARAM(cfn));
}
else {
TelemetrySensor * sensor = &g_model.telemetrySensors[CFN_PARAM(cfn) - FUNC_RESET_PARAM_FIRST_TELEM];
lcdDrawSizedText(col1, line2, sensor->label, TELEM_LABEL_LEN, ZCHAR);
dc->drawSizedText(col1, line2, sensor->label, TELEM_LABEL_LEN);
}
break;
@@ -327,16 +327,16 @@ class SpecialFunctionButton : public Button {
break;
case FUNC_PLAY_SOUND:
lcdDrawTextAtIndex(col1, line2, STR_FUNCSOUNDS, CFN_PARAM(cfn));
dc->drawTextAtIndex(col1, line2, STR_FUNCSOUNDS, CFN_PARAM(cfn));
break;
case FUNC_PLAY_TRACK:
case FUNC_BACKGND_MUSIC:
case FUNC_PLAY_SCRIPT:
if (ZEXIST(cfn->play.name))
lcdDrawSizedText(col1, line2, cfn->play.name, sizeof(cfn->play.name), 0);
dc->drawSizedText(col1, line2, cfn->play.name, sizeof(cfn->play.name), 0);
else
lcdDrawTextAtIndex(col1, line2, STR_VCSWFUNC, 0, 0);
dc->drawTextAtIndex(col1, line2, STR_VCSWFUNC, 0, 0);
break;
case FUNC_SET_TIMER:
@@ -344,7 +344,7 @@ class SpecialFunctionButton : public Button {
break;
case FUNC_SET_FAILSAFE:
lcdDrawTextAtIndex(col1, line2, "\004Int.Ext.", CFN_PARAM(cfn), 0);
dc->drawTextAtIndex(col1, line2, "\004Int.Ext.", CFN_PARAM(cfn), 0);
break;
case FUNC_PLAY_VALUE:
@@ -352,35 +352,35 @@ class SpecialFunctionButton : public Button {
break;
case FUNC_HAPTIC:
lcdDrawNumber(col1, line2, CFN_PARAM(cfn), 0);
dc->drawNumber(col1, line2, CFN_PARAM(cfn), 0);
break;
case FUNC_LOGS:
lcdDrawNumber(col3, line1, CFN_PARAM(cfn), PREC1, sizeof(CFN_PARAM(cfn)), nullptr, "s");
dc->drawNumber(col3, line1, CFN_PARAM(cfn), PREC1, sizeof(CFN_PARAM(cfn)), nullptr, "s");
break;
}
if (HAS_ENABLE_PARAM(func)) {
drawCheckBox(col3, line2, CFN_ACTIVE(cfn), 0);
drawCheckBox(dc, col3, line2, CFN_ACTIVE(cfn), 0);
}
else if (HAS_REPEAT_PARAM(func)) {
if (CFN_PLAY_REPEAT(cfn) == 0) {
lcdDrawText(col3, line2, "1x", 0);
dc->drawText(col3, line2, "1x", 0);
}
else if (CFN_PLAY_REPEAT(cfn) == CFN_PLAY_REPEAT_NOSTART) {
lcdDrawText(col3, line2, "!1x", 0);
dc->drawText(col3, line2, "!1x", 0);
}
else {
lcdDrawNumber(col3 + 12, line2, CFN_PLAY_REPEAT(cfn) * CFN_PLAY_REPEAT_MUL, 0 | RIGHT, 0, nullptr, "s");
dc->drawNumber(col3 + 12, line2, CFN_PLAY_REPEAT(cfn) * CFN_PLAY_REPEAT_MUL, 0 | RIGHT, 0, nullptr, "s");
}
}
}
virtual void paint(BitmapBuffer * dc) override
void paint(BitmapBuffer * dc) override
{
if (active)
dc->drawSolidFilledRect(2, 2, rect.w - 4, rect.h - 4, WARNING_COLOR);
paintSpecialFunctionLine(dc);
drawSolidRect(dc, 0, 0, rect.w, rect.h, 2, hasFocus() ? SCROLLBOX_COLOR : CURVE_AXIS_COLOR);
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, hasFocus() ? SCROLLBOX_COLOR : CURVE_AXIS_COLOR);
}
protected:
+122
View File
@@ -0,0 +1,122 @@
/*
* 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 "libopenui_config.h"
#include "switchchoice.h"
#include "menutoolbar.h"
#include "menu.h"
#include "draw_functions.h"
#include "strhelpers.h"
#include "dataconstants.h"
class SwitchChoiceMenuToolbar : public MenuToolbar<SwitchChoice> {
public:
SwitchChoiceMenuToolbar(SwitchChoice * choice, Menu * menu):
MenuToolbar<SwitchChoice>(choice, menu)
{
addButton(char('\312'), SWSRC_FIRST_SWITCH, SWSRC_LAST_SWITCH);
addButton(char('\313'), SWSRC_FIRST_TRIM, SWSRC_LAST_TRIM);
addButton(char('\312'), SWSRC_FIRST_LOGICAL_SWITCH, SWSRC_LAST_LOGICAL_SWITCH);
}
};
void SwitchChoice::paint(BitmapBuffer * dc)
{
FormField::paint(dc);
unsigned value = getValue();
LcdFlags textColor;
if (editMode)
textColor = TEXT_INVERTED_COLOR;
else if (hasFocus())
textColor = TEXT_INVERTED_BGCOLOR;
else if (value == 0)
textColor = CURVE_AXIS_COLOR;
else
textColor = 0;
drawSwitch(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, textColor);
}
void SwitchChoice::fillMenu(Menu * menu, std::function<bool(int16_t)> filter)
{
auto value = getValue();
int count = 0;
#if defined(HARDWARE_TOUCH)
int current = -1;
#else
int current = 0;
#endif
menu->removeLines();
for (int i = vmin; i <= vmax; ++i) {
if (filter && !filter(i))
continue;
if (isValueAvailable && !isValueAvailable(i))
continue;
menu->addLine(getSwitchPositionName(i), [=]() {
setValue(i);
});
if (value == i) {
current = count;
}
++count;
}
if (current >= 0) {
menu->select(current);
}
}
void SwitchChoice::openMenu()
{
auto menu = new Menu();
fillMenu(menu);
menu->setToolbar(new SwitchChoiceMenuToolbar(this, menu));
menu->setCloseHandler([=]() {
editMode = false;
setFocus();
});
}
#if defined(HARDWARE_KEYS)
void SwitchChoice::onKeyEvent(event_t event)
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
if (event == EVT_KEY_BREAK(KEY_ENTER)) {
editMode = true;
invalidate();
openMenu();
}
else {
FormField::onKeyEvent(event);
}
}
#endif
#if defined(HARDWARE_TOUCH)
bool SwitchChoice::onTouchEnd(coord_t, coord_t)
{
openMenu();
setFocus();
return true;
}
#endif
+74
View File
@@ -0,0 +1,74 @@
/*
* 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.
*/
#ifndef _SWITCHCHOICE_H_
#define _SWITCHCHOICE_H_
#include "form.h"
class Menu;
bool isSwitchAvailableInMixes(int swtch);
class SwitchChoice : public FormField {
template <class T> friend class MenuToolbar;
public:
SwitchChoice(Window * parent, const rect_t & rect, int vmin, int vmax, std::function<int16_t()> getValue, std::function<void(int16_t)> setValue):
FormField(parent, rect),
vmin(vmin),
vmax(vmax),
getValue(std::move(getValue)),
setValue(std::move(setValue))
{
}
#if defined(DEBUG_WINDOWS)
std::string getName() override
{
return "SwitchChoice";
}
#endif
void paint(BitmapBuffer * dc) override;
#if defined(HARDWARE_KEYS)
void onKeyEvent(event_t event) override;
#endif
#if defined(HARDWARE_TOUCH)
bool onTouchEnd(coord_t x, coord_t y) override ;
#endif
void setAvailableHandler(std::function<bool(int)> handler)
{
isValueAvailable = std::move(handler);
}
protected:
int16_t vmin;
int16_t vmax;
std::function<int16_t()> getValue;
std::function<void(int16_t)> setValue;
std::function<bool(int)> isValueAvailable = isSwitchAvailableInMixes;
void fillMenu(Menu * menu, std::function<bool(int16_t)> condition=nullptr);
void openMenu();
};
#endif // _SWITCHCHOICE_H_
+86 -28
View File
@@ -20,25 +20,26 @@
#include "opentx.h"
const BitmapBuffer * Theme::asterisk = NULL;
const BitmapBuffer * Theme::question = NULL;
const BitmapBuffer * Theme::busy = NULL;
extern ThemeBase * defaultTheme;
const BitmapBuffer * ThemeBase::asterisk = NULL;
const BitmapBuffer * ThemeBase::question = NULL;
const BitmapBuffer * ThemeBase::busy = NULL;
std::list<Theme *> & getRegisteredThemes()
std::list<ThemeBase *> & getRegisteredThemes()
{
static std::list<Theme *> themes;
static std::list<ThemeBase *> themes;
return themes;
}
void registerTheme(Theme * theme)
void registerTheme(ThemeBase * theme)
{
TRACE("register theme %s", theme->getName());
getRegisteredThemes().push_back(theme);
}
void Theme::init() const
void ThemeBase::init() const
{
memset(&g_eeGeneral.themeData, 0, sizeof(Theme::PersistentData));
memset(&g_eeGeneral.themeData, 0, sizeof(ThemeBase::PersistentData));
if (options) {
int i = 0;
for (const ZoneOption * option = options; option->name; option++, i++) {
@@ -48,19 +49,22 @@ void Theme::init() const
}
}
void Theme::load() const
void ThemeBase::load() const
{
if (!asterisk) asterisk = BitmapBuffer::load(getThemePath("asterisk.bmp"));
if (!question) question = BitmapBuffer::load(getThemePath("question.bmp"));
if (!busy) busy = BitmapBuffer::load(getThemePath("busy.bmp"));
if (!asterisk)
asterisk = BitmapBuffer::load(getFilePath("asterisk.bmp"));
if (!question)
question = BitmapBuffer::load(getFilePath("question.bmp"));
if (!busy)
busy = BitmapBuffer::load(getFilePath("busy.bmp"));
}
ZoneOptionValue * Theme::getOptionValue(unsigned int index) const
ZoneOptionValue * ThemeBase::getOptionValue(unsigned int index) const
{
return &g_eeGeneral.themeData.options[index];
}
const char * Theme::getFilePath(const char * filename) const
const char * ThemeBase::getFilePath(const char * filename) const
{
static char path[_MAX_LFN+1] = THEMES_PATH "/";
strcpy(path + sizeof(THEMES_PATH), getName());
@@ -70,7 +74,7 @@ const char * Theme::getFilePath(const char * filename) const
return path;
}
void Theme::drawThumb(coord_t x, coord_t y, uint32_t flags)
void ThemeBase::drawThumb(BitmapBuffer * dc, coord_t x, coord_t y, uint32_t flags)
{
#define THUMB_WIDTH 51
#define THUMB_HEIGHT 31
@@ -79,16 +83,16 @@ void Theme::drawThumb(coord_t x, coord_t y, uint32_t flags)
}
lcd->drawBitmap(x, y, thumb);
if (flags == LINE_COLOR) {
lcdDrawFilledRect(x, y, THUMB_WIDTH, THUMB_HEIGHT, SOLID, OVERLAY_COLOR | OPACITY(10));
dc->drawFilledRect(x, y, THUMB_WIDTH, THUMB_HEIGHT, SOLID, OVERLAY_COLOR | OPACITY(10));
}
}
void Theme::drawBackground(BitmapBuffer * dc) const
void ThemeBase::drawBackground(BitmapBuffer * dc) const
{
dc->drawSolidFilledRect(0, 0, LCD_W, LCD_H, TEXT_BGCOLOR);
}
void Theme::drawMessageBox(const char * title, const char * text, const char * action, uint32_t type) const
void ThemeBase::drawMessageBox(const char * title, const char * text, const char * action, uint32_t type) const
{
}
@@ -127,9 +131,62 @@ void Theme::drawMessageBox(const char * title, const char * text, const char * a
// }
//}
Theme * getTheme(const char * name)
void ThemeBase::drawCheckBox(BitmapBuffer * dc, bool value, bool focus) const
{
std::list<Theme *>::const_iterator it = getRegisteredThemes().cbegin();
if (focus) {
dc->drawSolidFilledRect(0, 2, 16, 16, TEXT_INVERTED_BGCOLOR);
if (value) {
dc->drawSolidFilledRect(2, 4, 12, 12, TEXT_BGCOLOR);
dc->drawSolidFilledRect(3, 5, 10, 10, SCROLLBOX_COLOR);
}
else {
dc->drawSolidFilledRect(2, 4, 12, 12, TEXT_BGCOLOR);
}
}
else {
if (value) {
dc->drawSolidFilledRect(2, 4, 12, 12, SCROLLBOX_COLOR);
dc->drawSolidRect(0, 2, 16, 16, 1, CURVE_AXIS_COLOR);
}
else {
dc->drawSolidRect(0, 2, 16, 16, 1, CURVE_AXIS_COLOR);
}
}
}
void ThemeBase::drawSlider(BitmapBuffer * dc, int vmin, int vmax, int value, const rect_t & rect, bool edit, bool focus) const
{
int val = limit(vmin, value, vmax);
int w = divRoundClosest((rect.w - 16) * (val - vmin), vmax - vmin);
if (edit) {
dc->drawBitmapPattern(0, 11, LBM_SLIDER_BAR_LEFT, TEXT_INVERTED_BGCOLOR);
dc->drawSolidFilledRect(4, 11, rect.w - 8, 4, TEXT_INVERTED_BGCOLOR);
dc->drawBitmapPattern(rect.w - 4, 11, LBM_SLIDER_BAR_RIGHT, TEXT_INVERTED_BGCOLOR);
}
else {
dc->drawBitmapPattern(0, 11, LBM_SLIDER_BAR_LEFT, LINE_COLOR);
dc->drawSolidFilledRect(4, 11, rect.w - 8, 4, LINE_COLOR);
dc->drawBitmapPattern(rect.w - 4, 11, LBM_SLIDER_BAR_RIGHT, LINE_COLOR);
}
dc->drawBitmapPattern(w, 5, LBM_SLIDER_POINT_OUT, TEXT_COLOR);
dc->drawBitmapPattern(w, 5, LBM_SLIDER_POINT_MID, TEXT_BGCOLOR);
// if ((options & INVERS) && (!(options & BLINK) || !BLINK_ON_PHASE))
if (focus) {
dc->drawBitmapPattern(w, 5, LBM_SLIDER_POINT_IN, TEXT_INVERTED_BGCOLOR);
}
}
void ThemeBase::drawPageHeader(BitmapBuffer * dc, const PageHeader * header) const
{
drawMenuBackground(dc, header->getIcon(), "");
dc->drawSolidFilledRect(MENU_HEADER_HEIGHT, 0, LCD_W - MENU_HEADER_HEIGHT, MENU_HEADER_HEIGHT, HEADER_BGCOLOR);
}
ThemeBase * getTheme(const char * name)
{
std::list<ThemeBase *>::const_iterator it = getRegisteredThemes().cbegin();
for (; it != getRegisteredThemes().cend(); ++it) {
if (!strcmp(name, (*it)->getName())) {
return (*it);
@@ -138,11 +195,11 @@ Theme * getTheme(const char * name)
return nullptr;
}
void loadTheme(Theme * newTheme)
void loadTheme(ThemeBase * newTheme)
{
TRACE("load theme %s", newTheme->getName());
theme = newTheme;
theme->load();
newTheme->load();
}
void loadTheme()
@@ -150,11 +207,12 @@ void loadTheme()
char name[THEME_NAME_LEN + 1];
memset(name, 0, sizeof(name));
strncpy(name, g_eeGeneral.themeName, THEME_NAME_LEN);
Theme * newTheme = getTheme(name);
if (newTheme) {
ThemeBase * newTheme = getTheme(name);
if (newTheme)
loadTheme(newTheme);
}
else {
theme->load();
}
else
loadTheme(defaultTheme);
// else {
// loadTheme(theme);
// }
}
+18 -31
View File
@@ -18,29 +18,30 @@
* GNU General Public License for more details.
*/
#ifndef _THEME_H_
#define _THEME_H_
#ifndef _COLORLCD_THEME_H_
#define _COLORLCD_THEME_H_
#include <list>
#include <vector>
#include "zone.h"
#include "thirdparty/libopenui/src/theme.h"
class BitmapBuffer;
class PageTab;
#define MAX_THEME_OPTIONS 5
class Theme;
void registerTheme(Theme * theme);
class ThemeBase;
void registerTheme(ThemeBase * theme);
class Theme
class ThemeBase: public Theme
{
public:
struct PersistentData {
ZoneOptionValue options[MAX_THEME_OPTIONS];
};
Theme(const char * name, const ZoneOption * options = nullptr):
ThemeBase(const char * name, const ZoneOption * options = nullptr):
name(name),
options(options),
thumb(nullptr)
@@ -55,7 +56,7 @@ class Theme
const char * getFilePath(const char * filename) const;
void drawThumb(coord_t x, coord_t y, uint32_t flags);
void drawThumb(BitmapBuffer * dc, coord_t x, coord_t y, uint32_t flags);
inline const ZoneOption * getOptions() const
{
@@ -74,25 +75,18 @@ class Theme
virtual void drawBackground(BitmapBuffer * dc) const;
virtual const BitmapBuffer * getIconButtonBitmap(uint8_t index, bool selected) const
{
TRACE("No bitmap for icon %d in this theme", index);
return nullptr;
}
virtual const BitmapBuffer * getIconMask(uint8_t index) const
{
TRACE("No mask for icon %d in this theme", index);
return nullptr;
}
virtual void drawMenuBackground(BitmapBuffer * dc, uint8_t icon, const char *title) const = 0;
virtual void drawMenuHeader(BitmapBuffer * dc, std::vector<PageTab *> & tabs, uint8_t currentIndex) const = 0;
virtual void drawMessageBox(const char * title, const char * text, const char * action, uint32_t flags) const;
// virtual void drawProgressBar(BitmapBuffer * dc, coord_t x, coord_t y, coord_t w, coord_t h, int value) const = 0;
virtual void drawProgressBar(BitmapBuffer * dc, coord_t x, coord_t y, coord_t w, coord_t h, int value) const = 0;
void drawCheckBox(BitmapBuffer * dc, bool value, bool focus) const override;
void drawSlider(BitmapBuffer * dc, int vmin, int vmax, int value, const rect_t & rect, bool edit, bool focus) const override;
void drawPageHeader(BitmapBuffer * dc, const PageHeader * page) const override;
protected:
const char * name;
@@ -105,17 +99,10 @@ class Theme
static const BitmapBuffer * busy;
};
extern Theme * theme;
inline const char * getThemePath(const char * filename)
{
return theme->getFilePath(filename);
}
Theme * getTheme(const char * name);
void loadTheme(Theme * theme);
ThemeBase * getTheme(const char * name);
void loadTheme(ThemeBase * theme);
void loadTheme();
std::list<Theme *> & getRegisteredThemes();
std::list<ThemeBase *> & getRegisteredThemes();
#endif // _THEME_H_
#endif // _COLORLCD_THEME_H_
+51 -46
View File
@@ -27,11 +27,11 @@ const ZoneOption OPTIONS_THEME_DEFAULT[] = {
{ nullptr, ZoneOption::Bool }
};
class FlyskyTheme: public Theme
class FlyskyTheme: public ThemeBase
{
public:
FlyskyTheme():
Theme("FlySky", OPTIONS_THEME_DEFAULT)
ThemeBase("FlySky", OPTIONS_THEME_DEFAULT)
{
loadColors();
}
@@ -78,9 +78,9 @@ class FlyskyTheme: public Theme
void loadMenuIcon(uint8_t index, const char * filename, uint32_t color=MENU_TITLE_COLOR) const
{
TRACE("loadMenuIcon %s", getThemePath(filename));
TRACE("loadMenuIcon %s", getFilePath(filename));
BitmapBuffer * mask = BitmapBuffer::loadMask(getThemePath(filename));
BitmapBuffer * mask = BitmapBuffer::loadMask(getFilePath(filename));
if (mask) {
delete iconMask[index];
iconMask[index] = mask;
@@ -177,9 +177,9 @@ class FlyskyTheme: public Theme
loadMenuIcon(ICON_MONITOR_CHANNELS4, "mask_monitor_channels4.png");
loadMenuIcon(ICON_MONITOR_LOGICAL_SWITCHES, "mask_monitor_logsw.png");
BitmapBuffer * background = BitmapBuffer::loadMask(getThemePath("mask_currentmenu_bg.png"));
BitmapBuffer * shadow = BitmapBuffer::loadMask(getThemePath("mask_currentmenu_shadow.png"));
BitmapBuffer * dot = BitmapBuffer::loadMask(getThemePath("mask_currentmenu_dot.png"));
BitmapBuffer * background = BitmapBuffer::loadMask(getFilePath("mask_currentmenu_bg.png"));
BitmapBuffer * shadow = BitmapBuffer::loadMask(getFilePath("mask_currentmenu_shadow.png"));
BitmapBuffer * dot = BitmapBuffer::loadMask(getFilePath("mask_currentmenu_dot.png"));
if (!currentMenuBackground) {
currentMenuBackground = new BitmapBuffer(BMP_RGB565, 36, 53);
@@ -205,22 +205,22 @@ class FlyskyTheme: public Theme
{
// Calibration screen
delete calibStick;
calibStick = BitmapBuffer::load(getThemePath("stick_pointer.png"));
calibStick = BitmapBuffer::load(getFilePath("stick_pointer.png"));
delete calibStickBackground;
calibStickBackground = BitmapBuffer::load(getThemePath("stick_background.png"));
calibStickBackground = BitmapBuffer::load(getFilePath("stick_background.png"));
delete calibTrackpBackground;
calibTrackpBackground = BitmapBuffer::load(getThemePath("trackp_background.png"));
calibTrackpBackground = BitmapBuffer::load(getFilePath("trackp_background.png"));
delete calibRadioPict;
calibRadioPict = BitmapBuffer::load(getThemePath("NV14.bmp"));
calibRadioPict = BitmapBuffer::load(getFilePath("NV14.bmp"));
// Model Selection screen
delete modelselIconBitmap;
modelselIconBitmap = BitmapBuffer::loadMaskOnBackground("modelsel/mask_iconback.png", TITLE_BGCOLOR, TEXT_BGCOLOR);
if (modelselIconBitmap) {
BitmapBuffer * bitmap = BitmapBuffer::load(getThemePath("modelsel/icon_default.png"));
BitmapBuffer * bitmap = BitmapBuffer::load(getFilePath("modelsel/icon_default.png"));
modelselIconBitmap->drawBitmap(20, 8, bitmap);
delete bitmap;
}
@@ -235,13 +235,13 @@ class FlyskyTheme: public Theme
modelselModelNameBitmap = BitmapBuffer::loadMaskOnBackground("modelsel/mask_modelname.png", TEXT_COLOR, TEXT_BGCOLOR);
delete modelselModelMoveBackground;
modelselModelMoveBackground = BitmapBuffer::loadMask(getThemePath("modelsel/mask_moveback.png"));
modelselModelMoveBackground = BitmapBuffer::loadMask(getFilePath("modelsel/mask_moveback.png"));
delete modelselModelMoveIcon;
modelselModelMoveIcon = BitmapBuffer::loadMask(getThemePath("modelsel/mask_moveico.png"));
modelselModelMoveIcon = BitmapBuffer::loadMask(getFilePath("modelsel/mask_moveico.png"));
delete modelselWizardBackground;
modelselWizardBackground = BitmapBuffer::load(getThemePath("wizard/background.png"));
modelselWizardBackground = BitmapBuffer::load(getFilePath("wizard/background.png"));
// Channels monitor screen
delete chanMonLockedBitmap;
@@ -276,10 +276,10 @@ class FlyskyTheme: public Theme
mixerSetupCurveBitmap = BitmapBuffer::loadMaskOnBackground("mask_textline_curve.png", TEXT_COLOR, TEXT_BGCOLOR);
delete mixerSetupSwitchIcon;
mixerSetupSwitchIcon = BitmapBuffer::loadMask(getThemePath("mask_textline_switch.png"));
mixerSetupSwitchIcon = BitmapBuffer::loadMask(getFilePath("mask_textline_switch.png"));
delete mixerSetupFlightmodeIcon;
mixerSetupFlightmodeIcon = BitmapBuffer::loadMask(getThemePath("mask_textline_fm.png"));
mixerSetupFlightmodeIcon = BitmapBuffer::loadMask(getFilePath("mask_textline_fm.png"));
delete mixerSetupSlowBitmap;
mixerSetupSlowBitmap = BitmapBuffer::loadMaskOnBackground("mask_textline_slow.png", TEXT_COLOR, TEXT_BGCOLOR);
@@ -291,12 +291,12 @@ class FlyskyTheme: public Theme
mixerSetupDelaySlowBitmap = BitmapBuffer::loadMaskOnBackground("mask_textline_delayslow.png", TEXT_COLOR, TEXT_BGCOLOR);
}
virtual void load() const override
void load() const override
{
loadColors();
Theme::load();
ThemeBase::load();
if (!backgroundBitmap) {
backgroundBitmap = BitmapBuffer::load(getThemePath("background.png"));
backgroundBitmap = BitmapBuffer::load(getFilePath("background.png"));
}
update();
}
@@ -341,26 +341,25 @@ class FlyskyTheme: public Theme
void drawMenuBackground(BitmapBuffer * dc, uint8_t icon, const char * title) const override
{
dc->drawSolidFilledRect(0, 0, LCD_W, MENU_HEADER_HEIGHT, HEADER_BGCOLOR);
if (topleftBitmap) {
dc->drawBitmap(0, 0, topleftBitmap);
uint16_t width = topleftBitmap->getWidth();
dc->drawSolidFilledRect(width, 0, LCD_W-width, MENU_HEADER_HEIGHT, HEADER_BGCOLOR);
}
else {
// if (topleftBitmap) {
// dc->drawBitmap(0, 0, topleftBitmap);
// uint16_t width = topleftBitmap->getWidth();
// dc->drawSolidFilledRect(width, 0, LCD_W-width, MENU_HEADER_HEIGHT, HEADER_BGCOLOR);
// }
// else {
dc->drawSolidFilledRect(0, 0, LCD_W, MENU_HEADER_HEIGHT, HEADER_BGCOLOR);
}
if (icon == ICON_OPENTX)
dc->drawBitmap(4, 10, menuIconSelected[ICON_OPENTX]);
else
dc->drawBitmap(5, 7, menuIconSelected[icon]);
// }
//
// if (icon == ICON_OPENTX)
// dc->drawBitmap(4, 10, menuIconSelected[ICON_OPENTX]);
// else
// dc->drawBitmap(5, 7, menuIconSelected[icon]);
//
dc->drawSolidFilledRect(0, MENU_HEADER_HEIGHT, LCD_W, MENU_TITLE_TOP - MENU_HEADER_HEIGHT, TEXT_BGCOLOR); // the white separation line
dc->drawSolidFilledRect(0, MENU_TITLE_TOP, LCD_W, MENU_TITLE_HEIGHT, TITLE_BGCOLOR); // the title line background
//
if (title) {
lcdDrawText(MENUS_MARGIN_LEFT, MENU_TITLE_TOP, title, MENU_TITLE_COLOR);
dc->drawText(MENUS_MARGIN_LEFT, MENU_TITLE_TOP, title, MENU_TITLE_COLOR);
}
}
@@ -369,20 +368,20 @@ class FlyskyTheme: public Theme
return iconMask[index];
}
const BitmapBuffer * getIconButtonBitmap(uint8_t index, bool selected) const override
const BitmapBuffer * getIcon(uint8_t index, IconState state) const override
{
return selected ? menuIconSelected[index] : menuIconNormal[index];
return state == STATE_DEFAULT ? menuIconNormal[index] : menuIconSelected[index];
}
void drawMenuHeader(BitmapBuffer * dc, std::vector<PageTab *> & tabs, uint8_t currentIndex) const override
{
uint8_t padding_left = 0;
uint8_t padding_left = 4;
dc->drawSolidFilledRect(0, 0, padding_left, MENU_HEADER_BUTTON_WIDTH, HEADER_BGCOLOR);
for (unsigned i=0; i<tabs.size(); i++) {
dc->drawBitmap(padding_left + i*MENU_HEADER_BUTTON_WIDTH, 0, theme->getIconButtonBitmap(tabs[i]->getIcon(), currentIndex == i));
dc->drawSolidFilledRect(0, 0, 4, MENU_HEADER_BUTTON_WIDTH, HEADER_BGCOLOR);
for (unsigned i = 0; i < tabs.size(); i++) {
dc->drawBitmap(padding_left + i*MENU_HEADER_BUTTON_WIDTH, 0, theme->getIcon(tabs[i]->getIcon(), currentIndex == i ? STATE_PRESSED : STATE_DEFAULT));
}
coord_t x = padding_left + MENU_HEADER_BUTTON_WIDTH * tabs.size();
// coord_t x = padding_left + MENU_HEADER_BUTTON_WIDTH * tabs.size();
// coord_t w = width() - x;
// if (w > 0) {
// dc->drawSolidFilledRect(x, 0, w, MENU_HEADER_BUTTON_WIDTH, HEADER_BGCOLOR);
@@ -396,17 +395,22 @@ class FlyskyTheme: public Theme
struct gtm t;
gettime(&t);
char str[10];
#if defined(TRANSLATIONS_CN)
sprintf(str, "%d" TR_MONTH "%d", t.tm_mon + 1, t.tm_mday);
#else
const char * const STR_MONTHS[] = TR_MONTHS;
sprintf(str, "%d %s", t.tm_mday, STR_MONTHS[t.tm_mon]);
lcdDrawText(DATETIME_MIDDLE, DATETIME_LINE1, str, SMLSIZE|TEXT_INVERTED_COLOR|CENTERED);
#endif
dc->drawText(DATETIME_MIDDLE, DATETIME_LINE1, str, SMLSIZE|TEXT_INVERTED_COLOR|CENTERED);
getTimerString(str, getValue(MIXSRC_TX_TIME));
lcdDrawText(DATETIME_MIDDLE, DATETIME_LINE2, str, SMLSIZE|TEXT_INVERTED_COLOR|CENTERED);
dc->drawText(DATETIME_MIDDLE, DATETIME_LINE2, str, SMLSIZE|TEXT_INVERTED_COLOR|CENTERED);
}
void drawProgressBar(BitmapBuffer * dc, coord_t x, coord_t y, coord_t w, coord_t h, int value) const override
{
drawSolidRect(dc, x, y, w, h, 1, TEXT_COLOR);
dc->drawSolidRect(x, y, w, h, 1, TEXT_COLOR);
if (value > 0) {
int width = (w * value) / 100;
dc->drawSolidFilledRect(x + 2, y + 2, width - 4, h - 4, SCROLLBOX_COLOR);
@@ -432,5 +436,6 @@ BitmapBuffer * FlyskyTheme::currentMenuBackground = nullptr;
FlyskyTheme flyskyTheme;
#if defined(PCBFLYSKY)
ThemeBase * defaultTheme = &flyskyTheme;
Theme * theme = &flyskyTheme;
#endif
+37 -34
View File
@@ -27,11 +27,11 @@ const ZoneOption OPTIONS_THEME_DEFAULT[] = {
{ nullptr, ZoneOption::Bool }
};
class FrskyTheme: public Theme
class FrskyTheme: public ThemeBase
{
public:
FrskyTheme():
Theme("FrSky", OPTIONS_THEME_DEFAULT)
ThemeBase("FrSky", OPTIONS_THEME_DEFAULT)
{
loadColors();
}
@@ -72,8 +72,8 @@ class FrskyTheme: public Theme
void loadMenuIcon(uint8_t index, const char * filename, uint32_t color=MENU_TITLE_COLOR) const
{
TRACE("loadMenuIcon %s", getThemePath(filename));
BitmapBuffer * mask = BitmapBuffer::loadMask(getThemePath(filename));
TRACE("loadMenuIcon %s", getFilePath(filename));
BitmapBuffer * mask = BitmapBuffer::loadMask(getFilePath(filename));
if (mask) {
delete iconMask[index];
iconMask[index] = mask;
@@ -148,13 +148,14 @@ class FrskyTheme: public Theme
loadMenuIcon(ICON_MONITOR_CHANNELS4, "mask_monitor_channels4.png");
loadMenuIcon(ICON_MONITOR_LOGICAL_SWITCHES, "mask_monitor_logsw.png");
BitmapBuffer * background = BitmapBuffer::loadMask(getThemePath("mask_currentmenu_bg.png"));
BitmapBuffer * shadow = BitmapBuffer::loadMask(getThemePath("mask_currentmenu_shadow.png"));
BitmapBuffer * dot = BitmapBuffer::loadMask(getThemePath("mask_currentmenu_dot.png"));
BitmapBuffer * background = BitmapBuffer::loadMask(getFilePath("mask_currentmenu_bg.png"));
BitmapBuffer * shadow = BitmapBuffer::loadMask(getFilePath("mask_currentmenu_shadow.png"));
BitmapBuffer * dot = BitmapBuffer::loadMask(getFilePath("mask_currentmenu_dot.png"));
if (!currentMenuBackground) {
currentMenuBackground = new BitmapBuffer(BMP_RGB565, 36, 53);
}
if (currentMenuBackground) {
currentMenuBackground->drawSolidFilledRect(0, 0, currentMenuBackground->getWidth(), MENU_HEADER_HEIGHT, HEADER_BGCOLOR);
currentMenuBackground->drawSolidFilledRect(0, MENU_HEADER_HEIGHT, currentMenuBackground->getWidth(), MENU_TITLE_TOP - MENU_HEADER_HEIGHT, TEXT_BGCOLOR);
@@ -165,7 +166,7 @@ class FrskyTheme: public Theme
}
delete topleftBitmap;
topleftBitmap = BitmapBuffer::loadMaskOnBackground("topleft.png", TITLE_BGCOLOR, HEADER_BGCOLOR);
topleftBitmap = BitmapBuffer::loadMaskOnBackground(getFilePath("topleft.png"), TITLE_BGCOLOR, HEADER_BGCOLOR);
delete background;
delete shadow;
@@ -176,31 +177,31 @@ class FrskyTheme: public Theme
{
// Calibration screen
delete calibStick;
calibStick = BitmapBuffer::load(getThemePath("stick_pointer.png"));
calibStick = BitmapBuffer::load(getFilePath("stick_pointer.png"));
delete calibStickBackground;
calibStickBackground = BitmapBuffer::load(getThemePath("stick_background.png"));
calibStickBackground = BitmapBuffer::load(getFilePath("stick_background.png"));
delete calibTrackpBackground;
calibTrackpBackground = BitmapBuffer::load(getThemePath("trackp_background.png"));
calibTrackpBackground = BitmapBuffer::load(getFilePath("trackp_background.png"));
delete calibRadioPict;
#if defined(PCBX10)
if(STICKS_PWM_ENABLED()) {
calibRadioPict = BitmapBuffer::load(getThemePath("X10S.bmp"));
calibRadioPict = BitmapBuffer::load(getFilePath("X10S.bmp"));
}
else {
calibRadioPict = BitmapBuffer::load(getThemePath("X10.bmp"));
calibRadioPict = BitmapBuffer::load(getFilePath("X10.bmp"));
}
#else
calibRadioPict = BitmapBuffer::load(getThemePath("horus.bmp"));
calibRadioPict = BitmapBuffer::load(getFilePath("horus.bmp"));
#endif
// Model Selection screen
delete modelselIconBitmap;
modelselIconBitmap = BitmapBuffer::loadMaskOnBackground("modelsel/mask_iconback.png", TITLE_BGCOLOR, TEXT_BGCOLOR);
if (modelselIconBitmap) {
BitmapBuffer * bitmap = BitmapBuffer::load(getThemePath("modelsel/icon_default.png"));
BitmapBuffer * bitmap = BitmapBuffer::load(getFilePath("modelsel/icon_default.png"));
modelselIconBitmap->drawBitmap(20, 8, bitmap);
delete bitmap;
}
@@ -215,13 +216,13 @@ class FrskyTheme: public Theme
modelselModelNameBitmap = BitmapBuffer::loadMaskOnBackground("modelsel/mask_modelname.png", TEXT_COLOR, TEXT_BGCOLOR);
delete modelselModelMoveBackground;
modelselModelMoveBackground = BitmapBuffer::loadMask(getThemePath("modelsel/mask_moveback.png"));
modelselModelMoveBackground = BitmapBuffer::loadMask(getFilePath("modelsel/mask_moveback.png"));
delete modelselModelMoveIcon;
modelselModelMoveIcon = BitmapBuffer::loadMask(getThemePath("modelsel/mask_moveico.png"));
modelselModelMoveIcon = BitmapBuffer::loadMask(getFilePath("modelsel/mask_moveico.png"));
delete modelselWizardBackground;
modelselWizardBackground = BitmapBuffer::load(getThemePath("wizard/background.png"));
modelselWizardBackground = BitmapBuffer::load(getFilePath("wizard/background.png"));
// Channels monitor screen
delete chanMonLockedBitmap;
@@ -256,10 +257,10 @@ class FrskyTheme: public Theme
mixerSetupCurveBitmap = BitmapBuffer::loadMaskOnBackground("mask_textline_curve.png", TEXT_COLOR, TEXT_BGCOLOR);
delete mixerSetupSwitchIcon;
mixerSetupSwitchIcon = BitmapBuffer::loadMask(getThemePath("mask_textline_switch.png"));
mixerSetupSwitchIcon = BitmapBuffer::loadMask(getFilePath("mask_textline_switch.png"));
delete mixerSetupFlightmodeIcon;
mixerSetupFlightmodeIcon = BitmapBuffer::loadMask(getThemePath("mask_textline_fm.png"));
mixerSetupFlightmodeIcon = BitmapBuffer::loadMask(getFilePath("mask_textline_fm.png"));
delete mixerSetupSlowBitmap;
mixerSetupSlowBitmap = BitmapBuffer::loadMaskOnBackground("mask_textline_slow.png", TEXT_COLOR, TEXT_BGCOLOR);
@@ -271,17 +272,17 @@ class FrskyTheme: public Theme
mixerSetupDelaySlowBitmap = BitmapBuffer::loadMaskOnBackground("mask_textline_delayslow.png", TEXT_COLOR, TEXT_BGCOLOR);
}
virtual void load() const override
void load() const override
{
loadColors();
Theme::load();
ThemeBase::load();
if (!backgroundBitmap) {
backgroundBitmap = BitmapBuffer::load(getThemePath("background.png"));
backgroundBitmap = BitmapBuffer::load(getFilePath("background.png"));
}
update();
}
virtual void update() const override
void update() const override
{
TRACE("TODO THEME::UPDATE()");
#if 0
@@ -320,12 +321,10 @@ class FrskyTheme: public Theme
void drawMenuBackground(BitmapBuffer * dc, uint8_t icon, const char * title) const override
{
dc->drawSolidFilledRect(0, 0, LCD_W, MENU_HEADER_HEIGHT, HEADER_BGCOLOR);
if (topleftBitmap) {
dc->drawBitmap(0, 0, topleftBitmap);
uint16_t width = topleftBitmap->getWidth();
dc->drawSolidFilledRect(width, 0, LCD_W-width, MENU_HEADER_HEIGHT, HEADER_BGCOLOR);
dc->drawSolidFilledRect(width, 0, LCD_W - width, MENU_HEADER_HEIGHT, HEADER_BGCOLOR);
}
else {
dc->drawSolidFilledRect(0, 0, LCD_W, MENU_HEADER_HEIGHT, HEADER_BGCOLOR);
@@ -339,7 +338,7 @@ class FrskyTheme: public Theme
dc->drawSolidFilledRect(0, MENU_HEADER_HEIGHT, LCD_W, MENU_TITLE_TOP - MENU_HEADER_HEIGHT, TEXT_BGCOLOR); // the white separation line
dc->drawSolidFilledRect(0, MENU_TITLE_TOP, LCD_W, MENU_TITLE_HEIGHT, TITLE_BGCOLOR); // the title line background
if (title) {
lcdDrawText(MENUS_MARGIN_LEFT, MENU_TITLE_TOP + 1, title, MENU_TITLE_COLOR);
dc->drawText(MENUS_MARGIN_LEFT, MENU_TITLE_TOP + 1, title, MENU_TITLE_COLOR);
}
drawMenuDatetime(dc);
@@ -350,9 +349,9 @@ class FrskyTheme: public Theme
return iconMask[index];
}
const BitmapBuffer * getIconButtonBitmap(uint8_t index, bool selected) const override
const BitmapBuffer * getIcon(uint8_t index, IconState state) const override
{
return selected ? menuIconSelected[index] : menuIconNormal[index];
return state == STATE_DEFAULT ? menuIconNormal[index] : menuIconSelected[index];
}
void drawMenuHeader(BitmapBuffer * dc, std::vector<PageTab *> & tabs, uint8_t currentIndex) const override
@@ -373,17 +372,20 @@ class FrskyTheme: public Theme
struct gtm t;
gettime(&t);
char str[10];
#if defined(TRANSLATIONS_CN)
sprintf(str, "%d" TR_MONTH "%d", t.tm_mon + 1, t.tm_mday);
#else
const char * const STR_MONTHS[] = TR_MONTHS;
sprintf(str, "%d %s", t.tm_mday, STR_MONTHS[t.tm_mon]);
lcdDrawText(DATETIME_MIDDLE, DATETIME_LINE1, str, SMLSIZE|TEXT_INVERTED_COLOR|CENTERED);
#endif
dc->drawText(DATETIME_MIDDLE, DATETIME_LINE1, str, SMLSIZE|TEXT_INVERTED_COLOR|CENTERED);
getTimerString(str, getValue(MIXSRC_TX_TIME));
lcdDrawText(DATETIME_MIDDLE, DATETIME_LINE2, str, SMLSIZE|TEXT_INVERTED_COLOR|CENTERED);
dc->drawText(DATETIME_MIDDLE, DATETIME_LINE2, str, SMLSIZE|TEXT_INVERTED_COLOR|CENTERED);
}
void drawProgressBar(BitmapBuffer * dc, coord_t x, coord_t y, coord_t w, coord_t h, int value) const override
{
drawSolidRect(dc, x, y, w, h, 1, TEXT_COLOR);
dc->drawSolidRect(x, y, w, h, 1, TEXT_COLOR);
if (value > 0) {
int width = (w * value) / 100;
dc->drawSolidFilledRect(x + 2, y + 2, width - 4, h - 4, SCROLLBOX_COLOR);
@@ -409,5 +411,6 @@ BitmapBuffer * FrskyTheme::currentMenuBackground = nullptr;
FrskyTheme frskyTheme;
#if defined(PCBFRSKY)
ThemeBase * defaultTheme = &frskyTheme;
Theme * theme = &frskyTheme;
#endif
+96
View File
@@ -0,0 +1,96 @@
/*
* 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 "libopenui_config.h"
#include "timeedit.h"
#include "keyboard_number.h"
#include "strhelpers.h"
TimeEdit::TimeEdit(Window * parent, const rect_t & rect, int32_t vmin, int32_t vmax, std::function<int32_t()> getValue, std::function<void(int32_t)> setValue, LcdFlags flags):
BaseNumberEdit(parent, rect, vmin, vmax, getValue, setValue, flags)
{
}
void TimeEdit::paint(BitmapBuffer * dc)
{
FormField::paint(dc);
LcdFlags textColor;
if (editMode)
textColor = TEXT_INVERTED_COLOR;
else if (hasFocus())
textColor = TEXT_INVERTED_BGCOLOR;
else
textColor = TEXT_COLOR;
dc->drawText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, getTimerString(getValue(), (flags & TIMEHOUR) != 0), textColor);
}
#if defined(HARDWARE_KEYS)
// TODO could be moved to BaseNumberEdit
void TimeEdit::onKeyEvent(event_t event)
{
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
if (editMode) {
if (event == EVT_ROTARY_RIGHT) {
int value = getValue();
value += rotencSpeed * step;
if (value <= vmax)
setValue(value);
else
onKeyError();
return;
}
else if (event == EVT_ROTARY_LEFT) {
int value = getValue();
value -= rotencSpeed * step;
if (value >= vmin)
setValue(value);
else
onKeyError();
return;
}
}
FormField::onKeyEvent(event);
}
#endif
#if defined(HARDWARE_TOUCH)
bool TimeEdit::onTouchEnd(coord_t x, coord_t y)
{
if (!hasFocus()) {
setFocus();
}
NumberKeyboard * keyboard = NumberKeyboard::instance();
if (keyboard->getField() != this) {
keyboard->setField(this);
}
return true;
}
void TimeEdit::onFocusLost()
{
NumberKeyboard::instance()->disable(true);
}
#endif
+50
View File
@@ -0,0 +1,50 @@
/*
* 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.
*/
#ifndef _TIMEEDIT_H_
#define _TIMEEDIT_H_
#include "basenumberedit.h"
class TimeEdit : public BaseNumberEdit {
public:
TimeEdit(Window * parent, const rect_t & rect, int32_t vmin, int32_t vmax, std::function<int32_t()> getValue, std::function<void(int32_t)> setValue = nullptr, LcdFlags flags = 0);
#if defined(DEBUG_WINDOWS)
std::string getName() override
{
return "TimeEdit";
}
#endif
void paint(BitmapBuffer * dc) override;
#if defined(HARDWARE_KEYS)
void onKeyEvent(event_t event) override;
#endif
#if defined(HARDWARE_TOUCH)
bool onTouchEnd(coord_t x, coord_t y) override;
void onFocusLost() override;
#endif
};
#endif // _TIMEEDIT_H_
+9 -5
View File
@@ -21,6 +21,7 @@
#include "view_main.h"
#include "menu_model.h"
#include "menu_radio.h"
#include "menu_screen.h"
// #include "menu_screens.h"
// #include "model_select.h"
// #include "view_channels.h"
@@ -177,12 +178,18 @@ void ViewMain::onKeyEvent(event_t event)
new RadioMenu();
break;
case EVT_KEY_LONG(KEY_TELEM):
killEvents(event);
new ScreenMenu();
break;
case EVT_KEY_LONG(KEY_ENTER):
killEvents(event);
Menu * menu = new Menu();
menu->addLine(STR_MODEL_SELECT, [=]() {
// new ModelselectMenu();
});
if (1/*modelHasNotes()*/) {
if (modelHasNotes()) {
menu->addLine(STR_VIEW_NOTES, [=]() {
// TODO
});
@@ -221,14 +228,11 @@ void ViewMain::onKeyEvent(event_t event)
void ViewMain::checkEvents()
{
Window::checkEvents();
// TODO temporary for refreshing the trims
invalidate();
}
void ViewMain::paint(BitmapBuffer * dc)
{
theme->drawBackground(dc);
static_cast<ThemeBase *>(theme)->drawBackground(dc);
// drawMainPots();
+2 -2
View File
@@ -109,10 +109,10 @@ class WidgetsContainer: public WidgetsContainerInterface
char name[WIDGET_NAME_LEN + 1];
memset(name, 0, sizeof(name));
strncpy(name, persistentData->zones[i].widgetName, WIDGET_NAME_LEN);
widgets[i] = loadWidget(name, getZone(i), &persistentData->zones[i].widgetData);
// widgets[i] = loadWidget(name, getZone(i), &persistentData->zones[i].widgetData);
}
else {
widgets[i] = NULL;
widgets[i] = nullptr;
}
}
}