1 #ifndef __SELTRANS_H__
2 #define __SELTRANS_H__
4 /*
5 * Helper object for transforming selected items
6 *
7 * Authors:
8 * Lauris Kaplinski <lauris@kaplinski.com>
9 * Carl Hetherington <inkscape@carlh.net>
10 * Diederik van Lierop <mail@diedenrezi.nl>
11 *
12 * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
13 * Copyright (C) 1999-2002 Lauris Kaplinski
14 *
15 * Released under GNU GPL, read the file 'COPYING' for more information
16 */
18 #include <sigc++/sigc++.h>
19 #include <libnr/nr-point.h>
20 #include <libnr/nr-matrix.h>
21 #include <libnr/nr-rect.h>
22 #include "knot.h"
23 #include "forward.h"
24 #include "selcue.h"
25 #include "message-context.h"
26 #include <vector>
28 struct SPKnot;
29 class SPDesktop;
30 class SPCanvasItem;
31 class SPSelTransHandle;
33 namespace Inkscape
34 {
36 NR::scale calcScaleFactors(NR::Point const &initial_point, NR::Point const &new_point, NR::Point const &origin, bool const skew = false);
38 namespace XML
39 {
40 class Node;
41 }
43 class SelTrans
44 {
45 public:
46 SelTrans(SPDesktop *desktop);
47 ~SelTrans();
49 Inkscape::MessageContext &messageContext() {
50 return _message_context;
51 }
53 void increaseState();
54 void resetState();
55 void setCenter(NR::Point const &p);
56 void grab(NR::Point const &p, gdouble x, gdouble y, bool show_handles);
57 void transform(NR::Matrix const &rel_affine, NR::Point const &norm);
58 void ungrab();
59 void stamp();
60 void moveTo(NR::Point const &xy, guint state);
61 void stretch(SPSelTransHandle const &handle, NR::Point &pt, guint state);
62 void scale(NR::Point &pt, guint state);
63 void skew(SPSelTransHandle const &handle, NR::Point &pt, guint state);
64 void rotate(NR::Point &pt, guint state);
65 gboolean scaleRequest(NR::Point &pt, guint state);
66 gboolean stretchRequest(SPSelTransHandle const &handle, NR::Point &pt, guint state);
67 gboolean skewRequest(SPSelTransHandle const &handle, NR::Point &pt, guint state);
68 gboolean rotateRequest(NR::Point &pt, guint state);
69 gboolean centerRequest(NR::Point &pt, guint state);
71 gboolean handleRequest(SPKnot *knot, NR::Point *position, guint state, SPSelTransHandle const &handle);
72 void handleGrab(SPKnot *knot, guint state, SPSelTransHandle const &handle);
73 void handleClick(SPKnot *knot, guint state, SPSelTransHandle const &handle);
74 void handleNewEvent(SPKnot *knot, NR::Point *position, guint state, SPSelTransHandle const &handle);
76 enum Show
77 {
78 SHOW_CONTENT,
79 SHOW_OUTLINE
80 };
82 void setShow(Show s) {
83 _show = s;
84 }
85 bool isEmpty() {
86 return _empty;
87 }
88 bool isGrabbed() {
89 return _grabbed;
90 }
91 bool centerIsVisible() {
92 return ( _chandle && SP_KNOT_IS_VISIBLE (_chandle) );
93 }
95 private:
96 void _updateHandles();
97 void _updateVolatileState();
98 void _selChanged(Inkscape::Selection *selection);
99 void _selModified(Inkscape::Selection *selection, guint flags);
100 void _showHandles(SPKnot *knot[], SPSelTransHandle const handle[], gint num,
101 gchar const *even_tip, gchar const *odd_tip);
102 NR::Point _getGeomHandlePos(NR::Point const &visual_handle_pos);
103 NR::Point _calcAbsAffineDefault(NR::scale const default_scale);
104 NR::Point _calcAbsAffineGeom(NR::scale const geom_scale);
106 enum State {
107 STATE_SCALE, //scale or stretch
108 STATE_ROTATE //rotate or skew
109 };
111 SPDesktop *_desktop;
113 std::vector<std::pair<SPItem *, NR::Matrix> > _items;
114 std::vector<std::pair<SPItem *, NR::Point> > _items_centers;
116 std::vector<NR::Point> _snap_points;
117 std::vector<NR::Point> _bbox_points;
119 Inkscape::SelCue _selcue;
121 Inkscape::Selection *_selection;
122 State _state;
123 Show _show;
125 bool _grabbed;
126 bool _show_handles;
127 bool _empty;
128 bool _changed;
130 SPItem::BBoxType _snap_bbox_type;
132 NR::Maybe<NR::Rect> _bbox;
133 NR::Maybe<NR::Rect> _approximate_bbox;
134 NR::Maybe<NR::Rect> _geometric_bbox;
135 gdouble _strokewidth;
137 NR::Matrix _current_relative_affine;
138 NR::Matrix _absolute_affine;
139 NR::Matrix _relative_affine;
140 /* According to Merriam - Webster's online dictionary
141 * Affine: a transformation (as a translation, a rotation, or a uniform stretching) that carries straight
142 * lines into straight lines and parallel lines into parallel lines but may alter distance between points
143 * and angles between lines <affine geometry>
144 */
146 NR::Point _opposite; ///< opposite point to where a scale is taking place
147 NR::Point _opposite_for_specpoints;
148 NR::Point _opposite_for_bboxpoints;
149 NR::Point _origin_for_specpoints;
150 NR::Point _origin_for_bboxpoints;
152 gdouble _handle_x;
153 gdouble _handle_y;
155 NR::Maybe<NR::Point> _center;
156 bool _center_is_set; ///< we've already set _center, no need to reread it from items
158 SPKnot *_shandle[8];
159 SPKnot *_rhandle[8];
160 SPKnot *_chandle;
161 SPCanvasItem *_norm;
162 SPCanvasItem *_grip;
163 SPCanvasItem *_l[4];
164 guint _sel_changed_id;
165 guint _sel_modified_id;
166 GSList *_stamp_cache;
168 NR::Point _origin; ///< position of origin for transforms
169 NR::Point _point; ///< original position of the knot being used for the current transform
170 NR::Point _point_geom; ///< original position of the knot being used for the current transform
171 Inkscape::MessageContext _message_context;
172 sigc::connection _sel_changed_connection;
173 sigc::connection _sel_modified_connection;
174 };
176 }
178 #endif
181 /*
182 Local Variables:
183 mode:c++
184 c-file-style:"stroustrup"
185 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
186 indent-tabs-mode:nil
187 fill-column:99
188 End:
189 */
190 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :