Added <listSelectedColor> tag.

Began implementing GuiFastSelect. You can see what's currently in place by holding F2 and pressing up/down.
Hopefully fixed nearest neighbor filters with GuiImage.
This commit is contained in:
Aloshi 2012-09-30 22:29:55 -05:00
parent e08391080b
commit 31aebf3a7d
15 changed files with 174 additions and 13 deletions

View file

@ -1,7 +1,7 @@
CC=g++ 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_ 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 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 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 pugiXML/pugixml.cpp
SOURCES=$(addprefix src/,$(SRCSOURCES)) SOURCES=$(addprefix src/,$(SRCSOURCES))
OBJECTS=$(SOURCES:.cpp=.o) OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=emulationstation EXECUTABLE=emulationstation

View file

@ -1,7 +1,7 @@
CC=g++ CC=g++
CFLAGS=-c -Wall -I/usr/include/freetype2 -I/usr/include/SDL -I/usr/include -D_DESKTOP_ -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 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 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 pugiXML/pugixml.cpp
SOURCES=$(addprefix src/,$(SRCSOURCES)) SOURCES=$(addprefix src/,$(SRCSOURCES))
OBJECTS=$(SOURCES:.cpp=.o) OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=emulationstation EXECUTABLE=emulationstation

View file

@ -63,6 +63,8 @@ Display tags must be at the root of the <theme> tree - for example, they can't b
`<listSelectorColor>` - the hex color to use for the "selector bar" on the GuiGameList. `<listSelectorColor>` - the hex color to use for the "selector bar" on the GuiGameList.
`<listSelectedColor>` - the hex color to use for selected text on the GuiGameList. Default is -1, which will not change the color.
`<listLeftAlign />` - if present, the games list names will be left aligned to the value of `<listOffsetX>` (default 0.5). `<listLeftAlign />` - if present, the games list names will be left aligned to the value of `<listOffsetX>` (default 0.5).
`<hideHeader />` - if present, the system name header won't be displayed (useful for replacing it with an image). `<hideHeader />` - if present, the system name header won't be displayed (useful for replacing it with an image).

View file

@ -1,3 +1,8 @@
September 30
-Began implementing GuiFastSelect, currently invoked by holding F2. Unfortunately, it doesn't do anything yet.
-Added <listSelectedColor>.
-Fixed OpenGL mipmap generation not setting a magnification filter. Hopefully this fixes the weird scaling. If not, I can switch from nearest neighbor to linear.
September 29 September 29
-SDL is now completely shut down on both the RPi and SDL GL renderer. You may see the flicker of a terminal when you launch a game. This was done in preparation for audio. -SDL is now completely shut down on both the RPi and SDL GL renderer. You may see the flicker of a terminal when you launch a game. This was done in preparation for audio.

View file

@ -67,6 +67,9 @@ void InputManager::processEvent(SDL_Event* event)
case SDLK_F1: case SDLK_F1:
button = MENU; button = MENU;
break; break;
case SDLK_F2:
button = SELECT;
break;
default: default:
button = UNKNOWN; button = UNKNOWN;

View file

@ -17,7 +17,7 @@ namespace InputManager {
void loadConfig(); void loadConfig();
//enum for identifying input, regardless of configuration //enum for identifying input, regardless of configuration
enum InputButton { UNKNOWN, UP, DOWN, LEFT, RIGHT, BUTTON1, BUTTON2, MENU }; enum InputButton { UNKNOWN, UP, DOWN, LEFT, RIGHT, BUTTON1, BUTTON2, MENU, SELECT};
void processEvent(SDL_Event* event); void processEvent(SDL_Event* event);

View file

@ -0,0 +1,100 @@
#include "GuiFastSelect.h"
#include "../Renderer.h"
#include <iostream>
const std::string GuiFastSelect::LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int GuiFastSelect::SCROLLSPEED = 120;
const int GuiFastSelect::SCROLLDELAY = 507;
GuiFastSelect::GuiFastSelect(GuiComponent* parent, SystemData* system, char startLetter)
{
mLetterID = LETTERS.find(toupper(startLetter));
if(mLetterID == std::string::npos)
mLetterID = 0;
Renderer::registerComponent(this);
InputManager::registerComponent(this);
mParent = parent;
mSystem = system;
mScrolling = false;
mScrollTimer = 0;
mScrollOffset = 0;
mParent->pause();
}
GuiFastSelect::~GuiFastSelect()
{
Renderer::unregisterComponent(this);
InputManager::unregisterComponent(this);
mParent->resume();
}
void GuiFastSelect::onRender()
{
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);
}
void GuiFastSelect::onInput(InputManager::InputButton button, bool keyDown)
{
if(button == InputManager::UP && keyDown)
{
setLetterID(mLetterID - 1);
mScrollOffset = -1;
}
if(button == InputManager::DOWN && keyDown)
{
setLetterID(mLetterID + 1);
mScrollOffset = 1;
}
if((button == InputManager::UP || button == InputManager::DOWN) && !keyDown)
{
mScrolling = false;
mScrollTimer = 0;
mScrollOffset = 0;
}
if(button == InputManager::SELECT && !keyDown)
{
delete this;
return;
}
}
void GuiFastSelect::onTick(int deltaTime)
{
if(mScrollOffset != 0)
{
mScrollTimer += deltaTime;
if(!mScrolling && mScrollTimer >= SCROLLDELAY)
{
mScrolling = true;
mScrollTimer = SCROLLSPEED;
}
if(mScrolling && mScrollTimer >= SCROLLSPEED)
{
mScrollTimer = 0;
setLetterID(mLetterID + mScrollOffset);
}
}
}
void GuiFastSelect::setLetterID(int id)
{
while(id < 0)
id += LETTERS.length();
while(id >= (int)LETTERS.length())
id -= LETTERS.length();
mLetterID = (size_t)id;
}

View file

@ -0,0 +1,30 @@
#ifndef _GUIFASTSELECT_H_
#define _GUIFASTSELECT_H_
#include "../GuiComponent.h"
#include "../SystemData.h"
class GuiFastSelect : GuiComponent
{
public:
GuiFastSelect(GuiComponent* parent, SystemData* system, char startLetter);
~GuiFastSelect();
void onRender();
void onInput(InputManager::InputButton button, bool keyDown);
void onTick(int deltaTime);
private:
static const std::string LETTERS;
static const int SCROLLSPEED;
static const int SCROLLDELAY;
void setLetterID(int id);
SystemData* mSystem;
size_t mLetterID;
GuiComponent* mParent;
int mScrollTimer, mScrollOffset;
bool mScrolling;
};
#endif

View file

@ -2,6 +2,7 @@
#include "../InputManager.h" #include "../InputManager.h"
#include <iostream> #include <iostream>
#include "GuiMenu.h" #include "GuiMenu.h"
#include "GuiFastSelect.h"
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
@ -13,7 +14,6 @@ GuiGameList::GuiGameList(bool useDetail)
std::cout << "Creating GuiGameList\n"; std::cout << "Creating GuiGameList\n";
mDetailed = useDetail; mDetailed = useDetail;
mTheme = new GuiTheme(); //not a child because it's rendered manually by GuiGameList::onRender (to make sure it's rendered first) mTheme = new GuiTheme(); //not a child because it's rendered manually by GuiGameList::onRender (to make sure it's rendered first)
//The GuiGameList can use the older, simple game list if so desired. //The GuiGameList can use the older, simple game list if so desired.
@ -152,6 +152,12 @@ void GuiGameList::onInput(InputManager::InputButton button, bool keyDown)
new GuiMenu(this); new GuiMenu(this);
} }
if(button == InputManager::SELECT && keyDown)
{
std::cout << "Creating GuiFastSelect\n";
new GuiFastSelect(this, mSystem, mList->getSelectedObject()->getName()[0]);
}
if(mDetailed) if(mDetailed)
{ {
if(button == InputManager::UP || button == InputManager::DOWN) if(button == InputManager::UP || button == InputManager::DOWN)
@ -199,6 +205,7 @@ void GuiGameList::updateTheme()
mTheme->readXML(""); //clears any current theme mTheme->readXML(""); //clears any current theme
mList->setSelectorColor(mTheme->getSelectorColor()); mList->setSelectorColor(mTheme->getSelectorColor());
mList->setSelectedTextColor(mTheme->getSelectedTextColor());
mList->setCentered(mTheme->getListCentered()); mList->setCentered(mTheme->getListCentered());
if(mDetailed) if(mDetailed)

View file

@ -149,6 +149,7 @@ void GuiImage::loadImage(std::string path)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageRGBA); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageRGBA);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
mWidth = width; mWidth = width;
mHeight = height; mHeight = height;

View file

@ -4,8 +4,8 @@
#include <fstream> #include <fstream>
std::string GuiInputConfig::sConfigPath = "./input.cfg"; std::string GuiInputConfig::sConfigPath = "./input.cfg";
std::string GuiInputConfig::sInputs[] = { "UNKNOWN", "UP", "DOWN", "LEFT", "RIGHT", "BUTTON1 (Accept)", "BUTTON2 (Back)", "START (Menu)" }; //must be same order as InputManager::InputButton enum std::string GuiInputConfig::sInputs[] = { "UNKNOWN", "UP", "DOWN", "LEFT", "RIGHT", "BUTTON1 (Accept)", "BUTTON2 (Back)", "START (Menu)", "SELECT (Jump-to-letter)" }; //must be same order as InputManager::InputButton enum
int GuiInputConfig::sInputCount = 8; int GuiInputConfig::sInputCount = 8; //set to 9 after fast select is in
GuiInputConfig::GuiInputConfig() GuiInputConfig::GuiInputConfig()
{ {

View file

@ -18,6 +18,8 @@ GuiList<listType>::GuiList(int offsetX, int offsetY, Renderer::FontSize fontsize
mFont = fontsize; mFont = fontsize;
mSelectorColor = 0x000000; mSelectorColor = 0x000000;
mSelectedTextColorOverride = -1;
mDrawCentered = true; mDrawCentered = true;
InputManager::registerComponent(this); InputManager::registerComponent(this);
@ -74,7 +76,7 @@ void GuiList<listType>::onRender()
if(mDrawCentered) if(mDrawCentered)
Renderer::drawCenteredText(row.name, getOffsetX(), y, row.color, mFont); Renderer::drawCenteredText(row.name, getOffsetX(), y, row.color, mFont);
else else
Renderer::drawText(row.name, getOffsetX() + mTextOffsetX, y, row.color, mFont); Renderer::drawText(row.name, getOffsetX() + mTextOffsetX, y, (mSelectedTextColorOverride != -1 && mSelection == i ? mSelectedTextColorOverride : row.color), mFont);
y += entrySize; y += entrySize;
} }
@ -212,6 +214,12 @@ void GuiList<listType>::setSelectorColor(int selectorColor)
mSelectorColor = selectorColor; mSelectorColor = selectorColor;
} }
template <typename listType>
void GuiList<listType>::setSelectedTextColor(int selectedColor)
{
mSelectedTextColorOverride = selectedColor;
}
template<typename listType> template<typename listType>
void GuiList<listType>::setCentered(bool centered) void GuiList<listType>::setCentered(bool centered)
{ {

View file

@ -7,9 +7,6 @@
#include <vector> #include <vector>
#include <string> #include <string>
#define SCROLLDELAY 507
#define SCROLLTIME 200
//A graphical list. Supports multiple colors for rows and scrolling. //A graphical list. Supports multiple colors for rows and scrolling.
//TODO - add truncation to text rendering if name exceeds a maximum width (a trailing elipses, perhaps). //TODO - add truncation to text rendering if name exceeds a maximum width (a trailing elipses, perhaps).
template <typename listType> template <typename listType>
@ -35,16 +32,20 @@ public:
bool isScrolling(); bool isScrolling();
void setSelectorColor(int selectorColor); void setSelectorColor(int selectorColor);
void setSelectedTextColor(int selectedColor);
void setCentered(bool centered); void setCentered(bool centered);
void setTextOffsetX(int textoffsetx); void setTextOffsetX(int textoffsetx);
private: private:
static const int SCROLLDELAY = 507;
static const int SCROLLTIME = 200;
int mScrollDir, mScrollAccumulator; int mScrollDir, mScrollAccumulator;
bool mScrolling; bool mScrolling;
Renderer::FontSize mFont; Renderer::FontSize mFont;
int mSelectorColor; int mSelectorColor, mSelectedTextColorOverride;
bool mDrawCentered; bool mDrawCentered;
int mTextOffsetX; int mTextOffsetX;

View file

@ -15,11 +15,12 @@ bool GuiTheme::getHeaderHidden() { return mHideHeader; }
bool GuiTheme::getDividersHidden() { return mHideDividers; } bool GuiTheme::getDividersHidden() { return mHideDividers; }
bool GuiTheme::getListCentered() { return mListCentered; } bool GuiTheme::getListCentered() { return mListCentered; }
//not yet implemented
float GuiTheme::getListOffsetX() { return mListOffsetX; } float GuiTheme::getListOffsetX() { return mListOffsetX; }
float GuiTheme::getGameImageOffsetY() { return mGameImageOffsetY; } float GuiTheme::getGameImageOffsetY() { return mGameImageOffsetY; }
float GuiTheme::getListTextOffsetX() { return mListTextOffsetX; } float GuiTheme::getListTextOffsetX() { return mListTextOffsetX; }
int GuiTheme::getSelectedTextColor() { return mListSelectedColor; }
GuiTheme::GuiTheme(std::string path) GuiTheme::GuiTheme(std::string path)
{ {
setDefaults(); setDefaults();
@ -38,6 +39,7 @@ void GuiTheme::setDefaults()
mListPrimaryColor = 0x0000FF; mListPrimaryColor = 0x0000FF;
mListSecondaryColor = 0x00FF00; mListSecondaryColor = 0x00FF00;
mListSelectorColor = 0x000000; mListSelectorColor = 0x000000;
mListSelectedColor = -1; //-1 = use original list color when selected
mDescColor = 0x0000FF; mDescColor = 0x0000FF;
mHideHeader = false; mHideHeader = false;
mHideDividers = false; mHideDividers = false;
@ -93,6 +95,7 @@ void GuiTheme::readXML(std::string path)
mListPrimaryColor = resolveColor(root.child("listPrimaryColor").text().get(), mListPrimaryColor); mListPrimaryColor = resolveColor(root.child("listPrimaryColor").text().get(), mListPrimaryColor);
mListSecondaryColor = resolveColor(root.child("listSecondaryColor").text().get(), mListSecondaryColor); mListSecondaryColor = resolveColor(root.child("listSecondaryColor").text().get(), mListSecondaryColor);
mListSelectorColor = resolveColor(root.child("listSelectorColor").text().get(), mListSelectorColor); mListSelectorColor = resolveColor(root.child("listSelectorColor").text().get(), mListSelectorColor);
mListSelectedColor = resolveColor(root.child("listSelectedColor").text().get(), mListSelectedColor);
mDescColor = resolveColor(root.child("descColor").text().get(), mDescColor); mDescColor = resolveColor(root.child("descColor").text().get(), mDescColor);
mHideHeader = root.child("hideHeader"); mHideHeader = root.child("hideHeader");
mHideDividers = root.child("hideDividers"); mHideDividers = root.child("hideDividers");

View file

@ -16,6 +16,7 @@ public:
int getPrimaryColor(); int getPrimaryColor();
int getSecondaryColor(); int getSecondaryColor();
int getSelectorColor(); int getSelectorColor();
int getSelectedTextColor();
int getDescColor(); int getDescColor();
bool getHeaderHidden(); bool getHeaderHidden();
bool getDividersHidden(); bool getDividersHidden();
@ -39,7 +40,7 @@ private:
std::vector<GuiComponent*> mComponentVector; std::vector<GuiComponent*> mComponentVector;
std::string mPath; std::string mPath;
int mListPrimaryColor, mListSecondaryColor, mListSelectorColor, mDescColor; int mListPrimaryColor, mListSecondaryColor, mListSelectorColor, mListSelectedColor, mDescColor;
bool mHideHeader, mHideDividers, mListCentered; bool mHideHeader, mHideDividers, mListCentered;
float mListOffsetX, mGameImageOffsetY, mListTextOffsetX; float mListOffsetX, mGameImageOffsetY, mListTextOffsetX;