-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.cpp
More file actions
76 lines (65 loc) · 1.12 KB
/
widget.cpp
File metadata and controls
76 lines (65 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <utility>
#include "widget.h"
#include "util.h"
using namespace std;
Widget::Widget()
: _x(0)
, _y(0)
, _w(0)
, _h(0)
, _state(IDLE)
{}
Widget::Widget(Widget&& other)
: Drawable(forward<Drawable>(other))
, _x(other._x)
, _y(other._y)
, _w(other._w)
, _h(other._h)
, _state(exchange(other._state, DISABLED))
, _handler(exchange(other._handler, function<void(Widget&)>()))
{}
void Widget::set_position(int x, int y)
{
aquire(_mut);
_x = x;
_y = y;
}
void Widget::get_position(int *x, int *y) const
{
aquire(_mut);
if (x) *x = _x;
if (y) *y = _y;
}
void Widget::get_size(int *w, int *h) const
{
aquire(_mut);
if (w) *w = _w;
if (h) *h = _h;
}
bool Widget::contains(int x, int y) const
{
aquire(_mut);
return (_x <= x && x <= _x + _w)
&& (_y <= y && y <= _y + _h);
}
void Widget::set_handler(function<void(Widget&)>&& f)
{
aquire(_mut);
swap(_handler, f);
}
void Widget::trigger()
{
aquire(_mut);
if (_handler && _state != DISABLED)
_handler(*this);
}
void Widget::set_state(const State s)
{
aquire(_mut);
_state = s;
}
Widget::State Widget::get_state() const
{
aquire(_mut);
return _state;
}