GUI
src
Widget.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2017 by Maciej Wiecierzewski
3
*/
4
5
#include "
Widget.h
"
6
7
#include "
GUISystem.h
"
8
9
#include "
loggerLocator.h
"
10
11
using namespace
gui
;
12
13
Widget::Widget
() :
14
x(0),
15
y(0),
16
w(0),
17
h(0),
18
state(STATE_UP),
19
focused(false),
20
visible(true),
21
parent(NULL)
22
{
23
updateAbs
();
24
}
25
26
Widget::Widget
(
int
x
,
int
y
,
int
w
,
int
h
) :
27
x(x),
28
y(y),
29
w(w),
30
h(h),
31
state
(
STATE_UP
),
32
focused
(false),
33
visible
(true),
34
parent
(NULL)
35
{
36
updateAbs
();
37
}
38
39
Widget::~Widget
()
40
{
41
//dtor
42
}
43
44
void
Widget::render
(
Renderer
*renderer)
45
{
46
}
47
48
void
Widget::keyChar
(
int
unichar)
49
{
50
}
51
52
void
Widget::keyDown
(
int
keyCode)
53
{
54
}
55
56
void
Widget::mouseMove
(
int
x
,
int
y
)
57
{
58
Event
evt =
guiSystem
->
createEvent
(
EventType::MOUSE_MOVE
);
59
emitEvent
(evt);
60
}
61
62
void
Widget::stateChange
(
State
state
)
63
{
64
this->state =
state
;
65
}
66
67
void
Widget::resize
(
int
x
,
int
y
,
int
w
,
int
h
)
68
{
69
this->x =
x
;
70
this->y =
y
;
71
this->w =
w
;
72
this->h =
h
;
73
74
updateAbs
();
75
76
Event
evt =
guiSystem
->
createEvent
(
EventType::RESIZE
);
77
emitEvent
(evt);
78
}
79
80
void
Widget::updateAbs
()
81
{
82
int
parentX = 0, parentY = 0;
83
84
if
(
parent
!= NULL)
85
{
86
parentX =
parent
->
xAbs
;
87
parentY =
parent
->
yAbs
;
88
}
89
90
xAbs
= parentX +
x
;
91
yAbs
= parentY +
y
;
92
93
for
(std::forward_list<Widget*>::iterator i =
children
.begin(); i !=
children
.end(); i++)
94
{
95
(*i)->updateAbs();
96
}
97
}
98
99
void
Widget::focusIn
()
100
{
101
focused
=
true
;
102
}
103
104
void
Widget::focusOut
()
105
{
106
focused
=
false
;
107
}
108
109
void
Widget::setVisibility
(
bool
visible
)
110
{
111
this->visible =
visible
;
112
113
for
(std::forward_list<Widget*>::iterator i =
children
.begin(); i !=
children
.end(); i++)
114
{
115
(*i)->setVisibility(visible);
116
}
117
}
118
119
void
Widget::addChild
(
Widget
*widget)
120
{
121
children
.push_front(widget);
122
}
123
124
void
Widget::removeChild
(
Widget
*widget)
125
{
126
widget->
setParent
(NULL);
127
//children.remove(widget);
128
}
129
130
void
Widget::setParent
(
Widget
*widget)
131
{
132
widget->
addChild
(
this
);
133
134
if
(
parent
!= NULL)
135
parent
->
removeChild
(
this
);
136
137
parent
= widget;
138
updateAbs
();
139
}
140
141
bool
Widget::contain
(
int
posX,
int
posY)
142
{
143
if
(posX >=
xAbs
&& posX <= xAbs+w && posY >=
yAbs
&& posY <=
yAbs
+
h
)
144
return
true
;
145
else
146
return
false
;
147
}
Generated on Sat Feb 11 2017 20:22:32 for GUI by
1.8.13