Reworked opacity to be stored in that wasted color byte.

This commit is contained in:
Aloshi 2012-10-17 13:21:56 -05:00
parent 358658a36d
commit 8b1e061929
13 changed files with 92 additions and 78 deletions

View file

@ -165,7 +165,7 @@ struct tex {
GLfloat tex2y;
};
void Font::drawText(std::string text, int startx, int starty, int color, char opacity)
void Font::drawText(std::string text, int startx, int starty, int color)
{
starty += mMaxGlyphHeight;
@ -224,7 +224,7 @@ void Font::drawText(std::string text, int startx, int starty, int color, char op
x += charData[letter].advX;
}
Renderer::buildGLColorArray(colors, color, opacity, pointCount * 3);
Renderer::buildGLColorArray(colors, color, 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, char opacity); //Render some text using this font.
void drawText(std::string text, int startx, int starty, int color); //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

@ -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 char opacity, unsigned int vertCount);
void buildGLColorArray(GLubyte* ptr, unsigned int color, unsigned int vertCount);
//drawing commands
void swapBuffers();
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);
void drawRect(int x, int y, int w, int h, unsigned int color);
void drawText(std::string text, int x, int y, unsigned int color, FontSize fontsize = MEDIUM);
void drawCenteredText(std::string text, int xOffset, int y, unsigned int color, FontSize fontsize = MEDIUM);
void drawWrappedText(std::string text, int xStart, int yStart, int xLen, unsigned int color, FontSize fontsize = MEDIUM);
}
#endif

View file

@ -8,24 +8,24 @@
namespace Renderer {
bool loadedFonts = false;
void setColor4bArray(GLubyte* array, int color, unsigned char opacity)
void setColor4bArray(GLubyte* array, unsigned int color)
{
array[0] = (color & 0x00ff0000) / 0x10000;
array[1] = (color & 0x0000ff00) / 0x100;
array[2] = (color & 0x000000ff);
array[3] = opacity;
array[0] = (color & 0xff000000) / 0x1000000;
array[1] = (color & 0x00ff0000) / 0x10000;
array[2] = (color & 0x0000ff00) / 0x100;
array[3] = (color & 0x000000ff);
}
void buildGLColorArray(GLubyte* ptr, int color, unsigned char opacity, unsigned int vertCount)
void buildGLColorArray(GLubyte* ptr, unsigned int color, unsigned int vertCount)
{
for(unsigned int i = 0; i < vertCount; i++)
{
setColor4bArray(ptr, color, opacity);
setColor4bArray(ptr, color);
ptr += 4;
}
}
void drawRect(int x, int y, int w, int h, int color, unsigned char opacity)
void drawRect(int x, int y, int w, int h, unsigned int color)
{
GLfloat points[12];
@ -38,7 +38,7 @@ namespace Renderer {
points[10] = x + w; points[11] = y + h;
GLubyte colors[6*4];
buildGLColorArray(colors, color, opacity, 6);
buildGLColorArray(colors, color, 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, unsigned char opacity, FontSize font)
void drawText(std::string text, int x, int y, unsigned int color, 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, opacity);
getFont(font)->drawText(text, x, y, color);
}
void drawCenteredText(std::string text, int xOffset, int y, int color, unsigned char opacity, FontSize fontsize)
void drawCenteredText(std::string text, int xOffset, int y, unsigned int color, FontSize fontsize)
{
if(!loadedFonts)
loadFonts();
@ -145,12 +145,12 @@ namespace Renderer {
x += xOffset * 0.5;
drawText(text, x, y, color, opacity, fontsize);
drawText(text, x, y, color, 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, unsigned char opacity, FontSize fontsize)
void drawWrappedText(std::string text, int xStart, int yStart, int xLen, unsigned int color, 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, opacity, fontsize);
drawText(line, xStart, y, color, fontsize);
//increment y by height and some extra padding for the next line
y += h + 4;

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, 255);
Renderer::drawRect(sw * 0.2, sh * 0.2, sw * 0.6, sh * 0.6, 0x000FF0FF);
mBox->render();
Renderer::drawCenteredText(LETTERS.substr(mLetterID, 1), 0, sh * 0.5 - (Renderer::getFontHeight(Renderer::LARGE) * 0.5), mTextColor, 255, Renderer::LARGE);
Renderer::drawCenteredText(LETTERS.substr(mLetterID, 1), 0, sh * 0.5 - (Renderer::getFontHeight(Renderer::LARGE) * 0.5), mTextColor, Renderer::LARGE);
}
void GuiFastSelect::onInput(InputManager::InputButton button, bool keyDown)

View file

@ -93,13 +93,13 @@ void GuiGameList::onRender()
//header
if(!mTheme->getHeaderHidden())
Renderer::drawCenteredText(mSystem->getName(), 0, 1, 0xFF0000, 255, Renderer::LARGE);
Renderer::drawCenteredText(mSystem->getName(), 0, 1, 0xFF0000FF, Renderer::LARGE);
if(mDetailed)
{
//divider
if(!mTheme->getDividersHidden())
Renderer::drawRect(Renderer::getScreenWidth() * mTheme->getListOffsetX() - 4, Renderer::getFontHeight(Renderer::LARGE) + 2, 8, Renderer::getScreenHeight(), 0x0000FF, 255);
Renderer::drawRect(Renderer::getScreenWidth() * mTheme->getListOffsetX() - 4, Renderer::getFontHeight(Renderer::LARGE) + 2, 8, Renderer::getScreenHeight(), 0x0000FFFF);
//if we're not scrolling and we have selected a non-folder
if(!mList->isScrolling() && mList->getSelectedObject() && !mList->getSelectedObject()->isFolder())
@ -108,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(), 255, Renderer::SMALL);
Renderer::drawWrappedText(desc, Renderer::getScreenWidth() * 0.03, mScreenshot->getOffsetY() + mScreenshot->getHeight() + 12, Renderer::getScreenWidth() * (mTheme->getListOffsetX() - 0.03), mTheme->getDescColor(), Renderer::SMALL);
}
}
}
@ -223,6 +223,8 @@ void GuiGameList::updateTheme()
mTheme->readXML(""); //clears any current theme
mList->setSelectorColor(mTheme->getSelectorColor());
std::cout << "selector alpha: " << (mTheme->getSelectorColor() & 0x000000ff) << "\n";
mList->setSelectedTextColor(mTheme->getSelectedTextColor());
mList->setScrollSound(mTheme->getMenuScrollSound());

View file

@ -271,10 +271,10 @@ void GuiImage::onRender()
float xCount = ((float)mResizeWidth/mWidth);
float yCount = ((float)mResizeHeight/mHeight);
Renderer::buildGLColorArray(colors, 0xFFFFFF, getOpacity(), 6);
Renderer::buildGLColorArray(colors, 0xFFFFFF00 | (getOpacity()), 6);
buildImageArray(getOffsetX(), getOffsetY(), points, texs, xCount, yCount);
}else{
Renderer::buildGLColorArray(colors, 0xFFFFFF, getOpacity(), 6);
Renderer::buildGLColorArray(colors, 0xFFFFFF00 | (getOpacity()), 6);
buildImageArray(getOffsetX(), getOffsetY(), points, texs);
}

View file

@ -36,21 +36,21 @@ GuiInputConfig::~GuiInputConfig()
void GuiInputConfig::onRender()
{
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0xFFFFFF);
Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0xFFFFFFFF);
int height = Renderer::getFontHeight(Renderer::MEDIUM) + 6;
Renderer::drawCenteredText("It looks like you have a joystick plugged in!", 0, 2, 0x000000);
Renderer::drawCenteredText("POV hats (some D-Pads) are automatically mapped to directions.", 0, height, 0x000000);
Renderer::drawCenteredText("You can press a keyboard key to skip any input.", 0, height * 2, 0x000000);
Renderer::drawCenteredText("If you want to remap later, just delete ~/.es_input.cfg.", 0, height * 3, 0x000000);
Renderer::drawCenteredText("This interface only configures the first joystick plugged in.", 0, height * 4, 0x000000);
Renderer::drawCenteredText("Remember - you'll need to set up your emulator separately!", 0, Renderer::getScreenHeight() - height, 0x000000);
Renderer::drawCenteredText("It looks like you have a joystick plugged in!", 0, 2, 0x000000FF);
Renderer::drawCenteredText("POV hats (some D-Pads) are automatically mapped to directions.", 0, height, 0x000000FF);
Renderer::drawCenteredText("You can press a keyboard key to skip any input.", 0, height * 2, 0x000000FF);
Renderer::drawCenteredText("If you want to remap later, just delete ~/.es_input.cfg.", 0, height * 3, 0x000000FF);
Renderer::drawCenteredText("This interface only configures the first joystick plugged in.", 0, height * 4, 0x000000FF);
Renderer::drawCenteredText("Remember - you'll need to set up your emulator separately!", 0, Renderer::getScreenHeight() - height, 0x000000FF);
if(mDone)
Renderer::drawCenteredText("All done! Press a keyboard key to save.", 0, height * 5, 0x00BB00);
Renderer::drawCenteredText("All done! Press a keyboard key to save.", 0, height * 5, 0x00BB00FF);
else
Renderer::drawCenteredText("Please press the axis/button for " + sInputs[mInputNum], 0, height * 5, 0x00C000);
Renderer::drawCenteredText("Please press the axis/button for " + sInputs[mInputNum], 0, height * 5, 0x00C000FF);
}
void GuiInputConfig::onInput(InputManager::InputButton button, bool keyDown)

View file

@ -17,8 +17,8 @@ GuiList<listType>::GuiList(int offsetX, int offsetY, Renderer::FontSize fontsize
mTextOffsetX = 0;
mFont = fontsize;
mSelectorColor = 0x000000;
mSelectedTextColorOverride = -1;
mSelectorColor = 0x000000FF;
mSelectedTextColorOverride = 0x0000FF;
mScrollSound = NULL;
mDrawCentered = true;
@ -56,7 +56,7 @@ void GuiList<listType>::onRender()
if(mRowVector.size() == 0)
{
Renderer::drawCenteredText("The list is empty.", 0, y, 0x0000FF, 255, mFont);
Renderer::drawCenteredText("The list is empty.", 0, y, 0xFF0000FF, mFont);
return;
}
@ -66,17 +66,18 @@ void GuiList<listType>::onRender()
for(int i = startEntry; i < listCutoff; i++)
{
//draw selector bar
if(mSelection == i)
{
Renderer::drawRect(getOffsetX(), y, Renderer::getScreenWidth(), Renderer::getFontHeight(mFont), mSelectorColor, 255);
Renderer::drawRect(getOffsetX(), y, Renderer::getScreenWidth(), Renderer::getFontHeight(mFont), mSelectorColor);
}
ListRow row = mRowVector.at((unsigned int)i);
if(mDrawCentered)
Renderer::drawCenteredText(row.name, getOffsetX(), y, row.color, mFont);
Renderer::drawCenteredText(row.name, getOffsetX(), y, (mSelection == i) ? mSelectedTextColorOverride : row.color, mFont);
else
Renderer::drawText(row.name, getOffsetX() + mTextOffsetX, y, (mSelectedTextColorOverride != -1 && mSelection == i ? mSelectedTextColorOverride : row.color), 255, mFont);
Renderer::drawText(row.name, getOffsetX() + mTextOffsetX, y, (mSelection == i) ? mSelectedTextColorOverride : row.color, mFont);
y += entrySize;
}
@ -163,7 +164,7 @@ void GuiList<listType>::scroll()
//list management stuff
template <typename listType>
void GuiList<listType>::addObject(std::string name, listType obj, int color)
void GuiList<listType>::addObject(std::string name, listType obj, unsigned int color)
{
ListRow row = {name, obj, color};
mRowVector.push_back(row);
@ -219,13 +220,14 @@ void GuiList<listType>::onResume()
}
template <typename listType>
void GuiList<listType>::setSelectorColor(int selectorColor)
void GuiList<listType>::setSelectorColor(unsigned int selectorColor)
{
mSelectorColor = selectorColor;
std::cout << "mSelectorColor alpha: " << (mSelectorColor & 0x000000ff) << "\n";
}
template <typename listType>
void GuiList<listType>::setSelectedTextColor(int selectedColor)
void GuiList<listType>::setSelectedTextColor(unsigned int selectedColor)
{
mSelectedTextColorOverride = selectedColor;
}

View file

@ -21,7 +21,7 @@ public:
void onTick(int deltaTime);
void onInput(InputManager::InputButton button, bool keyDown);
void addObject(std::string name, listType obj, int color = 0xFF0000);
void addObject(std::string name, listType obj, unsigned int color = 0xFF0000);
void clear();
void onPause();
@ -33,8 +33,8 @@ public:
void stopScrolling();
bool isScrolling();
void setSelectorColor(int selectorColor);
void setSelectedTextColor(int selectedColor);
void setSelectorColor(unsigned int selectorColor);
void setSelectedTextColor(unsigned int selectedColor);
void setCentered(bool centered);
void setScrollSound(Sound* sound);
void setTextOffsetX(int textoffsetx);
@ -53,7 +53,7 @@ private:
bool mScrolling;
Renderer::FontSize mFont;
int mSelectorColor, mSelectedTextColorOverride;
unsigned int mSelectorColor, mSelectedTextColorOverride;
bool mDrawCentered;
int mTextOffsetX;
@ -62,7 +62,7 @@ private:
{
std::string name;
listType object;
int color;
unsigned int color;
};
std::vector<ListRow> mRowVector;

View file

@ -49,8 +49,8 @@ void GuiMenu::populateList()
{
mList->clear();
mList->addObject("Restart", "sudo shutdown -r now", 0x0000FF);
mList->addObject("Shutdown", "sudo shutdown -h now", 0x0000FF);
mList->addObject("Restart", "sudo shutdown -r now", 0x0000FFFF);
mList->addObject("Shutdown", "sudo shutdown -h now", 0x0000FFFF);
}
void GuiMenu::onRender()

View file

@ -7,18 +7,18 @@
#include <sstream>
#include "../Renderer.h"
int GuiTheme::getPrimaryColor() { return mListPrimaryColor; }
int GuiTheme::getSecondaryColor() { return mListSecondaryColor; }
int GuiTheme::getSelectorColor() { return mListSelectorColor; }
int GuiTheme::getDescColor() { return mDescColor; }
int GuiTheme::getFastSelectColor() { return mFastSelectColor; }
unsigned int GuiTheme::getPrimaryColor() { return mListPrimaryColor; }
unsigned int GuiTheme::getSecondaryColor() { return mListSecondaryColor; }
unsigned int GuiTheme::getSelectorColor() { return mListSelectorColor; }
unsigned int GuiTheme::getDescColor() { return mDescColor; }
unsigned int GuiTheme::getFastSelectColor() { return mFastSelectColor; }
bool GuiTheme::getHeaderHidden() { return mHideHeader; }
bool GuiTheme::getDividersHidden() { return mHideDividers; }
bool GuiTheme::getListCentered() { return mListCentered; }
float GuiTheme::getListOffsetX() { return mListOffsetX; }
float GuiTheme::getListTextOffsetX() { return mListTextOffsetX; }
int GuiTheme::getSelectedTextColor() { return mListSelectedColor; }
unsigned int GuiTheme::getSelectedTextColor() { return mListSelectedColor; }
GuiBoxData GuiTheme::getBoxData() { return mBoxData; }
@ -49,12 +49,12 @@ GuiTheme::~GuiTheme()
void GuiTheme::setDefaults()
{
mListPrimaryColor = 0x0000FF;
mListSecondaryColor = 0x00FF00;
mListSelectorColor = 0x000000;
mListSelectedColor = -1; //-1 = use original list color when selected
mDescColor = 0x0000FF;
mFastSelectColor = 0xFF0000;
mListPrimaryColor = 0x0000FFFF;
mListSecondaryColor = 0x00FF00FF;
mListSelectorColor = 0x000000FF;
mListSelectedColor = 0xFF0000FF;
mDescColor = 0x0000FFFF;
mFastSelectColor = 0xFF0000FF;
mHideHeader = false;
mHideDividers = false;
mListCentered = true;
@ -128,7 +128,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);
mListSelectedColor = resolveColor(root.child("listSelectedColor").text().get(), mListPrimaryColor);
mDescColor = resolveColor(root.child("descColor").text().get(), mDescColor);
mFastSelectColor = resolveColor(root.child("fastSelectColor").text().get(), mFastSelectColor);
mHideHeader = root.child("hideHeader");
@ -271,12 +271,22 @@ float GuiTheme::resolveExp(std::string str, float defaultVal)
}
//takes a string of hex and resolves it to an integer
int GuiTheme::resolveColor(std::string str, int defaultColor)
unsigned int GuiTheme::resolveColor(std::string str, unsigned int defaultColor)
{
if(str.empty())
return defaultColor;
int ret;
if(str.length() != 6 && str.length() != 8)
{
std::cerr << "Error - color \"" << str << "\" is not a valid hex color! Must be 6 or 8 characters.\n";
return defaultColor;
}
//if there's no alpha specified, assume FF
if(str.length() == 6)
str += "FF";
unsigned int ret;
std::stringstream ss;
ss << std::hex << str;
ss >> ret;

View file

@ -15,12 +15,12 @@ public:
void readXML(std::string path);
int getPrimaryColor();
int getSecondaryColor();
int getSelectorColor();
int getSelectedTextColor();
int getDescColor();
int getFastSelectColor();
unsigned int getPrimaryColor();
unsigned int getSecondaryColor();
unsigned int getSelectorColor();
unsigned int getSelectedTextColor();
unsigned int getDescColor();
unsigned int getFastSelectColor();
bool getHeaderHidden();
bool getDividersHidden();
bool getListCentered();
@ -50,13 +50,13 @@ private:
//utility functions
std::string expandPath(std::string path);
float resolveExp(std::string str, float defaultVal = 0.0);
int resolveColor(std::string str, int defaultColor = 0x000000);
unsigned int resolveColor(std::string str, unsigned int defaultColor = 0x000000FF);
void splitString(std::string str, char delim, std::string* before, std::string* after);
float strToFloat(std::string str, float defaultVal = 0.0f);
std::vector<GuiComponent*> mComponentVector;
std::string mPath;
int mListPrimaryColor, mListSecondaryColor, mListSelectorColor, mListSelectedColor, mDescColor, mFastSelectColor;
unsigned int mListPrimaryColor, mListSecondaryColor, mListSelectorColor, mListSelectedColor, mDescColor, mFastSelectColor;
bool mHideHeader, mHideDividers, mListCentered;
float mListOffsetX, mListTextOffsetX, mGameImageOffsetX, mGameImageOffsetY, mGameImageWidth, mGameImageHeight, mGameImageOriginX, mGameImageOriginY;