Improvements to time and timer display #911 (#912)

* Fix time display #911

* move TIMEHOUR definition

* change time format

* Refactoring

* rename

* remove unncessary code

* Change hour/minute format

* pack TimerDisplayOptions structure
This commit is contained in:
eshifri
2021-10-25 12:36:16 +11:00
committed by GitHub
parent 2b8dfeef59
commit 4e571c1325
13 changed files with 95 additions and 56 deletions
+4 -6
View File
@@ -20,6 +20,7 @@
*/
#include "opentx.h"
#include "lcd.h"
coord_t drawStringWithIndex(BitmapBuffer * dc, coord_t x, coord_t y, const char * str, int idx, LcdFlags flags, const char * prefix, const char * suffix)
{
@@ -415,16 +416,13 @@ void drawSensorCustomValue(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t sens
}
}
// libopemui defines TIMOUR as zero
#if !TIMHOUR
#undef TIMEHOUR
#define TIMEHOUR 0x2000
#endif
void drawTimer(BitmapBuffer * dc, coord_t x, coord_t y, int32_t tme, LcdFlags flags)
{
char str[LEN_TIMER_STRING];
getTimerString(str, tme, (flags & TIMEHOUR) != 0);
TimerOptions timerOptions;
timerOptions.options = (flags & TIMEHOUR) != 0 ? SHOW_TIME : SHOW_TIMER;
getTimerString(str, tme, timerOptions);
dc->drawText(x, y, str, flags);
}
+9
View File
@@ -26,6 +26,15 @@
#include "telemetry/telemetry_sensors.h"
#include <stdio.h>
// libopenui defines TIMOUR as zero
#if !TIMEHOUR
#undef TIMEHOUR
#endif
#if !defined(TIMEHOUR)
#define TIMEHOUR 0x2000
#endif
#define OPTION_MENU_NO_FOOTER 0x01
#define OPTION_MENU_TITLE_BAR 0x02
#define OPTION_MENU_NO_SCROLLBAR 0x04
@@ -80,7 +80,7 @@ void TopbarImpl::paint(BitmapBuffer * dc)
{
dc->drawSolidFilledRect(0, 0, width(), height(), COLOR_THEME_SECONDARY1);
OpenTxTheme::instance()->drawTopLeftBitmap(dc);
const TimerOptions timerOptions = {.options = SHOW_TIME};
struct gtm t;
gettime(&t);
char str[10];
@@ -92,7 +92,7 @@ void TopbarImpl::paint(BitmapBuffer * dc)
#endif
//dc->drawSolidVerticalLine(DATETIME_SEPARATOR_X, 7, 31, COLOR_THEME_SECONDARY1);
dc->drawText(DATETIME_MIDDLE, DATETIME_LINE1, str, FONT(XS) | CENTERED | COLOR_THEME_PRIMARY2);
getTimerString(str, getValue(MIXSRC_TX_TIME));
getTimerString(str, getValue(MIXSRC_TX_TIME), timerOptions);
dc->drawText(DATETIME_MIDDLE, DATETIME_LINE2, str, FONT(XS) | CENTERED | COLOR_THEME_PRIMARY2);
#if defined(INTERNAL_GPS)
@@ -374,7 +374,7 @@ class Theme480: public OpenTxTheme
void drawMenuDatetime(BitmapBuffer * dc) const
{
//dc->drawSolidVerticalLine(DATETIME_SEPARATOR_X, 7, 31, COLOR_THEME_PRIMARY2);
const TimerOptions timerOptions = {.options = SHOW_TIME};
struct gtm t;
gettime(&t);
char str[10];
@@ -385,7 +385,7 @@ class Theme480: public OpenTxTheme
sprintf(str, "%d %s", t.tm_mday, STR_MONTHS[t.tm_mon]);
#endif
dc->drawText(DATETIME_MIDDLE, DATETIME_LINE1, str, FONT(XS)|COLOR_THEME_PRIMARY2|CENTERED);
getTimerString(str, getValue(MIXSRC_TX_TIME));
getTimerString(str, getValue(MIXSRC_TX_TIME), timerOptions);
dc->drawText(DATETIME_MIDDLE, DATETIME_LINE2, str, FONT(XS)|COLOR_THEME_PRIMARY2|CENTERED);
}
+2 -1
View File
@@ -391,6 +391,7 @@ class FlyskyTheme: public OpenTxTheme
{
dc->drawSolidVerticalLine(DATETIME_SEPARATOR_X, 7, 31, COLOR_THEME_PRIMARY2);
const TimerOptions timerOptions = {.options = SHOW_TIME};
struct gtm t;
gettime(&t);
char str[10];
@@ -403,7 +404,7 @@ class FlyskyTheme: public OpenTxTheme
#endif
dc->drawText(DATETIME_MIDDLE, DATETIME_LINE1, str, FONT(XS)|COLOR_THEME_PRIMARY2|CENTERED);
getTimerString(str, getValue(MIXSRC_TX_TIME));
getTimerString(str, getValue(MIXSRC_TX_TIME), timerOptions);
dc->drawText(DATETIME_MIDDLE, DATETIME_LINE2, str, FONT(XS)|COLOR_THEME_PRIMARY2|CENTERED);
}
+3 -3
View File
@@ -41,8 +41,8 @@ void TimeEdit::paint(BitmapBuffer * dc)
else
textColor = COLOR_THEME_SECONDARY1;
TimerOptions timerOptions;
timerOptions.options = (textFlags & TIMEHOUR) != 0 ? SHOW_TIME : SHOW_TIMER;
dc->drawText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP,
getTimerString(getValue(), (textFlags & TIMEHOUR) != 0),
textColor);
getTimerString(getValue(), timerOptions), textColor);
}
+9 -9
View File
@@ -20,9 +20,9 @@
*/
#include "view_statistics.h"
#include "libopenui.h"
#include "opentx.h"
#include "draw_functions.h"
StatisticsViewPageGroup::StatisticsViewPageGroup() : TabsGroup(ICON_STATS)
{
@@ -94,7 +94,7 @@ void StatisticsViewPage::build(FormWindow *window)
COLOR_THEME_PRIMARY1);
new DynamicText(
window, grid.getFieldSlot(3, 0),
[] { return getTimerString(sessionTimer, TIMEHOUR); },
[] { return getTimerString(sessionTimer); },
COLOR_THEME_PRIMARY1);
// Battery data
@@ -103,7 +103,7 @@ void StatisticsViewPage::build(FormWindow *window)
new DynamicText(
window, grid.getFieldSlot(3, 2),
[] {
return getTimerString(g_eeGeneral.globalTimer + sessionTimer, TIMEHOUR);
return getTimerString(g_eeGeneral.globalTimer + sessionTimer);
},
COLOR_THEME_PRIMARY1);
grid.nextLine();
@@ -113,7 +113,7 @@ void StatisticsViewPage::build(FormWindow *window)
COLOR_THEME_PRIMARY1);
new DynamicText(
window, grid.getFieldSlot(3, 0),
[] { return getTimerString(s_timeCumThr, TIMEHOUR); },
[] { return getTimerString(s_timeCumThr); },
COLOR_THEME_PRIMARY1);
// Throttle % data
@@ -121,7 +121,7 @@ void StatisticsViewPage::build(FormWindow *window)
COLOR_THEME_PRIMARY1);
new DynamicText(
window, grid.getFieldSlot(3, 2),
[] { return getTimerString(s_timeCum16ThrP / 16, TIMEHOUR); },
[] { return getTimerString(s_timeCum16ThrP / 16); },
COLOR_THEME_PRIMARY1);
grid.nextLine();
@@ -130,15 +130,15 @@ void StatisticsViewPage::build(FormWindow *window)
COLOR_THEME_PRIMARY1);
new DynamicText(
window, grid.getFieldSlot(3, 0),
[] { return getTimerString(timersStates[0].val, TIMEHOUR); },
[] { return getTimerString(timersStates[0].val); },
COLOR_THEME_PRIMARY1);
new DynamicText(
window, grid.getFieldSlot(3, 1),
[] { return getTimerString(timersStates[1].val, TIMEHOUR); },
[] { return getTimerString(timersStates[1].val); },
COLOR_THEME_PRIMARY1);
new DynamicText(
window, grid.getFieldSlot(3, 2),
[] { return getTimerString(timersStates[2].val, TIMEHOUR); },
[] { return getTimerString(timersStates[2].val); },
COLOR_THEME_PRIMARY1);
grid.nextLine();
-6
View File
@@ -22,12 +22,6 @@
#include "opentx.h"
#include "widgets_container_impl.h"
// libopemui defines TIMOUR as zero
#ifdef TIMEHOUR
#undef TIMEHOUR
#define TIMEHOUR 0x2000
#endif
class TimerWidget : public Widget
{
public:
+2 -2
View File
@@ -101,11 +101,11 @@ class ValueWidget: public Widget
if (persistentData->options[2].value.boolValue) {
drawSource(dc, xLabel + 1, yLabel + 1, field, COLOR2FLAGS(BLACK));
drawTimer(dc, xValue + 1, yValue + 1, tme,
attrValue | FONT(STD) | COLOR2FLAGS(BLACK));
attrValue | FONT(STD) | COLOR2FLAGS(BLACK) | TIMEHOUR);
}
drawSource(dc, xLabel, yLabel, field, attrLabel | color);
drawTimer(dc, xValue, yValue, tme,
attrValue | FONT(STD) | color);
attrValue | FONT(STD) | color | TIMEHOUR);
} else {
if (field >= MIXSRC_FIRST_TELEM) {
@@ -23,6 +23,7 @@
#include "widget.h"
#include "widgets_container.h"
#include "draw_functions.h"
template<int N, int O>
class WidgetsContainerImpl: public WidgetsContainer