Utility/*TextDrawer: Use float internally
+ some fixes
This commit is contained in:
@@ -102,7 +102,7 @@ namespace Nz
|
||||
mutable std::unordered_map<RenderKey, RenderIndices, HashRenderKey> m_renderInfos;
|
||||
mutable std::vector<VertexStruct_XY_Color_UV> m_localVertices;
|
||||
Color m_color;
|
||||
Recti m_localBounds;
|
||||
Rectf m_localBounds;
|
||||
float m_scale;
|
||||
|
||||
static TextSpriteLibrary::LibraryMap s_library;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Nz
|
||||
|
||||
inline TextSprite::TextSprite() :
|
||||
m_color(Color::White),
|
||||
m_localBounds(Nz::Recti::Zero()),
|
||||
m_localBounds(Nz::Rectf::Zero()),
|
||||
m_scale(1.f)
|
||||
{
|
||||
ResetMaterials(1U);
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Nz
|
||||
|
||||
virtual void Clear() = 0;
|
||||
|
||||
virtual const Recti& GetBounds() const = 0;
|
||||
virtual const Rectf& GetBounds() const = 0;
|
||||
virtual Font* GetFont(std::size_t index) const = 0;
|
||||
virtual std::size_t GetFontCount() const = 0;
|
||||
virtual const Glyph& GetGlyph(std::size_t index) const = 0;
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Nz
|
||||
inline const String& GetBlockText(std::size_t index) const;
|
||||
|
||||
inline BlockRef GetBlock(std::size_t index);
|
||||
const Recti& GetBounds() const override;
|
||||
const Rectf& GetBounds() const override;
|
||||
inline unsigned int GetDefaultCharacterSize() const;
|
||||
inline const Color& GetDefaultColor() const;
|
||||
inline const FontRef& GetDefaultFont() const;
|
||||
@@ -86,14 +86,11 @@ namespace Nz
|
||||
|
||||
static constexpr std::size_t InvalidBlockIndex = std::numeric_limits<std::size_t>::max();
|
||||
|
||||
//static RichTextDrawer Draw(const String& str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White);
|
||||
//static RichTextDrawer Draw(Font* font, const String& str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White);
|
||||
|
||||
private:
|
||||
struct Block;
|
||||
|
||||
inline void AppendNewLine(const Font* font, unsigned int characterSize) const;
|
||||
void AppendNewLine(const Font* font, unsigned int characterSize, std::size_t glyphIndex, unsigned int glyphPosition) const;
|
||||
void AppendNewLine(const Font* font, unsigned int characterSize, std::size_t glyphIndex, float glyphPosition) const;
|
||||
inline void ClearGlyphs() const;
|
||||
inline void ConnectFontSlots();
|
||||
inline void DisconnectFontSlots();
|
||||
@@ -145,14 +142,13 @@ namespace Nz
|
||||
std::vector<FontData> m_fonts;
|
||||
mutable std::vector<Glyph> m_glyphs;
|
||||
mutable std::vector<Line> m_lines;
|
||||
mutable Rectf m_workingBounds;
|
||||
mutable Recti m_bounds;
|
||||
mutable Vector2ui m_drawPos;
|
||||
mutable Rectf m_bounds;
|
||||
mutable Vector2f m_drawPos;
|
||||
mutable bool m_glyphUpdated;
|
||||
float m_defaultOutlineThickness;
|
||||
float m_maxLineWidth;
|
||||
unsigned int m_defaultCharacterSize;
|
||||
mutable unsigned int m_lastSeparatorPosition;
|
||||
mutable float m_lastSeparatorPosition;
|
||||
};
|
||||
|
||||
class RichTextDrawer::BlockRef
|
||||
|
||||
@@ -148,7 +148,7 @@ namespace Nz
|
||||
m_lines.clear();
|
||||
m_glyphs.clear();
|
||||
m_glyphUpdated = true;
|
||||
m_workingBounds.MakeZero(); //< Compute bounds as float to speedup bounds computation (as casting between floats and integers is costly)
|
||||
m_bounds.MakeZero(); //< Compute bounds as float to speedup bounds computation (as casting between floats and integers is costly)
|
||||
}
|
||||
|
||||
inline void RichTextDrawer::ConnectFontSlots()
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Nz
|
||||
|
||||
void Clear() override;
|
||||
|
||||
const Recti& GetBounds() const override;
|
||||
const Rectf& GetBounds() const override;
|
||||
inline unsigned int GetCharacterSize() const;
|
||||
inline const Color& GetColor() const;
|
||||
inline Font* GetFont() const;
|
||||
@@ -38,6 +38,7 @@ namespace Nz
|
||||
std::size_t GetGlyphCount() const override;
|
||||
const Line& GetLine(std::size_t index) const override;
|
||||
std::size_t GetLineCount() const override;
|
||||
inline float GetLineHeight() const;
|
||||
float GetMaxLineWidth() const override;
|
||||
inline const Color& GetOutlineColor() const;
|
||||
inline float GetOutlineThickness() const;
|
||||
@@ -64,7 +65,7 @@ namespace Nz
|
||||
|
||||
private:
|
||||
inline void AppendNewLine() const;
|
||||
void AppendNewLine(std::size_t glyphIndex, unsigned int glyphPosition) const;
|
||||
void AppendNewLine(std::size_t glyphIndex, float glyphPosition) const;
|
||||
|
||||
void ClearGlyphs() const;
|
||||
|
||||
@@ -74,6 +75,8 @@ namespace Nz
|
||||
bool GenerateGlyph(Glyph& glyph, char32_t character, float outlineThickness, bool lineWrap, Nz::Color color, int renderOrder, int* advance) const;
|
||||
void GenerateGlyphs(const String& text) const;
|
||||
|
||||
inline float GetLineHeight(const Font::SizeInfo& sizeInfo) const;
|
||||
|
||||
inline void InvalidateColor();
|
||||
inline void InvalidateGlyphs();
|
||||
|
||||
@@ -94,20 +97,19 @@ namespace Nz
|
||||
NazaraSlot(Font, OnFontRelease, m_fontReleaseSlot);
|
||||
|
||||
mutable std::size_t m_lastSeparatorGlyph;
|
||||
mutable unsigned int m_lastSeparatorPosition;
|
||||
mutable std::vector<Glyph> m_glyphs;
|
||||
mutable std::vector<Line> m_lines;
|
||||
Color m_color;
|
||||
Color m_outlineColor;
|
||||
FontRef m_font;
|
||||
mutable Rectf m_workingBounds;
|
||||
mutable Recti m_bounds;
|
||||
mutable Rectf m_bounds;
|
||||
String m_text;
|
||||
TextStyleFlags m_style;
|
||||
mutable UInt32 m_previousCharacter;
|
||||
mutable Vector2ui m_drawPos;
|
||||
mutable Vector2f m_drawPos;
|
||||
mutable bool m_colorUpdated;
|
||||
mutable bool m_glyphUpdated;
|
||||
mutable float m_lastSeparatorPosition;
|
||||
float m_maxLineWidth;
|
||||
float m_outlineThickness;
|
||||
unsigned int m_characterSize;
|
||||
|
||||
@@ -61,6 +61,12 @@ namespace Nz
|
||||
return m_font;
|
||||
}
|
||||
|
||||
inline float SimpleTextDrawer::GetLineHeight() const
|
||||
{
|
||||
NazaraAssert(m_font, "SimpleTextDrawer has no font");
|
||||
return GetLineHeight(m_font->GetSizeInfo(m_characterSize));
|
||||
}
|
||||
|
||||
inline const Color& SimpleTextDrawer::GetOutlineColor() const
|
||||
{
|
||||
return m_outlineColor;
|
||||
@@ -205,7 +211,11 @@ namespace Nz
|
||||
|
||||
// Update slot pointers (TODO: Improve the way of doing this)
|
||||
ConnectFontSlots();
|
||||
drawer.DisconnectFontSlots();
|
||||
if (m_font)
|
||||
{
|
||||
drawer.DisconnectFontSlots();
|
||||
ConnectFontSlots();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -265,6 +275,27 @@ namespace Nz
|
||||
AppendNewLine(InvalidGlyph, 0);
|
||||
}
|
||||
|
||||
inline void SimpleTextDrawer::ConnectFontSlots()
|
||||
{
|
||||
m_atlasChangedSlot.Connect(m_font->OnFontAtlasChanged, this, &SimpleTextDrawer::OnFontInvalidated);
|
||||
m_atlasLayerChangedSlot.Connect(m_font->OnFontAtlasLayerChanged, this, &SimpleTextDrawer::OnFontAtlasLayerChanged);
|
||||
m_fontReleaseSlot.Connect(m_font->OnFontRelease, this, &SimpleTextDrawer::OnFontRelease);
|
||||
m_glyphCacheClearedSlot.Connect(m_font->OnFontGlyphCacheCleared, this, &SimpleTextDrawer::OnFontInvalidated);
|
||||
}
|
||||
|
||||
inline void SimpleTextDrawer::DisconnectFontSlots()
|
||||
{
|
||||
m_atlasChangedSlot.Disconnect();
|
||||
m_atlasLayerChangedSlot.Disconnect();
|
||||
m_fontReleaseSlot.Disconnect();
|
||||
m_glyphCacheClearedSlot.Disconnect();
|
||||
}
|
||||
|
||||
inline float SimpleTextDrawer::GetLineHeight(const Font::SizeInfo& sizeInfo) const
|
||||
{
|
||||
return float(sizeInfo.lineHeight);
|
||||
}
|
||||
|
||||
inline void SimpleTextDrawer::InvalidateColor()
|
||||
{
|
||||
m_colorUpdated = false;
|
||||
|
||||
Reference in New Issue
Block a user