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) 1999-2002 Lauris Kaplinski
12 *
13 * Released under GNU GPL, read the file 'COPYING' for more information
14 */
16 #include <sigc++/sigc++.h>
17 #include <libnr/nr-point.h>
18 #include <libnr/nr-matrix.h>
19 #include <libnr/nr-rect.h>
20 #include "forward.h"
21 #include "selcue.h"
22 #include "message-context.h"
23 #include <vector>
25 struct SPKnot;
26 class SPDesktop;
27 class SPCanvasItem;
28 class SPSelTransHandle;
30 namespace Inkscape
31 {
33 namespace XML
34 {
35 class Node;
36 }
38 class SelTrans
39 {
40 public:
41 SelTrans(SPDesktop *desktop);
42 ~SelTrans();
44 Inkscape::MessageContext &messageContext() {
45 return _message_context;
46 }
48 void increaseState();
49 void resetState();
50 void setCenter(NR::Point const &p);
51 void grab(NR::Point const &p, gdouble x, gdouble y, bool show_handles);
52 void transform(NR::Matrix const &rel_affine, NR::Point const &norm);
53 void ungrab();
54 void stamp();
55 void moveTo(NR::Point const &xy, guint state);
56 void stretch(SPSelTransHandle const &handle, NR::Point &pt, guint state);
57 void scale(NR::Point &pt, guint state);
58 void skew(SPSelTransHandle const &handle, NR::Point &pt, guint state);
59 void rotate(NR::Point &pt, guint state);
60 gboolean scaleRequest(NR::Point &pt, guint state);
61 gboolean stretchRequest(SPSelTransHandle const &handle, NR::Point &pt, guint state);
62 gboolean skewRequest(SPSelTransHandle const &handle, NR::Point &pt, guint state);
63 gboolean rotateRequest(NR::Point &pt, guint state);
64 gboolean centerRequest(NR::Point &pt, guint state);
66 gboolean handleRequest(SPKnot *knot, NR::Point *position, guint state, SPSelTransHandle const &handle);
67 void handleGrab(SPKnot *knot, guint state, SPSelTransHandle const &handle);
68 void handleClick(SPKnot *knot, guint state, SPSelTransHandle const &handle);
69 void handleNewEvent(SPKnot *knot, NR::Point *position, guint state, SPSelTransHandle const &handle);
71 enum Show
72 {
73 SHOW_CONTENT,
74 SHOW_OUTLINE
75 };
77 void setShow(Show s) {
78 _show = s;
79 }
80 bool isEmpty() {
81 return _empty;
82 }
84 private:
85 void _updateHandles();
86 void _updateVolatileState();
87 void _selChanged(Inkscape::Selection *selection);
88 void _selModified(Inkscape::Selection *selection, guint flags);
89 void _showHandles(SPKnot *knot[], SPSelTransHandle const handle[], gint num,
90 gchar const *even_tip, gchar const *odd_tip);
92 enum State {
93 STATE_SCALE,
94 STATE_ROTATE
95 };
97 SPDesktop *_desktop;
99 std::vector<std::pair<SPItem *, NR::Matrix> > _items;
101 std::vector<NR::Point> _snap_points;
102 std::vector<NR::Point> _bbox_points;
104 Inkscape::SelCue _selcue;
106 Inkscape::Selection *_selection;
107 State _state;
108 Show _show;
110 bool _grabbed;
111 bool _show_handles;
112 bool _empty;
113 bool _changed;
115 NR::Rect _box;
116 gdouble _strokewidth;
117 NR::Matrix _current;
118 NR::Point _opposite; ///< opposite point to where a scale is taking place
119 NR::Point _center;
120 SPKnot *_shandle[8];
121 SPKnot *_rhandle[8];
122 SPKnot *_chandle;
123 SPCanvasItem *_norm;
124 SPCanvasItem *_grip;
125 SPCanvasItem *_l[4];
126 guint _sel_changed_id;
127 guint _sel_modified_id;
128 GSList *_stamp_cache;
130 NR::Point _origin; ///< position of origin for transforms
131 NR::Point _point; ///< original position of the knot being used for the current transform
132 Inkscape::MessageContext _message_context;
133 SigC::Connection _sel_changed_connection;
134 SigC::Connection _sel_modified_connection;
135 };
137 }
139 #endif
142 /*
143 Local Variables:
144 mode:c++
145 c-file-style:"stroustrup"
146 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
147 indent-tabs-mode:nil
148 fill-column:99
149 End:
150 */
151 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :