From 12087c1a6579d3fa7e06b50cbbc58fb4f505c512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Thu, 20 Jun 2013 02:38:56 -0300 Subject: [PATCH] Changed the text vertical draw implementation. Removed the bool to activate the vertical draw everywere, and added FONT_DRAW_VERTICAL flag to draw in vertical mode. --- include/eepp/graphics/cfont.hpp | 26 +- include/eepp/graphics/ctextcache.hpp | 36 ++- include/eepp/graphics/ctexturefont.hpp | 15 +- include/eepp/graphics/ctexturefontloader.hpp | 13 +- include/eepp/graphics/cttffont.hpp | 11 +- include/eepp/graphics/cttffontloader.hpp | 10 +- include/eepp/graphics/fonthelper.hpp | 2 + include/eepp/ui/uihelper.hpp | 37 +-- projects/linux/ee.creator.user | 2 +- src/eepp/graphics/cfont.cpp | 303 ++++--------------- src/eepp/graphics/ctextcache.cpp | 40 ++- src/eepp/graphics/ctexturefont.cpp | 22 +- src/eepp/graphics/ctexturefontloader.cpp | 20 +- src/eepp/graphics/cttffont.cpp | 17 +- src/eepp/graphics/cttffontloader.cpp | 15 +- src/eepp/ui/cuitextbox.cpp | 3 +- src/eepp/ui/cuitooltip.cpp | 3 +- src/test/eetest.cpp | 11 +- 18 files changed, 194 insertions(+), 392 deletions(-) diff --git a/include/eepp/graphics/cfont.hpp b/include/eepp/graphics/cfont.hpp index 1e37ba34f..765319989 100755 --- a/include/eepp/graphics/cfont.hpp +++ b/include/eepp/graphics/cfont.hpp @@ -19,7 +19,7 @@ class EE_API cFont { void SetText( const String& Text ); /** @return The width of the string rendered */ - eeFloat GetTextWidth() const; + eeFloat GetTextWidth(); /** @return Assign a new text and then returns his width */ eeFloat GetTextWidth( const String& Text ); @@ -60,14 +60,8 @@ class EE_API cFont { /** @return The current text */ String GetText(); - /** Set if the font will cache de text width and the number of lines ( default: true ). */ - void CacheData( bool Cache ); - - /** @return If the font is caching the text data. */ - const bool& CacheData() const; - /** @return The last text rendered or setted lines width */ - const std::vector& GetLinesWidth() const; + const std::vector& GetLinesWidth(); /** Draw a String on the screen * @param Text The text to draw @@ -114,7 +108,7 @@ class EE_API cFont { void ShrinkText( std::string& Str, const Uint32& MaxWidth ); /** Cache the with of the current text */ - void CacheWidth( const String& Text, std::vector& LinesWidth, eeFloat& CachedWidth, eeInt& NumLines ); + void CacheWidth( const String& Text, std::vector& LinesWidth, eeFloat& CachedWidth, eeInt& NumLines, eeInt& LargestLineCharCount ); /** @return The font texture id */ const Uint32& GetTexId() const; @@ -134,33 +128,21 @@ class EE_API cFont { Uint32 mType; std::string mFontName; Uint32 mFontHash; - - String mText; - bool mCacheData; - eeColorA mColor; - eeColorA mShadowColor; - eeInt mNumLines; - bool mVerticalDraw; Uint32 mTexId; - eeFloat mCachedWidth; Uint32 mHeight; Uint32 mSize; Int32 mLineSkip; Int32 mAscent; Int32 mDescent; - std::vector mLinesWidth; std::vector mGlyphs; std::vector mTexCoords; - std::vector mRenderCoords; - std::vector mColors; + cTextCache mTextCache; cFont( const Uint32& Type, const std::string& Name ); void CacheWidth(); - void CacheNumLines(); - void SubDraw( const String& Text, const eeFloat& X, const eeFloat& Y, const Uint32& Flags, const eeFloat& Scale, const eeFloat& Angle, const bool& Cached, const EE_BLEND_MODE& Effect ); }; }} diff --git a/include/eepp/graphics/ctextcache.hpp b/include/eepp/graphics/ctextcache.hpp index 1460981c2..d12c3b2ee 100644 --- a/include/eepp/graphics/ctextcache.hpp +++ b/include/eepp/graphics/ctextcache.hpp @@ -11,35 +11,45 @@ class cFont; /** @brief Caches text for a fast font rendering. */ class EE_API cTextCache { public: + /** Create a text from a font */ cTextCache( cFont * font, const String& text = "", eeColorA FontColor = eeColorA(255,255,255,255), eeColorA FontShadowColor = eeColorA(0,0,0,255) ); cTextCache(); ~cTextCache(); + /** Create a text from a font */ void Create( cFont * font, const String& text = "", eeColorA FontColor = eeColorA(255,255,255,255), eeColorA FontShadowColor = eeColorA(0,0,0,255) ); + /** @return The font used for the text cache */ cFont * Font() const; + /** Change the font used for the text cache */ void Font( cFont * font ); + /** @return The text cached */ String& Text(); + /** Set the text to be cached */ void Text( const String& text ); + /** @return The cached text width */ eeFloat GetTextWidth(); + /** @return The cached text height */ eeFloat GetTextHeight(); + /** @return Every cached text line width */ const std::vector& LinesWidth(); + /** @return The vertex coordinates cached */ std::vector& VertextCoords(); + /** @return The text colors cached */ std::vector& Colors(); - void Draw( const eeFloat& X, const eeFloat& Y, const Uint32& Flags = 0, const eeFloat& Scale = 1.0f, const eeFloat& Angle = 0, EE_BLEND_MODE Effect = ALPHA_NORMAL ); - - void Cache(); + /** Draw the cached text on screen */ + void Draw( const eeFloat& X, const eeFloat& Y, const eeFloat& Scale = 1.0f, const eeFloat& Angle = 0, EE_BLEND_MODE Effect = ALPHA_NORMAL ); /** @return The Font Color */ const eeColorA& Color() const; @@ -60,27 +70,39 @@ class EE_API cTextCache { /** Set the shadow color of the string rendered */ void ShadowColor(const eeColorA& color); + /** @return The number of lines that the cached text contains */ const eeInt& GetNumLines() const; + + /** Set the font draw flags */ + void Flags( const Uint32& flags ); + + /** @return The font draw flags */ + const Uint32& Flags() const; + + /** Force to cache the width of the current text */ + void Cache(); protected: friend class cFont; String mText; cFont * mFont; - std::vector mLinesWidth; + eeFloat mCachedWidth; eeInt mNumLines; + eeInt mLargestLineCharCount; eeColorA mFontColor; eeColorA mFontShadowColor; - std::vector mRenderCoords; - std::vector mColors; - Uint32 mFlags; Uint32 mVertexNumCached; bool mCachedCoords; + std::vector mLinesWidth; + std::vector mRenderCoords; + std::vector mColors; + void UpdateCoords(); const bool& CachedCoords() const; diff --git a/include/eepp/graphics/ctexturefont.hpp b/include/eepp/graphics/ctexturefont.hpp index 0bbad4f19..6d884b463 100755 --- a/include/eepp/graphics/ctexturefont.hpp +++ b/include/eepp/graphics/ctexturefont.hpp @@ -20,47 +20,42 @@ class EE_API cTextureFont : public cFont { * @param TexId The texture id returned by cTextureFactory * @param StartChar The fist char represented on the texture * @param Spacing The space between every char ( default 0 means TextureWidth / TexColumns ) - * @param VerticalDraw If true render the string verticaly * @param TexColumns The number of chars per column * @param TexRows The number of chars per row * @param NumChars The number of characters to read from the texture * @return True if success */ - bool Load( const Uint32& TexId, const eeUint& StartChar = 0, const eeUint& Spacing = 0, const bool& VerticalDraw = false, const eeUint& TexColumns = 16, const eeUint& TexRows = 16, const Uint16& NumChars = 256 ); + bool Load( const Uint32& TexId, const eeUint& StartChar = 0, const eeUint& Spacing = 0, const eeUint& TexColumns = 16, const eeUint& TexRows = 16, const Uint16& NumChars = 256 ); /** Load's a texture font and then load's the character coordinates file ( generated by the cTTFFont class ) * @param TexId The texture id returned by cTextureFactory * @param CoordinatesDatPath The character coordinates file - * @param VerticalDraw If true render the string verticaly * @return True if success */ - bool Load( const Uint32& TexId, const std::string& CoordinatesDatPath, const bool& VerticalDraw = false ); + bool Load( const Uint32& TexId, const std::string& CoordinatesDatPath ); /** * @param TexId The texture id returned by cTextureFactory * @param Pack Pointer to the pack instance * @param FilePackPath The path of the file inside the pack - * @param VerticalDraw If true render the string verticaly * @return True success */ - bool LoadFromPack( const Uint32& TexId, cPack * Pack, const std::string& FilePackPath, const bool& VerticalDraw = false ); + bool LoadFromPack( const Uint32& TexId, cPack * Pack, const std::string& FilePackPath ); /** Load's a texture font and then load's the character coordinates file previously loaded on memory ( generated by the cTTFFont class ) * @param TexId The texture id returned by cTextureFactory * @param CoordData The character coordinates buffer pointer * @param CoordDataSize The size of CoordData - * @param VerticalDraw If true render the string verticaly * @return True if success */ - bool LoadFromMemory( const Uint32& TexId, const char* CoordData, const Uint32& CoordDataSize, const bool& VerticalDraw = false ); + bool LoadFromMemory( const Uint32& TexId, const char* CoordData, const Uint32& CoordDataSize ); /** Load's a texture font and then load's the character coordinates from a IO stream file ( generated by the cTTFFont class ) * @param TexId The texture id returned by cTextureFactory * @param IOS IO stream file for the coordinates - * @param VerticalDraw If true render the string verticaly * @return True if success */ - bool LoadFromStream( const Uint32& TexId, cIOStream& IOS, const bool& VerticalDraw ); + bool LoadFromStream( const Uint32& TexId, cIOStream& IOS ); private: eeUint mStartChar; eeUint mTexColumns; diff --git a/include/eepp/graphics/ctexturefontloader.hpp b/include/eepp/graphics/ctexturefontloader.hpp index 57f311968..da348feb9 100644 --- a/include/eepp/graphics/ctexturefontloader.hpp +++ b/include/eepp/graphics/ctexturefontloader.hpp @@ -18,38 +18,34 @@ class EE_API cTextureFontLoader : public cObjectLoader { * @param TexLoader An instance of a texture loader that will be used to load the texture. The instance will be released by the Texture Font Loader when is destroyed. * @param StartChar The fist char represented on the texture * @param Spacing The space between every char ( default 0 means TextureWidth / TexColumns ) - * @param VerticalDraw If true render the string verticaly * @param TexColumns The number of chars per column * @param TexRows The number of chars per row * @param NumChars The number of characters to read from the texture */ - cTextureFontLoader( const std::string FontName, cTextureLoader * TexLoader, const eeUint& StartChar = 0, const eeUint& Spacing = 0, const bool& VerticalDraw = false, const eeUint& TexColumns = 16, const eeUint& TexRows = 16, const Uint16& NumChars = 256 ); + cTextureFontLoader( const std::string FontName, cTextureLoader * TexLoader, const eeUint& StartChar = 0, const eeUint& Spacing = 0, const eeUint& TexColumns = 16, const eeUint& TexRows = 16, const Uint16& NumChars = 256 ); /** Load's a texture font and then load's the character coordinates file ( generated by the cTTFFont class ) * @param FontName The font name * @param TexLoader An instance of a texture loader that will be used to load the texture. The instance will be released by the Texture Font Loader when is destroyed. * @param CoordinatesDatPath The character coordinates file ( this is the file created when the TTF font was converted to a texture font. @see cTTFFont::Save ). - * @param VerticalDraw If true render the string verticaly */ - cTextureFontLoader( const std::string FontName, cTextureLoader * TexLoader, const std::string& CoordinatesDatPath, const bool& VerticalDraw = false ); + cTextureFontLoader( const std::string FontName, cTextureLoader * TexLoader, const std::string& CoordinatesDatPath ); /** Load's a texture font and then load's the character coordinates file ( generated by the cTTFFont class ) stored in a pack file. * @param FontName The font name * @param TexLoader An instance of a texture loader that will be used to load the texture. The instance will be released by the Texture Font Loader when is destroyed. * @param Pack The pack used to load the characters coordinates * @param FilePackPath The character coordinates file path inside the pack ( this is the file created when the TTF font was converted to a texture font. @see cTTFFont::Save ). - * @param VerticalDraw If true render the string verticaly */ - cTextureFontLoader( const std::string FontName, cTextureLoader * TexLoader, cPack * Pack, const std::string& FilePackPath, const bool& VerticalDraw = false ); + cTextureFontLoader( const std::string FontName, cTextureLoader * TexLoader, cPack * Pack, const std::string& FilePackPath ); /** Load's a texture font and then load's the character coordinates file ( generated by the cTTFFont class ) from memory. * @param FontName The font name * @param TexLoader An instance of a texture loader that will be used to load the texture. The instance will be released by the Texture Font Loader when is destroyed. * @param CoordData The character coordinates buffer pointer ( this is the file created when the TTF font was converted to a texture font. @see cTTFFont::Save ). * @param CoordDataSize The buffer pointer size - * @param VerticalDraw If true render the string verticaly */ - cTextureFontLoader( const std::string FontName, cTextureLoader * TexLoader, const char* CoordData, const Uint32& CoordDataSize, const bool& VerticalDraw = false ); + cTextureFontLoader( const std::string FontName, cTextureLoader * TexLoader, const char* CoordData, const Uint32& CoordDataSize ); virtual ~cTextureFontLoader(); @@ -85,7 +81,6 @@ class EE_API cTextureFontLoader : public cObjectLoader { eeUint mStartChar; eeUint mSpacing; - bool mVerticalDraw; eeUint mTexColumns; eeUint mTexRows; eeUint mNumChars; diff --git a/include/eepp/graphics/cttffont.hpp b/include/eepp/graphics/cttffont.hpp index 8c68c99dd..f6e70c867 100755 --- a/include/eepp/graphics/cttffont.hpp +++ b/include/eepp/graphics/cttffont.hpp @@ -24,7 +24,6 @@ class EE_API cTTFFont : public cFont { * @param Filepath The TTF file path * @param Size The Size Width and Height for the font. * @param Style The Font Style - * @param VerticalDraw If draw in vertical instead of horizontal * @param NumCharsToGen Determine the number of characters to generate ( from char 0 to ... x ) * @param FontColor The Font color (this is the texture font color, if you plan to use a custom color and use outline, set it ) * @param OutlineSize The Ouline Size @@ -32,14 +31,13 @@ class EE_API cTTFFont : public cFont { * @param AddPixelSeparator Indicates if separates the glyphs by a pixel to avoid problems with font scaling * @return If success */ - bool Load( const std::string& Filepath, const eeUint& Size, EE_TTF_FONT_STYLE Style = TTF_STYLE_NORMAL, const bool& VerticalDraw = false, const Uint16& NumCharsToGen = 512, const eeColor& FontColor = eeColor(), const Uint8& OutlineSize = 0, const eeColor& OutlineColor = eeColor(0,0,0), const bool& AddPixelSeparator = true ); + bool Load( const std::string& Filepath, const eeUint& Size, EE_TTF_FONT_STYLE Style = TTF_STYLE_NORMAL, const Uint16& NumCharsToGen = 512, const eeColor& FontColor = eeColor(), const Uint8& OutlineSize = 0, const eeColor& OutlineColor = eeColor(0,0,0), const bool& AddPixelSeparator = true ); /** Loads a True Type Font from pack * @param Pack Pointer to the pack instance * @param FilePackPath The path of the file inside the pack * @param Size The Size of the Font * @param Style The Font Style - * @param VerticalDraw If draw in vertical instead of horizontal * @param NumCharsToGen Determine the number of characters to generate ( from char 0 to ... x ) * @param FontColor The Font color (this is the texture font color, if you plan to use a custom color and use outline, set it ) * @param OutlineSize The Ouline Size @@ -47,14 +45,13 @@ class EE_API cTTFFont : public cFont { * @param AddPixelSeparator Indicates if separates the glyphs by a pixel to avoid problems with font scaling * @return If success */ - bool LoadFromPack( cPack* Pack, const std::string& FilePackPath, const eeUint& Size, EE_TTF_FONT_STYLE Style = TTF_STYLE_NORMAL, const bool& VerticalDraw = false, const Uint16& NumCharsToGen = 512, const eeColor& FontColor = eeColor(), const Uint8& OutlineSize = 0, const eeColor& OutlineColor = eeColor(0,0,0), const bool& AddPixelSeparator = true ); + bool LoadFromPack( cPack* Pack, const std::string& FilePackPath, const eeUint& Size, EE_TTF_FONT_STYLE Style = TTF_STYLE_NORMAL, const Uint16& NumCharsToGen = 512, const eeColor& FontColor = eeColor(), const Uint8& OutlineSize = 0, const eeColor& OutlineColor = eeColor(0,0,0), const bool& AddPixelSeparator = true ); /** Loads a True Type Font from memory * @param TTFData The pointer to the data * @param TTFDataSize The size of the data * @param Size The Size of the Font * @param Style The Font Style - * @param VerticalDraw If draw in vertical instead of horizontal * @param NumCharsToGen Determine the number of characters to generate ( from char 0 to ... x ) * @param FontColor The Font color (this is the texture font color, if you plan to use a custom color and use outline, set it ) * @param OutlineSize The Ouline Size @@ -62,7 +59,7 @@ class EE_API cTTFFont : public cFont { * @param AddPixelSeparator Indicates if separates the glyphs by a pixel to avoid problems with font scaling * @return If success */ - bool LoadFromMemory( Uint8* TTFData, const eeUint& TTFDataSize, const eeUint& Size, EE_TTF_FONT_STYLE Style = TTF_STYLE_NORMAL, const bool& VerticalDraw = false, const Uint16& NumCharsToGen = 512, const eeColor& FontColor = eeColor(), const Uint8& OutlineSize = 0, const eeColor& OutlineColor = eeColor(0,0,0), const bool& AddPixelSeparator = true ); + bool LoadFromMemory( Uint8* TTFData, const eeUint& TTFDataSize, const eeUint& Size, EE_TTF_FONT_STYLE Style = TTF_STYLE_NORMAL, const Uint16& NumCharsToGen = 512, const eeColor& FontColor = eeColor(), const Uint8& OutlineSize = 0, const eeColor& OutlineColor = eeColor(0,0,0), const bool& AddPixelSeparator = true ); /** Save the texture generated from the TTF file to disk */ bool SaveTexture( const std::string& Filepath, const EE_SAVE_TYPE& Format = SAVE_TYPE_PNG ); @@ -103,7 +100,7 @@ class EE_API cTTFFont : public cFont { void UpdateLoading(); - bool iLoad( const eeUint& Size, EE_TTF_FONT_STYLE Style, const bool& VerticalDraw, const Uint16& NumCharsToGen, const eeColor& FontColor, Uint8 OutlineSize, const eeColor& OutlineColor, const bool& AddPixelSeparator ); + bool iLoad( const eeUint& Size, EE_TTF_FONT_STYLE Style, const Uint16& NumCharsToGen, const eeColor& FontColor, Uint8 OutlineSize, const eeColor& OutlineColor, const bool& AddPixelSeparator ); void MakeOutline( Uint8 *in, Uint8 *out, Int16 w, Int16 h, Int16 OutlineSize ); diff --git a/include/eepp/graphics/cttffontloader.hpp b/include/eepp/graphics/cttffontloader.hpp index fcf70761d..cfcc7bef0 100644 --- a/include/eepp/graphics/cttffontloader.hpp +++ b/include/eepp/graphics/cttffontloader.hpp @@ -18,14 +18,13 @@ class EE_API cTTFFontLoader : public cObjectLoader { * @param Filepath The TTF file path * @param Size The Size Width and Height for the font. * @param Style The Font Style - * @param VerticalDraw If draw in vertical instead of horizontal * @param NumCharsToGen Determine the number of characters to generate ( from char 0 to ... x ) * @param FontColor The Font color (this is the texture font color, if you plan to use a custom color and use outline, set it ) * @param OutlineSize The Ouline Size * @param OutlineColor The Outline Color * @param AddPixelSeparator Indicates if separates the glyphs by a pixel to avoid problems with font scaling */ - cTTFFontLoader( const std::string& FontName, const std::string& Filepath, const eeUint& Size, EE_TTF_FONT_STYLE Style = TTF_STYLE_NORMAL, const bool& VerticalDraw = false, const Uint16& NumCharsToGen = 512, const eeColor& FontColor = eeColor(), const Uint8& OutlineSize = 0, const eeColor& OutlineColor = eeColor(0,0,0), const bool& AddPixelSeparator = true ); + cTTFFontLoader( const std::string& FontName, const std::string& Filepath, const eeUint& Size, EE_TTF_FONT_STYLE Style = TTF_STYLE_NORMAL, const Uint16& NumCharsToGen = 512, const eeColor& FontColor = eeColor(), const Uint8& OutlineSize = 0, const eeColor& OutlineColor = eeColor(0,0,0), const bool& AddPixelSeparator = true ); /** Load a True Type Font from a Pack * @param FontName The font name @@ -33,14 +32,13 @@ class EE_API cTTFFontLoader : public cObjectLoader { * @param FilePackPath The path of the file inside the pack * @param Size The Size of the Font * @param Style The Font Style - * @param VerticalDraw If draw in vertical instead of horizontal * @param NumCharsToGen Determine the number of characters to generate ( from char 0 to ... x ) * @param FontColor The Font color (this is the texture font color, if you plan to use a custom color and use outline, set it ) * @param OutlineSize The Ouline Size * @param OutlineColor The Outline Color * @param AddPixelSeparator Indicates if separates the glyphs by a pixel to avoid problems with font scaling */ - cTTFFontLoader( const std::string& FontName, cPack * Pack, const std::string& FilePackPath, const eeUint& Size, EE_TTF_FONT_STYLE Style = TTF_STYLE_NORMAL, const bool& VerticalDraw = false, const Uint16& NumCharsToGen = 512, const eeColor& FontColor = eeColor(), const Uint8& OutlineSize = 0, const eeColor& OutlineColor = eeColor(0,0,0), const bool& AddPixelSeparator = true ); + cTTFFontLoader( const std::string& FontName, cPack * Pack, const std::string& FilePackPath, const eeUint& Size, EE_TTF_FONT_STYLE Style = TTF_STYLE_NORMAL, const Uint16& NumCharsToGen = 512, const eeColor& FontColor = eeColor(), const Uint8& OutlineSize = 0, const eeColor& OutlineColor = eeColor(0,0,0), const bool& AddPixelSeparator = true ); /** Loads a True Type Font from memory * @param FontName The font name @@ -48,14 +46,13 @@ class EE_API cTTFFontLoader : public cObjectLoader { * @param TTFDataSize The size of the data * @param Size The Size of the Font * @param Style The Font Style - * @param VerticalDraw If draw in vertical instead of horizontal * @param NumCharsToGen Determine the number of characters to generate ( from char 0 to ... x ) * @param FontColor The Font color (this is the texture font color, if you plan to use a custom color and use outline, set it ) * @param OutlineSize The Ouline Size * @param OutlineColor The Outline Color * @param AddPixelSeparator Indicates if separates the glyphs by a pixel to avoid problems with font scaling */ - cTTFFontLoader( const std::string& FontName, Uint8* TTFData, const eeUint& TTFDataSize, const eeUint& Size, EE_TTF_FONT_STYLE Style = TTF_STYLE_NORMAL, const bool& VerticalDraw = false, const Uint16& NumCharsToGen = 512, const eeColor& FontColor = eeColor(), const Uint8& OutlineSize = 0, const eeColor& OutlineColor = eeColor(0,0,0), const bool& AddPixelSeparator = true ); + cTTFFontLoader( const std::string& FontName, Uint8* TTFData, const eeUint& TTFDataSize, const eeUint& Size, EE_TTF_FONT_STYLE Style = TTF_STYLE_NORMAL, const Uint16& NumCharsToGen = 512, const eeColor& FontColor = eeColor(), const Uint8& OutlineSize = 0, const eeColor& OutlineColor = eeColor(0,0,0), const bool& AddPixelSeparator = true ); virtual ~cTTFFontLoader(); @@ -88,7 +85,6 @@ class EE_API cTTFFontLoader : public cObjectLoader { std::string mFilepath; eeUint mSize; EE_TTF_FONT_STYLE mStyle; - bool mVerticalDraw; Uint16 mNumCharsToGen; eeColor mFontColor; Uint8 mOutlineSize; diff --git a/include/eepp/graphics/fonthelper.hpp b/include/eepp/graphics/fonthelper.hpp index 51646c3f8..2ed73b79b 100644 --- a/include/eepp/graphics/fonthelper.hpp +++ b/include/eepp/graphics/fonthelper.hpp @@ -31,6 +31,8 @@ inline Uint32 FontVAlignGet( Uint32 Flags ) { } #define FONT_DRAW_SHADOW (1 << 5) +#define FONT_DRAW_VERTICAL (1 << 6) + #define FONT_DRAW_ALIGN_MASK ( FONT_DRAW_VALIGN_MASK | FONT_DRAW_HALIGN_MASK ) /** Basic Glyph structure used by the engine */ diff --git a/include/eepp/ui/uihelper.hpp b/include/eepp/ui/uihelper.hpp index 92317b7a2..06aa1c8e0 100644 --- a/include/eepp/ui/uihelper.hpp +++ b/include/eepp/ui/uihelper.hpp @@ -41,24 +41,25 @@ enum UI_FLAGS { UI_VALIGN_BOTTOM = FONT_DRAW_BOTTOM, UI_VALIGN_CENTER = FONT_DRAW_MIDDLE, UI_DRAW_SHADOW = FONT_DRAW_SHADOW, - UI_AUTO_SIZE = (1 << 6), - UI_INGORE_FOCUS = (1 << 7), - UI_FILL_BACKGROUND = (1 << 8), - UI_BORDER = (1 << 9), - UI_TAB_STOP = (1 << 10), - UI_FIT_TO_CONTROL = (1 << 11), - UI_CLIP_ENABLE = (1 << 12), - UI_AUTO_SHRINK_TEXT = (1 << 13), - UI_MULTI_SELECT = (1 << 14), - UI_AUTO_PADDING = (1 << 15), - UI_DRAG_ENABLE = (1 << 16), - UI_REPORT_SIZE_CHANGE_TO_CHILDS = (1 << 17), - UI_ANCHOR_TOP = (1 << 18), - UI_ANCHOR_BOTTOM = (1 << 19), - UI_ANCHOR_LEFT = (1 << 20), - UI_ANCHOR_RIGHT = (1 << 21), - UI_AUTO_FIT = (1 << 22), - UI_TOUCH_DRAG_ENABLED = (1 << 23) + UI_TEXT_DRAW_VERTICAL = FONT_DRAW_VERTICAL, + UI_AUTO_SIZE = (1 << 7), + UI_INGORE_FOCUS = (1 << 8), + UI_FILL_BACKGROUND = (1 << 9), + UI_BORDER = (1 << 10), + UI_TAB_STOP = (1 << 11), + UI_FIT_TO_CONTROL = (1 << 12), + UI_CLIP_ENABLE = (1 << 13), + UI_AUTO_SHRINK_TEXT = (1 << 14), + UI_MULTI_SELECT = (1 << 15), + UI_AUTO_PADDING = (1 << 16), + UI_DRAG_ENABLE = (1 << 17), + UI_REPORT_SIZE_CHANGE_TO_CHILDS = (1 << 18), + UI_ANCHOR_TOP = (1 << 19), + UI_ANCHOR_BOTTOM = (1 << 20), + UI_ANCHOR_LEFT = (1 << 21), + UI_ANCHOR_RIGHT = (1 << 22), + UI_AUTO_FIT = (1 << 23), + UI_TOUCH_DRAG_ENABLED = (1 << 24) }; enum UI_CONTROL_TYPES { diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 565fb9c26..6bbae736d 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + ProjectExplorer.Project.ActiveTarget diff --git a/src/eepp/graphics/cfont.cpp b/src/eepp/graphics/cfont.cpp index a835f702d..cb7e8c9a6 100644 --- a/src/eepp/graphics/cfont.cpp +++ b/src/eepp/graphics/cfont.cpp @@ -7,24 +7,19 @@ namespace EE { namespace Graphics { cFont::cFont( const Uint32& Type, const std::string& Name ) : mType( Type ), - mCacheData(true), - mColor(255,255,255,255), - mShadowColor(0,0,0,255), - mNumLines(1), mTexId(0), - mCachedWidth(0.f), mHeight(0), mSize(0), mLineSkip(0), mAscent(0), - mDescent(0) + mDescent(0), + mTextCache( this ) { this->Name( Name ); cFontManager::instance()->Add( this ); } cFont::~cFont() { - mText.clear(); mGlyphs.clear(); if ( !cFontManager::instance()->IsDestroying() ) { @@ -33,61 +28,36 @@ cFont::~cFont() { } void cFont::SetText( const String& Text ) { - if ( mText.size() != Text.size() ) { - Int32 size = Text.size() * EE_QUAD_VERTEX; - - mRenderCoords.resize( size ); - mColors.resize( size, mColor ); - } - - mText = Text; - - if ( mCacheData ) - CacheWidth(); + mTextCache.Text( Text ); } const eeColorA& cFont::Color() const { - return mColor; + return mTextCache.Color(); } void cFont::Color(const eeColorA& Color) { - if ( mColor != Color ) { - mColor = Color; - - mColors.assign( mText.size() * EE_QUAD_VERTEX, mColor ); - } + mTextCache.Color( Color ); } const eeColorA& cFont::ShadowColor() const { - return mShadowColor; + return mTextCache.ShadowColor(); } void cFont::ShadowColor(const eeColorA& Color) { - mShadowColor = Color; -} - -void cFont::CacheNumLines() { - Int32 c = 1; - - for ( eeUint i = 0; i < mText.size(); i++ ) { - if ( mText[i] == '\n' ) - c++; - } - - mNumLines = c; + mTextCache.ShadowColor( Color ); } eeInt cFont::GetNumLines() { - return mNumLines; + return mTextCache.GetNumLines(); } eeFloat cFont::GetTextWidth( const String& Text ) { SetText( Text ); - return mCachedWidth; + return mTextCache.GetTextWidth(); } -eeFloat cFont::GetTextWidth() const { - return mCachedWidth; +eeFloat cFont::GetTextWidth() { + return mTextCache.GetTextWidth(); } Uint32 cFont::GetFontSize() const { @@ -111,31 +81,25 @@ Int32 cFont::GetFontDescent() const { } String cFont::GetText() { - return mText; -} - -void cFont::CacheData( bool Cache ) { - mCacheData = Cache; -} - -const bool& cFont::CacheData() const { - return mCacheData; + return mTextCache.Text(); } eeFloat cFont::GetTextHeight() { return (eeFloat)GetFontHeight() * (eeFloat)GetNumLines(); } -const std::vector& cFont::GetLinesWidth() const { - return mLinesWidth; +const std::vector& cFont::GetLinesWidth() { + return mTextCache.LinesWidth(); } void cFont::Draw( const eeFloat& X, const eeFloat& Y, const Uint32& Flags, const eeFloat& Scale, const eeFloat& Angle, const EE_BLEND_MODE& Effect) { - SubDraw( mText, X, Y, Flags, Scale, Angle, true, Effect ); + Draw( mTextCache, X, Y, Flags, Scale, Angle, Effect ); } void cFont::Draw( const String& Text, const eeFloat& X, const eeFloat& Y, const Uint32& Flags, const eeFloat& Scale, const eeFloat& Angle, const EE_BLEND_MODE& Effect ) { - SubDraw( Text, X, Y, Flags, Scale, Angle, false, Effect ); + mTextCache.Text( Text ); + mTextCache.Flags( Flags ); + mTextCache.Draw( X, Y, Scale, Angle, Effect ); } void cFont::Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, const Uint32& Flags, const eeFloat& Scale, const eeFloat& Angle, const EE_BLEND_MODE& Effect ) { @@ -167,6 +131,8 @@ void cFont::Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, con Draw( X + 1, Y + 1, f, Scale, Angle, Effect ); + mTextCache.Flags( Flags ); + Color( Col ); } @@ -192,15 +158,17 @@ void cFont::Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, con std::vector& Colors = TextCache.Colors(); if ( !TextCache.CachedCoords() ) { - switch ( FontHAlignGet( Flags ) ) { - case FONT_DRAW_CENTER: - nX = (eeFloat)( (Int32)( ( TextCache.GetTextWidth() - TextCache.LinesWidth()[ Line ] ) * 0.5f ) ); - Line++; - break; - case FONT_DRAW_RIGHT: - nX = TextCache.GetTextWidth() - TextCache.LinesWidth()[ Line ]; - Line++; - break; + if ( !( Flags & FONT_DRAW_VERTICAL ) ) { + switch ( FontHAlignGet( Flags ) ) { + case FONT_DRAW_CENTER: + nX = (eeFloat)( (Int32)( ( TextCache.GetTextWidth() - TextCache.LinesWidth()[ Line ] ) * 0.5f ) ); + Line++; + break; + case FONT_DRAW_RIGHT: + nX = TextCache.GetTextWidth() - TextCache.LinesWidth()[ Line ]; + Line++; + break; + } } Int32 tGlyphSize = (Int32)mGlyphs.size(); @@ -217,7 +185,7 @@ void cFont::Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, con switch( Char ) { case '\v': { - if (mVerticalDraw) + if ( Flags & FONT_DRAW_VERTICAL ) nY += GetFontHeight(); else nX += mGlyphs[ Char ].Advance; @@ -225,7 +193,7 @@ void cFont::Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, con } case '\t': { - if (mVerticalDraw) + if ( Flags & FONT_DRAW_VERTICAL ) nY += GetFontHeight() * 4; else nX += mGlyphs[ Char ].Advance * 4; @@ -233,7 +201,7 @@ void cFont::Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, con } case '\n': { - if (mVerticalDraw) { + if ( Flags & FONT_DRAW_VERTICAL ) { nX += (GetFontHeight() * Scale); nY = 0; } else { @@ -304,7 +272,7 @@ void cFont::Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, con numvert++; #endif - if (mVerticalDraw) + if ( Flags & FONT_DRAW_VERTICAL ) nY += GetFontHeight(); else nX += mGlyphs[ Char ].Advance; @@ -319,9 +287,9 @@ void cFont::Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, con numvert = TextCache.CachedVerts(); } - GLi->ColorPointer ( 4, GL_UNSIGNED_BYTE , 0 , reinterpret_cast( &Colors[0] ) ); - GLi->TexCoordPointer( 2, GL_FP , sizeof(eeVertexCoords), reinterpret_cast( &RenderCoords[0] ) ); - GLi->VertexPointer ( 2, GL_FP , sizeof(eeVertexCoords), reinterpret_cast( &RenderCoords[0] ) + sizeof(eeFloat) * 2 ); + GLi->ColorPointer ( 4, GL_UNSIGNED_BYTE , 0 , reinterpret_cast( &Colors[0] ) ); + GLi->TexCoordPointer( 2, GL_FP , sizeof(eeVertexCoords), reinterpret_cast( &RenderCoords[0] ) ); + GLi->VertexPointer ( 2, GL_FP , sizeof(eeVertexCoords), reinterpret_cast( &RenderCoords[0] ) + sizeof(eeFloat) * 2 ); #ifndef EE_GLES GLi->DrawArrays( GL_QUADS, 0, numvert ); @@ -334,207 +302,42 @@ void cFont::Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, con } } -void cFont::SubDraw( const String& Text, const eeFloat& X, const eeFloat& Y, const Uint32& Flags, const eeFloat& Scale, const eeFloat& Angle, const bool& Cached, const EE_BLEND_MODE& Effect ) { - if ( !Text.size() ) - return; - - cGlobalBatchRenderer::instance()->Draw(); - cTextureFactory::instance()->Bind( mTexId ); - BlendMode::SetMode( Effect ); - - if ( !Cached && ( Text.size() != mRenderCoords.size() / EE_QUAD_VERTEX || Angle != 0.f || Scale != 1.f || FontHAlignGet( Flags ) == FONT_DRAW_CENTER || FontHAlignGet( Flags ) == FONT_DRAW_RIGHT ) ) { - SetText( Text ); - } - - if ( Flags & FONT_DRAW_SHADOW ) { - Uint32 f = Flags; - f &= ~FONT_DRAW_SHADOW; - - eeColorA Col = mColor; - - if ( Col.A() != 255 ) { - eeColorA ShadowColor = mShadowColor; - - ShadowColor.Alpha = (Uint8)( (eeFloat)ShadowColor.Alpha * ( (eeFloat)Col.A() / (eeFloat)255 ) ); - - Color( ShadowColor ); - } else { - Color( mShadowColor ); - } - - SubDraw( Text, X + 1, Y + 1, f, Scale, Angle, true, Effect ); - - Color( Col ); - } - - eeFloat cX = (eeFloat) ( (Int32)X ); - eeFloat cY = (eeFloat) ( (Int32)Y ); - eeFloat nX = 0; - eeFloat nY = 0; - Int16 Char = 0; - eeUint Line = 0; - eeUint numvert = 0; - - if ( Angle != 0.0f || Scale != 1.0f ) { - GLi->PushMatrix(); - - eeVector2f Center( cX + GetTextWidth() * 0.5f, cY + GetTextHeight() * 0.5f ); - GLi->Translatef( Center.x , Center.y, 0.f ); - GLi->Rotatef( Angle, 0.0f, 0.0f, 1.0f ); - GLi->Scalef( Scale, Scale, 1.0f ); - GLi->Translatef( -Center.x, -Center.y, 0.f ); - } - - switch ( FontHAlignGet( Flags ) ) { - case FONT_DRAW_CENTER: - nX = (eeFloat)( (Int32)( ( mCachedWidth - mLinesWidth[ Line ] ) * 0.5f ) ); - Line++; - break; - case FONT_DRAW_RIGHT: - nX = mCachedWidth - mLinesWidth[ Line ]; - Line++; - break; - } - - Int32 tGlyphSize = (Int32)mGlyphs.size(); - - for ( eeUint i = 0; i < Text.size(); i++ ) { - Char = static_cast( Text.at(i) ); - - if ( Char < 0 && Char > -128 ) - Char = 256 + Char; - - if ( Char >= 0 && Char < tGlyphSize ) { - eeTexCoords * C = &mTexCoords[ Char ]; - - switch( Char ) { - case '\v': - if (mVerticalDraw) - nY += GetFontHeight(); - else - nX += mGlyphs[ Char ].Advance; - break; - case '\t': - if (mVerticalDraw) - nY += GetFontHeight() * 4; - else - nX += mGlyphs[ Char ].Advance * 4; - break; - case '\n': - if (mVerticalDraw) { - nX += (GetFontHeight() * Scale); - nY = 0; - } else { - if ( i + 1 < Text.size() ) { - switch ( FontHAlignGet( Flags ) ) { - case FONT_DRAW_CENTER: - nX = (eeFloat)( (Int32)( ( mCachedWidth - mLinesWidth[ Line ] ) * 0.5f ) ); - break; - case FONT_DRAW_RIGHT: - nX = mCachedWidth - mLinesWidth[ Line ]; - break; - default: - nX = 0; - } - } - - nY += (GetFontHeight() * Scale); - Line++; - } - - break; - default: - #ifndef EE_GLES - for ( Uint8 z = 0; z < 8; z+=2 ) { - mRenderCoords[ numvert ].TexCoords[0] = C->TexCoords[z]; - mRenderCoords[ numvert ].TexCoords[1] = C->TexCoords[ z + 1 ]; - mRenderCoords[ numvert ].Vertex[0] = cX + C->Vertex[z] + nX; - mRenderCoords[ numvert ].Vertex[1] = cY + C->Vertex[ z + 1 ] + nY; - numvert++; - } - #else - mRenderCoords[ numvert ].TexCoords[0] = C->TexCoords[2]; - mRenderCoords[ numvert ].TexCoords[1] = C->TexCoords[ 2 + 1 ]; - mRenderCoords[ numvert ].Vertex[0] = cX + C->Vertex[2] + nX; - mRenderCoords[ numvert ].Vertex[1] = cY + C->Vertex[ 2 + 1 ] + nY; - numvert++; - - mRenderCoords[ numvert ].TexCoords[0] = C->TexCoords[0]; - mRenderCoords[ numvert ].TexCoords[1] = C->TexCoords[ 0 + 1 ]; - mRenderCoords[ numvert ].Vertex[0] = cX + C->Vertex[0] + nX; - mRenderCoords[ numvert ].Vertex[1] = cY + C->Vertex[ 0 + 1 ] + nY; - numvert++; - - mRenderCoords[ numvert ].TexCoords[0] = C->TexCoords[6]; - mRenderCoords[ numvert ].TexCoords[1] = C->TexCoords[ 6 + 1 ]; - mRenderCoords[ numvert ].Vertex[0] = cX + C->Vertex[6] + nX; - mRenderCoords[ numvert ].Vertex[1] = cY + C->Vertex[ 6 + 1 ] + nY; - numvert++; - - mRenderCoords[ numvert ].TexCoords[0] = C->TexCoords[2]; - mRenderCoords[ numvert ].TexCoords[1] = C->TexCoords[ 2 + 1 ]; - mRenderCoords[ numvert ].Vertex[0] = cX + C->Vertex[2] + nX; - mRenderCoords[ numvert ].Vertex[1] = cY + C->Vertex[ 2 + 1 ] + nY; - numvert++; - - mRenderCoords[ numvert ].TexCoords[0] = C->TexCoords[4]; - mRenderCoords[ numvert ].TexCoords[1] = C->TexCoords[ 4 + 1 ]; - mRenderCoords[ numvert ].Vertex[0] = cX + C->Vertex[4] + nX; - mRenderCoords[ numvert ].Vertex[1] = cY + C->Vertex[ 4 + 1 ] + nY; - numvert++; - - mRenderCoords[ numvert ].TexCoords[0] = C->TexCoords[6]; - mRenderCoords[ numvert ].TexCoords[1] = C->TexCoords[ 6 + 1 ]; - mRenderCoords[ numvert ].Vertex[0] = cX + C->Vertex[6] + nX; - mRenderCoords[ numvert ].Vertex[1] = cY + C->Vertex[ 6 + 1 ] + nY; - numvert++; - #endif - - if ( mVerticalDraw ) - nY += GetFontHeight(); - else - nX += mGlyphs[ Char ].Advance; - } - } - } - - GLi->ColorPointer ( 4, GL_UNSIGNED_BYTE , 0 , reinterpret_cast( &mColors[0] ) ); - GLi->TexCoordPointer ( 2, GL_FP , sizeof(eeVertexCoords), reinterpret_cast( &mRenderCoords[0] ) ); - GLi->VertexPointer ( 2, GL_FP , sizeof(eeVertexCoords), reinterpret_cast( &mRenderCoords[0] ) + sizeof(eeFloat) * 2 ); - - #ifndef EE_GLES - GLi->DrawArrays( GL_QUADS, 0, numvert ); - #else - GLi->DrawArrays( GL_TRIANGLES, 0, numvert ); - #endif - - if ( Angle != 0.0f || Scale != 1.0f ) - GLi->PopMatrix(); -} - -void cFont::CacheWidth( const String& Text, std::vector& LinesWidth, eeFloat& CachedWidth, eeInt& NumLines ) { +void cFont::CacheWidth( const String& Text, std::vector& LinesWidth, eeFloat& CachedWidth, eeInt& NumLines , eeInt& LargestLineCharCount ) { LinesWidth.clear(); eeFloat Width = 0, MaxWidth = 0; Int32 CharID; Int32 Lines = 1; + Int32 CharCount = 0; Int32 tGlyphSize = (Int32)mGlyphs.size(); + LargestLineCharCount = 0; + for (std::size_t i = 0; i < Text.size(); ++i) { CharID = static_cast( Text.at(i) ); if ( CharID >= 0 && CharID < tGlyphSize ) { Width += mGlyphs[CharID].Advance; + CharCount++; + if ( CharID == '\t' ) Width += mGlyphs[CharID].Advance * 3; if ( CharID == '\n' ) { Lines++; + eeFloat lWidth = ( CharID == '\t' ) ? mGlyphs[CharID].Advance * 4.f : mGlyphs[CharID].Advance; + LinesWidth.push_back( Width - lWidth ); + Width = 0; + + CharCount = 0; + } else { + if ( CharCount > LargestLineCharCount ) + LargestLineCharCount = CharCount; } if ( Width > MaxWidth ) @@ -551,7 +354,7 @@ void cFont::CacheWidth( const String& Text, std::vector& LinesWidth, ee } void cFont::CacheWidth() { - CacheWidth( mText, mLinesWidth, mCachedWidth, mNumLines ); + mTextCache.Cache(); } void cFont::ShrinkText( std::string& Str, const Uint32& MaxWidth ) { diff --git a/src/eepp/graphics/ctextcache.cpp b/src/eepp/graphics/ctextcache.cpp index f6122952a..5f533c866 100644 --- a/src/eepp/graphics/ctextcache.cpp +++ b/src/eepp/graphics/ctextcache.cpp @@ -9,9 +9,11 @@ cTextCache::cTextCache() : mFont(NULL), mCachedWidth(0.f), mNumLines(1), + mLargestLineCharCount(0), mFontColor(255,255,255,255), mFontShadowColor(0,0,0,255), mFlags(0), + mVertexNumCached(0), mCachedCoords(false) { } @@ -20,7 +22,11 @@ cTextCache::cTextCache( cFont * font, const String& text, eeColorA FontColor, ee mText( text ), mFont( font ), mCachedWidth(0.f), - mNumLines(1) + mNumLines(1), + mLargestLineCharCount(0), + mFlags(0), + mVertexNumCached(0), + mCachedCoords(false) { Cache(); UpdateCoords(); @@ -116,7 +122,7 @@ std::vector& cTextCache::Colors() { void cTextCache::Cache() { if ( NULL != mFont && mText.size() ) { - mFont->CacheWidth( mText, mLinesWidth, mCachedWidth, mNumLines ); + mFont->CacheWidth( mText, mLinesWidth, mCachedWidth, mNumLines, mLargestLineCharCount ); }else { mCachedWidth = 0; } @@ -125,11 +131,11 @@ void cTextCache::Cache() { } eeFloat cTextCache::GetTextWidth() { - return mCachedWidth; + return ( mFlags & FONT_DRAW_VERTICAL ) ? (eeFloat)mFont->GetFontHeight() * (eeFloat)mNumLines : mCachedWidth; } eeFloat cTextCache::GetTextHeight() { - return (eeFloat)mFont->GetFontHeight() * (eeFloat)mNumLines; + return ( mFlags & FONT_DRAW_VERTICAL ) ? mLargestLineCharCount * (eeFloat)mFont->GetFontHeight() : (eeFloat)mFont->GetFontHeight() * (eeFloat)mNumLines; } const eeInt& cTextCache::GetNumLines() const { @@ -140,21 +146,16 @@ const std::vector& cTextCache::LinesWidth() { return mLinesWidth; } -void cTextCache::Draw( const eeFloat& X, const eeFloat& Y, const Uint32& Flags, const eeFloat& Scale, const eeFloat& Angle, EE_BLEND_MODE Effect ) { +void cTextCache::Draw( const eeFloat& X, const eeFloat& Y, const eeFloat& Scale, const eeFloat& Angle, EE_BLEND_MODE Effect ) { if ( NULL != mFont ) { - if ( mFlags != Flags ) { - mFlags = Flags; - mCachedCoords = false; - } - cGlobalBatchRenderer::instance()->Draw(); if ( Angle != 0.0f || Scale != 1.0f ) { - mFont->Draw( *this, X, Y, Flags, Scale, Angle, Effect ); + mFont->Draw( *this, X, Y, mFlags, Scale, Angle, Effect ); } else { GLi->Translatef( X, Y, 0.f ); - mFont->Draw( *this, 0, 0, Flags, Scale, Angle, Effect ); + mFont->Draw( *this, 0, 0, mFlags, Scale, Angle, Effect ); GLi->Translatef( -X, -Y, 0.f ); } @@ -177,4 +178,19 @@ void cTextCache::CachedVerts( const eeUint& num ) { mVertexNumCached = num; } +void cTextCache::Flags( const Uint32& flags ) { + if ( mFlags != flags ) { + mFlags = flags; + mCachedCoords = false; + + if ( ( mFlags & FONT_DRAW_VERTICAL ) != ( flags & FONT_DRAW_VERTICAL ) ) { + Cache(); + } + } +} + +const Uint32& cTextCache::Flags() const { + return mFlags; +} + }} diff --git a/src/eepp/graphics/ctexturefont.cpp b/src/eepp/graphics/ctexturefont.cpp index 99587b953..a368f043d 100755 --- a/src/eepp/graphics/ctexturefont.cpp +++ b/src/eepp/graphics/ctexturefont.cpp @@ -20,7 +20,7 @@ cTextureFont::cTextureFont( const std::string FontName ) : cTextureFont::~cTextureFont() { } -bool cTextureFont::Load( const Uint32& TexId, const eeUint& StartChar, const eeUint& Spacing, const bool& VerticalDraw, const eeUint& TexColumns, const eeUint& TexRows, const Uint16& NumChars ) { +bool cTextureFont::Load( const Uint32& TexId, const eeUint& StartChar, const eeUint& Spacing, const eeUint& TexColumns, const eeUint& TexRows, const Uint16& NumChars ) { cTexture * Tex = cTextureFactory::instance()->GetTexture( TexId ); mTexId = TexId; @@ -38,8 +38,6 @@ bool cTextureFont::Load( const Uint32& TexId, const eeUint& StartChar, const eeU mFHeight = (eeFloat)( Tex->Height() / mTexRows ); mHeight = mSize = mLineSkip = (eeUint)mFHeight; - mVerticalDraw = VerticalDraw; - if ( Spacing == 0 ) mSpacing = static_cast( mFWidth ); else @@ -144,48 +142,46 @@ void cTextureFont::BuildFromGlyphs() { } } -bool cTextureFont::Load( const Uint32& TexId, const std::string& CoordinatesDatPath, const bool& VerticalDraw ) { +bool cTextureFont::Load( const Uint32& TexId, const std::string& CoordinatesDatPath ) { if ( FileSystem::FileExists( CoordinatesDatPath ) ) { cIOStreamFile IOS( CoordinatesDatPath, std::ios::in | std::ios::binary ); - return LoadFromStream( TexId, IOS, VerticalDraw ); + return LoadFromStream( TexId, IOS ); } else if ( cPackManager::instance()->FallbackToPacks() ) { std::string tPath( CoordinatesDatPath ); cPack * tPack = cPackManager::instance()->Exists( tPath ); if ( NULL != tPack ) { - return LoadFromPack( TexId, tPack, tPath, VerticalDraw ); + return LoadFromPack( TexId, tPack, tPath ); } } return false; } -bool cTextureFont::LoadFromPack( const Uint32& TexId, cPack* Pack, const std::string& FilePackPath, const bool& VerticalDraw ) { +bool cTextureFont::LoadFromPack( const Uint32& TexId, cPack* Pack, const std::string& FilePackPath ) { if ( NULL != Pack && Pack->IsOpen() && -1 != Pack->Exists( FilePackPath ) ) { SafeDataPointer PData; Pack->ExtractFileToMemory( FilePackPath, PData ); - return LoadFromMemory( TexId, reinterpret_cast ( PData.Data ), PData.DataSize, VerticalDraw ); + return LoadFromMemory( TexId, reinterpret_cast ( PData.Data ), PData.DataSize ); } return false; } -bool cTextureFont::LoadFromMemory( const Uint32& TexId, const char* CoordData, const Uint32& CoordDataSize, const bool& VerticalDraw ) { +bool cTextureFont::LoadFromMemory( const Uint32& TexId, const char* CoordData, const Uint32& CoordDataSize ) { cIOStreamMemory IOS( CoordData, CoordDataSize ); - return LoadFromStream( TexId, IOS, VerticalDraw ); + return LoadFromStream( TexId, IOS ); } -bool cTextureFont::LoadFromStream( const Uint32& TexId, cIOStream& IOS, const bool& VerticalDraw ) { +bool cTextureFont::LoadFromStream( const Uint32& TexId, cIOStream& IOS ) { mTexId = TexId; if ( mTexId > 0 ) { - mVerticalDraw = VerticalDraw; - if ( IOS.IsOpen() ) { sFntHdr FntHdr; diff --git a/src/eepp/graphics/ctexturefontloader.cpp b/src/eepp/graphics/ctexturefontloader.cpp index 0fbd48b9c..22839d292 100644 --- a/src/eepp/graphics/ctexturefontloader.cpp +++ b/src/eepp/graphics/ctexturefontloader.cpp @@ -3,13 +3,12 @@ namespace EE { namespace Graphics { -cTextureFontLoader::cTextureFontLoader( const std::string FontName, cTextureLoader * TexLoader, const eeUint& StartChar, const eeUint& Spacing, const bool& VerticalDraw, const eeUint& TexColumns, const eeUint& TexRows, const Uint16& NumChars ) : +cTextureFontLoader::cTextureFontLoader( const std::string FontName, cTextureLoader * TexLoader, const eeUint& StartChar, const eeUint& Spacing, const eeUint& TexColumns, const eeUint& TexRows, const Uint16& NumChars ) : cObjectLoader( FontTexLoader ), mLoadType( TEF_LT_TEX ), mFontName( FontName ), mStartChar( StartChar ), mSpacing( Spacing ), - mVerticalDraw( VerticalDraw ), mTexColumns( TexColumns ), mTexRows( TexRows ), mNumChars( NumChars ), @@ -19,24 +18,22 @@ cTextureFontLoader::cTextureFontLoader( const std::string FontName, cTextureLoad mTexLoader = TexLoader; } -cTextureFontLoader::cTextureFontLoader( const std::string FontName, cTextureLoader * TexLoader, const std::string& CoordinatesDatPath, const bool& VerticalDraw ) : +cTextureFontLoader::cTextureFontLoader( const std::string FontName, cTextureLoader * TexLoader, const std::string& CoordinatesDatPath ) : cObjectLoader( FontTexLoader ), mLoadType( TEF_LT_PATH ), mFontName( FontName ), mFilepath( CoordinatesDatPath ), - mVerticalDraw( VerticalDraw ), mTexLoaded( false ), mFontLoaded( false ) { mTexLoader = TexLoader; } -cTextureFontLoader::cTextureFontLoader( const std::string FontName, cTextureLoader * TexLoader, cPack * Pack, const std::string& FilePackPath, const bool& VerticalDraw ) : +cTextureFontLoader::cTextureFontLoader( const std::string FontName, cTextureLoader * TexLoader, cPack * Pack, const std::string& FilePackPath ) : cObjectLoader( FontTexLoader ), mLoadType( TEF_LT_PACK ), mFontName( FontName ), mFilepath( FilePackPath ), - mVerticalDraw( VerticalDraw ), mPack( Pack ), mTexLoaded( false ), mFontLoaded( false ) @@ -44,11 +41,10 @@ cTextureFontLoader::cTextureFontLoader( const std::string FontName, cTextureLoad mTexLoader = TexLoader; } -cTextureFontLoader::cTextureFontLoader( const std::string FontName, cTextureLoader * TexLoader, const char* CoordData, const Uint32& CoordDataSize, const bool& VerticalDraw ) : +cTextureFontLoader::cTextureFontLoader( const std::string FontName, cTextureLoader * TexLoader, const char* CoordData, const Uint32& CoordDataSize ) : cObjectLoader( FontTexLoader ), mLoadType( TEF_LT_MEM ), mFontName( FontName ), - mVerticalDraw( VerticalDraw ), mData( CoordData ), mDataSize( CoordDataSize ), mTexLoaded( false ), @@ -96,19 +92,19 @@ const std::string& cTextureFontLoader::Id() const { } void cTextureFontLoader::LoadFromPath() { - mFont->Load( mTexLoader->Id(), mFilepath, mVerticalDraw ); + mFont->Load( mTexLoader->Id(), mFilepath ); } void cTextureFontLoader::LoadFromMemory() { - mFont->LoadFromMemory( mTexLoader->Id(), mData, mDataSize, mVerticalDraw ); + mFont->LoadFromMemory( mTexLoader->Id(), mData, mDataSize ); } void cTextureFontLoader::LoadFromPack() { - mFont->LoadFromPack( mTexLoader->Id(), mPack, mFilepath, mVerticalDraw ); + mFont->LoadFromPack( mTexLoader->Id(), mPack, mFilepath ); } void cTextureFontLoader::LoadFromTex() { - mFont->Load( mTexLoader->Id(), mStartChar, mSpacing, mVerticalDraw, mTexColumns, mTexRows, mNumChars ); + mFont->Load( mTexLoader->Id(), mStartChar, mSpacing, mTexColumns, mTexRows, mNumChars ); } void cTextureFontLoader::LoadFont() { diff --git a/src/eepp/graphics/cttffont.cpp b/src/eepp/graphics/cttffont.cpp index 6487e6266..a22f8e189 100755 --- a/src/eepp/graphics/cttffont.cpp +++ b/src/eepp/graphics/cttffont.cpp @@ -23,20 +23,20 @@ cTTFFont::~cTTFFont() { hkFontManager::instance()->Destroy(); } -bool cTTFFont::LoadFromPack( cPack* Pack, const std::string& FilePackPath, const eeUint& Size, EE_TTF_FONT_STYLE Style, const bool& VerticalDraw, const Uint16& NumCharsToGen, const eeColor& FontColor, const Uint8& OutlineSize, const eeColor& OutlineColor, const bool& AddPixelSeparator ) { +bool cTTFFont::LoadFromPack( cPack* Pack, const std::string& FilePackPath, const eeUint& Size, EE_TTF_FONT_STYLE Style, const Uint16& NumCharsToGen, const eeColor& FontColor, const Uint8& OutlineSize, const eeColor& OutlineColor, const bool& AddPixelSeparator ) { bool Ret = false; SafeDataPointer PData; if ( Pack->IsOpen() && Pack->ExtractFileToMemory( FilePackPath, PData ) ) { mFilepath = FilePackPath; - Ret = LoadFromMemory( PData.Data, PData.DataSize, Size, Style, VerticalDraw, NumCharsToGen, FontColor, OutlineSize, OutlineColor, AddPixelSeparator ); + Ret = LoadFromMemory( PData.Data, PData.DataSize, Size, Style, NumCharsToGen, FontColor, OutlineSize, OutlineColor, AddPixelSeparator ); } return Ret; } -bool cTTFFont::LoadFromMemory( Uint8* TTFData, const eeUint& TTFDataSize, const eeUint& Size, EE_TTF_FONT_STYLE Style, const bool& VerticalDraw, const Uint16& NumCharsToGen, const eeColor& FontColor, const Uint8& OutlineSize, const eeColor& OutlineColor, const bool& AddPixelSeparator ) { +bool cTTFFont::LoadFromMemory( Uint8* TTFData, const eeUint& TTFDataSize, const eeUint& Size, EE_TTF_FONT_STYLE Style, const Uint16& NumCharsToGen, const eeColor& FontColor, const Uint8& OutlineSize, const eeColor& OutlineColor, const bool& AddPixelSeparator ) { if ( !mFilepath.size() ) mFilepath = "from memory"; @@ -44,10 +44,10 @@ bool cTTFFont::LoadFromMemory( Uint8* TTFData, const eeUint& TTFDataSize, const mFont = hkFontManager::instance()->OpenFromMemory( reinterpret_cast(&TTFData[0]), TTFDataSize, Size, 0, NumCharsToGen ); - return iLoad( Size, Style, VerticalDraw, NumCharsToGen, FontColor, OutlineSize, OutlineColor, AddPixelSeparator ); + return iLoad( Size, Style, NumCharsToGen, FontColor, OutlineSize, OutlineColor, AddPixelSeparator ); } -bool cTTFFont::Load( const std::string& Filepath, const eeUint& Size, EE_TTF_FONT_STYLE Style, const bool& VerticalDraw, const Uint16& NumCharsToGen, const eeColor& FontColor, const Uint8& OutlineSize, const eeColor& OutlineColor, const bool& AddPixelSeparator ) { +bool cTTFFont::Load( const std::string& Filepath, const eeUint& Size, EE_TTF_FONT_STYLE Style, const Uint16& NumCharsToGen, const eeColor& FontColor, const Uint8& OutlineSize, const eeColor& OutlineColor, const bool& AddPixelSeparator ) { mFilepath = Filepath; if ( FileSystem::FileExists( Filepath ) ) { @@ -55,19 +55,19 @@ bool cTTFFont::Load( const std::string& Filepath, const eeUint& Size, EE_TTF_FON mFont = hkFontManager::instance()->OpenFromFile( Filepath.c_str(), Size, 0, NumCharsToGen ); - return iLoad( Size, Style, VerticalDraw, NumCharsToGen, FontColor, OutlineSize, OutlineColor, AddPixelSeparator ); + return iLoad( Size, Style, NumCharsToGen, FontColor, OutlineSize, OutlineColor, AddPixelSeparator ); } else if ( cPackManager::instance()->FallbackToPacks() ) { cPack * tPack = cPackManager::instance()->Exists( mFilepath ); if ( NULL != tPack ) { - return LoadFromPack( tPack, mFilepath, Size, Style, VerticalDraw, NumCharsToGen, FontColor, OutlineSize, OutlineColor, AddPixelSeparator ); + return LoadFromPack( tPack, mFilepath, Size, Style, NumCharsToGen, FontColor, OutlineSize, OutlineColor, AddPixelSeparator ); } } return false; } -bool cTTFFont::iLoad( const eeUint& Size, EE_TTF_FONT_STYLE Style, const bool& VerticalDraw, const Uint16& NumCharsToGen, const eeColor& FontColor, Uint8 OutlineSize, const eeColor& OutlineColor, const bool& AddPixelSeparator ) { +bool cTTFFont::iLoad( const eeUint& Size, EE_TTF_FONT_STYLE Style, const Uint16& NumCharsToGen, const eeColor& FontColor, Uint8 OutlineSize, const eeColor& OutlineColor, const bool& AddPixelSeparator ) { eeRect CurrentPos; eeSize GlyphRect; @@ -90,7 +90,6 @@ bool cTTFFont::iLoad( const eeUint& Size, EE_TTF_FONT_STYLE Style, const bool& V mFont->Style( Style ); - mVerticalDraw = VerticalDraw; mSize = Size; mHeight = mFont->Height() + OutlineTotal; mLineSkip = mFont->LineSkip(); diff --git a/src/eepp/graphics/cttffontloader.cpp b/src/eepp/graphics/cttffontloader.cpp index 9ff6d829c..92cb3eab7 100644 --- a/src/eepp/graphics/cttffontloader.cpp +++ b/src/eepp/graphics/cttffontloader.cpp @@ -4,14 +4,13 @@ namespace EE { namespace Graphics { -cTTFFontLoader::cTTFFontLoader( const std::string& FontName, const std::string& Filepath, const eeUint& Size, EE_TTF_FONT_STYLE Style, const bool& VerticalDraw, const Uint16& NumCharsToGen, const eeColor& FontColor, const Uint8& OutlineSize, const eeColor& OutlineColor, const bool& AddPixelSeparator ) : +cTTFFontLoader::cTTFFontLoader( const std::string& FontName, const std::string& Filepath, const eeUint& Size, EE_TTF_FONT_STYLE Style, const Uint16& NumCharsToGen, const eeColor& FontColor, const Uint8& OutlineSize, const eeColor& OutlineColor, const bool& AddPixelSeparator ) : cObjectLoader( FontTTFLoader ), mLoadType( TTF_LT_PATH ), mFontName( FontName ), mFilepath( Filepath ), mSize( Size ), mStyle( Style ), - mVerticalDraw( VerticalDraw ), mNumCharsToGen( NumCharsToGen ), mFontColor( FontColor ), mOutlineSize( OutlineSize ), @@ -22,14 +21,13 @@ cTTFFontLoader::cTTFFontLoader( const std::string& FontName, const std::string& Create(); } -cTTFFontLoader::cTTFFontLoader( const std::string& FontName, cPack * Pack, const std::string& FilePackPath, const eeUint& Size, EE_TTF_FONT_STYLE Style, const bool& VerticalDraw, const Uint16& NumCharsToGen, const eeColor& FontColor, const Uint8& OutlineSize, const eeColor& OutlineColor, const bool& AddPixelSeparator ) : +cTTFFontLoader::cTTFFontLoader( const std::string& FontName, cPack * Pack, const std::string& FilePackPath, const eeUint& Size, EE_TTF_FONT_STYLE Style, const Uint16& NumCharsToGen, const eeColor& FontColor, const Uint8& OutlineSize, const eeColor& OutlineColor, const bool& AddPixelSeparator ) : cObjectLoader( FontTTFLoader ), mLoadType( TTF_LT_PACK ), mFontName( FontName ), mFilepath( FilePackPath ), mSize( Size ), mStyle( Style ), - mVerticalDraw( VerticalDraw ), mNumCharsToGen( NumCharsToGen ), mFontColor( FontColor ), mOutlineSize( OutlineSize ), @@ -41,13 +39,12 @@ cTTFFontLoader::cTTFFontLoader( const std::string& FontName, cPack * Pack, const Create(); } -cTTFFontLoader::cTTFFontLoader( const std::string& FontName, Uint8* TTFData, const eeUint& TTFDataSize, const eeUint& Size, EE_TTF_FONT_STYLE Style, const bool& VerticalDraw, const Uint16& NumCharsToGen, const eeColor& FontColor, const Uint8& OutlineSize, const eeColor& OutlineColor, const bool& AddPixelSeparator ) : +cTTFFontLoader::cTTFFontLoader( const std::string& FontName, Uint8* TTFData, const eeUint& TTFDataSize, const eeUint& Size, EE_TTF_FONT_STYLE Style, const Uint16& NumCharsToGen, const eeColor& FontColor, const Uint8& OutlineSize, const eeColor& OutlineColor, const bool& AddPixelSeparator ) : cObjectLoader( FontTTFLoader ), mLoadType( TTF_LT_MEM ), mFontName( FontName ), mSize( Size ), mStyle( Style ), - mVerticalDraw( VerticalDraw ), mNumCharsToGen( NumCharsToGen ), mFontColor( FontColor ), mOutlineSize( OutlineSize ), @@ -98,15 +95,15 @@ const std::string& cTTFFontLoader::Id() const { } void cTTFFontLoader::LoadFromPath() { - mFont->Load( mFilepath, mSize, mStyle, mVerticalDraw, mNumCharsToGen, mFontColor, mOutlineSize, mOutlineColor, mAddPixelSeparator ); + mFont->Load( mFilepath, mSize, mStyle, mNumCharsToGen, mFontColor, mOutlineSize, mOutlineColor, mAddPixelSeparator ); } void cTTFFontLoader::LoadFromMemory() { - mFont->LoadFromMemory( mData, mDataSize, mSize, mStyle, mVerticalDraw, mNumCharsToGen, mFontColor, mOutlineSize, mOutlineColor, mAddPixelSeparator ); + mFont->LoadFromMemory( mData, mDataSize, mSize, mStyle, mNumCharsToGen, mFontColor, mOutlineSize, mOutlineColor, mAddPixelSeparator ); } void cTTFFontLoader::LoadFromPack() { - mFont->LoadFromPack( mPack, mFilepath, mSize, mStyle, mVerticalDraw, mNumCharsToGen, mFontColor, mOutlineSize, mOutlineColor, mAddPixelSeparator ); + mFont->LoadFromPack( mPack, mFilepath, mSize, mStyle, mNumCharsToGen, mFontColor, mOutlineSize, mOutlineColor, mAddPixelSeparator ); } cFont * cTTFFontLoader::Font() const { diff --git a/src/eepp/ui/cuitextbox.cpp b/src/eepp/ui/cuitextbox.cpp index bd94f4e68..0ac622bf0 100644 --- a/src/eepp/ui/cuitextbox.cpp +++ b/src/eepp/ui/cuitextbox.cpp @@ -51,7 +51,8 @@ void cUITextBox::Draw() { ); } - mTextCache->Draw( (eeFloat)mScreenPos.x + mAlignOffset.x + (eeFloat)mPadding.Left, (eeFloat)mScreenPos.y + mAlignOffset.y + (eeFloat)mPadding.Top, Flags(), 1.f, 0.f, Blend() ); + mTextCache->Flags( Flags() ); + mTextCache->Draw( (eeFloat)mScreenPos.x + mAlignOffset.x + (eeFloat)mPadding.Left, (eeFloat)mScreenPos.y + mAlignOffset.y + (eeFloat)mPadding.Top, 1.f, 0.f, Blend() ); if ( mFlags & UI_CLIP_ENABLE ) { cUIManager::instance()->ClipDisable(); diff --git a/src/eepp/ui/cuitooltip.cpp b/src/eepp/ui/cuitooltip.cpp index 1d4a67f76..fd25112e9 100644 --- a/src/eepp/ui/cuitooltip.cpp +++ b/src/eepp/ui/cuitooltip.cpp @@ -95,7 +95,8 @@ void cUITooltip::Draw() { cUIControlAnim::Draw(); if ( mTextCache->GetTextWidth() ) { - mTextCache->Draw( (eeFloat)mScreenPos.x + mAlignOffset.x, (eeFloat)mScreenPos.y + mAlignOffset.y, Flags(), 1.f, 0.f, Blend() ); + mTextCache->Flags( Flags() ); + mTextCache->Draw( (eeFloat)mScreenPos.x + mAlignOffset.x, (eeFloat)mScreenPos.y + mAlignOffset.y, 1.f, 0.f, Blend() ); } } } diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index adf8cd871..27da4f315 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -160,8 +160,8 @@ void cEETest::LoadFonts() { mFontLoader.Add( eeNew( cTextureFontLoader, ( "conchars", tl, (eeUint)32 ) ) ); mFontLoader.Add( eeNew( cTextureFontLoader, ( "ProggySquareSZ", eeNew( cTextureLoader, ( MyPath + "fonts/ProggySquareSZ.png" ) ), MyPath + "fonts/ProggySquareSZ.dat" ) ) ); - mFontLoader.Add( eeNew( cTTFFontLoader, ( "arial", MyPath + "fonts/arial.ttf", 12, TTF_STYLE_NORMAL, false, 256, eeColor(255,255,255) ) ) ); - mFontLoader.Add( eeNew( cTTFFontLoader, ( "arialb", MyPath + "fonts/arial.ttf", 12, TTF_STYLE_NORMAL, false, 256, eeColor(255,255,255), 1, eeColor(0,0,0), true ) ) ); + mFontLoader.Add( eeNew( cTTFFontLoader, ( "arial", MyPath + "fonts/arial.ttf", 12, TTF_STYLE_NORMAL, 256, eeColor(255,255,255) ) ) ); + mFontLoader.Add( eeNew( cTTFFontLoader, ( "arialb", MyPath + "fonts/arial.ttf", 12, TTF_STYLE_NORMAL, 256, eeColor(255,255,255), 1, eeColor(0,0,0), true ) ) ); mFontLoader.Load( cb::Make1( this, &cEETest::OnFontLoaded ) ); } @@ -1196,7 +1196,8 @@ void cEETest::Screen4() { mVBO->Draw(); mVBO->Unbind(); - mFBOText.Draw( 128.f - (eeFloat)(Int32)( mFBOText.GetTextWidth() * 0.5f ), 25.f - (eeFloat)(Int32)( mFBOText.GetTextHeight() * 0.5f ), FONT_DRAW_CENTER ); + mFBOText.Flags( FONT_DRAW_CENTER ); + mFBOText.Draw( 128.f - (eeFloat)(Int32)( mFBOText.GetTextWidth() * 0.5f ), 25.f - (eeFloat)(Int32)( mFBOText.GetTextHeight() * 0.5f ) ); } if ( NULL != mFBO ) { @@ -1270,6 +1271,8 @@ void cEETest::Render() { eeColorA ColRR2( 100, 100, 100, 220 ); eeColorA ColRR3( 100, 100, 100, 220 ); + mEEText.Flags( FONT_DRAW_CENTER ); + PR.SetColor( eeColorA(150, 150, 150, 220) ); PR.FillMode( DRAW_FILL ); PR.DrawRectangle( @@ -1286,7 +1289,7 @@ void cEETest::Render() { ColRR1, ColRR2, ColRR3, ColRR4 ); - mEEText.Draw( 0.f, (eeFloat)mWindow->GetHeight() - mEEText.GetTextHeight(), FONT_DRAW_CENTER ); + mEEText.Draw( 0.f, (eeFloat)mWindow->GetHeight() - mEEText.GetTextHeight() ); mInfoText.Draw( 6.f, 6.f );