1 // SPDX-License-Identifier: GPL-2.0-or-later
2 #ifndef SEEN_KNOT_HOLDER_ENTITY_H
3 #define SEEN_KNOT_HOLDER_ENTITY_H
4 /*
5  * Authors:
6  *   Mitsuru Oka <oka326@parkcity.ne.jp>
7  *   Maximilian Albert <maximilian.albert@gmail.com>
8  *
9  * Copyright (C) 1999-2001 Lauris Kaplinski
10  * Copyright (C) 2000-2001 Ximian, Inc.
11  * Copyright (C) 2001 Mitsuru Oka
12  * Copyright (C) 2004 Monash University
13  * Copyright (C) 2008 Maximilian Albert
14  *
15  * Released under GNU GPL v2+, read the file 'COPYING' for more information.
16  */
17 
18 #include <2geom/forward.h>
19 
20 #include "knot.h"
21 #include "snapper.h"
22 
23 #include "display/control/canvas-item-enums.h"
24 
25 class SPHatch;
26 class SPItem;
27 class SPKnot;
28 class SPDesktop;
29 class SPPattern;
30 class KnotHolder;
31 
32 namespace Inkscape {
33 namespace LivePathEffect {
34     class Effect;
35 } // namespace LivePathEffect
36 } // namespace Inkscape
37 
38 typedef void (* SPKnotHolderSetFunc) (SPItem *item, Geom::Point const &p, Geom::Point const &origin, unsigned int state);
39 typedef Geom::Point (* SPKnotHolderGetFunc) (SPItem *item);
40 
41 /**
42  * KnotHolderEntity definition.
43  */
44 class KnotHolderEntity {
45 public:
KnotHolderEntity()46     KnotHolderEntity() {}
47     virtual ~KnotHolderEntity();
48 
49     void create(SPDesktop *desktop, SPItem *item, KnotHolder *parent,
50                 Inkscape::CanvasItemCtrlType type = Inkscape::CANVAS_ITEM_CTRL_TYPE_DEFAULT,
51                 Glib::ustring const & name = Glib::ustring("unknown"),
52                 char const *tip = "",
53                 guint32 color = 0xffffff00);
54 
55     /* the get/set/click handlers are virtual functions; each handler class for a knot
56        should be derived from KnotHolderEntity and override these functions */
57     virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, unsigned int state) = 0;
58     virtual void knot_ungrabbed(Geom::Point const &p, Geom::Point const &origin, unsigned int state) = 0;
knot_missing()59     virtual bool knot_missing() const { return false; }
60     virtual Geom::Point knot_get() const = 0;
knot_click(unsigned int)61     virtual void knot_click(unsigned int /*state*/) {}
62 
63     void update_knot();
64 
65 //private:
66     Geom::Point snap_knot_position(Geom::Point const &p, unsigned int state);
67     Geom::Point snap_knot_position_constrained(Geom::Point const &p, Inkscape::Snapper::SnapConstraint const &constraint, unsigned int state);
68 
69     SPKnot *knot = nullptr;
70     SPItem *item = nullptr;
71     SPDesktop *desktop = nullptr;
72     KnotHolder *parent_holder = nullptr;
73 
74     int my_counter = 0;
75     inline static int counter = 0;
76 
77     /** Connection to \a knot's "moved" signal. */
78     unsigned int   handler_id = 0;
79     /** Connection to \a knot's "clicked" signal. */
80     unsigned int   _click_handler_id = 0;
81     /** Connection to \a knot's "ungrabbed" signal. */
82     unsigned int   _ungrab_handler_id = 0;
83 
84 private:
85     sigc::connection _mousedown_connection;
86     sigc::connection _moved_connection;
87     sigc::connection _click_connection;
88     sigc::connection _ungrabbed_connection;
89 };
90 
91 // derived KnotHolderEntity class for LPEs
92 class LPEKnotHolderEntity : public KnotHolderEntity {
93 public:
LPEKnotHolderEntity(Inkscape::LivePathEffect::Effect * effect)94     LPEKnotHolderEntity(Inkscape::LivePathEffect::Effect *effect) : _effect(effect) {};
95     void knot_ungrabbed(Geom::Point const &p, Geom::Point const &origin, guint state) override;
96 protected:
97     Inkscape::LivePathEffect::Effect *_effect;
98 };
99 
100 /* pattern manipulation */
101 
102 class PatternKnotHolderEntity : public KnotHolderEntity {
103   public:
PatternKnotHolderEntity(bool fill)104     PatternKnotHolderEntity(bool fill) : KnotHolderEntity(), _fill(fill) {}
105     bool knot_missing() const override;
knot_ungrabbed(Geom::Point const & p,Geom::Point const & origin,guint state)106     void knot_ungrabbed(Geom::Point const &p, Geom::Point const &origin, guint state) override{};
107 
108   protected:
109     // true if the entity tracks fill, false for stroke
110     bool _fill;
111     SPPattern *_pattern() const;
112 };
113 
114 class PatternKnotHolderEntityXY : public PatternKnotHolderEntity {
115 public:
PatternKnotHolderEntityXY(bool fill)116     PatternKnotHolderEntityXY(bool fill) : PatternKnotHolderEntity(fill) {}
117     Geom::Point knot_get() const override;
118     void knot_set(Geom::Point const &p, Geom::Point const &origin, unsigned int state) override;
119 };
120 
121 class PatternKnotHolderEntityAngle : public PatternKnotHolderEntity {
122 public:
PatternKnotHolderEntityAngle(bool fill)123     PatternKnotHolderEntityAngle(bool fill) : PatternKnotHolderEntity(fill) {}
124     Geom::Point knot_get() const override;
125     void knot_set(Geom::Point const &p, Geom::Point const &origin, unsigned int state) override;
126 };
127 
128 class PatternKnotHolderEntityScale : public PatternKnotHolderEntity {
129 public:
PatternKnotHolderEntityScale(bool fill)130     PatternKnotHolderEntityScale(bool fill) : PatternKnotHolderEntity(fill) {}
131     Geom::Point knot_get() const override;
132     void knot_set(Geom::Point const &p, Geom::Point const &origin, unsigned int state) override;
133 };
134 
135 /* Hatch manipulation */
136 class HatchKnotHolderEntity : public KnotHolderEntity {
137   public:
HatchKnotHolderEntity(bool fill)138     HatchKnotHolderEntity(bool fill)
139         : KnotHolderEntity()
140         , _fill(fill)
141     {
142     }
143     bool knot_missing() const override;
knot_ungrabbed(Geom::Point const & p,Geom::Point const & origin,guint state)144     void knot_ungrabbed(Geom::Point const &p, Geom::Point const &origin, guint state) override{};
145 
146   protected:
147     // true if the entity tracks fill, false for stroke
148     bool _fill;
149     SPHatch *_hatch() const;
150 };
151 
152 class HatchKnotHolderEntityXY : public HatchKnotHolderEntity {
153   public:
HatchKnotHolderEntityXY(bool fill)154     HatchKnotHolderEntityXY(bool fill)
155         : HatchKnotHolderEntity(fill)
156     {
157     }
158     Geom::Point knot_get() const override;
159     void knot_set(Geom::Point const &p, Geom::Point const &origin, unsigned int state) override;
160 };
161 
162 class HatchKnotHolderEntityAngle : public HatchKnotHolderEntity {
163   public:
HatchKnotHolderEntityAngle(bool fill)164     HatchKnotHolderEntityAngle(bool fill)
165         : HatchKnotHolderEntity(fill)
166     {
167     }
168     Geom::Point knot_get() const override;
169     void knot_set(Geom::Point const &p, Geom::Point const &origin, unsigned int state) override;
170 };
171 
172 class HatchKnotHolderEntityScale : public HatchKnotHolderEntity {
173   public:
HatchKnotHolderEntityScale(bool fill)174     HatchKnotHolderEntityScale(bool fill)
175         : HatchKnotHolderEntity(fill)
176     {
177     }
178     Geom::Point knot_get() const override;
179     void knot_set(Geom::Point const &p, Geom::Point const &origin, unsigned int state) override;
180 };
181 
182 
183 /* Filter manipulation */
184 class FilterKnotHolderEntity : public KnotHolderEntity {
185   public:
FilterKnotHolderEntity(bool topleft)186     FilterKnotHolderEntity(bool topleft) : KnotHolderEntity(), _topleft(topleft) {}
187     Geom::Point knot_get() const override;
knot_ungrabbed(Geom::Point const & p,Geom::Point const & origin,guint state)188     void knot_ungrabbed(Geom::Point const &p, Geom::Point const &origin, guint state) override {};
189     void knot_set(Geom::Point const &p, Geom::Point const &origin, unsigned int state) override;
190 private:
191     bool _topleft; // true for topleft point, false for bottomright
192 };
193 
194 #endif /* !SEEN_KNOT_HOLDER_ENTITY_H */
195 
196 /*
197   Local Variables:
198   mode:c++
199   c-file-style:"stroustrup"
200   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
201   indent-tabs-mode:nil
202   fill-column:99
203   End:
204 */
205 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
206