Utility/SimpleTextDrawer: Add character spacing offset
This commit is contained in:
parent
5dd37ed3d8
commit
11d51872fa
|
|
@ -29,6 +29,7 @@ namespace Nz
|
|||
void Clear() override;
|
||||
|
||||
const Rectf& GetBounds() const override;
|
||||
inline float GetCharacterSpacingOffset() const;
|
||||
inline unsigned int GetCharacterSize() const;
|
||||
inline const Color& GetColor() const;
|
||||
inline Font* GetFont() const;
|
||||
|
|
@ -46,6 +47,7 @@ namespace Nz
|
|||
inline TextStyleFlags GetStyle() const;
|
||||
inline const String& GetText() const;
|
||||
|
||||
inline void SetCharacterSpacingOffset(float offset);
|
||||
inline void SetCharacterSize(unsigned int characterSize);
|
||||
inline void SetColor(const Color& color);
|
||||
inline void SetFont(Font* font);
|
||||
|
|
@ -112,6 +114,7 @@ namespace Nz
|
|||
mutable bool m_glyphUpdated;
|
||||
mutable float m_lastSeparatorPosition;
|
||||
float m_lineSpacingFactor;
|
||||
float m_characterSpacingOffset;
|
||||
float m_maxLineWidth;
|
||||
float m_outlineThickness;
|
||||
unsigned int m_characterSize;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ namespace Nz
|
|||
m_colorUpdated(true),
|
||||
m_glyphUpdated(true),
|
||||
m_lineSpacingFactor(1.f),
|
||||
m_characterSpacingOffset(0.f),
|
||||
m_maxLineWidth(std::numeric_limits<float>::infinity()),
|
||||
m_outlineThickness(0.f),
|
||||
m_characterSize(24)
|
||||
|
|
@ -29,6 +30,7 @@ namespace Nz
|
|||
m_glyphUpdated(false),
|
||||
m_outlineColor(drawer.m_outlineColor),
|
||||
m_lineSpacingFactor(drawer.m_lineSpacingFactor),
|
||||
m_characterSpacingOffset(drawer.m_characterSpacingOffset),
|
||||
m_maxLineWidth(drawer.m_maxLineWidth),
|
||||
m_outlineThickness(drawer.m_outlineThickness),
|
||||
m_characterSize(drawer.m_characterSize)
|
||||
|
|
@ -48,6 +50,11 @@ namespace Nz
|
|||
GenerateGlyphs(str);
|
||||
}
|
||||
|
||||
inline float SimpleTextDrawer::GetCharacterSpacingOffset() const
|
||||
{
|
||||
return m_characterSpacingOffset;
|
||||
}
|
||||
|
||||
inline unsigned int SimpleTextDrawer::GetCharacterSize() const
|
||||
{
|
||||
return m_characterSize;
|
||||
|
|
@ -94,6 +101,16 @@ namespace Nz
|
|||
return m_text;
|
||||
}
|
||||
|
||||
inline void SimpleTextDrawer::SetCharacterSpacingOffset(float offset)
|
||||
{
|
||||
if (m_characterSpacingOffset != offset)
|
||||
{
|
||||
m_characterSpacingOffset = offset;
|
||||
|
||||
InvalidateGlyphs();
|
||||
}
|
||||
}
|
||||
|
||||
inline void SimpleTextDrawer::SetCharacterSize(unsigned int characterSize)
|
||||
{
|
||||
if (m_characterSize != characterSize)
|
||||
|
|
@ -196,6 +213,7 @@ namespace Nz
|
|||
inline SimpleTextDrawer& SimpleTextDrawer::operator=(const SimpleTextDrawer& drawer)
|
||||
{
|
||||
m_characterSize = drawer.m_characterSize;
|
||||
m_characterSpacingOffset = drawer.m_characterSpacingOffset;
|
||||
m_color = drawer.m_color;
|
||||
m_lineSpacingFactor = drawer.m_lineSpacingFactor;
|
||||
m_maxLineWidth = drawer.m_maxLineWidth;
|
||||
|
|
@ -217,6 +235,7 @@ namespace Nz
|
|||
m_bounds = std::move(drawer.m_bounds);
|
||||
m_colorUpdated = std::move(drawer.m_colorUpdated);
|
||||
m_characterSize = std::move(drawer.m_characterSize);
|
||||
m_characterSpacingOffset = drawer.m_characterSpacingOffset;
|
||||
m_color = std::move(drawer.m_color);
|
||||
m_glyphs = std::move(drawer.m_glyphs);
|
||||
m_glyphUpdated = std::move(drawer.m_glyphUpdated);
|
||||
|
|
|
|||
|
|
@ -206,16 +206,16 @@ namespace Nz
|
|||
m_previousCharacter = character;
|
||||
|
||||
bool whitespace = true;
|
||||
float advance = 0.f;
|
||||
float advance = m_characterSpacingOffset;
|
||||
switch (character)
|
||||
{
|
||||
case ' ':
|
||||
case '\n':
|
||||
advance = float(sizeInfo.spaceAdvance);
|
||||
advance += float(sizeInfo.spaceAdvance);
|
||||
break;
|
||||
|
||||
case '\t':
|
||||
advance = float(sizeInfo.spaceAdvance) * 4.f;
|
||||
advance += float(sizeInfo.spaceAdvance) * 4.f;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
@ -230,7 +230,7 @@ namespace Nz
|
|||
if (!GenerateGlyph(glyph, character, 0.f, true, m_color, 0, &iAdvance))
|
||||
continue; // Glyph failed to load, just skip it (can't do much)
|
||||
|
||||
advance = float(iAdvance);
|
||||
advance += float(iAdvance);
|
||||
|
||||
if (m_outlineThickness > 0.f)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue