From aea93748d581d5ef4bf70fe5fa386a231259f5d2 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Fri, 5 Oct 2012 15:04:12 -0500 Subject: [PATCH] Began working on GuiBox for theming of boxes (a revolutionary concept). --- Makefile | 2 +- Makefile.x86 | 2 +- changelog.txt | 1 + src/GuiComponent.cpp | 2 +- src/GuiComponent.h | 1 + src/components/GuiBox.cpp | 53 ++++++++++++++++++++++++++++++++ src/components/GuiBox.h | 27 ++++++++++++++++ src/components/GuiFastSelect.cpp | 12 +++++++- src/components/GuiFastSelect.h | 3 ++ src/components/GuiGameList.cpp | 1 + src/components/GuiImage.cpp | 40 ++++++++++++++++-------- src/components/GuiImage.h | 3 ++ 12 files changed, 130 insertions(+), 17 deletions(-) create mode 100644 src/components/GuiBox.cpp create mode 100644 src/components/GuiBox.h diff --git a/Makefile b/Makefile index cb30a62c8..c2f129209 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CC=g++ CFLAGS=-c -Wall -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/usr/include/freetype2 -I/usr/include/SDL -I/usr/include -D_RPI_ LDFLAGS=-L/opt/vc/lib -lbcm_host -lEGL -lGLESv2 -lfreetype -lSDL -lboost_system -lboost_filesystem -lfreeimage -SRCSOURCES=main.cpp Renderer.cpp Renderer_init.cpp Font.cpp Renderer_draw_gl.cpp GuiComponent.cpp InputManager.cpp SystemData.cpp GameData.cpp FolderData.cpp XMLReader.cpp MathExp.cpp components/GuiGameList.cpp components/GuiInputConfig.cpp components/GuiImage.cpp components/GuiMenu.cpp components/GuiTheme.cpp components/GuiFastSelect.cpp pugiXML/pugixml.cpp +SRCSOURCES=main.cpp Renderer.cpp Renderer_init.cpp Font.cpp Renderer_draw_gl.cpp GuiComponent.cpp InputManager.cpp SystemData.cpp GameData.cpp FolderData.cpp XMLReader.cpp MathExp.cpp components/GuiGameList.cpp components/GuiInputConfig.cpp components/GuiImage.cpp components/GuiMenu.cpp components/GuiTheme.cpp components/GuiFastSelect.cpp components/GuiBox.cpp pugiXML/pugixml.cpp SOURCES=$(addprefix src/,$(SRCSOURCES)) OBJECTS=$(SOURCES:.cpp=.o) EXECUTABLE=emulationstation diff --git a/Makefile.x86 b/Makefile.x86 index 7f5e3f077..f8147540c 100644 --- a/Makefile.x86 +++ b/Makefile.x86 @@ -1,7 +1,7 @@ CC=g++ CFLAGS=-c -Wall -I/usr/include/freetype2 -I/usr/include/SDL -I/usr/include -D_DESKTOP_ -g LDFLAGS=-lGL -lfreetype -lSDL -lboost_system -lboost_filesystem -lfreeimage -SRCSOURCES=main.cpp Renderer.cpp Renderer_init.cpp Font.cpp Renderer_draw_gl.cpp GuiComponent.cpp InputManager.cpp SystemData.cpp GameData.cpp FolderData.cpp XMLReader.cpp MathExp.cpp components/GuiGameList.cpp components/GuiInputConfig.cpp components/GuiImage.cpp components/GuiMenu.cpp components/GuiTheme.cpp components/GuiFastSelect.cpp pugiXML/pugixml.cpp +SRCSOURCES=main.cpp Renderer.cpp Renderer_init.cpp Font.cpp Renderer_draw_gl.cpp GuiComponent.cpp InputManager.cpp SystemData.cpp GameData.cpp FolderData.cpp XMLReader.cpp MathExp.cpp components/GuiGameList.cpp components/GuiInputConfig.cpp components/GuiImage.cpp components/GuiMenu.cpp components/GuiTheme.cpp components/GuiFastSelect.cpp components/GuiBox.cpp pugiXML/pugixml.cpp SOURCES=$(addprefix src/,$(SRCSOURCES)) OBJECTS=$(SOURCES:.cpp=.o) EXECUTABLE=emulationstation diff --git a/changelog.txt b/changelog.txt index 669ad0f45..91234562b 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,6 @@ October 5 -GuiFastSelect is working, but ugly. +-Began work on GuiBox for theming the fast select dialog. September 30 -Began implementing GuiFastSelect, currently invoked by holding F2. Unfortunately, it doesn't do anything yet. diff --git a/src/GuiComponent.cpp b/src/GuiComponent.cpp index fbf0f19f4..93cdd956a 100644 --- a/src/GuiComponent.cpp +++ b/src/GuiComponent.cpp @@ -35,7 +35,7 @@ void GuiComponent::removeChild(GuiComponent* comp) if(mChildren.at(i) == comp) { mChildren.erase(mChildren.begin() + i); - break; + return; } } diff --git a/src/GuiComponent.h b/src/GuiComponent.h index 3d031abad..b56db5dd6 100644 --- a/src/GuiComponent.h +++ b/src/GuiComponent.h @@ -51,6 +51,7 @@ public: void setOffsetY(int val); static void processTicks(int deltaTime); + private: int mOffsetX, mOffsetY; diff --git a/src/components/GuiBox.cpp b/src/components/GuiBox.cpp new file mode 100644 index 000000000..9a617666c --- /dev/null +++ b/src/components/GuiBox.cpp @@ -0,0 +1,53 @@ +#include "GuiBox.h" + +GuiBox::GuiBox(int offsetX, int offsetY, unsigned int width, unsigned int height) +{ + setOffsetX(offsetX); + setOffsetY(offsetY); + + mWidth = width; + mHeight = height; +} + +void GuiBox::setHorizontalImage(std::string path, bool tiled) +{ + mHorizontalImage.setImage(path); +} + +void GuiBox::setVerticalImage(std::string path, bool tiled) +{ + mVerticalImage.setImage(path); +} + +void GuiBox::setBackgroundImage(std::string path, bool tiled) +{ + mBackgroundImage.setImage(path); + mBackgroundImage.setTiling(tiled); +} + +void GuiBox::onRender() +{ + //left border + mHorizontalImage.setOffsetX(getOffsetX()); + mHorizontalImage.setOffsetY(getOffsetY()); + mHorizontalImage.setOrigin(0.5, 0); + mHorizontalImage.setResize(12, mHeight, true); + mHorizontalImage.render(); + + //right border + mHorizontalImage.setOffsetX(getOffsetX() + mWidth); + mHorizontalImage.setOffsetY(getOffsetY()); + mHorizontalImage.render(); +} + +void GuiBox::onInit() +{ + mHorizontalImage.init(); + mVerticalImage.init(); +} + +void GuiBox::onDeinit() +{ + mHorizontalImage.deinit(); + mVerticalImage.deinit(); +} diff --git a/src/components/GuiBox.h b/src/components/GuiBox.h new file mode 100644 index 000000000..720880341 --- /dev/null +++ b/src/components/GuiBox.h @@ -0,0 +1,27 @@ +#ifndef _GUIBOX_H_ +#define _GUIBOX_H_ + +#include "../GuiComponent.h" +#include "GuiImage.h" +#include + +class GuiBox : public GuiComponent +{ +public: + GuiBox(int offsetX, int offsetY, unsigned int width, unsigned int height); + + void setBackgroundImage(std::string path, bool tiled = true); + void setHorizontalImage(std::string path, bool tiled = false); + void setVerticalImage(std::string path, bool tiled = false); + + void onRender(); + + void onInit(); + void onDeinit(); +private: + GuiImage mBackgroundImage, mHorizontalImage, mVerticalImage; + + unsigned int mWidth, mHeight; +}; + +#endif diff --git a/src/components/GuiFastSelect.cpp b/src/components/GuiFastSelect.cpp index ac214c8de..980663ec7 100644 --- a/src/components/GuiFastSelect.cpp +++ b/src/components/GuiFastSelect.cpp @@ -22,6 +22,13 @@ GuiFastSelect::GuiFastSelect(GuiComponent* parent, GuiList* list, cha mScrollTimer = 0; mScrollOffset = 0; + unsigned int sw = Renderer::getScreenWidth(), sh = Renderer::getScreenHeight(); + mBox = new GuiBox(sw * 0.2, sh * 0.2, sw * 0.6, sh * 0.6); + addChild(mBox); + + //set test mBox info + //mBox->setHorizontalImage("test.jpg"); + mParent->pause(); } @@ -30,12 +37,15 @@ GuiFastSelect::~GuiFastSelect() Renderer::unregisterComponent(this); InputManager::unregisterComponent(this); + removeChild(mBox); + delete mBox; + mParent->resume(); } void GuiFastSelect::onRender() { - int sw = Renderer::getScreenWidth(), sh = Renderer::getScreenHeight(); + unsigned int sw = Renderer::getScreenWidth(), sh = Renderer::getScreenHeight(); Renderer::drawRect(sw * 0.2, sh * 0.2, sw * 0.6, sh * 0.6, 0x000FF0); Renderer::drawCenteredText(LETTERS.substr(mLetterID, 1), 0, sh * 0.5 - (Renderer::getFontHeight(Renderer::LARGE) * 0.5), 0xFF0000, Renderer::LARGE); diff --git a/src/components/GuiFastSelect.h b/src/components/GuiFastSelect.h index e0064fd94..dffda4bf0 100644 --- a/src/components/GuiFastSelect.h +++ b/src/components/GuiFastSelect.h @@ -5,6 +5,7 @@ #include "../SystemData.h" #include "../FolderData.h" #include "GuiList.h" +#include "GuiBox.h" class GuiFastSelect : GuiComponent { @@ -29,6 +30,8 @@ private: size_t mLetterID; GuiComponent* mParent; + GuiBox* mBox; + int mScrollTimer, mScrollOffset; bool mScrolling; }; diff --git a/src/components/GuiGameList.cpp b/src/components/GuiGameList.cpp index fc2868487..0ef3a650d 100644 --- a/src/components/GuiGameList.cpp +++ b/src/components/GuiGameList.cpp @@ -236,6 +236,7 @@ void GuiGameList::onPause() void GuiGameList::onResume() { + updateDetailData(); InputManager::registerComponent(this); } diff --git a/src/components/GuiImage.cpp b/src/components/GuiImage.cpp index a250ccd9b..54c262570 100644 --- a/src/components/GuiImage.cpp +++ b/src/components/GuiImage.cpp @@ -17,8 +17,8 @@ GuiImage::GuiImage(int offsetX, int offsetY, std::string path, unsigned int resi mOriginX = 0.5; mOriginY = 0.5; - mWidth = 0; - mHeight = 0; + mWidth = mDrawWidth = 0; + mHeight = mDrawHeight = 0; mTiled = false; @@ -160,6 +160,14 @@ void GuiImage::loadImage(std::string path) //free the memory from that pointer delete[] imageRGBA; + resize(); +} + +void GuiImage::resize() +{ + mDrawWidth = mWidth; + mDrawHeight = mHeight; + //(we don't resize tiled images) if(!mTiled) { @@ -184,12 +192,10 @@ void GuiImage::loadImage(std::string path) resizeScaleX = resizeScaleY; if(resizeScaleX) - mWidth *= resizeScaleX; + mDrawWidth *= resizeScaleX; if(resizeScaleY) - mHeight *= resizeScaleY; + mDrawHeight *= resizeScaleY; } - - //std::cout << "Image load successful, w: " << mWidth << " h: " << mHeight << " texID: " << mTextureID << "\n"; } void GuiImage::unloadImage() @@ -229,6 +235,14 @@ void GuiImage::setTiling(bool tile) mResizeExact = false; } +void GuiImage::setResize(unsigned int width, unsigned int height, bool resizeExact) +{ + mResizeWidth = width; + mResizeHeight = height; + mResizeExact = resizeExact; + resize(); +} + void GuiImage::onRender() { if(mTextureID) @@ -246,7 +260,7 @@ void GuiImage::onRender() { for(unsigned int y = 0; y < yCount; y++) { - buildImageArray(getOffsetX() + x*mWidth, getOffsetY() + y*mHeight, points + (12 * (x*yCount + y)), texs + (12 * (x*yCount + y))); + buildImageArray(getOffsetX() + x*mDrawWidth, getOffsetY() + y*mDrawHeight, points + (12 * (x*yCount + y)), texs + (12 * (x*yCount + y))); } } drawImageArray(points, texs, xCount * yCount * 6); @@ -262,13 +276,13 @@ void GuiImage::onRender() void GuiImage::buildImageArray(int posX, int posY, GLfloat* points, GLfloat* texs) { - points[0] = posX - (mWidth * mOriginX); points[1] = posY - (mHeight * mOriginY); - points[2] = posX - (mWidth * mOriginX); points[3] = posY + (mHeight * (1 - mOriginY)); - points[4] = posX + (mWidth * (1 - mOriginX)); points[5] = posY - (mHeight * mOriginY); + points[0] = posX - (mDrawWidth * mOriginX); points[1] = posY - (mDrawHeight * mOriginY); + points[2] = posX - (mDrawWidth * mOriginX); points[3] = posY + (mDrawHeight * (1 - mOriginY)); + points[4] = posX + (mDrawWidth * (1 - mOriginX)); points[5] = posY - (mDrawHeight * mOriginY); - points[6] = posX + (mWidth * (1 - mOriginX)); points[7] = posY - (mHeight * mOriginY); - points[8] = posX - (mWidth * mOriginX); points[9] = posY + (mHeight * (1 - mOriginY)); - points[10] = posX + (mWidth * (1 -mOriginX)); points[11] = posY + (mHeight * (1 - mOriginY)); + points[6] = posX + (mDrawWidth * (1 - mOriginX)); points[7] = posY - (mDrawHeight * mOriginY); + points[8] = posX - (mDrawWidth * mOriginX); points[9] = posY + (mDrawHeight * (1 - mOriginY)); + points[10] = posX + (mDrawWidth * (1 -mOriginX)); points[11] = posY + (mDrawHeight * (1 - mOriginY)); diff --git a/src/components/GuiImage.h b/src/components/GuiImage.h index 32b76f17b..cb8a38573 100644 --- a/src/components/GuiImage.h +++ b/src/components/GuiImage.h @@ -19,6 +19,7 @@ public: void setImage(std::string path); //Loads the image at the given filepath. void setOrigin(float originX, float originY); //Sets the origin as a percentage of this image (e.g. (0, 0) is top left, (0.5, 0.5) is the center) void setTiling(bool tile); //Enables or disables tiling. Must be called before loading an image or resizing will be weird. + void setResize(unsigned int width, unsigned int height, bool resizeExact); unsigned int getWidth(); //Returns render width in pixels. May be different than actual texture width. unsigned int getHeight(); //Returns render height in pixels. May be different than actual texture height. @@ -35,6 +36,7 @@ private: bool mResizeExact, mTiled; void loadImage(std::string path); + void resize(); void buildImageArray(int x, int y, GLfloat* points, GLfloat* texs); //writes 12 GLfloat points and 12 GLfloat texture coordinates to a given array at a given position void drawImageArray(GLfloat* points, GLfloat* texs, unsigned int count = 6); //draws the given set of points and texture coordinates, number of coordinate pairs may be specified (default 6) void unloadImage(); @@ -42,6 +44,7 @@ private: std::string mPath; unsigned int mWidth, mHeight; //Our rendered size. + unsigned int mDrawWidth, mDrawHeight; GLuint mTextureID; };