Initial GuiAnimation added.

This commit is contained in:
Aloshi 2012-10-17 12:15:58 -05:00
parent dd7a77c96a
commit 358658a36d
19 changed files with 198 additions and 46 deletions

View file

@ -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 -lSDL_mixer
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 AudioManager.cpp Sound.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 components/GuiAnimation.cpp AudioManager.cpp Sound.cpp pugiXML/pugixml.cpp
SOURCES=$(addprefix src/,$(SRCSOURCES))
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=emulationstation

View file

@ -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 -lSDL_mixer
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 Sound.cpp AudioManager.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 components/GuiAnimation.cpp Sound.cpp AudioManager.cpp pugiXML/pugixml.cpp
SOURCES=$(addprefix src/,$(SRCSOURCES))
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=emulationstation

View file

@ -1,3 +1,7 @@
October 17
-Added GuiAnimation class which animates its children.
-The game image on the game list now slides/fades in and out.
October 14
-Fixed game list continuing to scroll when a menu is opened or a game is started.

View file

@ -165,7 +165,7 @@ struct tex {
GLfloat tex2y;
};
void Font::drawText(std::string text, int startx, int starty, int color)
void Font::drawText(std::string text, int startx, int starty, int color, char opacity)
{
starty += mMaxGlyphHeight;
@ -224,7 +224,7 @@ void Font::drawText(std::string text, int startx, int starty, int color)
x += charData[letter].advX;
}
Renderer::buildGLColorArray(colors, color, pointCount * 3);
Renderer::buildGLColorArray(colors, color, opacity, pointCount * 3);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

View file

@ -35,7 +35,7 @@ public:
GLuint textureID;
void drawText(std::string text, int startx, int starty, int color); //Render some text using this font.
void drawText(std::string text, int startx, int starty, int color, char opacity); //Render some text using this font.
void sizeText(std::string text, int* w, int* h); //Sets the width and height of a given string to given pointers. Skipped if pointer is NULL.
private:

View file

@ -10,6 +10,7 @@ GuiComponent::GuiComponent()
mOffsetX = 0;
mOffsetY = 0;
mOpacity = 255;
}
GuiComponent::~GuiComponent()
@ -103,5 +104,9 @@ void GuiComponent::deinit()
void GuiComponent::setOffsetX(int val) { mOffsetX = val; }
void GuiComponent::setOffsetY(int val) { mOffsetY = val; }
void GuiComponent::setOffset(int x, int y) { mOffsetX = x; mOffsetY = y; }
int GuiComponent::getOffsetX() { return mOffsetX; }
int GuiComponent::getOffsetY() { return mOffsetY; }
void GuiComponent::setOpacity(unsigned char opacity) { mOpacity = opacity; }
unsigned char GuiComponent::getOpacity() { return mOpacity; }

View file

@ -49,12 +49,18 @@ public:
int getOffsetY();
void setOffsetX(int val);
void setOffsetY(int val);
void setOffset(int x, int y);
unsigned char getOpacity();
void setOpacity(unsigned char opacity);
static void processTicks(int deltaTime);
private:
int mOffsetX, mOffsetY;
unsigned char mOpacity;
static std::vector<GuiComponent*> sComponentVector;
std::vector<GuiComponent*> mChildren;
};

View file

@ -27,14 +27,14 @@ namespace Renderer
enum FontSize { SMALL, MEDIUM, LARGE };
int getFontHeight(FontSize size); //sometimes font size is needed before fonts have been loaded; this takes care of that
void buildGLColorArray(GLubyte* ptr, int color, unsigned int vertCount);
void buildGLColorArray(GLubyte* ptr, int color, unsigned char opacity, unsigned int vertCount);
//drawing commands
void swapBuffers();
void drawRect(int x, int y, int w, int h, int color);
void drawText(std::string text, int x, int y, int color, FontSize fontsize = MEDIUM);
void drawCenteredText(std::string text, int xOffset, int y, int color, FontSize fontsize = MEDIUM);
void drawWrappedText(std::string text, int xStart, int yStart, int xLen, int color, FontSize fontsize = MEDIUM);
void drawRect(int x, int y, int w, int h, int color, unsigned char opacity = 255);
void drawText(std::string text, int x, int y, int color, unsigned char opacity = 255, FontSize fontsize = MEDIUM);
void drawCenteredText(std::string text, int xOffset, int y, int color, unsigned char opacity = 255, FontSize fontsize = MEDIUM);
void drawWrappedText(std::string text, int xStart, int yStart, int xLen, int color, unsigned char opacity = 255, FontSize fontsize = MEDIUM);
}
#endif

View file

@ -8,24 +8,24 @@
namespace Renderer {
bool loadedFonts = false;
void setColor4bArray(GLubyte* array, int color)
void setColor4bArray(GLubyte* array, int color, unsigned char opacity)
{
array[0] = (color & 0x00ff0000) / 0x10000;
array[1] = (color & 0x0000ff00) / 0x100;
array[2] = (color & 0x000000ff);
array[3] = 255;
array[3] = opacity;
}
void buildGLColorArray(GLubyte* ptr, int color, unsigned int vertCount)
void buildGLColorArray(GLubyte* ptr, int color, unsigned char opacity, unsigned int vertCount)
{
for(unsigned int i = 0; i < vertCount; i++)
{
setColor4bArray(ptr, color);
setColor4bArray(ptr, color, opacity);
ptr += 4;
}
}
void drawRect(int x, int y, int w, int h, int color)
void drawRect(int x, int y, int w, int h, int color, unsigned char opacity)
{
GLfloat points[12];
@ -38,7 +38,7 @@ namespace Renderer {
points[10] = x + w; points[11] = y + h;
GLubyte colors[6*4];
buildGLColorArray(colors, color, 6);
buildGLColorArray(colors, color, opacity, 6);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
@ -119,7 +119,7 @@ namespace Renderer {
return h;
}
void drawText(std::string text, int x, int y, int color, FontSize font)
void drawText(std::string text, int x, int y, int color, unsigned char opacity, FontSize font)
{
if(!loadedFonts)
loadFonts();
@ -127,10 +127,10 @@ namespace Renderer {
//if(x < 0)
// std::cout << "drawing at " << x << std::endl;
getFont(font)->drawText(text, x, y, color);
getFont(font)->drawText(text, x, y, color, opacity);
}
void drawCenteredText(std::string text, int xOffset, int y, int color, FontSize fontsize)
void drawCenteredText(std::string text, int xOffset, int y, int color, unsigned char opacity, FontSize fontsize)
{
if(!loadedFonts)
loadFonts();
@ -145,12 +145,12 @@ namespace Renderer {
x += xOffset * 0.5;
drawText(text, x, y, color, fontsize);
drawText(text, x, y, color, opacity, fontsize);
}
//this could probably be optimized
//draws text and ensures it's never longer than xLen
void drawWrappedText(std::string text, int xStart, int yStart, int xLen, int color, FontSize fontsize)
void drawWrappedText(std::string text, int xStart, int yStart, int xLen, int color, unsigned char opacity, FontSize fontsize)
{
if(!loadedFonts)
loadFonts();
@ -199,7 +199,7 @@ namespace Renderer {
{
//render line now
if(w > 0) //make sure it's not blank
drawText(line, xStart, y, color, fontsize);
drawText(line, xStart, y, color, opacity, fontsize);
//increment y by height and some extra padding for the next line
y += h + 4;

View file

@ -32,7 +32,7 @@ namespace Renderer
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
sdlScreen = SDL_SetVideoMode(display_width, display_height, 16, SDL_OPENGL | SDL_FULLSCREEN);
sdlScreen = SDL_SetVideoMode(display_width, display_height, 16, SDL_OPENGL | SDL_FULLSCREEN | SDL_DOUBLEBUF);
if(sdlScreen == NULL)
{

View file

@ -0,0 +1,87 @@
#include "GuiAnimation.h"
GuiAnimation::GuiAnimation()
{
mMoveX = 0;
mMoveY = 0;
mMoveSpeed = 0;
mFadeRate = 0;
}
void GuiAnimation::move(int x, int y, int speed)
{
mMoveX = x;
mMoveY = y;
mMoveSpeed = speed;
}
void GuiAnimation::fadeIn(int time)
{
setOpacity(0);
setChildrenOpacity(0);
mFadeRate = time;
}
void GuiAnimation::fadeOut(int time)
{
setOpacity(255);
setChildrenOpacity(255);
mFadeRate = -time;
}
void GuiAnimation::onTick(int deltaTime)
{
float mult = deltaTime * 0.05;
if(mMoveX != 0 || mMoveY != 0)
{
int offsetx = (mMoveX > mMoveSpeed) ? mMoveSpeed : mMoveX;
int offsety = (mMoveY > mMoveSpeed) ? mMoveSpeed : mMoveY;
offsetx *= mult;
offsety *= mult;
moveChildren(offsetx, offsety);
mMoveX -= offsetx;
mMoveY -= offsety;
}
if(mFadeRate != 0)
{
int opacity = getOpacity() + mFadeRate;
if(opacity > 255)
{
mFadeRate = 0;
opacity = 255;
}
if(opacity < 0)
{
mFadeRate = 0;
opacity = 0;
}
setOpacity((unsigned char)opacity);
setChildrenOpacity((unsigned char)opacity);
}
}
void GuiAnimation::moveChildren(int offsetx, int offsety)
{
for(unsigned int i = 0; i < getChildCount(); i++)
{
GuiComponent* comp = getChild(i);
comp->setOffset(comp->getOffsetX() + offsetx, comp->getOffsetY() + offsety);
}
}
void GuiAnimation::setChildrenOpacity(unsigned char opacity)
{
for(unsigned int i = 0; i < getChildCount(); i++)
{
getChild(i)->setOpacity(opacity);
}
}

View file

@ -0,0 +1,24 @@
#ifndef _GUIANIMATION_H_
#define _GUIANIMATION_H_
#include "../GuiComponent.h"
class GuiAnimation : public GuiComponent
{
public:
GuiAnimation();
void move(int x, int y, int speed);
void fadeIn(int time);
void fadeOut(int time);
void onTick(int deltaTime);
private:
void moveChildren(int offsetx, int offsety);
void setChildrenOpacity(unsigned char opacity);
int mFadeRate;
int mMoveX, mMoveY, mMoveSpeed;
};
#endif

View file

@ -47,11 +47,11 @@ void GuiFastSelect::onRender()
unsigned int sw = Renderer::getScreenWidth(), sh = Renderer::getScreenHeight();
if(!mBox->hasBackground())
Renderer::drawRect(sw * 0.2, sh * 0.2, sw * 0.6, sh * 0.6, 0x000FF0);
Renderer::drawRect(sw * 0.2, sh * 0.2, sw * 0.6, sh * 0.6, 0x000FF0, 255);
mBox->render();
Renderer::drawCenteredText(LETTERS.substr(mLetterID, 1), 0, sh * 0.5 - (Renderer::getFontHeight(Renderer::LARGE) * 0.5), mTextColor, Renderer::LARGE);
Renderer::drawCenteredText(LETTERS.substr(mLetterID, 1), 0, sh * 0.5 - (Renderer::getFontHeight(Renderer::LARGE) * 0.5), mTextColor, 255, Renderer::LARGE);
}
void GuiFastSelect::onInput(InputManager::InputButton button, bool keyDown)

View file

@ -25,10 +25,15 @@ GuiGameList::GuiGameList(bool useDetail)
mScreenshot = new GuiImage(Renderer::getScreenWidth() * sInfoWidth * 0.5, Renderer::getScreenHeight() * mTheme->getGameImageOffsetY(), "", Renderer::getScreenWidth() * sInfoWidth * 0.7, 0, false);
mScreenshot->setOrigin(mTheme->getGameImageOriginX(), mTheme->getGameImageOriginY());
addChild(mScreenshot);
//addChild(mScreenshot);
mImageAnimation = new GuiAnimation();
mImageAnimation->addChild(mScreenshot);
addChild(mImageAnimation);
}else{
mList = new GuiList<FileData*>(0, Renderer::getFontHeight(Renderer::LARGE) + 2);
mScreenshot = NULL;
mImageAnimation = NULL;
}
addChild(mList);
@ -46,6 +51,7 @@ GuiGameList::~GuiGameList()
if(mDetailed)
{
delete mImageAnimation;
delete mScreenshot;
delete mTheme;
}
@ -87,13 +93,13 @@ void GuiGameList::onRender()
//header
if(!mTheme->getHeaderHidden())
Renderer::drawCenteredText(mSystem->getName(), 0, 1, 0xFF0000, Renderer::LARGE);
Renderer::drawCenteredText(mSystem->getName(), 0, 1, 0xFF0000, 255, Renderer::LARGE);
if(mDetailed)
{
//divider
if(!mTheme->getDividersHidden())
Renderer::drawRect(Renderer::getScreenWidth() * mTheme->getListOffsetX() - 4, Renderer::getFontHeight(Renderer::LARGE) + 2, 8, Renderer::getScreenHeight(), 0x0000FF);
Renderer::drawRect(Renderer::getScreenWidth() * mTheme->getListOffsetX() - 4, Renderer::getFontHeight(Renderer::LARGE) + 2, 8, Renderer::getScreenHeight(), 0x0000FF, 255);
//if we're not scrolling and we have selected a non-folder
if(!mList->isScrolling() && mList->getSelectedObject() && !mList->getSelectedObject()->isFolder())
@ -102,7 +108,7 @@ void GuiGameList::onRender()
std::string desc = game->getDescription();
if(!desc.empty())
Renderer::drawWrappedText(desc, Renderer::getScreenWidth() * 0.03, mScreenshot->getOffsetY() + mScreenshot->getHeight() + 12, Renderer::getScreenWidth() * (mTheme->getListOffsetX() - 0.03), mTheme->getDescColor(), Renderer::SMALL);
Renderer::drawWrappedText(desc, Renderer::getScreenWidth() * 0.03, mScreenshot->getOffsetY() + mScreenshot->getHeight() + 12, Renderer::getScreenWidth() * (mTheme->getListOffsetX() - 0.03), mTheme->getDescColor(), 255, Renderer::SMALL);
}
}
}
@ -177,7 +183,7 @@ void GuiGameList::onInput(InputManager::InputButton button, bool keyDown)
if(!keyDown)
updateDetailData();
else
mScreenshot->setImage(""); //clear the image when we start scrolling
clearDetailData();
}
}
}
@ -241,12 +247,23 @@ void GuiGameList::updateDetailData()
if(mList->getSelectedObject() && !mList->getSelectedObject()->isFolder())
{
mScreenshot->setOffset((mTheme->getGameImageOffsetX() - 0.05) * Renderer::getScreenWidth(), mTheme->getGameImageOffsetY() * Renderer::getScreenHeight());
mScreenshot->setImage(((GameData*)mList->getSelectedObject())->getImagePath());
mImageAnimation->fadeIn(15);
mImageAnimation->move((int)(0.05 * Renderer::getScreenWidth()), 0, 5);
}else{
mScreenshot->setImage("");
}
}
void GuiGameList::clearDetailData()
{
if(mDetailed)
{
mImageAnimation->fadeOut(35);
}
}
//these are called when the menu opens/closes
void GuiGameList::onPause()
{

View file

@ -5,6 +5,7 @@
#include "GuiList.h"
#include "GuiImage.h"
#include "GuiTheme.h"
#include "GuiAnimation.h"
#include <string>
#include <stack>
#include "../SystemData.h"
@ -35,6 +36,7 @@ private:
void updateList();
void updateTheme();
void updateDetailData();
void clearDetailData();
SystemData* mSystem;
FolderData* mFolder;
@ -44,6 +46,7 @@ private:
GuiList<FileData*>* mList;
GuiImage* mScreenshot;
GuiAnimation* mImageAnimation;
GuiTheme* mTheme;
};

View file

@ -261,26 +261,24 @@ void GuiImage::setFlipY(bool flip)
void GuiImage::onRender()
{
if(mTextureID)
if(mTextureID && getOpacity() > 0)
{
GLfloat points[12], texs[12];
GLubyte colors[6*4];
if(mTiled)
{
float xCount = ((float)mResizeWidth/mWidth);
float yCount = ((float)mResizeHeight/mHeight);
//std::cout << "Array size: " << xCount << "x" << yCount << "\n";
GLfloat* points = new GLfloat[12];
GLfloat* texs = new GLfloat[12];
Renderer::buildGLColorArray(colors, 0xFFFFFF, getOpacity(), 6);
buildImageArray(getOffsetX(), getOffsetY(), points, texs, xCount, yCount);
drawImageArray(points, texs, 6);
delete[] points;
delete[] texs;
}else{
GLfloat points[12], texs[12];
Renderer::buildGLColorArray(colors, 0xFFFFFF, getOpacity(), 6);
buildImageArray(getOffsetX(), getOffsetY(), points, texs);
drawImageArray(points, texs, 6);
}
drawImageArray(points, texs, colors, 6);
}
}
@ -322,7 +320,7 @@ void GuiImage::buildImageArray(int posX, int posY, GLfloat* points, GLfloat* tex
}
}
void GuiImage::drawImageArray(GLfloat* points, GLfloat* texs, unsigned int numArrays)
void GuiImage::drawImageArray(GLfloat* points, GLfloat* texs, GLubyte* colors, unsigned int numArrays)
{
glBindTexture(GL_TEXTURE_2D, mTextureID);
glEnable(GL_TEXTURE_2D);
@ -333,6 +331,12 @@ void GuiImage::drawImageArray(GLfloat* points, GLfloat* texs, unsigned int numAr
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if(colors != NULL)
{
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
}
glVertexPointer(2, GL_FLOAT, 0, points);
glTexCoordPointer(2, GL_FLOAT, 0, texs);
@ -341,6 +345,9 @@ void GuiImage::drawImageArray(GLfloat* points, GLfloat* texs, unsigned int numAr
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
if(colors != NULL)
glDisableClientState(GL_COLOR_ARRAY);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
}

View file

@ -43,7 +43,7 @@ private:
void loadImage(std::string path);
void resize();
void buildImageArray(int x, int y, GLfloat* points, GLfloat* texs, float percentageX = 1, float percentageY = 1); //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 drawImageArray(GLfloat* points, GLfloat* texs, GLubyte* colors, unsigned int count = 6); //draws the given set of points and texture coordinates, number of coordinate pairs may be specified (default 6)
void unloadImage();
std::string mPath;

View file

@ -56,7 +56,7 @@ void GuiList<listType>::onRender()
if(mRowVector.size() == 0)
{
Renderer::drawCenteredText("The list is empty.", 0, y, 0x0000FF, mFont);
Renderer::drawCenteredText("The list is empty.", 0, y, 0x0000FF, 255, mFont);
return;
}
@ -68,7 +68,7 @@ void GuiList<listType>::onRender()
{
if(mSelection == i)
{
Renderer::drawRect(getOffsetX(), y, Renderer::getScreenWidth(), Renderer::getFontHeight(mFont), mSelectorColor);
Renderer::drawRect(getOffsetX(), y, Renderer::getScreenWidth(), Renderer::getFontHeight(mFont), mSelectorColor, 255);
}
ListRow row = mRowVector.at((unsigned int)i);
@ -76,7 +76,7 @@ void GuiList<listType>::onRender()
if(mDrawCentered)
Renderer::drawCenteredText(row.name, getOffsetX(), y, row.color, mFont);
else
Renderer::drawText(row.name, getOffsetX() + mTextOffsetX, y, (mSelectedTextColorOverride != -1 && mSelection == i ? mSelectedTextColorOverride : row.color), mFont);
Renderer::drawText(row.name, getOffsetX() + mTextOffsetX, y, (mSelectedTextColorOverride != -1 && mSelection == i ? mSelectedTextColorOverride : row.color), 255, mFont);
y += entrySize;
}

View file

@ -8,7 +8,6 @@
#include "components/GuiInputConfig.h"
#include <SDL.h>
#include "AudioManager.h"
#include "platform.h"
#ifdef _RPI_