Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
canvas.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/*
6 * Authors:
7 * Tavmjong Bah
8 * PBS <pbs3141@gmail.com>
9 *
10 * Copyright (C) 2022 Authors
11 *
12 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
13 */
14
15#ifndef INKSCAPE_UI_WIDGET_CANVAS_H
16#define INKSCAPE_UI_WIDGET_CANVAS_H
17
18#include <memory>
19#include <optional>
20#include <2geom/int-rect.h>
21#include <2geom/rect.h>
22#include <glibmm/refptr.h>
23#include <gtk/gtk.h> // GtkEventController*
24#include <gtkmm/gesture.h> // Gtk::EventSequenceState
25#include <sigc++/signal.h>
26
27#include "display/rendermode.h"
28#include "events/enums.h"
29#include "optglarea.h"
30
31namespace Gdk {
32class Rectangle;
33} // namespace Gdk
34
35namespace Gtk {
36class EventControllerKey;
37class EventControllerMotion;
38class EventControllerScroll;
39class GestureClick;
40} // namespace Gtk
41
42class SPDesktop;
43
44namespace Inkscape {
45
46class CanvasItem;
47class CanvasItemGroup;
48class Drawing;
49
50namespace Colors::CMS {
51 class Transform;
52}
53
54namespace UI::Widget {
55
56class CanvasPrivate;
57
61class Canvas final : public OptGLArea
62{
64
65public:
66 Canvas();
67 ~Canvas() final;
68
69 /* Configuration */
70
71 // Desktop (Todo: Remove.)
73 SPDesktop *get_desktop() const { return _desktop; }
74
75 // Drawing
76 void set_drawing(Inkscape::Drawing *drawing);
77
78 // Canvas item root
80
81 // Geometry
82 void set_pos (const Geom::IntPoint &pos);
83 void set_pos (const Geom::Point &fpos) { set_pos(fpos.round()); }
84 void set_affine(const Geom::Affine &affine);
85 const Geom::IntPoint &get_pos () const { return _pos; }
86 const Geom::Affine &get_affine() const { return _affine; }
87 const Geom::Affine &get_geom_affine() const; // tool-base.cpp (todo: remove this dependency)
88
89 // Background
90 void set_desk (uint32_t rgba);
91 void set_border(uint32_t rgba);
92 void set_page (uint32_t rgba);
93
94 // Rendering modes
101 void set_clip_to_page_mode(bool clip);
102 void set_antialiasing_enabled(bool enabled);
103
104 // CMS
105 void set_cms_active(bool active) { _cms_active = active; }
106 bool get_cms_active() const { return _cms_active; }
107
108 /* Observers */
109
110 // Geometry
112 bool world_point_inside_canvas(Geom::Point const &world) const; // desktop-events.cpp
113 Geom::Point canvas_to_world(Geom::Point const &window) const;
115 bool canvas_point_in_outline_zone(Geom::Point const &world) const;
116
117 // State
118 bool is_dragging() const { return _is_dragging; } // selection-chemistry.cpp
119
120 // Mouse
121 std::optional<Geom::Point> get_last_mouse() const; // desktop-widget.cpp
122
123 /* Methods */
124
125 // Invalidation
126 void redraw_all(); // Mark everything as having changed.
127 void redraw_area(Geom::Rect const &area); // Mark a rectangle of world space as having changed.
128 void redraw_area(int x0, int y0, int x1, int y1);
130 void request_update(); // Mark geometry as needing recalculation.
131
132 // Callback run on destructor of any canvas item
134
135 // State
146
147 void enable_autoscroll();
148
149 sigc::connection connectResize(sigc::slot<void ()> &&slot) { return _signal_resize.connect(std::move(slot)); }
150 sigc::connection connectFocusIn(sigc::slot<void ()> &&slot) { return _signal_focus_in.connect(std::move(slot)); }
151 sigc::connection connectFocusOut(sigc::slot<void ()> &&slot) { return _signal_focus_out.connect(std::move(slot)); }
152
153private:
154 // EventControllerScroll
155 bool on_scroll(Gtk::EventControllerScroll const &controller, double dx, double dy);
156
157 // GestureClick
158 Gtk::EventSequenceState on_button_pressed (Gtk::GestureClick const &controller,
159 int n_press, double x, double y);
160 Gtk::EventSequenceState on_button_released(Gtk::GestureClick const &controller,
161 int n_press, double x, double y);
162
163 // EventControllerMotion
164 void on_motion(Gtk::EventControllerMotion const &controller, double x, double y);
165 void on_enter (Gtk::EventControllerMotion const &controller, double x, double y);
166 void on_leave (Gtk::EventControllerMotion const &controller);
167
168 // EventControllerFocus
169 void on_focus_in();
170 void on_focus_out();
171
172 // EventControllerKey
173 bool on_key_pressed (Gtk::EventControllerKey const &controller,
174 unsigned keyval, unsigned keycode, Gdk::ModifierType state);
175 void on_key_released(Gtk::EventControllerKey const &controller,
176 unsigned keyval, unsigned keycode, Gdk::ModifierType state);
177
178 void on_realize() final;
179 void on_unrealize() final;
180 void size_allocate_vfunc(int width, int height, int baseline) final;
181
182 Glib::RefPtr<Gdk::GLContext> create_context() final;
183 void paint_widget(Cairo::RefPtr<Cairo::Context> const &) final;
184
185 /* Configuration */
186
187 // Desktop
188 SPDesktop *_desktop = nullptr;
189
190 // Drawing
192
193 // Geometry
194 Geom::IntPoint _pos = {0, 0};
196
197 // Rendering modes
202
203 // CMS
204 bool _cms_active = false;
205 std::shared_ptr<Colors::CMS::Transform> _cms_transform;
206 void set_cms_transform();
207
208 /* Internal state */
209
210 // Event handling/item picking
214 int _state;
215
220
221 // Drawing
222 bool _need_update = true; // Set true so setting CanvasItem bounds are calculated at least once.
223
224 // Split view
230
231 sigc::signal<void ()> _signal_resize;
232 sigc::signal<void ()> _signal_focus_in;
233 sigc::signal<void ()> _signal_focus_out;
234
235 void update_cursor();
236
237 // Opaque pointer to implementation
238 friend class CanvasPrivate;
239 std::unique_ptr<CanvasPrivate> d;
240};
241
242} // namespace UI::Widget
243
244} // namespace Inkscape
245
246#endif // INKSCAPE_UI_WIDGET_CANVAS_H
247
248/*
249 Local Variables:
250 mode:c++
251 c-file-style:"stroustrup"
252 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
253 indent-tabs-mode:nil
254 fill-column:99
255 End:
256*/
257// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
3x3 matrix representing an affine transformation.
Definition affine.h:70
Axis aligned, non-empty, generic rectangle.
Two-dimensional point with integer coordinates.
Definition int-point.h:57
Two-dimensional point that doubles as a vector.
Definition point.h:66
IntPoint round() const
Round to nearest integer coordinates.
Definition point.h:202
Axis aligned, non-empty rectangle.
Definition rect.h:92
A mask representing a subset of EventTypes.
Definition enums.h:38
A widget for Inkscape's canvas.
Definition canvas.h:62
void on_key_released(Gtk::EventControllerKey const &controller, unsigned keyval, unsigned keycode, Gdk::ModifierType state)
Definition canvas.cpp:1129
void set_cms_active(bool active)
Definition canvas.h:105
Inkscape::SplitDirection _split_direction
Definition canvas.h:225
void request_update()
Redraw after changing canvas item geometry.
Definition canvas.cpp:1681
void set_pos(const Geom::IntPoint &pos)
Scroll window so drawing point 'pos' is at upper left corner of canvas.
Definition canvas.cpp:1693
Geom::Affine _affine
The affine that we have been requested to draw at.
Definition canvas.h:195
friend class CanvasPrivate
Definition canvas.h:238
bool on_scroll(Gtk::EventControllerScroll const &controller, double dx, double dy)
Definition canvas.cpp:936
Geom::IntPoint get_dimensions() const
Definition canvas.cpp:1536
sigc::signal< void()> _signal_focus_in
Definition canvas.h:232
Inkscape::SplitMode _split_mode
Definition canvas.h:199
Inkscape::SplitDirection _hover_direction
Definition canvas.h:227
Inkscape::SplitMode get_split_mode() const
Definition canvas.h:100
int _state
Last known modifier state (SHIFT, CTRL, etc.).
Definition canvas.h:214
Inkscape::CanvasItem * get_grabbed_canvas_item() const
Definition canvas.h:140
void paint_widget(Cairo::RefPtr< Cairo::Context > const &) final
Reimplement to render the widget.
Definition canvas.cpp:1950
void set_desktop(SPDesktop *desktop)
Definition canvas.h:72
SPDesktop * get_desktop() const
Definition canvas.h:73
void set_page(uint32_t rgba)
Set the page colour.
Definition canvas.cpp:1746
Gtk::EventSequenceState on_button_pressed(Gtk::GestureClick const &controller, int n_press, double x, double y)
Definition canvas.cpp:951
Gtk::EventSequenceState on_button_released(Gtk::GestureClick const &controller, int n_press, double x, double y)
Definition canvas.cpp:997
bool on_key_pressed(Gtk::EventControllerKey const &controller, unsigned keyval, unsigned keycode, Gdk::ModifierType state)
Definition canvas.cpp:1112
CanvasItemGroup * get_canvas_item_root() const
Definition canvas.cpp:532
void size_allocate_vfunc(int width, int height, int baseline) final
Definition canvas.cpp:1891
const Geom::Affine & get_affine() const
Definition canvas.h:86
Inkscape::ColorMode _color_mode
Definition canvas.h:200
Inkscape::CanvasItem * _grabbed_canvas_item
Item that holds a pointer grab; nullptr if none.
Definition canvas.h:218
Inkscape::RenderMode get_render_mode() const
Definition canvas.h:98
sigc::signal< void()> _signal_focus_out
Definition canvas.h:233
void on_leave(Gtk::EventControllerMotion const &controller)
Definition canvas.cpp:1085
sigc::connection connectResize(sigc::slot< void()> &&slot)
Definition canvas.h:149
void set_antialiasing_enabled(bool enabled)
Definition canvas.cpp:1782
void set_pos(const Geom::Point &fpos)
Definition canvas.h:83
void canvas_item_destructed(Inkscape::CanvasItem *item)
Clear current and grabbed items.
Definition canvas.cpp:1801
void set_clip_to_page_mode(bool clip)
Definition canvas.cpp:1790
sigc::signal< void()> _signal_resize
Definition canvas.h:231
bool _is_dragging
Used in selection-chemistry to block undo/redo.
Definition canvas.h:213
bool _all_enter_events
Keep all enter events. Only set true in connector-tool.cpp.
Definition canvas.h:212
void redraw_area(Geom::Rect const &area)
Definition canvas.cpp:1673
sigc::connection connectFocusOut(sigc::slot< void()> &&slot)
Definition canvas.h:151
void set_cms_transform()
Set the lcms transform.
Definition canvas.cpp:1838
Geom::IntPoint _pos
Coordinates of top-left pixel of canvas view within canvas.
Definition canvas.h:194
void set_render_mode(Inkscape::RenderMode mode)
Definition canvas.cpp:1756
void set_drawing(Inkscape::Drawing *drawing)
Definition canvas.cpp:519
Glib::RefPtr< Gdk::GLContext > create_context() final
Reimplement to create the desired OpenGL context.
Definition canvas.cpp:1927
Geom::IntPoint _split_drag_start
Definition canvas.h:229
sigc::connection connectFocusIn(sigc::slot< void()> &&slot)
Definition canvas.h:150
Geom::IntRect get_area_world() const
Return the area shown in the canvas in world coordinates.
Definition canvas.cpp:1560
std::unique_ptr< CanvasPrivate > d
Definition canvas.h:239
void set_current_canvas_item(Inkscape::CanvasItem *item)
Definition canvas.h:137
void set_color_mode(Inkscape::ColorMode mode)
Definition canvas.cpp:1763
void on_motion(Gtk::EventControllerMotion const &controller, double x, double y)
Definition canvas.cpp:1146
Inkscape::Drawing * _drawing
Definition canvas.h:191
void redraw_all()
Invalidate drawing and redraw during idle.
Definition canvas.cpp:1610
bool canvas_point_in_outline_zone(Geom::Point const &world) const
Return whether a point in screen space / canvas coordinates is inside the region of the canvas where ...
Definition canvas.cpp:1569
Inkscape::CanvasItem * _current_canvas_item
Item containing cursor, nullptr if none.
Definition canvas.h:216
bool get_cms_active() const
Definition canvas.h:106
Inkscape::RenderMode _render_mode
Definition canvas.h:198
void set_all_enter_events(bool on)
Definition canvas.h:145
void set_border(uint32_t rgba)
Set the page border colour.
Definition canvas.cpp:1736
bool world_point_inside_canvas(Geom::Point const &world) const
Is world point inside canvas area?
Definition canvas.cpp:1544
void set_split_mode(Inkscape::SplitMode mode)
Definition canvas.cpp:1771
std::optional< Geom::Point > get_last_mouse() const
Return the last known mouse position of center if off-canvas.
Definition canvas.cpp:1590
const Geom::IntPoint & get_pos() const
Definition canvas.h:85
bool _left_grabbed_item
Relied upon by connector tool.
Definition canvas.h:211
Geom::Point canvas_to_world(Geom::Point const &window) const
Translate point in canvas to world coordinates.
Definition canvas.cpp:1552
Inkscape::CanvasItem * _current_canvas_item_new
Item to become _current_item, nullptr if none.
Definition canvas.h:217
const Geom::Affine & get_geom_affine() const
Definition canvas.cpp:1595
void set_desk(uint32_t rgba)
Set the desk colour.
Definition canvas.cpp:1723
void set_grabbed_canvas_item(Inkscape::CanvasItem *item, EventMask mask)
Definition canvas.h:141
void on_enter(Gtk::EventControllerMotion const &controller, double x, double y)
Definition canvas.cpp:1068
Inkscape::CanvasItem * get_current_canvas_item() const
Definition canvas.h:136
void set_affine(const Geom::Affine &affine)
Set the affine for the canvas.
Definition canvas.cpp:1708
Inkscape::ColorMode get_color_mode() const
Definition canvas.h:99
std::shared_ptr< Colors::CMS::Transform > _cms_transform
The lcms transform to apply to canvas.
Definition canvas.h:205
A widget that can dynamically switch between a Gtk::DrawingArea and a Gtk::GLArea.
Definition optglarea.h:20
To do: update description of desktop.
Definition desktop.h:149
double Coord
Floating point type used to store coordinates.
Definition coord.h:76
SPItem * item
Axis-aligned rectangle with integer coordinates.
Control handle rendering/caching.
Various utility functions.
Definition affine.h:22
Definition desktop.h:50
static constexpr int height
Helper class to stream background task notifications as a series of messages.
static T clip(T const &v, T const &a, T const &b)
int mode
Axis-aligned rectangle.
TODO: insert short description here.
SPDesktop * desktop
double width