soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SSkinObjBase.h
1#ifndef __SSKINOBJBASE__H__
2#define __SSKINOBJBASE__H__
3
5#include <interface/sxml-i.h>
6#include <helper/obj-ref-impl.hpp>
7#include <sobject/Sobject.hpp>
8#include <souicoll.h>
9
10SNSBEGIN
11
12/**
13 * @class SState2Index
14 * @brief Maps skin states to indices.
15 *
16 * This class provides functionality to map skin states to their corresponding indices.
17 * It can be initialized from an XML node and supports default state-to-index mappings.
18 */
19class SOUI_EXP SState2Index {
20 public:
21 /**
22 * @brief Default constructor.
23 */
25 {
26 }
27
28 /**
29 * @brief Copy constructor.
30 * @param src Source SState2Index object to copy from.
31 */
32 SState2Index(const SState2Index &src);
33
34 /**
35 * @brief Gets the index for a given state.
36 * @param dwState State to get the index for.
37 * @param checkAsPushdown Flag to check if the state should be treated as pushdown.
38 * @return Index corresponding to the state.
39 */
40 int GetIndex(DWORD dwState, bool checkAsPushdown) const;
41
42 /**
43 * @brief Initializes the state-to-index mapping from an XML node.
44 * @param pNode Pointer to the XML node containing the state mappings.
45 * @return TRUE if initialization is successful, FALSE otherwise.
46 */
47 BOOL Init(IXmlNode *pNode);
48
49 /**
50 * @brief Gets the default index for a given state.
51 * @param dwState State to get the default index for.
52 * @param checkAsPushdown Flag to check if the state should be treated as pushdown.
53 * @return Default index corresponding to the state.
54 */
55 static int GetDefIndex(DWORD dwState, bool checkAsPushdown = false);
56
57 /**
58 * @brief Converts a string representation of a state to a DWORD value.
59 * @param strState String representation of the state.
60 * @return DWORD value representing the state.
61 */
62 static DWORD String2State(const SStringW &strState);
63
64 protected:
65 SMap<DWORD, int> m_mapOfStates; // Map of states to indices.
66};
67
68/**
69 * @class SSkinObjBase
70 * @brief Base class for skin objects.
71 *
72 * This class provides a base implementation for skin objects, which are used to define
73 * the visual appearance of UI elements. It includes methods for drawing, scaling, and
74 * colorizing skins, as well as managing state-to-index mappings.
75 */
76class SOUI_EXP SSkinObjBase : public TObjRefImpl<SObjectImpl<ISkinObj>> {
77 DEF_SOBJECT(SObjectImpl<ISkinObj>, L"skinObjBase")
78
79 public:
80 /**
81 * @brief Constructor.
82 */
84
85 /**
86 * @brief Gets the name of the skin object.
87 * @return Name of the skin object.
88 */
89 STDMETHOD_(LPCWSTR, GetName)(THIS) SCONST OVERRIDE;
90
91 /**
92 * @brief Draws the skin by state with alpha blending.
93 * @param pRT Pointer to the render target.
94 * @param rcDraw Rectangle to draw in.
95 * @param dwState State to draw.
96 * @param byAlpha Alpha value for transparency.
97 */
98 STDMETHOD_(void, DrawByState2)
99 (THIS_ IRenderTarget *pRT, LPCRECT rcDraw, DWORD dwState, BYTE byAlpha) SCONST OVERRIDE;
100
101 /**
102 * @brief Draws the skin by state without alpha blending.
103 * @param pRT Pointer to the render target.
104 * @param rcDraw Rectangle to draw in.
105 * @param dwState State to draw.
106 */
107 STDMETHOD_(void, DrawByState)
108 (THIS_ IRenderTarget *pRT, LPCRECT rcDraw, DWORD dwState) SCONST OVERRIDE;
109
110 /**
111 * @brief Draws the skin by index with alpha blending.
112 * @param pRT Pointer to the render target.
113 * @param rcDraw Rectangle to draw in.
114 * @param iState Index of the state to draw.
115 * @param byAlpha Alpha value for transparency.
116 */
117 STDMETHOD_(void, DrawByIndex2)
118 (THIS_ IRenderTarget *pRT, LPCRECT rcDraw, int iState, BYTE byAlpha) SCONST OVERRIDE;
119
120 /**
121 * @brief Draws the skin by index without alpha blending.
122 * @param pRT Pointer to the render target.
123 * @param rcDraw Rectangle to draw in.
124 * @param iState Index of the state to draw.
125 */
126 STDMETHOD_(void, DrawByIndex)
127 (THIS_ IRenderTarget *pRT, LPCRECT rcDraw, int iState) SCONST OVERRIDE;
128
129 /**
130 * @brief Gets the size of the skin.
131 * @return Size of the skin.
132 */
133 STDMETHOD_(SIZE, GetSkinSize)(THIS) SCONST OVERRIDE;
134
135 /**
136 * @brief Gets the number of states supported by the skin.
137 * @return Number of states.
138 */
139 STDMETHOD_(int, GetStates)(THIS) SCONST OVERRIDE;
140
141 /**
142 * @brief Gets the alpha value of the skin.
143 * @return Alpha value.
144 */
145 STDMETHOD_(BYTE, GetAlpha)(THIS) SCONST OVERRIDE;
146
147 /**
148 * @brief Sets the alpha value of the skin.
149 * @param byAlpha Alpha value to set.
150 */
151 STDMETHOD_(void, SetAlpha)(THIS_ BYTE byAlpha) OVERRIDE;
152
153 /**
154 * @brief Gets the scale factor of the skin.
155 * @return Scale factor.
156 */
157 STDMETHOD_(int, GetScale)(THIS) SCONST OVERRIDE;
158
159 /**
160 * @brief Sets the scale factor of the skin.
161 * @param scale Scale factor to set.
162 */
163 STDMETHOD_(void, SetScale)(THIS_ int scale) OVERRIDE;
164
165 /**
166 * @brief Scales the skin.
167 * @param nScale Scale factor.
168 * @return Pointer to the scaled skin object.
169 */
170 STDMETHOD_(ISkinObj *, Scale)(THIS_ int nScale) OVERRIDE;
171
172 /**
173 * @brief Applies colorization to the skin.
174 * @param cr Color to apply for colorization.
175 */
176 STDMETHOD_(void, OnColorize)(THIS_ COLORREF cr) OVERRIDE;
177
178 /**
179 * @brief Converts a state to its corresponding index.
180 * @param dwState State to convert.
181 * @return Index corresponding to the state.
182 */
183 int State2Index(DWORD dwState) const;
184
185 public:
186 SOUI_ATTRS_BEGIN()
187 ATTR_INT(L"alpha", m_byAlpha, TRUE) // Skin transparency
188 ATTR_BOOL(L"enableColorize", m_bEnableColorize, TRUE)
189 ATTR_BOOL(L"checkAsPushdown", m_checkAsPushdown, TRUE)
190 ATTR_INT(L"scale", m_nScale, FALSE)
191 ATTR_BOOL(L"enableScale", m_bEnableScale, TRUE)
192 SOUI_ATTRS_END()
193
194 protected:
195 /**
196 * @brief Called when initialization is finished.
197 * @param pNode Pointer to the XML node.
198 */
199 STDMETHOD_(void, OnInitFinished)(THIS_ IXmlNode *pNode) OVERRIDE;
200
201 /**
202 * @brief Scales the skin object.
203 * @param pObj Pointer to the skin object.
204 * @param nScale Scale factor.
205 */
206 virtual void _Scale(ISkinObj *pObj, int nScale);
207
208 /**
209 * @brief Draws the skin by state with alpha blending.
210 * @param pRT Pointer to the render target.
211 * @param rcDraw Rectangle to draw in.
212 * @param dwState State to draw.
213 * @param byAlpha Alpha value for transparency.
214 */
215 virtual void _DrawByState(IRenderTarget *pRT, LPCRECT rcDraw, DWORD dwState, BYTE byAlpha) const;
216
217 /**
218 * @brief Draws the skin by index with alpha blending.
219 * @param pRT Pointer to the render target.
220 * @param rcDraw Rectangle to draw in.
221 * @param iState Index of the state to draw.
222 * @param byAlpha Alpha value for transparency.
223 */
224 virtual void _DrawByIndex(IRenderTarget *pRT, LPCRECT rcDraw, int iState, BYTE byAlpha) const = 0;
225
226 protected:
227 BYTE m_byAlpha; // Alpha value for transparency.
228 COLORREF m_crColorize; // Color for colorization.
229 bool m_bEnableColorize; // Flag to enable colorization.
230 int m_nScale; // Scale factor.
231 bool m_bEnableScale; // Flag to enable scaling.
232 bool m_checkAsPushdown; // Flag to check if the state should be treated as pushdown.
233 SState2Index m_state2Index; // State-to-index mapping.
234};
235
236SNSEND
237#endif // __SSKINOBJBASE__H__
Interface for Skin Objects.
int State2Index(DWORD dwState) const
Converts a state to its corresponding index.
LPCWSTR GetName() SCONST OVERRIDE
Gets the name of the skin object.
virtual void _DrawByState(IRenderTarget *pRT, LPCRECT rcDraw, DWORD dwState, BYTE byAlpha) const
Draws the skin by state with alpha blending.
void DrawByIndex(IRenderTarget *pRT, LPCRECT rcDraw, int iState) SCONST OVERRIDE
Draws the skin by index without alpha blending.
int GetStates() SCONST OVERRIDE
Gets the number of states supported by the skin.
virtual void _DrawByIndex(IRenderTarget *pRT, LPCRECT rcDraw, int iState, BYTE byAlpha) const =0
Draws the skin by index with alpha blending.
int GetScale() SCONST OVERRIDE
Gets the scale factor of the skin.
BYTE GetAlpha() SCONST OVERRIDE
Gets the alpha value of the skin.
SIZE GetSkinSize() SCONST OVERRIDE
Gets the size of the skin.
void OnColorize(COLORREF cr) OVERRIDE
Applies colorization to the skin.
void OnInitFinished(IXmlNode *pNode) OVERRIDE
Called when initialization is finished.
void DrawByState2(IRenderTarget *pRT, LPCRECT rcDraw, DWORD dwState, BYTE byAlpha) SCONST OVERRIDE
Draws the skin by state with alpha blending.
void SetAlpha(BYTE byAlpha) OVERRIDE
Sets the alpha value of the skin.
virtual void _Scale(ISkinObj *pObj, int nScale)
Scales the skin object.
void SetScale(int scale) OVERRIDE
Sets the scale factor of the skin.
void DrawByIndex2(IRenderTarget *pRT, LPCRECT rcDraw, int iState, BYTE byAlpha) SCONST OVERRIDE
Draws the skin by index with alpha blending.
ISkinObj * Scale(int nScale) OVERRIDE
Scales the skin.
SSkinObjBase()
Constructor.
void DrawByState(IRenderTarget *pRT, LPCRECT rcDraw, DWORD dwState) SCONST OVERRIDE
Draws the skin by state without alpha blending.
Maps skin states to indices.
SState2Index()
Default constructor.
A class representing an ASCII string.
Definition sstringw.h:96
Interface for rendering target objects.
Definition SRender-i.h:1440
Interface for Skin Objects.
Definition SSkinobj-i.h:29
Interface for XML nodes.
Definition sxml-i.h:128