Added Atlas listeners
Former-commit-id: a487b6ed53d9b97bfee27b28ba5523e43c1e9e7e
This commit is contained in:
@@ -10,31 +10,45 @@
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/SparsePtr.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
|
||||
class NzAbstractImage;
|
||||
class NzFont;
|
||||
class NzImage;
|
||||
|
||||
class NAZARA_API NzAbstractFontAtlas
|
||||
{
|
||||
public:
|
||||
NzAbstractFontAtlas() = default;
|
||||
class Listener;
|
||||
|
||||
NzAbstractFontAtlas();
|
||||
virtual ~NzAbstractFontAtlas();
|
||||
|
||||
void AddListener(Listener* font, void* userdata = nullptr) const;
|
||||
|
||||
virtual void Clear() = 0;
|
||||
virtual void Free(NzSparsePtr<const NzRectui> rects, NzSparsePtr<unsigned int> layers, unsigned int count) = 0;
|
||||
virtual NzAbstractImage* GetLayer(unsigned int layerIndex) const = 0;
|
||||
virtual unsigned int GetLayerCount() const = 0;
|
||||
virtual bool Insert(const NzImage& image, NzRectui* rect, bool* flipped, unsigned int* layerIndex) = 0;
|
||||
void RegisterFont(NzFont* font);
|
||||
void UnregisterFont(NzFont* font);
|
||||
|
||||
void RemoveListener(Listener* font) const;
|
||||
|
||||
class Listener
|
||||
{
|
||||
public:
|
||||
Listener() = default;
|
||||
virtual ~Listener();
|
||||
|
||||
virtual bool OnAtlasCleared(const NzAbstractFontAtlas* atlas, void* userdata);
|
||||
virtual void OnAtlasReleased(const NzAbstractFontAtlas* atlas, void* userdata);
|
||||
};
|
||||
|
||||
protected:
|
||||
void NotifyCleared();
|
||||
|
||||
private:
|
||||
std::set<NzFont*> m_registredFonts;
|
||||
mutable std::unordered_map<Listener*, void*> m_listeners;
|
||||
bool m_listenersLocked;
|
||||
};
|
||||
|
||||
#endif // NAZARA_ABSTRACTFONTATLAS_HPP
|
||||
|
||||
@@ -29,7 +29,7 @@ using NzFontConstRef = NzResourceRef<const NzFont>;
|
||||
using NzFontLoader = NzResourceLoader<NzFont, NzFontParams>;
|
||||
using NzFontRef = NzResourceRef<NzFont>;
|
||||
|
||||
class NAZARA_API NzFont : public NzResource, NzNonCopyable
|
||||
class NAZARA_API NzFont : public NzResource, NzAbstractFontAtlas::Listener, NzNonCopyable
|
||||
{
|
||||
friend NzAbstractFontAtlas;
|
||||
friend NzFontLoader;
|
||||
@@ -108,7 +108,8 @@ class NAZARA_API NzFont : public NzResource, NzNonCopyable
|
||||
using GlyphMap = std::unordered_map<char32_t, Glyph>;
|
||||
|
||||
nzUInt64 ComputeKey(unsigned int characterSize, nzUInt32 style) const;
|
||||
void OnAtlasCleared();
|
||||
bool OnAtlasCleared(const NzAbstractFontAtlas* atlas, void* userdata) override;
|
||||
void OnAtlasReleased(const NzAbstractFontAtlas* atlas, void* userdata) override;
|
||||
const Glyph& PrecacheGlyph(GlyphMap& glyphMap, unsigned int characterSize, nzUInt32 style, char32_t character) const;
|
||||
|
||||
std::shared_ptr<NzAbstractFontAtlas> m_atlas;
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include <Nazara/Utility/AbstractImage.hpp>
|
||||
#include <Nazara/Utility/Image.hpp>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
class NAZARA_API NzGuillotineImageAtlas : public NzAbstractFontAtlas
|
||||
@@ -59,7 +58,6 @@ class NAZARA_API NzGuillotineImageAtlas : public NzAbstractFontAtlas
|
||||
private:
|
||||
void ProcessGlyphQueue(Layer& layer) const;
|
||||
|
||||
std::set<NzFont*> m_fonts;
|
||||
mutable std::vector<Layer> m_layers;
|
||||
NzGuillotineBinPack::FreeRectChoiceHeuristic m_rectChoiceHeuristic;
|
||||
NzGuillotineBinPack::GuillotineSplitHeuristic m_rectSplitHeuristic;
|
||||
|
||||
Reference in New Issue
Block a user