Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
stores.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/*
6 * Copyright (C) 2022 PBS <pbs3141@gmail.com>
7 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
8 */
9
10#ifndef INKSCAPE_UI_WIDGET_CANVAS_STORES_H
11#define INKSCAPE_UI_WIDGET_CANVAS_STORES_H
12
13#include "fragment.h"
14#include "util.h"
15#include "ui/util.h"
16
17namespace Inkscape::UI::Widget {
18
19struct Fragment;
20class Prefs;
21class Graphics;
22
23class Stores
24{
25public:
26 enum class Mode
27 {
28 None,
29 Normal,
31 };
32
33 enum class Action
34 {
35 None,
36 Recreated,
37 Shifted
38 };
39
40 struct Store : Fragment
41 {
46 Cairo::RefPtr<Cairo::Region> drawn;
47 };
48
50 Stores(Prefs const &prefs)
51 : _mode(Mode::None)
52 , _graphics(nullptr)
53 , _prefs(prefs) {}
54
57
59 void reset();
60
62 Action update(Fragment const &view);
63
65 Action finished_draw(Fragment const &view);
66
68 void mark_drawn(Geom::IntRect const &rect) { _store.drawn->do_union(geom_to_cairo(rect)); }
69
70 // Getters.
71 Store const &store() const { return _store; }
72 Store const &snapshot() const { return _snapshot; }
73 Mode mode() const { return _mode; }
74
75private:
76 // Internal state.
79
80 // The graphics object that executes the operations on the stores.
82
83 // The preferences object we read preferences from.
84 Prefs const &_prefs;
85
86 // Internal actions.
87 Geom::IntRect centered(Fragment const &view) const;
88 void recreate_store(Fragment const &view);
89 void shift_store(Fragment const &view);
90 void take_snapshot(Fragment const &view);
91 void snapshot_combine(Fragment const &view);
92};
93
94} // namespace Inkscape::UI::Widget
95
96#endif // INKSCAPE_UI_WIDGET_CANVAS_STORES_H
97
98/*
99 Local Variables:
100 mode:c++
101 c-file-style:"stroustrup"
102 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
103 indent-tabs-mode:nil
104 fill-column:99
105 End:
106*/
107// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Axis aligned, non-empty, generic rectangle.
void recreate_store(Fragment const &view)
Definition stores.cpp:103
Stores(Prefs const &prefs)
Construct a blank object with no stores.
Definition stores.h:50
Action update(Fragment const &view)
Respond to a viewport change. (Requires a valid graphics.)
Definition stores.cpp:257
void mark_drawn(Geom::IntRect const &rect)
Record a rectangle as being drawn to the store.
Definition stores.h:68
@ Normal
Not initialised or just reset; no stores exist yet.
@ Decoupled
Normal mode consisting of just a backing store.
Geom::IntRect centered(Fragment const &view) const
Definition stores.cpp:97
Store const & snapshot() const
Definition stores.h:72
void shift_store(Fragment const &view)
Definition stores.cpp:113
Store const & store() const
Definition stores.h:71
void set_graphics(Graphics *g)
Set the pointer to the graphics object.
Definition stores.h:56
void snapshot_combine(Fragment const &view)
Definition stores.cpp:137
void take_snapshot(Fragment const &view)
Definition stores.cpp:125
void reset()
Discards all stores. (The actual operation on the graphics is performed on the next update()....
Definition stores.cpp:249
Action finished_draw(Fragment const &view)
Respond to drawing of the backing store having finished. (Requires a valid graphics....
Definition stores.cpp:346
@ Shifted
The backing store was completely recreated.
@ Recreated
The backing store was not changed.
Custom widgets.
Definition desktop.h:126
A "fragment" is a rectangle of drawn content at a specfic place.
Definition fragment.h:12
Cairo::RefPtr< Cairo::Region > drawn
The region of space containing drawn content.
Definition stores.h:46
Cairo::RectangleInt geom_to_cairo(const Geom::IntRect &rect)
Definition util.cpp:338