1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-26 11:15:19 +02:00

Improved conversion from color enum to string and vice versa.

The stringToColor() and colorToString() methods were changed into file-scope functions, so they can be inlined by the compiler.
The colorNames array is now used for lookups in both directions, removing duplication of the color names.
The missing "selectionBg" entry was added to the colorNames array.
This commit is contained in:
Maarten ter Huurne 2010-07-28 16:15:52 +02:00
parent c91a190f28
commit b54a595e26
2 changed files with 26 additions and 39 deletions

View File

@ -82,6 +82,31 @@ const char *CARD_ROOT = "/card";
using namespace std; using namespace std;
using namespace fastdelegate; using namespace fastdelegate;
// Note: Keep this in sync with the enum!
static const char *colorNames[NUM_COLORS] = {
"topBarBg",
"bottomBarBg",
"selectionBg",
"messageBoxBg",
"messageBoxBorder",
"messageBoxSelection",
};
static enum color stringToColor(const string &name)
{
for (unsigned int i = 0; i < NUM_COLORS; i++) {
if (strcmp(colorNames[i], name.c_str()) == 0) {
return (enum color)i;
}
}
return (enum color)-1;
}
static const char *colorToString(enum color c)
{
return colorNames[c];
}
int main(int /*argc*/, char */*argv*/[]) { int main(int /*argc*/, char */*argv*/[]) {
cout << "----" << endl; cout << "----" << endl;
cout << "GMenu2X starting: If you read this message in the logs, check http://gmenu2x.sourceforge.net/page/Troubleshooting for a solution" << endl; cout << "GMenu2X starting: If you read this message in the logs, check http://gmenu2x.sourceforge.net/page/Troubleshooting for a solution" << endl;
@ -1096,42 +1121,6 @@ void GMenu2X::skinMenu() {
} }
} }
enum color GMenu2X::stringToColor(const string &name)
{
if (name == "topBarBg")
return COLOR_TOP_BAR_BG;
else if (name == "bottomBarBg")
return COLOR_BOTTOM_BAR_BG;
else if (name == "messageBoxBg")
return COLOR_MESSAGE_BOX_BG;
else if (name == "messageBoxBorder")
return COLOR_MESSAGE_BOX_BORDER;
else if (name == "messageBoxSelection")
return COLOR_MESSAGE_BOX_SELECTION;
else
return (enum color)-1;
}
const string &GMenu2X::colorToString(enum color c)
{
static const std::string colorNames[NUM_COLORS + 1] = {
"topBarBg",
"bottomBarBg",
"messageBoxBg",
"messageBoxBorder",
"messageBoxSelection",
"unkown",
};
if (c < NUM_COLORS)
return colorNames[c];
else
return colorNames[NUM_COLORS];
}
void GMenu2X::toggleTvOut() { void GMenu2X::toggleTvOut() {
#ifdef TARGET_GP2X #ifdef TARGET_GP2X
/* if (cx25874!=0) /* if (cx25874!=0)

View File

@ -52,6 +52,7 @@ extern const char *CARD_ROOT;
extern void jz_cpuspeed(unsigned clockspeed); extern void jz_cpuspeed(unsigned clockspeed);
// Note: Keep this in sync with colorNames!
enum color { enum color {
COLOR_TOP_BAR_BG, COLOR_TOP_BAR_BG,
COLOR_BOTTOM_BAR_BG, COLOR_BOTTOM_BAR_BG,
@ -144,9 +145,6 @@ private:
void gp2x_deinit(); void gp2x_deinit();
void toggleTvOut(); void toggleTvOut();
enum color stringToColor(const string &name);
const string &colorToString(enum color);
public: public:
GMenu2X(); GMenu2X();
~GMenu2X(); ~GMenu2X();