diff --git a/frodo_menu.cpp b/frodo_menu.cpp index 789743d..ae020a7 100644 --- a/frodo_menu.cpp +++ b/frodo_menu.cpp @@ -74,6 +74,7 @@ public: virtual void escapeCallback(int which) { printf("entry %d escaped: %s\n", which, this->pp_msgs[which]); + this->parent->parent->resetViewStack(); } private: @@ -166,7 +167,7 @@ Gui::Gui() /* Create the views */ MainView *mv = new MainView(this); - this->registerView(mv); + this->pushView(mv); this->cur_view = mv; } @@ -227,7 +228,8 @@ void Gui::runLogic(void) this->cur_view->runLogic(); } -void Gui::registerView(GuiView *view) + +void Gui::pushView(GuiView *view) { int cur = this->n_views; @@ -237,6 +239,27 @@ void Gui::registerView(GuiView *view) this->views[cur] = view; } +GuiView *Gui::popView() +{ + this->n_views--; + if (this->n_views <= 0) + { + this->n_views = 0; + free(this->views); + return NULL; + } + + this->views = (GuiView**)xrealloc(this->views, + sizeof(GuiView*) * this->n_views); + return this->views[this->n_views - 1]; +} + +void Gui::resetViewStack() +{ + free(this->views); + this->views = NULL; +} + void Gui::pushEvent(SDL_Event *ev) { if (this->is_active) diff --git a/frodo_menu.hh b/frodo_menu.hh index d1b3f8e..21f1155 100644 --- a/frodo_menu.hh +++ b/frodo_menu.hh @@ -24,7 +24,6 @@ public: virtual void draw(SDL_Surface *where) = 0; -protected: Gui *parent; }; @@ -47,7 +46,11 @@ public: void draw(SDL_Surface *where); - void registerView(GuiView *view); + void pushView(GuiView *view); + + GuiView *popView(); + + void resetViewStack(); /* These are private, keep off! */ const char *getThemePath(const char *dir, const char *what);