Code

Make curvature work again by fixing a minor omission
[inkscape.git] / src / shape-editor.h
1 #ifndef __SHAPE_EDITOR_H__
2 #define __SHAPE_EDITOR_H__
4 /*
5  * Inkscape::ShapeEditor
6  *
7  * This is a container class which contains either knotholder (for shapes) or nodepath (for
8  * paths). It is attached to a single item so only one of these is active at a time.
9  *
10  * Authors:
11  *   bulia byak <buliabyak@users.sf.net>
12  *
13  */
15 #include <forward.h>
16 #include <2geom/forward.h>
18 namespace Inkscape { namespace NodePath { class Path; } }
19 namespace Inkscape { namespace XML { class Node; } }
21 class KnotHolder;
22 class SPDesktop;
23 class SPNodeContext;
24 class ShapeEditorsCollective;
25 class LivePathEffectObject;
27 #include "libnr/nr-path-code.h"
28 #include <2geom/point.h>
29 #include <boost/optional.hpp>
30 #include <vector>
32 enum SubType{
33     SH_NODEPATH,
34     SH_KNOTHOLDER
35 };
37 class ShapeEditor {
38 public:
40     ShapeEditor(SPDesktop *desktop);
41     ~ShapeEditor();
43     void set_item (SPItem *item, SubType type, bool keep_knotholder = false);
44     void set_item_lpe_path_parameter(SPItem *item, LivePathEffectObject *lpeobject, const char * key);
45     void unset_item (SubType type, bool keep_knotholder = false);
47     bool has_nodepath (); //((deprecated))
48     void update_knotholder (); //((deprecated))
50     bool has_local_change (SubType type);
51     void decrement_local_change (SubType type);
53     GList *save_nodepath_selection ();
54     void restore_nodepath_selection (GList *saved);
56     void nodepath_destroyed ();
58     void update_statusbar ();
60     bool is_over_stroke (Geom::Point event_p, bool remember);
62     void add_node_near_point(); // uses the shapeeditor's remembered point, if any
64     void select_segment_near_point(bool toggle); // uses the shapeeditor's remembered point, if any
66     void cancel_hit ();
68     bool hits_curve ();
70     void curve_drag (gdouble eventx, gdouble eventy);
72     void finish_drag ();
74     void select_rect (Geom::Rect  const &rect, bool add);
76     bool has_selection ();
77     void deselect ();
79     Inkscape::NodePath::Path *get_nodepath() {return nodepath;} //((deprecated))
80     ShapeEditorsCollective *get_container() {return container;}
82     void add_node();
84     void delete_nodes();
85     void delete_nodes_preserving_shape();
86     void delete_segment();
88     void set_node_type(int type);
90     void break_at_nodes();
91     void join_nodes();
92     void join_segments();
94     void duplicate_nodes();
96     void set_type_of_segments(NRPathcode code);
98     void move_nodes(gdouble dx, gdouble dy);
99     void move_nodes_screen(SPDesktop *desktop, gdouble dx, gdouble dy);
101     void rotate_nodes(gdouble angle, int which, bool screen);
103     void scale_nodes(gdouble const grow, int const which);
104     void scale_nodes_screen(gdouble const grow, int const which);
106     void select_all (bool invert);
107     void select_all_from_subpath (bool invert);
108     void select_next ();
109     void select_prev ();
111     void show_handles (bool show);
112     void show_helperpath (bool show);
114     void flip (Geom::Dim2 axis, boost::optional<Geom::Point> center = boost::optional<Geom::Point>());
116     void distribute (Geom::Dim2 axis);
117     void align (Geom::Dim2 axis);
119     bool nodepath_edits_repr_key(gchar const *name);
121     // this one is only public because it's called from non-C++ repr changed callback
122     void shapeeditor_event_attr_changed(gchar const *name);
124 private:
125     bool has_knotholder ();
126     void reset_item (SubType type, bool keep_knotholder = true);
127     const SPItem *get_item (SubType type);
129     SPDesktop *desktop;
131     Inkscape::NodePath::Path *nodepath;
133     // TODO: std::list<KnotHolder *> knotholders;
134     KnotHolder *knotholder;
136     ShapeEditorsCollective *container;
138     //Inkscape::XML::Node *lidtened_repr;
140     double grab_t;
141     int grab_node; // number of node grabbed by sp_node_context_is_over_stroke
142     bool hit;
143     Geom::Point curvepoint_event; // int coords from event
144     Geom::Point curvepoint_doc; // same, in doc coords
146     Inkscape::XML::Node *knotholder_listener_attached_for;
147     Inkscape::XML::Node *nodepath_listener_attached_for;
148 };
151 /* As the next stage, this will be a collection of multiple ShapeEditors,
152 with the same interface as the single ShapeEditor, passing the actions to all its
153 contained ShapeEditors. Thus it should be easy to switch node context from 
154 using a single ShapeEditor to using a ShapeEditorsCollective. */
156 class ShapeEditorsCollective {
157 public:
159     ShapeEditorsCollective(SPDesktop *desktop);
160     ~ShapeEditorsCollective();
162     void update_statusbar();
164 private:
165     std::vector<ShapeEditor> editors;
167     SPNodeContext *nc; // who holds us
168 };
170 #endif
173 /*
174   Local Variables:
175   mode:c++
176   c-file-style:"stroustrup"
177   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
178   indent-tabs-mode:nil
179   fill-column:99
180   End:
181 */
182 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :