Utility/SimpleTextDrawer: Fix movement
Former-commit-id: f5086d1ca281f31a3b89d5cd535f9aeaa9b2a929
This commit is contained in:
parent
2b48917176
commit
831b9358ef
|
|
@ -19,7 +19,7 @@ class NAZARA_UTILITY_API NzSimpleTextDrawer : public NzAbstractTextDrawer
|
||||||
public:
|
public:
|
||||||
NzSimpleTextDrawer();
|
NzSimpleTextDrawer();
|
||||||
NzSimpleTextDrawer(const NzSimpleTextDrawer& drawer);
|
NzSimpleTextDrawer(const NzSimpleTextDrawer& drawer);
|
||||||
NzSimpleTextDrawer(NzSimpleTextDrawer&&) = default;
|
NzSimpleTextDrawer(NzSimpleTextDrawer&& drawer);
|
||||||
virtual ~NzSimpleTextDrawer();
|
virtual ~NzSimpleTextDrawer();
|
||||||
|
|
||||||
const NzRectui& GetBounds() const;
|
const NzRectui& GetBounds() const;
|
||||||
|
|
@ -39,10 +39,15 @@ class NAZARA_UTILITY_API NzSimpleTextDrawer : public NzAbstractTextDrawer
|
||||||
void SetStyle(nzUInt32 style);
|
void SetStyle(nzUInt32 style);
|
||||||
void SetText(const NzString& str);
|
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(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);
|
static NzSimpleTextDrawer Draw(NzFont* font, const NzString& str, unsigned int characterSize, nzUInt32 style = nzTextStyle_Regular, const NzColor& color = NzColor::White);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void ConnectFontSlots();
|
||||||
|
void DisconnectFontSlots();
|
||||||
void OnFontAtlasLayerChanged(const NzFont* font, NzAbstractImage* oldLayer, NzAbstractImage* newLayer);
|
void OnFontAtlasLayerChanged(const NzFont* font, NzAbstractImage* oldLayer, NzAbstractImage* newLayer);
|
||||||
void OnFontInvalidated(const NzFont* font);
|
void OnFontInvalidated(const NzFont* font);
|
||||||
void OnFontRelease(const NzFont* object);
|
void OnFontRelease(const NzFont* object);
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,12 @@ m_characterSize(drawer.m_characterSize)
|
||||||
SetFont(drawer.m_font);
|
SetFont(drawer.m_font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NzSimpleTextDrawer::NzSimpleTextDrawer(NzSimpleTextDrawer&& drawer)
|
||||||
|
{
|
||||||
|
operator=(std::move(drawer));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NzSimpleTextDrawer::~NzSimpleTextDrawer() = default;
|
NzSimpleTextDrawer::~NzSimpleTextDrawer() = default;
|
||||||
|
|
||||||
const NzRectui& NzSimpleTextDrawer::GetBounds() const
|
const NzRectui& NzSimpleTextDrawer::GetBounds() const
|
||||||
|
|
@ -112,20 +118,11 @@ void NzSimpleTextDrawer::SetFont(NzFont* font)
|
||||||
if (m_font != font)
|
if (m_font != font)
|
||||||
{
|
{
|
||||||
m_font = font;
|
m_font = font;
|
||||||
|
|
||||||
if (m_font)
|
if (m_font)
|
||||||
{
|
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);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
DisconnectFontSlots();
|
||||||
m_atlasChangedSlot.Disconnect();
|
|
||||||
m_atlasLayerChangedSlot.Disconnect();
|
|
||||||
m_fontReleaseSlot.Disconnect();
|
|
||||||
m_glyphCacheClearedSlot.Disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_glyphUpdated = false;
|
m_glyphUpdated = false;
|
||||||
}
|
}
|
||||||
|
|
@ -145,6 +142,25 @@ void NzSimpleTextDrawer::SetText(const NzString& str)
|
||||||
m_glyphUpdated = false;
|
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 NzSimpleTextDrawer::Draw(const NzString& str, unsigned int characterSize, nzUInt32 style, const NzColor& color)
|
||||||
{
|
{
|
||||||
NzSimpleTextDrawer drawer;
|
NzSimpleTextDrawer drawer;
|
||||||
|
|
@ -168,6 +184,22 @@ NzSimpleTextDrawer NzSimpleTextDrawer::Draw(NzFont* font, const NzString& str, u
|
||||||
return drawer;
|
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)
|
void NzSimpleTextDrawer::OnFontAtlasLayerChanged(const NzFont* font, NzAbstractImage* oldLayer, NzAbstractImage* newLayer)
|
||||||
{
|
{
|
||||||
NazaraUnused(font);
|
NazaraUnused(font);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue