80bbbcf350b3f4d5220f31b5a78c6e7673f5d93f
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 }
83 bool isGrabbed() {
84 return _grabbed;
85 }
87 private:
88 void _updateHandles();
89 void _updateVolatileState();
90 void _selChanged(Inkscape::Selection *selection);
91 void _selModified(Inkscape::Selection *selection, guint flags);
92 void _showHandles(SPKnot *knot[], SPSelTransHandle const handle[], gint num,
93 gchar const *even_tip, gchar const *odd_tip);
95 enum State {
96 STATE_SCALE,
97 STATE_ROTATE
98 };
100 SPDesktop *_desktop;
102 std::vector<std::pair<SPItem *, NR::Matrix> > _items;
103 std::vector<std::pair<SPItem *, NR::Point> > _items_centers;
105 std::vector<NR::Point> _snap_points;
106 std::vector<NR::Point> _bbox_points;
108 Inkscape::SelCue _selcue;
110 Inkscape::Selection *_selection;
111 State _state;
112 Show _show;
114 bool _grabbed;
115 bool _show_handles;
116 bool _empty;
117 bool _changed;
119 NR::Rect _box;
120 gdouble _strokewidth;
121 NR::Matrix _current;
122 NR::Point _opposite; ///< opposite point to where a scale is taking place
124 NR::Point _center;
125 bool _center_is_set; ///< we've already set _center, no need to reread it from items
127 SPKnot *_shandle[8];
128 SPKnot *_rhandle[8];
129 SPKnot *_chandle;
130 SPCanvasItem *_norm;
131 SPCanvasItem *_grip;
132 SPCanvasItem *_l[4];
133 guint _sel_changed_id;
134 guint _sel_modified_id;
135 GSList *_stamp_cache;
137 NR::Point _origin; ///< position of origin for transforms
138 NR::Point _point; ///< original position of the knot being used for the current transform
139 Inkscape::MessageContext _message_context;
140 SigC::Connection _sel_changed_connection;
141 SigC::Connection _sel_modified_connection;
142 };
144 }
146 #endif
149 /*
150 Local Variables:
151 mode:c++
152 c-file-style:"stroustrup"
153 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
154 indent-tabs-mode:nil
155 fill-column:99
156 End:
157 */
158 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :