MyGUI
3.2.1
Main Page
Related Pages
Namespaces
Data Structures
Files
Examples
File List
Globals
mygui
MyGUIEngine
src
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
13
namespace
MyGUI
14
{
15
16
Button::Button
() :
17
mIsMousePressed(false),
18
mIsMouseFocus(false),
19
mStateSelected(false),
20
mImage(
nullptr
),
21
mModeImage(false)
22
{
23
}
24
25
void
Button::initialiseOverride
()
26
{
27
Base::initialiseOverride
();
28
30
assignWidget
(mImage,
"Image"
);
31
}
32
33
void
Button::shutdownOverride
()
34
{
35
mImage =
nullptr
;
36
37
Base::shutdownOverride
();
38
}
39
40
void
Button::onMouseSetFocus
(
Widget
* _old)
41
{
42
_setMouseFocus
(
true
);
43
44
Base::onMouseSetFocus
(_old);
45
}
46
47
void
Button::onMouseLostFocus
(
Widget
* _new)
48
{
49
_setMouseFocus
(
false
);
50
51
Base::onMouseLostFocus
(_new);
52
}
53
54
void
Button::onMouseButtonPressed
(
int
_left,
int
_top,
MouseButton
_id)
55
{
56
if
(_id ==
MouseButton::Left
)
57
{
58
mIsMousePressed =
true
;
59
updateButtonState();
60
}
61
62
Base::onMouseButtonPressed
(_left, _top, _id);
63
}
64
65
void
Button::onMouseButtonReleased
(
int
_left,
int
_top,
MouseButton
_id)
66
{
67
if
(_id ==
MouseButton::Left
)
68
{
69
mIsMousePressed =
false
;
70
updateButtonState();
71
}
72
73
Base::onMouseButtonReleased
(_left, _top, _id);
74
}
75
76
void
Button::updateButtonState()
77
{
78
if
(mStateSelected)
79
{
80
if
(!
getInheritedEnabled
())
81
{
82
if
(!
_setState
(
"disabled_checked"
))
83
_setState
(
"disabled"
);
84
}
85
else
if
(mIsMousePressed)
86
{
87
if
(!
_setState
(
"pushed_checked"
))
88
_setState
(
"pushed"
);
89
}
90
else
if
(mIsMouseFocus)
91
{
92
if
(!
_setState
(
"highlighted_checked"
))
93
_setState
(
"pushed"
);
94
}
95
else
96
_setState
(
"normal_checked"
);
97
}
98
else
99
{
100
if
(!
getInheritedEnabled
())
101
_setState
(
"disabled"
);
102
else
if
(mIsMousePressed)
103
_setState
(
"pushed"
);
104
else
if
(mIsMouseFocus)
105
_setState
(
"highlighted"
);
106
else
107
_setState
(
"normal"
);
108
}
109
}
110
111
void
Button::setStateSelected
(
bool
_check)
112
{
113
if
(mStateSelected == _check)
114
return
;
115
116
mStateSelected = _check;
117
updateButtonState();
118
}
119
120
void
Button::_setMouseFocus
(
bool
_focus)
121
{
122
mIsMouseFocus = _focus;
123
updateButtonState();
124
}
125
126
void
Button::baseUpdateEnable
()
127
{
128
updateButtonState();
129
if
(!
getInheritedEnabled
())
130
{
131
mIsMouseFocus =
false
;
132
}
133
}
134
135
void
Button::setModeImage
(
bool
_value)
136
{
137
mModeImage = _value;
138
updateButtonState();
139
}
140
141
bool
Button::_setState
(
const
std::string& _value)
142
{
143
if
(mModeImage)
144
{
145
if
(mImage)
146
mImage->
setItemName
(_value);
147
148
_setWidgetState
(_value);
149
return
true
;
150
}
151
152
return
_setWidgetState
(_value);
153
}
154
155
void
Button::setImageResource
(
const
std::string& _name)
156
{
157
if
(mImage)
158
mImage->
setItemResource
(_name);
159
updateButtonState();
160
}
161
162
void
Button::setImageGroup
(
const
std::string& _name)
163
{
164
if
(mImage)
165
mImage->
setItemGroup
(_name);
166
updateButtonState();
167
}
168
169
void
Button::setImageName
(
const
std::string& _name)
170
{
171
if
(mImage)
172
mImage->
setItemName
(_name);
173
}
174
175
void
Button::setPropertyOverride
(
const
std::string& _key,
const
std::string& _value)
176
{
178
if
(_key ==
"StateSelected"
)
179
setStateSelected
(utility::parseValue<bool>(_value));
180
182
else
if
(_key ==
"ModeImage"
)
183
setModeImage
(utility::parseValue<bool>(_value));
184
186
else
if
(_key ==
"ImageResource"
)
187
setImageResource
(_value);
188
190
else
if
(_key ==
"ImageGroup"
)
191
setImageGroup
(_value);
192
194
else
if
(_key ==
"ImageName"
)
195
setImageName
(_value);
196
197
else
198
{
199
Base::setPropertyOverride
(_key, _value);
200
return
;
201
}
202
203
eventChangeProperty
(
this
, _key, _value);
204
}
205
206
bool
Button::getStateSelected
()
const
207
{
208
return
mStateSelected;
209
}
210
211
bool
Button::getModeImage
()
const
212
{
213
return
mModeImage;
214
}
215
216
ImageBox
*
Button::_getImageBox
()
217
{
218
return
mImage;
219
}
220
221
}
// namespace MyGUI
Generated on Wed Aug 20 2014 00:03:32 for MyGUI by
1.8.3.1