Compile with clang and add cotire

* Add cotire cmake module to speedup compilation https://github.com/sakra/cotire
* Fix clang error and warnings
* Rename Font to BitmapFont to fix conflict with Xlib.g Font typedef
* Remove legacy PCH support
* Improve Position hash
This commit is contained in:
Eduardo Bart
2012-06-16 20:19:43 -03:00
parent 4813b7eb4b
commit 10b33c6124
24 changed files with 2835 additions and 373 deletions

View File

@@ -20,14 +20,14 @@
* THE SOFTWARE.
*/
#include "font.h"
#include "bitmapfont.h"
#include "texturemanager.h"
#include "graphics.h"
#include "image.h"
#include <framework/otml/otml.h>
void Font::load(const OTMLNodePtr& fontNode)
void BitmapFont::load(const OTMLNodePtr& fontNode)
{
OTMLNodePtr textureNode = fontNode->at("texture");
std::string textureFile = stdext::resolve_path(textureNode->value(), textureNode->source());
@@ -66,14 +66,14 @@ void Font::load(const OTMLNodePtr& fontNode)
}
}
void Font::drawText(const std::string& text, const Point& startPos)
void BitmapFont::drawText(const std::string& text, const Point& startPos)
{
Size boxSize = g_painter->getResolution() - startPos.toSize();
Rect screenCoords(startPos, boxSize);
drawText(text, screenCoords, Fw::AlignTopLeft);
}
void Font::drawText(const std::string& text, const Rect& screenCoords, Fw::AlignmentFlag align)
void BitmapFont::drawText(const std::string& text, const Rect& screenCoords, Fw::AlignmentFlag align)
{
static CoordsBuffer coordsBuffer;
coordsBuffer.clear();
@@ -82,7 +82,7 @@ void Font::drawText(const std::string& text, const Rect& screenCoords, Fw::Align
g_painter->drawTextureCoords(coordsBuffer, m_texture);
}
void Font::calculateDrawTextCoords(CoordsBuffer& coordsBuffer, const std::string& text, const Rect& screenCoords, Fw::AlignmentFlag align)
void BitmapFont::calculateDrawTextCoords(CoordsBuffer& coordsBuffer, const std::string& text, const Rect& screenCoords, Fw::AlignmentFlag align)
{
// prevent glitches from invalid rects
if(!screenCoords.isValid() || !m_texture)
@@ -158,7 +158,7 @@ void Font::calculateDrawTextCoords(CoordsBuffer& coordsBuffer, const std::string
}
}
const std::vector<Point>& Font::calculateGlyphsPositions(const std::string& text,
const std::vector<Point>& BitmapFont::calculateGlyphsPositions(const std::string& text,
Fw::AlignmentFlag align,
Size *textBoxSize) const
{
@@ -242,14 +242,14 @@ const std::vector<Point>& Font::calculateGlyphsPositions(const std::string& text
return glyphsPositions;
}
Size Font::calculateTextRectSize(const std::string& text)
Size BitmapFont::calculateTextRectSize(const std::string& text)
{
Size size;
calculateGlyphsPositions(text, Fw::AlignTopLeft, &size);
return size;
}
void Font::calculateGlyphsWidthsAutomatically(const ImagePtr& image, const Size& glyphSize)
void BitmapFont::calculateGlyphsWidthsAutomatically(const ImagePtr& image, const Size& glyphSize)
{
int numHorizontalGlyphs = image->getSize().width() / glyphSize.width();
auto texturePixels = image->getPixels();
@@ -280,7 +280,7 @@ void Font::calculateGlyphsWidthsAutomatically(const ImagePtr& image, const Size&
}
}
std::string Font::wrapText(const std::string& text, int maxWidth)
std::string BitmapFont::wrapText(const std::string& text, int maxWidth)
{
std::string outText;
std::string line;

View File

@@ -20,18 +20,18 @@
* THE SOFTWARE.
*/
#ifndef FONT_H
#define FONT_H
#ifndef BITMAPFONT_H
#define BITMAPFONT_H
#include "declarations.h"
#include <framework/otml/declarations.h>
#include <framework/graphics/coordsbuffer.h>
class Font
class BitmapFont
{
public:
Font(const std::string& name) : m_name(name) { }
BitmapFont(const std::string& name) : m_name(name) { }
/// Load font from otml node
void load(const OTMLNodePtr& fontNode);

View File

@@ -23,7 +23,7 @@
#include "cachedtext.h"
#include "painter.h"
#include "fontmanager.h"
#include "font.h"
#include "bitmapfont.h"
CachedText::CachedText()
{

View File

@@ -34,13 +34,13 @@ public:
void draw(const Rect& rect);
void wrapText(int maxWidth);
void setFont(const FontPtr& font) { m_font = font; update(); }
void setFont(const BitmapFontPtr& font) { m_font = font; update(); }
void setText(const std::string& text) { m_text = text; update(); }
void setAlign(Fw::AlignmentFlag align) { m_align = align; update(); }
Size getTextSize() { return m_textSize; }
std::string getText() { return m_text; }
FontPtr getFont() { return m_font; }
BitmapFontPtr getFont() { return m_font; }
Fw::AlignmentFlag getAlign() { return m_align; }
private:
@@ -51,7 +51,7 @@ private:
Boolean<true> m_textMustRecache;
CoordsBuffer m_textCoordsBuffer;
Rect m_textCachedScreenCoords;
FontPtr m_font;
BitmapFontPtr m_font;
Fw::AlignmentFlag m_align;
};

View File

@@ -29,7 +29,7 @@
class Texture;
class Image;
class AnimatedTexture;
class Font;
class BitmapFont;
class CachedText;
class FrameBuffer;
class Shader;
@@ -46,7 +46,7 @@ typedef std::weak_ptr<ParticleSystem> ParticleSystemWeakPtr;
typedef std::shared_ptr<Image> ImagePtr;
typedef std::shared_ptr<Texture> TexturePtr;
typedef std::shared_ptr<AnimatedTexture> AnimatedTexturePtr;
typedef std::shared_ptr<Font> FontPtr;
typedef std::shared_ptr<BitmapFont> BitmapFontPtr;
typedef std::shared_ptr<CachedText> CachedTextPtr;
typedef std::shared_ptr<FrameBuffer> FrameBufferPtr;
typedef std::shared_ptr<Shader> ShaderPtr;

View File

@@ -29,7 +29,7 @@ FontManager g_fonts;
FontManager::FontManager()
{
m_defaultFont = FontPtr(new Font("emptyfont"));
m_defaultFont = BitmapFontPtr(new BitmapFont("emptyfont"));
}
void FontManager::releaseFonts()
@@ -57,7 +57,7 @@ bool FontManager::importFont(std::string fontFile)
}
}
FontPtr font(new Font(name));
BitmapFontPtr font(new BitmapFont(name));
font->load(fontNode);
m_fonts.push_back(font);
@@ -74,17 +74,17 @@ bool FontManager::importFont(std::string fontFile)
bool FontManager::fontExists(const std::string& fontName)
{
for(const FontPtr& font : m_fonts) {
for(const BitmapFontPtr& font : m_fonts) {
if(font->getName() == fontName)
return true;
}
return false;
}
FontPtr FontManager::getFont(const std::string& fontName)
BitmapFontPtr FontManager::getFont(const std::string& fontName)
{
// find font by name
for(const FontPtr& font : m_fonts) {
for(const BitmapFontPtr& font : m_fonts) {
if(font->getName() == fontName)
return font;
}

View File

@@ -23,7 +23,7 @@
#ifndef FONTMANAGER_H
#define FONTMANAGER_H
#include "font.h"
#include "bitmapfont.h"
class FontManager
{
@@ -37,14 +37,14 @@ public:
bool importFont(std::string fontFile);
bool fontExists(const std::string& fontName);
FontPtr getFont(const std::string& fontName);
FontPtr getDefaultFont() { return m_defaultFont; }
BitmapFontPtr getFont(const std::string& fontName);
BitmapFontPtr getDefaultFont() { return m_defaultFont; }
void setDefaultFont(const std::string& fontName) { m_defaultFont = getFont(fontName); }
private:
std::vector<FontPtr> m_fonts;
FontPtr m_defaultFont;
std::vector<BitmapFontPtr> m_fonts;
BitmapFontPtr m_defaultFont;
};
extern FontManager g_fonts;

View File

@@ -20,6 +20,9 @@
* THE SOFTWARE.
*/
#ifndef PAINTEROGL2_SHADERSOURCES_H
#define PAINTEROGL2_SHADERSOURCES_H
static const std::string glslMainVertexShader = "\n\
highp vec4 calculatePosition();\n\
void main() {\n\
@@ -66,3 +69,5 @@ static const std::string glslSolidColorFragmentShader = "\n\
lowp vec4 calculatePixel() {\n\
return u_Color;\n\
}\n";
#endif

View File

@@ -78,6 +78,7 @@ bool Shader::compileSourceFile(const std::string& sourceFile)
} catch(stdext::exception& e) {
g_logger.error(stdext::format("unable to load shader source form file: %s", sourceFile));
}
return false;
}
std::string Shader::log()