Gui refactoring 2: Separate the timer controller from the Gui

This commit is contained in:
simon.kagstrom 2010-08-15 12:11:23 +00:00
parent 01e2513f62
commit fd5fe7825f
9 changed files with 26 additions and 15 deletions

View File

@ -46,7 +46,7 @@ public:
SaveScreenshot() : TimeoutHandler() SaveScreenshot() : TimeoutHandler()
{ {
/* ~45 seconds from now */ /* ~45 seconds from now */
Gui::gui->controller->arm(this, 45000); TimerController::controller->arm(this, 45000);
} }
virtual void timeoutCallback() virtual void timeoutCallback()
@ -56,7 +56,7 @@ public:
if (Gui::gui->is_active) if (Gui::gui->is_active)
{ {
/* Rearm if we are in the GUI */ /* Rearm if we are in the GUI */
Gui::gui->controller->arm(this, 10000); TimerController::controller->arm(this, 10000);
return; return;
} }
Gui::gui->cur_gameInfo->setScreenshot(TheC64->TheDisplay->SurfaceFromC64Display()); Gui::gui->cur_gameInfo->setScreenshot(TheC64->TheDisplay->SurfaceFromC64Display());
@ -74,7 +74,7 @@ public:
{ {
Gui::gui->status_bar->queueMessage("Resetting the C64"); Gui::gui->status_bar->queueMessage("Resetting the C64");
TheC64->Reset(); TheC64->Reset();
Gui::gui->controller->arm(this, 4500); TimerController::controller->arm(this, 4500);
} }
virtual void timeoutCallback() virtual void timeoutCallback()
@ -149,7 +149,7 @@ public:
free(tmp_filename); free(tmp_filename);
} }
Gui::gui->controller->disarm(this); TimerController::controller->disarm(this);
Gui::gui->dv->loadGameInfo(fileName); Gui::gui->dv->loadGameInfo(fileName);
if (Gui::gui->dv->gameInfo->gi) if (Gui::gui->dv->gameInfo->gi)
@ -172,7 +172,7 @@ public:
virtual void hoverCallback(int which) virtual void hoverCallback(int which)
{ {
Gui::gui->controller->arm(this, 350); TimerController::controller->arm(this, 350);
} }
virtual void timeoutCallback() virtual void timeoutCallback()
@ -182,7 +182,7 @@ public:
virtual void escapeCallback(int which) virtual void escapeCallback(int which)
{ {
Gui::gui->controller->disarm(this); TimerController::controller->disarm(this);
Gui::gui->popView(); Gui::gui->popView();
} }

View File

@ -101,7 +101,6 @@ Gui::Gui()
this->n_views = 0; this->n_views = 0;
this->views = NULL; this->views = NULL;
this->controller = new TimerController();
VirtualKeyboard::kbd = new VirtualKeyboard(NULL); VirtualKeyboard::kbd = new VirtualKeyboard(NULL);
@ -143,7 +142,6 @@ Gui::~Gui()
delete this->nrv; delete this->nrv;
delete this->cur_gameInfo; delete this->cur_gameInfo;
delete this->controller;
if (this->status_bar) if (this->status_bar)
delete this->status_bar; delete this->status_bar;
@ -277,7 +275,7 @@ void Gui::runLogic(void)
GuiView *cur_view = this->peekView(); GuiView *cur_view = this->peekView();
this->status_bar->runLogic(); this->status_bar->runLogic();
this->controller->tick(); TimerController::controller->tick();
if (this->kbd) if (this->kbd)
this->kbd->runLogic(); this->kbd->runLogic();

View File

@ -19,7 +19,7 @@ public:
TheC64->pushKeyCode(this->kc, false); TheC64->pushKeyCode(this->kc, false);
/* Release it soon */ /* Release it soon */
Gui::gui->controller->arm(this, 1); TimerController::controller->arm(this, 1);
} }
virtual void timeoutCallback() virtual void timeoutCallback()

View File

@ -72,7 +72,7 @@ void NetworkServerMessages::timeoutCallback()
if (this->messages[this->tail]) if (this->messages[this->tail])
break; break;
} }
Gui::gui->controller->arm(this, 5000); TimerController::controller->arm(this, 5000);
free(cpy); free(cpy);
} }

View File

@ -95,7 +95,7 @@ public:
virtual void hoverCallback(int which) virtual void hoverCallback(int which)
{ {
Gui::gui->controller->arm(this, 350); TimerController::controller->arm(this, 350);
} }
virtual void escapeCallback(int which) virtual void escapeCallback(int which)

View File

@ -29,7 +29,7 @@ void StatusBar::queueMessage(const char *fmt, ...)
/* If this is the first message, display it as soon as possible */ /* If this is the first message, display it as soon as possible */
if (this->head == this->tail) if (this->head == this->tail)
Gui::gui->controller->arm(this, 1); TimerController::controller->arm(this, 1);
this->head = (this->head + 1) % N_STATUS_MESSAGES; this->head = (this->head + 1) % N_STATUS_MESSAGES;
if (this->head == this->tail) if (this->head == this->tail)
@ -60,7 +60,7 @@ void StatusBar::timeoutCallback()
this->setText(text); this->setText(text);
else else
this->setText(NULL); this->setText(NULL);
Gui::gui->controller->arm(this, 2000); TimerController::controller->arm(this, 2000);
free((void *)this->cur_message); free((void *)this->cur_message);
} }

View File

@ -255,6 +255,7 @@ void Frodo::ReadyToRun(void)
// Create and start C64 // Create and start C64
TheC64 = new C64; TheC64 = new C64;
DataStore::ds = new DataStore(); DataStore::ds = new DataStore();
TimerController::init();
Gui::init(); Gui::init();
load_rom_files(); load_rom_files();
TheC64->Run(); TheC64->Run();

View File

@ -10,7 +10,7 @@
TimeoutHandler::~TimeoutHandler() TimeoutHandler::~TimeoutHandler()
{ {
/* If we haven't timed out yet, disarm us */ /* If we haven't timed out yet, disarm us */
Gui::gui->controller->disarm(this); TimerController::controller->disarm(this);
} }
@ -80,3 +80,11 @@ void TimerController::tick()
cur->tick(); cur->tick();
} }
} }
TimerController *TimerController::controller;
void TimerController::init()
{
TimerController::controller = new TimerController();
}

View File

@ -14,6 +14,10 @@ public:
void tick(); void tick();
/* Singleton */
static TimerController *controller;
static void init();
private: private:
int n_handlers; int n_handlers;
TimeoutHandler **handlers; TimeoutHandler **handlers;