summaryrefslogtreecommitdiffstats
path: root/src/display/drawing.h
blob: 709050ebe682b3a1211cf4efaa045998656b8518 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// SPDX-License-Identifier: GPL-2.0-or-later
/**
 * @file
 * SVG drawing for display.
 *//*
 * Authors:
 *   Krzysztof Kosiński <tweenk.pl@gmail.com>
 *
 * Copyright (C) 2011 Authors
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#ifndef SEEN_INKSCAPE_DISPLAY_DRAWING_H
#define SEEN_INKSCAPE_DISPLAY_DRAWING_H

#include <2geom/rect.h>
#include <boost/operators.hpp>
#include <boost/utility.hpp>
#include <set>
#include <sigc++/sigc++.h>

#include "display/drawing-item.h"
#include "display/rendermode.h"
#include "nr-filter-gaussian.h" // BLUR_QUALITY_BEST
#include "nr-filter-colormatrix.h"

typedef unsigned int guint32;

namespace Inkscape {

class DrawingItem;
class CanvasItemDrawing;

class Drawing
    : boost::noncopyable
{
public:
    struct OutlineColors {
        guint32 paths;
        guint32 clippaths;
        guint32 masks;
        guint32 images;
    };

    Drawing(Inkscape::CanvasItemDrawing *drawing = nullptr);
    ~Drawing();

    DrawingItem *root() { return _root; }
    Inkscape::CanvasItemDrawing *getCanvasItemDrawing() { return _canvas_item_drawing; }
    void setRoot(DrawingItem *item);

    RenderMode renderMode() const;
    ColorMode colorMode() const;
    bool outline() const;
    bool visibleHairlines() const;
    bool outlineOverlay() const;
    bool renderFilters() const;
    int blurQuality() const;
    int filterQuality() const;
    void setRenderMode(RenderMode mode);
    void setColorMode(ColorMode mode);
    void setBlurQuality(int q);
    void setFilterQuality(int q);
    void setExact(bool e);
    bool getExact() const { return _exact; };
    void setOutlineSensitive(bool e);
    bool getOutlineSensitive() const { return _outline_sensitive; };

    Geom::OptIntRect const &cacheLimit() const;
    void setCacheLimit(Geom::OptIntRect const &r);
    void setCacheBudget(size_t bytes);

    OutlineColors const &colors() const { return _colors; }

    void setGrayscaleMatrix(double value_matrix[20]);

    void update(Geom::IntRect const &area = Geom::IntRect::infinite(), unsigned flags = DrawingItem::STATE_ALL,
                unsigned reset = 0);

    void render(DrawingContext &dc, Geom::IntRect const &area, unsigned flags = 0, int antialiasing = -1);
    DrawingItem *pick(Geom::Point const &p, double delta, unsigned flags);

    void average_color(Geom::IntRect const &area, double &R, double &G, double &B, double &A);

    sigc::signal<void, DrawingItem *> signal_request_update;
    sigc::signal<void, Geom::IntRect const &> signal_request_render;
    sigc::signal<void, DrawingItem *> signal_item_deleted;

private:
    void _pickItemsForCaching();

    typedef std::list<CacheRecord> CandidateList;
    bool _outline_sensitive = false;
    DrawingItem *_root = nullptr;
    std::set<DrawingItem *> _cached_items; // modified by DrawingItem::setCached()
    CandidateList _candidate_items;        // keep this list always sorted with std::greater

public:
    // TODO: remove these temporarily public members
    guint32 outlinecolor = 0x000000ff;
    double delta = 0;

private:
    bool _exact = false;  // if true then rendering must be exact
    RenderMode _rendermode = RenderMode::NORMAL;
    ColorMode _colormode = ColorMode::NORMAL;
    int _blur_quality = BLUR_QUALITY_BEST;
    int _filter_quality = Filters::FILTER_QUALITY_BEST;
    Geom::OptIntRect _cache_limit;

    double _cache_score_threshold = 50000.0; ///< do not consider objects for caching below this score
    size_t _cache_budget = 0;                ///< maximum allowed size of cache

    OutlineColors _colors;
    Filters::FilterColorMatrix::ColorMatrixMatrix _grayscale_colormatrix;
    Inkscape::CanvasItemDrawing *_canvas_item_drawing = nullptr;

    friend class DrawingItem;
};

} // end namespace Inkscape

#endif // !SEEN_INKSCAPE_DRAWING_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 :