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
|
#include "VBWidget.h"
#include "VBForm.h"
#include <LibGUI/GPainter.h>
VBWidget::VBWidget(VBForm& form)
: m_form(form)
{
}
VBWidget::~VBWidget()
{
}
bool VBWidget::is_selected() const
{
return m_form.is_selected(*this);
}
Rect VBWidget::grabber_rect(Direction direction) const
{
int grabber_size = 5;
int half_grabber_size = grabber_size / 2;
switch (direction) {
case Direction::Left:
return { m_rect.x() - half_grabber_size, m_rect.center().y() - half_grabber_size, grabber_size, grabber_size };
case Direction::UpLeft:
return { m_rect.x() - half_grabber_size, m_rect.y() - half_grabber_size, grabber_size, grabber_size };
case Direction::Up:
return { m_rect.center().x() - half_grabber_size, m_rect.y() - half_grabber_size, grabber_size, grabber_size };
case Direction::UpRight:
return { m_rect.right() - half_grabber_size, m_rect.y() - half_grabber_size, grabber_size, grabber_size };
case Direction::Right:
return { m_rect.right() - half_grabber_size, m_rect.center().y() - half_grabber_size, grabber_size, grabber_size };
case Direction::DownLeft:
return { m_rect.x() - half_grabber_size, m_rect.bottom() - half_grabber_size, grabber_size, grabber_size };
case Direction::Down:
return { m_rect.center().x() - half_grabber_size, m_rect.bottom() - half_grabber_size, grabber_size, grabber_size };
case Direction::DownRight:
return { m_rect.right() - half_grabber_size, m_rect.bottom() - half_grabber_size, grabber_size, grabber_size };
default:
ASSERT_NOT_REACHED();
}
}
Direction VBWidget::grabber_at(const Point& position) const
{
Direction found_grabber = Direction::None;
for_each_direction([&] (Direction direction) {
if (grabber_rect(direction).contains(position))
found_grabber = direction;
});
return found_grabber;
}
void VBWidget::paint(GPainter& painter)
{
painter.fill_rect(m_rect, Color::White);
painter.draw_rect(m_rect, Color::Black);
if (is_selected()) {
for_each_direction([&] (Direction direction) {
painter.fill_rect(grabber_rect(direction), Color::Black);
});
}
}
|