diff --git a/Makefile.common b/Makefile.common index abd6c087a..a7c8c7c5d 100644 --- a/Makefile.common +++ b/Makefile.common @@ -2,7 +2,7 @@ CXX=g++ CXXFLAGS=-Wall -g -O2 LDFLAGS= -SRC_SOURCES=AudioManager.cpp InputConfig.cpp Log.cpp FolderData.cpp Font.cpp GameData.cpp Gui.cpp InputManager.cpp main.cpp MathExp.cpp Renderer_draw_gl.cpp Renderer_init.cpp Sound.cpp SystemData.cpp XMLReader.cpp components/GuiAnimation.cpp components/GuiBox.cpp components/GuiFastSelect.cpp components/GuiGameList.cpp components/GuiImage.cpp components/GuiInputConfig.cpp components/GuiMenu.cpp components/GuiTheme.cpp pugiXML/pugixml.cpp +SRC_SOURCES=AudioManager.cpp Window.cpp InputConfig.cpp Log.cpp FolderData.cpp Font.cpp GameData.cpp Gui.cpp InputManager.cpp main.cpp MathExp.cpp Renderer_draw_gl.cpp Renderer_init.cpp Sound.cpp SystemData.cpp XMLReader.cpp components/GuiAnimation.cpp components/GuiBox.cpp components/GuiFastSelect.cpp components/GuiGameList.cpp components/GuiImage.cpp components/GuiInputConfig.cpp components/GuiMenu.cpp components/GuiTheme.cpp pugiXML/pugixml.cpp SOURCES=$(addprefix src/,$(SRC_SOURCES)) OBJECTS=$(SOURCES:.cpp=.o) DEPS=$(SOURCES:.cpp=.d) diff --git a/src/Gui.cpp b/src/Gui.cpp index a51730dc9..b36053d3a 100644 --- a/src/Gui.cpp +++ b/src/Gui.cpp @@ -9,3 +9,9 @@ Gui::~Gui() { mWindow->removeGui(this); } + +void Gui::setOffset(int x, int y) { mOffsetX = x; mOffsetY = y; } +void Gui::setOffsetX(int x) { mOffsetX = x; } +void Gui::setOffsetY(int y) { mOffsetY = y; } +int Gui::getOffsetX() { return mOffsetX; } +int Gui::getOffsetY() { return mOffsetY; } diff --git a/src/Gui.h b/src/Gui.h index 9053f4ae9..d8ba72dd8 100644 --- a/src/Gui.h +++ b/src/Gui.h @@ -14,7 +14,19 @@ public: virtual void input(InputConfig* config, Input input) { }; virtual void update(int deltaTime) { }; virtual void render() { }; + + virtual void init() { }; + virtual void deinit() { }; + + void setOffsetX(int x); + void setOffsetY(int y); + void setOffset(int x, int y); + int getOffsetX(); + int getOffsetY(); protected: + int mOffsetX; + int mOffsetY; + Window* mWindow; }; diff --git a/src/Renderer.h b/src/Renderer.h index 8250bba7a..c4fa2dacb 100644 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -14,16 +14,8 @@ class Font; //Defined in multiple files - Renderer.cpp has the GuiComponent stuff, Renderer_draw_* includes renderer-specific drawing implementations, and Renderer_init_* includes renderer-specific init/deinit. namespace Renderer { - void registerComponent(GuiComponent* comp); - void unregisterComponent(GuiComponent* comp); - void deleteAll(); - bool init(int w, int h); - void onInit(); void deinit(); - void onDeinit(); - - void render(); unsigned int getScreenWidth(); unsigned int getScreenHeight(); diff --git a/src/Renderer_init_sdlgl.cpp b/src/Renderer_init_sdlgl.cpp index b3306e3ba..6d15ebfba 100644 --- a/src/Renderer_init_sdlgl.cpp +++ b/src/Renderer_init_sdlgl.cpp @@ -80,14 +80,11 @@ namespace Renderer glOrtho(0, display_width, display_height, 0, -1.0, 1.0); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - onInit(); - return true; } void deinit() { - onDeinit(); destroySurface(); } }; diff --git a/src/Window.cpp b/src/Window.cpp index 4efcdd5dd..8ebefce7a 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -47,6 +47,22 @@ void Window::render() } } +void Window::init() +{ + 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(); + } +} + void Window::input(InputConfig* config, Input input) { if(peekGui()) @@ -63,8 +79,3 @@ InputManager* Window::getInputManager() { return mInputManager; } - -asIScriptEngine* Window::getScriptEngine() -{ - return mScriptEngine; -} diff --git a/src/Window.h b/src/Window.h index c54358f8e..cbabce33f 100644 --- a/src/Window.h +++ b/src/Window.h @@ -19,6 +19,9 @@ public: void update(int deltaTime); void render(); + void init(); + void deinit(); + InputManager* getInputManager(); private: diff --git a/src/components/GuiBox.cpp b/src/components/GuiBox.cpp index 07200f97d..6b51f6dc6 100644 --- a/src/components/GuiBox.cpp +++ b/src/components/GuiBox.cpp @@ -1,6 +1,7 @@ #include "GuiBox.h" -GuiBox::GuiBox(int offsetX, int offsetY, unsigned int width, unsigned int height) +GuiBox::GuiBox(Window* window, int offsetX, int offsetY, unsigned int width, unsigned int height) : Gui(window), mBackgroundImage(window), + mHorizontalImage(window), mVerticalImage(window), mCornerImage(window) { setOffsetX(offsetX); setOffsetY(offsetY); @@ -112,14 +113,10 @@ void GuiBox::render() void GuiBox::onInit() { - mHorizontalImage.init(); - mVerticalImage.init(); } void GuiBox::onDeinit() { - mHorizontalImage.deinit(); - mVerticalImage.deinit(); } int GuiBox::getHorizontalBorderWidth() diff --git a/src/components/GuiBox.h b/src/components/GuiBox.h index 5e781c5a6..cc164c21c 100644 --- a/src/components/GuiBox.h +++ b/src/components/GuiBox.h @@ -16,10 +16,10 @@ struct GuiBoxData std::string cornerPath; }; -class GuiBox +class GuiBox : public Gui { public: - GuiBox(int offsetX, int offsetY, unsigned int width, unsigned int height); + GuiBox(Window* window, int offsetX, int offsetY, unsigned int width, unsigned int height); void setData(GuiBoxData data); diff --git a/src/components/GuiFastSelect.cpp b/src/components/GuiFastSelect.cpp index 75f1f7f43..321edfb40 100644 --- a/src/components/GuiFastSelect.cpp +++ b/src/components/GuiFastSelect.cpp @@ -1,12 +1,13 @@ #include "GuiFastSelect.h" #include "../Renderer.h" #include +#include "GuiGameList.h" const std::string GuiFastSelect::LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const int GuiFastSelect::SCROLLSPEED = 100; const int GuiFastSelect::SCROLLDELAY = 507; -GuiFastSelect::GuiFastSelect(Window* window, GuiComponent* parent, GuiList* list, char startLetter, GuiBoxData data, +GuiFastSelect::GuiFastSelect(Window* window, GuiGameList* parent, GuiList* list, char startLetter, GuiBoxData data, int textcolor, Sound* scrollsound, Font* font) : Gui(window) { mLetterID = LETTERS.find(toupper(startLetter)); @@ -23,7 +24,7 @@ GuiFastSelect::GuiFastSelect(Window* window, GuiComponent* parent, GuiListsetData(data); mTextColor = textcolor; @@ -31,6 +32,7 @@ GuiFastSelect::GuiFastSelect(Window* window, GuiComponent* parent, GuiListupdateDetailData(); delete mBox; } diff --git a/src/components/GuiFastSelect.h b/src/components/GuiFastSelect.h index 37d73996c..95720b081 100644 --- a/src/components/GuiFastSelect.h +++ b/src/components/GuiFastSelect.h @@ -8,10 +8,12 @@ #include "GuiList.h" #include "GuiBox.h" +class GuiGameList; + class GuiFastSelect : Gui { public: - GuiFastSelect(Window* window, GuiComponent* parent, GuiList* list, char startLetter, GuiBoxData data, int textcolor, Sound* scrollsound, Font* font); + GuiFastSelect(Window* window, GuiGameList* parent, GuiList* list, char startLetter, GuiBoxData data, int textcolor, Sound* scrollsound, Font* font); ~GuiFastSelect(); void input(InputConfig* config, Input input); @@ -29,7 +31,7 @@ private: GuiList* mList; size_t mLetterID; - GuiComponent* mParent; + GuiGameList* mParent; GuiBox* mBox; int mTextColor; diff --git a/src/components/GuiGameList.cpp b/src/components/GuiGameList.cpp index c317f05ca..18c870dac 100644 --- a/src/components/GuiGameList.cpp +++ b/src/components/GuiGameList.cpp @@ -22,11 +22,10 @@ GuiGameList::GuiGameList(Window* window, bool useDetail) : Gui(window) mScreenshot = new GuiImage(mWindow, Renderer::getScreenWidth() * mTheme->getFloat("gameImageOffsetX"), Renderer::getScreenHeight() * mTheme->getFloat("gameImageOffsetY"), "", mTheme->getFloat("gameImageWidth"), mTheme->getFloat("gameImageHeight"), false); mScreenshot->setOrigin(mTheme->getFloat("gameImageOriginX"), mTheme->getFloat("gameImageOriginY")); - //the animation renders the screenshot mImageAnimation = new GuiAnimation(); mImageAnimation->addChild(mScreenshot); }else{ - mList = new GuiList(0, Renderer::getDefaultFont(Renderer::LARGE)->getHeight() + 2, Renderer::getDefaultFont(Renderer::MEDIUM)); + mList = new GuiList(mWindow, 0, Renderer::getDefaultFont(Renderer::LARGE)->getHeight() + 2, Renderer::getDefaultFont(Renderer::MEDIUM)); mScreenshot = NULL; mImageAnimation = NULL; } @@ -97,7 +96,11 @@ void GuiGameList::render() if(!desc.empty()) Renderer::drawWrappedText(desc, Renderer::getScreenWidth() * 0.03, mScreenshot->getOffsetY() + mScreenshot->getHeight() + 12, Renderer::getScreenWidth() * (mTheme->getFloat("listOffsetX") - 0.03), mTheme->getColor("description"), mTheme->getDescriptionFont()); } + + mScreenshot->render(); } + + mList->render(); } void GuiGameList::input(InputConfig* config, Input input) @@ -119,7 +122,7 @@ void GuiGameList::input(InputConfig* config, Input input) //wait for the sound to finish or we'll never hear it... while(mTheme->getSound("menuSelect")->isPlaying()); - mSystem->launchGame((GameData*)file); + mSystem->launchGame(mWindow, (GameData*)file); } } @@ -151,7 +154,7 @@ void GuiGameList::input(InputConfig* config, Input input) //open the "start menu" if(config->isMappedTo("menu", input) && input.value != 0) { - new GuiMenu(this); + new GuiMenu(mWindow, this); } //open the fast select menu @@ -297,5 +300,7 @@ GuiGameList* GuiGameList::create(Window* window) } } - return new GuiGameList(window, detailed); + GuiGameList* list = new GuiGameList(window, detailed); + window->pushGui(list); + return list; } diff --git a/src/components/GuiGameList.h b/src/components/GuiGameList.h index 1aa9f0cd5..22a1fa57b 100644 --- a/src/components/GuiGameList.h +++ b/src/components/GuiGameList.h @@ -17,7 +17,7 @@ class GuiGameList : public Gui { public: - GuiGameList(bool useDetail = false); + GuiGameList(Window* window, bool useDetail = false); ~GuiGameList(); void setSystemId(int id); @@ -28,13 +28,14 @@ public: void onInit(); void onDeinit(); + void updateDetailData(); + static GuiGameList* create(Window* window); static const float sInfoWidth; private: void updateList(); void updateTheme(); - void updateDetailData(); void clearDetailData(); std::string getThemeFile(); diff --git a/src/components/GuiImage.cpp b/src/components/GuiImage.cpp index bc261c7ae..6ed084ed4 100644 --- a/src/components/GuiImage.cpp +++ b/src/components/GuiImage.cpp @@ -3,16 +3,16 @@ #include #include #include "../Log.h" +#include "../Renderer.h" unsigned int GuiImage::getWidth() { return mDrawWidth; } unsigned int GuiImage::getHeight() { return mDrawHeight; } -GuiImage::GuiImage(GuiWindow* window, int offsetX, int offsetY, std::string path, unsigned int resizeWidth, unsigned int resizeHeight, bool resizeExact) : Gui(window) +GuiImage::GuiImage(Window* window, int offsetX, int offsetY, std::string path, unsigned int resizeWidth, unsigned int resizeHeight, bool resizeExact) : Gui(window) { mTextureID = 0; - mOffsetX = offsetX; - mOffsetY = offsetY; + setOffset(offsetX, offsetY); //default origin is the center of image mOriginX = 0.5; @@ -369,8 +369,5 @@ bool GuiImage::hasImage() return !mPath.empty(); } -int GuiImage::getOffsetX() { return mOffsetX; } -int GuiImage::getOffsetY() { return mOffsetY; } unsigned char GuiImage::getOpacity() { return mOpacity; } -void GuiImage::setOffset(int x, int y) { mOffsetX = x; mOffsetY = y; } void GuiImage::setOpacity(unsigned char opacity) { mOpacity = opacity; } diff --git a/src/components/GuiImage.h b/src/components/GuiImage.h index ff7291700..e0f0d6413 100644 --- a/src/components/GuiImage.h +++ b/src/components/GuiImage.h @@ -35,11 +35,8 @@ public: void onInit(); void onDeinit(); - int getOffsetX(); - int getOffsetY(); unsigned char getOpacity(); void setOpacity(unsigned char opacity); - void setOffset(int x, int y); private: unsigned int mResizeWidth, mResizeHeight; float mOriginX, mOriginY; diff --git a/src/components/GuiInputConfig.cpp b/src/components/GuiInputConfig.cpp index f8fe4d681..7f1077171 100644 --- a/src/components/GuiInputConfig.cpp +++ b/src/components/GuiInputConfig.cpp @@ -11,47 +11,15 @@ int GuiInputConfig::sInputCount = 10; GuiInputConfig::GuiInputConfig(Window* window) : Gui(window) { - mInputNum = 0; - mDone = false; - - if(SDL_NumJoysticks() < 1) - { - std::cerr << "Error - GuiInputConfig found no SDL joysticks!\n"; - mJoystick = NULL; - mDone = true; - return; - }else{ - LOG(LogInfo) << "Opening joystick \"" << SDL_JoystickName(0) << "\" for configuration..."; - mJoystick = SDL_JoystickOpen(0); - } - - SDL_JoystickEventState(SDL_ENABLE); } GuiInputConfig::~GuiInputConfig() { } -void GuiInputConfig::onRender() +void GuiInputConfig::render() { - Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0xFFFFFFFF); - - Font* font = Renderer::getDefaultFont(Renderer::MEDIUM); - - int height = font->getHeight() + 6; - - - Renderer::drawCenteredText("It looks like you have a joystick plugged in!", 0, 2, 0x000000FF, font); - Renderer::drawCenteredText("POV hats (some D-Pads) are automatically mapped to directions.", 0, height, 0x000000FF, font); - Renderer::drawCenteredText("You can press a keyboard key to skip any input.", 0, height * 2, 0x000000FF, font); - Renderer::drawCenteredText("If you want to remap later, delete ~/.emulationstation/es_input.cfg.", 0, height * 3, 0x000000FF, font); - Renderer::drawCenteredText("This interface only configures the first joystick plugged in.", 0, height * 4, 0x000000FF, font); - Renderer::drawCenteredText("Remember - you'll need to set up your emulator separately!", 0, Renderer::getScreenHeight() - height, 0x000000FF, font); - - if(mDone) - Renderer::drawCenteredText("All done! Press a key or button to save.", 0, height * 5, 0x00BB00FF, font); - else - Renderer::drawCenteredText("Please press the axis/button for " + sInputs[mInputNum], 0, height * 5, 0x00C000FF, font); + Renderer::drawCenteredText("IN DEVELOPMENT", 0, 2, 0x000000FF, Renderer::getDefaultFont(Renderer::MEDIUM)); } void GuiInputConfig::input(InputConfig* config, Input input) diff --git a/src/components/GuiTheme.cpp b/src/components/GuiTheme.cpp index 4981d2b30..a871c7c0a 100644 --- a/src/components/GuiTheme.cpp +++ b/src/components/GuiTheme.cpp @@ -147,8 +147,6 @@ void GuiTheme::deleteComponents() mComponentVector.clear(); - clearChildren(); - //deletes fonts if any were created setDefaults(); } @@ -260,11 +258,11 @@ void GuiTheme::readXML(std::string path) } //recursively creates components (with proper parenting) -void GuiTheme::createComponentChildren(pugi::xml_node node, GuiComponent* parent) +void GuiTheme::createComponentChildren(pugi::xml_node node, Gui* parent) { for(pugi::xml_node data = node.child("component"); data; data = data.next_sibling("component")) { - GuiComponent* nextComp = createElement(data, parent); + Gui* nextComp = createElement(data, parent); if(nextComp) createComponentChildren(data, nextComp); @@ -272,7 +270,7 @@ void GuiTheme::createComponentChildren(pugi::xml_node node, GuiComponent* parent } //takes an XML element definition and creates an object from it -GuiComponent* GuiTheme::createElement(pugi::xml_node data, GuiComponent* parent) +Gui* GuiTheme::createElement(pugi::xml_node data, Gui* parent) { std::string type = data.child("type").text().get(); @@ -316,7 +314,6 @@ GuiComponent* GuiTheme::createElement(pugi::xml_node data, GuiComponent* parent) comp->setTiling(tiled); comp->setImage(path); - parent->addChild(comp); mComponentVector.push_back(comp); return comp; } @@ -426,3 +423,11 @@ Font* GuiTheme::resolveFont(pugi::xml_node node, std::string defaultPath, unsign return new Font(path, size); } + +void GuiTheme::render() +{ + for(unsigned int i = 0; i < mComponentVector.size(); i++) + { + mComponentVector.at(i)->render(); + } +} diff --git a/src/components/GuiTheme.h b/src/components/GuiTheme.h index 23563ab89..30382e495 100644 --- a/src/components/GuiTheme.h +++ b/src/components/GuiTheme.h @@ -7,8 +7,8 @@ #include "../Sound.h" #include "../Font.h" -//This class loads an XML-defined list of GuiComponents. -class GuiTheme : Gui +//This class loads an XML-defined list of Guis. +class GuiTheme : public Gui { public: GuiTheme(Window* window, bool detailed, std::string path = ""); @@ -18,6 +18,8 @@ public: GuiBoxData getBoxData(); + void render(); + unsigned int getColor(std::string name); bool getBool(std::string name); float getFloat(std::string name); @@ -30,8 +32,8 @@ public: private: void setDefaults(); void deleteComponents(); - void createComponentChildren(pugi::xml_node node, GuiComponent* parent); - GuiComponent* createElement(pugi::xml_node data, GuiComponent* parent); + void createComponentChildren(pugi::xml_node node, Gui* parent); + Gui* createElement(pugi::xml_node data, Gui* parent); //utility functions std::string expandPath(std::string path);