Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
drawing-group.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
/*
6 * Authors:
7 * Krzysztof KosiƄski <tweenk.pl@gmail.com>
8 *
9 * Copyright (C) 2011 Authors
10 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11 */
12
13#include "drawing-group.h"
14#include "cairo-utils.h"
15#include "drawing-context.h"
16#include "drawing-surface.h"
17#include "drawing-text.h"
18#include "drawing.h"
19#include "style.h"
20
21namespace Inkscape {
22
25
30void DrawingGroup::setPickChildren(bool pick_children)
31{
32 defer([=, this] {
33 _pick_children = pick_children;
34 });
35}
36
43{
44 defer([=, this] {
45 auto constexpr EPS = 1e-18;
47 if (Geom::are_near(transform, current, EPS)) return;
49 _child_transform = transform.isIdentity(EPS) ? nullptr : std::make_unique<Geom::Affine>(transform);
51 });
52}
53
54unsigned DrawingGroup::_updateItem(Geom::IntRect const &area, UpdateContext const &ctx, unsigned flags, unsigned reset)
55{
57
58 UpdateContext child_ctx(ctx);
59 if (_child_transform) {
60 child_ctx.ctm = *_child_transform * ctx.ctm;
61 }
62
63 _bbox = {};
64
65 for (auto &c : _children) {
66 c.update(area, child_ctx, flags, reset);
67 if (c.visible()) {
68 _bbox.unionWith(outline ? c.bbox() : c.drawbox());
69 }
70 _update_complexity += c.getUpdateComplexity();
71 _contains_unisolated_blend |= c.unisolatedBlend();
72 }
73
74 return STATE_ALL;
75}
76
77unsigned DrawingGroup::_renderItem(DrawingContext &dc, RenderContext &rc, Geom::IntRect const &area, unsigned flags, DrawingItem const *stop_at) const
78{
79 if (!stop_at) {
80 // normal rendering
81 for (auto &i : _children) {
82 i.render(dc, rc, area, flags, stop_at);
83 }
84 } else {
85 // background rendering
86 for (auto &i : _children) {
87 if (&i == stop_at) {
88 return RENDER_OK; // do not render the stop_at item at all
89 }
90 if (i.isAncestorOf(stop_at)) {
91 // render its ancestors without masks, opacity or filters
92 i.render(dc, rc, area, flags | RENDER_FILTER_BACKGROUND, stop_at);
93 return RENDER_OK;
94 } else {
95 i.render(dc, rc, area, flags, stop_at);
96 }
97 }
98 }
99 return RENDER_OK;
100}
101
103{
104 for (auto &i : _children) {
105 i.clip(dc, rc, area);
106 }
107}
108
109DrawingItem *DrawingGroup::_pickItem(Geom::Point const &p, double delta, unsigned flags)
110{
111 for (auto &i : _children) {
112 DrawingItem *picked = i.pick(p, delta, flags);
113 if (picked) {
114 return _pick_children ? picked : this;
115 }
116 }
117 return nullptr;
118}
119
120} // namespace Inkscape
121
122/*
123 Local Variables:
124 mode:c++
125 c-file-style:"stroustrup"
126 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
127 indent-tabs-mode:nil
128 fill-column:99
129 End:
130*/
131// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Cairo integration helpers.
3x3 matrix representing an affine transformation.
Definition affine.h:70
bool isIdentity(Coord eps=EPSILON) const
Check whether this matrix is an identity matrix.
Definition affine.cpp:109
void unionWith(CRect const &b)
Enlarge the rectangle to contain the argument.
Axis aligned, non-empty, generic rectangle.
Two-dimensional point that doubles as a vector.
Definition point.h:66
Minimal wrapper over Cairo.
unsigned _updateItem(Geom::IntRect const &area, UpdateContext const &ctx, unsigned flags, unsigned reset) override
void setPickChildren(bool)
Set whether the group returns children from pick calls.
std::unique_ptr< Geom::Affine > _child_transform
DrawingItem * _pickItem(Geom::Point const &p, double delta, unsigned flags) override
void setChildTransform(Geom::Affine const &)
Set additional transform for the group.
DrawingGroup(Drawing &drawing)
unsigned _renderItem(DrawingContext &dc, RenderContext &rc, Geom::IntRect const &area, unsigned flags, DrawingItem const *stop_at) const override
void _clipItem(DrawingContext &dc, RenderContext &rc, Geom::IntRect const &area) const override
SVG drawing item for display.
DrawingItem * pick(Geom::Point const &p, double delta, unsigned flags=0)
Get the item under the specified point.
Geom::OptIntRect _bbox
Bounding box in display (pixel) coords including stroke.
void _markForUpdate(unsigned state, bool propagate)
Marks the item as needing a recomputation of internal data.
unsigned _pick_children
For groups: if true, children are returned from pick(), otherwise the group is returned.
void _markForRendering()
Marks the current visual bounding box of the item for redrawing.
Geom::Affine transform() const
RenderMode renderMode() const
Definition drawing.h:67
bool outlineOverlay() const
Definition drawing.h:69
RectangularCluster rc
double c[8][4]
static char const *const current
Definition dir-util.cpp:71
Cairo drawing context with Inkscape extensions.
Group belonging to an SVG drawing element.
Cairo surface that remembers its origin.
Group belonging to an SVG drawing element.
SVG drawing for display.
Affine identity()
Create an identity matrix.
Definition affine.h:210
bool are_near(Affine const &a1, Affine const &a2, Coord eps=EPSILON)
Helper class to stream background task notifications as a series of messages.
Geom::PathVector outline(Geom::Path const &input, double width, double miter, LineJoinType join, LineCapType butt, double tolerance)
Strokes the path given by input.
SPStyle - a style object for SPItem objects.
int delta