Utility/Font: Replace Listener system by Signals

Former-commit-id: 0391c506c039c7aeb7acf4a01faa8a979be16749
This commit is contained in:
Lynix
2015-06-07 16:08:14 +02:00
parent cc9b0b307e
commit 022f082363
4 changed files with 71 additions and 43 deletions

View File

@@ -95,15 +95,6 @@ class NAZARA_API NzFont : public NzRefCounted, public NzResource, NzNonCopyable
static void SetDefaultGlyphBorder(unsigned int borderSize);
static void SetDefaultMinimumStepSize(unsigned int minimumStepSize);
enum ModicationCode
{
ModificationCode_AtlasChanged,
ModificationCode_AtlasLayerChanged,
ModificationCode_GlyphCacheCleared,
ModificationCode_KerningCacheCleared,
ModificationCode_SizeInfoCacheCleared
};
struct Glyph
{
NzRecti aabb;
@@ -124,6 +115,13 @@ class NAZARA_API NzFont : public NzRefCounted, public NzResource, NzNonCopyable
float underlineThickness;
};
NazaraSignal(OnFontAtlasChanged, const NzFont*); //< Args: me
NazaraSignal(OnFontAtlasLayerChanged, const NzFont*); //< Args: me
NazaraSignal(OnFontGlyphCacheCleared, const NzFont*); //< Args: me
NazaraSignal(OnFontKerningCacheCleared, const NzFont*); //< Args: me
NazaraSignal(OnFontRelease, const NzFont*); //< Args: me
NazaraSignal(OnFontSizeInfoCacheCleared, const NzFont*); //< Args: me
private:
using GlyphMap = std::unordered_map<char32_t, Glyph>;

View File

@@ -15,10 +15,12 @@
#include <Nazara/Utility/Font.hpp>
#include <vector>
class NAZARA_API NzSimpleTextDrawer : public NzAbstractTextDrawer, NzObjectListener
class NAZARA_API NzSimpleTextDrawer : public NzAbstractTextDrawer
{
public:
NzSimpleTextDrawer();
NzSimpleTextDrawer(const NzSimpleTextDrawer& drawer);
NzSimpleTextDrawer(NzSimpleTextDrawer&&) = default;
virtual ~NzSimpleTextDrawer() = default;
const NzRectui& GetBounds() const;
@@ -42,14 +44,18 @@ class NAZARA_API NzSimpleTextDrawer : public NzAbstractTextDrawer, NzObjectListe
static NzSimpleTextDrawer Draw(NzFont* font, const NzString& str, unsigned int characterSize, nzUInt32 style = nzTextStyle_Regular, const NzColor& color = NzColor::White);
private:
bool OnObjectModified(const NzRefCounted* object, int index, unsigned int code) override;
void OnObjectReleased(const NzRefCounted* object, int index) override;
void OnFontInvalidated(const NzFont* font);
void OnFontRelease(const NzFont* object);
void UpdateGlyphs() const;
NazaraSlot(NzFont, OnFontAtlasChanged, m_atlasChangedSlot);
NazaraSlot(NzFont, OnFontAtlasLayerChanged, m_atlasLayerChangedSlot);
NazaraSlot(NzFont, OnFontGlyphCacheCleared, m_glyphCacheClearedSlot);
NazaraSlot(NzFont, OnFontRelease, m_fontReleaseSlot);
mutable std::vector<Glyph> m_glyphs;
NzColor m_color;
NzFontRef m_font;
NzFontListener m_fontListener; // Doit se situer après le FontRef (pour être libéré avant)
mutable NzRectui m_bounds;
NzString m_text;
nzUInt32 m_style;