Utility/SimpleTextDrawer: Fix movement
Former-commit-id: ac62391a2e28f50a0a61e984692a7a1e3444b28e
This commit is contained in:
parent
21ad09d626
commit
40d35fbe5f
|
|
@ -19,7 +19,7 @@ class NAZARA_UTILITY_API NzSimpleTextDrawer : public NzAbstractTextDrawer
|
|||
public:
|
||||
NzSimpleTextDrawer();
|
||||
NzSimpleTextDrawer(const NzSimpleTextDrawer& drawer);
|
||||
NzSimpleTextDrawer(NzSimpleTextDrawer&&) = default;
|
||||
NzSimpleTextDrawer(NzSimpleTextDrawer&& drawer);
|
||||
virtual ~NzSimpleTextDrawer();
|
||||
|
||||
const NzRectui& GetBounds() const;
|
||||
|
|
@ -39,10 +39,15 @@ class NAZARA_UTILITY_API NzSimpleTextDrawer : public NzAbstractTextDrawer
|
|||
void SetStyle(nzUInt32 style);
|
||||
void SetText(const NzString& str);
|
||||
|
||||
NzSimpleTextDrawer& operator=(const NzSimpleTextDrawer& drawer) = default;
|
||||
NzSimpleTextDrawer& operator=(NzSimpleTextDrawer&& drawer);
|
||||
|
||||
static NzSimpleTextDrawer Draw(const NzString& str, unsigned int characterSize, nzUInt32 style = nzTextStyle_Regular, const NzColor& color = NzColor::White);
|
||||
static NzSimpleTextDrawer Draw(NzFont* font, const NzString& str, unsigned int characterSize, nzUInt32 style = nzTextStyle_Regular, const NzColor& color = NzColor::White);
|
||||
|
||||
private:
|
||||
void ConnectFontSlots();
|
||||
void DisconnectFontSlots();
|
||||
void OnFontAtlasLayerChanged(const NzFont* font, NzAbstractImage* oldLayer, NzAbstractImage* newLayer);
|
||||
void OnFontInvalidated(const NzFont* font);
|
||||
void OnFontRelease(const NzFont* object);
|
||||
|
|
|
|||
|
|
@ -24,6 +24,12 @@ m_characterSize(drawer.m_characterSize)
|
|||
SetFont(drawer.m_font);
|
||||
}
|
||||
|
||||
NzSimpleTextDrawer::NzSimpleTextDrawer(NzSimpleTextDrawer&& drawer)
|
||||
{
|
||||
operator=(std::move(drawer));
|
||||
}
|
||||
|
||||
|
||||
NzSimpleTextDrawer::~NzSimpleTextDrawer() = default;
|
||||
|
||||
const NzRectui& NzSimpleTextDrawer::GetBounds() const
|
||||
|
|
@ -112,20 +118,11 @@ void NzSimpleTextDrawer::SetFont(NzFont* font)
|
|||
if (m_font != font)
|
||||
{
|
||||
m_font = font;
|
||||
|
||||
if (m_font)
|
||||
{
|
||||
m_atlasChangedSlot.Connect(m_font->OnFontAtlasChanged, this, &NzSimpleTextDrawer::OnFontInvalidated);
|
||||
m_atlasLayerChangedSlot.Connect(m_font->OnFontAtlasLayerChanged, this, &NzSimpleTextDrawer::OnFontAtlasLayerChanged);
|
||||
m_fontReleaseSlot.Connect(m_font->OnFontRelease, this, &NzSimpleTextDrawer::OnFontRelease);
|
||||
m_glyphCacheClearedSlot.Connect(m_font->OnFontGlyphCacheCleared, this, &NzSimpleTextDrawer::OnFontInvalidated);
|
||||
}
|
||||
ConnectFontSlots();
|
||||
else
|
||||
{
|
||||
m_atlasChangedSlot.Disconnect();
|
||||
m_atlasLayerChangedSlot.Disconnect();
|
||||
m_fontReleaseSlot.Disconnect();
|
||||
m_glyphCacheClearedSlot.Disconnect();
|
||||
}
|
||||
DisconnectFontSlots();
|
||||
|
||||
m_glyphUpdated = false;
|
||||
}
|
||||
|
|
@ -145,6 +142,25 @@ void NzSimpleTextDrawer::SetText(const NzString& str)
|
|||
m_glyphUpdated = false;
|
||||
}
|
||||
|
||||
NzSimpleTextDrawer& NzSimpleTextDrawer::operator=(NzSimpleTextDrawer&& drawer)
|
||||
{
|
||||
DisconnectFontSlots();
|
||||
|
||||
m_bounds = std::move(drawer.m_bounds);
|
||||
m_characterSize = std::move(drawer.m_characterSize);
|
||||
m_color = std::move(drawer.m_color);
|
||||
m_glyphs = std::move(drawer.m_glyphs);
|
||||
m_glyphUpdated = std::move(drawer.m_glyphUpdated);
|
||||
m_font = std::move(drawer.m_font);
|
||||
m_style = std::move(drawer.m_style);
|
||||
m_text = std::move(drawer.m_text);
|
||||
|
||||
// Update slot pointers (TODO: Improve the way of doing this)
|
||||
ConnectFontSlots();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
NzSimpleTextDrawer NzSimpleTextDrawer::Draw(const NzString& str, unsigned int characterSize, nzUInt32 style, const NzColor& color)
|
||||
{
|
||||
NzSimpleTextDrawer drawer;
|
||||
|
|
@ -168,6 +184,22 @@ NzSimpleTextDrawer NzSimpleTextDrawer::Draw(NzFont* font, const NzString& str, u
|
|||
return drawer;
|
||||
}
|
||||
|
||||
void NzSimpleTextDrawer::ConnectFontSlots()
|
||||
{
|
||||
m_atlasChangedSlot.Connect(m_font->OnFontAtlasChanged, this, &NzSimpleTextDrawer::OnFontInvalidated);
|
||||
m_atlasLayerChangedSlot.Connect(m_font->OnFontAtlasLayerChanged, this, &NzSimpleTextDrawer::OnFontAtlasLayerChanged);
|
||||
m_fontReleaseSlot.Connect(m_font->OnFontRelease, this, &NzSimpleTextDrawer::OnFontRelease);
|
||||
m_glyphCacheClearedSlot.Connect(m_font->OnFontGlyphCacheCleared, this, &NzSimpleTextDrawer::OnFontInvalidated);
|
||||
}
|
||||
|
||||
void NzSimpleTextDrawer::DisconnectFontSlots()
|
||||
{
|
||||
m_atlasChangedSlot.Disconnect();
|
||||
m_atlasLayerChangedSlot.Disconnect();
|
||||
m_fontReleaseSlot.Disconnect();
|
||||
m_glyphCacheClearedSlot.Disconnect();
|
||||
}
|
||||
|
||||
void NzSimpleTextDrawer::OnFontAtlasLayerChanged(const NzFont* font, NzAbstractImage* oldLayer, NzAbstractImage* newLayer)
|
||||
{
|
||||
NazaraUnused(font);
|
||||
|
|
|
|||
Loading…
Reference in New Issue