Code

Fix for bug 168978
[inkscape.git] / src / seltrans.h
1 #ifndef __SELTRANS_H__
2 #define __SELTRANS_H__
4 /*
5  * Helper object for transforming selected items
6  *
7  * Author:
8  *   Lauris Kaplinski <lauris@kaplinski.com>
9  *   Carl Hetherington <inkscape@carlh.net>
10  *
11  * Copyright (C) 2006      Johan Engelen <johan@shouraizou.nl>
12  * Copyright (C) 1999-2002 Lauris Kaplinski
13  *
14  * Released under GNU GPL, read the file 'COPYING' for more information
15  */
17 #include <sigc++/sigc++.h>
18 #include <libnr/nr-point.h>
19 #include <libnr/nr-matrix.h>
20 #include <libnr/nr-rect.h>
21 #include "knot.h"
22 #include "forward.h"
23 #include "selcue.h"
24 #include "message-context.h"
25 #include <vector>
27 struct SPKnot;
28 class SPDesktop;
29 class SPCanvasItem;
30 class SPSelTransHandle;
32 namespace Inkscape
33 {
35 namespace XML
36 {
37   class Node;
38 }
40 class SelTrans
41 {
42 public:
43     SelTrans(SPDesktop *desktop);
44     ~SelTrans();
46     Inkscape::MessageContext &messageContext() {
47         return _message_context;
48     }
50     void increaseState();
51     void resetState();
52     void setCenter(NR::Point const &p);
53     void grab(NR::Point const &p, gdouble x, gdouble y, bool show_handles);
54     void transform(NR::Matrix const &rel_affine, NR::Point const &norm);
55     void ungrab();
56     void stamp();
57     void moveTo(NR::Point const &xy, guint state);
58     void stretch(SPSelTransHandle const &handle, NR::Point &pt, guint state);
59     void scale(NR::Point &pt, guint state);
60     void skew(SPSelTransHandle const &handle, NR::Point &pt, guint state);
61     void rotate(NR::Point &pt, guint state);
62     gboolean scaleRequest(NR::Point &pt, guint state);
63     gboolean stretchRequest(SPSelTransHandle const &handle, NR::Point &pt, guint state);
64     gboolean skewRequest(SPSelTransHandle const &handle, NR::Point &pt, guint state);
65     gboolean rotateRequest(NR::Point &pt, guint state);
66     gboolean centerRequest(NR::Point &pt, guint state);
68     gboolean handleRequest(SPKnot *knot, NR::Point *position, guint state, SPSelTransHandle const &handle);
69     void handleGrab(SPKnot *knot, guint state, SPSelTransHandle const &handle);
70     void handleClick(SPKnot *knot, guint state, SPSelTransHandle const &handle);
71     void handleNewEvent(SPKnot *knot, NR::Point *position, guint state, SPSelTransHandle const &handle);
73     enum Show
74     {
75         SHOW_CONTENT,
76         SHOW_OUTLINE
77     };
79     void setShow(Show s) {
80         _show = s;
81     }
82     bool isEmpty() {
83         return _empty;
84     }
85     bool isGrabbed() {
86         return _grabbed;    
87     }
88         bool centerIsVisible() {
89                 return ( _chandle && SP_KNOT_IS_VISIBLE (_chandle) );
90         }
92 private:
93     void _updateHandles();
94     void _updateVolatileState();
95     void _selChanged(Inkscape::Selection *selection);
96     void _selModified(Inkscape::Selection *selection, guint flags);
97     void _showHandles(SPKnot *knot[], SPSelTransHandle const handle[], gint num,
98                       gchar const *even_tip, gchar const *odd_tip);
100     enum State {
101         STATE_SCALE,
102         STATE_ROTATE
103     };
104     
105     SPDesktop *_desktop;
107     std::vector<std::pair<SPItem *, NR::Matrix> > _items;
108     std::vector<std::pair<SPItem *, NR::Point> > _items_centers;
109     
110     std::vector<NR::Point> _snap_points;
111     std::vector<NR::Point> _bbox_points;
112     
113     Inkscape::SelCue _selcue;
115     Inkscape::Selection *_selection;
116     State _state;
117     Show _show;
119     bool _grabbed;
120     bool _show_handles;
121     bool _empty;
122     bool _changed;
124     SPItem::BBoxType _snap_bbox_type;
125     
126     NR::Maybe<NR::Rect> _bbox;
127     NR::Maybe<NR::Rect> _approximate_bbox;
128     gdouble _strokewidth;
129     NR::Matrix _current;
130     NR::Point _opposite; ///< opposite point to where a scale is taking place
132     NR::Point _opposite_for_specpoints;
133     NR::Point _opposite_for_bboxpoints;
134     NR::Point _origin_for_specpoints;
135     NR::Point _origin_for_bboxpoints;
137     NR::Maybe<NR::Point> _center;
138     bool _center_is_set; ///< we've already set _center, no need to reread it from items
140     SPKnot *_shandle[8];
141     SPKnot *_rhandle[8];
142     SPKnot *_chandle;
143     SPCanvasItem *_norm;
144     SPCanvasItem *_grip;
145     SPCanvasItem *_l[4];
146     guint _sel_changed_id;
147     guint _sel_modified_id;
148     GSList *_stamp_cache;
150     NR::Point _origin; ///< position of origin for transforms
151     NR::Point _point; ///< original position of the knot being used for the current transform
152     Inkscape::MessageContext _message_context;
153     sigc::connection _sel_changed_connection;
154     sigc::connection _sel_modified_connection;
155 };
159 #endif
162 /*
163   Local Variables:
164   mode:c++
165   c-file-style:"stroustrup"
166   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
167   indent-tabs-mode:nil
168   fill-column:99
169   End:
170 */
171 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :