Rework TextDrawer interface

This commit is contained in:
SirLynix 2023-08-24 17:47:20 +02:00
parent 9579eba43d
commit 557da10dc6
17 changed files with 293 additions and 299 deletions

View File

@ -34,7 +34,7 @@ int main(int argc, char* argv[])
Nz::SimpleTextDrawer textDrawer; Nz::SimpleTextDrawer textDrawer;
textDrawer.SetText("Hello world !"); textDrawer.SetText("Hello world !");
textDrawer.SetCharacterSize(72); textDrawer.SetCharacterSize(72);
textDrawer.SetOutlineThickness(4.f); textDrawer.SetTextOutlineThickness(4.f);
std::shared_ptr<Nz::TextSprite> textSprite = std::make_shared<Nz::TextSprite>(); std::shared_ptr<Nz::TextSprite> textSprite = std::make_shared<Nz::TextSprite>();
textSprite->Update(textDrawer); textSprite->Update(textDrawer);

View File

@ -39,7 +39,7 @@ int main(int argc, char* argv[])
Nz::SimpleTextDrawer textDrawer; Nz::SimpleTextDrawer textDrawer;
textDrawer.SetCharacterSize(72); textDrawer.SetCharacterSize(72);
textDrawer.SetOutlineThickness(4.f); textDrawer.SetTextOutlineThickness(4.f);
textDrawer.SetText("Press a key"); textDrawer.SetText("Press a key");
std::shared_ptr<Nz::TextSprite> textSprite = std::make_shared<Nz::TextSprite>(); std::shared_ptr<Nz::TextSprite> textSprite = std::make_shared<Nz::TextSprite>();

View File

@ -23,10 +23,10 @@ namespace Nz
RichTextDrawer(); RichTextDrawer();
RichTextDrawer(const RichTextDrawer& drawer); RichTextDrawer(const RichTextDrawer& drawer);
RichTextDrawer(RichTextDrawer&& drawer); RichTextDrawer(RichTextDrawer&& drawer) noexcept;
~RichTextDrawer(); ~RichTextDrawer();
BlockRef AppendText(const std::string& str, bool forceNewBlock = false); BlockRef AppendText(std::string_view str, bool forceNewBlock = false);
void Clear() override; void Clear() override;
@ -38,7 +38,6 @@ namespace Nz
inline std::size_t GetBlockCount() const; inline std::size_t GetBlockCount() const;
inline std::size_t GetBlockFirstGlyphIndex(std::size_t index) const; inline std::size_t GetBlockFirstGlyphIndex(std::size_t index) const;
inline const std::shared_ptr<Font>& GetBlockFont(std::size_t index) const; inline const std::shared_ptr<Font>& GetBlockFont(std::size_t index) const;
inline float GetBlockLineHeight(std::size_t index) const;
inline float GetBlockLineSpacingOffset(std::size_t index) const; inline float GetBlockLineSpacingOffset(std::size_t index) const;
inline const Color& GetBlockOutlineColor(std::size_t index) const; inline const Color& GetBlockOutlineColor(std::size_t index) const;
inline float GetBlockOutlineThickness(std::size_t index) const; inline float GetBlockOutlineThickness(std::size_t index) const;
@ -47,14 +46,9 @@ namespace Nz
inline BlockRef GetBlock(std::size_t index); inline BlockRef GetBlock(std::size_t index);
const Rectf& GetBounds() const override; const Rectf& GetBounds() const override;
inline unsigned int GetDefaultCharacterSize() const; inline unsigned int GetCharacterSize() const;
inline float GetDefaultCharacterSpacingOffset() const; inline float GetCharacterSpacingOffset() const;
inline const Color& GetDefaultColor() const; inline float GetLineSpacingOffset() const;
inline const std::shared_ptr<Font>& GetDefaultFont() const;
inline float GetDefaultLineSpacingOffset() const;
inline const Color& GetDefaultOutlineColor() const;
inline float GetDefaultOutlineThickness() const;
inline TextStyleFlags GetDefaultStyle() const;
const std::shared_ptr<Font>& GetFont(std::size_t index) const override; const std::shared_ptr<Font>& GetFont(std::size_t index) const override;
std::size_t GetFontCount() const override; std::size_t GetFontCount() const override;
const Glyph& GetGlyph(std::size_t index) const override; const Glyph& GetGlyph(std::size_t index) const override;
@ -63,6 +57,12 @@ namespace Nz
std::size_t GetLineCount() const override; std::size_t GetLineCount() const override;
float GetMaxLineWidth() const override; float GetMaxLineWidth() const override;
inline const Color& GetTextColor() const;
inline const std::shared_ptr<Font>& GetTextFont() const;
inline const Color& GetTextOutlineColor() const;
inline float GetTextOutlineThickness() const;
inline TextStyleFlags GetTextStyle() const;
inline bool HasBlocks() const; inline bool HasBlocks() const;
void MergeBlocks(); void MergeBlocks();
@ -79,22 +79,22 @@ namespace Nz
inline void SetBlockStyle(std::size_t index, TextStyleFlags style); inline void SetBlockStyle(std::size_t index, TextStyleFlags style);
inline void SetBlockText(std::size_t index, std::string str); inline void SetBlockText(std::size_t index, std::string str);
inline void SetDefaultCharacterSize(unsigned int characterSize); inline void SetCharacterSize(unsigned int characterSize);
inline void SetDefaultCharacterSpacingOffset(float offset); inline void SetCharacterSpacingOffset(float offset);
inline void SetDefaultColor(const Color& color); inline void SetLineSpacingOffset(float offset);
inline void SetDefaultFont(const std::shared_ptr<Font>& font); inline void SetTextColor(const Color& color);
inline void SetDefaultLineSpacingOffset(float offset); inline void SetTextFont(const std::shared_ptr<Font>& font);
inline void SetDefaultOutlineColor(const Color& color); inline void SetTextOutlineColor(const Color& color);
inline void SetDefaultOutlineThickness(float thickness); inline void SetTextOutlineThickness(float thickness);
inline void SetDefaultStyle(TextStyleFlags style); inline void SetTextStyle(TextStyleFlags style);
void SetMaxLineWidth(float lineWidth) override; void SetMaxLineWidth(float lineWidth) override;
RichTextDrawer& operator=(const RichTextDrawer& drawer); RichTextDrawer& operator=(const RichTextDrawer& drawer);
RichTextDrawer& operator=(RichTextDrawer&& drawer); RichTextDrawer& operator=(RichTextDrawer&& drawer) noexcept;
static constexpr std::size_t InvalidBlockIndex = std::numeric_limits<std::size_t>::max(); static constexpr std::size_t InvalidBlockIndex = std::numeric_limits<std::size_t>::max();
private: private:
struct Block; struct Block;
@ -145,10 +145,10 @@ namespace Nz
NazaraSlot(Font, OnFontRelease, fontReleaseSlot); NazaraSlot(Font, OnFontRelease, fontReleaseSlot);
}; };
Color m_defaultColor; Color m_currentColor;
Color m_defaultOutlineColor; Color m_currentOutlineColor;
TextStyleFlags m_defaultStyle; TextStyleFlags m_currentStyle;
std::shared_ptr<Font> m_defaultFont; std::shared_ptr<Font> m_currentFont;
mutable std::size_t m_lastSeparatorGlyph; mutable std::size_t m_lastSeparatorGlyph;
std::unordered_map<std::shared_ptr<Font>, std::size_t> m_fontIndexes; std::unordered_map<std::shared_ptr<Font>, std::size_t> m_fontIndexes;
std::vector<Block> m_blocks; std::vector<Block> m_blocks;
@ -158,11 +158,11 @@ namespace Nz
mutable Rectf m_bounds; mutable Rectf m_bounds;
mutable Vector2f m_drawPos; mutable Vector2f m_drawPos;
mutable bool m_glyphUpdated; mutable bool m_glyphUpdated;
float m_defaultCharacterSpacingOffset; float m_currentCharacterSpacingOffset;
float m_defaultLineSpacingOffset; float m_currentLineSpacingOffset;
float m_defaultOutlineThickness; float m_currentOutlineThickness;
float m_maxLineWidth; float m_maxLineWidth;
unsigned int m_defaultCharacterSize; unsigned int m_currentCharacterSize;
mutable float m_lastSeparatorPosition; mutable float m_lastSeparatorPosition;
}; };

View File

@ -87,12 +87,6 @@ namespace Nz
return m_fonts[fontIndex].font; 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 inline float RichTextDrawer::GetBlockLineSpacingOffset(std::size_t index) const
{ {
NazaraAssert(index < m_blocks.size(), "Invalid block index"); NazaraAssert(index < m_blocks.size(), "Invalid block index");
@ -123,44 +117,19 @@ namespace Nz
return m_blocks[index].text; return m_blocks[index].text;
} }
inline unsigned int RichTextDrawer::GetDefaultCharacterSize() const inline unsigned int RichTextDrawer::GetCharacterSize() const
{ {
return m_defaultCharacterSize; return m_currentCharacterSize;
} }
inline float RichTextDrawer::GetDefaultCharacterSpacingOffset() const inline float RichTextDrawer::GetCharacterSpacingOffset() const
{ {
return m_defaultCharacterSpacingOffset; return m_currentCharacterSpacingOffset;
} }
inline const Color& RichTextDrawer::GetDefaultColor() const inline float RichTextDrawer::GetLineSpacingOffset() const
{ {
return m_defaultColor; return m_currentLineSpacingOffset;
}
inline const std::shared_ptr<Font>& RichTextDrawer::GetDefaultFont() const
{
return m_defaultFont;
}
inline float RichTextDrawer::GetDefaultLineSpacingOffset() const
{
return m_defaultLineSpacingOffset;
}
inline const Color& RichTextDrawer::GetDefaultOutlineColor() const
{
return m_defaultOutlineColor;
}
inline float RichTextDrawer::GetDefaultOutlineThickness() const
{
return m_defaultOutlineThickness;
}
inline TextStyleFlags RichTextDrawer::GetDefaultStyle() const
{
return m_defaultStyle;
} }
inline void RichTextDrawer::AppendNewLine(const Font& font, unsigned int characterSize, float lineSpacingOffset) const inline void RichTextDrawer::AppendNewLine(const Font& font, unsigned int characterSize, float lineSpacingOffset) const
@ -261,6 +230,31 @@ namespace Nz
return m_lines.back().bounds.GetMaximum().x + size > m_maxLineWidth; return m_lines.back().bounds.GetMaximum().x + size > m_maxLineWidth;
} }
inline const Color& RichTextDrawer::GetTextColor() const
{
return m_currentColor;
}
inline const std::shared_ptr<Font>& RichTextDrawer::GetTextFont() const
{
return m_currentFont;
}
inline const Color& RichTextDrawer::GetTextOutlineColor() const
{
return m_currentOutlineColor;
}
inline float RichTextDrawer::GetTextOutlineThickness() const
{
return m_currentOutlineThickness;
}
inline TextStyleFlags RichTextDrawer::GetTextStyle() const
{
return m_currentStyle;
}
inline bool RichTextDrawer::HasBlocks() const inline bool RichTextDrawer::HasBlocks() const
{ {
return !m_blocks.empty(); return !m_blocks.empty();
@ -358,44 +352,44 @@ namespace Nz
InvalidateGlyphs(); InvalidateGlyphs();
} }
inline void RichTextDrawer::SetDefaultCharacterSize(unsigned int characterSize) inline void RichTextDrawer::SetCharacterSize(unsigned int characterSize)
{ {
m_defaultCharacterSize = characterSize; m_currentCharacterSize = characterSize;
} }
inline void RichTextDrawer::SetDefaultCharacterSpacingOffset(float offset) inline void RichTextDrawer::SetCharacterSpacingOffset(float offset)
{ {
m_defaultCharacterSpacingOffset = offset; m_currentCharacterSpacingOffset = offset;
} }
inline void RichTextDrawer::SetDefaultColor(const Color& color) inline void RichTextDrawer::SetLineSpacingOffset(float offset)
{ {
m_defaultColor = color; m_currentLineSpacingOffset = offset;
} }
inline void RichTextDrawer::SetDefaultFont(const std::shared_ptr<Font>& font) inline void RichTextDrawer::SetTextColor(const Color& color)
{ {
m_defaultFont = font; m_currentColor = color;
} }
inline void RichTextDrawer::SetDefaultLineSpacingOffset(float offset) inline void RichTextDrawer::SetTextFont(const std::shared_ptr<Font>& font)
{ {
m_defaultLineSpacingOffset = offset; m_currentFont = font;
} }
inline void RichTextDrawer::SetDefaultOutlineColor(const Color& color) inline void RichTextDrawer::SetTextOutlineColor(const Color& color)
{ {
m_defaultOutlineColor = color; m_currentOutlineColor = color;
} }
inline void RichTextDrawer::SetDefaultOutlineThickness(float thickness) inline void RichTextDrawer::SetTextOutlineThickness(float thickness)
{ {
m_defaultOutlineThickness = thickness; m_currentOutlineThickness = thickness;
} }
inline void RichTextDrawer::SetDefaultStyle(TextStyleFlags style) inline void RichTextDrawer::SetTextStyle(TextStyleFlags style)
{ {
m_defaultStyle = style; m_currentStyle = style;
} }
inline void RichTextDrawer::InvalidateGlyphs() inline void RichTextDrawer::InvalidateGlyphs()
@ -453,7 +447,7 @@ namespace Nz
* Returns the font used for the characters of the referenced block * Returns the font used for the characters of the referenced block
* \return A reference on the referenced block font * \return A reference on the referenced block font
* *
* \see GetCharacterSize, GetColor, GetStyle, GetText, SetFont * \see GetCharacterSize, GetTextColor, GetStyle, GetText, SetFont
*/ */
inline const std::shared_ptr<Font>& RichTextDrawer::BlockRef::GetFont() const inline const std::shared_ptr<Font>& RichTextDrawer::BlockRef::GetFont() const
{ {
@ -464,7 +458,7 @@ namespace Nz
* Returns the line spacing offset used for the characters of the referenced block * Returns the line spacing offset used for the characters of the referenced block
* \return The referenced block character size * \return The referenced block character size
* *
* \see GetColor, GetFont, GetStyle, GetText, SetCharacterSize * \see GetTextColor, GetTextFont, GetStyle, GetText, SetCharacterSize
*/ */
inline float RichTextDrawer::BlockRef::GetLineSpacingOffset() const inline float RichTextDrawer::BlockRef::GetLineSpacingOffset() const
{ {
@ -475,7 +469,7 @@ namespace Nz
* Returns the outline color used for the characters of the referenced block * Returns the outline color used for the characters of the referenced block
* \return The referenced block outline color * \return The referenced block outline color
* *
* \see GetCharacterSize, GetColor, GetStyle, GetText, SetFont * \see GetCharacterSize, GetTextColor, GetStyle, GetText, SetFont
*/ */
inline Color RichTextDrawer::BlockRef::GetOutlineColor() const inline Color RichTextDrawer::BlockRef::GetOutlineColor() const
{ {
@ -486,7 +480,7 @@ namespace Nz
* Returns the outline thickness used for the characters of the referenced block * Returns the outline thickness used for the characters of the referenced block
* \return The referenced block outline thickness * \return The referenced block outline thickness
* *
* \see GetCharacterSize, GetColor, GetStyle, GetText, SetFont * \see GetCharacterSize, GetTextColor, GetStyle, GetText, SetFont
*/ */
inline float RichTextDrawer::BlockRef::GetOutlineThickness() const inline float RichTextDrawer::BlockRef::GetOutlineThickness() const
{ {
@ -497,7 +491,7 @@ namespace Nz
* Returns the style flags used for the characters of the referenced block * Returns the style flags used for the characters of the referenced block
* \return The referenced block style flags (see TextStyleFlags) * \return The referenced block style flags (see TextStyleFlags)
* *
* \see GetCharacterSize, GetColor, GetFont, GetText, SetStyle * \see GetCharacterSize, GetTextColor, GetTextFont, GetText, SetStyle
*/ */
inline TextStyleFlags RichTextDrawer::BlockRef::GetStyle() const inline TextStyleFlags RichTextDrawer::BlockRef::GetStyle() const
{ {
@ -519,7 +513,7 @@ namespace Nz
* Returns the text of the referenced block * Returns the text of the referenced block
* \return The referenced block text * \return The referenced block text
* *
* \see GetCharacterSize, GetColor, GetFont, GetStyle, SetText * \see GetCharacterSize, GetTextColor, GetTextFont, GetStyle, SetText
*/ */
inline const std::string& RichTextDrawer::BlockRef::GetText() const inline const std::string& RichTextDrawer::BlockRef::GetText() const
{ {
@ -552,7 +546,7 @@ namespace Nz
* Changes the color of the referenced block characters * Changes the color of the referenced block characters
* \remark This is the only property that can be changed without forcing a glyph regeneration * \remark This is the only property that can be changed without forcing a glyph regeneration
* *
* \see GetColor, SetCharacterSize, SetFont, SetStyle, SetText * \see GetTextColor, SetCharacterSize, SetFont, SetStyle, SetText
*/ */
inline void RichTextDrawer::BlockRef::SetColor(Color color) inline void RichTextDrawer::BlockRef::SetColor(Color color)
{ {
@ -563,7 +557,7 @@ namespace Nz
* Changes the font of the referenced block characters * Changes the font 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. * \remark This invalidates the drawer and will force a (complete or partial, depending on the block index) glyph regeneration to occur.
* *
* \see GetCharacterSize, SetCharacterSize, SetColor, SetStyle, SetText * \see GetCharacterSize, SetCharacterSize, SetTextColor, SetStyle, SetText
*/ */
inline void RichTextDrawer::BlockRef::SetFont(std::shared_ptr<Font> font) inline void RichTextDrawer::BlockRef::SetFont(std::shared_ptr<Font> font)
{ {
@ -574,7 +568,7 @@ namespace Nz
* Changes the line spacing offset of the referenced block characters * 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. * \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 * \see GetLineSpacingOffset, SetTextColor, SetTextFont, SetStyle, SetText
*/ */
inline void RichTextDrawer::BlockRef::SetLineSpacingOffset(float offset) inline void RichTextDrawer::BlockRef::SetLineSpacingOffset(float offset)
{ {
@ -585,7 +579,7 @@ namespace Nz
* Changes the outline color of the referenced block characters * 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. * \remark This invalidates the drawer and will force a (complete or partial, depending on the block index) glyph regeneration to occur.
* *
* \see GetCharacterSize, SetCharacterSize, SetColor, SetStyle, SetText * \see GetCharacterSize, SetCharacterSize, SetTextColor, SetStyle, SetText
*/ */
inline void RichTextDrawer::BlockRef::SetOutlineColor(Color color) inline void RichTextDrawer::BlockRef::SetOutlineColor(Color color)
{ {
@ -596,7 +590,7 @@ namespace Nz
* Changes the outline thickness of the referenced block characters * Changes the outline thickness 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. * \remark This invalidates the drawer and will force a (complete or partial, depending on the block index) glyph regeneration to occur.
* *
* \see GetCharacterSize, SetCharacterSize, SetColor, SetStyle, SetText * \see GetCharacterSize, SetCharacterSize, SetTextColor, SetStyle, SetText
*/ */
inline void RichTextDrawer::BlockRef::SetOutlineThickness(float thickness) inline void RichTextDrawer::BlockRef::SetOutlineThickness(float thickness)
{ {
@ -607,7 +601,7 @@ namespace Nz
* Changes the style flags of the referenced block characters * Changes the style flags 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. * \remark This invalidates the drawer and will force a (complete or partial, depending on the block index) glyph regeneration to occur.
* *
* \see GetStyle, SetCharacterSize, SetColor, SetFont, SetText * \see GetStyle, SetCharacterSize, SetTextColor, SetTextFont, SetText
*/ */
inline void RichTextDrawer::BlockRef::SetStyle(TextStyleFlags style) inline void RichTextDrawer::BlockRef::SetStyle(TextStyleFlags style)
{ {
@ -618,7 +612,7 @@ namespace Nz
* Changes the text of the referenced block * Changes the text of the referenced block
* \remark This invalidates the drawer and will force a (complete or partial, depending on the block index) glyph regeneration to occur. * \remark This invalidates the drawer and will force a (complete or partial, depending on the block index) glyph regeneration to occur.
* *
* \see GetText, SetCharacterSize, SetColor, SetFont, SetStyle * \see GetText, SetCharacterSize, SetTextColor, SetTextFont, SetTextStyle
*/ */
inline void RichTextDrawer::BlockRef::SetText(std::string text) inline void RichTextDrawer::BlockRef::SetText(std::string text)
{ {
@ -627,3 +621,4 @@ namespace Nz
} }
#include <Nazara/Utility/DebugOff.hpp> #include <Nazara/Utility/DebugOff.hpp>
#include "RichTextDrawer.hpp"

View File

@ -30,8 +30,6 @@ namespace Nz
const Rectf& GetBounds() const override; const Rectf& GetBounds() const override;
inline float GetCharacterSpacingOffset() const; inline float GetCharacterSpacingOffset() const;
inline unsigned int GetCharacterSize() const; inline unsigned int GetCharacterSize() const;
inline const Color& GetColor() const;
inline const std::shared_ptr<Font>& GetFont() const;
const std::shared_ptr<Font>& GetFont(std::size_t index) const override; const std::shared_ptr<Font>& GetFont(std::size_t index) const override;
std::size_t GetFontCount() const override; std::size_t GetFontCount() const override;
const Glyph& GetGlyph(std::size_t index) const override; const Glyph& GetGlyph(std::size_t index) const override;
@ -41,29 +39,32 @@ namespace Nz
inline float GetLineHeight() const; inline float GetLineHeight() const;
inline float GetLineSpacingOffset() const; inline float GetLineSpacingOffset() const;
float GetMaxLineWidth() const override; float GetMaxLineWidth() const override;
inline const Color& GetOutlineColor() const;
inline float GetOutlineThickness() const;
inline TextStyleFlags GetStyle() const;
inline const std::string& GetText() const; inline const std::string& GetText() const;
inline const Color& GetTextColor() const;
inline const std::shared_ptr<Font>& GetTextFont() const;
inline const Color& GetTextOutlineColor() const;
inline float GetTextOutlineThickness() const;
inline TextStyleFlags GetTextStyle() const;
inline void SetCharacterSpacingOffset(float offset); inline void SetCharacterSpacingOffset(float offset);
inline void SetCharacterSize(unsigned int characterSize); inline void SetCharacterSize(unsigned int characterSize);
inline void SetColor(const Color& color);
inline void SetFont(std::shared_ptr<Font> font);
inline void SetLineSpacingOffset(float offset); inline void SetLineSpacingOffset(float offset);
inline void SetMaxLineWidth(float lineWidth) override; inline void SetMaxLineWidth(float lineWidth) override;
inline void SetOutlineColor(const Color& color);
inline void SetOutlineThickness(float thickness);
inline void SetStyle(TextStyleFlags style);
inline void SetText(std::string str); inline void SetText(std::string str);
inline void SetTextColor(const Color& color);
inline void SetTextFont(std::shared_ptr<Font> font);
inline void SetTextOutlineColor(const Color& color);
inline void SetTextOutlineThickness(float thickness);
inline void SetTextStyle(TextStyleFlags style);
inline SimpleTextDrawer& operator=(const SimpleTextDrawer& drawer); inline SimpleTextDrawer& operator=(const SimpleTextDrawer& drawer);
inline SimpleTextDrawer& operator=(SimpleTextDrawer&& drawer) noexcept; inline SimpleTextDrawer& operator=(SimpleTextDrawer&& drawer) noexcept;
static inline SimpleTextDrawer Draw(const std::string& str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White()); static inline SimpleTextDrawer Draw(std::string str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White());
static inline SimpleTextDrawer Draw(const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor); static inline SimpleTextDrawer Draw(std::string str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor);
static inline SimpleTextDrawer Draw(const std::shared_ptr<Font>& font, const std::string& str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White()); static inline SimpleTextDrawer Draw(const std::shared_ptr<Font>& font, std::string str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White());
static inline SimpleTextDrawer Draw(const std::shared_ptr<Font>& font, const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor); static inline SimpleTextDrawer Draw(const std::shared_ptr<Font>& font, std::string str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor);
private: private:
inline void AppendNewLine() const; inline void AppendNewLine() const;

View File

@ -18,7 +18,7 @@ namespace Nz
m_outlineThickness(0.f), m_outlineThickness(0.f),
m_characterSize(24) m_characterSize(24)
{ {
SetFont(Font::GetDefault()); SetTextFont(Font::GetDefault());
} }
inline SimpleTextDrawer::SimpleTextDrawer(const SimpleTextDrawer& drawer) : inline SimpleTextDrawer::SimpleTextDrawer(const SimpleTextDrawer& drawer) :
@ -34,7 +34,7 @@ namespace Nz
m_outlineThickness(drawer.m_outlineThickness), m_outlineThickness(drawer.m_outlineThickness),
m_characterSize(drawer.m_characterSize) m_characterSize(drawer.m_characterSize)
{ {
SetFont(drawer.m_font); SetTextFont(drawer.m_font);
} }
inline SimpleTextDrawer::SimpleTextDrawer(SimpleTextDrawer&& drawer) noexcept inline SimpleTextDrawer::SimpleTextDrawer(SimpleTextDrawer&& drawer) noexcept
@ -59,16 +59,6 @@ namespace Nz
return m_characterSize; return m_characterSize;
} }
inline const Color& SimpleTextDrawer::GetColor() const
{
return m_color;
}
inline const std::shared_ptr<Font>& SimpleTextDrawer::GetFont() const
{
return m_font;
}
inline float SimpleTextDrawer::GetLineHeight() const inline float SimpleTextDrawer::GetLineHeight() const
{ {
NazaraAssert(m_font, "SimpleTextDrawer has no font"); NazaraAssert(m_font, "SimpleTextDrawer has no font");
@ -80,26 +70,36 @@ namespace Nz
return m_lineSpacingOffset; return m_lineSpacingOffset;
} }
inline const Color& SimpleTextDrawer::GetOutlineColor() const inline const std::string& SimpleTextDrawer::GetText() const
{
return m_text;
}
inline const Color& SimpleTextDrawer::GetTextColor() const
{
return m_color;
}
inline const std::shared_ptr<Font>& SimpleTextDrawer::GetTextFont() const
{
return m_font;
}
inline const Color& SimpleTextDrawer::GetTextOutlineColor() const
{ {
return m_outlineColor; return m_outlineColor;
} }
inline float SimpleTextDrawer::GetOutlineThickness() const inline float SimpleTextDrawer::GetTextOutlineThickness() const
{ {
return m_outlineThickness; return m_outlineThickness;
} }
inline TextStyleFlags SimpleTextDrawer::GetStyle() const inline TextStyleFlags SimpleTextDrawer::GetTextStyle() const
{ {
return m_style; return m_style;
} }
inline const std::string& SimpleTextDrawer::GetText() const
{
return m_text;
}
inline void SimpleTextDrawer::SetCharacterSpacingOffset(float offset) inline void SimpleTextDrawer::SetCharacterSpacingOffset(float offset)
{ {
if (m_characterSpacingOffset != offset) if (m_characterSpacingOffset != offset)
@ -120,31 +120,6 @@ namespace Nz
} }
} }
inline void SimpleTextDrawer::SetColor(const Color& color)
{
if (m_color != color)
{
m_color = color;
InvalidateColor();
}
}
inline void SimpleTextDrawer::SetFont(std::shared_ptr<Font> font)
{
if (m_font != font)
{
m_font = std::move(font);
if (m_font)
ConnectFontSlots();
else
DisconnectFontSlots();
InvalidateGlyphs();
}
}
inline void SimpleTextDrawer::SetLineSpacingOffset(float offset) inline void SimpleTextDrawer::SetLineSpacingOffset(float offset)
{ {
if (m_lineSpacingOffset != offset) if (m_lineSpacingOffset != offset)
@ -167,7 +142,42 @@ namespace Nz
} }
} }
inline void SimpleTextDrawer::SetOutlineColor(const Color& color) inline void SimpleTextDrawer::SetText(std::string str)
{
if (m_text != str)
{
m_text = std::move(str);
InvalidateGlyphs();
}
}
inline void SimpleTextDrawer::SetTextColor(const Color& color)
{
if (m_color != color)
{
m_color = color;
InvalidateColor();
}
}
inline void SimpleTextDrawer::SetTextFont(std::shared_ptr<Font> font)
{
if (m_font != font)
{
m_font = std::move(font);
if (m_font)
ConnectFontSlots();
else
DisconnectFontSlots();
InvalidateGlyphs();
}
}
inline void SimpleTextDrawer::SetTextOutlineColor(const Color& color)
{ {
if (m_outlineColor != color) if (m_outlineColor != color)
{ {
@ -177,7 +187,7 @@ namespace Nz
} }
} }
inline void SimpleTextDrawer::SetOutlineThickness(float thickness) inline void SimpleTextDrawer::SetTextOutlineThickness(float thickness)
{ {
if (m_outlineThickness != thickness) if (m_outlineThickness != thickness)
{ {
@ -189,7 +199,7 @@ namespace Nz
} }
} }
inline void SimpleTextDrawer::SetStyle(TextStyleFlags style) inline void SimpleTextDrawer::SetTextStyle(TextStyleFlags style)
{ {
if (m_style != style) if (m_style != style)
{ {
@ -199,16 +209,6 @@ namespace Nz
} }
} }
inline void SimpleTextDrawer::SetText(std::string str)
{
if (m_text != str)
{
m_text = std::move(str);
InvalidateGlyphs();
}
}
inline SimpleTextDrawer& SimpleTextDrawer::operator=(const SimpleTextDrawer& drawer) inline SimpleTextDrawer& SimpleTextDrawer::operator=(const SimpleTextDrawer& drawer)
{ {
m_characterSize = drawer.m_characterSize; m_characterSize = drawer.m_characterSize;
@ -221,7 +221,7 @@ namespace Nz
m_style = drawer.m_style; m_style = drawer.m_style;
m_text = drawer.m_text; m_text = drawer.m_text;
SetFont(drawer.m_font); SetTextFont(drawer.m_font);
InvalidateGlyphs(); InvalidateGlyphs();
return *this; return *this;
@ -256,52 +256,52 @@ namespace Nz
return *this; return *this;
} }
inline SimpleTextDrawer SimpleTextDrawer::Draw(const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color) inline SimpleTextDrawer SimpleTextDrawer::Draw(std::string str, unsigned int characterSize, TextStyleFlags style, const Color& color)
{ {
SimpleTextDrawer drawer; SimpleTextDrawer drawer;
drawer.SetCharacterSize(characterSize); drawer.SetCharacterSize(characterSize);
drawer.SetColor(color); drawer.SetTextColor(color);
drawer.SetStyle(style); drawer.SetTextStyle(style);
drawer.SetText(str); drawer.SetText(std::move(str));
return drawer; return drawer;
} }
inline SimpleTextDrawer SimpleTextDrawer::Draw(const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor) inline SimpleTextDrawer SimpleTextDrawer::Draw(std::string str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor)
{ {
SimpleTextDrawer drawer; SimpleTextDrawer drawer;
drawer.SetCharacterSize(characterSize); drawer.SetCharacterSize(characterSize);
drawer.SetColor(color); drawer.SetTextColor(color);
drawer.SetOutlineColor(outlineColor); drawer.SetTextOutlineColor(outlineColor);
drawer.SetOutlineThickness(outlineThickness); drawer.SetTextOutlineThickness(outlineThickness);
drawer.SetStyle(style); drawer.SetTextStyle(style);
drawer.SetText(str); drawer.SetText(std::move(str));
return drawer; return drawer;
} }
inline SimpleTextDrawer SimpleTextDrawer::Draw(const std::shared_ptr<Font>& font, const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color) inline SimpleTextDrawer SimpleTextDrawer::Draw(const std::shared_ptr<Font>& font, std::string str, unsigned int characterSize, TextStyleFlags style, const Color& color)
{ {
SimpleTextDrawer drawer; SimpleTextDrawer drawer;
drawer.SetCharacterSize(characterSize); drawer.SetCharacterSize(characterSize);
drawer.SetColor(color); drawer.SetTextColor(color);
drawer.SetFont(font); drawer.SetTextFont(font);
drawer.SetStyle(style); drawer.SetTextStyle(style);
drawer.SetText(str); drawer.SetText(std::move(str));
return drawer; return drawer;
} }
inline SimpleTextDrawer SimpleTextDrawer::Draw(const std::shared_ptr<Font>& font, const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor) inline SimpleTextDrawer SimpleTextDrawer::Draw(const std::shared_ptr<Font>& font, std::string str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor)
{ {
SimpleTextDrawer drawer; SimpleTextDrawer drawer;
drawer.SetCharacterSize(characterSize); drawer.SetCharacterSize(characterSize);
drawer.SetColor(color); drawer.SetTextColor(color);
drawer.SetFont(font); drawer.SetTextFont(font);
drawer.SetOutlineColor(outlineColor); drawer.SetTextOutlineColor(outlineColor);
drawer.SetOutlineThickness(outlineThickness); drawer.SetTextOutlineThickness(outlineThickness);
drawer.SetStyle(style); drawer.SetTextStyle(style);
drawer.SetText(str); drawer.SetText(std::move(str));
return drawer; return drawer;
} }

View File

@ -64,9 +64,9 @@ namespace Nz
inline void SetReadOnly(bool readOnly = true); inline void SetReadOnly(bool readOnly = true);
inline void SetSelection(Vector2ui fromPosition, Vector2ui toPosition); inline void SetSelection(Vector2ui fromPosition, Vector2ui toPosition);
inline void Write(const std::string& text); inline void Write(std::string_view text);
inline void Write(const std::string& text, const Vector2ui& glyphPosition); inline void Write(std::string_view text, const Vector2ui& glyphPosition);
virtual void Write(const std::string& text, std::size_t glyphPosition) = 0; virtual void Write(std::string_view text, std::size_t glyphPosition) = 0;
AbstractTextAreaWidget& operator=(const AbstractTextAreaWidget&) = delete; AbstractTextAreaWidget& operator=(const AbstractTextAreaWidget&) = delete;
AbstractTextAreaWidget& operator=(AbstractTextAreaWidget&&) = delete; AbstractTextAreaWidget& operator=(AbstractTextAreaWidget&&) = delete;

View File

@ -231,12 +231,12 @@ namespace Nz
} }
} }
inline void AbstractTextAreaWidget::Write(const std::string& text) inline void AbstractTextAreaWidget::Write(std::string_view text)
{ {
Write(text, GetGlyphIndex(m_cursorPositionBegin)); Write(text, GetGlyphIndex(m_cursorPositionBegin));
} }
inline void AbstractTextAreaWidget::Write(const std::string& text, const Vector2ui& glyphPosition) inline void AbstractTextAreaWidget::Write(std::string_view text, const Vector2ui& glyphPosition)
{ {
Write(text, GetGlyphIndex(glyphPosition)); Write(text, GetGlyphIndex(glyphPosition));
} }

View File

@ -20,7 +20,7 @@ namespace Nz
RichTextAreaWidget(RichTextAreaWidget&&) = delete; RichTextAreaWidget(RichTextAreaWidget&&) = delete;
~RichTextAreaWidget() = default; ~RichTextAreaWidget() = default;
void AppendText(const std::string& text); void AppendText(std::string_view text);
void Clear() override; void Clear() override;
@ -44,7 +44,7 @@ namespace Nz
inline void SetTextOutlineThickness(float thickness); inline void SetTextOutlineThickness(float thickness);
inline void SetTextStyle(TextStyleFlags style); inline void SetTextStyle(TextStyleFlags style);
void Write(const std::string& text, std::size_t glyphPosition) override; void Write(std::string_view text, std::size_t glyphPosition) override;
RichTextAreaWidget& operator=(const RichTextAreaWidget&) = delete; RichTextAreaWidget& operator=(const RichTextAreaWidget&) = delete;
RichTextAreaWidget& operator=(RichTextAreaWidget&&) = delete; RichTextAreaWidget& operator=(RichTextAreaWidget&&) = delete;

View File

@ -8,82 +8,82 @@ namespace Nz
{ {
inline unsigned int RichTextAreaWidget::GetCharacterSize() const inline unsigned int RichTextAreaWidget::GetCharacterSize() const
{ {
return m_drawer.GetDefaultCharacterSize(); return m_drawer.GetCharacterSize();
} }
inline float RichTextAreaWidget::GetCharacterSpacingOffset() const inline float RichTextAreaWidget::GetCharacterSpacingOffset() const
{ {
return m_drawer.GetDefaultCharacterSpacingOffset(); return m_drawer.GetCharacterSpacingOffset();
} }
inline float RichTextAreaWidget::GetLineSpacingOffset() const inline float RichTextAreaWidget::GetLineSpacingOffset() const
{ {
return m_drawer.GetDefaultLineSpacingOffset(); return m_drawer.GetLineSpacingOffset();
} }
inline const Color& RichTextAreaWidget::GetTextColor() const inline const Color& RichTextAreaWidget::GetTextColor() const
{ {
return m_drawer.GetDefaultColor(); return m_drawer.GetTextColor();
} }
inline const std::shared_ptr<Font>& RichTextAreaWidget::GetTextFont() const inline const std::shared_ptr<Font>& RichTextAreaWidget::GetTextFont() const
{ {
return m_drawer.GetDefaultFont(); return m_drawer.GetTextFont();
} }
inline const Color& RichTextAreaWidget::GetTextOutlineColor() const inline const Color& RichTextAreaWidget::GetTextOutlineColor() const
{ {
return m_drawer.GetDefaultOutlineColor(); return m_drawer.GetTextOutlineColor();
} }
inline float RichTextAreaWidget::GetTextOutlineThickness() const inline float RichTextAreaWidget::GetTextOutlineThickness() const
{ {
return m_drawer.GetDefaultOutlineThickness(); return m_drawer.GetTextOutlineThickness();
} }
inline TextStyleFlags RichTextAreaWidget::GetTextStyle() const inline TextStyleFlags RichTextAreaWidget::GetTextStyle() const
{ {
return m_drawer.GetDefaultStyle(); return m_drawer.GetTextStyle();
} }
inline void RichTextAreaWidget::SetCharacterSize(unsigned int characterSize) inline void RichTextAreaWidget::SetCharacterSize(unsigned int characterSize)
{ {
m_drawer.SetDefaultCharacterSize(characterSize); m_drawer.SetCharacterSize(characterSize);
} }
inline void RichTextAreaWidget::SetCharacterSpacingOffset(float offset) inline void RichTextAreaWidget::SetCharacterSpacingOffset(float offset)
{ {
m_drawer.SetDefaultCharacterSpacingOffset(offset); m_drawer.SetCharacterSpacingOffset(offset);
} }
inline void RichTextAreaWidget::SetLineSpacingOffset(float offset) inline void RichTextAreaWidget::SetLineSpacingOffset(float offset)
{ {
m_drawer.SetDefaultLineSpacingOffset(offset); m_drawer.SetLineSpacingOffset(offset);
} }
inline void RichTextAreaWidget::SetTextColor(const Color& color) inline void RichTextAreaWidget::SetTextColor(const Color& color)
{ {
m_drawer.SetDefaultColor(color); m_drawer.SetTextColor(color);
} }
inline void RichTextAreaWidget::SetTextFont(std::shared_ptr<Font> font) inline void RichTextAreaWidget::SetTextFont(std::shared_ptr<Font> font)
{ {
m_drawer.SetDefaultFont(std::move(font)); m_drawer.SetTextFont(std::move(font));
} }
inline void RichTextAreaWidget::SetTextOutlineColor(const Color& color) inline void RichTextAreaWidget::SetTextOutlineColor(const Color& color)
{ {
m_drawer.SetDefaultOutlineColor(color); m_drawer.SetTextOutlineColor(color);
} }
inline void RichTextAreaWidget::SetTextOutlineThickness(float thickness) inline void RichTextAreaWidget::SetTextOutlineThickness(float thickness)
{ {
m_drawer.SetDefaultOutlineThickness(thickness); m_drawer.SetTextOutlineThickness(thickness);
} }
inline void RichTextAreaWidget::SetTextStyle(TextStyleFlags style) inline void RichTextAreaWidget::SetTextStyle(TextStyleFlags style)
{ {
m_drawer.SetDefaultStyle(style); m_drawer.SetTextStyle(style);
} }
} }

View File

@ -20,7 +20,7 @@ namespace Nz
TextAreaWidget(TextAreaWidget&&) = delete; TextAreaWidget(TextAreaWidget&&) = delete;
~TextAreaWidget() = default; ~TextAreaWidget() = default;
void AppendText(const std::string& text); void AppendText(std::string_view text);
void Clear() override; void Clear() override;
@ -49,7 +49,7 @@ namespace Nz
inline void SetTextStyle(TextStyleFlags style); inline void SetTextStyle(TextStyleFlags style);
using AbstractTextAreaWidget::Write; using AbstractTextAreaWidget::Write;
void Write(const std::string& text, std::size_t glyphPosition) override; void Write(std::string_view text, std::size_t glyphPosition) override;
TextAreaWidget& operator=(const TextAreaWidget&) = delete; TextAreaWidget& operator=(const TextAreaWidget&) = delete;
TextAreaWidget& operator=(TextAreaWidget&&) = delete; TextAreaWidget& operator=(TextAreaWidget&&) = delete;

View File

@ -33,27 +33,27 @@ namespace Nz
inline const Color& TextAreaWidget::GetTextColor() const inline const Color& TextAreaWidget::GetTextColor() const
{ {
return m_drawer.GetColor(); return m_drawer.GetTextColor();
} }
inline const std::shared_ptr<Font>& TextAreaWidget::GetTextFont() const inline const std::shared_ptr<Font>& TextAreaWidget::GetTextFont() const
{ {
return m_drawer.GetFont(); return m_drawer.GetTextFont();
} }
inline const Color& TextAreaWidget::GetTextOulineColor() const inline const Color& TextAreaWidget::GetTextOulineColor() const
{ {
return m_drawer.GetOutlineColor(); return m_drawer.GetTextOutlineColor();
} }
inline float TextAreaWidget::GetTextOulineThickness() const inline float TextAreaWidget::GetTextOulineThickness() const
{ {
return m_drawer.GetOutlineThickness(); return m_drawer.GetTextOutlineThickness();
} }
inline TextStyleFlags TextAreaWidget::GetTextStyle() const inline TextStyleFlags TextAreaWidget::GetTextStyle() const
{ {
return m_drawer.GetStyle(); return m_drawer.GetTextStyle();
} }
inline void TextAreaWidget::SetCharacterSize(unsigned int characterSize) inline void TextAreaWidget::SetCharacterSize(unsigned int characterSize)
@ -89,35 +89,35 @@ namespace Nz
inline void TextAreaWidget::SetTextColor(const Color& text) inline void TextAreaWidget::SetTextColor(const Color& text)
{ {
m_drawer.SetColor(text); m_drawer.SetTextColor(text);
UpdateDisplayText(); UpdateDisplayText();
} }
inline void TextAreaWidget::SetTextFont(std::shared_ptr<Font> font) inline void TextAreaWidget::SetTextFont(std::shared_ptr<Font> font)
{ {
m_drawer.SetFont(std::move(font)); m_drawer.SetTextFont(std::move(font));
UpdateDisplayText(); UpdateDisplayText();
} }
inline void TextAreaWidget::SetTextOutlineColor(const Color& color) inline void TextAreaWidget::SetTextOutlineColor(const Color& color)
{ {
m_drawer.SetOutlineColor(color); m_drawer.SetTextOutlineColor(color);
UpdateDisplayText(); UpdateDisplayText();
} }
inline void TextAreaWidget::SetTextOutlineThickness(float thickness) inline void TextAreaWidget::SetTextOutlineThickness(float thickness)
{ {
m_drawer.SetOutlineThickness(thickness); m_drawer.SetTextOutlineThickness(thickness);
UpdateDisplayText(); UpdateDisplayText();
} }
inline void TextAreaWidget::SetTextStyle(TextStyleFlags style) inline void TextAreaWidget::SetTextStyle(TextStyleFlags style)
{ {
m_drawer.SetStyle(style); m_drawer.SetTextStyle(style);
UpdateDisplayText(); UpdateDisplayText();
} }

View File

@ -10,31 +10,31 @@
namespace Nz namespace Nz
{ {
RichTextDrawer::RichTextDrawer() : RichTextDrawer::RichTextDrawer() :
m_defaultColor(Color::White()), m_currentColor(Color::White()),
m_defaultOutlineColor(Color::Black()), m_currentOutlineColor(Color::Black()),
m_defaultStyle(TextStyle_Regular), m_currentStyle(TextStyle_Regular),
m_glyphUpdated(false), m_glyphUpdated(false),
m_defaultCharacterSpacingOffset(0.f), m_currentCharacterSpacingOffset(0.f),
m_defaultLineSpacingOffset(0.f), m_currentLineSpacingOffset(0.f),
m_defaultOutlineThickness(0.f), m_currentOutlineThickness(0.f),
m_maxLineWidth(std::numeric_limits<float>::infinity()), m_maxLineWidth(std::numeric_limits<float>::infinity()),
m_defaultCharacterSize(24) m_currentCharacterSize(24)
{ {
SetDefaultFont(Font::GetDefault()); SetTextFont(Font::GetDefault());
} }
RichTextDrawer::RichTextDrawer(const RichTextDrawer& drawer) : RichTextDrawer::RichTextDrawer(const RichTextDrawer& drawer) :
m_defaultColor(drawer.m_defaultColor), m_currentColor(drawer.m_currentColor),
m_defaultOutlineColor(drawer.m_defaultOutlineColor), m_currentOutlineColor(drawer.m_currentOutlineColor),
m_defaultStyle(drawer.m_defaultStyle), m_currentStyle(drawer.m_currentStyle),
m_fontIndexes(drawer.m_fontIndexes), m_fontIndexes(drawer.m_fontIndexes),
m_blocks(drawer.m_blocks), m_blocks(drawer.m_blocks),
m_glyphUpdated(false), m_glyphUpdated(false),
m_defaultCharacterSpacingOffset(drawer.m_defaultCharacterSpacingOffset), m_currentCharacterSpacingOffset(drawer.m_currentCharacterSpacingOffset),
m_defaultLineSpacingOffset(drawer.m_defaultLineSpacingOffset), m_currentLineSpacingOffset(drawer.m_currentLineSpacingOffset),
m_defaultOutlineThickness(drawer.m_defaultOutlineThickness), m_currentOutlineThickness(drawer.m_currentOutlineThickness),
m_maxLineWidth(drawer.m_maxLineWidth), m_maxLineWidth(drawer.m_maxLineWidth),
m_defaultCharacterSize(drawer.m_defaultCharacterSize) m_currentCharacterSize(drawer.m_currentCharacterSize)
{ {
m_fonts.resize(drawer.m_fonts.size()); m_fonts.resize(drawer.m_fonts.size());
for (std::size_t i = 0; i < m_fonts.size(); ++i) for (std::size_t i = 0; i < m_fonts.size(); ++i)
@ -43,38 +43,38 @@ namespace Nz
m_fonts[i].useCount = drawer.m_fonts[i].useCount; m_fonts[i].useCount = drawer.m_fonts[i].useCount;
} }
SetDefaultFont(drawer.m_defaultFont); SetTextFont(drawer.m_currentFont);
ConnectFontSlots(); ConnectFontSlots();
} }
RichTextDrawer::RichTextDrawer(RichTextDrawer&& drawer) RichTextDrawer::RichTextDrawer(RichTextDrawer&& drawer) noexcept
{ {
operator=(std::move(drawer)); operator=(std::move(drawer));
} }
RichTextDrawer::~RichTextDrawer() = default; RichTextDrawer::~RichTextDrawer() = default;
auto RichTextDrawer::AppendText(const std::string& str, bool forceNewBlock) -> BlockRef auto RichTextDrawer::AppendText(std::string_view str, bool forceNewBlock) -> BlockRef
{ {
NazaraAssert(!str.empty(), "String cannot be empty"); NazaraAssert(!str.empty(), "String cannot be empty");
std::size_t defaultFontIndex = HandleFontAddition(m_defaultFont); std::size_t currentFontIndex = HandleFontAddition(m_currentFont);
auto HasDefaultProperties = [&](const Block& block) auto DoPropertiesMatch = [&](const Block& block)
{ {
return block.characterSize == m_defaultCharacterSize && return block.characterSize == m_currentCharacterSize &&
block.color == m_defaultColor && block.color == m_currentColor &&
block.fontIndex == defaultFontIndex && block.fontIndex == currentFontIndex &&
block.characterSpacingOffset == m_defaultCharacterSpacingOffset && block.characterSpacingOffset == m_currentCharacterSpacingOffset &&
block.lineSpacingOffset == m_defaultLineSpacingOffset && block.lineSpacingOffset == m_currentLineSpacingOffset &&
block.outlineColor == m_defaultOutlineColor && block.outlineColor == m_currentOutlineColor &&
block.outlineThickness == m_defaultOutlineThickness && block.outlineThickness == m_currentOutlineThickness &&
block.style == m_defaultStyle; block.style == m_currentStyle;
}; };
// Check if last block has the same property as default, else create a new block // Check if last block has the same properties as previous block, else create a new block
if (forceNewBlock || m_blocks.empty() || !HasDefaultProperties(m_blocks.back())) if (forceNewBlock || m_blocks.empty() || !DoPropertiesMatch(m_blocks.back()))
{ {
std::size_t glyphIndex; std::size_t glyphIndex;
if (!m_blocks.empty()) if (!m_blocks.empty())
@ -87,15 +87,15 @@ namespace Nz
m_blocks.emplace_back(); m_blocks.emplace_back();
Block& newBlock = m_blocks.back(); Block& newBlock = m_blocks.back();
newBlock.characterSize = m_defaultCharacterSize; newBlock.characterSize = m_currentCharacterSize;
newBlock.characterSpacingOffset = m_defaultCharacterSpacingOffset; newBlock.characterSpacingOffset = m_currentCharacterSpacingOffset;
newBlock.color = m_defaultColor; newBlock.color = m_currentColor;
newBlock.fontIndex = defaultFontIndex; newBlock.fontIndex = currentFontIndex;
newBlock.glyphIndex = glyphIndex; newBlock.glyphIndex = glyphIndex;
newBlock.lineSpacingOffset = m_defaultLineSpacingOffset; newBlock.lineSpacingOffset = m_currentLineSpacingOffset;
newBlock.outlineColor = m_defaultOutlineColor; newBlock.outlineColor = m_currentOutlineColor;
newBlock.outlineThickness = m_defaultOutlineThickness; newBlock.outlineThickness = m_currentOutlineThickness;
newBlock.style = m_defaultStyle; newBlock.style = m_currentStyle;
newBlock.text = str; newBlock.text = str;
assert(newBlock.fontIndex < m_fonts.size()); assert(newBlock.fontIndex < m_fonts.size());
@ -235,14 +235,14 @@ namespace Nz
DisconnectFontSlots(); DisconnectFontSlots();
m_blocks = drawer.m_blocks; m_blocks = drawer.m_blocks;
m_defaultCharacterSize = drawer.m_defaultCharacterSize; m_currentCharacterSize = drawer.m_currentCharacterSize;
m_defaultCharacterSpacingOffset = drawer.m_defaultCharacterSpacingOffset; m_currentCharacterSpacingOffset = drawer.m_currentCharacterSpacingOffset;
m_defaultColor = drawer.m_defaultColor; m_currentColor = drawer.m_currentColor;
m_defaultFont = drawer.m_defaultFont; m_currentFont = drawer.m_currentFont;
m_defaultLineSpacingOffset = drawer.m_defaultLineSpacingOffset; m_currentLineSpacingOffset = drawer.m_currentLineSpacingOffset;
m_defaultOutlineColor = drawer.m_defaultOutlineColor; m_currentOutlineColor = drawer.m_currentOutlineColor;
m_defaultOutlineThickness = drawer.m_defaultOutlineThickness; m_currentOutlineThickness = drawer.m_currentOutlineThickness;
m_defaultStyle = drawer.m_defaultStyle; m_currentStyle = drawer.m_currentStyle;
m_fontIndexes = drawer.m_fontIndexes; m_fontIndexes = drawer.m_fontIndexes;
m_fonts.resize(drawer.m_fonts.size()); m_fonts.resize(drawer.m_fonts.size());
@ -258,20 +258,20 @@ namespace Nz
return *this; return *this;
} }
RichTextDrawer& RichTextDrawer::operator=(RichTextDrawer&& drawer) RichTextDrawer& RichTextDrawer::operator=(RichTextDrawer&& drawer) noexcept
{ {
DisconnectFontSlots(); DisconnectFontSlots();
m_blocks = std::move(drawer.m_blocks); m_blocks = std::move(drawer.m_blocks);
m_bounds = std::move(drawer.m_bounds); m_bounds = std::move(drawer.m_bounds);
m_defaultCharacterSize = std::move(drawer.m_defaultCharacterSize); m_currentCharacterSize = std::move(drawer.m_currentCharacterSize);
m_defaultCharacterSpacingOffset = std::move(drawer.m_defaultCharacterSpacingOffset); m_currentCharacterSpacingOffset = std::move(drawer.m_currentCharacterSpacingOffset);
m_defaultColor = std::move(drawer.m_defaultColor); m_currentColor = std::move(drawer.m_currentColor);
m_defaultFont = std::move(drawer.m_defaultFont); m_currentFont = std::move(drawer.m_currentFont);
m_defaultLineSpacingOffset = std::move(drawer.m_defaultLineSpacingOffset); m_currentLineSpacingOffset = std::move(drawer.m_currentLineSpacingOffset);
m_defaultOutlineColor = std::move(drawer.m_defaultOutlineColor); m_currentOutlineColor = std::move(drawer.m_currentOutlineColor);
m_defaultOutlineThickness = std::move(drawer.m_defaultOutlineThickness); m_currentOutlineThickness = std::move(drawer.m_currentOutlineThickness);
m_defaultStyle = std::move(drawer.m_defaultStyle); m_currentStyle = std::move(drawer.m_currentStyle);
m_drawPos = std::move(drawer.m_drawPos); m_drawPos = std::move(drawer.m_drawPos);
m_fontIndexes = std::move(drawer.m_fontIndexes); m_fontIndexes = std::move(drawer.m_fontIndexes);
m_fonts = std::move(drawer.m_fonts); m_fonts = std::move(drawer.m_fonts);
@ -545,7 +545,7 @@ namespace Nz
} }
#endif #endif
//SetFont(nullptr); //SetTextFont(nullptr);
} }
void RichTextDrawer::UpdateGlyphs() const void RichTextDrawer::UpdateGlyphs() const

View File

@ -23,12 +23,10 @@ namespace Nz
return m_bounds; return m_bounds;
} }
const std::shared_ptr<Font>& SimpleTextDrawer::GetFont(std::size_t index) const const std::shared_ptr<Font>& SimpleTextDrawer::GetFont([[maybe_unused]] std::size_t index) const
{ {
NazaraAssert(index == 0, "Font index out of range"); NazaraAssert(index == 0, "font index out of range");
NazaraUnused(index); return GetTextFont();
return GetFont();
} }
std::size_t SimpleTextDrawer::GetFontCount() const std::size_t SimpleTextDrawer::GetFontCount() const
@ -333,6 +331,6 @@ namespace Nz
} }
#endif #endif
SetFont(nullptr); SetTextFont(nullptr);
} }
} }

View File

@ -13,7 +13,7 @@ namespace Nz
Layout(); Layout();
} }
void RichTextAreaWidget::AppendText(const std::string& text) void RichTextAreaWidget::AppendText(std::string_view text)
{ {
//m_text += text; //m_text += text;
switch (m_echoMode) switch (m_echoMode)
@ -132,7 +132,7 @@ namespace Nz
UpdateDisplayText(); UpdateDisplayText();
} }
void RichTextAreaWidget::Write(const std::string& text, std::size_t glyphPosition) void RichTextAreaWidget::Write(std::string_view text, std::size_t glyphPosition)
{ {
if (m_drawer.HasBlocks()) if (m_drawer.HasBlocks())
{ {

View File

@ -39,7 +39,7 @@ namespace Nz
Layout(); Layout();
} }
void TextAreaWidget::AppendText(const std::string& text) void TextAreaWidget::AppendText(std::string_view text)
{ {
m_text += text; m_text += text;
@ -113,7 +113,7 @@ namespace Nz
SetText(newText); SetText(newText);
} }
void TextAreaWidget::Write(const std::string& text, std::size_t glyphPosition) void TextAreaWidget::Write(std::string_view text, std::size_t glyphPosition)
{ {
if (glyphPosition >= m_drawer.GetGlyphCount()) if (glyphPosition >= m_drawer.GetGlyphCount())
{ {

View File

@ -53,9 +53,9 @@ int main()
auto UpdatePresentModeText = [&] auto UpdatePresentModeText = [&]
{ {
Nz::RichTextDrawer textDrawer; Nz::RichTextDrawer textDrawer;
textDrawer.SetDefaultStyle(Nz::TextStyle::Bold); textDrawer.SetTextStyle(Nz::TextStyle::Bold);
textDrawer.AppendText("Supported present modes:\n"); textDrawer.AppendText("Supported present modes:\n");
textDrawer.SetDefaultStyle(Nz::TextStyle_Regular); textDrawer.SetTextStyle(Nz::TextStyle_Regular);
textDrawer.AppendText("Use +/- to switch present mode (and * to limit FPS to 50)\n"); textDrawer.AppendText("Use +/- to switch present mode (and * to limit FPS to 50)\n");
for (Nz::PresentMode presentMode : supportedPresentModes) for (Nz::PresentMode presentMode : supportedPresentModes)
@ -63,9 +63,9 @@ int main()
textDrawer.AppendText("- "); textDrawer.AppendText("- ");
if (presentMode == swapchain.GetPresentMode()) if (presentMode == swapchain.GetPresentMode())
textDrawer.SetDefaultColor(Nz::Color::Yellow()); textDrawer.SetTextColor(Nz::Color::Yellow());
else else
textDrawer.SetDefaultColor(Nz::Color::White()); textDrawer.SetTextColor(Nz::Color::White());
switch (presentMode) switch (presentMode)
{ {
@ -76,11 +76,11 @@ int main()
} }
} }
textDrawer.SetDefaultColor(Nz::Color::White()); textDrawer.SetTextColor(Nz::Color::White());
textDrawer.AppendText("Use * to limit FPS to 50\n"); textDrawer.AppendText("Use * to limit FPS to 50\n");
if (limitFps) if (limitFps)
{ {
textDrawer.SetDefaultColor(Nz::Color::Red()); textDrawer.SetTextColor(Nz::Color::Red());
textDrawer.AppendText("FPS limited to 50\n"); textDrawer.AppendText("FPS limited to 50\n");
} }
else else