Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
freehand-base.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifndef INKSCAPE_UI_TOOLS_FREEHAND_BASE_H
3#define INKSCAPE_UI_TOOLS_FREEHAND_BASE_H
4
5/*
6 * Generic drawing context
7 *
8 * Author:
9 * Lauris Kaplinski <lauris@kaplinski.com>
10 *
11 * Copyright (C) 2000 Lauris Kaplinski
12 * Copyright (C) 2000-2001 Ximian, Inc.
13 * Copyright (C) 2002 Lauris Kaplinski
14 *
15 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
16 */
17
18#include <2geom/pathvector.h>
19
20#include "ui/tools/tool-base.h"
23
24struct SPDrawAnchor;
25
26namespace Inkscape {
27class CanvasItemBpath;
28class Selection;
29} // namespace Inkscape
30
31namespace Inkscape::UI::Tools {
32
43
44class FreehandBase : public ToolBase
45{
46public:
47 FreehandBase(SPDesktop *desktop, std::string &&prefs_path, std::string &&cursor_filename);
48 ~FreehandBase() override;
49
50 Selection *selection = nullptr;
51
52protected:
53 uint32_t red_color = 0xff00007f;
54 uint32_t blue_color = 0x0000ff7f;
55 uint32_t green_color = 0x00ff007f;
56 uint32_t highlight_color = 0x0000007f;
57
58public:
59 // Red - Last segment as it's drawn.
62 std::optional<Geom::Point> red_curve_get_last_point() const;
63
64 // Blue - New path after LPE as it's drawn.
67
68 // Green - New path as it's drawn.
69 std::vector<CanvasItemPtr<CanvasItemBpath>> green_bpaths;
70 std::shared_ptr<Geom::PathVector> green_curve;
71 std::unique_ptr<SPDrawAnchor> green_anchor;
72 bool green_closed = false; // a flag meaning we hit the green anchor, so close the path on itself
73
74 // White
75 SPItem *white_item = nullptr;
76 std::vector<std::shared_ptr<Geom::PathVector>> white_curves;
77 std::vector<std::unique_ptr<SPDrawAnchor>> white_anchors;
78
79 // Temporary modified curve when start anchor
80 std::shared_ptr<Geom::PathVector> sa_overwrited;
81
82 // Start anchor
83 SPDrawAnchor *sa = nullptr;
84
85 // End anchor
86 SPDrawAnchor *ea = nullptr;
87
88 // Type of the LPE that is to be applied automatically to a finished path (if any)
90
91 sigc::connection sel_changed_connection;
92 sigc::connection sel_modified_connection;
93
94 bool red_curve_is_valid = false;
95
96 bool anchor_statusbar = false;
97
98 bool tablet_enabled = false;
99 bool is_tablet = false;
100
101 double pressure = 1.0;
102
103 void onSelectionModified();
104
105protected:
106 bool root_handler(CanvasEvent const &event) override;
107 void _attachSelection();
108};
109
114
120void spdc_concat_colors_and_flush(FreehandBase *dc, bool forceclosed);
121
130void spdc_endpoint_snap_rotation(ToolBase *tool, Geom::Point &p, Geom::Point const &o, unsigned state);
131
132void spdc_endpoint_snap_free(ToolBase *tool, Geom::Point &p, std::optional<Geom::Point> &start_of_line);
133
139
143void spdc_create_single_dot(ToolBase *tool, Geom::Point const &pt, char const *path, unsigned event_state);
144
145} // namespace Inkscape::UI::Tools
146
147#endif // INKSCAPE_UI_TOOLS_FREEHAND_BASE_H
148
149/*
150 Local Variables:
151 mode:c++
152 c-file-style:"stroustrup"
153 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
154 indent-tabs-mode:nil
155 fill-column:99
156 End:
157*/
158// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
std::unique_ptr< T, CanvasItemUnlinkDeleter > CanvasItemPtr
Smart pointer used to hold CanvasItems, like std::unique_ptr.
Sequence of subpaths.
Definition pathvector.h:122
Two-dimensional point that doubles as a vector.
Definition point.h:66
The set of selected SPObjects for a given document and layer model.
Definition selection.h:80
LivePathEffect::EffectType waiting_LPE_type
std::shared_ptr< Geom::PathVector > green_curve
sigc::connection sel_changed_connection
CanvasItemPtr< CanvasItemBpath > red_bpath
bool root_handler(CanvasEvent const &event) override
std::shared_ptr< Geom::PathVector > sa_overwrited
std::unique_ptr< SPDrawAnchor > green_anchor
std::vector< std::unique_ptr< SPDrawAnchor > > white_anchors
std::optional< Geom::Point > red_curve_get_last_point() const
std::vector< std::shared_ptr< Geom::PathVector > > white_curves
CanvasItemPtr< CanvasItemBpath > blue_bpath
std::vector< CanvasItemPtr< CanvasItemBpath > > green_bpaths
sigc::connection sel_modified_connection
Base class for Event processors.
Definition tool-base.h:95
To do: update description of desktop.
Definition desktop.h:149
The drawing anchor.
Definition draw-anchor.h:40
Base class for visual SVG elements.
Definition sp-item.h:109
static Glib::ustring const prefs_path
SPItem * item
static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, Geom::PathVector const *curve, bool is_bend)
void spdc_endpoint_snap_free(ToolBase *tool, Geom::Point &p, std::optional< Geom::Point > &start_of_line)
void spdc_endpoint_snap_rotation(ToolBase *tool, Geom::Point &p, Geom::Point const &o, unsigned state)
Snaps node or handle to PI/rotationsnapsperpi degree increments.
SPDrawAnchor * spdc_test_inside(FreehandBase *dc, Geom::Point const &p)
Returns FIRST active anchor (the activated one).
void spdc_concat_colors_and_flush(FreehandBase *dc, bool forceclosed)
Concats red, blue and green.
void spdc_create_single_dot(ToolBase *tool, Geom::Point const &pt, char const *path, unsigned event_state)
Create a single dot represented by a circle.
Helper class to stream background task notifications as a series of messages.
PathVector - a sequence of subpaths.
Abstract base class for events.
SPDesktop * desktop