soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SSwitch.h
Go to the documentation of this file.
1/**
2 * @file SSwitch.h
3 * @brief Definition of the SSwitch class.
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 _SWITCH_H_
13#define _SWITCH_H_
14
15#include <core/SWnd.h>
16
17SNSBEGIN
18
19/**
20 * @class SSwitch
21 * @brief A switch control class derived from SWindow.
22 *
23 * This class represents a switch control that can be toggled between two states.
24 */
26 : public SWindow
27 , protected IAnimatorListener
28 , public IAnimatorUpdateListener {
29 DEF_SOBJECT(SWindow, L"switch")
30
31 public:
32 /**
33 * @brief Constructor for SSwitch.
34 */
35 SSwitch();
36
37 /**
38 * @brief Destructor for SSwitch.
39 */
40 ~SSwitch();
41
42 protected:
43 /**
44 * @brief Handles the start of an animation.
45 * @param pAnimator Pointer to the animator.
46 */
47 STDMETHOD_(void, onAnimationStart)(THIS_ IValueAnimator *pAnimator) override
48 {
49 }
50
51 /**
52 * @brief Handles the end of an animation.
53 * @param pAnimator Pointer to the animator.
54 */
55 STDMETHOD_(void, onAnimationEnd)(THIS_ IValueAnimator *pAnimator) override;
56
57 /**
58 * @brief Handles the repetition of an animation.
59 * @param pAnimator Pointer to the animator.
60 */
61 STDMETHOD_(void, onAnimationRepeat)(THIS_ IValueAnimator *pAnimator) override
62 {
63 }
64
65 /**
66 * @brief Handles the update of an animation.
67 * @param pAnimator Pointer to the animator.
68 */
69 STDMETHOD_(void, onAnimationUpdate)(THIS_ IValueAnimator *pAnimator) override;
70
71 protected: // SWindow's virtual functions
72 /**
73 * @brief Calculates the desired size of the control.
74 * @param psz Pointer to the SIZE structure to receive the desired size.
75 * @param nParentWid Width of the parent window.
76 * @param nParentHei Height of the parent window.
77 */
78 STDMETHOD_(void, GetDesiredSize)(THIS_ SIZE *psz, int nParentWid, int nParentHei) OVERRIDE;
79
80 /**
81 * @brief Determines whether the control needs to be redrawn when its state changes.
82 * @return TRUE if the control needs to be redrawn, otherwise FALSE.
83 */
85 {
86 return TRUE;
87 }
88
89 protected: // Message handling, similar to WTL and MFC
90 /**
91 * @brief Handles the paint event.
92 * @param pRT Pointer to the render target.
93 */
94 void OnPaint(IRenderTarget *pRT);
95
96 /**
97 * @brief Handles the left mouse button up event.
98 * @param nFlags Flags associated with the mouse event.
99 * @param point The position of the mouse cursor.
100 */
101 void OnLButtonUp(UINT nFlags, CPoint point);
102
103 /**
104 * @brief Handles the key down event.
105 * @param nChar The virtual-key code of the key.
106 * @param nRepCnt The repeat count for the key.
107 * @param nFlags Flags indicating the key state.
108 */
109 void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
110
111 // SOUI control message map
112 SOUI_MSG_MAP_BEGIN()
113 MSG_WM_PAINT_EX(OnPaint) /**< Window paint message. */
114 MSG_WM_LBUTTONUP(OnLButtonUp) /**< Left mouse button up message. */
115 MSG_WM_KEYDOWN(OnKeyDown) /**< Key down message. */
116 SOUI_MSG_MAP_END()
117
118 SAutoRefPtr<ISkinObj> m_pSkin; /**< Skin object for the switch. */
119 SAutoRefPtr<ISkinObj> m_pSkinForce; /**< Skin object for the forced state. */
120
121 /**
122 * @brief Handles the 'animator' attribute.
123 * @param value The attribute value.
124 * @param bLoading Flag indicating if the attribute is being loaded.
125 * @return Result of the attribute handling.
126 */
127 HRESULT OnAttrAnimator(const SStringW &value, BOOL bLoading);
128
129 /**
130 * @brief Handles the 'checked' attribute.
131 * @param strValue The attribute value.
132 * @param bLoading Flag indicating if the attribute is being loaded.
133 * @return Result of the attribute handling.
134 */
135 HRESULT OnAttrCheck(const SStringW &strValue, BOOL bLoading);
136
137 SOUI_ATTRS_BEGIN()
138 ATTR_SKIN(L"skin", m_pSkin, TRUE) /**< Skin object for the switch. */
139 ATTR_SKIN(L"skinforce", m_pSkinForce, TRUE) /**< Skin object for the forced state. */
140 ATTR_CUSTOM(L"animator", OnAttrAnimator) /**< Custom animator attribute. */
141 ATTR_CUSTOM(L"checked", OnAttrCheck) /**< Custom checked attribute. */
142 ATTR_CHAIN_PTR(m_animator, 0) /**< Chain attributes to animator. */
143 SOUI_ATTRS_END()
144
145 private:
146 SAutoRefPtr<IValueAnimator> m_animator; /**< Animator for the switch. */
147};
148
149SNSEND
150
151#endif // _SWITCH_H_
SOUI基础DUI窗口模块
Smart pointer class for managing COM-style reference-counted objects.
A class representing an ASCII string.
Definition sstringw.h:96
BOOL NeedRedrawWhenStateChange() override
Determines whether the control needs to be redrawn when its state changes.
Definition SSwitch.h:84
void onAnimationEnd(IValueAnimator *pAnimator) override
Handles the end of an animation.
Definition SSwitch.cpp:21
void onAnimationUpdate(IValueAnimator *pAnimator) override
Handles the update of an animation.
Definition SSwitch.cpp:27
~SSwitch()
Destructor for SSwitch.
Definition SSwitch.cpp:17
HRESULT OnAttrAnimator(const SStringW &value, BOOL bLoading)
Handles the 'animator' attribute.
Definition SSwitch.cpp:110
void onAnimationRepeat(IValueAnimator *pAnimator) override
Handles the repetition of an animation.
Definition SSwitch.h:61
void OnPaint(IRenderTarget *pRT)
Handles the paint event.
Definition SSwitch.cpp:32
SAutoRefPtr< ISkinObj > m_pSkin
Definition SSwitch.h:118
void onAnimationStart(IValueAnimator *pAnimator) override
Handles the start of an animation.
Definition SSwitch.h:47
void OnLButtonUp(UINT nFlags, CPoint point)
Handles the left mouse button up event.
Definition SSwitch.cpp:90
void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
Handles the key down event.
Definition SSwitch.cpp:101
HRESULT OnAttrCheck(const SStringW &strValue, BOOL bLoading)
Handles the 'checked' attribute.
Definition SSwitch.cpp:118
void GetDesiredSize(SIZE *psz, int nParentWid, int nParentHei) OVERRIDE
Calculates the desired size of the control.
Definition SSwitch.cpp:82
SAutoRefPtr< ISkinObj > m_pSkinForce
Definition SSwitch.h:119
SSwitch()
Constructor for SSwitch.
Definition SSwitch.cpp:6
SWindow()
Constructor.
Definition Swnd.cpp:104
Interface for rendering target objects.
Definition SRender-i.h:1440
Interface for Skin Objects.
Definition SSkinobj-i.h:29