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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
// SPDX-License-Identifier: GPL-2.0-or-later
/**
* @file
* Group belonging to an SVG drawing element.
*//*
* Authors:
* Krzysztof Kosiński <tweenk.pl@gmail.com>
*
* Copyright (C) 2011 Authors
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#include "display/drawing-group.h"
#include "display/cairo-utils.h"
#include "display/drawing-context.h"
#include "display/drawing-item.h"
#include "display/drawing-surface.h"
#include "display/drawing-text.h"
#include "display/drawing.h"
#include "style.h"
namespace Inkscape {
DrawingGroup::DrawingGroup(Drawing &drawing)
: DrawingItem(drawing)
, _child_transform(nullptr)
{}
DrawingGroup::~DrawingGroup()
{
delete _child_transform; // delete NULL; is safe
}
/**
* Set whether the group returns children from pick calls.
* Previously this feature was called "transparent groups".
*/
void
DrawingGroup::setPickChildren(bool p)
{
_pick_children = p;
}
/**
* Set additional transform for the group.
* This is applied after the normal transform and mainly useful for
* markers, clipping paths, etc.
*/
void
DrawingGroup::setChildTransform(Geom::Affine const &new_trans)
{
Geom::Affine current;
if (_child_transform) {
current = *_child_transform;
}
if (!Geom::are_near(current, new_trans, 1e-18)) {
// mark the area where the object was for redraw.
_markForRendering();
if (new_trans.isIdentity()) {
delete _child_transform; // delete NULL; is safe
_child_transform = nullptr;
} else {
_child_transform = new Geom::Affine(new_trans);
}
_markForUpdate(STATE_ALL, true);
}
}
unsigned
DrawingGroup::_updateItem(Geom::IntRect const &area, UpdateContext const &ctx, unsigned flags, unsigned reset)
{
unsigned beststate = STATE_ALL;
bool outline = _drawing.outline() || _drawing.outlineOverlay();
UpdateContext child_ctx(ctx);
if (_child_transform) {
child_ctx.ctm = *_child_transform * ctx.ctm;
}
for (auto & i : _children) {
i.update(area, child_ctx, flags, reset);
}
if (beststate & STATE_BBOX) {
_bbox = Geom::OptIntRect();
for (auto & i : _children) {
if (i.visible()) {
_bbox.unionWith(outline ? i.geometricBounds() : i.visualBounds());
}
}
}
return beststate;
}
unsigned
DrawingGroup::_renderItem(DrawingContext &dc, Geom::IntRect const &area, unsigned flags, DrawingItem *stop_at)
{
if (stop_at == nullptr) {
// normal rendering
for (auto &i : _children) {
i.setAntialiasing(_antialias);
i.render(dc, area, flags, stop_at);
}
} else {
// background rendering
for (auto &i : _children) {
if (&i == stop_at)
return RENDER_OK; // do not render the stop_at item at all
if (i.isAncestorOf(stop_at)) {
// render its ancestors without masks, opacity or filters
i.setAntialiasing(_antialias);
i.render(dc, area, flags | RENDER_FILTER_BACKGROUND, stop_at);
return RENDER_OK;
} else {
i.setAntialiasing(_antialias);
i.render(dc, area, flags, stop_at);
}
}
}
return RENDER_OK;
}
void
DrawingGroup::_clipItem(DrawingContext &dc, Geom::IntRect const &area)
{
for (auto & i : _children) {
i.setAntialiasing(_antialias);
i.clip(dc, area);
}
}
DrawingItem *
DrawingGroup::_pickItem(Geom::Point const &p, double delta, unsigned flags)
{
for (auto & i : _children) {
DrawingItem *picked = i.pick(p, delta, flags);
if (picked) {
return _pick_children ? picked : this;
}
}
return nullptr;
}
bool
DrawingGroup::_canClip()
{
return true;
}
bool is_drawing_group(DrawingItem *item)
{
return dynamic_cast<DrawingGroup *>(item) != nullptr;
}
} // end 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:fileencoding=utf-8:textwidth=99 :
|