Massive cleaning (#5538)
[opentx.git] / radio / src / gui / 480x272 / theme.cpp
blob260ecefe48018738f17905cc6400bcc5c59bf6ae
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "opentx.h"
23 const BitmapBuffer * Theme::asterisk = NULL;
24 const BitmapBuffer * Theme::question = NULL;
25 const BitmapBuffer * Theme::busy = NULL;
27 std::list<Theme *> & getRegisteredThemes()
29 static std::list<Theme *> themes;
30 return themes;
33 void registerTheme(Theme * theme)
35 TRACE("register theme %s", theme->getName());
36 getRegisteredThemes().push_back(theme);
39 void Theme::init() const
41 memset(&g_eeGeneral.themeData, 0, sizeof(Theme::PersistentData));
42 if (options) {
43 int i = 0;
44 for (const ZoneOption * option = options; option->name; option++, i++) {
45 // TODO compiler bug? The CPU freezes ... g_eeGeneral.themeData.options[i] = &option->deflt;
46 memcpy(&g_eeGeneral.themeData.options[i], &option->deflt, sizeof(ZoneOptionValue));
51 void Theme::load() const
53 if (!asterisk) asterisk = BitmapBuffer::load(getThemePath("asterisk.bmp"));
54 if (!question) question = BitmapBuffer::load(getThemePath("question.bmp"));
55 if (!busy) busy = BitmapBuffer::load(getThemePath("busy.bmp"));
58 ZoneOptionValue * Theme::getOptionValue(unsigned int index) const
60 return &g_eeGeneral.themeData.options[index];
63 const char * Theme::getFilePath(const char * filename) const
65 static char path[_MAX_LFN+1] = THEMES_PATH "/";
66 strcpy(path + sizeof(THEMES_PATH), getName());
67 int len = sizeof(THEMES_PATH) + strlen(path + sizeof(THEMES_PATH));
68 path[len] = '/';
69 strcpy(path+len+1, filename);
70 return path;
73 void Theme::drawThumb(uint16_t x, uint16_t y, uint32_t flags)
75 #define THUMB_WIDTH 51
76 #define THUMB_HEIGHT 31
77 if (!thumb) {
78 thumb = BitmapBuffer::load(getFilePath("thumb.bmp"));
80 lcd->drawBitmap(x, y, thumb);
81 if (flags == LINE_COLOR) {
82 lcdDrawFilledRect(x, y, THUMB_WIDTH, THUMB_HEIGHT, SOLID, OVERLAY_COLOR | OPACITY(10));
86 void Theme::drawBackground() const
88 lcdDrawSolidFilledRect(0, 0, LCD_W, LCD_H, TEXT_BGCOLOR);
91 void Theme::drawMessageBox(const char * title, const char * text, const char * action, uint32_t type) const
93 //if (flags & MESSAGEBOX_TYPE_ALERT) {
94 drawBackground();
95 lcdDrawFilledRect(0, POPUP_Y, LCD_W, POPUP_H, SOLID, TEXT_INVERTED_COLOR | OPACITY(8));
96 //}
98 if (type == WARNING_TYPE_ALERT || type == WARNING_TYPE_ASTERISK)
99 lcd->drawBitmap(POPUP_X-80, POPUP_Y+12, asterisk);
100 else if (type == WARNING_TYPE_INFO)
101 lcd->drawBitmap(POPUP_X-80, POPUP_Y+12, busy);
102 else
103 lcd->drawBitmap(POPUP_X-80, POPUP_Y+12, question);
105 if (type == WARNING_TYPE_ALERT) {
106 #if defined(TRANSLATIONS_FR) || defined(TRANSLATIONS_IT) || defined(TRANSLATIONS_CZ)
107 lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y, STR_WARNING, ALARM_COLOR|DBLSIZE);
108 lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y+28, title, ALARM_COLOR|DBLSIZE);
109 #else
110 lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y, title, ALARM_COLOR|DBLSIZE);
111 lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y+28, STR_WARNING, ALARM_COLOR|DBLSIZE);
112 #endif
114 else if (title) {
115 lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y, title, ALARM_COLOR|DBLSIZE);
118 if (text) {
119 lcdDrawText(WARNING_LINE_X, WARNING_INFOLINE_Y, text);
122 if (action) {
123 lcdDrawText(WARNING_LINE_X, WARNING_INFOLINE_Y+24, action);
127 Theme * getTheme(const char * name)
129 std::list<Theme *>::const_iterator it = getRegisteredThemes().cbegin();
130 for (; it != getRegisteredThemes().cend(); ++it) {
131 if (!strcmp(name, (*it)->getName())) {
132 return (*it);
135 return NULL;
138 void loadTheme(Theme * new_theme)
140 TRACE("load theme %s", new_theme->getName());
141 theme = new_theme;
142 theme->load();
145 void loadTheme()
147 char name[sizeof(g_eeGeneral.themeName)+1];
148 memset(name, 0, sizeof(name));
149 strncpy(name, g_eeGeneral.themeName, sizeof(g_eeGeneral.themeName));
150 Theme * new_theme = getTheme(name);
151 if (new_theme) {
152 loadTheme(new_theme);
154 else {
155 theme->load();