Utility/RichTextDrawer: Add character & line spacing offsets
This commit is contained in:
@@ -33,10 +33,13 @@ namespace Nz
|
||||
inline std::size_t FindBlock(std::size_t glyphIndex) const;
|
||||
|
||||
inline unsigned int GetBlockCharacterSize(std::size_t index) const;
|
||||
inline float GetBlockCharacterSpacingOffset(std::size_t index) const;
|
||||
inline const Color& GetBlockColor(std::size_t index) const;
|
||||
inline std::size_t GetBlockCount() const;
|
||||
inline std::size_t GetBlockFirstGlyphIndex(std::size_t index) const;
|
||||
inline const FontRef& GetBlockFont(std::size_t index) const;
|
||||
inline float GetBlockLineHeight(std::size_t index) const;
|
||||
inline float GetBlockLineSpacingOffset(std::size_t index) const;
|
||||
inline const Color& GetBlockOutlineColor(std::size_t index) const;
|
||||
inline float GetBlockOutlineThickness(std::size_t index) const;
|
||||
inline TextStyleFlags GetBlockStyle(std::size_t index) const;
|
||||
@@ -45,8 +48,10 @@ namespace Nz
|
||||
inline BlockRef GetBlock(std::size_t index);
|
||||
const Rectf& GetBounds() const override;
|
||||
inline unsigned int GetDefaultCharacterSize() const;
|
||||
inline float GetDefaultCharacterSpacingOffset() const;
|
||||
inline const Color& GetDefaultColor() const;
|
||||
inline const FontRef& GetDefaultFont() const;
|
||||
inline float GetDefaultLineSpacingOffset() const;
|
||||
inline const Color& GetDefaultOutlineColor() const;
|
||||
inline float GetDefaultOutlineThickness() const;
|
||||
inline TextStyleFlags GetDefaultStyle() const;
|
||||
@@ -65,16 +70,20 @@ namespace Nz
|
||||
void RemoveBlock(std::size_t index);
|
||||
|
||||
inline void SetBlockCharacterSize(std::size_t index, unsigned int characterSize);
|
||||
inline void SetBlockCharacterSpacingOffset(std::size_t index, float offset);
|
||||
inline void SetBlockColor(std::size_t index, const Color& color);
|
||||
inline void SetBlockFont(std::size_t index, FontRef font);
|
||||
inline void SetBlockLineSpacingOffset(std::size_t index, float offset);
|
||||
inline void SetBlockOutlineColor(std::size_t index, const Color& color);
|
||||
inline void SetBlockOutlineThickness(std::size_t index, float thickness);
|
||||
inline void SetBlockStyle(std::size_t index, TextStyleFlags style);
|
||||
inline void SetBlockText(std::size_t index, String str);
|
||||
|
||||
inline void SetDefaultCharacterSize(unsigned int characterSize);
|
||||
inline void SetDefaultCharacterSpacingOffset(float offset);
|
||||
inline void SetDefaultColor(const Color& color);
|
||||
inline void SetDefaultFont(const FontRef& font);
|
||||
inline void SetDefaultLineSpacingOffset(float offset);
|
||||
inline void SetDefaultOutlineColor(const Color& color);
|
||||
inline void SetDefaultOutlineThickness(float thickness);
|
||||
inline void SetDefaultStyle(TextStyleFlags style);
|
||||
@@ -89,13 +98,15 @@ namespace Nz
|
||||
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, float glyphPosition) const;
|
||||
inline void AppendNewLine(const Font* font, unsigned int characterSize, float lineSpacingOffset) const;
|
||||
void AppendNewLine(const Font* font, unsigned int characterSize, float lineSpacingOffset, std::size_t glyphIndex, float glyphPosition) const;
|
||||
inline void ClearGlyphs() const;
|
||||
inline void ConnectFontSlots();
|
||||
inline void DisconnectFontSlots();
|
||||
bool GenerateGlyph(Glyph& glyph, char32_t character, float outlineThickness, bool lineWrap, const Font* font, const Color& color, TextStyleFlags style, unsigned int characterSize, int renderOrder, int* advance) const;
|
||||
void GenerateGlyphs(const Font* font, const Color& color, TextStyleFlags style, unsigned int characterSize, const Color& outlineColor, float outlineThickness, const String& text) const;
|
||||
bool GenerateGlyph(Glyph& glyph, char32_t character, float outlineThickness, bool lineWrap, const Font* font, const Color& color, TextStyleFlags style, float lineSpacingOffset, unsigned int characterSize, int renderOrder, int* advance) const;
|
||||
void GenerateGlyphs(const Font* font, const Color& color, TextStyleFlags style, unsigned int characterSize, const Color& outlineColor, float characterSpacingOffset, float lineSpacingOffset, float outlineThickness, const String& text) const;
|
||||
inline float GetLineHeight(const Block& block) const;
|
||||
inline float GetLineHeight(float lineSpacingOffset, const Font::SizeInfo& sizeInfo) const;
|
||||
inline std::size_t HandleFontAddition(const FontRef& font);
|
||||
inline void InvalidateGlyphs();
|
||||
inline void ReleaseFont(std::size_t fontIndex);
|
||||
@@ -117,6 +128,8 @@ namespace Nz
|
||||
Color outlineColor;
|
||||
String text;
|
||||
TextStyleFlags style;
|
||||
float characterSpacingOffset;
|
||||
float lineSpacingOffset;
|
||||
float outlineThickness;
|
||||
unsigned int characterSize;
|
||||
};
|
||||
@@ -145,6 +158,8 @@ namespace Nz
|
||||
mutable Rectf m_bounds;
|
||||
mutable Vector2f m_drawPos;
|
||||
mutable bool m_glyphUpdated;
|
||||
float m_defaultCharacterSpacingOffset;
|
||||
float m_defaultLineSpacingOffset;
|
||||
float m_defaultOutlineThickness;
|
||||
float m_maxLineWidth;
|
||||
unsigned int m_defaultCharacterSize;
|
||||
@@ -160,18 +175,22 @@ namespace Nz
|
||||
BlockRef(BlockRef&&) = default;
|
||||
~BlockRef() = default;
|
||||
|
||||
inline float GetCharacterSpacingOffset() const;
|
||||
inline unsigned int GetCharacterSize() const;
|
||||
inline Color GetColor() const;
|
||||
inline std::size_t GetFirstGlyphIndex() const;
|
||||
inline const FontRef& GetFont() const;
|
||||
inline float GetLineSpacingOffset() const;
|
||||
inline Color GetOutlineColor() const;
|
||||
inline float GetOutlineThickness() const;
|
||||
inline TextStyleFlags GetStyle() const;
|
||||
inline const String& GetText() const;
|
||||
|
||||
inline void SetCharacterSpacingOffset(float offset);
|
||||
inline void SetCharacterSize(unsigned int size);
|
||||
inline void SetColor(Color color);
|
||||
inline void SetFont(FontRef font);
|
||||
inline void SetLineSpacingOffset(float offset);
|
||||
inline void SetOutlineColor(Color color);
|
||||
inline void SetOutlineThickness(float thickness);
|
||||
inline void SetStyle(TextStyleFlags style);
|
||||
|
||||
@@ -57,6 +57,12 @@ namespace Nz
|
||||
return m_blocks[index].characterSize;
|
||||
}
|
||||
|
||||
inline float RichTextDrawer::GetBlockCharacterSpacingOffset(std::size_t index) const
|
||||
{
|
||||
NazaraAssert(index < m_blocks.size(), "Invalid block index");
|
||||
return m_blocks[index].characterSpacingOffset;
|
||||
}
|
||||
|
||||
inline const Color& RichTextDrawer::GetBlockColor(std::size_t index) const
|
||||
{
|
||||
NazaraAssert(index < m_blocks.size(), "Invalid block index");
|
||||
@@ -82,6 +88,18 @@ namespace Nz
|
||||
return m_fonts[fontIndex].font;
|
||||
}
|
||||
|
||||
inline float RichTextDrawer::GetBlockLineHeight(std::size_t index) const
|
||||
{
|
||||
NazaraAssert(index < m_blocks.size(), "Invalid block index");
|
||||
return m_blocks[index].lineSpacingOffset;
|
||||
}
|
||||
|
||||
inline float RichTextDrawer::GetBlockLineSpacingOffset(std::size_t index) const
|
||||
{
|
||||
NazaraAssert(index < m_blocks.size(), "Invalid block index");
|
||||
return m_blocks[index].lineSpacingOffset;
|
||||
}
|
||||
|
||||
inline const Color& RichTextDrawer::GetBlockOutlineColor(std::size_t index) const
|
||||
{
|
||||
NazaraAssert(index < m_blocks.size(), "Invalid block index");
|
||||
@@ -111,6 +129,11 @@ namespace Nz
|
||||
return m_defaultCharacterSize;
|
||||
}
|
||||
|
||||
inline float RichTextDrawer::GetDefaultCharacterSpacingOffset() const
|
||||
{
|
||||
return m_defaultCharacterSpacingOffset;
|
||||
}
|
||||
|
||||
inline const Color& RichTextDrawer::GetDefaultColor() const
|
||||
{
|
||||
return m_defaultColor;
|
||||
@@ -121,6 +144,11 @@ namespace Nz
|
||||
return m_defaultFont;
|
||||
}
|
||||
|
||||
inline float RichTextDrawer::GetDefaultLineSpacingOffset() const
|
||||
{
|
||||
return m_defaultLineSpacingOffset;
|
||||
}
|
||||
|
||||
inline const Color& RichTextDrawer::GetDefaultOutlineColor() const
|
||||
{
|
||||
return m_defaultOutlineColor;
|
||||
@@ -136,9 +164,9 @@ namespace Nz
|
||||
return m_defaultStyle;
|
||||
}
|
||||
|
||||
inline void RichTextDrawer::AppendNewLine(const Font* font, unsigned int characterSize) const
|
||||
inline void RichTextDrawer::AppendNewLine(const Font* font, unsigned int characterSize, float lineSpacingOffset) const
|
||||
{
|
||||
AppendNewLine(font, characterSize, InvalidGlyph, 0);
|
||||
AppendNewLine(font, characterSize, lineSpacingOffset, InvalidGlyph, 0);
|
||||
}
|
||||
|
||||
inline void RichTextDrawer::ClearGlyphs() const
|
||||
@@ -173,6 +201,19 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
inline float RichTextDrawer::GetLineHeight(const Block& block) const
|
||||
{
|
||||
assert(block.fontIndex < m_fonts.size());
|
||||
const FontData& fontData = m_fonts[block.fontIndex];
|
||||
|
||||
return GetLineHeight(block.lineSpacingOffset, fontData.font->GetSizeInfo(block.characterSize));
|
||||
}
|
||||
|
||||
inline float RichTextDrawer::GetLineHeight(float lineSpacingOffset, const Font::SizeInfo& sizeInfo) const
|
||||
{
|
||||
return float(sizeInfo.lineHeight) + lineSpacingOffset;
|
||||
}
|
||||
|
||||
inline std::size_t RichTextDrawer::HandleFontAddition(const FontRef& font)
|
||||
{
|
||||
auto it = m_fontIndexes.find(font);
|
||||
@@ -204,10 +245,10 @@ namespace Nz
|
||||
{
|
||||
// Shift font indexes
|
||||
m_fontIndexes.erase(fontData.font);
|
||||
for (auto it = m_fontIndexes.begin(); it != m_fontIndexes.end(); ++it)
|
||||
for (auto& fontIndexe : m_fontIndexes)
|
||||
{
|
||||
if (it->second > fontIndex)
|
||||
it->second--;
|
||||
if (fontIndexe.second > fontIndex)
|
||||
fontIndexe.second--;
|
||||
}
|
||||
|
||||
m_fonts.erase(m_fonts.begin() + fontIndex);
|
||||
@@ -235,6 +276,14 @@ namespace Nz
|
||||
InvalidateGlyphs();
|
||||
}
|
||||
|
||||
inline void RichTextDrawer::SetBlockCharacterSpacingOffset(std::size_t index, float offset)
|
||||
{
|
||||
NazaraAssert(index < m_blocks.size(), "Invalid block index");
|
||||
m_blocks[index].characterSpacingOffset = offset;
|
||||
|
||||
InvalidateGlyphs();
|
||||
}
|
||||
|
||||
inline void RichTextDrawer::SetBlockColor(std::size_t index, const Color& color)
|
||||
{
|
||||
NazaraAssert(index < m_blocks.size(), "Invalid block index");
|
||||
@@ -260,6 +309,14 @@ namespace Nz
|
||||
InvalidateGlyphs();
|
||||
}
|
||||
|
||||
inline void RichTextDrawer::SetBlockLineSpacingOffset(std::size_t index, float offset)
|
||||
{
|
||||
NazaraAssert(index < m_blocks.size(), "Invalid block index");
|
||||
m_blocks[index].lineSpacingOffset = offset;
|
||||
|
||||
InvalidateGlyphs();
|
||||
}
|
||||
|
||||
inline void RichTextDrawer::SetBlockOutlineColor(std::size_t index, const Color& color)
|
||||
{
|
||||
NazaraAssert(index < m_blocks.size(), "Invalid block index");
|
||||
@@ -308,6 +365,11 @@ namespace Nz
|
||||
m_defaultCharacterSize = characterSize;
|
||||
}
|
||||
|
||||
inline void RichTextDrawer::SetDefaultCharacterSpacingOffset(float offset)
|
||||
{
|
||||
m_defaultCharacterSpacingOffset = offset;
|
||||
}
|
||||
|
||||
inline void RichTextDrawer::SetDefaultColor(const Color& color)
|
||||
{
|
||||
m_defaultColor = color;
|
||||
@@ -318,6 +380,11 @@ namespace Nz
|
||||
m_defaultFont = font;
|
||||
}
|
||||
|
||||
inline void RichTextDrawer::SetDefaultLineSpacingOffset(float offset)
|
||||
{
|
||||
m_defaultLineSpacingOffset = offset;
|
||||
}
|
||||
|
||||
inline void RichTextDrawer::SetDefaultOutlineColor(const Color& color)
|
||||
{
|
||||
m_defaultOutlineColor = color;
|
||||
@@ -351,6 +418,17 @@ namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the character spacing offset used for the characters of the referenced block
|
||||
* \return The referenced block character size
|
||||
*
|
||||
* \see GetColor, GetFont, GetStyle, GetText, SetCharacterSize
|
||||
*/
|
||||
inline float RichTextDrawer::BlockRef::GetCharacterSpacingOffset() const
|
||||
{
|
||||
return m_drawer.GetBlockCharacterSpacingOffset(m_blockIndex);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the character size used for the characters of the referenced block
|
||||
* \return The referenced block character size
|
||||
@@ -384,6 +462,17 @@ namespace Nz
|
||||
return m_drawer.GetBlockFont(m_blockIndex);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the line spacing offset used for the characters of the referenced block
|
||||
* \return The referenced block character size
|
||||
*
|
||||
* \see GetColor, GetFont, GetStyle, GetText, SetCharacterSize
|
||||
*/
|
||||
inline float RichTextDrawer::BlockRef::GetLineSpacingOffset() const
|
||||
{
|
||||
return m_drawer.GetBlockLineSpacingOffset(m_blockIndex);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Returns the outline color used for the characters of the referenced block
|
||||
* \return The referenced block outline color
|
||||
@@ -439,6 +528,17 @@ namespace Nz
|
||||
return m_drawer.GetBlockText(m_blockIndex);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Changes the character spacing offset of the referenced block characters
|
||||
* \remark This invalidates the drawer and will force a (complete or partial, depending on the block index) glyph regeneration to occur.
|
||||
*
|
||||
* \see GetCharacterSpacingOffset, SetColor, SetFont, SetStyle, SetText
|
||||
*/
|
||||
inline void RichTextDrawer::BlockRef::SetCharacterSpacingOffset(float offset)
|
||||
{
|
||||
m_drawer.SetBlockCharacterSpacingOffset(m_blockIndex, offset);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Changes the character size of the referenced block characters
|
||||
* \remark This invalidates the drawer and will force a (complete or partial, depending on the block index) glyph regeneration to occur.
|
||||
@@ -472,6 +572,17 @@ namespace Nz
|
||||
m_drawer.SetBlockFont(m_blockIndex, std::move(font));
|
||||
}
|
||||
|
||||
/*!
|
||||
* Changes the line spacing offset of the referenced block characters
|
||||
* \remark This invalidates the drawer and will force a (complete or partial, depending on the block index) glyph regeneration to occur.
|
||||
*
|
||||
* \see GetLineSpacingOffset, SetColor, SetFont, SetStyle, SetText
|
||||
*/
|
||||
inline void RichTextDrawer::BlockRef::SetLineSpacingOffset(float offset)
|
||||
{
|
||||
m_drawer.SetBlockLineSpacingOffset(m_blockIndex, offset);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Changes the outline color of the referenced block characters
|
||||
* \remark This invalidates the drawer and will force a (complete or partial, depending on the block index) glyph regeneration to occur.
|
||||
|
||||
Reference in New Issue
Block a user