Remove cur_view and use peek instead

This commit is contained in:
simon.kagstrom 2009-12-05 09:33:58 +00:00
parent 688a18721b
commit 4aafeb344a
2 changed files with 22 additions and 12 deletions

View File

@ -74,7 +74,7 @@ public:
virtual void escapeCallback(int which)
{
printf("entry %d escaped: %s\n", which, this->pp_msgs[which]);
this->parent->parent->resetViewStack();
this->parent->parent->exitMenu();
}
private:
@ -168,7 +168,6 @@ Gui::Gui()
/* Create the views */
MainView *mv = new MainView(this);
this->pushView(mv);
this->cur_view = mv;
}
@ -222,10 +221,10 @@ bool Gui::setTheme(const char *path)
void Gui::runLogic(void)
{
if (!this->is_active)
return;
GuiView *cur_view = this->peekView();
this->cur_view->runLogic();
if (!this->is_active || !cur_view)
return;
}
@ -254,7 +253,7 @@ GuiView *Gui::popView()
return this->views[this->n_views - 1];
}
void Gui::resetViewStack()
void Gui::exitMenu()
{
free(this->views);
this->views = NULL;
@ -262,17 +261,22 @@ void Gui::resetViewStack()
void Gui::pushEvent(SDL_Event *ev)
{
if (this->is_active)
this->cur_view->pushEvent(ev);
GuiView *cur_view = this->peekView();
if (this->is_active || !cur_view)
cur_view->pushEvent(ev);
cur_view->runLogic();
}
void Gui::draw(SDL_Surface *where)
{
if (!this->is_active)
GuiView *cur_view = this->peekView();
if (!this->is_active || !cur_view)
return;
SDL_BlitSurface(this->background, NULL, screen, NULL);
this->cur_view->draw(where);
cur_view->draw(where);
}
void Gui::activate()

View File

@ -50,7 +50,14 @@ public:
GuiView *popView();
void resetViewStack();
GuiView *peekView()
{
if (!this->views)
return NULL;
return this->views[this->n_views-1];
}
void exitMenu();
/* These are private, keep off! */
const char *getThemePath(const char *dir, const char *what);
@ -74,7 +81,6 @@ public:
Font *small_font;
GuiView **views;
GuiView *cur_view;
int n_views;
};