Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Inkscape::UI::Tools::PenTool Class Reference

PenTool: a context for pen tool events. More...

#include <pen-tool.h>

Inheritance diagram for Inkscape::UI::Tools::PenTool:
Inkscape::UI::Tools::FreehandBase Inkscape::UI::Tools::ToolBase Inkscape::UI::Tools::LpeTool

Public Types

enum  Mode { MODE_CLICK , MODE_DRAG }
 
enum  State {
  POINT , CONTROL , CLOSE , STOP ,
  DEAD
}
 

Public Member Functions

 PenTool (SPDesktop *desktop, std::string &&prefs_path="/tools/freehand/pen", std::string &&cursor_filename="pen.svg")
 
 ~PenTool () override
 
void nextParaxialDirection (Geom::Point const &pt, Geom::Point const &origin, guint state)
 
void setPolylineMode ()
 
bool hasWaitingLPE ()
 
void waitForLPEMouseClicks (Inkscape::LivePathEffect::EffectType effect_type, unsigned int num_clicks, bool use_polylines=true)
 
- Public Member Functions inherited from Inkscape::UI::Tools::FreehandBase
 FreehandBase (SPDesktop *desktop, std::string &&prefs_path, std::string &&cursor_filename)
 
 ~FreehandBase () override
 
std::optional< Geom::Pointred_curve_get_last_point () const
 
void onSelectionModified ()
 
- Public Member Functions inherited from Inkscape::UI::Tools::ToolBase
 ToolBase (SPDesktop *desktop, std::string &&prefs_path, std::string &&cursor_filename, bool uses_snap=true)
 
virtual ~ToolBase ()
 
virtual void menu_popup (CanvasEvent const &event, SPObject *obj=nullptr)
 Create popup menu and tell Gtk to show it.
 
virtual bool can_undo (bool redo=false)
 
virtual bool is_ready () const
 
virtual void switching_away (std::string const &new_tool)
 
std::string const & getPrefsPath () const
 
void enableSelectionCue (bool enable=true)
 Enables/disables the ToolBase's SelCue.
 
MessageContextdefaultMessageContext () const
 
SPDesktopgetDesktop () const
 
SPGroupcurrentLayer () const
 
void set_last_active_tool (Glib::ustring last_tool)
 
const Glib::ustring & get_last_active_tool () const
 
bool start_root_handler (CanvasEvent const &event)
 Handles snapping events for all tools and then passes to tool_root_handler.
 
bool tool_root_handler (CanvasEvent const &event)
 Calls the right tool's event handler, depending on the selected tool and state.
 
bool start_item_handler (SPItem *item, CanvasEvent const &event)
 Starts handling item snapping and pass to virtual_item_handler afterwards.
 
bool virtual_item_handler (SPItem *item, CanvasEvent const &event)
 
bool is_panning () const
 True if we're panning with any method (space bar, middle-mouse, right-mouse+Ctrl)
 
bool is_space_panning () const
 True if we're panning with the space bar.
 
void snap_delay_handler (gpointer item, gpointer item2, MotionEvent const &event, DelayedSnapEvent::Origin origin)
 Analyses the current event, calculates the mouse speed, turns snapping off (temporarily) if the mouse speed is above a threshold, and stores the current event such that it can be re-triggered when needed (re-triggering is controlled by a timeout).
 
void process_delayed_snap_event ()
 When the delayed snap event timer expires, this method will be called and will re-inject the last motion event in an appropriate place, with snapping being turned on again.
 
void discard_delayed_snap_event ()
 If a delayed snap event has been scheduled, this function will cancel it.
 
void set_cursor (std::string filename)
 Sets the current cursor to the given filename.
 
void use_cursor (Glib::RefPtr< Gdk::Cursor > cursor)
 Set the cursor to this specific one, don't remember it.
 
Glib::RefPtr< Gdk::Cursor > get_cursor (Gtk::Widget &widget, std::string const &filename) const
 Returns the Gdk Cursor for the given filename.
 
void use_tool_cursor ()
 Uses the saved cursor, based on the saved filename.
 
void enableGrDrag (bool enable=true)
 
bool deleteSelectedDrag (bool just_one)
 Delete a selected GrDrag point.
 
bool hasGradientDrag () const
 Return true if there is a gradient drag.
 
GrDragget_drag ()
 

Public Attributes

Geom::Point p_array [5]
 
Geom::Point previous
 
gint npoints = 0
 \invar npoints in {0, 2, 5}.
 
Mode mode = MODE_CLICK
 
State state = POINT
 
bool polylines_only = false
 
bool polylines_paraxial = false
 
Geom::Point paraxial_angle
 
bool spiro = false
 
bool bspline = false
 
unsigned int expecting_clicks_for_LPE = 0
 
Inkscape::LivePathEffect::Effectwaiting_LPE = nullptr
 
SPLPEItemwaiting_item = nullptr
 
CanvasItemPtr< CanvasItemCtrlctrl [4]
 
CanvasItemPtr< CanvasItemCurvecl0
 
CanvasItemPtr< CanvasItemCurvecl1
 
bool events_disabled = false
 
- Public Attributes inherited from Inkscape::UI::Tools::FreehandBase
Selectionselection = nullptr
 
CanvasItemPtr< CanvasItemBpathred_bpath
 
Geom::PathVector red_curve
 
CanvasItemPtr< CanvasItemBpathblue_bpath
 
Geom::PathVector blue_curve
 
std::vector< CanvasItemPtr< CanvasItemBpath > > green_bpaths
 
std::shared_ptr< Geom::PathVectorgreen_curve
 
std::unique_ptr< SPDrawAnchorgreen_anchor
 
bool green_closed = false
 
SPItemwhite_item = nullptr
 
std::vector< std::shared_ptr< Geom::PathVector > > white_curves
 
std::vector< std::unique_ptr< SPDrawAnchor > > white_anchors
 
std::shared_ptr< Geom::PathVectorsa_overwrited
 
SPDrawAnchorsa = nullptr
 
SPDrawAnchorea = nullptr
 
LivePathEffect::EffectType waiting_LPE_type = LivePathEffect::INVALID_LPE
 
sigc::connection sel_changed_connection
 
sigc::connection sel_modified_connection
 
bool red_curve_is_valid = false
 
bool anchor_statusbar = false
 
bool tablet_enabled = false
 
bool is_tablet = false
 
double pressure = 1.0
 
- Public Attributes inherited from Inkscape::UI::Tools::ToolBase
std::unique_ptr< MessageContextmessage_context
 
SelCue_selcue = nullptr
 
GrDrag_grdrag = nullptr
 
ShapeEditorshape_editor = nullptr
 
bool _uses_snap = false
 

Static Public Attributes

static constexpr std::array< CanvasItemCtrlType, 4 > ctrl_types
 

Protected Member Functions

void set (Inkscape::Preferences::Entry const &val) override
 Callback that sets key to value in pen context.
 
bool root_handler (CanvasEvent const &event) override
 Callback to handle all pen events.
 
bool item_handler (SPItem *item, CanvasEvent const &event) override
 Handles item specific events.
 
- Protected Member Functions inherited from Inkscape::UI::Tools::FreehandBase
void _attachSelection ()
 
- Protected Member Functions inherited from Inkscape::UI::Tools::ToolBase
void setup_for_drag_start (ButtonPressEvent const &ev)
 
void saveDragOrigin (Geom::Point const &pos)
 
bool checkDragMoved (Geom::Point const &pos)
 Analyse the current position and return true once it has moved farther than tolerance from the drag origin (indicating they intend to move the object, not click).
 
void grabCanvasEvents (EventMask mask=EventType::KEY_PRESS|EventType::BUTTON_RELEASE|EventType::MOTION|EventType::BUTTON_PRESS)
 Grab events from the Canvas Catchall.
 
void ungrabCanvasEvents ()
 Ungrab events from the Canvas Catchall.
 
bool sp_event_context_knot_mouseover () const
 Returns true if we're hovering above a knot (needed because we don't want to pre-snap in that case).
 
void set_high_motion_precision (bool high_precision=true)
 Enable (or disable) high precision for motion events.
 

Private Member Functions

bool _handleButtonPress (ButtonPressEvent const &event)
 Handle mouse single button press event.
 
bool _handle2ButtonPress (ButtonPressEvent const &event)
 Handle mouse double button press event.
 
bool _handleMotionNotify (MotionEvent const &event)
 Handle motion_notify event.
 
bool _handleButtonRelease (ButtonReleaseEvent const &event)
 Handle mouse button release event.
 
bool _handleKeyPress (KeyPressEvent const &event)
 
void _bsplineSpiroColor ()
 
void _bsplineSpiro (bool shift)
 
void _bsplineSpiroOn ()
 
void _bsplineSpiroOff ()
 
void _bsplineSpiroStartAnchor (bool shift)
 
void _bsplineSpiroStartAnchorOn ()
 
void _bsplineSpiroStartAnchorOff ()
 
void _bsplineSpiroMotion (guint const state)
 
void _bsplineSpiroEndAnchorOn ()
 
void _bsplineSpiroEndAnchorOff ()
 
void _bsplineSpiroBuild ()
 
void _setInitialPoint (Geom::Point const p)
 
void _setSubsequentPoint (Geom::Point const p, bool statusbar, guint status=0)
 
void _setCtrl (Geom::Point const p, guint state)
 
void _finishSegment (Geom::Point p, guint state)
 
bool _undoLastPoint (bool user_undo=false)
 
bool _redoLastPoint ()
 Re-add the last undone point to the path being drawn.
 
void _finish (bool closed)
 
void _resetColors ()
 
void _disableEvents ()
 
void _enableEvents ()
 
void _setToNearestHorizVert (Geom::Point &pt, guint const state) const
 
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 _lastpointToLine ()
 
void _lastpointToCurve ()
 
void _lastpointMoveScreen (gdouble x, gdouble y)
 
void _lastpointMove (gdouble x, gdouble y)
 
void _redrawAll ()
 
void _endpointSnapHandle (Geom::Point &p, guint const state)
 Snaps new node's handle relative to the new node.
 
void _endpointSnap (Geom::Point &p, guint const state)
 Snaps new node relative to the previous node.
 
void _cancel ()
 

Private Attributes

sigc::connection _desktop_destroy
 
std::vector< Geom::PathVector_redo_stack
 History of undone events.
 
bool _did_redo = false
 
Util::ActionAccel _acc_to_line
 
Util::ActionAccel _acc_to_curve
 
Util::ActionAccel _acc_to_guides
 

Additional Inherited Members

- Protected Attributes inherited from Inkscape::UI::Tools::FreehandBase
uint32_t red_color = 0xff00007f
 
uint32_t blue_color = 0x0000ff7f
 
uint32_t green_color = 0x00ff007f
 
uint32_t highlight_color = 0x0000007f
 
- Protected Attributes inherited from Inkscape::UI::Tools::ToolBase
Glib::RefPtr< Gdk::Cursor > _cursor
 
std::string _cursor_filename = "select.svg"
 
std::string _cursor_default = "select.svg"
 
Geom::IntPoint xyp
 where drag started
 
bool dragging = false
 are we dragging?
 
int tolerance = 0
 
bool within_tolerance = false
 are we still within tolerance of origin
 
bool _button1on = false
 
bool _button2on = false
 
bool _button3on = false
 
SPItemitem_to_select = nullptr
 the item where mouse_press occurred, to be selected if this is a click not drag
 
SPDesktop_desktop = nullptr
 
Util::ActionAccel _acc_undo
 
Util::ActionAccel _acc_redo
 
Util::ActionAccel _acc_quick_preview
 
Util::ActionAccel _acc_quick_zoom
 
Util::ActionAccel _acc_quick_pan
 

Detailed Description

PenTool: a context for pen tool events.

Definition at line 37 of file pen-tool.h.

Member Enumeration Documentation

◆ Mode

Enumerator
MODE_CLICK 
MODE_DRAG 

Definition at line 45 of file pen-tool.h.

◆ State

Enumerator
POINT 
CONTROL 
CLOSE 
STOP 
DEAD 

Definition at line 50 of file pen-tool.h.

Constructor & Destructor Documentation

◆ PenTool()

◆ ~PenTool()

Member Function Documentation

◆ _bsplineSpiro()

void Inkscape::UI::Tools::PenTool::_bsplineSpiro ( bool  shift)
private

Definition at line 1214 of file pen-tool.cpp.

References _bsplineSpiroBuild(), _bsplineSpiroOff(), _bsplineSpiroOn(), bspline, and spiro.

Referenced by _finishSegment().

◆ _bsplineSpiroBuild()

◆ _bsplineSpiroColor()

◆ _bsplineSpiroEndAnchorOff()

◆ _bsplineSpiroEndAnchorOn()

◆ _bsplineSpiroMotion()

◆ _bsplineSpiroOff()

void Inkscape::UI::Tools::PenTool::_bsplineSpiroOff ( )
private

◆ _bsplineSpiroOn()

◆ _bsplineSpiroStartAnchor()

◆ _bsplineSpiroStartAnchorOff()

void Inkscape::UI::Tools::PenTool::_bsplineSpiroStartAnchorOff ( )
private

◆ _bsplineSpiroStartAnchorOn()

void Inkscape::UI::Tools::PenTool::_bsplineSpiroStartAnchorOn ( )
private

◆ _cancel()

void Inkscape::UI::Tools::PenTool::_cancel ( )
private

◆ _disableEvents()

void Inkscape::UI::Tools::PenTool::_disableEvents ( )
private

Definition at line 1886 of file pen-tool.cpp.

References events_disabled.

Referenced by _finish().

◆ _enableEvents()

void Inkscape::UI::Tools::PenTool::_enableEvents ( )
private

Definition at line 1890 of file pen-tool.cpp.

References events_disabled.

Referenced by _finish().

◆ _endpointSnap()

void Inkscape::UI::Tools::PenTool::_endpointSnap ( Geom::Point p,
guint const  state 
)
private

◆ _endpointSnapHandle()

void Inkscape::UI::Tools::PenTool::_endpointSnapHandle ( Geom::Point p,
guint const  state 
)
private

Snaps new node's handle relative to the new node.

Definition at line 203 of file pen-tool.cpp.

References npoints, origin, p_array, Inkscape::UI::Tools::spdc_endpoint_snap_free(), Inkscape::UI::Tools::spdc_endpoint_snap_rotation(), and state.

Referenced by _handleMotionNotify().

◆ _finish()

◆ _finishSegment()

◆ _handle2ButtonPress()

bool Inkscape::UI::Tools::PenTool::_handle2ButtonPress ( ButtonPressEvent const &  event)
private

Handle mouse double button press event.

Definition at line 452 of file pen-tool.cpp.

References _finish(), Inkscape::ButtonEvent::button, CLOSE, npoints, and state.

◆ _handleButtonPress()

bool Inkscape::UI::Tools::PenTool::_handleButtonPress ( ButtonPressEvent const &  event)
private

Handle mouse single button press event.

Definition at line 267 of file pen-tool.cpp.

References _bsplineSpiroColor(), _bsplineSpiroStartAnchor(), Inkscape::UI::Tools::ToolBase::_button1on, Inkscape::UI::Tools::ToolBase::_desktop, _endpointSnap(), _finish(), _finishSegment(), _setInitialPoint(), _setSubsequentPoint(), bspline, Inkscape::ButtonEvent::button, Inkscape::ObjectSet::clear(), CLOSE, CONTROL, SPDrawAnchor::curve, Inkscape::UI::Tools::ToolBase::defaultMessageContext(), SPDrawAnchor::dp, Inkscape::UI::Tools::FreehandBase::ea, events_disabled, expecting_clicks_for_LPE, Inkscape::MessageStack::flash(), SPDesktop::getNamedView(), SPDesktop::getSelection(), Inkscape::UI::Tools::ToolBase::grabCanvasEvents(), Inkscape::UI::Tools::FreehandBase::green_anchor, Inkscape::UI::Tools::FreehandBase::green_closed, Inkscape::UI::Tools::FreehandBase::green_curve, hasWaitingLPE(), Inkscape::have_viable_layer(), SPDesktop::messageStack(), mode, MODE_CLICK, MODE_DRAG, Inkscape::CanvasEvent::modifiers, Inkscape::NORMAL_MESSAGE, npoints, p_array, Inkscape::UI::Tools::pen_drag_origin_w, Inkscape::UI::Tools::pen_within_tolerance, POINT, polylines_only, polylines_paraxial, Inkscape::ButtonEvent::pos, Inkscape::UI::Tools::FreehandBase::sa, Inkscape::UI::Tools::FreehandBase::sa_overwrited, Inkscape::UI::Tools::FreehandBase::selection, SnapManager::setup(), Inkscape::ObjectSet::singleItem(), SPNamedView::snap_manager, Inkscape::SNAPSOURCE_NODE_HANDLE, Inkscape::UI::Tools::spdc_create_single_dot(), Inkscape::UI::Tools::spdc_test_inside(), spiro, SPDrawAnchor::start, state, STOP, and SPDesktop::w2d().

Referenced by item_handler().

◆ _handleButtonRelease()

◆ _handleKeyPress()

◆ _handleMotionNotify()

◆ _lastpointMove()

◆ _lastpointMoveScreen()

void Inkscape::UI::Tools::PenTool::_lastpointMoveScreen ( gdouble  x,
gdouble  y 
)
private

◆ _lastpointToCurve()

◆ _lastpointToLine()

◆ _redoLastPoint()

◆ _redrawAll()

◆ _resetColors()

◆ _setAngleDistanceStatusMessage()

void Inkscape::UI::Tools::PenTool::_setAngleDistanceStatusMessage ( Geom::Point const  p,
int  pc_point_to_compare,
gchar const *  message 
)
private

Show the status message for the current line/curve segment.

This type of message always shows angle/distance as the last two parameters ("angle %3.2f&#176;, distance %s").

Definition at line 1144 of file pen-tool.cpp.

References Inkscape::UI::Tools::ToolBase::_desktop, SPNamedView::display_units, Inkscape::Preferences::get(), Inkscape::Preferences::getBool(), SPDesktop::getNamedView(), Inkscape::IMMEDIATE_MESSAGE, SPDesktop::is_yaxisdown(), Geom::L2(), Inkscape::UI::Tools::ToolBase::message_context, p_array, Inkscape::Util::Quantity::string(), Geom::X, and Geom::Y.

Referenced by _setCtrl(), and _setSubsequentPoint().

◆ _setCtrl()

◆ _setInitialPoint()

void Inkscape::UI::Tools::PenTool::_setInitialPoint ( Geom::Point const  p)
private

Definition at line 1129 of file pen-tool.cpp.

References npoints, p_array, and Inkscape::UI::Tools::FreehandBase::red_bpath.

Referenced by _handleButtonPress().

◆ _setSubsequentPoint()

◆ _setToNearestHorizVert()

◆ _undoLastPoint()

◆ hasWaitingLPE()

◆ item_handler()

bool Inkscape::UI::Tools::PenTool::item_handler ( SPItem item,
CanvasEvent const &  event 
)
overrideprotectedvirtual

Handles item specific events.

Gets called from Gdk.

Only reacts to right mouse button at the moment.

Todo:
Fixme: do context sensitive popup menu on items.

Reimplemented from Inkscape::UI::Tools::ToolBase.

Definition at line 217 of file pen-tool.cpp.

References _handleButtonPress(), _handleButtonRelease(), Inkscape::inspect_event(), item, and Inkscape::UI::Tools::ToolBase::item_handler().

Referenced by Inkscape::UI::Tools::LpeTool::item_handler().

◆ nextParaxialDirection()

void Inkscape::UI::Tools::PenTool::nextParaxialDirection ( Geom::Point const &  pt,
Geom::Point const &  origin,
guint  state 
)

◆ root_handler()

bool Inkscape::UI::Tools::PenTool::root_handler ( CanvasEvent const &  event)
overrideprotectedvirtual

◆ set()

void Inkscape::UI::Tools::PenTool::set ( Inkscape::Preferences::Entry const &  val)
overrideprotectedvirtual

Callback that sets key to value in pen context.

Reimplemented from Inkscape::UI::Tools::ToolBase.

Definition at line 152 of file pen-tool.cpp.

References Inkscape::Preferences::Entry::getEntryName(), Inkscape::Preferences::Entry::getString(), mode, MODE_CLICK, MODE_DRAG, and name.

◆ setPolylineMode()

◆ waitForLPEMouseClicks()

void Inkscape::UI::Tools::PenTool::waitForLPEMouseClicks ( Inkscape::LivePathEffect::EffectType  effect_type,
unsigned int  num_clicks,
bool  use_polylines = true 
)

Member Data Documentation

◆ _acc_to_curve

Util::ActionAccel Inkscape::UI::Tools::PenTool::_acc_to_curve
private

Definition at line 163 of file pen-tool.h.

Referenced by _handleKeyPress().

◆ _acc_to_guides

Util::ActionAccel Inkscape::UI::Tools::PenTool::_acc_to_guides
private

Definition at line 164 of file pen-tool.h.

Referenced by _handleKeyPress().

◆ _acc_to_line

Util::ActionAccel Inkscape::UI::Tools::PenTool::_acc_to_line
private

Definition at line 162 of file pen-tool.h.

Referenced by _handleKeyPress().

◆ _desktop_destroy

sigc::connection Inkscape::UI::Tools::PenTool::_desktop_destroy
private

Definition at line 156 of file pen-tool.h.

Referenced by PenTool(), and ~PenTool().

◆ _did_redo

bool Inkscape::UI::Tools::PenTool::_did_redo = false
private

Definition at line 160 of file pen-tool.h.

Referenced by _redoLastPoint(), and _undoLastPoint().

◆ _redo_stack

std::vector<Geom::PathVector> Inkscape::UI::Tools::PenTool::_redo_stack
private

History of undone events.

Definition at line 159 of file pen-tool.h.

Referenced by _cancel(), _finish(), _finishSegment(), _redoLastPoint(), and _undoLastPoint().

◆ bspline

◆ cl0

CanvasItemPtr<CanvasItemCurve> Inkscape::UI::Tools::PenTool::cl0

◆ cl1

CanvasItemPtr<CanvasItemCurve> Inkscape::UI::Tools::PenTool::cl1

◆ ctrl

CanvasItemPtr<CanvasItemCtrl> Inkscape::UI::Tools::PenTool::ctrl[4]

◆ ctrl_types

constexpr std::array<CanvasItemCtrlType, 4> Inkscape::UI::Tools::PenTool::ctrl_types
staticconstexpr

◆ events_disabled

bool Inkscape::UI::Tools::PenTool::events_disabled = false

◆ expecting_clicks_for_LPE

unsigned int Inkscape::UI::Tools::PenTool::expecting_clicks_for_LPE = 0

◆ mode

◆ npoints

◆ p_array

◆ paraxial_angle

Geom::Point Inkscape::UI::Tools::PenTool::paraxial_angle

Definition at line 68 of file pen-tool.h.

Referenced by _setToNearestHorizVert(), _undoLastPoint(), and nextParaxialDirection().

◆ polylines_only

bool Inkscape::UI::Tools::PenTool::polylines_only = false

◆ polylines_paraxial

bool Inkscape::UI::Tools::PenTool::polylines_paraxial = false

◆ previous

Geom::Point Inkscape::UI::Tools::PenTool::previous

◆ spiro

◆ state

◆ waiting_item

SPLPEItem* Inkscape::UI::Tools::PenTool::waiting_item = nullptr

Definition at line 75 of file pen-tool.h.

Referenced by _handleButtonRelease(), and ~PenTool().

◆ waiting_LPE

Inkscape::LivePathEffect::Effect* Inkscape::UI::Tools::PenTool::waiting_LPE = nullptr

Definition at line 74 of file pen-tool.h.

Referenced by _handleButtonRelease(), and hasWaitingLPE().


The documentation for this class was generated from the following files: