1 // SPDX-License-Identifier: GPL-2.0-or-later
2 #ifndef SEEN_SP_DRAW_CONTEXT_H
3 #define SEEN_SP_DRAW_CONTEXT_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 <sigc++/connection.h>
19 
20 #include "ui/tools/tool-base.h"
21 #include "live_effects/effect-enum.h"
22 
23 #include <memory>
24 
25 class SPCurve;
26 class SPCanvasItem;
27 
28 struct SPDrawAnchor;
29 
30 namespace Inkscape {
31     class CanvasItemBpath;
32     class Selection;
33 }
34 
35 namespace boost {
36     template<class T>
37     class optional;
38 }
39 
40 /* Freehand context */
41 
42 #define SP_DRAW_CONTEXT(obj) (dynamic_cast<Inkscape::UI::Tools::FreehandBase*>((Inkscape::UI::Tools::ToolBase*)obj))
43 #define SP_IS_DRAW_CONTEXT(obj) (dynamic_cast<const Inkscape::UI::Tools::FreehandBase*>((const Inkscape::UI::Tools::ToolBase*)obj) != NULL)
44 
45 
46 namespace Inkscape {
47 namespace UI {
48 namespace Tools {
49 
50 enum shapeType { NONE, TRIANGLE_IN, TRIANGLE_OUT, ELLIPSE, CLIPBOARD, BEND_CLIPBOARD, LAST_APPLIED };
51 
52 class FreehandBase : public ToolBase {
53 public:
54     FreehandBase(const std::string& cursor_filename);
55     ~FreehandBase() override;
56 
57     Inkscape::Selection *selection;
58 
59     bool attach;
60 
61     guint32 red_color;
62     guint32 blue_color;
63     guint32 green_color;
64     guint32 highlight_color;
65 
66     // Red - Last segement as it's drawn.
67     Inkscape::CanvasItemBpath *red_bpath;
68     std::unique_ptr<SPCurve> red_curve;
69     std::optional<Geom::Point> red_curve_get_last_point();
70 
71     // Blue - New path after LPE as it's drawn.
72     Inkscape::CanvasItemBpath *blue_bpath;
73     std::unique_ptr<SPCurve> blue_curve;
74 
75     // Green - New path as it's drawn.
76     std::vector<Inkscape::CanvasItemBpath *> green_bpaths;
77     std::unique_ptr<SPCurve> green_curve;
78     SPDrawAnchor *green_anchor;
79     gboolean green_closed; // a flag meaning we hit the green anchor, so close the path on itself
80 
81     // White
82     SPItem *white_item;
83     std::list<std::unique_ptr<SPCurve>> white_curves;
84     std::vector<SPDrawAnchor*> white_anchors;
85 
86     // Temporary modified curve when start anchor
87     std::unique_ptr<SPCurve> sa_overwrited;
88 
89     // Start anchor
90     SPDrawAnchor *sa;
91 
92     // End anchor
93     SPDrawAnchor *ea;
94 
95 
96     /* Type of the LPE that is to be applied automatically to a finished path (if any) */
97     Inkscape::LivePathEffect::EffectType waiting_LPE_type;
98 
99     sigc::connection sel_changed_connection;
100     sigc::connection sel_modified_connection;
101 
102     bool red_curve_is_valid;
103 
104     bool anchor_statusbar;
105 
106     bool tablet_enabled;
107 
108     bool is_tablet;
109 
110     gdouble pressure;
111     void set(const Inkscape::Preferences::Entry& val) override;
112 
113 protected:
114 
115     void setup() override;
116     void finish() override;
117     bool root_handler(GdkEvent* event) override;
118 };
119 
120 /**
121  * Returns FIRST active anchor (the activated one).
122  */
123 SPDrawAnchor *spdc_test_inside(FreehandBase *dc, Geom::Point p);
124 
125 /**
126  * Concats red, blue and green.
127  * If any anchors are defined, process these, optionally removing curves from white list
128  * Invoke _flush_white to write result back to object.
129  */
130 void spdc_concat_colors_and_flush(FreehandBase *dc, gboolean forceclosed);
131 
132 /**
133  *  Snaps node or handle to PI/rotationsnapsperpi degree increments.
134  *
135  *  @param dc draw context.
136  *  @param p cursor point (to be changed by snapping).
137  *  @param o origin point.
138  *  @param state  keyboard state to check if ctrl or shift was pressed.
139  */
140 void spdc_endpoint_snap_rotation(ToolBase* const ec, Geom::Point &p, Geom::Point const &o, guint state);
141 
142 void spdc_endpoint_snap_free(ToolBase* const ec, Geom::Point &p, std::optional<Geom::Point> &start_of_line, guint state);
143 
144 /**
145  * If we have an item and a waiting LPE, apply the effect to the item
146  * (spiro spline mode is treated separately).
147  */
148 void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item);
149 
150 /**
151  * Create a single dot represented by a circle.
152  */
153 void spdc_create_single_dot(ToolBase *ec, Geom::Point const &pt, char const *tool, guint event_state);
154 
155 }
156 }
157 }
158 
159 #endif // SEEN_SP_DRAW_CONTEXT_H
160 
161 /*
162   Local Variables:
163   mode:c++
164   c-file-style:"stroustrup"
165   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
166   indent-tabs-mode:nil
167   fill-column:99
168   End:
169 */
170 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
171