Renderer now uses an int for colors instead of mixing SDL_Color and ints. GuiList now scrolls.

This commit is contained in:
Aloshi 2012-07-21 15:16:07 -05:00
parent bdc7246ee5
commit 561e4a7f44
6 changed files with 32 additions and 20 deletions

View file

@ -27,8 +27,8 @@ namespace Renderer
//drawing commands
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 drawCenteredText(std::string text, int y, SDL_Color& color);
void drawText(std::string text, int x, int y, int color);
void drawCenteredText(std::string text, int y, int color);
void loadFonts();
}

View file

@ -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)
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)
{
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);
}
void Renderer::drawCenteredText(std::string text, int y, SDL_Color& color)
void Renderer::drawCenteredText(std::string text, int y, int color)
{
if(!font)
loadFonts();

View file

@ -24,10 +24,9 @@ GuiGameList::~GuiGameList()
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, color);
Renderer::drawCenteredText(mSystem->getName(), 2, 0x0000FF);
}
void GuiGameList::onInput(InputManager::InputButton button, bool keyDown)

View file

@ -1,5 +1,4 @@
#include "GuiList.h"
#include <SDL/SDL.h>
#include <iostream>
GuiList::GuiList()
@ -15,8 +14,22 @@ GuiList::~GuiList()
void GuiList::onRender()
{
int y = 40;
SDL_Color color = {0, 0, 255};
const int cutoff = 40;
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)
{
@ -24,14 +37,14 @@ void GuiList::onRender()
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::drawCenteredText(mNameVector.at(i), y, color);
Renderer::drawCenteredText(mNameVector.at((unsigned int)i), y, color);
y += 40;
}
}

View file

@ -11,7 +11,6 @@ GuiTitleScreen::GuiTitleScreen()
void GuiTitleScreen::onRender()
{
Renderer::drawRect(0, 0, 640, 480, 0xFFFFFF);
SDL_Color color = {255, 0, 0};
Renderer::drawCenteredText("EmulationStation", 5, color);
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0xFFFFFF);
Renderer::drawCenteredText("EmulationStation", 5, 0x00FF00);
}

View file

@ -21,7 +21,7 @@ int main()
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)
{
std::cerr << "Error - could not set video mode!\n";
@ -35,7 +35,7 @@ int main()
//GuiTitleScreen* testGui = new GuiTitleScreen();
//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);