summaryrefslogtreecommitdiffstats
path: root/src/display/drawing-pattern.h
blob: 86b881ae1f4b1b7d9d006ec3e80c954388f9db0f (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
// SPDX-License-Identifier: GPL-2.0-or-later
/**
 * @file
 * Canvas belonging to SVG pattern.
 *//*
 * Authors:
 *   Tomasz Boczkowski <penginsbacon@gmail.com>
 *
 * Copyright (C) 2014 Authors
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#ifndef SEEN_INKSCAPE_DISPLAY_DRAWING_PATTERN_H
#define SEEN_INKSCAPE_DISPLAY_DRAWING_PATTERN_H

#include "display/drawing-group.h"

typedef struct _cairo_pattern cairo_pattern_t;

namespace Inkscape {

/**
 * @brief Drawing tree node used for rendering paints.
 *
 * DrawingPattern is used for rendering patterns and hatches.
 *
 * It renders it's children to a cairo_pattern_t structure that can be
 * applied as source for fill or stroke operations.
 */
class DrawingPattern
    : public DrawingGroup
{
public:
    DrawingPattern(Drawing &drawing, bool debug = false);
    ~DrawingPattern() override;

    /**
     * Set the transformation from pattern to user coordinate systems.
     * @see SPPattern description for explanation of coordinate systems.
     */
    void setPatternToUserTransform(Geom::Affine const &new_trans);
    /**
     * Set the tile rect position and dimensions in content coordinate system
     */
    void setTileRect(Geom::Rect const &tile_rect);
    /**
     * Turn on overflow rendering.
     *
     * Overflow is implemented as repeated rendering of pattern contents. In every step
     * a translation transform is applied.
     */
    void setOverflow(Geom::Affine initial_transform, int steps, Geom::Affine step_transform);
    /**
     * Render the pattern.
     *
     * Returns caito_pattern_t structure that can be set as source surface.
     */
    cairo_pattern_t *renderPattern(float opacity);
protected:
    unsigned _updateItem(Geom::IntRect const &area, UpdateContext const &ctx,
                                     unsigned flags, unsigned reset) override;

    Geom::Affine *_pattern_to_user;
    Geom::Affine _overflow_initial_transform;
    Geom::Affine _overflow_step_transform;
    int _overflow_steps;
    Geom::OptRect _tile_rect;
    bool _debug;
    Geom::IntPoint _pattern_resolution;
};

bool is_drawing_group(DrawingItem *item);

} // end namespace Inkscape

#endif // !SEEN_INKSCAPE_DISPLAY_DRAWING_PATTERN_H

/*
  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 :