diff --git a/gui.cpp b/gui.cpp index 86163f3..8a5d2e8 100644 --- a/gui.cpp +++ b/gui.cpp @@ -15,13 +15,15 @@ class Gui; class MainMenu; class MainView; +#define THEME_ROOT_PATH "themes" + static const char *get_theme_path(const char *dir, const char *what) { static char buf[255]; memset(buf, 0, sizeof(buf)); - snprintf(buf, 254, "%s/%s", - dir, what); + snprintf(buf, 254, "%s/%s/%s", + THEME_ROOT_PATH, dir, what); return buf; } @@ -202,3 +204,16 @@ Font *Gui::loadThemeFont(const char *dir, const char *what, int size) return new Font_TTF(fnt, 255,255,255); } + + +/* The singleton/factory stuff */ +Gui *Gui::gui; +void Gui::init() +{ + Gui *p = new Gui(); + + /* Set the default theme */ + panic_if(!p->setTheme("default"), + "Setting default theme failed\n"); + Gui::gui = p; +} diff --git a/gui.hh b/gui.hh index 4771d3b..404e975 100644 --- a/gui.hh +++ b/gui.hh @@ -83,6 +83,11 @@ public: GuiView **views; int n_views; + + + /* Singleton */ + static void init(); + static Gui *gui; }; #endif /* GUI_HH */ diff --git a/main.cpp b/main.cpp index 511a8f1..fa50691 100644 --- a/main.cpp +++ b/main.cpp @@ -5,7 +5,6 @@ #include "utils.hh" SDL_Surface *screen; -static Gui *g_gui; static void run(void) { @@ -17,10 +16,10 @@ static void run(void) if (ev.type == SDL_QUIT) exit(1); - g_gui->pushEvent(&ev); + Gui::gui->pushEvent(&ev); } - g_gui->runLogic(); - g_gui->draw(screen); + Gui::gui->runLogic(); + Gui::gui->draw(screen); SDL_Flip(screen); SDL_Delay(50); @@ -34,10 +33,8 @@ static void init(void) panic_if(!screen, "Cannot initialize video: %s\n", SDL_GetError()); TTF_Init(); - g_gui = new Gui(); - panic_if(!g_gui->setTheme("themes/default"), - "Setting theme failed\n"); - g_gui->activate(); + Gui::init(); + Gui::gui->activate(); } int main(int argc, char *argv[])