Rework TextDrawer interface
This commit is contained in:
@@ -23,10 +23,10 @@ namespace Nz
|
||||
|
||||
RichTextDrawer();
|
||||
RichTextDrawer(const RichTextDrawer& drawer);
|
||||
RichTextDrawer(RichTextDrawer&& drawer);
|
||||
RichTextDrawer(RichTextDrawer&& drawer) noexcept;
|
||||
~RichTextDrawer();
|
||||
|
||||
BlockRef AppendText(const std::string& str, bool forceNewBlock = false);
|
||||
BlockRef AppendText(std::string_view str, bool forceNewBlock = false);
|
||||
|
||||
void Clear() override;
|
||||
|
||||
@@ -38,7 +38,6 @@ namespace Nz
|
||||
inline std::size_t GetBlockCount() const;
|
||||
inline std::size_t GetBlockFirstGlyphIndex(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 const Color& GetBlockOutlineColor(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);
|
||||
const Rectf& GetBounds() const override;
|
||||
inline unsigned int GetDefaultCharacterSize() const;
|
||||
inline float GetDefaultCharacterSpacingOffset() const;
|
||||
inline const Color& GetDefaultColor() 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;
|
||||
inline unsigned int GetCharacterSize() const;
|
||||
inline float GetCharacterSpacingOffset() const;
|
||||
inline float GetLineSpacingOffset() const;
|
||||
const std::shared_ptr<Font>& GetFont(std::size_t index) const override;
|
||||
std::size_t GetFontCount() const override;
|
||||
const Glyph& GetGlyph(std::size_t index) const override;
|
||||
@@ -63,6 +57,12 @@ namespace Nz
|
||||
std::size_t GetLineCount() 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;
|
||||
|
||||
void MergeBlocks();
|
||||
@@ -79,22 +79,22 @@ namespace Nz
|
||||
inline void SetBlockStyle(std::size_t index, TextStyleFlags style);
|
||||
inline void SetBlockText(std::size_t index, std::string str);
|
||||
|
||||
inline void SetDefaultCharacterSize(unsigned int characterSize);
|
||||
inline void SetDefaultCharacterSpacingOffset(float offset);
|
||||
inline void SetDefaultColor(const Color& color);
|
||||
inline void SetDefaultFont(const std::shared_ptr<Font>& font);
|
||||
inline void SetDefaultLineSpacingOffset(float offset);
|
||||
inline void SetDefaultOutlineColor(const Color& color);
|
||||
inline void SetDefaultOutlineThickness(float thickness);
|
||||
inline void SetDefaultStyle(TextStyleFlags style);
|
||||
inline void SetCharacterSize(unsigned int characterSize);
|
||||
inline void SetCharacterSpacingOffset(float offset);
|
||||
inline void SetLineSpacingOffset(float offset);
|
||||
inline void SetTextColor(const Color& color);
|
||||
inline void SetTextFont(const std::shared_ptr<Font>& font);
|
||||
inline void SetTextOutlineColor(const Color& color);
|
||||
inline void SetTextOutlineThickness(float thickness);
|
||||
inline void SetTextStyle(TextStyleFlags style);
|
||||
|
||||
void SetMaxLineWidth(float lineWidth) override;
|
||||
|
||||
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();
|
||||
|
||||
|
||||
private:
|
||||
struct Block;
|
||||
|
||||
@@ -145,10 +145,10 @@ namespace Nz
|
||||
NazaraSlot(Font, OnFontRelease, fontReleaseSlot);
|
||||
};
|
||||
|
||||
Color m_defaultColor;
|
||||
Color m_defaultOutlineColor;
|
||||
TextStyleFlags m_defaultStyle;
|
||||
std::shared_ptr<Font> m_defaultFont;
|
||||
Color m_currentColor;
|
||||
Color m_currentOutlineColor;
|
||||
TextStyleFlags m_currentStyle;
|
||||
std::shared_ptr<Font> m_currentFont;
|
||||
mutable std::size_t m_lastSeparatorGlyph;
|
||||
std::unordered_map<std::shared_ptr<Font>, std::size_t> m_fontIndexes;
|
||||
std::vector<Block> m_blocks;
|
||||
@@ -158,11 +158,11 @@ 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_currentCharacterSpacingOffset;
|
||||
float m_currentLineSpacingOffset;
|
||||
float m_currentOutlineThickness;
|
||||
float m_maxLineWidth;
|
||||
unsigned int m_defaultCharacterSize;
|
||||
unsigned int m_currentCharacterSize;
|
||||
mutable float m_lastSeparatorPosition;
|
||||
};
|
||||
|
||||
|
||||
@@ -87,12 +87,6 @@ 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");
|
||||
@@ -123,44 +117,19 @@ namespace Nz
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
return m_currentLineSpacingOffset;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
return !m_blocks.empty();
|
||||
@@ -358,44 +352,44 @@ namespace Nz
|
||||
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()
|
||||
@@ -453,7 +447,7 @@ namespace Nz
|
||||
* Returns the font used for the characters of the referenced block
|
||||
* \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
|
||||
{
|
||||
@@ -464,7 +458,7 @@ namespace Nz
|
||||
* 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
|
||||
* \see GetTextColor, GetTextFont, GetStyle, GetText, SetCharacterSize
|
||||
*/
|
||||
inline float RichTextDrawer::BlockRef::GetLineSpacingOffset() const
|
||||
{
|
||||
@@ -475,7 +469,7 @@ namespace Nz
|
||||
* Returns the outline color used for the characters of the referenced block
|
||||
* \return The referenced block outline color
|
||||
*
|
||||
* \see GetCharacterSize, GetColor, GetStyle, GetText, SetFont
|
||||
* \see GetCharacterSize, GetTextColor, GetStyle, GetText, SetFont
|
||||
*/
|
||||
inline Color RichTextDrawer::BlockRef::GetOutlineColor() const
|
||||
{
|
||||
@@ -486,7 +480,7 @@ namespace Nz
|
||||
* Returns the outline thickness used for the characters of the referenced block
|
||||
* \return The referenced block outline thickness
|
||||
*
|
||||
* \see GetCharacterSize, GetColor, GetStyle, GetText, SetFont
|
||||
* \see GetCharacterSize, GetTextColor, GetStyle, GetText, SetFont
|
||||
*/
|
||||
inline float RichTextDrawer::BlockRef::GetOutlineThickness() const
|
||||
{
|
||||
@@ -497,7 +491,7 @@ namespace Nz
|
||||
* Returns the style flags used for the characters of the referenced block
|
||||
* \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
|
||||
{
|
||||
@@ -519,7 +513,7 @@ namespace Nz
|
||||
* Returns the text of the referenced block
|
||||
* \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
|
||||
{
|
||||
@@ -552,7 +546,7 @@ namespace Nz
|
||||
* Changes the color of the referenced block characters
|
||||
* \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)
|
||||
{
|
||||
@@ -563,7 +557,7 @@ namespace Nz
|
||||
* 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.
|
||||
*
|
||||
* \see GetCharacterSize, SetCharacterSize, SetColor, SetStyle, SetText
|
||||
* \see GetCharacterSize, SetCharacterSize, SetTextColor, SetStyle, SetText
|
||||
*/
|
||||
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
|
||||
* \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)
|
||||
{
|
||||
@@ -585,7 +579,7 @@ namespace Nz
|
||||
* 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.
|
||||
*
|
||||
* \see GetCharacterSize, SetCharacterSize, SetColor, SetStyle, SetText
|
||||
* \see GetCharacterSize, SetCharacterSize, SetTextColor, SetStyle, SetText
|
||||
*/
|
||||
inline void RichTextDrawer::BlockRef::SetOutlineColor(Color color)
|
||||
{
|
||||
@@ -596,7 +590,7 @@ namespace Nz
|
||||
* 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.
|
||||
*
|
||||
* \see GetCharacterSize, SetCharacterSize, SetColor, SetStyle, SetText
|
||||
* \see GetCharacterSize, SetCharacterSize, SetTextColor, SetStyle, SetText
|
||||
*/
|
||||
inline void RichTextDrawer::BlockRef::SetOutlineThickness(float thickness)
|
||||
{
|
||||
@@ -607,7 +601,7 @@ namespace Nz
|
||||
* 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.
|
||||
*
|
||||
* \see GetStyle, SetCharacterSize, SetColor, SetFont, SetText
|
||||
* \see GetStyle, SetCharacterSize, SetTextColor, SetTextFont, SetText
|
||||
*/
|
||||
inline void RichTextDrawer::BlockRef::SetStyle(TextStyleFlags style)
|
||||
{
|
||||
@@ -618,7 +612,7 @@ namespace Nz
|
||||
* 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.
|
||||
*
|
||||
* \see GetText, SetCharacterSize, SetColor, SetFont, SetStyle
|
||||
* \see GetText, SetCharacterSize, SetTextColor, SetTextFont, SetTextStyle
|
||||
*/
|
||||
inline void RichTextDrawer::BlockRef::SetText(std::string text)
|
||||
{
|
||||
@@ -627,3 +621,4 @@ namespace Nz
|
||||
}
|
||||
|
||||
#include <Nazara/Utility/DebugOff.hpp>
|
||||
#include "RichTextDrawer.hpp"
|
||||
|
||||
@@ -30,8 +30,6 @@ namespace Nz
|
||||
const Rectf& GetBounds() const override;
|
||||
inline float GetCharacterSpacingOffset() 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;
|
||||
std::size_t GetFontCount() const override;
|
||||
const Glyph& GetGlyph(std::size_t index) const override;
|
||||
@@ -41,29 +39,32 @@ namespace Nz
|
||||
inline float GetLineHeight() const;
|
||||
inline float GetLineSpacingOffset() const;
|
||||
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 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 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 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 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=(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(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, 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, 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 = TextStyle_Regular, const Color& color = Color::White());
|
||||
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, 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, const Color& color, float outlineThickness, const Color& outlineColor);
|
||||
|
||||
private:
|
||||
inline void AppendNewLine() const;
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Nz
|
||||
m_outlineThickness(0.f),
|
||||
m_characterSize(24)
|
||||
{
|
||||
SetFont(Font::GetDefault());
|
||||
SetTextFont(Font::GetDefault());
|
||||
}
|
||||
|
||||
inline SimpleTextDrawer::SimpleTextDrawer(const SimpleTextDrawer& drawer) :
|
||||
@@ -34,7 +34,7 @@ namespace Nz
|
||||
m_outlineThickness(drawer.m_outlineThickness),
|
||||
m_characterSize(drawer.m_characterSize)
|
||||
{
|
||||
SetFont(drawer.m_font);
|
||||
SetTextFont(drawer.m_font);
|
||||
}
|
||||
|
||||
inline SimpleTextDrawer::SimpleTextDrawer(SimpleTextDrawer&& drawer) noexcept
|
||||
@@ -59,16 +59,6 @@ namespace Nz
|
||||
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
|
||||
{
|
||||
NazaraAssert(m_font, "SimpleTextDrawer has no font");
|
||||
@@ -80,26 +70,36 @@ namespace Nz
|
||||
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;
|
||||
}
|
||||
|
||||
inline float SimpleTextDrawer::GetOutlineThickness() const
|
||||
inline float SimpleTextDrawer::GetTextOutlineThickness() const
|
||||
{
|
||||
return m_outlineThickness;
|
||||
}
|
||||
|
||||
inline TextStyleFlags SimpleTextDrawer::GetStyle() const
|
||||
inline TextStyleFlags SimpleTextDrawer::GetTextStyle() const
|
||||
{
|
||||
return m_style;
|
||||
}
|
||||
|
||||
inline const std::string& SimpleTextDrawer::GetText() const
|
||||
{
|
||||
return m_text;
|
||||
}
|
||||
|
||||
inline void SimpleTextDrawer::SetCharacterSpacingOffset(float 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
@@ -177,7 +187,7 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
inline void SimpleTextDrawer::SetOutlineThickness(float thickness)
|
||||
inline void SimpleTextDrawer::SetTextOutlineThickness(float 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)
|
||||
{
|
||||
@@ -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)
|
||||
{
|
||||
m_characterSize = drawer.m_characterSize;
|
||||
@@ -221,7 +221,7 @@ namespace Nz
|
||||
m_style = drawer.m_style;
|
||||
m_text = drawer.m_text;
|
||||
|
||||
SetFont(drawer.m_font);
|
||||
SetTextFont(drawer.m_font);
|
||||
InvalidateGlyphs();
|
||||
|
||||
return *this;
|
||||
@@ -256,52 +256,52 @@ namespace Nz
|
||||
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;
|
||||
drawer.SetCharacterSize(characterSize);
|
||||
drawer.SetColor(color);
|
||||
drawer.SetStyle(style);
|
||||
drawer.SetText(str);
|
||||
drawer.SetTextColor(color);
|
||||
drawer.SetTextStyle(style);
|
||||
drawer.SetText(std::move(str));
|
||||
|
||||
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;
|
||||
drawer.SetCharacterSize(characterSize);
|
||||
drawer.SetColor(color);
|
||||
drawer.SetOutlineColor(outlineColor);
|
||||
drawer.SetOutlineThickness(outlineThickness);
|
||||
drawer.SetStyle(style);
|
||||
drawer.SetText(str);
|
||||
drawer.SetTextColor(color);
|
||||
drawer.SetTextOutlineColor(outlineColor);
|
||||
drawer.SetTextOutlineThickness(outlineThickness);
|
||||
drawer.SetTextStyle(style);
|
||||
drawer.SetText(std::move(str));
|
||||
|
||||
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;
|
||||
drawer.SetCharacterSize(characterSize);
|
||||
drawer.SetColor(color);
|
||||
drawer.SetFont(font);
|
||||
drawer.SetStyle(style);
|
||||
drawer.SetText(str);
|
||||
drawer.SetTextColor(color);
|
||||
drawer.SetTextFont(font);
|
||||
drawer.SetTextStyle(style);
|
||||
drawer.SetText(std::move(str));
|
||||
|
||||
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;
|
||||
drawer.SetCharacterSize(characterSize);
|
||||
drawer.SetColor(color);
|
||||
drawer.SetFont(font);
|
||||
drawer.SetOutlineColor(outlineColor);
|
||||
drawer.SetOutlineThickness(outlineThickness);
|
||||
drawer.SetStyle(style);
|
||||
drawer.SetText(str);
|
||||
drawer.SetTextColor(color);
|
||||
drawer.SetTextFont(font);
|
||||
drawer.SetTextOutlineColor(outlineColor);
|
||||
drawer.SetTextOutlineThickness(outlineThickness);
|
||||
drawer.SetTextStyle(style);
|
||||
drawer.SetText(std::move(str));
|
||||
|
||||
return drawer;
|
||||
}
|
||||
|
||||
@@ -64,9 +64,9 @@ namespace Nz
|
||||
inline void SetReadOnly(bool readOnly = true);
|
||||
inline void SetSelection(Vector2ui fromPosition, Vector2ui toPosition);
|
||||
|
||||
inline void Write(const std::string& text);
|
||||
inline void Write(const std::string& text, const Vector2ui& glyphPosition);
|
||||
virtual void Write(const std::string& text, std::size_t glyphPosition) = 0;
|
||||
inline void Write(std::string_view text);
|
||||
inline void Write(std::string_view text, const Vector2ui& glyphPosition);
|
||||
virtual void Write(std::string_view text, std::size_t glyphPosition) = 0;
|
||||
|
||||
AbstractTextAreaWidget& operator=(const AbstractTextAreaWidget&) = delete;
|
||||
AbstractTextAreaWidget& operator=(AbstractTextAreaWidget&&) = delete;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Nz
|
||||
RichTextAreaWidget(RichTextAreaWidget&&) = delete;
|
||||
~RichTextAreaWidget() = default;
|
||||
|
||||
void AppendText(const std::string& text);
|
||||
void AppendText(std::string_view text);
|
||||
|
||||
void Clear() override;
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace Nz
|
||||
inline void SetTextOutlineThickness(float thickness);
|
||||
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=(RichTextAreaWidget&&) = delete;
|
||||
|
||||
@@ -8,82 +8,82 @@ namespace Nz
|
||||
{
|
||||
inline unsigned int RichTextAreaWidget::GetCharacterSize() const
|
||||
{
|
||||
return m_drawer.GetDefaultCharacterSize();
|
||||
return m_drawer.GetCharacterSize();
|
||||
}
|
||||
|
||||
inline float RichTextAreaWidget::GetCharacterSpacingOffset() const
|
||||
{
|
||||
return m_drawer.GetDefaultCharacterSpacingOffset();
|
||||
return m_drawer.GetCharacterSpacingOffset();
|
||||
}
|
||||
|
||||
inline float RichTextAreaWidget::GetLineSpacingOffset() const
|
||||
{
|
||||
return m_drawer.GetDefaultLineSpacingOffset();
|
||||
return m_drawer.GetLineSpacingOffset();
|
||||
}
|
||||
|
||||
inline const Color& RichTextAreaWidget::GetTextColor() const
|
||||
{
|
||||
return m_drawer.GetDefaultColor();
|
||||
return m_drawer.GetTextColor();
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<Font>& RichTextAreaWidget::GetTextFont() const
|
||||
{
|
||||
return m_drawer.GetDefaultFont();
|
||||
return m_drawer.GetTextFont();
|
||||
}
|
||||
|
||||
inline const Color& RichTextAreaWidget::GetTextOutlineColor() const
|
||||
{
|
||||
return m_drawer.GetDefaultOutlineColor();
|
||||
return m_drawer.GetTextOutlineColor();
|
||||
}
|
||||
|
||||
inline float RichTextAreaWidget::GetTextOutlineThickness() const
|
||||
{
|
||||
return m_drawer.GetDefaultOutlineThickness();
|
||||
return m_drawer.GetTextOutlineThickness();
|
||||
}
|
||||
|
||||
inline TextStyleFlags RichTextAreaWidget::GetTextStyle() const
|
||||
{
|
||||
return m_drawer.GetDefaultStyle();
|
||||
return m_drawer.GetTextStyle();
|
||||
}
|
||||
|
||||
inline void RichTextAreaWidget::SetCharacterSize(unsigned int characterSize)
|
||||
{
|
||||
m_drawer.SetDefaultCharacterSize(characterSize);
|
||||
m_drawer.SetCharacterSize(characterSize);
|
||||
}
|
||||
|
||||
inline void RichTextAreaWidget::SetCharacterSpacingOffset(float offset)
|
||||
{
|
||||
m_drawer.SetDefaultCharacterSpacingOffset(offset);
|
||||
m_drawer.SetCharacterSpacingOffset(offset);
|
||||
}
|
||||
|
||||
inline void RichTextAreaWidget::SetLineSpacingOffset(float offset)
|
||||
{
|
||||
m_drawer.SetDefaultLineSpacingOffset(offset);
|
||||
m_drawer.SetLineSpacingOffset(offset);
|
||||
}
|
||||
|
||||
inline void RichTextAreaWidget::SetTextColor(const Color& color)
|
||||
{
|
||||
m_drawer.SetDefaultColor(color);
|
||||
m_drawer.SetTextColor(color);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
m_drawer.SetDefaultOutlineColor(color);
|
||||
m_drawer.SetTextOutlineColor(color);
|
||||
}
|
||||
|
||||
inline void RichTextAreaWidget::SetTextOutlineThickness(float thickness)
|
||||
{
|
||||
m_drawer.SetDefaultOutlineThickness(thickness);
|
||||
m_drawer.SetTextOutlineThickness(thickness);
|
||||
}
|
||||
|
||||
inline void RichTextAreaWidget::SetTextStyle(TextStyleFlags style)
|
||||
{
|
||||
m_drawer.SetDefaultStyle(style);
|
||||
m_drawer.SetTextStyle(style);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Nz
|
||||
TextAreaWidget(TextAreaWidget&&) = delete;
|
||||
~TextAreaWidget() = default;
|
||||
|
||||
void AppendText(const std::string& text);
|
||||
void AppendText(std::string_view text);
|
||||
|
||||
void Clear() override;
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Nz
|
||||
inline void SetTextStyle(TextStyleFlags style);
|
||||
|
||||
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=(TextAreaWidget&&) = delete;
|
||||
|
||||
@@ -33,27 +33,27 @@ namespace Nz
|
||||
|
||||
inline const Color& TextAreaWidget::GetTextColor() const
|
||||
{
|
||||
return m_drawer.GetColor();
|
||||
return m_drawer.GetTextColor();
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<Font>& TextAreaWidget::GetTextFont() const
|
||||
{
|
||||
return m_drawer.GetFont();
|
||||
return m_drawer.GetTextFont();
|
||||
}
|
||||
|
||||
inline const Color& TextAreaWidget::GetTextOulineColor() const
|
||||
{
|
||||
return m_drawer.GetOutlineColor();
|
||||
return m_drawer.GetTextOutlineColor();
|
||||
}
|
||||
|
||||
inline float TextAreaWidget::GetTextOulineThickness() const
|
||||
{
|
||||
return m_drawer.GetOutlineThickness();
|
||||
return m_drawer.GetTextOutlineThickness();
|
||||
}
|
||||
|
||||
inline TextStyleFlags TextAreaWidget::GetTextStyle() const
|
||||
{
|
||||
return m_drawer.GetStyle();
|
||||
return m_drawer.GetTextStyle();
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetCharacterSize(unsigned int characterSize)
|
||||
@@ -89,35 +89,35 @@ namespace Nz
|
||||
|
||||
inline void TextAreaWidget::SetTextColor(const Color& text)
|
||||
{
|
||||
m_drawer.SetColor(text);
|
||||
m_drawer.SetTextColor(text);
|
||||
|
||||
UpdateDisplayText();
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetTextFont(std::shared_ptr<Font> font)
|
||||
{
|
||||
m_drawer.SetFont(std::move(font));
|
||||
m_drawer.SetTextFont(std::move(font));
|
||||
|
||||
UpdateDisplayText();
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetTextOutlineColor(const Color& color)
|
||||
{
|
||||
m_drawer.SetOutlineColor(color);
|
||||
m_drawer.SetTextOutlineColor(color);
|
||||
|
||||
UpdateDisplayText();
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetTextOutlineThickness(float thickness)
|
||||
{
|
||||
m_drawer.SetOutlineThickness(thickness);
|
||||
m_drawer.SetTextOutlineThickness(thickness);
|
||||
|
||||
UpdateDisplayText();
|
||||
}
|
||||
|
||||
inline void TextAreaWidget::SetTextStyle(TextStyleFlags style)
|
||||
{
|
||||
m_drawer.SetStyle(style);
|
||||
m_drawer.SetTextStyle(style);
|
||||
|
||||
UpdateDisplayText();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user