MyGUI: MyGUI_Button.cpp Source File

MyGUI 3.4.3

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