blob: 93193c30d8c2054c205cfd98c35b498086f9e7f2 (
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
// SPDX-License-Identifier: GPL-2.0-or-later
/**
* A CanvasItem that contains other CanvasItem's.
*/
/*
* Author:
* Tavmjong Bah
*
* Copyright (C) 2020 Tavmjong Bah
*
* Rewrite of SPCanvasGroup
*
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#include <boost/range/adaptor/reversed.hpp>
#include "canvas-item-group.h"
constexpr bool DEBUG_LOGGING = false;
namespace Inkscape {
CanvasItemGroup::CanvasItemGroup(CanvasItemGroup *group)
: CanvasItem(group)
{
_name = "CanvasItemGroup";
_pickable = true; // For now all groups are pickable... look into turning this off for some groups (e.g. temp).
}
CanvasItemGroup::CanvasItemGroup(CanvasItemContext *context)
: CanvasItem(context)
{
_name = "CanvasItemGroup:Root";
_pickable = true; // see above
}
CanvasItemGroup::~CanvasItemGroup()
{
items.clear_and_dispose([] (auto c) { delete c; });
}
void CanvasItemGroup::_update(bool propagate)
{
_bounds = {};
// Update all children and calculate new bounds.
for (auto &item : items) {
item.update(propagate);
_bounds |= item.get_bounds();
}
}
void CanvasItemGroup::_mark_net_invisible()
{
if (!_net_visible) {
return;
}
_net_visible = false;
_need_update = false;
for (auto &item : items) {
item._mark_net_invisible();
}
_bounds = {};
}
void CanvasItemGroup::visit_page_rects(std::function<void(Geom::Rect const &)> const &f) const
{
for (auto &item : items) {
if (!item.is_visible()) continue;
item.visit_page_rects(f);
}
}
void CanvasItemGroup::_render(Inkscape::CanvasItemBuffer &buf) const
{
for (auto &item : items) {
item.render(buf);
}
}
// Return last visible and pickable item that contains point.
// SPCanvasGroup returned distance but it was not used.
CanvasItem *CanvasItemGroup::pick_item(Geom::Point const &p)
{
if constexpr (DEBUG_LOGGING) {
std::cout << "CanvasItemGroup::pick_item:" << std::endl;
std::cout << " PICKING: In group: " << _name << " bounds: " << _bounds << std::endl;
}
for (auto &item : boost::adaptors::reverse(items)) {
if constexpr (DEBUG_LOGGING) std::cout << " PICKING: Checking: " << item.get_name() << " bounds: " << item.get_bounds() << std::endl;
if (item.is_visible() && item.is_pickable() && item.contains(p)) {
if (auto group = dynamic_cast<CanvasItemGroup*>(&item)) {
if (auto ret = group->pick_item(p)) {
return ret;
}
} else {
return &item;
}
}
}
return nullptr;
}
} // namespace Inkscape
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
|