From 31aebf3a7d9e7235c7663b9cb745a366db877ed7 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sun, 30 Sep 2012 22:29:55 -0500 Subject: [PATCH] Added 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. --- Makefile | 2 +- Makefile.x86 | 2 +- THEMES.md | 2 + changelog.txt | 5 ++ src/InputManager.cpp | 3 + src/InputManager.h | 2 +- src/components/GuiFastSelect.cpp | 100 ++++++++++++++++++++++++++++++ src/components/GuiFastSelect.h | 30 +++++++++ src/components/GuiGameList.cpp | 9 ++- src/components/GuiImage.cpp | 1 + src/components/GuiInputConfig.cpp | 4 +- src/components/GuiList.cpp | 10 ++- src/components/GuiList.h | 9 +-- src/components/GuiTheme.cpp | 5 +- src/components/GuiTheme.h | 3 +- 15 files changed, 174 insertions(+), 13 deletions(-) create mode 100644 src/components/GuiFastSelect.cpp create mode 100644 src/components/GuiFastSelect.h diff --git a/Makefile b/Makefile index cc0e2c077..cb30a62c8 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 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)) OBJECTS=$(SOURCES:.cpp=.o) EXECUTABLE=emulationstation diff --git a/Makefile.x86 b/Makefile.x86 index f0d07f6f7..7f5e3f077 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 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)) OBJECTS=$(SOURCES:.cpp=.o) EXECUTABLE=emulationstation diff --git a/THEMES.md b/THEMES.md index 10749bab8..176b53f51 100644 --- a/THEMES.md +++ b/THEMES.md @@ -63,6 +63,8 @@ Display tags must be at the root of the tree - for example, they can't b `` - the hex color to use for the "selector bar" on the GuiGameList. +`` - the hex color to use for selected text on the GuiGameList. Default is -1, which will not change the color. + `` - if present, the games list names will be left aligned to the value of `` (default 0.5). `` - if present, the system name header won't be displayed (useful for replacing it with an image). diff --git a/changelog.txt b/changelog.txt index 415a676cb..19f07afff 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,8 @@ +September 30 +-Began implementing GuiFastSelect, currently invoked by holding F2. Unfortunately, it doesn't do anything yet. +-Added . +-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 -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. diff --git a/src/InputManager.cpp b/src/InputManager.cpp index f9d18ebb7..69159c287 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -67,6 +67,9 @@ void InputManager::processEvent(SDL_Event* event) case SDLK_F1: button = MENU; break; + case SDLK_F2: + button = SELECT; + break; default: button = UNKNOWN; diff --git a/src/InputManager.h b/src/InputManager.h index 9fe414f90..e7b544d1c 100644 --- a/src/InputManager.h +++ b/src/InputManager.h @@ -17,7 +17,7 @@ namespace InputManager { void loadConfig(); //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); diff --git a/src/components/GuiFastSelect.cpp b/src/components/GuiFastSelect.cpp new file mode 100644 index 000000000..f8b8c9cb7 --- /dev/null +++ b/src/components/GuiFastSelect.cpp @@ -0,0 +1,100 @@ +#include "GuiFastSelect.h" +#include "../Renderer.h" +#include + +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; +} diff --git a/src/components/GuiFastSelect.h b/src/components/GuiFastSelect.h new file mode 100644 index 000000000..d5457dde8 --- /dev/null +++ b/src/components/GuiFastSelect.h @@ -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 diff --git a/src/components/GuiGameList.cpp b/src/components/GuiGameList.cpp index acfbea604..af7a018c0 100644 --- a/src/components/GuiGameList.cpp +++ b/src/components/GuiGameList.cpp @@ -2,6 +2,7 @@ #include "../InputManager.h" #include #include "GuiMenu.h" +#include "GuiFastSelect.h" #include @@ -13,7 +14,6 @@ GuiGameList::GuiGameList(bool useDetail) std::cout << "Creating GuiGameList\n"; mDetailed = useDetail; - 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. @@ -152,6 +152,12 @@ void GuiGameList::onInput(InputManager::InputButton button, bool keyDown) new GuiMenu(this); } + if(button == InputManager::SELECT && keyDown) + { + std::cout << "Creating GuiFastSelect\n"; + new GuiFastSelect(this, mSystem, mList->getSelectedObject()->getName()[0]); + } + if(mDetailed) { if(button == InputManager::UP || button == InputManager::DOWN) @@ -199,6 +205,7 @@ void GuiGameList::updateTheme() mTheme->readXML(""); //clears any current theme mList->setSelectorColor(mTheme->getSelectorColor()); + mList->setSelectedTextColor(mTheme->getSelectedTextColor()); mList->setCentered(mTheme->getListCentered()); if(mDetailed) diff --git a/src/components/GuiImage.cpp b/src/components/GuiImage.cpp index b1fe50577..a250ccd9b 100644 --- a/src/components/GuiImage.cpp +++ b/src/components/GuiImage.cpp @@ -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); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); mWidth = width; mHeight = height; diff --git a/src/components/GuiInputConfig.cpp b/src/components/GuiInputConfig.cpp index e10f48abf..1f7d7a0eb 100644 --- a/src/components/GuiInputConfig.cpp +++ b/src/components/GuiInputConfig.cpp @@ -4,8 +4,8 @@ #include 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 -int GuiInputConfig::sInputCount = 8; +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; //set to 9 after fast select is in GuiInputConfig::GuiInputConfig() { diff --git a/src/components/GuiList.cpp b/src/components/GuiList.cpp index 3e99670e6..5ebc94cbf 100644 --- a/src/components/GuiList.cpp +++ b/src/components/GuiList.cpp @@ -18,6 +18,8 @@ GuiList::GuiList(int offsetX, int offsetY, Renderer::FontSize fontsize mFont = fontsize; mSelectorColor = 0x000000; + mSelectedTextColorOverride = -1; + mDrawCentered = true; InputManager::registerComponent(this); @@ -74,7 +76,7 @@ void GuiList::onRender() if(mDrawCentered) Renderer::drawCenteredText(row.name, getOffsetX(), y, row.color, mFont); 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; } @@ -212,6 +214,12 @@ void GuiList::setSelectorColor(int selectorColor) mSelectorColor = selectorColor; } +template +void GuiList::setSelectedTextColor(int selectedColor) +{ + mSelectedTextColorOverride = selectedColor; +} + template void GuiList::setCentered(bool centered) { diff --git a/src/components/GuiList.h b/src/components/GuiList.h index 5b00a9596..94ef62604 100644 --- a/src/components/GuiList.h +++ b/src/components/GuiList.h @@ -7,9 +7,6 @@ #include #include -#define SCROLLDELAY 507 -#define SCROLLTIME 200 - //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). template @@ -35,16 +32,20 @@ public: bool isScrolling(); void setSelectorColor(int selectorColor); + void setSelectedTextColor(int selectedColor); void setCentered(bool centered); void setTextOffsetX(int textoffsetx); private: + static const int SCROLLDELAY = 507; + static const int SCROLLTIME = 200; + int mScrollDir, mScrollAccumulator; bool mScrolling; Renderer::FontSize mFont; - int mSelectorColor; + int mSelectorColor, mSelectedTextColorOverride; bool mDrawCentered; int mTextOffsetX; diff --git a/src/components/GuiTheme.cpp b/src/components/GuiTheme.cpp index 26eba1af5..964162e00 100644 --- a/src/components/GuiTheme.cpp +++ b/src/components/GuiTheme.cpp @@ -15,11 +15,12 @@ bool GuiTheme::getHeaderHidden() { return mHideHeader; } bool GuiTheme::getDividersHidden() { return mHideDividers; } bool GuiTheme::getListCentered() { return mListCentered; } -//not yet implemented float GuiTheme::getListOffsetX() { return mListOffsetX; } float GuiTheme::getGameImageOffsetY() { return mGameImageOffsetY; } float GuiTheme::getListTextOffsetX() { return mListTextOffsetX; } +int GuiTheme::getSelectedTextColor() { return mListSelectedColor; } + GuiTheme::GuiTheme(std::string path) { setDefaults(); @@ -38,6 +39,7 @@ void GuiTheme::setDefaults() mListPrimaryColor = 0x0000FF; mListSecondaryColor = 0x00FF00; mListSelectorColor = 0x000000; + mListSelectedColor = -1; //-1 = use original list color when selected mDescColor = 0x0000FF; mHideHeader = false; mHideDividers = false; @@ -93,6 +95,7 @@ void GuiTheme::readXML(std::string path) mListPrimaryColor = resolveColor(root.child("listPrimaryColor").text().get(), mListPrimaryColor); mListSecondaryColor = resolveColor(root.child("listSecondaryColor").text().get(), mListSecondaryColor); mListSelectorColor = resolveColor(root.child("listSelectorColor").text().get(), mListSelectorColor); + mListSelectedColor = resolveColor(root.child("listSelectedColor").text().get(), mListSelectedColor); mDescColor = resolveColor(root.child("descColor").text().get(), mDescColor); mHideHeader = root.child("hideHeader"); mHideDividers = root.child("hideDividers"); diff --git a/src/components/GuiTheme.h b/src/components/GuiTheme.h index fced0c774..a8d47e9dd 100644 --- a/src/components/GuiTheme.h +++ b/src/components/GuiTheme.h @@ -16,6 +16,7 @@ public: int getPrimaryColor(); int getSecondaryColor(); int getSelectorColor(); + int getSelectedTextColor(); int getDescColor(); bool getHeaderHidden(); bool getDividersHidden(); @@ -39,7 +40,7 @@ private: std::vector mComponentVector; std::string mPath; - int mListPrimaryColor, mListSecondaryColor, mListSelectorColor, mDescColor; + int mListPrimaryColor, mListSecondaryColor, mListSelectorColor, mListSelectedColor, mDescColor; bool mHideHeader, mHideDividers, mListCentered; float mListOffsetX, mGameImageOffsetY, mListTextOffsetX;