mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-04-10 19:15:13 +00:00
Renderer now uses an int for colors instead of mixing SDL_Color and ints. GuiList now scrolls.
This commit is contained in:
parent
bdc7246ee5
commit
561e4a7f44
|
@ -27,8 +27,8 @@ namespace Renderer
|
||||||
|
|
||||||
//drawing commands
|
//drawing commands
|
||||||
void drawRect(int x, int y, int w, int h, int color);
|
void drawRect(int x, int y, int w, int h, int color);
|
||||||
void drawText(std::string text, int x, int y, SDL_Color& color);
|
void drawText(std::string text, int x, int y, int color);
|
||||||
void drawCenteredText(std::string text, int y, SDL_Color& color);
|
void drawCenteredText(std::string text, int y, int color);
|
||||||
|
|
||||||
void loadFonts();
|
void loadFonts();
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,14 +24,15 @@ void Renderer::loadFonts()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::drawText(std::string text, int x, int y, SDL_Color& color)
|
void Renderer::drawText(std::string text, int x, int y, int color)
|
||||||
{
|
{
|
||||||
if(!font)
|
if(!font)
|
||||||
loadFonts();
|
loadFonts();
|
||||||
|
|
||||||
//color = {255, 0, 0};
|
//SDL_Color sdlcolor = (SDL_Color)color; //SDL_MapRGB(//{(char)color, (char)(*(&color + 1)), (char)(*(&color + 2))};
|
||||||
|
SDL_Color* sdlcolor = (SDL_Color*)&color;
|
||||||
|
|
||||||
SDL_Surface* textSurf = TTF_RenderText_Blended(font, text.c_str(), color);
|
SDL_Surface* textSurf = TTF_RenderText_Blended(font, text.c_str(), *sdlcolor);
|
||||||
if(textSurf == NULL)
|
if(textSurf == NULL)
|
||||||
{
|
{
|
||||||
std::cerr << "Error - could not render text \"" << text << "\" to surface!\n";
|
std::cerr << "Error - could not render text \"" << text << "\" to surface!\n";
|
||||||
|
@ -44,7 +45,7 @@ void Renderer::drawText(std::string text, int x, int y, SDL_Color& color)
|
||||||
SDL_FreeSurface(textSurf);
|
SDL_FreeSurface(textSurf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::drawCenteredText(std::string text, int y, SDL_Color& color)
|
void Renderer::drawCenteredText(std::string text, int y, int color)
|
||||||
{
|
{
|
||||||
if(!font)
|
if(!font)
|
||||||
loadFonts();
|
loadFonts();
|
||||||
|
|
|
@ -24,10 +24,9 @@ GuiGameList::~GuiGameList()
|
||||||
|
|
||||||
void GuiGameList::onRender()
|
void GuiGameList::onRender()
|
||||||
{
|
{
|
||||||
Renderer::drawRect(0, 0, 640, 480, 0xFFFFFF);
|
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0xFFFFFF);
|
||||||
|
|
||||||
SDL_Color color = {0, 155, 100};
|
Renderer::drawCenteredText(mSystem->getName(), 2, 0x0000FF);
|
||||||
Renderer::drawCenteredText(mSystem->getName(), 2, color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiGameList::onInput(InputManager::InputButton button, bool keyDown)
|
void GuiGameList::onInput(InputManager::InputButton button, bool keyDown)
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include "GuiList.h"
|
#include "GuiList.h"
|
||||||
#include <SDL/SDL.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
GuiList::GuiList()
|
GuiList::GuiList()
|
||||||
|
@ -15,8 +14,22 @@ GuiList::~GuiList()
|
||||||
|
|
||||||
void GuiList::onRender()
|
void GuiList::onRender()
|
||||||
{
|
{
|
||||||
int y = 40;
|
const int cutoff = 40;
|
||||||
SDL_Color color = {0, 0, 255};
|
const int entrySize = 40;
|
||||||
|
|
||||||
|
//number of entries that can fit on the screen simultaniously
|
||||||
|
int screenCount = (Renderer::getScreenHeight() - cutoff) / entrySize;
|
||||||
|
screenCount -= 1;
|
||||||
|
|
||||||
|
int startEntry = mSelection - (screenCount * 0.5);
|
||||||
|
if(startEntry < 0)
|
||||||
|
startEntry = 0;
|
||||||
|
if(startEntry >= (int)mNameVector.size() - screenCount)
|
||||||
|
startEntry = mNameVector.size() - screenCount;
|
||||||
|
|
||||||
|
|
||||||
|
int y = cutoff;
|
||||||
|
int color = 0xFF0000;
|
||||||
|
|
||||||
if(mNameVector.size() == 0)
|
if(mNameVector.size() == 0)
|
||||||
{
|
{
|
||||||
|
@ -24,14 +37,14 @@ void GuiList::onRender()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(unsigned int i = 0; i < mNameVector.size(); i++)
|
for(int i = startEntry; i < startEntry + screenCount; i++)
|
||||||
{
|
{
|
||||||
if(mSelection == (int)i)
|
if(mSelection == i)
|
||||||
{
|
{
|
||||||
Renderer::drawRect(0, y, Renderer::getScreenWidth(), 52, 0x000000);
|
Renderer::drawRect(0, y, Renderer::getScreenWidth(), 52, 0x000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer::drawCenteredText(mNameVector.at(i), y, color);
|
Renderer::drawCenteredText(mNameVector.at((unsigned int)i), y, color);
|
||||||
y += 40;
|
y += 40;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ GuiTitleScreen::GuiTitleScreen()
|
||||||
|
|
||||||
void GuiTitleScreen::onRender()
|
void GuiTitleScreen::onRender()
|
||||||
{
|
{
|
||||||
Renderer::drawRect(0, 0, 640, 480, 0xFFFFFF);
|
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0xFFFFFF);
|
||||||
SDL_Color color = {255, 0, 0};
|
Renderer::drawCenteredText("EmulationStation", 5, 0x00FF00);
|
||||||
Renderer::drawCenteredText("EmulationStation", 5, color);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ int main()
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer::screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE);
|
Renderer::screen = SDL_SetVideoMode(Renderer::getScreenWidth(), Renderer::getScreenHeight(), 16, SDL_SWSURFACE);
|
||||||
if(Renderer::screen == NULL)
|
if(Renderer::screen == NULL)
|
||||||
{
|
{
|
||||||
std::cerr << "Error - could not set video mode!\n";
|
std::cerr << "Error - could not set video mode!\n";
|
||||||
|
@ -35,7 +35,7 @@ int main()
|
||||||
//GuiTitleScreen* testGui = new GuiTitleScreen();
|
//GuiTitleScreen* testGui = new GuiTitleScreen();
|
||||||
|
|
||||||
//test systemData
|
//test systemData
|
||||||
SystemData* testSystem = SystemData::loadConfig("./systems.cfg").at(0); //= new SystemData("Test", "./testdir/", ".smc");
|
SystemData* testSystem = SystemData::loadConfig("./systems.cfg").at(0);
|
||||||
GuiGameList* testGui = new GuiGameList(testSystem);
|
GuiGameList* testGui = new GuiGameList(testSystem);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue