2012-08-02 04:03:15 +00:00
|
|
|
#include "GuiMenu.h"
|
|
|
|
#include <iostream>
|
2012-11-14 15:07:09 +00:00
|
|
|
#include <SDL/SDL.h>
|
2012-08-02 04:03:15 +00:00
|
|
|
|
2012-12-18 15:20:13 +00:00
|
|
|
//defined in main.cpp
|
|
|
|
extern bool DONTSHOWEXIT;
|
|
|
|
|
2012-08-02 04:03:15 +00:00
|
|
|
GuiMenu::GuiMenu(GuiComponent* parent)
|
|
|
|
{
|
|
|
|
mParent = parent;
|
|
|
|
parent->pause();
|
|
|
|
|
2012-10-31 14:46:06 +00:00
|
|
|
mList = new GuiList<std::string>(0, Renderer::getDefaultFont(Renderer::LARGE)->getHeight() + 2, Renderer::getDefaultFont(Renderer::LARGE));
|
2012-10-25 18:03:35 +00:00
|
|
|
mList->setSelectedTextColor(0x0000FFFF);
|
2012-08-04 21:38:37 +00:00
|
|
|
populateList();
|
2012-08-02 04:03:15 +00:00
|
|
|
addChild(mList);
|
|
|
|
|
|
|
|
mSkippedMenuClose = false;
|
|
|
|
|
|
|
|
Renderer::registerComponent(this);
|
|
|
|
InputManager::registerComponent(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
GuiMenu::~GuiMenu()
|
|
|
|
{
|
|
|
|
Renderer::unregisterComponent(this);
|
|
|
|
InputManager::unregisterComponent(this);
|
|
|
|
|
|
|
|
delete mList;
|
|
|
|
mParent->resume();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiMenu::onInput(InputManager::InputButton button, bool keyDown)
|
|
|
|
{
|
|
|
|
if(button == InputManager::MENU && !keyDown)
|
|
|
|
{
|
|
|
|
if(!mSkippedMenuClose)
|
|
|
|
{
|
|
|
|
mSkippedMenuClose = true;
|
|
|
|
}else{
|
|
|
|
delete this;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-08-02 04:50:18 +00:00
|
|
|
|
|
|
|
if(button == InputManager::BUTTON1 && keyDown)
|
|
|
|
{
|
2012-11-14 15:07:09 +00:00
|
|
|
executeCommand(mList->getSelectedObject());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiMenu::executeCommand(std::string command)
|
|
|
|
{
|
|
|
|
if(command == "exit")
|
|
|
|
{
|
|
|
|
//push SDL quit event
|
|
|
|
SDL_Event* event = new SDL_Event();
|
|
|
|
event->type = SDL_QUIT;
|
|
|
|
SDL_PushEvent(event);
|
|
|
|
}else{
|
|
|
|
if(system(command.c_str()) != 0)
|
|
|
|
std::cout << "(warning: command terminated with nonzero result!)\n";
|
2012-08-02 04:50:18 +00:00
|
|
|
}
|
2012-08-02 04:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiMenu::populateList()
|
|
|
|
{
|
2012-08-02 04:50:18 +00:00
|
|
|
mList->clear();
|
2012-08-02 04:03:15 +00:00
|
|
|
|
2012-10-28 23:07:05 +00:00
|
|
|
//if you want to add your own commands to the menu, here is where you need to change!
|
|
|
|
//commands added here are called with system() when selected (so are executed as shell commands)
|
|
|
|
//the method is GuiList::addObject(std::string displayString, std::string commandString, unsigned int displayHexColor);
|
|
|
|
//the list will automatically adjust as items are added to it, this should be the only area you need to change
|
2012-11-14 15:07:09 +00:00
|
|
|
//if you want to do something special within ES, override your command in the executeComand() method
|
2012-10-17 18:21:56 +00:00
|
|
|
mList->addObject("Restart", "sudo shutdown -r now", 0x0000FFFF);
|
|
|
|
mList->addObject("Shutdown", "sudo shutdown -h now", 0x0000FFFF);
|
2012-12-18 15:20:13 +00:00
|
|
|
|
|
|
|
if(!DONTSHOWEXIT)
|
|
|
|
mList->addObject("Exit", "exit", 0xFF0000FF); //a special case; pushes an SDL quit event to the event stack instead of being called by system()
|
2012-08-02 04:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiMenu::onRender()
|
|
|
|
{
|
2012-08-16 15:26:36 +00:00
|
|
|
Renderer::drawRect(Renderer::getScreenWidth() * 0.25, 0, Renderer::getScreenWidth() * 0.5, Renderer::getScreenHeight(), 0x999999);
|
2012-08-02 04:03:15 +00:00
|
|
|
}
|