If LinLibertine.ttf can't be found, fall back to a system font.

This commit is contained in:
Aloshi 2012-08-01 21:37:07 -05:00
parent 7920753718
commit b56094fe3d
6 changed files with 51 additions and 9 deletions

View file

@ -64,6 +64,9 @@ void InputManager::processEvent(SDL_Event* event)
case SDLK_ESCAPE:
button = BUTTON2;
break;
case SDLK_F1:
button = MENU;
break;
default:
button = UNKNOWN;
@ -246,5 +249,5 @@ std::string InputManager::getConfigPath()
return "";
}
return(home + "/.es_input.cfg");
return(home + "/.emulationstation/es_input.cfg");
}

View file

@ -15,7 +15,7 @@ namespace InputManager {
void loadConfig();
//enum for identifying input, regardless of configuration
enum InputButton { UNKNOWN, UP, DOWN, LEFT, RIGHT, BUTTON1, BUTTON2 };
enum InputButton { UNKNOWN, UP, DOWN, LEFT, RIGHT, BUTTON1, BUTTON2, MENU };
void processEvent(SDL_Event* event);

View file

@ -3,6 +3,7 @@
#include <SDL/SDL_ttf.h>
#include <iostream>
#include <string>
#include <boost/filesystem.hpp>
SDL_Surface* Renderer::screen;
bool Renderer::loadedFonts = false;
@ -17,7 +18,15 @@ void Renderer::drawRect(int x, int y, int h, int w, int color)
bool Renderer::loadFonts()
{
const char* fontPath = "LinLibertine_R.ttf";
std::string fontPath = "LinLibertine_R.ttf";
//if our font isn't foud, make a last-ditch effort to load a system font
if(!boost::filesystem::exists(fontPath))
{
std::cerr << "Error - " << fontPath << " font not found. Falling back to ";
fontPath = "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf";
std::cerr << fontPath << " (which may not exist).\n";
}
//int sizeArray[] = {Renderer::getScreenHeight() * 0.025, Renderer::getScreenHeight() * 0.05, Renderer::getScreenHeight() * 0.075};
int sizeArray[] = {Renderer::getScreenWidth() * 0.015, Renderer::getScreenWidth() * 0.03, Renderer::getScreenWidth() * 0.05};
@ -26,7 +35,7 @@ bool Renderer::loadFonts()
//the three here should be the font count but, again, I don't remember the syntax
for(unsigned int i = 0; i < 3; i++)
{
TTF_Font* font = TTF_OpenFont(fontPath, sizeArray[i]);
TTF_Font* font = TTF_OpenFont(fontPath.c_str(), sizeArray[i]);
if(!font)
{
std::cerr << "Error - could not load font!\n";

View file

@ -228,7 +228,7 @@ std::string SystemData::getConfigPath()
return "";
}
return(home + "/.es_systems.cfg");
return(home + "/.emulationstation/es_systems.cfg");
}
FolderData* SystemData::getRootFolder()

View file

@ -4,8 +4,8 @@
#include <fstream>
std::string GuiInputConfig::sConfigPath = "./input.cfg";
std::string GuiInputConfig::sInputs[] = { "UNKNOWN", "UP", "DOWN", "LEFT", "RIGHT", "BUTTON1 (Accept)", "BUTTON2 (Back)" }; //must be same order as InputManager::InputButton enum
int GuiInputConfig::sInputCount = 7;
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;
GuiInputConfig::GuiInputConfig()
{

View file

@ -60,9 +60,39 @@ int main(int argc, char* argv[])
SDL_ShowCursor(false);
SDL_JoystickEventState(SDL_ENABLE);
//make sure the config directory exists
std::string home = getenv("HOME");
std::string configDir = home + "/.emulationstation";
if(!boost::filesystem::exists(configDir))
{
std::cout << "Creating config directory " << configDir << "\n";
boost::filesystem::create_directory(configDir);
}
//check if there are config files in the old places, and if so, move them to the new directory
std::string oldSysPath = home + "/.es_systems.cfg";
std::string oldInpPath = home + "/.es_input.cfg";
if(boost::filesystem::exists(oldSysPath))
{
std::cout << "Moving old system config file " << oldSysPath << " to new path at " << SystemData::getConfigPath() << "\n";
boost::filesystem::copy_file(oldSysPath, SystemData::getConfigPath());
boost::filesystem::remove(oldSysPath);
}
if(boost::filesystem::exists(oldInpPath))
{
std::cout << "Moving old input config file " << oldInpPath << " to new path at " << InputManager::getConfigPath() << "\n";
boost::filesystem::copy_file(oldInpPath, InputManager::getConfigPath());
boost::filesystem::remove(oldInpPath);
}
if(!boost::filesystem::exists(SystemData::getConfigPath()))
{
std::cerr << "A system config file in $HOME/.es_systems.cfg was not found. An example will be created.\n";
std::cerr << "A system config file in " << SystemData::getConfigPath() << " was not found. An example will be created.\n";
SystemData::writeExampleConfig();
std::cerr << "Set it up, then re-run EmulationStation.\n";
running = false;
@ -71,7 +101,7 @@ int main(int argc, char* argv[])
if(SystemData::sSystemVector.size() == 0)
{
std::cerr << "A system config file in $HOME/.es_systems.cfg was found, but contained no systems.\n";
std::cerr << "A system config file in " << SystemData::getConfigPath() << " was found, but contained no systems.\n";
std::cerr << "You should probably go read that, or delete it.\n";
running = false;
}else{