Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
canvas-item-group.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/*
6 * Author:
7 * Tavmjong Bah
8 *
9 * Copyright (C) 2020 Tavmjong Bah
10 *
11 * Rewrite of SPCanvasGroup
12 *
13 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
14 */
15
16#include <boost/range/adaptor/reversed.hpp>
17#include "canvas-item-group.h"
18
19constexpr bool DEBUG_LOGGING = false;
20
21namespace Inkscape {
22
24 : CanvasItem(group)
25{
26 _name = "CanvasItemGroup";
27 _pickable = true; // For now all groups are pickable... look into turning this off for some groups (e.g. temp).
28}
29
31 : CanvasItem(context)
32{
33 _name = "CanvasItemGroup:Root";
34 _pickable = true; // see above
35}
36
38{
39 items.clear_and_dispose([] (auto c) { delete c; });
40}
41
42void CanvasItemGroup::_update(bool propagate)
43{
44 _bounds = {};
45
46 // Update all children and calculate new bounds.
47 for (auto &item : items) {
48 item.update(propagate);
49 _bounds |= item.get_bounds();
50 }
51}
52
54{
55 if (!_net_visible) {
56 return;
57 }
58 _net_visible = false;
59 _need_update = false;
60 for (auto &item : items) {
61 item._mark_net_invisible();
62 }
63 _bounds = {};
64}
65
66void CanvasItemGroup::visit_page_rects(std::function<void(Geom::Rect const &)> const &f) const
67{
68 for (auto &item : items) {
69 if (!item.is_visible()) continue;
70 item.visit_page_rects(f);
71 }
72}
73
75{
76 for (auto &item : items) {
77 item.render(buf);
78 }
79}
80
82{
83 for (auto &c : items) {
84 c._invalidate_ctrl_handles();
85 }
86}
87
88// Return last visible and pickable item that contains point.
89// SPCanvasGroup returned distance but it was not used.
91{
92 if constexpr (DEBUG_LOGGING) {
93 std::cout << "CanvasItemGroup::pick_item:" << std::endl;
94 std::cout << " PICKING: In group: " << _name << " bounds: " << _bounds << std::endl;
95 }
96
97 for (auto &item : boost::adaptors::reverse(items)) {
98 if constexpr (DEBUG_LOGGING) std::cout << " PICKING: Checking: " << item.get_name() << " bounds: " << item.get_bounds() << std::endl;
99
100 if (item.is_visible() && item.is_pickable() && item.contains(p)) {
101 if (auto group = dynamic_cast<CanvasItemGroup*>(&item)) {
102 if (auto ret = group->pick_item(p)) {
103 return ret;
104 }
105 } else {
106 return &item;
107 }
108 }
109 }
110
111 return nullptr;
112}
113
114} // namespace Inkscape
115
116/*
117 Local Variables:
118 mode:c++
119 c-file-style:"stroustrup"
120 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
121 indent-tabs-mode:nil
122 fill-column:99
123 End:
124*/
125// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
constexpr bool DEBUG_LOGGING
A CanvasItem that contains other CanvasItem's.
Two-dimensional point that doubles as a vector.
Definition point.h:66
Axis aligned, non-empty rectangle.
Definition rect.h:92
CanvasItem * pick_item(Geom::Point const &p)
void _update(bool propagate) override
void visit_page_rects(std::function< void(Geom::Rect const &)> const &) const override
void _render(Inkscape::CanvasItemBuffer &buf) const override
void _invalidate_ctrl_handles() override
Geom::OptRect _bounds
friend class CanvasItemGroup
void update(SPCtx *ctx, unsigned int flags) override
Definition sp-item.cpp:779
double c[8][4]
SPItem * item
Helper class to stream background task notifications as a series of messages.
int buf
Class used when rendering canvas items.