Implement status bar

This commit is contained in:
simon.kagstrom 2010-01-16 09:08:54 +00:00
parent 0eae47a65f
commit 5ec545ff11
4 changed files with 117 additions and 1 deletions

13
gui.cpp
View File

@ -68,6 +68,7 @@ Gui::Gui()
this->main_menu_bg = NULL; this->main_menu_bg = NULL;
this->infobox = NULL; this->infobox = NULL;
this->textbox = NULL; this->textbox = NULL;
this->status_bar_bg = NULL;
this->default_font = NULL; this->default_font = NULL;
this->dialogue_bg = NULL; this->dialogue_bg = NULL;
this->small_font = NULL; this->small_font = NULL;
@ -104,6 +105,7 @@ bool Gui::setTheme(const char *path)
this->background = this->loadThemeImage(path, "background.png"); this->background = this->loadThemeImage(path, "background.png");
this->main_menu_bg = this->loadThemeImage(path, "main_menu_bg.png"); this->main_menu_bg = this->loadThemeImage(path, "main_menu_bg.png");
this->status_bar_bg = this->loadThemeImage(path, "status_bar.png");
this->infobox = this->loadThemeImage(path, "infobox.png"); this->infobox = this->loadThemeImage(path, "infobox.png");
this->textbox = this->loadThemeImage(path, "textbox.png"); this->textbox = this->loadThemeImage(path, "textbox.png");
this->dialogue_bg = this->loadThemeImage(path, "dialogue_box.png"); this->dialogue_bg = this->loadThemeImage(path, "dialogue_box.png");
@ -122,6 +124,7 @@ bool Gui::setTheme(const char *path)
!this->disc_info || !this->disc_info ||
!this->selected_key || !this->selected_key ||
!this->highlighted_key || !this->highlighted_key ||
!this->status_bar_bg ||
!this->default_font || !this->default_font ||
!this->small_font) !this->small_font)
{ {
@ -151,6 +154,8 @@ bool Gui::setTheme(const char *path)
/* Create the views */ /* Create the views */
if (!this->mv) if (!this->mv)
{ {
this->status_bar = new StatusBar();
this->mv = new MainView(); this->mv = new MainView();
this->dv = new DiscView(); this->dv = new DiscView();
this->ov = new OptionsView(); this->ov = new OptionsView();
@ -178,6 +183,9 @@ void Gui::runLogic(void)
{ {
GuiView *cur_view = this->peekView(); GuiView *cur_view = this->peekView();
this->status_bar->runLogic();
this->timerController->tick();
if (!this->is_active || !cur_view) if (!this->is_active || !cur_view)
return; return;
if (this->dlg) if (this->dlg)
@ -186,7 +194,6 @@ void Gui::runLogic(void)
this->kbd->runLogic(); this->kbd->runLogic();
else else
cur_view->runLogic(); cur_view->runLogic();
this->timerController->tick();
} }
void Gui::pushView(GuiView *view) void Gui::pushView(GuiView *view)
@ -266,7 +273,10 @@ void Gui::draw(SDL_Surface *where)
GuiView *cur_view = this->peekView(); GuiView *cur_view = this->peekView();
if (!this->is_active || !cur_view) if (!this->is_active || !cur_view)
{
this->status_bar->draw(where);
return; return;
}
SDL_BlitSurface(this->background, NULL, screen, NULL); SDL_BlitSurface(this->background, NULL, screen, NULL);
cur_view->draw(where); cur_view->draw(where);
@ -274,6 +284,7 @@ void Gui::draw(SDL_Surface *where)
this->kbd->draw(where); this->kbd->draw(where);
if (this->dlg) if (this->dlg)
this->dlg->draw(where); this->dlg->draw(where);
this->status_bar->draw(where);
} }
void Gui::activate() void Gui::activate()

3
gui.hh
View File

@ -12,6 +12,7 @@
#include <Prefs.h> #include <Prefs.h>
class DialogueBox; class DialogueBox;
class StatusBar;
class MainView; class MainView;
class BindKeysView; class BindKeysView;
@ -73,6 +74,7 @@ public:
SDL_Surface *background; SDL_Surface *background;
SDL_Surface *main_menu_bg; SDL_Surface *main_menu_bg;
SDL_Surface *status_bar_bg;
SDL_Surface *infobox; SDL_Surface *infobox;
SDL_Surface *textbox; SDL_Surface *textbox;
SDL_Surface *dialogue_bg; SDL_Surface *dialogue_bg;
@ -89,6 +91,7 @@ public:
/* Handled specially */ /* Handled specially */
VirtualKeyboard *kbd; VirtualKeyboard *kbd;
DialogueBox *dlg; DialogueBox *dlg;
StatusBar *status_bar;
MainView *mv; MainView *mv;
DiscView *dv; DiscView *dv;

65
status_bar.cpp Normal file
View File

@ -0,0 +1,65 @@
#include "status_bar.hh"
#include "gui.hh"
StatusBar::StatusBar() : Menu(Gui::gui->small_font), TimeoutHandler()
{
memset(this->messages, 0, sizeof(this->messages));
this->head = this->tail = 0;
this->cur_message = NULL;
this->setSelectedBackground(NULL, NULL, NULL, NULL, NULL, NULL);
}
void StatusBar::queueMessage(const char *message)
{
this->messages[this->head] = message;
/* If this is the first message, display it as soon as possible */
if (this->head == this->tail)
Gui::gui->timerController->arm(this, 1);
this->head = (this->head + 1) % N_STATUS_MESSAGES;
if (this->head == this->tail)
this->tail = (this->tail + 1) % N_STATUS_MESSAGES;
}
const char *StatusBar::dequeueMessage()
{
const char *out = this->messages[this->tail];
if (this->head == this->tail)
return NULL;
this->tail = (this->tail + 1) % N_STATUS_MESSAGES;
return out;
}
void StatusBar::timeoutCallback()
{
static const char *text[2];
this->cur_message = this->dequeueMessage();
if (this->cur_message)
Gui::gui->timerController->arm(this, 500);
text[0] = this->cur_message;
text[1] = NULL;
this->setText(text);
}
void StatusBar::draw(SDL_Surface *where)
{
SDL_Rect dst;
int x = 130;
int y = 12;
int w = 496;
int h = 56;
if (!this->cur_message)
return;
/* Blit the backgrounds */
dst = (SDL_Rect){x,y,0,0};
SDL_BlitSurface(Gui::gui->status_bar_bg, NULL, where, &dst);
Menu::draw(where, x+4, y+4, w, h);
}

37
status_bar.hh Normal file
View File

@ -0,0 +1,37 @@
#ifndef __STATUS_BAR_HH__
#define __STATUS_BAR_HH__
#include "menu.hh"
#include "gui.hh"
#include "timer.hh"
#define N_STATUS_MESSAGES 8
class StatusBar : public Menu, TimeoutHandler
{
public:
StatusBar();
void queueMessage(const char *message);
virtual void draw(SDL_Surface *where);
virtual void hoverCallback(int which) {};
virtual void selectCallback(int which) {};
virtual void escapeCallback(int which) {};
protected:
virtual void timeoutCallback();
const char *dequeueMessage();
const char *messages[N_STATUS_MESSAGES];
const char *cur_message;
int head, tail;
int x;
int y;
};
#endif /* __DIALOGUE_BOX_HH__ */