Commit fe030fb6 authored by Aloshi's avatar Aloshi

Added custom font support.

Check out THEMES.md for more information.
parent 3ebb819a
......@@ -114,6 +114,28 @@ Display tags define some "meta" display attributes about your theme. Display tag
`<boxCorner>` - path to the "top left corner" image file. It will be flipped for the top right, bottom right, and bottom left corners. ~ and . are expanded.
Fonts
=====
Fonts are defined like so:
```
<fontTag>
<path>./path/to/font</path>
<size>0.05</size>
</fontTag>
```
You can leave off any tags you don't want to use, and they'll use the default. Size is defined as a percentage of the screen height. "." and "~" are expanded for paths.
**Font tags:**
`<listFont>` - font to use for the game list.
`<descriptionFont>` - font to use for description text.
Audio
=====
......
October 31
-Added custom font support. Check out THEMES.md.
-Happy halloween!
October 26
-Hopefully fixed the black screen bug with certain programs.
......
......@@ -10,6 +10,13 @@ bool Font::libraryInitialized = false;
int Font::getDpiX() { return 96; }
int Font::getDpiY() { return 96; }
int Font::getSize() { return mSize; }
std::string Font::getDefaultPath()
{
return "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif.ttf";
}
void Font::initLibrary()
{
if(FT_Init_FreeType(&sLibrary))
......@@ -149,7 +156,10 @@ void Font::buildAtlas()
x += g->bitmap.width;
}
std::cout << "Final texture coords: " << x << ", " << y << "\n";
if(y >= textureHeight)
{
std::cerr << "Error - font size exceeded texture size! If you were doing something reasonable, tell Aloshi to fix it!\n";
}
glBindTexture(GL_TEXTURE_2D, 0);
......
......@@ -45,6 +45,9 @@ public:
void onInit();
void onDeinit();
int getSize();
static std::string getDefaultPath();
private:
static int getDpiX();
static int getDpiY();
......
......@@ -87,8 +87,9 @@ namespace Renderer {
//make sure our font exists
if(!boost::filesystem::exists(fontPath))
{
std::cout << "Default font \"" << fontPath << "\" does not exist! Attempting to default to a system font...";
fontPath = "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf";
//std::cout << "Default font \"" << fontPath << "\" does not exist! Attempting to default to a system font...";
//fontPath = "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf";
fontPath = Font::getDefaultPath();
if(!boost::filesystem::exists(fontPath))
{
std::cerr << "System font \"" << fontPath << "\" wasn't found either! Well, you're kind of screwed. Sorry.\n";
......@@ -96,7 +97,7 @@ namespace Renderer {
}
}
float fontSizes[] = {0.035, 0.05, 0.1};
float fontSizes[] = {0.035, 0.045, 0.1};
for(unsigned int i = 0; i < 3; i++)
{
fonts[i] = new Font(fontPath, (unsigned int)(fontSizes[i] * getScreenHeight()));
......
......@@ -21,17 +21,18 @@ GuiGameList::GuiGameList(bool useDetail)
//Those with smaller displays may prefer the older view.
if(mDetailed)
{
mList = new GuiList<FileData*>(Renderer::getScreenWidth() * sInfoWidth, Renderer::getDefaultFont(Renderer::LARGE)->getHeight() + 2);
mList = new GuiList<FileData*>(Renderer::getScreenWidth() * sInfoWidth, Renderer::getDefaultFont(Renderer::LARGE)->getHeight() + 2, Renderer::getDefaultFont(Renderer::MEDIUM));
mScreenshot = new GuiImage(Renderer::getScreenWidth() * mTheme->getGameImageOffsetX(), Renderer::getScreenHeight() * mTheme->getGameImageOffsetY(), "", Renderer::getScreenWidth() * sInfoWidth * 0.7, 0, false);
mScreenshot->setOrigin(mTheme->getGameImageOriginX(), mTheme->getGameImageOriginY());
//addChild(mScreenshot);
//the animation renders the screenshot
mImageAnimation = new GuiAnimation();
mImageAnimation->addChild(mScreenshot);
addChild(mImageAnimation);
}else{
mList = new GuiList<FileData*>(0, Renderer::getDefaultFont(Renderer::LARGE)->getHeight() + 2);
mList = new GuiList<FileData*>(0, Renderer::getDefaultFont(Renderer::LARGE)->getHeight() + 2, Renderer::getDefaultFont(Renderer::MEDIUM));
mScreenshot = NULL;
mImageAnimation = NULL;
}
......@@ -108,7 +109,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(), Renderer::getDefaultFont(Renderer::SMALL));
Renderer::drawWrappedText(desc, Renderer::getScreenWidth() * 0.03, mScreenshot->getOffsetY() + mScreenshot->getHeight() + 12, Renderer::getScreenWidth() * (mTheme->getListOffsetX() - 0.03), mTheme->getDescColor(), mTheme->getDescriptionFont());
}
}
}
......@@ -226,6 +227,9 @@ void GuiGameList::updateTheme()
mList->setSelectedTextColor(mTheme->getSelectedTextColor());
mList->setScrollSound(mTheme->getMenuScrollSound());
//fonts
mList->setFont(mTheme->getListFont());
if(mDetailed)
{
mList->setCentered(mTheme->getListCentered());
......
......@@ -4,7 +4,7 @@
#include <iostream>
template <typename listType>
GuiList<listType>::GuiList(int offsetX, int offsetY, Renderer::FontSize fontsize)
GuiList<listType>::GuiList(int offsetX, int offsetY, Font* font)
{
mSelection = 0;
mScrollDir = 0;
......@@ -16,7 +16,7 @@ GuiList<listType>::GuiList(int offsetX, int offsetY, Renderer::FontSize fontsize
mTextOffsetX = 0;
mFont = Renderer::getDefaultFont(fontsize);
mFont = font;
mSelectorColor = 0x000000FF;
mSelectedTextColorOverride = 0x0000FF;
mScrollSound = NULL;
......@@ -266,3 +266,9 @@ void GuiList<listType>::setScrollSound(Sound* sound)
{
mScrollSound = sound;
}
template <typename listType>
void GuiList<listType>::setFont(Font* font)
{
mFont = font;
}
......@@ -15,7 +15,7 @@ template <typename listType>
class GuiList : public GuiComponent
{
public:
GuiList(int offsetX = 0, int offsetY = 0, Renderer::FontSize fontsize = Renderer::MEDIUM);
GuiList(int offsetX, int offsetY, Font* font);
~GuiList();
void onRender();
......@@ -44,6 +44,7 @@ public:
listType getObject(int i);
void setSelection(int i);
void setFont(Font* f);
private:
static const int SCROLLDELAY = 507;
static const int SCROLLTIME = 200;
......
......@@ -6,7 +6,7 @@ GuiMenu::GuiMenu(GuiComponent* parent)
mParent = parent;
parent->pause();
mList = new GuiList<std::string>(0, Renderer::getDefaultFont(Renderer::LARGE)->getHeight() + 2, Renderer::LARGE);
mList = new GuiList<std::string>(0, Renderer::getDefaultFont(Renderer::LARGE)->getHeight() + 2, Renderer::getDefaultFont(Renderer::LARGE));
mList->setSelectedTextColor(0x0000FFFF);
populateList();
addChild(mList);
......
......@@ -36,8 +36,27 @@ float GuiTheme::getGameImageOriginY() { return mGameImageOriginY; }
std::string GuiTheme::getImageNotFoundPath() { return mImageNotFoundPath; }
Font* GuiTheme::getListFont()
{
if(mListFont == NULL)
return Renderer::getDefaultFont(Renderer::MEDIUM);
else
return mListFont;
}
Font* GuiTheme::getDescriptionFont()
{
if(mDescFont == NULL)
return Renderer::getDefaultFont(Renderer::SMALL);
else
return mDescFont;
}
GuiTheme::GuiTheme(std::string path)
{
mListFont = NULL;
mDescFont = NULL;
setDefaults();
if(!path.empty())
......@@ -85,6 +104,18 @@ void GuiTheme::setDefaults()
mMenuOpenSound.loadFile("");
mImageNotFoundPath = "";
if(mListFont != NULL)
{
delete mListFont;
mListFont = NULL;
}
if(mDescFont != NULL)
{
delete mDescFont;
mDescFont = NULL;
}
}
void GuiTheme::deleteComponents()
......@@ -178,7 +209,8 @@ void GuiTheme::readXML(std::string path)
mMenuOpenSound.loadFile(expandPath(root.child("menuOpenSound").text().get()));
//fonts
//mListFont = resolveFont(root.child("listFont"), NULL);
mListFont = resolveFont(root.child("listFont"), Font::getDefaultPath(), Renderer::getDefaultFont(Renderer::MEDIUM)->getSize());
mDescFont = resolveFont(root.child("descriptionFont"), Font::getDefaultPath(), Renderer::getDefaultFont(Renderer::SMALL)->getSize());
//actually read the components
createComponentChildren(root, this);
......@@ -331,13 +363,23 @@ float GuiTheme::strToFloat(std::string str, float defaultVal)
return ret;
}
Font* GuiTheme::resolveFont(pugi::xml_node node, Font* def)
Font* GuiTheme::resolveFont(pugi::xml_node node, std::string defaultPath, unsigned int defaultSize)
{
if(!node)
return def;
return NULL;
std::string path = expandPath(node.child("path").text().get());
int size = (int)(strToFloat(node.child("size").value()) * Renderer::getScreenHeight());
unsigned int size = (unsigned int)(strToFloat(node.child("size").text().get()) * Renderer::getScreenHeight());
if(!boost::filesystem::exists(path))
{
path = defaultPath;
}
if(size == 0)
{
size = defaultSize;
}
return new Font(path, size);
}
......@@ -44,6 +44,9 @@ public:
Sound* getMenuOpenSound();
std::string getImageNotFoundPath();
Font* getListFont();
Font* getDescriptionFont();
private:
void setDefaults();
void deleteComponents();
......@@ -56,7 +59,7 @@ private:
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);
Font* resolveFont(pugi::xml_node node, Font* def);
Font* resolveFont(pugi::xml_node node, std::string defaultPath, unsigned int defaultSize);
std::vector<GuiComponent*> mComponentVector;
std::string mPath;
......@@ -67,6 +70,8 @@ private:
GuiBoxData mBoxData;
Sound mMenuScrollSound, mMenuSelectSound, mMenuBackSound, mMenuOpenSound;
std::string mImageNotFoundPath;
Font* mListFont;
Font* mDescFont;
};
#endif
......@@ -48,7 +48,7 @@ int main(int argc, char* argv[])
}else if(strcmp(argv[i], "--draw-framerate") == 0)
{
DRAWFRAMERATE = true;
}else if(strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0)
}else if(strcmp(argv[i], "--help") == 0)
{
std::cout << "EmulationStation, a graphical front-end for ROM browsing.\n";
std::cout << "Command line arguments:\n";
......@@ -166,7 +166,7 @@ int main(int argc, char* argv[])
ss << framerate;
std::string fps;
ss >> fps;
Renderer::drawText(fps, 50, 50, 0x00FF00, Renderer::getDefaultFont(Renderer::MEDIUM));
Renderer::drawText(fps, 50, 50, 0x00FF00FF, Renderer::getDefaultFont(Renderer::MEDIUM));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment