Code

Better node transform handles behavior
[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/shared_ptr.hpp>
19 #include <boost/weak_ptr.hpp>
20 #include <boost/optional.hpp>
21 #include <sigc++/sigc++.h>
22 #include <2geom/forward.h>
23 #include <2geom/point.h>
24 #include "display/display-forward.h"
25 #include "util/accumulators.h"
26 #include "util/hash.h"
27 #include "ui/tool/commit-events.h"
28 #include "ui/tool/manipulator.h"
30 namespace std { using namespace tr1; }
32 class SPDesktop;
34 namespace Inkscape {
35 namespace UI {
37 class TransformHandleSet;
38 class SelectableControlPoint;
40 class ControlPointSelection : public Manipulator {
41 public:
42     ControlPointSelection(SPDesktop *d, SPCanvasGroup *th_group);
43     ~ControlPointSelection();
44     typedef std::list<sigc::connection> connlist_type;
45     typedef std::unordered_map< SelectableControlPoint *,
46         boost::shared_ptr<connlist_type> > map_type;
47     typedef std::unordered_set< SelectableControlPoint * > set_type;
48     typedef set_type Set; // convenience alias
50     typedef map_type::iterator iterator;
51     typedef map_type::const_iterator const_iterator;
52     typedef map_type::size_type size_type;
53     typedef SelectableControlPoint *value_type;
54     typedef SelectableControlPoint *key_type;
56     // size
57     bool empty() { return _points.empty(); }
58     size_type size() { return _points.size(); }
60     // iterators
61     iterator begin() { return _points.begin(); }
62     const_iterator begin() const { return _points.begin(); }
63     iterator end() { return _points.end(); }
64     const_iterator end() const { return _points.end(); }
66     // insert
67     std::pair<iterator, bool> insert(const value_type& x);
68     template <class InputIterator>
69     void insert(InputIterator first, InputIterator last) {
70         for (; first != last; ++first) {
71             insert(*first);
72         }
73     }
75     // erase
76     void clear();
77     void erase(iterator pos);
78     size_type erase(const key_type& k);
79     void erase(iterator first, iterator last);
81     // find
82     iterator find(const key_type &k) { return _points.find(k); }
84     // Sometimes it is very useful to keep a list of all selectable points.
85     set_type const &allPoints() const { return _all_points; }
86     set_type &allPoints() { return _all_points; }
87     // ...for example in these methods. Another useful case is snapping.
88     void selectAll();
89     void selectArea(Geom::Rect const &);
90     void invertSelection();
91     void spatialGrow(SelectableControlPoint *origin, int dir);
93     virtual bool event(GdkEvent *);
95     void transform(Geom::Matrix const &m);
96     void align(Geom::Dim2 d);
97     void distribute(Geom::Dim2 d);
99     Geom::OptRect pointwiseBounds();
100     Geom::OptRect bounds();
102     void showTransformHandles(bool v, bool one_node);
103     // the two methods below do not modify the state; they are for use in manipulators
104     // that need to temporarily hide the handles, for example when moving a node
105     void hideTransformHandles();
106     void restoreTransformHandles();
107     void toggleTransformHandlesMode();
109     sigc::signal<void> signal_update;
110     sigc::signal<void, SelectableControlPoint *, bool> signal_point_changed;
111     sigc::signal<void, CommitEvent> signal_commit;
112 private:
113     // The functions below are invoked from SelectableControlPoint.
114     // Previously they were connected to handlers when selecting, but this
115     // creates problems when dragging a point that was not selected.
116     void _pointGrabbed();
117     void _pointDragged(Geom::Point const &, Geom::Point &, GdkEventMotion *);
118     void _pointUngrabbed();
119     bool _pointClicked(SelectableControlPoint *, GdkEventButton *);
121     void _updateTransformHandles(bool preserve_center);
122     bool _keyboardMove(GdkEventKey const &, Geom::Point const &);
123     bool _keyboardRotate(GdkEventKey const &, int);
124     bool _keyboardScale(GdkEventKey const &, int);
125     bool _keyboardFlip(Geom::Dim2);
126     void _keyboardTransform(Geom::Matrix const &);
127     void _commitTransform(CommitEvent ce);
128     map_type _points;
129     set_type _all_points;
130     boost::optional<double> _rot_radius;
131     TransformHandleSet *_handles;
132     SelectableControlPoint *_grabbed_point;
133     unsigned _dragging         : 1;
134     unsigned _handles_visible  : 1;
135     unsigned _one_node_handles : 1;
137     friend class SelectableControlPoint;
138 };
140 } // namespace UI
141 } // namespace Inkscape
143 #endif
145 /*
146   Local Variables:
147   mode:c++
148   c-file-style:"stroustrup"
149   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
150   indent-tabs-mode:nil
151   fill-column:99
152   End:
153 */
154 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :