Moved Font.h/.cpp to the "resources" directory (since it's a Reloadable).

This commit is contained in:
Aloshi 2013-10-04 18:24:41 -05:00
parent b510aa8cd4
commit a6dbaa2dea
16 changed files with 697 additions and 697 deletions

View file

@ -137,7 +137,6 @@ set(ES_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/src/EmulationStation.h ${CMAKE_CURRENT_SOURCE_DIR}/src/EmulationStation.h
${CMAKE_CURRENT_SOURCE_DIR}/src/FileData.h ${CMAKE_CURRENT_SOURCE_DIR}/src/FileData.h
${CMAKE_CURRENT_SOURCE_DIR}/src/FolderData.h ${CMAKE_CURRENT_SOURCE_DIR}/src/FolderData.h
${CMAKE_CURRENT_SOURCE_DIR}/src/Font.h
${CMAKE_CURRENT_SOURCE_DIR}/src/GameData.h ${CMAKE_CURRENT_SOURCE_DIR}/src/GameData.h
${CMAKE_CURRENT_SOURCE_DIR}/src/GuiComponent.h ${CMAKE_CURRENT_SOURCE_DIR}/src/GuiComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/HttpReq.h ${CMAKE_CURRENT_SOURCE_DIR}/src/HttpReq.h
@ -186,6 +185,7 @@ set(ES_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/src/scrapers/TheArchiveScraper.h ${CMAKE_CURRENT_SOURCE_DIR}/src/scrapers/TheArchiveScraper.h
${CMAKE_CURRENT_SOURCE_DIR}/src/pugiXML/pugiconfig.hpp ${CMAKE_CURRENT_SOURCE_DIR}/src/pugiXML/pugiconfig.hpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pugiXML/pugixml.hpp ${CMAKE_CURRENT_SOURCE_DIR}/src/pugiXML/pugixml.hpp
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/Font.h
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/ResourceManager.h ${CMAKE_CURRENT_SOURCE_DIR}/src/resources/ResourceManager.h
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/TextureResource.h ${CMAKE_CURRENT_SOURCE_DIR}/src/resources/TextureResource.h
${CMAKE_CURRENT_SOURCE_DIR}/data/Resources.h ${CMAKE_CURRENT_SOURCE_DIR}/data/Resources.h
@ -193,7 +193,6 @@ set(ES_HEADERS
set(ES_SOURCES set(ES_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/AudioManager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/AudioManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/FolderData.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/FolderData.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Font.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/GameData.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/GameData.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/GuiComponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/GuiComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/HttpReq.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/HttpReq.cpp
@ -240,6 +239,7 @@ set(ES_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/scrapers/GamesDBScraper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/scrapers/GamesDBScraper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/scrapers/TheArchiveScraper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/scrapers/TheArchiveScraper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/pugiXML/pugixml.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/pugiXML/pugixml.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/Font.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/ResourceManager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/resources/ResourceManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/resources/TextureResource.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/resources/TextureResource.cpp

View file

@ -2,7 +2,7 @@
#include "Renderer.h" #include "Renderer.h"
#include GLHEADER #include GLHEADER
#include <iostream> #include <iostream>
#include "Font.h" #include "resources/Font.h"
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include "Log.h" #include "Log.h"
#include <stack> #include <stack>

View file

@ -1,7 +1,7 @@
#include "Renderer.h" #include "Renderer.h"
#include "platform.h" #include "platform.h"
#include GLHEADER #include GLHEADER
#include "Font.h" #include "resources/Font.h"
namespace Renderer namespace Renderer
{ {

View file

@ -5,7 +5,7 @@
#include "InputManager.h" #include "InputManager.h"
#include "resources/ResourceManager.h" #include "resources/ResourceManager.h"
#include <vector> #include <vector>
#include "Font.h" #include "resources/Font.h"
class Window class Window
{ {

View file

@ -2,7 +2,7 @@
#include "../GuiComponent.h" #include "../GuiComponent.h"
#include <functional> #include <functional>
#include "../Font.h" #include "../resources/Font.h"
#include "NinePatchComponent.h" #include "NinePatchComponent.h"
class ButtonComponent : public GuiComponent class ButtonComponent : public GuiComponent

View file

@ -2,7 +2,7 @@
#include "../GuiComponent.h" #include "../GuiComponent.h"
#include <boost/date_time.hpp> #include <boost/date_time.hpp>
#include "../Font.h" #include "../resources/Font.h"
class DateTimeComponent : public GuiComponent class DateTimeComponent : public GuiComponent
{ {

View file

@ -1,7 +1,7 @@
#include "GuiDetectDevice.h" #include "GuiDetectDevice.h"
#include "../Window.h" #include "../Window.h"
#include "../Renderer.h" #include "../Renderer.h"
#include "../Font.h" #include "../resources/Font.h"
#include "GuiInputConfig.h" #include "GuiInputConfig.h"
#include <iostream> #include <iostream>
#include <string> #include <string>

View file

@ -1,7 +1,7 @@
#include "GuiInputConfig.h" #include "GuiInputConfig.h"
#include "../Window.h" #include "../Window.h"
#include "../Renderer.h" #include "../Renderer.h"
#include "../Font.h" #include "../resources/Font.h"
#include "GuiGameList.h" #include "GuiGameList.h"
#include "../Log.h" #include "../Log.h"

View file

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "../GuiComponent.h" #include "../GuiComponent.h"
#include "../Font.h" #include "../resources/Font.h"
#include <vector> #include <vector>
#include <functional> #include <functional>
#include "../Renderer.h" #include "../Renderer.h"

View file

@ -1,6 +1,6 @@
#include "SwitchComponent.h" #include "SwitchComponent.h"
#include "../Renderer.h" #include "../Renderer.h"
#include "../Font.h" #include "../resources/Font.h"
#include "../Window.h" #include "../Window.h"
SwitchComponent::SwitchComponent(Window* window, bool state) : GuiComponent(window), mState(state) SwitchComponent::SwitchComponent(Window* window, bool state) : GuiComponent(window), mState(state)

View file

@ -2,7 +2,7 @@
#define _TEXTCOMPONENT_H_ #define _TEXTCOMPONENT_H_
#include "../GuiComponent.h" #include "../GuiComponent.h"
#include "../Font.h" #include "../resources/Font.h"
class TextComponent : public GuiComponent class TextComponent : public GuiComponent
{ {

View file

@ -1,6 +1,6 @@
#include "TextEditComponent.h" #include "TextEditComponent.h"
#include "../Log.h" #include "../Log.h"
#include "../Font.h" #include "../resources/Font.h"
#include "../Window.h" #include "../Window.h"
#include "../Renderer.h" #include "../Renderer.h"
#include "ComponentListComponent.h" #include "ComponentListComponent.h"

View file

@ -2,7 +2,7 @@
#define _TEXTLISTCOMPONENT_H_ #define _TEXTLISTCOMPONENT_H_
#include "../Renderer.h" #include "../Renderer.h"
#include "../Font.h" #include "../resources/Font.h"
#include "../GuiComponent.h" #include "../GuiComponent.h"
#include "../InputManager.h" #include "../InputManager.h"
#include <vector> #include <vector>

View file

@ -6,7 +6,7 @@
#include "../GuiComponent.h" #include "../GuiComponent.h"
#include "../pugiXML/pugixml.hpp" #include "../pugiXML/pugixml.hpp"
#include "../AudioManager.h" #include "../AudioManager.h"
#include "../Font.h" #include "../resources/Font.h"
//This class loads an XML-defined list of GuiComponents. //This class loads an XML-defined list of GuiComponents.
class ThemeComponent : public GuiComponent class ThemeComponent : public GuiComponent

File diff suppressed because it is too large Load diff

View file

@ -1,121 +1,121 @@
#ifndef _FONT_H_ #ifndef _FONT_H_
#define _FONT_H_ #define _FONT_H_
#include <string> #include <string>
#include "platform.h" #include "../platform.h"
#include GLHEADER #include GLHEADER
#include <ft2build.h> #include <ft2build.h>
#include FT_FREETYPE_H #include FT_FREETYPE_H
#include <Eigen/Dense> #include <Eigen/Dense>
#include "resources/ResourceManager.h" #include "ResourceManager.h"
class TextCache; class TextCache;
#define FONT_SIZE_SMALL ((unsigned int)(0.035f * Renderer::getScreenHeight())) #define FONT_SIZE_SMALL ((unsigned int)(0.035f * Renderer::getScreenHeight()))
#define FONT_SIZE_MEDIUM ((unsigned int)(0.045f * Renderer::getScreenHeight())) #define FONT_SIZE_MEDIUM ((unsigned int)(0.045f * Renderer::getScreenHeight()))
#define FONT_SIZE_LARGE ((unsigned int)(0.1f * Renderer::getScreenHeight())) #define FONT_SIZE_LARGE ((unsigned int)(0.1f * Renderer::getScreenHeight()))
//A TrueType Font renderer that uses FreeType and OpenGL. //A TrueType Font renderer that uses FreeType and OpenGL.
//The library is automatically initialized when it's needed. //The library is automatically initialized when it's needed.
class Font : public IReloadable class Font : public IReloadable
{ {
public: public:
static void initLibrary(); static void initLibrary();
static std::shared_ptr<Font> get(int size, const std::string& path = getDefaultPath()); static std::shared_ptr<Font> get(int size, const std::string& path = getDefaultPath());
~Font(); ~Font();
FT_Face face; FT_Face face;
//contains sizing information for every glyph. //contains sizing information for every glyph.
struct charPosData { struct charPosData {
int texX; int texX;
int texY; int texY;
int texW; int texW;
int texH; int texH;
float advX; //!<The horizontal distance to advance to the next character after this one float advX; //!<The horizontal distance to advance to the next character after this one
float advY; //!<The vertical distance to advance to the next character after this one float advY; //!<The vertical distance to advance to the next character after this one
float bearingX; //!<The horizontal distance from the cursor to the start of the character float bearingX; //!<The horizontal distance from the cursor to the start of the character
float bearingY; //!<The vertical distance from the cursor to the start of the character float bearingY; //!<The vertical distance from the cursor to the start of the character
}; };
charPosData charData[128]; charPosData charData[128];
GLuint textureID; GLuint textureID;
TextCache* buildTextCache(const std::string& text, float offsetX, float offsetY, unsigned int color); TextCache* buildTextCache(const std::string& text, float offsetX, float offsetY, unsigned int color);
void renderTextCache(TextCache* cache); void renderTextCache(TextCache* cache);
//Create a TextCache, render with it, then delete it. Best used for short text or text that changes frequently. //Create a TextCache, render with it, then delete it. Best used for short text or text that changes frequently.
void drawText(std::string text, const Eigen::Vector2f& offset, unsigned int color); void drawText(std::string text, const Eigen::Vector2f& offset, unsigned int color);
Eigen::Vector2f sizeText(std::string text) const; //Sets the width and height of a given string to supplied pointers. A dimension is skipped if its pointer is NULL. Eigen::Vector2f sizeText(std::string text) const; //Sets the width and height of a given string to supplied pointers. A dimension is skipped if its pointer is NULL.
std::string wrapText(std::string text, float xLen) const; std::string wrapText(std::string text, float xLen) const;
void drawWrappedText(std::string text, const Eigen::Vector2f& offset, float xLen, unsigned int color); void drawWrappedText(std::string text, const Eigen::Vector2f& offset, float xLen, unsigned int color);
Eigen::Vector2f sizeWrappedText(std::string text, float xLen) const; Eigen::Vector2f sizeWrappedText(std::string text, float xLen) const;
Eigen::Vector2f getWrappedTextCursorOffset(std::string text, float xLen, int cursor) const; Eigen::Vector2f getWrappedTextCursorOffset(std::string text, float xLen, int cursor) const;
void drawCenteredText(std::string text, float xOffset, float y, unsigned int color); void drawCenteredText(std::string text, float xOffset, float y, unsigned int color);
int getHeight() const; int getHeight() const;
void unload(std::shared_ptr<ResourceManager>& rm) override; void unload(std::shared_ptr<ResourceManager>& rm) override;
void reload(std::shared_ptr<ResourceManager>& rm) override; void reload(std::shared_ptr<ResourceManager>& rm) override;
int getSize() const; int getSize() const;
static std::string getDefaultPath(); static std::string getDefaultPath();
private: private:
static int getDpiX(); static int getDpiX();
static int getDpiY(); static int getDpiY();
static FT_Library sLibrary; static FT_Library sLibrary;
static bool libraryInitialized; static bool libraryInitialized;
static std::map< std::pair<std::string, int>, std::weak_ptr<Font> > sFontMap; static std::map< std::pair<std::string, int>, std::weak_ptr<Font> > sFontMap;
Font(int size, const std::string& path); Font(int size, const std::string& path);
void init(ResourceData data); void init(ResourceData data);
void deinit(); void deinit();
void buildAtlas(ResourceData data); //Builds a "texture atlas," one big OpenGL texture with glyphs 32 to 128. void buildAtlas(ResourceData data); //Builds a "texture atlas," one big OpenGL texture with glyphs 32 to 128.
int textureWidth; //OpenGL texture width int textureWidth; //OpenGL texture width
int textureHeight; //OpenGL texture height int textureHeight; //OpenGL texture height
int mMaxGlyphHeight; int mMaxGlyphHeight;
float fontScale; //!<Font scale factor. It is > 1.0 if the font would be to big for the texture float fontScale; //!<Font scale factor. It is > 1.0 if the font would be to big for the texture
int mSize; int mSize;
const std::string mPath; const std::string mPath;
}; };
class TextCache class TextCache
{ {
public: public:
struct Vertex struct Vertex
{ {
Eigen::Vector2f pos; Eigen::Vector2f pos;
Eigen::Vector2f tex; Eigen::Vector2f tex;
}; };
struct CacheMetrics struct CacheMetrics
{ {
Eigen::Vector2f size; Eigen::Vector2f size;
} metrics; } metrics;
void setColor(unsigned int color); void setColor(unsigned int color);
TextCache(int verts, Vertex* v, GLubyte* c, const CacheMetrics& m); TextCache(int verts, Vertex* v, GLubyte* c, const CacheMetrics& m);
~TextCache(); ~TextCache();
int vertCount; int vertCount;
Vertex* verts; Vertex* verts;
GLubyte* colors; GLubyte* colors;
}; };
#endif #endif