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
14
#include "
display/control/canvas-item-enums.h
"
15
#include "
live_effects/effect.h
"
16
#include "
ui/tools/freehand-base.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
21
namespace
Inkscape
{
22
class
CanvasItemCtrl;
23
class
CanvasItemCurve;
24
25
struct
ButtonPressEvent;
26
struct
MotionEvent;
27
struct
ButtonReleaseEvent;
28
struct
KeyPressEvent;
29
struct
KeyReleaseEvent;
30
}
// namespace Inkscape
31
32
namespace
Inkscape::UI::Tools
{
33
37
class
PenTool
:
public
FreehandBase
38
{
39
public
:
40
PenTool
(
SPDesktop
*
desktop
,
41
std::string &&
prefs_path
=
"/tools/freehand/pen"
,
42
std::string &&cursor_filename =
"pen.svg"
);
43
~PenTool
()
override
;
44
45
enum
Mode
{
46
MODE_CLICK
,
47
MODE_DRAG
48
};
49
50
enum
State
{
51
POINT
,
52
CONTROL
,
53
CLOSE
,
54
STOP
,
55
DEAD
56
};
57
58
Geom::Point
p_array
[5];
59
Geom::Point
previous
;
61
// npoints somehow determines the type of the node (what does it mean, exactly? the number of Bezier handles?)
62
gint
npoints
= 0;
63
64
Mode
mode
=
MODE_CLICK
;
65
State
state
=
POINT
;
66
bool
polylines_only
=
false
;
67
bool
polylines_paraxial
=
false
;
68
Geom::Point
paraxial_angle
;
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
75
SPLPEItem
*
waiting_item
=
nullptr
;
76
77
CanvasItemPtr<CanvasItemCtrl>
ctrl
[4];
// Origin, Start, Center, End point of path.
78
static
constexpr
std::array<CanvasItemCtrlType, 4>
ctrl_types
= {
79
CANVAS_ITEM_CTRL_TYPE_NODE_SMOOTH
,
CANVAS_ITEM_CTRL_TYPE_ROTATE
,
80
CANVAS_ITEM_CTRL_TYPE_ROTATE
,
CANVAS_ITEM_CTRL_TYPE_NODE_SMOOTH
};
81
82
CanvasItemPtr<CanvasItemCurve>
cl0
;
83
CanvasItemPtr<CanvasItemCurve>
cl1
;
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
92
protected
:
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
97
private
:
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
113
void
_bsplineSpiroStartAnchor
(
bool
shift
);
114
//continues the existing curve with the union node in bspline or spiro modes
115
void
_bsplineSpiroStartAnchorOn
();
116
//continues an existing curve with the union node in CUSP mode
117
void
_bsplineSpiroStartAnchorOff
();
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
121
void
_bsplineSpiroEndAnchorOn
();
122
//closes the curve with the last node in CUSP mode
123
void
_bsplineSpiroEndAnchorOff
();
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
162
Util::ActionAccel
_acc_to_line
;
163
Util::ActionAccel
_acc_to_curve
;
164
Util::ActionAccel
_acc_to_guides
;
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 :
origin
Point origin
Definition
aa.cpp:227
set
bool set
Definition
actions-canvas-snapping.cpp:86
canvas-item-enums.h
Enums for CanvasItems.
CanvasItemPtr
std::unique_ptr< T, CanvasItemUnlinkDeleter > CanvasItemPtr
Smart pointer used to hold CanvasItems, like std::unique_ptr.
Definition
canvas-item-ptr.h:27
Geom::Point
Two-dimensional point that doubles as a vector.
Definition
point.h:66
Inkscape::LivePathEffect::Effect
Definition
effect.h:75
Inkscape::Preferences::Entry
Data type representing a typeless value of a preference.
Definition
preferences.h:152
Inkscape::UI::Tools::FreehandBase
Definition
freehand-base.h:45
Inkscape::UI::Tools::PenTool
PenTool: a context for pen tool events.
Definition
pen-tool.h:38
Inkscape::UI::Tools::PenTool::_acc_to_curve
Util::ActionAccel _acc_to_curve
Definition
pen-tool.h:163
Inkscape::UI::Tools::PenTool::_desktop_destroy
sigc::connection _desktop_destroy
Definition
pen-tool.h:156
Inkscape::UI::Tools::PenTool::bspline
bool bspline
Definition
pen-tool.h:71
Inkscape::UI::Tools::PenTool::_finish
void _finish(bool closed)
Definition
pen-tool.cpp:1852
Inkscape::UI::Tools::PenTool::State
State
Definition
pen-tool.h:50
Inkscape::UI::Tools::PenTool::DEAD
@ DEAD
Definition
pen-tool.h:55
Inkscape::UI::Tools::PenTool::CONTROL
@ CONTROL
Definition
pen-tool.h:52
Inkscape::UI::Tools::PenTool::STOP
@ STOP
Definition
pen-tool.h:54
Inkscape::UI::Tools::PenTool::CLOSE
@ CLOSE
Definition
pen-tool.h:53
Inkscape::UI::Tools::PenTool::POINT
@ POINT
Definition
pen-tool.h:51
Inkscape::UI::Tools::PenTool::_endpointSnap
void _endpointSnap(Geom::Point &p, guint const state)
Snaps new node relative to the previous node.
Definition
pen-tool.cpp:173
Inkscape::UI::Tools::PenTool::_handleMotionNotify
bool _handleMotionNotify(MotionEvent const &event)
Handle motion_notify event.
Definition
pen-tool.cpp:465
Inkscape::UI::Tools::PenTool::waiting_LPE
Inkscape::LivePathEffect::Effect * waiting_LPE
Definition
pen-tool.h:74
Inkscape::UI::Tools::PenTool::_setToNearestHorizVert
void _setToNearestHorizVert(Geom::Point &pt, guint const state) const
Definition
pen-tool.cpp:1925
Inkscape::UI::Tools::PenTool::root_handler
bool root_handler(CanvasEvent const &event) override
Callback to handle all pen events.
Definition
pen-tool.cpp:237
Inkscape::UI::Tools::PenTool::cl1
CanvasItemPtr< CanvasItemCurve > cl1
Definition
pen-tool.h:83
Inkscape::UI::Tools::PenTool::spiro
bool spiro
Definition
pen-tool.h:70
Inkscape::UI::Tools::PenTool::_redoLastPoint
bool _redoLastPoint()
Re-add the last undone point to the path being drawn.
Definition
pen-tool.cpp:1825
Inkscape::UI::Tools::PenTool::_redrawAll
void _redrawAll()
Definition
pen-tool.cpp:755
Inkscape::UI::Tools::PenTool::_bsplineSpiro
void _bsplineSpiro(bool shift)
Definition
pen-tool.cpp:1214
Inkscape::UI::Tools::PenTool::_bsplineSpiroStartAnchorOff
void _bsplineSpiroStartAnchorOff()
Definition
pen-tool.cpp:1314
Inkscape::UI::Tools::PenTool::_redo_stack
std::vector< Geom::PathVector > _redo_stack
History of undone events.
Definition
pen-tool.h:159
Inkscape::UI::Tools::PenTool::hasWaitingLPE
bool hasWaitingLPE()
Definition
pen-tool.cpp:164
Inkscape::UI::Tools::PenTool::_lastpointToCurve
void _lastpointToCurve()
Definition
pen-tool.cpp:851
Inkscape::UI::Tools::PenTool::_acc_to_line
Util::ActionAccel _acc_to_line
Definition
pen-tool.h:162
Inkscape::UI::Tools::PenTool::polylines_only
bool polylines_only
Definition
pen-tool.h:66
Inkscape::UI::Tools::PenTool::_finishSegment
void _finishSegment(Geom::Point p, guint state)
Definition
pen-tool.cpp:1699
Inkscape::UI::Tools::PenTool::_bsplineSpiroOn
void _bsplineSpiroOn()
Definition
pen-tool.cpp:1224
Inkscape::UI::Tools::PenTool::_enableEvents
void _enableEvents()
Definition
pen-tool.cpp:1890
Inkscape::UI::Tools::PenTool::item_handler
bool item_handler(SPItem *item, CanvasEvent const &event) override
Handles item specific events.
Definition
pen-tool.cpp:217
Inkscape::UI::Tools::PenTool::_lastpointMoveScreen
void _lastpointMoveScreen(gdouble x, gdouble y)
Definition
pen-tool.cpp:846
Inkscape::UI::Tools::PenTool::_handleButtonPress
bool _handleButtonPress(ButtonPressEvent const &event)
Handle mouse single button press event.
Definition
pen-tool.cpp:267
Inkscape::UI::Tools::PenTool::_setCtrl
void _setCtrl(Geom::Point const p, guint state)
Definition
pen-tool.cpp:1645
Inkscape::UI::Tools::PenTool::_handle2ButtonPress
bool _handle2ButtonPress(ButtonPressEvent const &event)
Handle mouse double button press event.
Definition
pen-tool.cpp:452
Inkscape::UI::Tools::PenTool::waitForLPEMouseClicks
void waitForLPEMouseClicks(Inkscape::LivePathEffect::EffectType effect_type, unsigned int num_clicks, bool use_polylines=true)
Definition
pen-tool.cpp:1896
Inkscape::UI::Tools::PenTool::_setSubsequentPoint
void _setSubsequentPoint(Geom::Point const p, bool statusbar, guint status=0)
Definition
pen-tool.cpp:1592
Inkscape::UI::Tools::PenTool::_setInitialPoint
void _setInitialPoint(Geom::Point const p)
Definition
pen-tool.cpp:1129
Inkscape::UI::Tools::PenTool::nextParaxialDirection
void nextParaxialDirection(Geom::Point const &pt, Geom::Point const &origin, guint state)
Definition
pen-tool.cpp:1906
Inkscape::UI::Tools::PenTool::_disableEvents
void _disableEvents()
Definition
pen-tool.cpp:1886
Inkscape::UI::Tools::PenTool::_handleKeyPress
bool _handleKeyPress(KeyPressEvent const &event)
Definition
pen-tool.cpp:952
Inkscape::UI::Tools::PenTool::waiting_item
SPLPEItem * waiting_item
Definition
pen-tool.h:75
Inkscape::UI::Tools::PenTool::_acc_to_guides
Util::ActionAccel _acc_to_guides
Definition
pen-tool.h:164
Inkscape::UI::Tools::PenTool::events_disabled
bool events_disabled
Definition
pen-tool.h:85
Inkscape::UI::Tools::PenTool::_resetColors
void _resetColors()
Definition
pen-tool.cpp:1103
Inkscape::UI::Tools::PenTool::_bsplineSpiroEndAnchorOn
void _bsplineSpiroEndAnchorOn()
Definition
pen-tool.cpp:1431
Inkscape::UI::Tools::PenTool::~PenTool
~PenTool() override
Definition
pen-tool.cpp:97
Inkscape::UI::Tools::PenTool::_cancel
void _cancel()
Definition
pen-tool.cpp:136
Inkscape::UI::Tools::PenTool::mode
Mode mode
Definition
pen-tool.h:64
Inkscape::UI::Tools::PenTool::_did_redo
bool _did_redo
Definition
pen-tool.h:160
Inkscape::UI::Tools::PenTool::_bsplineSpiroMotion
void _bsplineSpiroMotion(guint const state)
Definition
pen-tool.cpp:1331
Inkscape::UI::Tools::PenTool::_lastpointMove
void _lastpointMove(gdouble x, gdouble y)
Definition
pen-tool.cpp:815
Inkscape::UI::Tools::PenTool::cl0
CanvasItemPtr< CanvasItemCurve > cl0
Definition
pen-tool.h:82
Inkscape::UI::Tools::PenTool::_bsplineSpiroBuild
void _bsplineSpiroBuild()
Definition
pen-tool.cpp:1521
Inkscape::UI::Tools::PenTool::polylines_paraxial
bool polylines_paraxial
Definition
pen-tool.h:67
Inkscape::UI::Tools::PenTool::expecting_clicks_for_LPE
unsigned int expecting_clicks_for_LPE
Definition
pen-tool.h:73
Inkscape::UI::Tools::PenTool::npoints
gint npoints
\invar npoints in {0, 2, 5}.
Definition
pen-tool.h:62
Inkscape::UI::Tools::PenTool::setPolylineMode
void setPolylineMode()
Definition
pen-tool.cpp:121
Inkscape::UI::Tools::PenTool::p_array
Geom::Point p_array[5]
Definition
pen-tool.h:58
Inkscape::UI::Tools::PenTool::_handleButtonRelease
bool _handleButtonRelease(ButtonReleaseEvent const &event)
Handle mouse button release event.
Definition
pen-tool.cpp:633
Inkscape::UI::Tools::PenTool::_bsplineSpiroColor
void _bsplineSpiroColor()
Definition
pen-tool.cpp:1169
Inkscape::UI::Tools::PenTool::_lastpointToLine
void _lastpointToLine()
Definition
pen-tool.cpp:906
Inkscape::UI::Tools::PenTool::_bsplineSpiroOff
void _bsplineSpiroOff()
Definition
pen-tool.cpp:1235
Inkscape::UI::Tools::PenTool::_bsplineSpiroEndAnchorOff
void _bsplineSpiroEndAnchorOff()
Definition
pen-tool.cpp:1479
Inkscape::UI::Tools::PenTool::_bsplineSpiroStartAnchor
void _bsplineSpiroStartAnchor(bool shift)
Definition
pen-tool.cpp:1245
Inkscape::UI::Tools::PenTool::previous
Geom::Point previous
Definition
pen-tool.h:59
Inkscape::UI::Tools::PenTool::_bsplineSpiroStartAnchorOn
void _bsplineSpiroStartAnchorOn()
Definition
pen-tool.cpp:1290
Inkscape::UI::Tools::PenTool::state
State state
Definition
pen-tool.h:65
Inkscape::UI::Tools::PenTool::ctrl_types
static constexpr std::array< CanvasItemCtrlType, 4 > ctrl_types
Definition
pen-tool.h:78
Inkscape::UI::Tools::PenTool::ctrl
CanvasItemPtr< CanvasItemCtrl > ctrl[4]
Definition
pen-tool.h:77
Inkscape::UI::Tools::PenTool::_undoLastPoint
bool _undoLastPoint(bool user_undo=false)
Definition
pen-tool.cpp:1735
Inkscape::UI::Tools::PenTool::Mode
Mode
Definition
pen-tool.h:45
Inkscape::UI::Tools::PenTool::MODE_DRAG
@ MODE_DRAG
Definition
pen-tool.h:47
Inkscape::UI::Tools::PenTool::MODE_CLICK
@ MODE_CLICK
Definition
pen-tool.h:46
Inkscape::UI::Tools::PenTool::_setAngleDistanceStatusMessage
void _setAngleDistanceStatusMessage(Geom::Point const p, int pc_point_to_compare, gchar const *message)
Show the status message for the current line/curve segment.
Definition
pen-tool.cpp:1144
Inkscape::UI::Tools::PenTool::_endpointSnapHandle
void _endpointSnapHandle(Geom::Point &p, guint const state)
Snaps new node's handle relative to the new node.
Definition
pen-tool.cpp:203
Inkscape::UI::Tools::PenTool::paraxial_angle
Geom::Point paraxial_angle
Definition
pen-tool.h:68
Inkscape::Util::ActionAccel
The ActionAccel class stores the keyboard shortcuts for a given action and automatically keeps track ...
Definition
action-accel.h:78
SPDesktop
To do: update description of desktop.
Definition
desktop.h:149
SPItem
Base class for visual SVG elements.
Definition
sp-item.h:109
SPLPEItem
Definition
sp-lpe-item.h:47
freehand-base.h
prefs_path
static Glib::ustring const prefs_path
Definition
gradient-vector-selector.cpp:44
item
SPItem * item
Definition
imagemagick.cpp:43
effect.h
shift
void shift(T &a, T &b, T const &c)
Definition
match-curve.cpp:21
Inkscape::LivePathEffect::EffectType
EffectType
Definition
effect-enum.h:20
Inkscape::UI::Tools
Definition
desktop.h:121
Inkscape
Helper class to stream background task notifications as a series of messages.
Definition
actions-canvas-snapping.h:27
Inkscape::CANVAS_ITEM_CTRL_TYPE_NODE_SMOOTH
@ CANVAS_ITEM_CTRL_TYPE_NODE_SMOOTH
Definition
canvas-item-enums.h:63
Inkscape::CANVAS_ITEM_CTRL_TYPE_ROTATE
@ CANVAS_ITEM_CTRL_TYPE_ROTATE
Definition
canvas-item-enums.h:53
Inkscape::ButtonPressEvent
A mouse button (left/right/middle) is pressed.
Definition
canvas-event.h:119
Inkscape::ButtonReleaseEvent
A mouse button (left/right/middle) is released.
Definition
canvas-event.h:134
Inkscape::CanvasEvent
Abstract base class for events.
Definition
canvas-event.h:64
Inkscape::KeyPressEvent
A key has been pressed.
Definition
canvas-event.h:186
Inkscape::MotionEvent
Movement of the mouse pointer.
Definition
canvas-event.h:203
desktop
SPDesktop * desktop
Definition
tabs-widget.cpp:70
src
ui
tools
pen-tool.h
Generated on Sun Jul 6 2025 04:02:05 for Inkscape by
1.9.8