MyGUI: MyGUI_Button.cpp Source File

MyGUI 3.4.2

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

MyGUI_Button.cpp
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#include "MyGUI_Precompiled.h"
8#include "MyGUI_Button.h"
9#include "MyGUI_ResourceSkin.h"
10#include "MyGUI_ImageBox.h"
11#include "MyGUI_InputManager.h"
12
13namespace MyGUI
14{
15
16 Button::Button() :
17 mIsMousePressed(false),
18 mIsKeyFocus(false),
19 mIsMouseFocus(false),
20 mStateSelected(false),
21 mImage(nullptr),
22 mModeImage(false)
23 {
24 }
25
26 void Button::initialiseOverride()
27 {
28 Base::initialiseOverride();
29
31 assignWidget(mImage, "Image");
32 }
33
34 void Button::shutdownOverride()
35 {
36 mImage = nullptr;
37
38 Base::shutdownOverride();
39 }
40
41 void Button::onKeySetFocus(Widget* _old)
42 {
43 _setKeyFocus(true);
44
45 Base::onKeySetFocus(_old);
46 }
47
48 void Button::onKeyLostFocus(Widget* _new)
49 {
50 _setKeyFocus(false);
51
52 Base::onKeyLostFocus(_new);
53 }
54
55 void Button::onMouseSetFocus(Widget* _old)
56 {
57 _setMouseFocus(true);
58
59 Base::onMouseSetFocus(_old);
60 }
61
62 void Button::onMouseLostFocus(Widget* _new)
63 {
64 _setMouseFocus(false);
65
66 Base::onMouseLostFocus(_new);
67 }
68
69 void Button::onMouseButtonPressed(int _left, int _top, MouseButton _id)
70 {
71 if (_id == MouseButton::Left)
72 {
73 mIsMousePressed = true;
74 updateButtonState();
75 }
76
77 Base::onMouseButtonPressed(_left, _top, _id);
78 }
79
80 void Button::onMouseButtonReleased(int _left, int _top, MouseButton _id)
81 {
82 if (_id == MouseButton::Left)
83 {
84 mIsMousePressed = false;
85 updateButtonState();
86 }
87
88 Base::onMouseButtonReleased(_left, _top, _id);
89 }
90
91 void Button::updateButtonState()
92 {
93 if (mStateSelected)
94 {
95 if (!getInheritedEnabled())
96 {
97 if (!_setState("disabled_checked"))
98 _setState("disabled");
99 }
100 else if (mIsMousePressed)
101 {
102 if (!_setState("pushed_checked"))
103 _setState("pushed");
104 }
105 else if (mIsMouseFocus || mIsKeyFocus)
106 {
107 if (!_setState("highlighted_checked"))
108 _setState("pushed");
109 }
110 else
111 {
112 if (!_setState("normal_checked"))
113 _setState("pushed");
114 }
115 }
116 else
117 {
118 if (!getInheritedEnabled())
119 _setState("disabled");
120 else if (mIsMousePressed)
121 _setState("pushed");
122 else if (mIsMouseFocus || mIsKeyFocus)
123 _setState("highlighted");
124 else
125 _setState("normal");
126 }
127 }
128
129 void Button::setStateSelected(bool _check)
130 {
131 if (mStateSelected == _check)
132 return;
133
134 mStateSelected = _check;
135 updateButtonState();
136 }
137
138 void Button::_setKeyFocus(bool _focus)
139 {
140 mIsKeyFocus = _focus;
141 updateButtonState();
142 }
143
144 void Button::_setMouseFocus(bool _focus)
145 {
146 mIsMouseFocus = _focus;
147 updateButtonState();
148 }
149
150 void Button::baseUpdateEnable()
151 {
152 updateButtonState();
153 if (!getInheritedEnabled())
154 {
155 mIsKeyFocus = false;
156 mIsMouseFocus = false;
157 }
158 }
159
160 void Button::setModeImage(bool _value)
161 {
162 mModeImage = _value;
163 updateButtonState();
164 }
165
166 bool Button::_setState(const std::string& _value)
167 {
168 if (mModeImage)
169 {
170 if (mImage)
171 mImage->setItemName(_value);
172
173 _setWidgetState(_value);
174 return true;
175 }
176
177 return _setWidgetState(_value);
178 }
179
180 void Button::setImageResource(const std::string& _name)
181 {
182 if (mImage)
183 mImage->setItemResource(_name);
184 updateButtonState();
185 }
186
187 void Button::setImageGroup(const std::string& _name)
188 {
189 if (mImage)
190 mImage->setItemGroup(_name);
191 updateButtonState();
192 }
193
194 void Button::setImageName(const std::string& _name)
195 {
196 if (mImage)
197 mImage->setItemName(_name);
198 }
199
200 void Button::setPropertyOverride(const std::string& _key, const std::string& _value)
201 {
203 if (_key == "StateSelected")
204 setStateSelected(utility::parseValue<bool>(_value));
205
207 else if (_key == "ModeImage")
208 setModeImage(utility::parseValue<bool>(_value));
209
211 else if (_key == "ImageResource")
212 setImageResource(_value);
213
215 else if (_key == "ImageGroup")
216 setImageGroup(_value);
217
219 else if (_key == "ImageName")
220 setImageName(_value);
221
222 else
223 {
224 Base::setPropertyOverride(_key, _value);
225 return;
226 }
227
228 eventChangeProperty(this, _key, _value);
229 }
230
231 bool Button::getStateSelected() const
232 {
233 return mStateSelected;
234 }
235
236 bool Button::getModeImage() const
237 {
238 return mModeImage;
239 }
240
241 ImageBox* Button::_getImageBox() const
242 {
243 return mImage;
244 }
245
246} // namespace MyGUI
MyGUI_Button.h
MyGUI_ImageBox.h
MyGUI_InputManager.h
MyGUI_Precompiled.h
MyGUI_ResourceSkin.h
MyGUI::Button::setImageGroup
void setImageGroup(const std::string &_name)
Definition MyGUI_Button.cpp:187
MyGUI::Button::setImageName
void setImageName(const std::string &_name)
Definition MyGUI_Button.cpp:194
MyGUI::Button::onMouseSetFocus
void onMouseSetFocus(Widget *_old) override
Definition MyGUI_Button.cpp:55
MyGUI::Button::_setMouseFocus
void _setMouseFocus(bool _focus)
Definition MyGUI_Button.cpp:144
MyGUI::Button::onMouseButtonReleased
void onMouseButtonReleased(int _left, int _top, MouseButton _id) override
Definition MyGUI_Button.cpp:80
MyGUI::Button::onKeyLostFocus
void onKeyLostFocus(Widget *_new) override
Definition MyGUI_Button.cpp:48
MyGUI::Button::onMouseButtonPressed
void onMouseButtonPressed(int _left, int _top, MouseButton _id) override
Definition MyGUI_Button.cpp:69
MyGUI::Button::Button
Button()
Definition MyGUI_Button.cpp:16
MyGUI::Button::setStateSelected
void setStateSelected(bool _value)
Set button selected state.
Definition MyGUI_Button.cpp:129
MyGUI::Button::onKeySetFocus
void onKeySetFocus(Widget *_old) override
Definition MyGUI_Button.cpp:41
MyGUI::Button::setPropertyOverride
void setPropertyOverride(const std::string &_key, const std::string &_value) override
Definition MyGUI_Button.cpp:200
MyGUI::Button::getStateSelected
bool getStateSelected() const
Get buton selected.
Definition MyGUI_Button.cpp:231
MyGUI::Button::setImageResource
void setImageResource(const std::string &_name)
Definition MyGUI_Button.cpp:180
MyGUI::Button::getModeImage
bool getModeImage() const
Definition MyGUI_Button.cpp:236
MyGUI::Button::_getImageBox
ImageBox * _getImageBox() const
Definition MyGUI_Button.cpp:241
MyGUI::Button::shutdownOverride
void shutdownOverride() override
Definition MyGUI_Button.cpp:34
MyGUI::Button::baseUpdateEnable
void baseUpdateEnable() override
Definition MyGUI_Button.cpp:150
MyGUI::Button::initialiseOverride
void initialiseOverride() override
Definition MyGUI_Button.cpp:26
MyGUI::Button::setModeImage
void setModeImage(bool _value)
Definition MyGUI_Button.cpp:160
MyGUI::Button::onMouseLostFocus
void onMouseLostFocus(Widget *_new) override
Definition MyGUI_Button.cpp:62
MyGUI::Button::_setState
bool _setState(const std::string &_value)
Definition MyGUI_Button.cpp:166
MyGUI::Button::_setKeyFocus
void _setKeyFocus(bool _focus)
Definition MyGUI_Button.cpp:138
MyGUI::ImageBox
widget description should be here.
Definition MyGUI_ImageBox.h:24
MyGUI::ImageBox::setItemName
void setItemName(const std::string &_value)
Definition MyGUI_ImageBox.cpp:405
MyGUI::ImageBox::setItemResource
bool setItemResource(const std::string &_name)
Definition MyGUI_ImageBox.cpp:345
MyGUI::ImageBox::setItemGroup
void setItemGroup(const std::string &_value)
Definition MyGUI_ImageBox.cpp:395
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:37
MyGUI::Widget::getInheritedEnabled
bool getInheritedEnabled() const
Definition MyGUI_Widget.cpp:1335
MyGUI::Widget::eventChangeProperty
EventHandle_WidgetStringString eventChangeProperty
Definition MyGUI_Widget.h:268
MyGUI::Widget::_setWidgetState
bool _setWidgetState(const std::string &_value)
Definition MyGUI_Widget.cpp:374
MyGUI::Widget::assignWidget
void assignWidget(T *&_widget, const std::string &_name)
Definition MyGUI_Widget.h:336
MyGUI::utility::parseValue
T parseValue(const std::string &_value)
Definition MyGUI_StringUtility.h:112
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::MouseButton
Definition MyGUI_MouseButton.h:16
MyGUI::MouseButton::Left
@ Left
Definition MyGUI_MouseButton.h:21