Code

fix by dvlierop2 for snapping bugs 1579556 and 1579587
[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 "forward.h"
22 #include "selcue.h"
23 #include "message-context.h"
24 #include <vector>
26 struct SPKnot;
27 class SPDesktop;
28 class SPCanvasItem;
29 class SPSelTransHandle;
31 namespace Inkscape
32 {
34 namespace XML
35 {
36   class Node;
37 }
39 class SelTrans
40 {
41 public:
42     SelTrans(SPDesktop *desktop);
43     ~SelTrans();
45     Inkscape::MessageContext &messageContext() {
46         return _message_context;
47     }
49     void increaseState();
50     void resetState();
51     void setCenter(NR::Point const &p);
52     void grab(NR::Point const &p, gdouble x, gdouble y, bool show_handles);
53     void transform(NR::Matrix const &rel_affine, NR::Point const &norm);
54     void ungrab();
55     void stamp();
56     void moveTo(NR::Point const &xy, guint state);
57     void stretch(SPSelTransHandle const &handle, NR::Point &pt, guint state);
58     void scale(NR::Point &pt, guint state);
59     void skew(SPSelTransHandle const &handle, NR::Point &pt, guint state);
60     void rotate(NR::Point &pt, guint state);
61     gboolean scaleRequest(NR::Point &pt, guint state);
62     gboolean stretchRequest(SPSelTransHandle const &handle, NR::Point &pt, guint state);
63     gboolean skewRequest(SPSelTransHandle const &handle, NR::Point &pt, guint state);
64     gboolean rotateRequest(NR::Point &pt, guint state);
65     gboolean centerRequest(NR::Point &pt, guint state);
67     gboolean handleRequest(SPKnot *knot, NR::Point *position, guint state, SPSelTransHandle const &handle);
68     void handleGrab(SPKnot *knot, guint state, SPSelTransHandle const &handle);
69     void handleClick(SPKnot *knot, guint state, SPSelTransHandle const &handle);
70     void handleNewEvent(SPKnot *knot, NR::Point *position, guint state, SPSelTransHandle const &handle);
72     enum Show
73     {
74         SHOW_CONTENT,
75         SHOW_OUTLINE
76     };
78     void setShow(Show s) {
79         _show = s;
80     }
81     bool isEmpty() {
82         return _empty;
83     }
84     bool isGrabbed() {
85         return _grabbed;    
86     }
87     
88 private:
89     void _updateHandles();
90     void _updateVolatileState();
91     void _selChanged(Inkscape::Selection *selection);
92     void _selModified(Inkscape::Selection *selection, guint flags);
93     void _showHandles(SPKnot *knot[], SPSelTransHandle const handle[], gint num,
94                       gchar const *even_tip, gchar const *odd_tip);
96     enum State {
97         STATE_SCALE,
98         STATE_ROTATE
99     };
100     
101     SPDesktop *_desktop;
103     std::vector<std::pair<SPItem *, NR::Matrix> > _items;
104     std::vector<std::pair<SPItem *, NR::Point> > _items_centers;
105     
106     std::vector<NR::Point> _snap_points;
107     std::vector<NR::Point> _bbox_points;
108     std::vector<NR::Point> _bbox_4points;
109     
110     Inkscape::SelCue _selcue;
112     Inkscape::Selection *_selection;
113     State _state;
114     Show _show;
116     bool _grabbed;
117     bool _show_handles;
118     bool _empty;
119     bool _changed;
121     NR::Rect _box;
122     gdouble _strokewidth;
123     NR::Matrix _current;
124     NR::Point _opposite; ///< opposite point to where a scale is taking place
126     NR::Point _center;
127     bool _center_is_set; ///< we've already set _center, no need to reread it from items
129     SPKnot *_shandle[8];
130     SPKnot *_rhandle[8];
131     SPKnot *_chandle;
132     SPCanvasItem *_norm;
133     SPCanvasItem *_grip;
134     SPCanvasItem *_l[4];
135     guint _sel_changed_id;
136     guint _sel_modified_id;
137     GSList *_stamp_cache;    
139     NR::Point _origin; ///< position of origin for transforms
140     NR::Point _point; ///< original position of the knot being used for the current transform
141     Inkscape::MessageContext _message_context;
142     SigC::Connection _sel_changed_connection;
143     SigC::Connection _sel_modified_connection;
144 };
148 #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 :