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>
27 #include "sp-item.h"
29 struct SPKnot;
30 class SPDesktop;
31 class SPCanvasItem;
32 class SPSelTransHandle;
34 namespace Inkscape
35 {
37 Geom::Scale calcScaleFactors(Geom::Point const &initial_point, Geom::Point const &new_point, Geom::Point const &origin, bool const skew = false);
39 namespace XML
40 {
41 class Node;
42 }
44 class SelTrans
45 {
46 public:
47 SelTrans(SPDesktop *desktop);
48 ~SelTrans();
50 Inkscape::MessageContext &messageContext() {
51 return _message_context;
52 }
54 void increaseState();
55 void resetState();
56 void setCenter(Geom::Point const &p);
57 void grab(Geom::Point const &p, gdouble x, gdouble y, bool show_handles, bool translating);
58 void transform(Geom::Matrix const &rel_affine, Geom::Point const &norm);
59 void ungrab();
60 void stamp();
61 void moveTo(Geom::Point const &xy, guint state);
62 void stretch(SPSelTransHandle const &handle, Geom::Point &pt, guint state);
63 void scale(Geom::Point &pt, guint state);
64 void skew(SPSelTransHandle const &handle, Geom::Point &pt, guint state);
65 void rotate(Geom::Point &pt, guint state);
66 gboolean scaleRequest(Geom::Point &pt, guint state);
67 gboolean stretchRequest(SPSelTransHandle const &handle, Geom::Point &pt, guint state);
68 gboolean skewRequest(SPSelTransHandle const &handle, Geom::Point &pt, guint state);
69 gboolean rotateRequest(Geom::Point &pt, guint state);
70 gboolean centerRequest(Geom::Point &pt, guint state);
72 gboolean handleRequest(SPKnot *knot, Geom::Point *position, guint state, SPSelTransHandle const &handle);
73 void handleGrab(SPKnot *knot, guint state, SPSelTransHandle const &handle);
74 void handleClick(SPKnot *knot, guint state, SPSelTransHandle const &handle);
75 void handleNewEvent(SPKnot *knot, Geom::Point *position, guint state, SPSelTransHandle const &handle);
77 enum Show
78 {
79 SHOW_CONTENT,
80 SHOW_OUTLINE
81 };
83 void setShow(Show s) {
84 _show = s;
85 }
86 bool isEmpty() {
87 return _empty;
88 }
89 bool isGrabbed() {
90 return _grabbed;
91 }
92 bool centerIsVisible() {
93 return ( _chandle && SP_KNOT_IS_VISIBLE (_chandle) );
94 }
96 private:
97 void _updateHandles();
98 void _updateVolatileState();
99 void _selChanged(Inkscape::Selection *selection);
100 void _selModified(Inkscape::Selection *selection, guint flags);
101 void _showHandles(SPKnot *knot[], SPSelTransHandle const handle[], gint num,
102 gchar const *even_tip, gchar const *odd_tip);
103 Geom::Point _getGeomHandlePos(Geom::Point const &visual_handle_pos);
104 Geom::Point _calcAbsAffineDefault(Geom::Scale const default_scale);
105 Geom::Point _calcAbsAffineGeom(Geom::Scale const geom_scale);
106 void _keepClosestPointOnly(std::vector<Inkscape::SnapCandidatePoint> &points, const Geom::Point &reference);
107 void _display_snapsource();
109 enum State {
110 STATE_SCALE, //scale or stretch
111 STATE_ROTATE //rotate or skew
112 };
114 SPDesktop *_desktop;
116 std::vector<SPItem *> _items;
117 std::vector<SPItem const *> _items_const;
118 std::vector<Geom::Matrix> _items_affines;
119 std::vector<Geom::Point> _items_centers;
121 std::vector<Inkscape::SnapCandidatePoint> _snap_points;
122 std::vector<Inkscape::SnapCandidatePoint> _bbox_points; // the bbox point of the selection as a whole, i.e. max. 4 corners plus optionally some midpoints
123 std::vector<Inkscape::SnapCandidatePoint> _bbox_points_for_translating; // the bbox points of each selected item, only to be used for translating
125 Inkscape::SelCue _selcue;
127 Inkscape::Selection *_selection;
128 State _state;
129 Show _show;
131 bool _grabbed;
132 bool _show_handles;
133 bool _empty;
134 bool _changed;
136 SPItem::BBoxType _snap_bbox_type;
138 Geom::OptRect _bbox;
139 Geom::OptRect _approximate_bbox;
140 Geom::OptRect _geometric_bbox;
141 gdouble _strokewidth;
143 Geom::Matrix _current_relative_affine;
144 Geom::Matrix _absolute_affine;
145 Geom::Matrix _relative_affine;
146 /* According to Merriam - Webster's online dictionary
147 * Affine: a transformation (as a translation, a rotation, or a uniform stretching) that carries straight
148 * lines into straight lines and parallel lines into parallel lines but may alter distance between points
149 * and angles between lines <affine geometry>
150 */
152 Geom::Point _opposite; ///< opposite point to where a scale is taking place
153 Geom::Point _opposite_for_specpoints;
154 Geom::Point _opposite_for_bboxpoints;
155 Geom::Point _origin_for_specpoints;
156 Geom::Point _origin_for_bboxpoints;
158 gdouble _handle_x;
159 gdouble _handle_y;
161 boost::optional<Geom::Point> _center;
162 bool _center_is_set; ///< we've already set _center, no need to reread it from items
164 SPKnot *_shandle[8];
165 SPKnot *_rhandle[8];
166 SPKnot *_chandle;
167 SPCanvasItem *_norm;
168 SPCanvasItem *_grip;
169 SPCanvasItem *_l[4];
170 guint _sel_changed_id;
171 guint _sel_modified_id;
172 GSList *_stamp_cache;
174 Geom::Point _origin; ///< position of origin for transforms
175 Geom::Point _point; ///< original position of the knot being used for the current transform
176 Geom::Point _point_geom; ///< original position of the knot being used for the current transform
177 Inkscape::MessageContext _message_context;
178 sigc::connection _sel_changed_connection;
179 sigc::connection _sel_modified_connection;
180 };
182 }
184 #endif
187 /*
188 Local Variables:
189 mode:c++
190 c-file-style:"stroustrup"
191 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
192 indent-tabs-mode:nil
193 fill-column:99
194 End:
195 */
196 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :