GUI
src
Button.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2017 by Maciej Wiecierzewski
3
*/
4
5
#include "
Button.h
"
6
7
#include "
GUISystem.h
"
8
#include "
Renderer.h
"
9
10
using namespace
gui
;
11
12
Button::Button
(
GUISystem
*guiSystem,
int
x,
int
y,
int
w,
int
h, std::string text) :
13
Widget
(x, y, w, h),
14
text(text)
15
{
16
this->guiSystem =
guiSystem
;
17
}
18
19
void
Button::render
(
Renderer
*renderer)
20
{
21
int
x
=
xAbs
,
y
=
yAbs
;
22
renderer->
setTarget
(x, y,
w
,
h
);
23
24
if
(
state
==
Widget::STATE_UP
)
25
renderer->
drawFilledRect
(0, 0,
w
,
h
,
upStateColor
);
26
else
if
(
state
==
Widget::STATE_HOVER
)
27
renderer->
drawFilledRect
(0, 0,
w
,
h
,
hoverStateColor
);
28
else
if
(
state
==
Widget::STATE_DOWN
)
29
renderer->
drawFilledRect
(0, 0,
w
,
h
,
downStateColor
);
30
31
renderer->
drawText
(0, 0,
text
,
textColor
);
32
}
33
34
void
Button::stateChange
(
Widget::State
newState)
35
{
36
if
(
state
==
Widget::STATE_DOWN
&& (newState ==
Widget::STATE_UP
|| newState ==
Widget::STATE_HOVER
))
37
{
38
Event
evt = this->
guiSystem
->
createEvent
(
EventType::MOUSE_BUTTON_UP
);
39
emitEvent
(evt);
40
}
41
else
if
(newState ==
Widget::STATE_DOWN
)
42
{
43
Event
evt = this->
guiSystem
->
createEvent
(
EventType::MOUSE_BUTTON_DOWN
);
44
emitEvent
(evt);
45
}
46
else
if
(newState ==
Widget::STATE_HOVER
)
47
{
48
}
49
50
state
= newState;
51
}
52
53
void
Button::setText
(
const
std::string &
text
)
54
{
55
this->text =
text
;
56
}
57
Generated on Sat Feb 11 2017 20:22:31 for GUI by
1.8.13