Utility/Font: Replace Listener system by Signals
Former-commit-id: 0391c506c039c7aeb7acf4a01faa8a979be16749
This commit is contained in:
@@ -30,6 +30,8 @@ m_minimumStepSize(s_defaultMinimumStepSize)
|
||||
|
||||
NzFont::~NzFont()
|
||||
{
|
||||
OnFontRelease(this);
|
||||
|
||||
Destroy();
|
||||
SetAtlas(nullptr); // On libère l'atlas proprement
|
||||
}
|
||||
@@ -55,7 +57,8 @@ void NzFont::ClearGlyphCache()
|
||||
|
||||
// Destruction des glyphes mémorisés et notification
|
||||
m_glyphes.clear();
|
||||
NotifyModified(ModificationCode_GlyphCacheCleared);
|
||||
|
||||
OnFontGlyphCacheCleared(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,13 +66,15 @@ void NzFont::ClearGlyphCache()
|
||||
void NzFont::ClearKerningCache()
|
||||
{
|
||||
m_kerningCache.clear();
|
||||
NotifyModified(ModificationCode_KerningCacheCleared);
|
||||
|
||||
OnFontKerningCacheCleared(this);
|
||||
}
|
||||
|
||||
void NzFont::ClearSizeInfoCache()
|
||||
{
|
||||
m_sizeInfoCache.clear();
|
||||
NotifyModified(ModificationCode_SizeInfoCacheCleared);
|
||||
|
||||
OnFontSizeInfoCacheCleared(this);
|
||||
}
|
||||
|
||||
bool NzFont::Create(NzFontData* data)
|
||||
@@ -304,7 +309,7 @@ void NzFont::SetAtlas(const std::shared_ptr<NzAbstractAtlas>& atlas)
|
||||
NazaraDisconnect(m_atlasReleaseSlot);
|
||||
}
|
||||
|
||||
NotifyModified(ModificationCode_AtlasChanged);
|
||||
OnFontAtlasChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,7 +430,8 @@ void NzFont::OnAtlasCleared(const NzAbstractAtlas* atlas)
|
||||
|
||||
// Notre atlas vient d'être vidé, détruisons le cache de glyphe
|
||||
m_glyphes.clear();
|
||||
NotifyModified(ModificationCode_GlyphCacheCleared);
|
||||
|
||||
OnFontGlyphCacheCleared(this);
|
||||
}
|
||||
|
||||
void NzFont::OnAtlasLayerChange(const NzAbstractAtlas* atlas, NzAbstractImage* oldLayer, NzAbstractImage* newLayer)
|
||||
@@ -444,7 +450,7 @@ void NzFont::OnAtlasLayerChange(const NzAbstractAtlas* atlas, NzAbstractImage* o
|
||||
#endif
|
||||
|
||||
// Pour faciliter le travail des ressources qui nous écoutent
|
||||
NotifyModified(ModificationCode_AtlasLayerChanged);
|
||||
OnFontAtlasLayerChanged(this);
|
||||
}
|
||||
|
||||
void NzFont::OnAtlasRelease(const NzAbstractAtlas* atlas)
|
||||
|
||||
@@ -8,12 +8,22 @@
|
||||
|
||||
NzSimpleTextDrawer::NzSimpleTextDrawer() :
|
||||
m_color(NzColor::White),
|
||||
m_fontListener(this),
|
||||
m_style(nzTextStyle_Regular)
|
||||
m_style(nzTextStyle_Regular),
|
||||
m_glyphUpdated(false)
|
||||
{
|
||||
SetFont(NzFont::GetDefault());
|
||||
}
|
||||
|
||||
NzSimpleTextDrawer::NzSimpleTextDrawer(const NzSimpleTextDrawer& drawer) :
|
||||
m_color(drawer.m_color),
|
||||
m_text(drawer.m_text),
|
||||
m_style(drawer.m_style),
|
||||
m_glyphUpdated(false),
|
||||
m_characterSize(drawer.m_characterSize)
|
||||
{
|
||||
SetFont(drawer.m_font);
|
||||
}
|
||||
|
||||
const NzRectui& NzSimpleTextDrawer::GetBounds() const
|
||||
{
|
||||
if (!m_glyphUpdated)
|
||||
@@ -97,10 +107,26 @@ void NzSimpleTextDrawer::SetColor(const NzColor& color)
|
||||
|
||||
void NzSimpleTextDrawer::SetFont(NzFont* font)
|
||||
{
|
||||
m_font = font;
|
||||
m_fontListener = font;
|
||||
if (m_font != font)
|
||||
{
|
||||
m_font = font;
|
||||
if (m_font)
|
||||
{
|
||||
m_atlasChangedSlot = NazaraConnect(*m_font, OnFontAtlasChanged, OnFontInvalidated);
|
||||
m_atlasLayerChangedSlot = NazaraConnect(*m_font, OnFontAtlasLayerChanged, OnFontInvalidated);
|
||||
m_fontReleaseSlot = NazaraConnect(*m_font, OnFontRelease, OnFontRelease);
|
||||
m_glyphCacheClearedSlot = NazaraConnect(*m_font, OnFontGlyphCacheCleared, OnFontInvalidated);
|
||||
}
|
||||
else
|
||||
{
|
||||
NazaraDisconnect(m_atlasChangedSlot);
|
||||
NazaraDisconnect(m_atlasLayerChangedSlot);
|
||||
NazaraDisconnect(m_fontReleaseSlot);
|
||||
NazaraDisconnect(m_glyphCacheClearedSlot);
|
||||
}
|
||||
|
||||
m_glyphUpdated = false;
|
||||
m_glyphUpdated = false;
|
||||
}
|
||||
}
|
||||
|
||||
void NzSimpleTextDrawer::SetStyle(nzUInt32 style)
|
||||
@@ -140,38 +166,30 @@ NzSimpleTextDrawer NzSimpleTextDrawer::Draw(NzFont* font, const NzString& str, u
|
||||
return drawer;
|
||||
}
|
||||
|
||||
bool NzSimpleTextDrawer::OnObjectModified(const NzRefCounted* object, int index, unsigned int code)
|
||||
void NzSimpleTextDrawer::OnFontInvalidated(const NzFont* font)
|
||||
{
|
||||
NazaraUnused(object);
|
||||
NazaraUnused(index);
|
||||
NazaraUnused(font);
|
||||
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (m_font != object)
|
||||
if (m_font != font)
|
||||
{
|
||||
NazaraInternalError("Not listening to " + NzString::Pointer(object));
|
||||
return false;
|
||||
NazaraInternalError("Not listening to " + NzString::Pointer(font));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (code == NzFont::ModificationCode_AtlasChanged ||
|
||||
code == NzFont::ModificationCode_AtlasLayerChanged ||
|
||||
code == NzFont::ModificationCode_GlyphCacheCleared)
|
||||
{
|
||||
m_glyphUpdated = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
m_glyphUpdated = false;
|
||||
}
|
||||
|
||||
void NzSimpleTextDrawer::OnObjectReleased(const NzRefCounted* object, int index)
|
||||
void NzSimpleTextDrawer::OnFontRelease(const NzFont* font)
|
||||
{
|
||||
NazaraUnused(object);
|
||||
NazaraUnused(index);
|
||||
NazaraUnused(font);
|
||||
NazaraUnused(font);
|
||||
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (m_font != object)
|
||||
if (m_font != font)
|
||||
{
|
||||
NazaraInternalError("Not listening to " + NzString::Pointer(object));
|
||||
NazaraInternalError("Not listening to " + NzString::Pointer(font));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user