mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-18 06:55:48 +03:00
move nine-patches into scoped catalogs
Return shared handles from NinePatch creation and remove the process-wide NinePatchManager singleton. Extend ResourceCatalog with typed drawable-source ownership and expose drawable publication, lookup, and removal through ResourceScope. Preserve separate texture and drawable namespaces for direct typed lookup. Give each UITheme its own resource catalog and have scene-owned theme managers explicitly import and remove theme catalogs. Handle registered themes and default-only themes without leaking stale resource visibility between scenes. Update theme loading, Engine teardown, platform source manifests, and resource ownership tests for the catalog-based model. Document that remaining singleton resource managers must migrate to naturally owned catalogs and explicit scope imports instead of becoming new process-global semantic namespaces.
This commit is contained in:
@@ -25,7 +25,6 @@
|
||||
#include <eepp/graphics/image.hpp>
|
||||
#include <eepp/graphics/linewrap.hpp>
|
||||
#include <eepp/graphics/ninepatch.hpp>
|
||||
#include <eepp/graphics/ninepatchmanager.hpp>
|
||||
#include <eepp/graphics/packerhelper.hpp>
|
||||
#include <eepp/graphics/particle.hpp>
|
||||
#include <eepp/graphics/particlesystem.hpp>
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
|
||||
namespace EE { namespace Graphics {
|
||||
|
||||
class NinePatch;
|
||||
using NinePatchPtr = ResourcePtr<NinePatch>;
|
||||
using NinePatchWeakPtr = ResourceWeakPtr<NinePatch>;
|
||||
|
||||
class EE_API NinePatch : public DrawableResource {
|
||||
public:
|
||||
enum NinePatchSides {
|
||||
@@ -22,14 +26,14 @@ class EE_API NinePatch : public DrawableResource {
|
||||
SideCount
|
||||
};
|
||||
|
||||
static NinePatch* New( ResourceId textureId, int left, int top, int right, int bottom,
|
||||
const Float& pixelDensity = 1, const std::string& name = "" );
|
||||
static NinePatchPtr New( ResourceId textureId, int left, int top, int right, int bottom,
|
||||
const Float& pixelDensity = 1, const std::string& name = "" );
|
||||
|
||||
static NinePatch* New( TexturePtr tex, int left, int top, int right, int bottom,
|
||||
const Float& pixelDensity = 1, const std::string& name = "" );
|
||||
static NinePatchPtr New( TexturePtr tex, int left, int top, int right, int bottom,
|
||||
const Float& pixelDensity = 1, const std::string& name = "" );
|
||||
|
||||
static NinePatch* New( TextureRegion* textureRegion, int left, int top, int right, int bottom,
|
||||
const std::string& name = "" );
|
||||
static NinePatchPtr New( TextureRegion* textureRegion, int left, int top, int right, int bottom,
|
||||
const std::string& name = "" );
|
||||
|
||||
NinePatch( TexturePtr tex, int left, int top, int right, int bottom,
|
||||
const Float& pixelDensity = 1, const std::string& name = "" );
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
#ifndef EE_GRAPHICS_NINEPATCHMANAGER_HPP
|
||||
#define EE_GRAPHICS_NINEPATCHMANAGER_HPP
|
||||
|
||||
#include <eepp/graphics/base.hpp>
|
||||
#include <eepp/graphics/ninepatch.hpp>
|
||||
|
||||
#include <eepp/system/resourcemanager.hpp>
|
||||
#include <eepp/system/singleton.hpp>
|
||||
using namespace EE::System;
|
||||
|
||||
namespace EE { namespace Graphics {
|
||||
|
||||
class EE_API NinePatchManager : public ResourceManager<NinePatch> {
|
||||
SINGLETON_DECLARE_HEADERS( NinePatchManager )
|
||||
|
||||
~NinePatchManager();
|
||||
};
|
||||
|
||||
}} // namespace EE::Graphics
|
||||
|
||||
#endif
|
||||
@@ -2,6 +2,7 @@
|
||||
#define EE_GRAPHICS_RESOURCECATALOG_HPP
|
||||
|
||||
#include <eepp/core/containers.hpp>
|
||||
#include <eepp/graphics/drawable.hpp>
|
||||
#include <eepp/graphics/resource.hpp>
|
||||
#include <eepp/graphics/texture.hpp>
|
||||
#include <eepp/system/mutex.hpp>
|
||||
@@ -18,18 +19,25 @@ class EE_API ResourceCatalog {
|
||||
|
||||
void publish( ResourceKey key, TexturePtr texture );
|
||||
void publish( std::string key, TexturePtr texture );
|
||||
void publishDrawable( ResourceKey key, DrawablePtr drawable );
|
||||
void publishDrawable( std::string key, DrawablePtr drawable );
|
||||
|
||||
TexturePtr findTexture( const ResourceKey& key ) const;
|
||||
TexturePtr findTexture( const std::string& key ) const;
|
||||
DrawablePtr findDrawable( const ResourceKey& key ) const;
|
||||
DrawablePtr findDrawable( const std::string& key ) const;
|
||||
|
||||
bool erase( const ResourceKey& key );
|
||||
bool erase( const std::string& key );
|
||||
bool eraseDrawable( const ResourceKey& key );
|
||||
bool eraseDrawable( const std::string& key );
|
||||
void clear();
|
||||
std::size_t size() const;
|
||||
|
||||
private:
|
||||
mutable System::Mutex mMutex;
|
||||
UnorderedMap<std::string, TexturePtr> mTextures;
|
||||
UnorderedMap<std::string, DrawablePtr> mDrawables;
|
||||
};
|
||||
|
||||
}} // namespace EE::Graphics
|
||||
|
||||
@@ -18,13 +18,19 @@ class EE_API ResourceScope {
|
||||
|
||||
TexturePtr findTexture( const ResourceKey& key ) const;
|
||||
TexturePtr findTexture( const std::string& key ) const;
|
||||
DrawablePtr findDrawableSource( const ResourceKey& key ) const;
|
||||
DrawablePtr findDrawableSource( const std::string& key ) const;
|
||||
DrawablePtr findDrawable( const std::string& name, bool firstSearchSprite = false ) const;
|
||||
DrawablePtr findDrawable( const Uint32& id ) const;
|
||||
|
||||
void publishLocal( ResourceKey key, TexturePtr texture );
|
||||
void publishLocal( std::string key, TexturePtr texture );
|
||||
void publishLocalDrawable( ResourceKey key, DrawablePtr drawable );
|
||||
void publishLocalDrawable( std::string key, DrawablePtr drawable );
|
||||
bool eraseLocal( const ResourceKey& key );
|
||||
bool eraseLocal( const std::string& key );
|
||||
bool eraseLocalDrawable( const ResourceKey& key );
|
||||
bool eraseLocalDrawable( const std::string& key );
|
||||
void clearLocal();
|
||||
|
||||
void importCatalog( ResourceCatalogPtr catalog );
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef EE_UICUITHEME_HPP
|
||||
#define EE_UICUITHEME_HPP
|
||||
|
||||
#include <eepp/graphics/resourcecatalog.hpp>
|
||||
#include <eepp/system/resourcemanager.hpp>
|
||||
#include <eepp/ui/base.hpp>
|
||||
#include <eepp/ui/css/stylesheet.hpp>
|
||||
@@ -87,6 +88,8 @@ class EE_API UITheme : protected ResourceManagerMulti<UISkin> {
|
||||
|
||||
UIIconTheme* getIconTheme() const;
|
||||
|
||||
const Graphics::ResourceCatalogPtr& getResourceCatalog() const;
|
||||
|
||||
const std::string& getStyleSheetPath() const;
|
||||
|
||||
void setStyleSheetPath( const std::string& styleSheetPath );
|
||||
@@ -103,6 +106,7 @@ class EE_API UITheme : protected ResourceManagerMulti<UISkin> {
|
||||
CSS::StyleSheet mStyleSheet;
|
||||
std::string mStyleSheetPath;
|
||||
UIIconTheme* mIconTheme;
|
||||
Graphics::ResourceCatalogPtr mResourceCatalog;
|
||||
|
||||
void setTextureAtlas( Graphics::TextureAtlas* SG );
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef EE_UICTHEMEMANAGER
|
||||
#define EE_UICTHEMEMANAGER
|
||||
|
||||
#include <eepp/graphics/resourcescope.hpp>
|
||||
#include <eepp/ui/base.hpp>
|
||||
#include <eepp/ui/uitheme.hpp>
|
||||
|
||||
@@ -14,6 +15,16 @@ class EE_API UIThemeManager : public ResourceManager<UITheme> {
|
||||
|
||||
virtual ~UIThemeManager();
|
||||
|
||||
virtual UITheme* add( UITheme* theme );
|
||||
|
||||
bool remove( UITheme* theme, bool destroy = true );
|
||||
|
||||
bool removeById( const String::HashType& id, bool destroy = true );
|
||||
|
||||
bool removeByName( const std::string& name, bool destroy = true );
|
||||
|
||||
UIThemeManager* setResourceScope( Graphics::ResourceScopePtr resourceScope );
|
||||
|
||||
UIThemeManager* setDefaultFont( Font* Font );
|
||||
|
||||
Font* getDefaultFont() const;
|
||||
@@ -72,6 +83,7 @@ class EE_API UIThemeManager : public ResourceManager<UITheme> {
|
||||
bool mTooltipFollowMouse;
|
||||
|
||||
Sizei mCursorSize;
|
||||
Graphics::ResourceScopePtr mResourceScope;
|
||||
|
||||
UIThemeManager();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user