[Horus] Better handling of theme options

This commit is contained in:
Bertrand Songis
2016-03-16 20:47:56 +01:00
parent eb477f2953
commit 5a7c9311de
7 changed files with 52 additions and 23 deletions
+12 -3
View File
@@ -25,9 +25,9 @@
#undef OPAQUE #undef OPAQUE
#undef RGB #undef RGB
#define TO4BITS(x) ((x) >> 4) #define TO4BITS(x) (uint32_t(limit<int>(0, x, 255)) >> 4)
#define TO5BITS(x) ((x) >> 3) #define TO5BITS(x) (uint32_t(limit<int>(0, x, 255)) >> 3)
#define TO6BITS(x) ((x) >> 2) #define TO6BITS(x) (uint32_t(limit<int>(0, x, 255)) >> 2)
#define RGB(r, g, b) ((TO5BITS(r) << 11) + (TO6BITS(g) << 5) + (TO5BITS(b) << 0)) #define RGB(r, g, b) ((TO5BITS(r) << 11) + (TO6BITS(g) << 5) + (TO5BITS(b) << 0))
#define ARGB(a, r, g, b) ((TO4BITS(a) << 12) + (TO4BITS(r) << 8) + (TO4BITS(g) << 4) + (TO4BITS(b) << 0)) #define ARGB(a, r, g, b) ((TO4BITS(a) << 12) + (TO4BITS(r) << 8) + (TO4BITS(g) << 4) + (TO4BITS(b) << 0))
#define WHITE RGB(0xFF, 0xFF, 0xFF) #define WHITE RGB(0xFF, 0xFF, 0xFF)
@@ -115,4 +115,13 @@ extern uint16_t lcdColorTable[LCD_COLOR_COUNT];
#define COLOR_JOIN(r, g, b) \ #define COLOR_JOIN(r, g, b) \
(((r) << 11) + ((g) << 5) + (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_ #endif // _COLORS_H_
+4
View File
@@ -44,6 +44,10 @@ class Layout: public WidgetsContainer<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS>
return factory; return factory;
} }
virtual void update()
{
}
protected: protected:
const LayoutFactory * factory; const LayoutFactory * factory;
}; };
+12 -4
View File
@@ -67,7 +67,7 @@ int getZoneOptionColumns(const ZoneOption * option)
} }
} }
void editZoneOption(coord_t y, const ZoneOption * option, ZoneOptionValue * value, LcdFlags attr, uint32_t i_flags, evt_t event) bool editZoneOption(coord_t y, const ZoneOption * option, ZoneOptionValue * value, LcdFlags attr, uint32_t i_flags, evt_t event)
{ {
lcdDrawText(MENUS_MARGIN_LEFT, y, option->name); lcdDrawText(MENUS_MARGIN_LEFT, y, option->name);
@@ -150,6 +150,8 @@ void editZoneOption(coord_t y, const ZoneOption * option, ZoneOptionValue * valu
value->unsignedValue = COLOR_JOIN(r, g, b); value->unsignedValue = COLOR_JOIN(r, g, b);
} }
} }
return (attr && checkIncDec_Ret);
} }
int getOptionsCount(const ZoneOption * options) int getOptionsCount(const ZoneOption * options)
@@ -186,7 +188,9 @@ bool menuSettings(const char * title, const T * object, uint32_t i_flags, evt_t
if (k < linesCount) { if (k < linesCount) {
const ZoneOption * option = &options[k]; const ZoneOption * option = &options[k];
ZoneOptionValue * value = object->getOptionValue(k); ZoneOptionValue * value = object->getOptionValue(k);
editZoneOption(y, option, value, attr, i_flags, event); if (editZoneOption(y, option, value, attr, i_flags, event)) {
object->update();
}
} }
} }
@@ -446,7 +450,9 @@ bool menuScreensTheme(evt_t event)
if (index < optionsCount) { if (index < optionsCount) {
const ZoneOption * option = &options[index]; const ZoneOption * option = &options[index];
ZoneOptionValue * value = theme->getOptionValue(index); ZoneOptionValue * value = theme->getOptionValue(index);
editZoneOption(y, option, value, attr, EE_GENERAL, event); if (editZoneOption(y, option, value, attr, EE_GENERAL, event)) {
theme->update();
}
} }
else if (index == optionsCount) { else if (index == optionsCount) {
lcdDrawText(MENUS_MARGIN_LEFT, y, "Top bar"); lcdDrawText(MENUS_MARGIN_LEFT, y, "Top bar");
@@ -531,7 +537,9 @@ bool menuScreenSetup(int index, evt_t event)
if (index < optionsCount) { if (index < optionsCount) {
const ZoneOption * option = &options[index]; const ZoneOption * option = &options[index];
ZoneOptionValue * value = currentScreen->getOptionValue(index); ZoneOptionValue * value = currentScreen->getOptionValue(index);
editZoneOption(y, option, value, attr, EE_MODEL, event); if (editZoneOption(y, option, value, attr, EE_MODEL, event)) {
currentScreen->update();
}
} }
break; break;
} }
-1
View File
@@ -155,7 +155,6 @@ void loadTheme()
loadTheme(new_theme); loadTheme(new_theme);
} }
else { else {
theme->init();
theme->load(); theme->load();
} }
} }
+4
View File
@@ -59,6 +59,10 @@ class Theme
void init() const; void init() const;
virtual void update() const
{
}
ZoneOptionValue * getOptionValue(unsigned int index) const; ZoneOptionValue * getOptionValue(unsigned int index) const;
virtual void load() const; virtual void load() const;
+16 -15
View File
@@ -74,6 +74,22 @@ class DefaultTheme: public Theme
Theme::load(); Theme::load();
if (!backgroundBitmap) backgroundBitmap = BitmapBuffer::load(getThemePath("mainbg.bmp")); if (!backgroundBitmap) backgroundBitmap = BitmapBuffer::load(getThemePath("mainbg.bmp"));
if (!aboutBackgroundBitmap) aboutBackgroundBitmap = BitmapBuffer::load(getThemePath("aboutbg.bmp")); if (!aboutBackgroundBitmap) aboutBackgroundBitmap = BitmapBuffer::load(getThemePath("aboutbg.bmp"));
update();
}
virtual void update() const
{
uint32_t color = g_eeGeneral.themeData.options[1].unsignedValue;
lcdColorTable[TEXT_INVERTED_BGCOLOR_INDEX] = color;
lcdColorTable[SCROLLBOX_COLOR_INDEX] = color;
lcdColorTable[CURVE_COLOR_INDEX] = color;
lcdColorTable[CURVE_CURSOR_COLOR_INDEX] = color;
lcdColorTable[TITLE_BGCOLOR_INDEX] = color;
lcdColorTable[TRIM_BGCOLOR_INDEX] = color;
lcdColorTable[MAINVIEW_GRAPHICS_COLOR_INDEX] = color;
lcdColorTable[HEADER_BGCOLOR_INDEX] = RGB(GET_RED(color)-69, GET_GREEN(color)-32, GET_BLUE(color)-24);
lcdColorTable[HEADER_ICON_BGCOLOR_INDEX] = color;
lcdColorTable[HEADER_CURRENT_BGCOLOR_INDEX] = color;
} }
virtual void drawBackground() const virtual void drawBackground() const
@@ -94,21 +110,6 @@ class DefaultTheme: public Theme
virtual void drawTopbarBackground(const uint8_t * icon) const virtual void drawTopbarBackground(const uint8_t * icon) const
{ {
// TODO should be in updateOptions
if (lcdColorTable[TEXT_INVERTED_BGCOLOR_INDEX] != g_eeGeneral.themeData.options[1].unsignedValue) {
lcdColorTable[TEXT_INVERTED_BGCOLOR_INDEX] = g_eeGeneral.themeData.options[1].unsignedValue;
lcdColorTable[SCROLLBOX_COLOR_INDEX] = g_eeGeneral.themeData.options[1].unsignedValue;
lcdColorTable[CURVE_COLOR_INDEX] = g_eeGeneral.themeData.options[1].unsignedValue;
lcdColorTable[CURVE_CURSOR_COLOR_INDEX] = g_eeGeneral.themeData.options[1].unsignedValue;
lcdColorTable[TITLE_BGCOLOR_INDEX] = g_eeGeneral.themeData.options[1].unsignedValue;
lcdColorTable[TRIM_BGCOLOR_INDEX] = g_eeGeneral.themeData.options[1].unsignedValue;
lcdColorTable[MAINVIEW_GRAPHICS_COLOR_INDEX] = g_eeGeneral.themeData.options[1].unsignedValue;
lcdColorTable[HEADER_ICON_BGCOLOR_INDEX] = g_eeGeneral.themeData.options[1].unsignedValue;
lcdColorTable[HEADER_CURRENT_BGCOLOR_INDEX] = g_eeGeneral.themeData.options[1].unsignedValue;
// TODO quick and really dirty, create a new macro for that ...
lcdColorTable[HEADER_BGCOLOR_INDEX] = g_eeGeneral.themeData.options[1].unsignedValue - RGB(69, 32, 30);
}
lcdDrawSolidFilledRect(0, 0, LCD_W, MENU_HEADER_HEIGHT, HEADER_BGCOLOR); lcdDrawSolidFilledRect(0, 0, LCD_W, MENU_HEADER_HEIGHT, HEADER_BGCOLOR);
lcdDrawBitmapPattern(0, 0, LBM_TOPMENU_POLYGON, TITLE_BGCOLOR); lcdDrawBitmapPattern(0, 0, LBM_TOPMENU_POLYGON, TITLE_BGCOLOR);
+4
View File
@@ -90,6 +90,10 @@ class Widget
{ {
} }
virtual void update() const
{
}
inline const WidgetFactory * getFactory() const inline const WidgetFactory * getFactory() const
{ {
return factory; return factory;