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 <2geom/point.h>
20 #include <2geom/matrix.h>
21 #include <2geom/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 Geom::Scale calcScaleFactors(Geom::Point const &initial_point, Geom::Point const &new_point, Geom::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(Geom::Point const &p);
56 void grab(Geom::Point const &p, gdouble x, gdouble y, bool show_handles);
57 void transform(Geom::Matrix const &rel_affine, Geom::Point const &norm);
58 void ungrab();
59 void stamp();
60 void moveTo(Geom::Point const &xy, guint state);
61 void stretch(SPSelTransHandle const &handle, Geom::Point &pt, guint state);
62 void scale(Geom::Point &pt, guint state);
63 void skew(SPSelTransHandle const &handle, Geom::Point &pt, guint state);
64 void rotate(Geom::Point &pt, guint state);
65 gboolean scaleRequest(Geom::Point &pt, guint state);
66 gboolean stretchRequest(SPSelTransHandle const &handle, Geom::Point &pt, guint state);
67 gboolean skewRequest(SPSelTransHandle const &handle, Geom::Point &pt, guint state);
68 gboolean rotateRequest(Geom::Point &pt, guint state);
69 gboolean centerRequest(Geom::Point &pt, guint state);
71 gboolean handleRequest(SPKnot *knot, Geom::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, Geom::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 Geom::Point _getGeomHandlePos(Geom::Point const &visual_handle_pos);
103 Geom::Point _calcAbsAffineDefault(Geom::Scale const default_scale);
104 Geom::Point _calcAbsAffineGeom(Geom::Scale const geom_scale);
105 void _keepClosestPointOnly(std::vector<Geom::Point> &points, const Geom::Point &reference);
107 enum State {
108 STATE_SCALE, //scale or stretch
109 STATE_ROTATE //rotate or skew
110 };
112 SPDesktop *_desktop;
114 std::vector<SPItem *> _items;
115 std::vector<SPItem const *> _items_const;
116 std::vector<Geom::Matrix> _items_affines;
117 std::vector<Geom::Point> _items_centers;
119 std::vector<Geom::Point> _snap_points;
120 std::vector<Geom::Point> _bbox_points;
122 Inkscape::SelCue _selcue;
124 Inkscape::Selection *_selection;
125 State _state;
126 Show _show;
128 bool _grabbed;
129 bool _show_handles;
130 bool _empty;
131 bool _changed;
133 SPItem::BBoxType _snap_bbox_type;
135 Geom::OptRect _bbox;
136 Geom::OptRect _approximate_bbox;
137 Geom::OptRect _geometric_bbox;
138 gdouble _strokewidth;
140 Geom::Matrix _current_relative_affine;
141 Geom::Matrix _absolute_affine;
142 Geom::Matrix _relative_affine;
143 /* According to Merriam - Webster's online dictionary
144 * Affine: a transformation (as a translation, a rotation, or a uniform stretching) that carries straight
145 * lines into straight lines and parallel lines into parallel lines but may alter distance between points
146 * and angles between lines <affine geometry>
147 */
149 Geom::Point _opposite; ///< opposite point to where a scale is taking place
150 Geom::Point _opposite_for_specpoints;
151 Geom::Point _opposite_for_bboxpoints;
152 Geom::Point _origin_for_specpoints;
153 Geom::Point _origin_for_bboxpoints;
155 gdouble _handle_x;
156 gdouble _handle_y;
158 boost::optional<Geom::Point> _center;
159 bool _center_is_set; ///< we've already set _center, no need to reread it from items
161 SPKnot *_shandle[8];
162 SPKnot *_rhandle[8];
163 SPKnot *_chandle;
164 SPCanvasItem *_norm;
165 SPCanvasItem *_grip;
166 SPCanvasItem *_l[4];
167 guint _sel_changed_id;
168 guint _sel_modified_id;
169 GSList *_stamp_cache;
171 Geom::Point _origin; ///< position of origin for transforms
172 Geom::Point _point; ///< original position of the knot being used for the current transform
173 Geom::Point _point_geom; ///< original position of the knot being used for the current transform
174 Inkscape::MessageContext _message_context;
175 sigc::connection _sel_changed_connection;
176 sigc::connection _sel_modified_connection;
177 };
179 }
181 #endif
184 /*
185 Local Variables:
186 mode:c++
187 c-file-style:"stroustrup"
188 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
189 indent-tabs-mode:nil
190 fill-column:99
191 End:
192 */
193 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :