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 }
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 };
101 SPDesktop *_desktop;
103 std::vector<std::pair<SPItem *, NR::Matrix> > _items;
104 std::vector<std::pair<SPItem *, NR::Point> > _items_centers;
106 std::vector<NR::Point> _snap_points;
107 std::vector<NR::Point> _bbox_points;
109 Inkscape::SelCue _selcue;
111 Inkscape::Selection *_selection;
112 State _state;
113 Show _show;
115 bool _grabbed;
116 bool _show_handles;
117 bool _empty;
118 bool _changed;
120 SPItem::BBoxType _snap_bbox_type;
122 NR::Maybe<NR::Rect> _bbox;
123 NR::Maybe<NR::Rect> _approximate_bbox;
124 gdouble _strokewidth;
125 NR::Matrix _current;
126 NR::Point _opposite; ///< opposite point to where a scale is taking place
128 NR::Point _opposite_for_specpoints;
129 NR::Point _opposite_for_bboxpoints;
130 NR::Point _origin_for_specpoints;
131 NR::Point _origin_for_bboxpoints;
133 NR::Maybe<NR::Point> _center;
134 bool _center_is_set; ///< we've already set _center, no need to reread it from items
136 SPKnot *_shandle[8];
137 SPKnot *_rhandle[8];
138 SPKnot *_chandle;
139 SPCanvasItem *_norm;
140 SPCanvasItem *_grip;
141 SPCanvasItem *_l[4];
142 guint _sel_changed_id;
143 guint _sel_modified_id;
144 GSList *_stamp_cache;
146 NR::Point _origin; ///< position of origin for transforms
147 NR::Point _point; ///< original position of the knot being used for the current transform
148 Inkscape::MessageContext _message_context;
149 SigC::Connection _sel_changed_connection;
150 SigC::Connection _sel_modified_connection;
151 };
153 }
155 #endif
158 /*
159 Local Variables:
160 mode:c++
161 c-file-style:"stroustrup"
162 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
163 indent-tabs-mode:nil
164 fill-column:99
165 End:
166 */
167 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :