From aad20592ec39c04f72c61819371ac87dc0235636 Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Mon, 28 Dec 2009 08:46:18 +0000 Subject: [PATCH] Simplifiy the implementation of some things (no parent pointer, all resources in the Gui singleton) --- disc_menu.cpp | 8 ++++---- file_browser.hh | 4 +--- main_menu.cpp | 36 +++++++++++------------------------- 3 files changed, 16 insertions(+), 32 deletions(-) diff --git a/disc_menu.cpp b/disc_menu.cpp index c7d6b85..1e863be 100644 --- a/disc_menu.cpp +++ b/disc_menu.cpp @@ -42,8 +42,8 @@ class DiscMenu : public FileBrowser, TimeoutHandler friend class DiscView; public: - DiscMenu(Font *font, GuiView *parent) : - FileBrowser(game_exts, font, parent), TimeoutHandler() + DiscMenu(Font *font) : + FileBrowser(game_exts, font), TimeoutHandler() { } @@ -66,7 +66,7 @@ public: { printf("Hovering timed out over %s\n", this->pp_msgs[this->cur_sel]); - ((DiscView*)this->parent)->loadGameInfo(this->pp_msgs[this->cur_sel]); + Gui::gui->dv->loadGameInfo(this->pp_msgs[this->cur_sel]); } virtual void escapeCallback(int which) @@ -154,7 +154,7 @@ private: DiscView::DiscView() : GuiView() { - this->menu = new DiscMenu(NULL, this); + this->menu = new DiscMenu(NULL); this->gameInfo = new GameInfoBox(NULL); this->bg = NULL; diff --git a/file_browser.hh b/file_browser.hh index 8bc0e3d..262ff80 100644 --- a/file_browser.hh +++ b/file_browser.hh @@ -7,9 +7,8 @@ class FileBrowser : public Menu { public: - FileBrowser(const char **exts, Font *font, GuiView *parent) : Menu(font) + FileBrowser(const char **exts, Font *font) : Menu(font) { - this->parent = parent; this->path = NULL; this->exts = exts; @@ -50,7 +49,6 @@ protected: const char *path; const char **file_list; const char **exts; - GuiView *parent; }; #endif /* __FILE_BROWSER_HH__ */ diff --git a/main_menu.cpp b/main_menu.cpp index 5613d09..71f361b 100644 --- a/main_menu.cpp +++ b/main_menu.cpp @@ -37,9 +37,8 @@ class MainMenu : public Menu }; public: - MainMenu(Font *font, HelpBox *help, GuiView *parent) : Menu(font) + MainMenu(Font *font, HelpBox *help) : Menu(font) { - this->parent = parent; this->help = help; /* The dialogue box is only present when needed */ this->dialogue = NULL; @@ -113,7 +112,6 @@ public: private: DialogueBox *dialogue; - GuiView *parent; HelpBox *help; }; @@ -124,12 +122,8 @@ public: MainView() : GuiView() { this->help = new HelpBox(NULL, main_menu_help); - this->menu = new MainMenu(NULL, this->help, this); + this->menu = new MainMenu(NULL, this->help); this->menu->setText(main_menu_messages); - this->bg = NULL; - this->infobox = NULL; - this->textbox = NULL; - this->dialogue_bg = NULL; } ~MainView() @@ -140,11 +134,6 @@ public: void updateTheme() { - this->bg = Gui::gui->main_menu_bg; - this->infobox = Gui::gui->infobox; - this->textbox = Gui::gui->textbox; - this->dialogue_bg = Gui::gui->dialogue_bg; - 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, @@ -168,33 +157,30 @@ public: /* Blit the backgrounds */ dst = (SDL_Rect){20,45,300,400}; - SDL_BlitSurface(this->bg, NULL, where, &dst); + SDL_BlitSurface(Gui::gui->main_menu_bg, NULL, where, &dst); dst = (SDL_Rect){350,13,0,0}; - SDL_BlitSurface(this->infobox, NULL, where, &dst); + SDL_BlitSurface(Gui::gui->infobox, NULL, where, &dst); dst = (SDL_Rect){350,242,0,0}; - SDL_BlitSurface(this->textbox, NULL, where, &dst); + SDL_BlitSurface(Gui::gui->textbox, NULL, where, &dst); this->menu->draw(where, 50, 70, 300, 400); this->help->draw(where, 354, 24, 264, 210); if (this->menu->dialogue) { - int d_x = where->w / 2 - this->dialogue_bg->w / 2; - int d_y = where->h / 2 - this->dialogue_bg->h / 2; + int d_x = where->w / 2 - Gui::gui->dialogue_bg->w / 2; + int d_y = where->h / 2 - Gui::gui->dialogue_bg->h / 2; - dst = (SDL_Rect){d_x, d_y, this->dialogue_bg->w, this->dialogue_bg->h}; - SDL_BlitSurface(this->dialogue_bg, NULL, where, &dst); + dst = (SDL_Rect){d_x, d_y, + Gui::gui->dialogue_bg->w, Gui::gui->dialogue_bg->h}; + SDL_BlitSurface(Gui::gui->dialogue_bg, NULL, where, &dst); this->menu->dialogue->draw(where, d_x + 10, d_y + 10, - this->dialogue_bg->w - 10, this->dialogue_bg->h - 10); + Gui::gui->dialogue_bg->w - 10, Gui::gui->dialogue_bg->h - 10); } } protected: MainMenu *menu; HelpBox *help; - SDL_Surface *bg; - SDL_Surface *infobox; - SDL_Surface *textbox; - SDL_Surface *dialogue_bg; };