soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SSkinPool.h
Go to the documentation of this file.
1#ifndef __SSKINPOOL__H__
2#define __SSKINPOOL__H__
3
4#include <core/SSingletonMap.h>
5#include <interface/SSkinPool-i.h>
6#include <helper/obj-ref-impl.hpp>
7
8SNSBEGIN
9
10/**
11 * @file SSkinPool.h
12 * @brief Skin Object Pool Management
13 * @version v1.0
14 * @author SOUI团队
15 * @date 2014-05-28
16 *
17 * @details Manages a pool of skin objects, providing functionality to load, retrieve, and manage skins.
18 */
19
20// System built-in skin names
21enum SYS_SKIN
22{
23 SKIN_SYS_CHECKBOX = 0, // L"_skin.sys.checkbox"
24 SKIN_SYS_RADIO, // L"_skin.sys.radio"
25 SKIN_SYS_FOCUSCHECKBOX, // L"_skin.sys.focuscheckbox"
26 SKIN_SYS_FOCUSRADIO, // L"_skin.sys.focusradio"
27 SKIN_SYS_BTN_NORMAL, // L"_skin.sys.btn.normal"
28 SKIN_SYS_SCROLLBAR, // L"_skin.sys.scrollbar"
29 SKIN_SYS_BORDER, // L"_skin.sys.border"
30 SKIN_SYS_DROPBTN, // L"_skin.sys.dropbtn"
31 SKIN_SYS_TREE_TOGGLE, // L"_skin.sys.tree.toggle"
32 SKIN_SYS_TREE_CHECKBOX, // L"_skin.sys.tree.checkbox"
33 SKIN_SYS_TREE_LINES, // L"_skin.sys.tree.lines"
34 SKIN_SYS_TAB_PAGE, // L"_skin.sys.tab.page"
35 SKIN_SYS_HEADER, // L"_skin.sys.header"
36 SKIN_SYS_SPLIT_VERT, // L"_skin.sys.split.vert"
37 SKIN_SYS_SPLIT_HORZ, // L"_skin.sys.split.horz"
38 SKIN_SYS_PROG_BKGND, // L"_skin.sys.prog.bkgnd"
39 SKIN_SYS_PROG_BAR, // L"_skin.sys.prog.bar"
40 SKIN_SYS_VERT_PROG_BKGND, // L"_skin.sys.vert.prog.bkgnd"
41 SKIN_SYS_VERT_PROG_BAR, // L"_skin.sys.vert.prog.bar"
42 SKIN_SYS_SLIDER_THUMB, // L"_skin.sys.slider.thumb"
43
44 SKIN_SYS_BTN_CLOSE, // L"_skin.sys.btn.close"
45 SKIN_SYS_BTN_MINIMIZE, // L"_skin.sys.btn.minimize"
46 SKIN_SYS_BTN_MAXMIZE, // L"_skin.sys.btn.maxmize"
47 SKIN_SYS_BTN_RESTORE, // L"_skin.sys.btn.restore"
48
49 SKIN_SYS_MENU_CHECK, // L"_skin.sys.menu.check"
50 SKIN_SYS_MENU_SEP, // L"_skin.sys.menu.sep"
51 SKIN_SYS_MENU_ARROW, // L"_skin.sys.menu.arrow"
52 SKIN_SYS_MENU_BORDER, // L"_skin.sys.menu.border"
53 SKIN_SYS_MENU_SKIN, // L"_skin.sys.menu.skin"
54 SKIN_SYS_ICONS, // L"_skin.sys.icons"
55 SKIN_SYS_WND_BKGND, // L"_skin.sys.wnd.bkgnd"
56
57 SKIN_SYS_BTN_PREV,
58 SKIN_SYS_BTN_NEXT,
59 SKIN_SYS_SPIN_DOWN,
60 SKIN_SYS_SPIN_UP,
61
62 SKIN_SYS_SWITCH,
63 SKIN_SYS_SWITCH_BG,
64
65 SKIN_SYS_COUNT,
66};
67
68typedef ISkinObj *SSkinPtr;
69
70/**
71 * @struct SkinKey
72 * @brief Key for identifying a skin object in the pool.
73 */
74class SkinKey {
75 public:
76 SStringW strName; // Name of the skin
77 int scale; // Scale factor for the skin
78};
79
80/**
81 * @class CElementTraits<SkinKey>
82 * @brief Template specialization for SkinKey to provide hash and comparison functions.
83 */
84template <>
85class CElementTraits<SkinKey> : public CElementTraitsBase<SkinKey> {
86 public:
87 /**
88 * @brief Computes the hash value for a SkinKey.
89 * @param skinKey SkinKey object.
90 * @return Hash value.
91 */
92 static ULONG Hash(INARGTYPE skinKey)
93 {
94 ULONG nHash = CElementTraits<SStringW>::Hash(skinKey.strName);
95 nHash <<= 5;
96 nHash += skinKey.scale;
97 return nHash;
98 }
99
100 /**
101 * @brief Compares two SkinKey objects for equality.
102 * @param element1 First SkinKey object.
103 * @param element2 Second SkinKey object.
104 * @return TRUE if the objects are equal, FALSE otherwise.
105 */
106 static bool CompareElements(INARGTYPE element1, INARGTYPE element2)
107 {
108 return element1.strName == element2.strName && element1.scale == element2.scale;
109 }
110
111 /**
112 * @brief Compares two SkinKey objects in ordered manner.
113 * @param element1 First SkinKey object.
114 * @param element2 Second SkinKey object.
115 * @return Comparison result (-1 if element1 < element2, 0 if equal, 1 if element1 > element2).
116 */
117 static int CompareElementsOrdered(INARGTYPE element1, INARGTYPE element2)
118 {
119 int nRet = element1.strName.CompareNoCase(element2.strName);
120 if (nRet == 0)
121 nRet = element1.scale - element2.scale;
122 return nRet;
123 }
124};
125
126/**
127 * @class SSkinPool
128 * @brief Manages the mapping of skin names to ISkinObj objects.
129 *
130 * @details This class provides functionality to load, retrieve, and manage skin objects. It supports automatic scaling
131 * and maintains a pool of skin objects for efficient reuse.
132 */
133class SOUI_EXP SSkinPool
134 : public TObjRefImpl<ISkinPool>
135 , protected SCmnMap<SSkinPtr, SkinKey> {
136 public:
137 /**
138 * @brief Constructor.
139 * @param bAutoScale TRUE if automatic scaling is enabled, FALSE otherwise.
140 */
141 SSkinPool(BOOL bAutoScale = TRUE);
142
143 /**
144 * @brief Destructor.
145 */
146 virtual ~SSkinPool();
147
148 public:
149 /**
150 * @brief Retrieves a skin object by name and scale.
151 * @param strSkinName Name of the skin.
152 * @param nScale Scale factor for the skin.
153 * @return Pointer to the ISkinObj object, or nullptr if not found.
154 */
155 STDMETHOD_(ISkinObj *, GetSkin)(THIS_ LPCWSTR strSkinName, int nScale) OVERRIDE;
156
157 /**
158 * @brief Loads skins from an XML node.
159 * @param xmlNode XML node containing the skin definitions.
160 * @return Number of skins loaded.
161 */
162 STDMETHOD_(int, LoadSkins)(THIS_ IXmlNode *xmlNode) OVERRIDE;
163
164 /**
165 * @brief Adds a skin object to the pool.
166 * @param skin Pointer to the skin object to add.
167 * @return TRUE if the skin is successfully added, FALSE otherwise.
168 */
169 STDMETHOD_(BOOL, AddSkin)(THIS_ ISkinObj *skin) OVERRIDE;
170
171 /**
172 * @brief Removes a skin object from the pool.
173 * @param skin Pointer to the skin object to remove.
174 * @return TRUE if the skin is successfully removed, FALSE otherwise.
175 */
176 STDMETHOD_(BOOL, RemoveSkin)(THIS_ ISkinObj *skin) OVERRIDE;
177
178 /**
179 * @brief Removes all skin objects from the pool.
180 */
181 STDMETHOD_(void, RemoveAll)(THIS) OVERRIDE;
182
183 protected:
184 /**
185 * @brief Loads skins from an XML node.
186 * @param xmlNode XML node containing the skin definitions.
187 * @return Number of skins loaded.
188 */
189 int _LoadSkins(SXmlNode xmlNode);
190
191 /**
192 * @brief Loads a single skin from an XML node.
193 * @param xmlNode XML node containing the skin definition.
194 * @param nScale Scale factor for the skin.
195 * @return Pointer to the loaded ISkinObj object, or nullptr if loading fails.
196 */
197 ISkinObj *_LoadSkin(SXmlNode xmlNode, int nScale);
198
199 /**
200 * @brief Callback function called when a skin object is removed from the pool.
201 * @param obj Pointer to the removed skin object.
202 */
203 static void OnKeyRemoved(const SSkinPtr &obj);
204
205#ifdef _DEBUG
206 SMap<SkinKey, int> m_mapSkinUseCount; // Skin usage count map (debug only)
207#endif
208
209 BOOL m_bAutoScale; // Flag indicating if automatic scaling is enabled
210};
211
212SNSEND
213
214#endif // __SSKINPOOL__H__
static int CompareElementsOrdered(INARGTYPE element1, INARGTYPE element2)
Compares two SkinKey objects in ordered manner.
Definition SSkinPool.h:117
static bool CompareElements(INARGTYPE element1, INARGTYPE element2)
Compares two SkinKey objects for equality.
Definition SSkinPool.h:106
static ULONG Hash(INARGTYPE skinKey)
Computes the hash value for a SkinKey.
Definition SSkinPool.h:92
SCmnMap(void(*funOnKeyRemoved)(const SSkinPtr &)=NULL)
Definition SCmnMap.h:28
int _LoadSkins(SXmlNode xmlNode)
Loads skins from an XML node.
Definition SSkinPool.cpp:70
BOOL RemoveSkin(ISkinObj *skin) OVERRIDE
Removes a skin object from the pool.
static void OnKeyRemoved(const SSkinPtr &obj)
Callback function called when a skin object is removed from the pool.
ISkinObj * GetSkin(LPCWSTR strSkinName, int nScale) OVERRIDE
Retrieves a skin object by name and scale.
ISkinObj * _LoadSkin(SXmlNode xmlNode, int nScale)
Loads a single skin from an XML node.
Definition SSkinPool.cpp:36
void RemoveAll() OVERRIDE
Removes all skin objects from the pool.
BOOL AddSkin(ISkinObj *skin) OVERRIDE
Adds a skin object to the pool.
SSkinPool(BOOL bAutoScale=TRUE)
Constructor.
Definition SSkinPool.cpp:12
int LoadSkins(IXmlNode *xmlNode) OVERRIDE
Loads skins from an XML node.
Definition SSkinPool.cpp:95
A class representing an ASCII string.
Definition sstringw.h:96
Class representing an XML node.
Definition SXml.h:352
Key for identifying a skin object in the pool.
Definition SSkinPool.h:74
Interface for Skin Objects.
Definition SSkinobj-i.h:29
Interface for XML nodes.
Definition sxml-i.h:128