summaryrefslogtreecommitdiffstats
path: root/src/shape-editor.h
blob: f30f1aa12f7d0bf045c63dc2a7eb4aae5ea8d994 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#ifndef __SHAPE_EDITOR_H__
#define __SHAPE_EDITOR_H__

/*
 * Inkscape::ShapeEditor
 *
 * This is a container class which contains either knotholder (for shapes) or nodepath (for
 * paths). It is attached to a single item so only one of these is active at a time.
 *
 * Authors:
 *   bulia byak <buliabyak@users.sf.net>
 *
 */

#include <forward.h>
#include <libnr/nr-forward.h>

namespace Inkscape { namespace NodePath { class Path; } }
namespace Inkscape { namespace XML { class Node; } }

#include "libnr/nr-path-code.h"
#include "libnr/nr-point.h"
#include <boost/optional.hpp>
#include <vector>

class KnotHolder;
class SPDesktop;
class SPNodeContext;
class ShapeEditorsCollective;

enum SubType{
    SH_NODEPATH,
    SH_KNOTHOLDER
};

class ShapeEditor {
public:

    ShapeEditor(SPDesktop *desktop);
    ~ShapeEditor();

    void set_item (SPItem *item, SubType type, bool keep_knotholder = false);
    void set_item_lpe_path_parameter(SPItem *item, SPObject *lpeobject, const char * key);
    void unset_item (SubType type, bool keep_knotholder = false);

    bool has_nodepath (); //((deprecated))
    void update_knotholder (); //((deprecated))

    bool has_local_change (SubType type);
    void decrement_local_change (SubType type);

    GList *save_nodepath_selection ();
    void restore_nodepath_selection (GList *saved);

    void nodepath_destroyed ();

    void update_statusbar ();

    bool is_over_stroke (Geom::Point event_p, bool remember);

    void add_node_near_point(); // uses the shapeeditor's remembered point, if any

    void select_segment_near_point(bool toggle); // uses the shapeeditor's remembered point, if any

    void cancel_hit ();

    bool hits_curve ();

    void curve_drag (gdouble eventx, gdouble eventy);

    void finish_drag ();

    void select_rect (Geom::Rect  const &rect, bool add);

    bool has_selection ();
    void deselect ();

    Inkscape::NodePath::Path *get_nodepath() {return nodepath;} //((deprecated))
    ShapeEditorsCollective *get_container() {return container;}

    void add_node();

    void delete_nodes();
    void delete_nodes_preserving_shape();
    void delete_segment();

    void set_node_type(int type);

    void break_at_nodes();
    void join_nodes();
    void join_segments();

    void duplicate_nodes();

    void set_type_of_segments(NRPathcode code);

    void move_nodes(gdouble dx, gdouble dy);
    void move_nodes_screen(SPDesktop *desktop, gdouble dx, gdouble dy);

    void rotate_nodes(gdouble angle, int which, bool screen);

    void scale_nodes(gdouble const grow, int const which);
    void scale_nodes_screen(gdouble const grow, int const which);

    void select_all (bool invert);
    void select_all_from_subpath (bool invert);
    void select_next ();
    void select_prev ();

    void show_handles (bool show);
    void show_helperpath (bool show);

    void flip (Geom::Dim2 axis, boost::optional<Geom::Point> center = boost::optional<Geom::Point>());

    void distribute (Geom::Dim2 axis);
    void align (Geom::Dim2 axis);

    bool nodepath_edits_repr_key(gchar const *name);

    // this one is only public because it's called from non-C++ repr changed callback
    void shapeeditor_event_attr_changed(gchar const *name);

private:
    bool has_knotholder ();
    void reset_item (SubType type, bool keep_knotholder = true);
    const SPItem *get_item (SubType type);

    SPDesktop *desktop;

    Inkscape::NodePath::Path *nodepath;

    // TODO: std::list<KnotHolder *> knotholders;
    KnotHolder *knotholder;

    ShapeEditorsCollective *container;

    //Inkscape::XML::Node *lidtened_repr;

    double grab_t;
    int grab_node; // number of node grabbed by sp_node_context_is_over_stroke
    bool hit;
    Geom::Point curvepoint_event; // int coords from event
    Geom::Point curvepoint_doc; // same, in doc coords

    Inkscape::XML::Node *listener_attached_for;
};


/* As the next stage, this will be a collection of multiple ShapeEditors,
with the same interface as the single ShapeEditor, passing the actions to all its
contained ShapeEditors. Thus it should be easy to switch node context from 
using a single ShapeEditor to using a ShapeEditorsCollective. */

class ShapeEditorsCollective {
public:

    ShapeEditorsCollective(SPDesktop *desktop);
    ~ShapeEditorsCollective();

    void update_statusbar();

private:
    std::vector<ShapeEditor> editors;

    SPNodeContext *nc; // who holds us
};

#endif


/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :