2013-04-08 14:41:25 +00:00
|
|
|
#include "Window.h"
|
|
|
|
#include <iostream>
|
2013-04-10 17:29:07 +00:00
|
|
|
#include "Renderer.h"
|
|
|
|
#include "AudioManager.h"
|
2013-05-23 09:43:50 +00:00
|
|
|
#include "VolumeControl.h"
|
2013-04-08 14:41:25 +00:00
|
|
|
|
|
|
|
Window::Window()
|
|
|
|
{
|
|
|
|
mInputManager = new InputManager(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Window::~Window()
|
|
|
|
{
|
|
|
|
delete mInputManager;
|
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void Window::pushGui(GuiComponent* gui)
|
2013-04-08 14:41:25 +00:00
|
|
|
{
|
|
|
|
mGuiStack.push_back(gui);
|
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
void Window::removeGui(GuiComponent* gui)
|
2013-04-08 14:41:25 +00:00
|
|
|
{
|
2013-06-02 15:08:32 +00:00
|
|
|
for(auto i = mGuiStack.begin(); i != mGuiStack.end(); i++)
|
2013-04-08 14:41:25 +00:00
|
|
|
{
|
2013-06-02 15:08:32 +00:00
|
|
|
if(*i == gui)
|
2013-04-08 14:41:25 +00:00
|
|
|
{
|
2013-06-02 15:08:32 +00:00
|
|
|
mGuiStack.erase(i);
|
|
|
|
return;
|
2013-04-08 14:41:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-02 15:08:32 +00:00
|
|
|
GuiComponent* Window::peekGui()
|
2013-04-08 14:41:25 +00:00
|
|
|
{
|
|
|
|
if(mGuiStack.size() == 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return mGuiStack.at(mGuiStack.size() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::render()
|
|
|
|
{
|
2013-06-02 15:08:32 +00:00
|
|
|
//there's nothing to render, which should pretty much never happen
|
2013-04-08 14:41:25 +00:00
|
|
|
if(mGuiStack.size() == 0)
|
|
|
|
std::cout << "guistack empty\n";
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < mGuiStack.size(); i++)
|
|
|
|
{
|
|
|
|
mGuiStack.at(i)->render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-08 17:40:15 +00:00
|
|
|
void Window::init()
|
|
|
|
{
|
2013-04-10 17:29:07 +00:00
|
|
|
mInputManager->init();
|
|
|
|
Renderer::init(0, 0);
|
|
|
|
|
2013-04-08 17:40:15 +00:00
|
|
|
for(unsigned int i = 0; i < mGuiStack.size(); i++)
|
|
|
|
{
|
|
|
|
mGuiStack.at(i)->init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::deinit()
|
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < mGuiStack.size(); i++)
|
|
|
|
{
|
|
|
|
mGuiStack.at(i)->deinit();
|
|
|
|
}
|
2013-04-10 17:29:07 +00:00
|
|
|
|
|
|
|
mInputManager->deinit();
|
|
|
|
Renderer::deinit();
|
2013-04-08 17:40:15 +00:00
|
|
|
}
|
|
|
|
|
2013-04-08 14:41:25 +00:00
|
|
|
void Window::input(InputConfig* config, Input input)
|
|
|
|
{
|
2013-05-23 09:43:50 +00:00
|
|
|
if(config->isMappedTo("mastervolup", input))
|
|
|
|
{
|
|
|
|
VolumeControl::getInstance()->setVolume(VolumeControl::getInstance()->getVolume() + 5);
|
|
|
|
}
|
|
|
|
else if(config->isMappedTo("mastervoldown", input))
|
|
|
|
{
|
|
|
|
VolumeControl::getInstance()->setVolume(VolumeControl::getInstance()->getVolume() - 5);
|
|
|
|
}
|
|
|
|
else if(peekGui())
|
2013-04-08 14:41:25 +00:00
|
|
|
this->peekGui()->input(config, input);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::update(int deltaTime)
|
|
|
|
{
|
|
|
|
if(peekGui())
|
|
|
|
peekGui()->update(deltaTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
InputManager* Window::getInputManager()
|
|
|
|
{
|
|
|
|
return mInputManager;
|
|
|
|
}
|