2012-07-20 01:08:29 +00:00
|
|
|
#include "GuiList.h"
|
2012-07-20 16:14:09 +00:00
|
|
|
#include <SDL/SDL.h>
|
2012-07-21 19:06:24 +00:00
|
|
|
#include <iostream>
|
2012-07-20 01:08:29 +00:00
|
|
|
|
|
|
|
GuiList::GuiList()
|
|
|
|
{
|
|
|
|
mSelection = 0;
|
2012-07-21 19:06:24 +00:00
|
|
|
InputManager::registerComponent(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
GuiList::~GuiList()
|
|
|
|
{
|
|
|
|
InputManager::unregisterComponent(this);
|
2012-07-20 01:08:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiList::onRender()
|
|
|
|
{
|
2012-07-20 16:14:09 +00:00
|
|
|
int y = 40;
|
|
|
|
SDL_Color color = {0, 0, 255};
|
2012-07-21 19:06:24 +00:00
|
|
|
|
|
|
|
if(mNameVector.size() == 0)
|
|
|
|
{
|
|
|
|
Renderer::drawCenteredText("The list is empty.", y, color);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-20 16:14:09 +00:00
|
|
|
for(unsigned int i = 0; i < mNameVector.size(); i++)
|
|
|
|
{
|
2012-07-21 19:06:24 +00:00
|
|
|
if(mSelection == (int)i)
|
|
|
|
{
|
|
|
|
Renderer::drawRect(0, y, Renderer::getScreenWidth(), 52, 0x000000);
|
|
|
|
}
|
|
|
|
|
2012-07-20 16:14:09 +00:00
|
|
|
Renderer::drawCenteredText(mNameVector.at(i), y, color);
|
2012-07-21 19:06:24 +00:00
|
|
|
y += 40;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiList::onInput(InputManager::InputButton button, bool keyDown)
|
|
|
|
{
|
|
|
|
if(mNameVector.size() > 0 && keyDown)
|
|
|
|
{
|
|
|
|
if(button == InputManager::DOWN)
|
|
|
|
mSelection++;
|
|
|
|
|
|
|
|
if(button == InputManager::UP)
|
|
|
|
mSelection--;
|
|
|
|
|
|
|
|
if(mSelection < 0)
|
|
|
|
mSelection += mNameVector.size();
|
|
|
|
|
|
|
|
if(mSelection >= (int)mNameVector.size())
|
|
|
|
mSelection -= mNameVector.size();
|
2012-07-20 16:14:09 +00:00
|
|
|
}
|
2012-07-20 01:08:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiList::addObject(std::string name, void* obj)
|
|
|
|
{
|
|
|
|
mNameVector.push_back(name);
|
|
|
|
mPointerVector.push_back(obj);
|
|
|
|
}
|
|
|
|
|
2012-07-20 16:14:09 +00:00
|
|
|
void GuiList::clear()
|
2012-07-20 01:08:29 +00:00
|
|
|
{
|
|
|
|
mNameVector.clear();
|
|
|
|
mPointerVector.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GuiList::getSelectedName()
|
|
|
|
{
|
|
|
|
return mNameVector.at(mSelection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void* GuiList::getSelectedObject()
|
|
|
|
{
|
|
|
|
return mPointerVector.at(mSelection);
|
|
|
|
}
|
2012-07-21 19:06:24 +00:00
|
|
|
|
|
|
|
int GuiList::getSelection()
|
|
|
|
{
|
|
|
|
return mSelection;
|
|
|
|
}
|