soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SStackView.h
Go to the documentation of this file.
1/**
2 * @file SStackView.h
3 * @brief Definition of the SStackView and related classes.
4 * @version v1.0
5 * @author soui
6 * @date 2014-07-08
7 *
8 * @copyright Copyright (C) 2014-2050 SOUI团队
9 * All rights reserved.
10 */
11
12#ifndef __SSTACKVIEW__H__
13#define __SSTACKVIEW__H__
14
16#include <interface/SCtrl-i.h>
17#include <core/SWnd.h>
18#include <proxy/SWindowProxy.h>
19
20SNSBEGIN
21
22class SStackView;
23/**
24 * @class SViewSwitchAnimator
25 * @brief Animator for switching views in SStackView.
26 *
27 * This class handles the animation when switching between views in an SStackView.
28 */
29class SOUI_EXP SViewSwitchAnimator : public TValueAnimator<float> {
30 DEF_SOBJECT(TValueAnimator<float>, L"ViewSwitchAnimator")
31
32 public:
33 /**
34 * @brief Constructor for SViewSwitchAnimator.
35 * @param pOwner Pointer to the owner SStackView.
36 */
38 : TValueAnimator<float>(0.f, 1.f)
39 , m_pOwner(pOwner)
40 , m_iFrom(-1)
41 , m_iTo(-1)
42 , m_isOwnerResize(FALSE)
43 {
44 }
45
46 /**
47 * @brief Clones the animator.
48 * @return Pointer to the cloned animator.
49 */
50 STDMETHOD_(IValueAnimator *, clone)(THIS) SCONST OVERRIDE
51 {
52 return NULL;
53 }
54
55 /**
56 * @brief Evaluates the value at a given fraction.
57 * @param fraction The fraction of the animation.
58 */
59 STDMETHOD_(void, onEvaluateValue)(THIS_ float fraction) OVERRIDE;
60
61 /**
62 * @brief Starts the animation.
63 * @param pTimerlineMgr Pointer to the timeline handlers manager.
64 */
65 STDMETHOD_(void, start)(THIS_ ITimelineHandlersMgr *pTimerlineMgr) OVERRIDE;
66
67 /**
68 * @brief Sets the starting child index.
69 * @param iChild The starting child index.
70 */
71 void SetFrom(int iChild)
72 {
73 m_iFrom = iChild;
74 }
75
76 /**
77 * @brief Gets the starting child index.
78 * @return The starting child index.
79 */
80 int GetFrom() const
81 {
82 return m_iFrom;
83 }
84
85 /**
86 * @brief Sets the ending child index.
87 * @param iChild The ending child index.
88 */
89 void SetTo(int iChild)
90 {
91 m_iTo = iChild;
92 }
93
94 /**
95 * @brief Gets the ending child index.
96 * @return The ending child index.
97 */
98 int GetTo() const
99 {
100 return m_iTo;
101 }
102
103 /**
104 * @brief Handles owner resize.
105 */
106 void OnOwnerResize();
107
108 /**
109 * @brief Sets the owner size range.
110 * @param szFrom The starting size.
111 * @param szTo The ending size.
112 */
113 void SetOwnerSizeRange(SIZE szFrom, SIZE szTo);
114
115 /**
116 * @brief Checks if owner resize is enabled.
117 * @return TRUE if owner resize is enabled, otherwise FALSE.
118 */
119 BOOL IsOwnerResize() const
120 {
121 return m_isOwnerResize;
122 }
123
124 /**
125 * @brief Disables owner resize.
126 */
128 {
129 m_isOwnerResize = FALSE;
130 }
131
132 /**
133 * @brief Gets the owner size.
134 * @return The owner size.
135 */
136 SIZE GetOwnerSize() const;
137
138 /**
139 * @brief Gets the animation style.
140 * @return The animation style.
141 */
142 StackViewAniStyle GetAniStyle() const
143 {
144 return m_aniStyle;
145 }
146
147 protected:
148 /**
149 * @brief Initializes the evaluators.
150 */
151 void initEvaluator();
152
153 SStackView *m_pOwner; /**< Pointer to the owner SStackView. */
154 int m_iFrom, m_iTo; /**< Indices of the starting and ending children. */
155 BOOL m_bVertAni; /**< Flag indicating vertical animation. */
156 StackViewAniStyle m_aniStyle; /**< Animation style. */
157
158 SAutoRefPtr<IWindow> m_pFrom; /**< Pointer to the starting child window. */
159 SAutoRefPtr<IWindow> m_pTo; /**< Pointer to the ending child window. */
160
161 TypeEvaluator<RECT> m_evalRcFrom, m_evalRcTo; /**< Evaluators for rectangle animations. */
162 TypeEvaluator<BYTE> m_evalAlphaFrom, m_evalAlphaTo; /**< Evaluators for alpha animations. */
163 TypeEvaluator<SIZE> m_evalOwnerSize; /**< Evaluator for owner size animations. */
164 BOOL m_isOwnerResize; /**< Flag indicating if owner resize is enabled. */
165};
166
167/**
168 * @class SStackPage
169 * @brief A page within a stack view.
170 *
171 * This class represents a page within an SStackView, which can have animation styles.
172 */
173class SOUI_EXP SStackPage : public SWindow {
174 DEF_SOBJECT(SWindow, L"stackPage")
175
176 public:
177 /**
178 * @brief Constructor for SStackPage.
179 */
181 : m_bVertAni(FALSE)
182 , m_aniStyle(kAniNone)
183 {
184 }
185
186 public:
187 /**
188 * @brief Gets the animation style.
189 * @return The animation style.
190 */
191 StackViewAniStyle GetAnimateStyle() const
192 {
193 return m_aniStyle;
194 }
195
196 /**
197 * @brief Checks if vertical animation is enabled.
198 * @return TRUE if vertical animation is enabled, otherwise FALSE.
199 */
200 BOOL IsVertAnimate() const
201 {
202 return m_bVertAni;
203 }
204
205 public:
206 SOUI_ATTRS_BEGIN()
207 ATTR_BOOL(L"vertical", m_bVertAni, FALSE) /**< Flag indicating vertical animation. */
208 ATTR_ENUM_BEGIN(L"aniType", StackViewAniStyle, FALSE)
209 ATTR_ENUM_VALUE(L"none", kAniNone) /**< No animation. */
210 ATTR_ENUM_VALUE(L"fade", kFadeInOut) /**< Fade in/out animation. */
211 ATTR_ENUM_VALUE(L"move", kMoveInOut) /**< Move in/out animation. */
212 ATTR_ENUM_VALUE(L"push", kPushInOut) /**< Push in/out animation. */
213 ATTR_ENUM_END(m_aniStyle)
214 SOUI_ATTRS_END()
215
216 protected:
217 BOOL m_bVertAni; /**< Flag indicating vertical animation. */
218 StackViewAniStyle m_aniStyle; /**< Animation style. */
219};
220
221/**
222 * @class SStackView
223 * @brief A stack view that can contain multiple pages.
224 *
225 * This class represents a stack view that can switch between multiple pages with animations.
226 */
227class SOUI_EXP SStackView
228 : public TWindowProxy<IStackView>
229 , public IAnimatorListener {
230 friend class SViewSwitchAnimator;
231 DEF_SOBJECT(SWindow, L"stack")
232
233 public:
234 /**
235 * @brief Constructor for SStackView.
236 */
237 SStackView(void);
238
239 /**
240 * @brief Destructor for SStackView.
241 */
242 ~SStackView(void);
243
244 public:
245 /**
246 * @brief Selects a page.
247 * @param iView The index of the page to select.
248 * @param enableAnimate Flag indicating if animation should be enabled.
249 * @return TRUE if successful, otherwise FALSE.
250 */
251 STDMETHOD_(BOOL, SelectPage)(THIS_ int iView, BOOL enableAnimate DEF_VAL(TRUE)) OVERRIDE;
252
253 /**
254 * @brief Sets the animation style.
255 * @param aniStyle The animation style.
256 */
257 STDMETHOD_(void, SetAniStyle)(THIS_ StackViewAniStyle aniStyle) OVERRIDE;
258
259 /**
260 * @brief Sets the animation direction.
261 * @param bVert Flag indicating vertical animation.
262 */
263 STDMETHOD_(void, SetAniDir)(THIS_ BOOL bVert) OVERRIDE;
264
265 /**
266 * @brief Gets the selected page.
267 * @return Pointer to the selected page.
268 */
269 STDMETHOD_(IWindow *, GetSelPage)(CTHIS) SCONST OVERRIDE;
270
271 /**
272 * @brief Gets a page by index.
273 * @param iPage The index of the page.
274 * @return Pointer to the page.
275 */
276 STDMETHOD_(IWindow *, GetPage)(CTHIS_ int iPage) SCONST OVERRIDE;
277
278 public:
279 /**
280 * @brief Gets a child window by index.
281 * @param iChild The index of the child window.
282 * @return Pointer to the child window.
283 */
284 STDMETHOD_(IWindow *, GetIChild)(THIS_ int iChild) SCONST OVERRIDE;
285
286 /**
287 * @brief Updates the positions of child windows.
288 */
289 STDMETHOD_(void, UpdateChildrenPosition)(THIS) OVERRIDE;
290
291 protected:
292 /**
293 * @brief Handles the start of an animation.
294 * @param pAnimator Pointer to the animator.
295 */
296 STDMETHOD_(void, onAnimationStart)(THIS_ IValueAnimator *pAnimator) OVERRIDE
297 {
298 }
299
300 /**
301 * @brief Handles the repetition of an animation.
302 * @param pAnimator Pointer to the animator.
303 */
304 STDMETHOD_(void, onAnimationRepeat)(THIS_ IValueAnimator *pAnimator) OVERRIDE
305 {
306 }
307
308 /**
309 * @brief Handles the end of an animation.
310 * @param pAnimator Pointer to the animator.
311 */
312 STDMETHOD_(void, onAnimationEnd)(THIS_ IValueAnimator *pAnimator) OVERRIDE;
313
314 public:
315 SOUI_ATTRS_BEGIN()
316 ATTR_INT(L"curSel", m_iSel, FALSE) /**< Index of the currently selected page. */
317 ATTR_BOOL(L"vertical", m_bVertAni, FALSE) /**< Flag indicating vertical animation. */
318 ATTR_ENUM_BEGIN(L"aniType", StackViewAniStyle, FALSE)
319 ATTR_ENUM_VALUE(L"none", kAniNone) /**< No animation. */
320 ATTR_ENUM_VALUE(L"fade", kFadeInOut) /**< Fade in/out animation. */
321 ATTR_ENUM_VALUE(L"move", kMoveInOut) /**< Move in/out animation. */
322 ATTR_ENUM_VALUE(L"push", kPushInOut) /**< Push in/out animation. */
323 ATTR_ENUM_END(m_aniStyle)
324 ATTR_BOOL(L"samePageSize", m_isSamePageSize, FALSE) /**< Flag indicating if all pages have the same size. */
325 ATTR_CHAIN_CLASS(__baseCls) /**< Chain attributes to base class. */
326 ATTR_CHAIN(m_animator, 0) /**< Chain attributes to animator. */
327 SOUI_ATTRS_BREAK()
328
329 protected:
330 /**
331 * @brief Handles the destruction of the window.
332 */
333 void OnDestroy();
334
335 /**
336 * @brief Handles the size change of the window.
337 * @param nType The type of size change.
338 * @param size The new size.
339 */
340 void OnSize(UINT nType, CSize size);
341
342 SOUI_MSG_MAP_BEGIN()
343 MSG_WM_DESTROY(OnDestroy)
344 MSG_WM_SIZE(OnSize)
345 SOUI_MSG_MAP_END()
346
347 protected:
348 /**
349 * @brief Creates child windows from an XML node.
350 * @param xmlNode The XML node containing the child window definitions.
351 * @return TRUE if successful, otherwise FALSE.
352 */
353 BOOL CreateChildren(SXmlNode xmlNode) override;
354
355 /**
356 * @brief Measures the size of child windows.
357 * @param nParentWid The width of the parent window.
358 * @param nParentHei The height of the parent window.
359 * @return The measured size.
360 */
361 SIZE MeasureChildren(int nParentWid, int nParentHei) override;
362
363 /**
364 * @brief Handles the change of the container.
365 * @param pOldContainer Pointer to the old container.
366 * @param pNewContainer Pointer to the new container.
367 */
368 void OnContainerChanged(ISwndContainer *pOldContainer, ISwndContainer *pNewContainer) override;
369
370 /**
371 * @brief Handles the insertion of a child window.
372 * @param pChild Pointer to the child window.
373 */
374 void OnAfterInsertChild(SWindow *pChild) override;
375
376 /**
377 * @brief Handles the removal of a child window.
378 * @param pChild Pointer to the child window.
379 */
380 void OnAfterRemoveChild(SWindow *pChild) override;
381
382 protected:
383 /**
384 * @brief Builds the array of child windows.
385 * @param updateSel Flag indicating if the selection should be updated.
386 */
387 void BuildChildsArray(BOOL updateSel);
388
389 /**
390 * @brief Gets the animation style of a child.
391 * @param iChild The index of the child.
392 * @return The animation style.
393 */
394 StackViewAniStyle GetChildAnimateStyle(int iChild) const;
395
396 /**
397 * @brief Checks if vertical animation is enabled for a child.
398 * @param iChild The index of the child.
399 * @return TRUE if vertical animation is enabled, otherwise FALSE.
400 */
401 BOOL IsVertChildAnimate(int iChild) const;
402
403 /**
404 * @brief Gets the size of a child window.
405 * @param pPage Pointer to the child window.
406 * @return The size of the child window.
407 */
408 CSize GetChildSize(IWindow *pPage) const;
409
410 protected:
411 int m_iSel; /**< Index of the currently selected page. */
412 SViewSwitchAnimator m_animator; /**< Animator for view switching. */
413 SArray<SWindow *> m_childs; /**< Array of child windows. */
414
415 BOOL m_bVertAni; /**< Flag indicating vertical animation. */
416 StackViewAniStyle m_aniStyle; /**< Animation style. */
417 BOOL m_isSamePageSize; /**< Flag indicating if all pages have the same size. */
418};
419
420SNSEND
421
422#endif // __SSTACKVIEW__H__
Provides a simple timing engine for running animations which calculate animated values and set them o...
SOUI基础DUI窗口模块
Smart pointer class for managing COM-style reference-counted objects.
BOOL m_bVertAni
Definition SStackView.h:217
BOOL IsVertAnimate() const
Checks if vertical animation is enabled.
Definition SStackView.h:200
StackViewAniStyle GetAnimateStyle() const
Gets the animation style.
Definition SStackView.h:191
StackViewAniStyle m_aniStyle
Definition SStackView.h:218
SStackPage()
Constructor for SStackPage.
Definition SStackView.h:180
A stack view that can contain multiple pages.
Definition SStackView.h:229
BOOL IsVertChildAnimate(int iChild) const
Checks if vertical animation is enabled for a child.
SIZE MeasureChildren(int nParentWid, int nParentHei) override
Measures the size of child windows.
IWindow * GetIChild(int iChild) SCONST OVERRIDE
Gets a child window by index.
void OnSize(UINT nType, CSize size)
Handles the size change of the window.
void OnDestroy()
Handles the destruction of the window.
SViewSwitchAnimator m_animator
Definition SStackView.h:412
BOOL m_bVertAni
Definition SStackView.h:415
IWindow * GetSelPage() SCONST OVERRIDE
Gets the selected page.
void BuildChildsArray(BOOL updateSel)
Builds the array of child windows.
BOOL SelectPage(int iView, BOOL enableAnimate=TRUE) OVERRIDE
Selects a page.
StackViewAniStyle GetChildAnimateStyle(int iChild) const
Gets the animation style of a child.
void onAnimationRepeat(IValueAnimator *pAnimator) OVERRIDE
Handles the repetition of an animation.
Definition SStackView.h:304
StackViewAniStyle m_aniStyle
Definition SStackView.h:416
BOOL CreateChildren(SXmlNode xmlNode) override
Creates child windows from an XML node.
SArray< SWindow * > m_childs
Definition SStackView.h:413
void OnContainerChanged(ISwndContainer *pOldContainer, ISwndContainer *pNewContainer) override
Handles the change of the container.
void OnAfterRemoveChild(SWindow *pChild) override
Handles the removal of a child window.
void onAnimationStart(IValueAnimator *pAnimator) OVERRIDE
Handles the start of an animation.
Definition SStackView.h:296
void SetAniStyle(StackViewAniStyle aniStyle) OVERRIDE
Sets the animation style.
void OnAfterInsertChild(SWindow *pChild) override
Handles the insertion of a child window.
SStackView(void)
Constructor for SStackView.
Definition SStackView.cpp:6
CSize GetChildSize(IWindow *pPage) const
Gets the size of a child window.
BOOL m_isSamePageSize
Definition SStackView.h:417
IWindow * GetPage(int iPage) SCONST OVERRIDE
Gets a page by index.
void SetAniDir(BOOL bVert) OVERRIDE
Sets the animation direction.
void UpdateChildrenPosition() OVERRIDE
Updates the positions of child windows.
StackViewAniStyle m_aniStyle
Definition SStackView.h:156
int GetTo() const
Gets the ending child index.
Definition SStackView.h:98
SViewSwitchAnimator(SStackView *pOwner)
Constructor for SViewSwitchAnimator.
Definition SStackView.h:37
void DisableOwnerResize()
Disables owner resize.
Definition SStackView.h:127
int GetFrom() const
Gets the starting child index.
Definition SStackView.h:80
TypeEvaluator< SIZE > m_evalOwnerSize
Definition SStackView.h:163
IValueAnimator * clone() SCONST OVERRIDE
Clones the animator.
Definition SStackView.h:50
void SetTo(int iChild)
Sets the ending child index.
Definition SStackView.h:89
SStackView * m_pOwner
Definition SStackView.h:153
void SetFrom(int iChild)
Sets the starting child index.
Definition SStackView.h:71
StackViewAniStyle GetAniStyle() const
Gets the animation style.
Definition SStackView.h:142
TypeEvaluator< RECT > m_evalRcTo
Definition SStackView.h:161
SAutoRefPtr< IWindow > m_pFrom
Definition SStackView.h:158
BOOL IsOwnerResize() const
Checks if owner resize is enabled.
Definition SStackView.h:119
SAutoRefPtr< IWindow > m_pTo
Definition SStackView.h:159
TypeEvaluator< BYTE > m_evalAlphaTo
Definition SStackView.h:162
SWindow()
Constructor.
Definition Swnd.cpp:104
Class representing an XML node.
Definition SXml.h:352
TValueAnimator(float from, float to)
Template class for evaluating interpolated values between a start and end value.
SOUI Window Container Interface.