From 9b138afacc6156e434c2a4f5f287a6239b392002 Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Sat, 16 Jan 2010 07:11:17 +0000 Subject: [PATCH] Create views when the theme is loaded --- bind_keys_menu.cpp | 13 ++----------- disc_menu.cpp | 16 +++------------- game_info.cpp | 7 +++++-- game_info.hh | 7 ++++++- gui.cpp | 40 ++++++++++++++++++++++++++-------------- help_box.hh | 1 + main_menu.cpp | 16 +++++----------- menu.cpp | 12 +++++------- network_menu.cpp | 13 ++----------- options_menu.cpp | 13 ++----------- theme_menu.cpp | 12 +----------- 11 files changed, 58 insertions(+), 92 deletions(-) diff --git a/bind_keys_menu.cpp b/bind_keys_menu.cpp index 2dc63f2..497bb9c 100644 --- a/bind_keys_menu.cpp +++ b/bind_keys_menu.cpp @@ -414,8 +414,8 @@ class BindKeysView : public GuiView public: BindKeysView() : GuiView() { - this->help = new HelpBox(NULL, NULL); - this->menu = new BindKeysMenu(NULL, this->help); + this->help = new HelpBox(Gui::gui->small_font, NULL); + this->menu = new BindKeysMenu(Gui::gui->small_font, this->help); } ~BindKeysView() @@ -424,15 +424,6 @@ public: delete this->menu; } - void updateTheme() - { - this->menu->setFont(Gui::gui->small_font); - this->help->setFont(Gui::gui->small_font); - this->menu->setSelectedBackground(Gui::gui->bg_left, Gui::gui->bg_middle, - Gui::gui->bg_right, Gui::gui->bg_submenu_left, - Gui::gui->bg_submenu_middle, Gui::gui->bg_submenu_right); - } - void viewPushCallback() { this->menu->updateHelpMessages(); diff --git a/disc_menu.cpp b/disc_menu.cpp index ade4423..f05231e 100644 --- a/disc_menu.cpp +++ b/disc_menu.cpp @@ -22,8 +22,6 @@ public: void setDirectory(const char *path); /* Inherited */ - void updateTheme(); - void runLogic(); void draw(SDL_Surface *where); @@ -79,6 +77,7 @@ public: { this->gi = NULL; memset(this->gi_messages, 0, sizeof(this->gi_messages)); + this->setSelectedBackground(NULL, NULL, NULL, NULL, NULL, NULL); } void loadGameInfo(const char *what) @@ -150,8 +149,8 @@ private: DiscView::DiscView() : GuiView() { - this->menu = new DiscMenu(NULL); - this->gameInfo = new GameInfoBox(NULL); + this->menu = new DiscMenu(Gui::gui->default_font); + this->gameInfo = new GameInfoBox(Gui::gui->default_font); } DiscView::~DiscView() @@ -170,15 +169,6 @@ void DiscView::setDirectory(const char *path) this->menu->setDirectory(path); } -void DiscView::updateTheme() -{ - this->gameInfo->setFont(Gui::gui->small_font); - this->menu->setFont(Gui::gui->default_font); - this->menu->setSelectedBackground(Gui::gui->bg_left, Gui::gui->bg_middle, - Gui::gui->bg_right, Gui::gui->bg_submenu_left, - Gui::gui->bg_submenu_middle, Gui::gui->bg_submenu_right); -} - void DiscView::runLogic() { this->menu->runLogic(); diff --git a/game_info.cpp b/game_info.cpp index 85c9f7f..d98f00e 100644 --- a/game_info.cpp +++ b/game_info.cpp @@ -7,10 +7,13 @@ #include "utils.hh" #define VERSION_BASE (0x1978) -#define VERSION_MAGIC (VERSION_BASE + 0) +#define VERSION_MAGIC (VERSION_BASE + 1) -GameInfo::GameInfo(const char *name, const char *author, SDL_Surface *image) +GameInfo::GameInfo(const char *filename, + const char *name, const char *author, + SDL_Surface *image) { + this->filename = filename; this->name = name; this->author = author; this->screenshot = image; diff --git a/game_info.hh b/game_info.hh index ce1dd0c..d55156d 100644 --- a/game_info.hh +++ b/game_info.hh @@ -10,13 +10,17 @@ struct game_info uint16_t author_off; uint16_t name_off; uint16_t screenshot_off; /* In PNG format */ + uint16_t filename_off; + uint16_t flags; uint8_t data[]; /* 4-byte aligned */ }; class GameInfo { public: - GameInfo(const char *name = NULL, const char *author = NULL, SDL_Surface *image = NULL); + GameInfo(const char *filename = NULL, const char *name = NULL, + const char *author = NULL, + SDL_Surface *image = NULL); ~GameInfo(); @@ -33,6 +37,7 @@ public: /* Should perhaps be protected but I trust you - just be careful! */ const char *name; const char *author; + const char *filename; SDL_Surface *screenshot; }; diff --git a/gui.cpp b/gui.cpp index adad101..0d885d1 100644 --- a/gui.cpp +++ b/gui.cpp @@ -85,14 +85,12 @@ Gui::Gui() this->dlg = NULL; this->kbd = NULL; - /* Create the views */ - this->mv = new MainView(); - this->dv = new DiscView(); - this->ov = new OptionsView(); - this->nv = new NetworkView(); - this->tv = new ThemeView(); - this->bkv = new BindKeysView(); - this->pushView(mv); + this->mv = NULL; + this->dv = NULL; + this->ov = NULL; + this->nv = NULL; + this->tv = NULL; + this->bkv = NULL; } bool Gui::setTheme(const char *path) @@ -150,12 +148,26 @@ bool Gui::setTheme(const char *path) return false; } - this->mv->updateTheme(); - this->dv->updateTheme(); - this->ov->updateTheme(); - this->nv->updateTheme(); - this->tv->updateTheme(); - this->bkv->updateTheme(); + /* Create the views */ + if (!this->mv) + { + this->mv = new MainView(); + this->dv = new DiscView(); + this->ov = new OptionsView(); + this->nv = new NetworkView(); + this->tv = new ThemeView(); + this->bkv = new BindKeysView(); + this->pushView(mv); + } + else + { + this->mv->updateTheme(); + this->dv->updateTheme(); + this->ov->updateTheme(); + this->nv->updateTheme(); + this->tv->updateTheme(); + this->bkv->updateTheme(); + } VirtualKeyboard::kbd->updateTheme(); diff --git a/help_box.hh b/help_box.hh index 56ca3ad..50275e7 100644 --- a/help_box.hh +++ b/help_box.hh @@ -9,6 +9,7 @@ public: HelpBox(Font *font, const char ***all_messages) : Menu(font) { this->setHelpMessages(all_messages); + this->setSelectedBackground(NULL, NULL, NULL, NULL, NULL, NULL); } void setHelpMessages(const char ***all_messages) diff --git a/main_menu.cpp b/main_menu.cpp index 9eeabab..d15a43b 100644 --- a/main_menu.cpp +++ b/main_menu.cpp @@ -122,8 +122,11 @@ class MainView : public GuiView public: MainView() : GuiView() { - this->help = new HelpBox(NULL, main_menu_help); - this->menu = new MainMenu(NULL, this->help); + panic_if(!Gui::gui->default_font, + "Theme does not seem correctly loaded\n"); + + this->help = new HelpBox(Gui::gui->small_font, main_menu_help); + this->menu = new MainMenu(Gui::gui->default_font, this->help); } ~MainView() @@ -132,15 +135,6 @@ public: delete this->menu; } - void updateTheme() - { - this->menu->setFont(Gui::gui->default_font); - this->help->setFont(Gui::gui->small_font); - this->menu->setSelectedBackground(Gui::gui->bg_left, Gui::gui->bg_middle, - Gui::gui->bg_right, Gui::gui->bg_submenu_left, - Gui::gui->bg_submenu_middle, Gui::gui->bg_submenu_right); - } - void runLogic() { this->menu->runLogic(); diff --git a/menu.cpp b/menu.cpp index b75f4aa..19c9de6 100644 --- a/menu.cpp +++ b/menu.cpp @@ -15,6 +15,7 @@ #include "menu.hh" #include "font.hh" #include "utils.hh" +#include "gui.hh" #define IS_SUBMENU(p_msg) ( (p_msg)[0] == '^' ) #define IS_EMPTY(p_msg) ( (p_msg)[0] == '#' ) @@ -344,13 +345,6 @@ Menu::Menu(Font *font) : Widget() this->setTextColor((SDL_Color){0xff,0xff,0xff,0}); this->font = font; - this->text_bg_left = NULL; - this->text_bg_middle = NULL; - this->text_bg_right = NULL; - this->submenu_bg_left = NULL; - this->submenu_bg_middle = NULL; - this->submenu_bg_right = NULL; - this->pp_msgs = NULL; this->n_entries = 0; this->p_submenus = NULL; @@ -359,6 +353,10 @@ Menu::Menu(Font *font) : Widget() this->cur_sel = 0; this->mouse_x = -1; this->mouse_y = -1; + + this->setSelectedBackground(Gui::gui->bg_left, Gui::gui->bg_middle, + Gui::gui->bg_right, Gui::gui->bg_submenu_left, + Gui::gui->bg_submenu_middle, Gui::gui->bg_submenu_right); } void Menu::setTextColor(SDL_Color clr) diff --git a/network_menu.cpp b/network_menu.cpp index b93c821..3836a4e 100644 --- a/network_menu.cpp +++ b/network_menu.cpp @@ -123,8 +123,8 @@ class NetworkView : public GuiView public: NetworkView() : GuiView() { - this->help = new HelpBox(NULL, network_menu_help); - this->menu = new NetworkMenu(NULL, this->help); + this->help = new HelpBox(Gui::gui->small_font, network_menu_help); + this->menu = new NetworkMenu(Gui::gui->default_font, this->help); } ~NetworkView() @@ -133,15 +133,6 @@ public: delete this->menu; } - void updateTheme() - { - this->menu->setFont(Gui::gui->default_font); - this->help->setFont(Gui::gui->small_font); - this->menu->setSelectedBackground(Gui::gui->bg_left, Gui::gui->bg_middle, - Gui::gui->bg_right, Gui::gui->bg_submenu_left, - Gui::gui->bg_submenu_middle, Gui::gui->bg_submenu_right); - } - void runLogic() { this->menu->runLogic(); diff --git a/options_menu.cpp b/options_menu.cpp index 664e88b..8d30cee 100644 --- a/options_menu.cpp +++ b/options_menu.cpp @@ -96,8 +96,8 @@ class OptionsView : public GuiView public: OptionsView() : GuiView() { - this->help = new HelpBox(NULL, options_menu_help); - this->menu = new OptionsMenu(NULL, this->help); + this->help = new HelpBox(Gui::gui->small_font, options_menu_help); + this->menu = new OptionsMenu(Gui::gui->default_font, this->help); } ~OptionsView() @@ -106,15 +106,6 @@ public: delete this->menu; } - void updateTheme() - { - this->menu->setFont(Gui::gui->default_font); - this->help->setFont(Gui::gui->small_font); - this->menu->setSelectedBackground(Gui::gui->bg_left, Gui::gui->bg_middle, - Gui::gui->bg_right, Gui::gui->bg_submenu_left, - Gui::gui->bg_submenu_middle, Gui::gui->bg_submenu_right); - } - void viewPushCallback() { this->menu->updateSubmenus(); diff --git a/theme_menu.cpp b/theme_menu.cpp index 1461be8..028c520 100644 --- a/theme_menu.cpp +++ b/theme_menu.cpp @@ -15,8 +15,6 @@ public: void setDirectory(const char *path); /* Inherited */ - void updateTheme(); - void runLogic(); void draw(SDL_Surface *where); @@ -63,7 +61,7 @@ public: ThemeView::ThemeView() : GuiView() { - this->menu = new ThemeMenu(NULL); + this->menu = new ThemeMenu(Gui::gui->default_font); } ThemeView::~ThemeView() @@ -76,14 +74,6 @@ void ThemeView::setDirectory(const char *path) this->menu->setDirectory(path); } -void ThemeView::updateTheme() -{ - this->menu->setFont(Gui::gui->default_font); - this->menu->setSelectedBackground(Gui::gui->bg_left, Gui::gui->bg_middle, - Gui::gui->bg_right, Gui::gui->bg_submenu_left, - Gui::gui->bg_submenu_middle, Gui::gui->bg_submenu_right); -} - void ThemeView::runLogic() { this->menu->runLogic();