blob: b936ac9420c9d18f985e6acfd6cb2e5af910818a (
plain)
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
|
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "Selection.h"
#include "ImageEditor.h"
#include <LibGfx/Painter.h>
namespace PixelPaint {
Selection::Selection(Image& image)
: m_image(image)
{
}
void Selection::clear()
{
m_mask = {};
for (auto* client : m_clients)
client->selection_did_change();
}
void Selection::invert()
{
auto new_mask = Mask::full(m_image.rect());
new_mask.subtract(m_mask);
m_mask = new_mask;
}
void Selection::merge(Mask const& mask, MergeMode mode)
{
switch (mode) {
case MergeMode::Set:
m_mask = mask;
break;
case MergeMode::Add:
m_mask.add(mask);
break;
case MergeMode::Subtract:
m_mask.subtract(mask);
break;
case MergeMode::Intersect:
m_mask.intersect(mask);
break;
default:
VERIFY_NOT_REACHED();
}
}
void Selection::add_client(SelectionClient& client)
{
VERIFY(!m_clients.contains(&client));
m_clients.set(&client);
}
void Selection::remove_client(SelectionClient& client)
{
VERIFY(m_clients.contains(&client));
m_clients.remove(&client);
}
void Selection::set_mask(Mask mask)
{
m_mask = move(mask);
}
}
|