Code

Implementation of snap delay mechanism for guides
[inkscape.git] / src / ui / tool / control-point-selection.h
1 /** @file
2  * Node selection - stores a set of nodes and applies transformations
3  * to them
4  */
5 /* Authors:
6  *   Krzysztof KosiƄski <tweenk.pl@gmail.com>
7  *
8  * Copyright (C) 2009 Authors
9  * Released under GNU GPL, read the file 'COPYING' for more information
10  */
12 #ifndef SEEN_UI_TOOL_NODE_SELECTION_H
13 #define SEEN_UI_TOOL_NODE_SELECTION_H
15 #include <memory>
16 #include <tr1/unordered_map>
17 #include <tr1/unordered_set>
18 #include <boost/optional.hpp>
19 #include <sigc++/sigc++.h>
20 #include <2geom/forward.h>
21 #include <2geom/point.h>
22 #include <2geom/rect.h>
23 #include "display/display-forward.h"
24 #include "util/accumulators.h"
25 #include "util/hash.h"
26 #include "ui/tool/commit-events.h"
27 #include "ui/tool/manipulator.h"
29 class SPDesktop;
31 namespace Inkscape {
32 namespace UI {
33 class TransformHandleSet;
34 class SelectableControlPoint;
35 }
36 }
38 namespace Inkscape {
39 namespace UI {
41 class ControlPointSelection : public Manipulator {
42 public:
43     ControlPointSelection(SPDesktop *d, SPCanvasGroup *th_group);
44     ~ControlPointSelection();
45     typedef std::tr1::unordered_set< SelectableControlPoint * > set_type;
46     typedef set_type Set; // convenience alias
48     typedef set_type::iterator iterator;
49     typedef set_type::const_iterator const_iterator;
50     typedef set_type::size_type size_type;
51     typedef SelectableControlPoint *value_type;
52     typedef SelectableControlPoint *key_type;
54     // size
55     bool empty() { return _points.empty(); }
56     size_type size() { return _points.size(); }
58     // iterators
59     iterator begin() { return _points.begin(); }
60     const_iterator begin() const { return _points.begin(); }
61     iterator end() { return _points.end(); }
62     const_iterator end() const { return _points.end(); }
64     // insert
65     std::pair<iterator, bool> insert(const value_type& x);
66     template <class InputIterator>
67     void insert(InputIterator first, InputIterator last) {
68         for (; first != last; ++first) {
69             insert(*first);
70         }
71     }
73     // erase
74     void clear();
75     void erase(iterator pos);
76     size_type erase(const key_type& k);
77     void erase(iterator first, iterator last);
79     // find
80     iterator find(const key_type &k) { return _points.find(k); }
82     // Sometimes it is very useful to keep a list of all selectable points.
83     set_type const &allPoints() const { return _all_points; }
84     set_type &allPoints() { return _all_points; }
85     // ...for example in these methods. Another useful case is snapping.
86     void selectAll();
87     void selectArea(Geom::Rect const &);
88     void invertSelection();
89     void spatialGrow(SelectableControlPoint *origin, int dir);
91     virtual bool event(GdkEvent *);
93     void transform(Geom::Matrix const &m);
94     void align(Geom::Dim2 d);
95     void distribute(Geom::Dim2 d);
97     Geom::OptRect pointwiseBounds();
98     Geom::OptRect bounds();
100     bool transformHandlesEnabled() { return _handles_visible; }
101     void showTransformHandles(bool v, bool one_node);
102     // the two methods below do not modify the state; they are for use in manipulators
103     // that need to temporarily hide the handles, for example when moving a node
104     void hideTransformHandles();
105     void restoreTransformHandles();
106     void toggleTransformHandlesMode();
108     sigc::signal<void> signal_update;
109     sigc::signal<void, SelectableControlPoint *, bool> signal_point_changed;
110     sigc::signal<void, CommitEvent> signal_commit;
111 private:
112     // The functions below are invoked from SelectableControlPoint.
113     // Previously they were connected to handlers when selecting, but this
114     // creates problems when dragging a point that was not selected.
115     void _pointGrabbed();
116     void _pointDragged(Geom::Point const &, Geom::Point &, GdkEventMotion *);
117     void _pointUngrabbed();
118     bool _pointClicked(SelectableControlPoint *, GdkEventButton *);
119     void _pointChanged(SelectableControlPoint *, bool);
120     void _mouseoverChanged();
122     void _updateTransformHandles(bool preserve_center);
123     void _updateBounds();
124     bool _keyboardMove(GdkEventKey const &, Geom::Point const &);
125     bool _keyboardRotate(GdkEventKey const &, int);
126     bool _keyboardScale(GdkEventKey const &, int);
127     bool _keyboardFlip(Geom::Dim2);
128     void _keyboardTransform(Geom::Matrix const &);
129     void _commitHandlesTransform(CommitEvent ce);
130     double _rotationRadius(Geom::Point const &);
132     set_type _points;
133     set_type _all_points;
134     boost::optional<double> _rot_radius;
135     boost::optional<double> _mouseover_rot_radius;
136     Geom::OptRect _bounds;
137     TransformHandleSet *_handles;
138     SelectableControlPoint *_grabbed_point;
139     unsigned _dragging         : 1;
140     unsigned _handles_visible  : 1;
141     unsigned _one_node_handles : 1;
143     friend class SelectableControlPoint;
144 };
146 } // namespace UI
147 } // namespace Inkscape
149 #endif
151 /*
152   Local Variables:
153   mode:c++
154   c-file-style:"stroustrup"
155   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
156   indent-tabs-mode:nil
157   fill-column:99
158   End:
159 */
160 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :