Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
pen-tool.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifndef INKSCAPE_UI_TOOLS_PEN_TOOl_H
3#define INKSCAPE_UI_TOOLS_PEN_TOOl_H
4
/*
8 * Authors: see git history
9 *
10 * Copyright (C) 2018 Authors
11 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
12 */
13
15#include "live_effects/effect.h"
17
18#define SP_PEN_CONTEXT(obj) (dynamic_cast<Inkscape::UI::Tools::PenTool*>((Inkscape::UI::Tools::ToolBase*)obj))
19#define SP_IS_PEN_CONTEXT(obj) (dynamic_cast<const Inkscape::UI::Tools::PenTool*>((const Inkscape::UI::Tools::ToolBase*)obj) != NULL)
20
21namespace Inkscape {
22class CanvasItemCtrl;
23class CanvasItemCurve;
24
25struct ButtonPressEvent;
26struct MotionEvent;
27struct ButtonReleaseEvent;
28struct KeyPressEvent;
29struct KeyReleaseEvent;
30} // namespace Inkscape
31
32namespace Inkscape::UI::Tools {
33
37class PenTool : public FreehandBase
38{
39public:
41 std::string &&prefs_path = "/tools/freehand/pen",
42 std::string &&cursor_filename = "pen.svg");
43 ~PenTool() override;
44
49
57
61 // npoints somehow determines the type of the node (what does it mean, exactly? the number of Bezier handles?)
62 gint npoints = 0;
63
66 bool polylines_only = false;
67 bool polylines_paraxial = false;
69
70 bool spiro = false; // Spiro mode active?
71 bool bspline = false; // BSpline mode active?
72
73 unsigned int expecting_clicks_for_LPE = 0; // if positive, finish the path after this many clicks
74 Inkscape::LivePathEffect::Effect *waiting_LPE = nullptr; // if NULL, waiting_LPE_type in SPDrawContext is taken into account
76
77 CanvasItemPtr<CanvasItemCtrl> ctrl[4]; // Origin, Start, Center, End point of path.
81
84
85 bool events_disabled = false;
86
87 void nextParaxialDirection(Geom::Point const &pt, Geom::Point const &origin, guint state);
88 void setPolylineMode();
89 bool hasWaitingLPE();
90 void waitForLPEMouseClicks(Inkscape::LivePathEffect::EffectType effect_type, unsigned int num_clicks, bool use_polylines = true);
91
92protected:
93 void set(Inkscape::Preferences::Entry const &val) override;
94 bool root_handler(CanvasEvent const &event) override;
95 bool item_handler(SPItem* item, CanvasEvent const &event) override;
96
97private:
98 bool _handleButtonPress(ButtonPressEvent const &event);
99 bool _handle2ButtonPress(ButtonPressEvent const &event);
100 bool _handleMotionNotify(MotionEvent const &event);
101 bool _handleButtonRelease(ButtonReleaseEvent const &event);
102 bool _handleKeyPress(KeyPressEvent const &event);
103
104 //this function changes the colors red, green and blue making them transparent or not depending on if the function uses spiro
105 void _bsplineSpiroColor();
106 //creates a node in bspline or spiro modes
107 void _bsplineSpiro(bool shift);
108 //creates a node in bspline or spiro modes
109 void _bsplineSpiroOn();
110 //creates a CUSP node
111 void _bsplineSpiroOff();
112 //continues the existing curve in bspline or spiro mode
114 //continues the existing curve with the union node in bspline or spiro modes
116 //continues an existing curve with the union node in CUSP mode
118 //modifies the "red_curve" when it detects movement
119 void _bsplineSpiroMotion(guint const state);
120 //closes the curve with the last node in bspline or spiro mode
122 //closes the curve with the last node in CUSP mode
124 //apply the effect
125 void _bsplineSpiroBuild();
126
127 void _setInitialPoint(Geom::Point const p);
128 void _setSubsequentPoint(Geom::Point const p, bool statusbar, guint status = 0);
129 void _setCtrl(Geom::Point const p, guint state);
130 void _finishSegment(Geom::Point p, guint state);
131 bool _undoLastPoint(bool user_undo = false);
132 bool _redoLastPoint();
133
134 void _finish(bool closed);
135
136 void _resetColors();
137
138 void _disableEvents();
139 void _enableEvents();
140
141 void _setToNearestHorizVert(Geom::Point &pt, guint const state) const;
142
143 void _setAngleDistanceStatusMessage(Geom::Point const p, int pc_point_to_compare, gchar const *message);
144
145 void _lastpointToLine();
146 void _lastpointToCurve();
147 void _lastpointMoveScreen(gdouble x, gdouble y);
148 void _lastpointMove(gdouble x, gdouble y);
149 void _redrawAll();
150
151 void _endpointSnapHandle(Geom::Point &p, guint const state);
152 void _endpointSnap(Geom::Point &p, guint const state);
153
154 void _cancel();
155
156 sigc::connection _desktop_destroy;
157 // NOTE: undoing work in progress always deletes the last added point,
158 // so there's no need for an undo stack.
159 std::vector<Geom::PathVector> _redo_stack;
160 bool _did_redo = false;
161
165};
166
167} // namespace Inkscape:UI::Tools
168
169#endif // INKSCAPE_UI_TOOLS_PEN_TOOl_H
170
171/*
172 Local Variables:
173 mode:c++
174 c-file-style:"stroustrup"
175 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
176 indent-tabs-mode:nil
177 fill-column:99
178 End:
179*/
180// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Point origin
Definition aa.cpp:227
Enums for CanvasItems.
std::unique_ptr< T, CanvasItemUnlinkDeleter > CanvasItemPtr
Smart pointer used to hold CanvasItems, like std::unique_ptr.
Two-dimensional point that doubles as a vector.
Definition point.h:66
Data type representing a typeless value of a preference.
PenTool: a context for pen tool events.
Definition pen-tool.h:38
Util::ActionAccel _acc_to_curve
Definition pen-tool.h:163
sigc::connection _desktop_destroy
Definition pen-tool.h:156
void _finish(bool closed)
void _endpointSnap(Geom::Point &p, guint const state)
Snaps new node relative to the previous node.
Definition pen-tool.cpp:173
bool _handleMotionNotify(MotionEvent const &event)
Handle motion_notify event.
Definition pen-tool.cpp:465
Inkscape::LivePathEffect::Effect * waiting_LPE
Definition pen-tool.h:74
void _setToNearestHorizVert(Geom::Point &pt, guint const state) const
bool root_handler(CanvasEvent const &event) override
Callback to handle all pen events.
Definition pen-tool.cpp:237
CanvasItemPtr< CanvasItemCurve > cl1
Definition pen-tool.h:83
bool _redoLastPoint()
Re-add the last undone point to the path being drawn.
void _bsplineSpiro(bool shift)
std::vector< Geom::PathVector > _redo_stack
History of undone events.
Definition pen-tool.h:159
Util::ActionAccel _acc_to_line
Definition pen-tool.h:162
void _finishSegment(Geom::Point p, guint state)
bool item_handler(SPItem *item, CanvasEvent const &event) override
Handles item specific events.
Definition pen-tool.cpp:217
void _lastpointMoveScreen(gdouble x, gdouble y)
Definition pen-tool.cpp:846
bool _handleButtonPress(ButtonPressEvent const &event)
Handle mouse single button press event.
Definition pen-tool.cpp:267
void _setCtrl(Geom::Point const p, guint state)
bool _handle2ButtonPress(ButtonPressEvent const &event)
Handle mouse double button press event.
Definition pen-tool.cpp:452
void waitForLPEMouseClicks(Inkscape::LivePathEffect::EffectType effect_type, unsigned int num_clicks, bool use_polylines=true)
void _setSubsequentPoint(Geom::Point const p, bool statusbar, guint status=0)
void _setInitialPoint(Geom::Point const p)
void nextParaxialDirection(Geom::Point const &pt, Geom::Point const &origin, guint state)
bool _handleKeyPress(KeyPressEvent const &event)
Definition pen-tool.cpp:952
Util::ActionAccel _acc_to_guides
Definition pen-tool.h:164
void _bsplineSpiroMotion(guint const state)
void _lastpointMove(gdouble x, gdouble y)
Definition pen-tool.cpp:815
CanvasItemPtr< CanvasItemCurve > cl0
Definition pen-tool.h:82
unsigned int expecting_clicks_for_LPE
Definition pen-tool.h:73
gint npoints
\invar npoints in {0, 2, 5}.
Definition pen-tool.h:62
bool _handleButtonRelease(ButtonReleaseEvent const &event)
Handle mouse button release event.
Definition pen-tool.cpp:633
void _bsplineSpiroStartAnchor(bool shift)
static constexpr std::array< CanvasItemCtrlType, 4 > ctrl_types
Definition pen-tool.h:78
CanvasItemPtr< CanvasItemCtrl > ctrl[4]
Definition pen-tool.h:77
bool _undoLastPoint(bool user_undo=false)
void _setAngleDistanceStatusMessage(Geom::Point const p, int pc_point_to_compare, gchar const *message)
Show the status message for the current line/curve segment.
void _endpointSnapHandle(Geom::Point &p, guint const state)
Snaps new node's handle relative to the new node.
Definition pen-tool.cpp:203
The ActionAccel class stores the keyboard shortcuts for a given action and automatically keeps track ...
To do: update description of desktop.
Definition desktop.h:149
Base class for visual SVG elements.
Definition sp-item.h:109
static Glib::ustring const prefs_path
SPItem * item
void shift(T &a, T &b, T const &c)
Helper class to stream background task notifications as a series of messages.
@ CANVAS_ITEM_CTRL_TYPE_NODE_SMOOTH
@ CANVAS_ITEM_CTRL_TYPE_ROTATE
A mouse button (left/right/middle) is pressed.
A mouse button (left/right/middle) is released.
Abstract base class for events.
A key has been pressed.
Movement of the mouse pointer.
SPDesktop * desktop