mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-04-10 19:15:13 +00:00
Finally made GuiList a template.
This commit is contained in:
parent
eaf7df7ad5
commit
cd4ebeafa2
2
Makefile
2
Makefile
|
@ -1,7 +1,7 @@
|
||||||
CC=g++
|
CC=g++
|
||||||
CFLAGS=-c -Wall
|
CFLAGS=-c -Wall
|
||||||
LDFLAGS=-lSDL -lSDL_ttf -lSDL_image -lboost_system -lboost_filesystem
|
LDFLAGS=-lSDL -lSDL_ttf -lSDL_image -lboost_system -lboost_filesystem
|
||||||
SRCSOURCES=main.cpp Renderer.cpp Renderer_draw.cpp GuiComponent.cpp InputManager.cpp SystemData.cpp GameData.cpp FolderData.cpp XMLReader.cpp components/GuiList.cpp components/GuiGameList.cpp components/GuiInputConfig.cpp components/GuiImage.cpp components/GuiMenu.cpp pugiXML/pugixml.cpp
|
SRCSOURCES=main.cpp Renderer.cpp Renderer_draw.cpp GuiComponent.cpp InputManager.cpp SystemData.cpp GameData.cpp FolderData.cpp XMLReader.cpp components/GuiGameList.cpp components/GuiInputConfig.cpp components/GuiImage.cpp components/GuiMenu.cpp pugiXML/pugixml.cpp
|
||||||
SOURCES=$(addprefix src/,$(SRCSOURCES))
|
SOURCES=$(addprefix src/,$(SRCSOURCES))
|
||||||
OBJECTS=$(SOURCES:.cpp=.o)
|
OBJECTS=$(SOURCES:.cpp=.o)
|
||||||
EXECUTABLE=emulationstation
|
EXECUTABLE=emulationstation
|
||||||
|
|
|
@ -16,12 +16,12 @@ GuiGameList::GuiGameList(bool useDetail)
|
||||||
//Those with smaller displays may prefer the older view.
|
//Those with smaller displays may prefer the older view.
|
||||||
if(mDetailed)
|
if(mDetailed)
|
||||||
{
|
{
|
||||||
mList = new GuiList(Renderer::getScreenWidth() * 0.4, Renderer::getFontHeight(Renderer::LARGE) + 2);
|
mList = new GuiList<FileData*>(Renderer::getScreenWidth() * 0.4, Renderer::getFontHeight(Renderer::LARGE) + 2);
|
||||||
|
|
||||||
mScreenshot = new GuiImage(Renderer::getScreenWidth() * 0.2 - (SCREENSHOTWIDTH / 2), Renderer::getFontHeight(Renderer::LARGE) + 2);
|
mScreenshot = new GuiImage(Renderer::getScreenWidth() * 0.2 - (SCREENSHOTWIDTH / 2), Renderer::getFontHeight(Renderer::LARGE) + 2);
|
||||||
addChild(mScreenshot);
|
addChild(mScreenshot);
|
||||||
}else{
|
}else{
|
||||||
mList = new GuiList(0, Renderer::getFontHeight(Renderer::LARGE) + 2);
|
mList = new GuiList<FileData*>(0, Renderer::getFontHeight(Renderer::LARGE) + 2);
|
||||||
mScreenshot = NULL;
|
mScreenshot = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ void GuiGameList::onRender()
|
||||||
Renderer::drawRect(Renderer::getScreenWidth() * 0.4, Renderer::getFontHeight(Renderer::LARGE) + 2, 8, Renderer::getScreenHeight(), 0x0000FF);
|
Renderer::drawRect(Renderer::getScreenWidth() * 0.4, Renderer::getFontHeight(Renderer::LARGE) + 2, 8, Renderer::getScreenHeight(), 0x0000FF);
|
||||||
|
|
||||||
//if we have selected a non-folder
|
//if we have selected a non-folder
|
||||||
if(mList->getSelectedObject() && !((FileData*)mList->getSelectedObject())->isFolder())
|
if(mList->getSelectedObject() && !mList->getSelectedObject()->isFolder())
|
||||||
{
|
{
|
||||||
GameData* game = (GameData*)mList->getSelectedObject();
|
GameData* game = (GameData*)mList->getSelectedObject();
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ void GuiGameList::onInput(InputManager::InputButton button, bool keyDown)
|
||||||
{
|
{
|
||||||
if(!keyDown)
|
if(!keyDown)
|
||||||
{
|
{
|
||||||
FileData* file = (FileData*)mList->getSelectedObject();
|
FileData* file = mList->getSelectedObject();
|
||||||
if(file->isFolder())
|
if(file->isFolder())
|
||||||
{
|
{
|
||||||
//set current directory to this or something
|
//set current directory to this or something
|
||||||
|
@ -138,7 +138,7 @@ void GuiGameList::onInput(InputManager::InputButton button, bool keyDown)
|
||||||
{
|
{
|
||||||
if(!keyDown && (button == InputManager::UP || button == InputManager::DOWN))
|
if(!keyDown && (button == InputManager::UP || button == InputManager::DOWN))
|
||||||
{
|
{
|
||||||
if(mList->getSelectedObject() && !((FileData*)mList->getSelectedObject())->isFolder())
|
if(mList->getSelectedObject() && !mList->getSelectedObject()->isFolder())
|
||||||
{
|
{
|
||||||
mScreenshot->setImage(((GameData*)mList->getSelectedObject())->getImagePath());
|
mScreenshot->setImage(((GameData*)mList->getSelectedObject())->getImagePath());
|
||||||
}else{
|
}else{
|
||||||
|
@ -167,6 +167,7 @@ void GuiGameList::updateList()
|
||||||
}
|
}
|
||||||
|
|
||||||
//these are called when the menu opens/closes
|
//these are called when the menu opens/closes
|
||||||
|
//the second bit should be moved to GuiList
|
||||||
void GuiGameList::onPause()
|
void GuiGameList::onPause()
|
||||||
{
|
{
|
||||||
InputManager::unregisterComponent(this);
|
InputManager::unregisterComponent(this);
|
||||||
|
|
|
@ -31,7 +31,7 @@ private:
|
||||||
int mSystemId;
|
int mSystemId;
|
||||||
bool mDetailed;
|
bool mDetailed;
|
||||||
|
|
||||||
GuiList* mList;
|
GuiList<FileData*>* mList;
|
||||||
GuiImage* mScreenshot;
|
GuiImage* mScreenshot;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#include "GuiList.h"
|
#include "GuiList.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
GuiList::GuiList(int offsetX, int offsetY)
|
template <typename listType>
|
||||||
|
GuiList<listType>::GuiList(int offsetX, int offsetY)
|
||||||
{
|
{
|
||||||
mSelection = 0;
|
mSelection = 0;
|
||||||
mScrollDir = 0;
|
mScrollDir = 0;
|
||||||
|
@ -14,12 +15,14 @@ GuiList::GuiList(int offsetX, int offsetY)
|
||||||
InputManager::registerComponent(this);
|
InputManager::registerComponent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiList::~GuiList()
|
template <typename listType>
|
||||||
|
GuiList<listType>::~GuiList()
|
||||||
{
|
{
|
||||||
InputManager::unregisterComponent(this);
|
InputManager::unregisterComponent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiList::onRender()
|
template <typename listType>
|
||||||
|
void GuiList<listType>::onRender()
|
||||||
{
|
{
|
||||||
Renderer::FontSize fontsize = Renderer::MEDIUM;
|
Renderer::FontSize fontsize = Renderer::MEDIUM;
|
||||||
|
|
||||||
|
@ -66,7 +69,8 @@ void GuiList::onRender()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiList::onInput(InputManager::InputButton button, bool keyDown)
|
template <typename listType>
|
||||||
|
void GuiList<listType>::onInput(InputManager::InputButton button, bool keyDown)
|
||||||
{
|
{
|
||||||
if(mRowVector.size() > 0)
|
if(mRowVector.size() > 0)
|
||||||
{
|
{
|
||||||
|
@ -100,7 +104,8 @@ void GuiList::onInput(InputManager::InputButton button, bool keyDown)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiList::onTick(int deltaTime)
|
template <typename listType>
|
||||||
|
void GuiList<listType>::onTick(int deltaTime)
|
||||||
{
|
{
|
||||||
if(mScrollDir != 0)
|
if(mScrollDir != 0)
|
||||||
{
|
{
|
||||||
|
@ -134,29 +139,34 @@ void GuiList::onTick(int deltaTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
//list management stuff
|
//list management stuff
|
||||||
void GuiList::addObject(std::string name, void* obj, int color)
|
template <typename listType>
|
||||||
|
void GuiList<listType>::addObject(std::string name, listType obj, int color)
|
||||||
{
|
{
|
||||||
ListRow row = {name, obj, color};
|
ListRow row = {name, obj, color};
|
||||||
mRowVector.push_back(row);
|
mRowVector.push_back(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiList::clear()
|
template <typename listType>
|
||||||
|
void GuiList<listType>::clear()
|
||||||
{
|
{
|
||||||
mRowVector.clear();
|
mRowVector.clear();
|
||||||
mSelection = 0;
|
mSelection = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GuiList::getSelectedName()
|
template <typename listType>
|
||||||
|
std::string GuiList<listType>::getSelectedName()
|
||||||
{
|
{
|
||||||
return mRowVector.at(mSelection).name;
|
return mRowVector.at(mSelection).name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* GuiList::getSelectedObject()
|
template <typename listType>
|
||||||
|
listType GuiList<listType>::getSelectedObject()
|
||||||
{
|
{
|
||||||
return mRowVector.at(mSelection).object;
|
return mRowVector.at(mSelection).object;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GuiList::getSelection()
|
template <typename listType>
|
||||||
|
int GuiList<listType>::getSelection()
|
||||||
{
|
{
|
||||||
return mSelection;
|
return mSelection;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,14 +10,8 @@
|
||||||
#define SCROLLDELAY 507
|
#define SCROLLDELAY 507
|
||||||
#define SCROLLTIME (57*6)
|
#define SCROLLTIME (57*6)
|
||||||
|
|
||||||
struct ListRow
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
void* object;
|
|
||||||
int color;
|
|
||||||
};
|
|
||||||
|
|
||||||
//this should really be a template
|
//this should really be a template
|
||||||
|
template <typename listType>
|
||||||
class GuiList : public GuiComponent
|
class GuiList : public GuiComponent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -28,19 +22,29 @@ public:
|
||||||
void onTick(int deltaTime);
|
void onTick(int deltaTime);
|
||||||
void onInput(InputManager::InputButton button, bool keyDown);
|
void onInput(InputManager::InputButton button, bool keyDown);
|
||||||
|
|
||||||
void addObject(std::string name, void* obj, int color = 0xFF0000);
|
void addObject(std::string name, listType obj, int color = 0xFF0000);
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
std::string getSelectedName();
|
std::string getSelectedName();
|
||||||
void* getSelectedObject();
|
listType getSelectedObject();
|
||||||
int getSelection();
|
int getSelection();
|
||||||
private:
|
private:
|
||||||
int mScrollDir, mScrollAccumulator;
|
int mScrollDir, mScrollAccumulator;
|
||||||
bool mScrolling;
|
bool mScrolling;
|
||||||
|
|
||||||
int mOffsetX, mOffsetY;
|
int mOffsetX, mOffsetY;
|
||||||
|
|
||||||
|
struct ListRow
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
listType object;
|
||||||
|
int color;
|
||||||
|
};
|
||||||
|
|
||||||
std::vector<ListRow> mRowVector;
|
std::vector<ListRow> mRowVector;
|
||||||
int mSelection;
|
int mSelection;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#include "GuiList.cpp"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -6,7 +6,7 @@ GuiMenu::GuiMenu(GuiComponent* parent)
|
||||||
mParent = parent;
|
mParent = parent;
|
||||||
parent->pause();
|
parent->pause();
|
||||||
|
|
||||||
mList = new GuiList(Renderer::getScreenWidth() * 0.5, 20);
|
mList = new GuiList<std::string>(Renderer::getScreenWidth() * 0.5, 20);
|
||||||
|
|
||||||
addChild(mList);
|
addChild(mList);
|
||||||
|
|
||||||
|
@ -37,11 +37,19 @@ void GuiMenu::onInput(InputManager::InputButton button, bool keyDown)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(button == InputManager::BUTTON1 && keyDown)
|
||||||
|
{
|
||||||
|
system(mList->getSelectedObject().c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiMenu::populateList()
|
void GuiMenu::populateList()
|
||||||
{
|
{
|
||||||
|
mList->clear();
|
||||||
|
|
||||||
|
mList->addObject("Nothing", "");
|
||||||
|
mList->addObject("Shutdown", "sudo shutdown -h now");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiMenu::onRender()
|
void GuiMenu::onRender()
|
||||||
|
|
|
@ -15,7 +15,10 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GuiComponent* mParent;
|
GuiComponent* mParent;
|
||||||
GuiList* mList;
|
GuiList<std::string>* mList;
|
||||||
|
|
||||||
|
void populateList();
|
||||||
|
|
||||||
bool mSkippedMenuClose;
|
bool mSkippedMenuClose;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue