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);
106 void _display_snapsource();
108 enum State {
109 STATE_SCALE, //scale or stretch
110 STATE_ROTATE //rotate or skew
111 };
113 SPDesktop *_desktop;
115 std::vector<SPItem *> _items;
116 std::vector<SPItem const *> _items_const;
117 std::vector<Geom::Matrix> _items_affines;
118 std::vector<Geom::Point> _items_centers;
120 std::vector<Geom::Point> _snap_points;
121 std::vector<Geom::Point> _bbox_points;
123 Inkscape::SelCue _selcue;
125 Inkscape::Selection *_selection;
126 State _state;
127 Show _show;
129 bool _grabbed;
130 bool _show_handles;
131 bool _empty;
132 bool _changed;
134 SPItem::BBoxType _snap_bbox_type;
136 Geom::OptRect _bbox;
137 Geom::OptRect _approximate_bbox;
138 Geom::OptRect _geometric_bbox;
139 gdouble _strokewidth;
141 Geom::Matrix _current_relative_affine;
142 Geom::Matrix _absolute_affine;
143 Geom::Matrix _relative_affine;
144 /* According to Merriam - Webster's online dictionary
145 * Affine: a transformation (as a translation, a rotation, or a uniform stretching) that carries straight
146 * lines into straight lines and parallel lines into parallel lines but may alter distance between points
147 * and angles between lines <affine geometry>
148 */
150 Geom::Point _opposite; ///< opposite point to where a scale is taking place
151 Geom::Point _opposite_for_specpoints;
152 Geom::Point _opposite_for_bboxpoints;
153 Geom::Point _origin_for_specpoints;
154 Geom::Point _origin_for_bboxpoints;
156 gdouble _handle_x;
157 gdouble _handle_y;
159 boost::optional<Geom::Point> _center;
160 bool _center_is_set; ///< we've already set _center, no need to reread it from items
162 SPKnot *_shandle[8];
163 SPKnot *_rhandle[8];
164 SPKnot *_chandle;
165 SPCanvasItem *_norm;
166 SPCanvasItem *_grip;
167 SPCanvasItem *_l[4];
168 guint _sel_changed_id;
169 guint _sel_modified_id;
170 GSList *_stamp_cache;
172 Geom::Point _origin; ///< position of origin for transforms
173 Geom::Point _point; ///< original position of the knot being used for the current transform
174 Geom::Point _point_geom; ///< original position of the knot being used for the current transform
175 Inkscape::MessageContext _message_context;
176 sigc::connection _sel_changed_connection;
177 sigc::connection _sel_modified_connection;
178 };
180 }
182 #endif
185 /*
186 Local Variables:
187 mode:c++
188 c-file-style:"stroustrup"
189 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
190 indent-tabs-mode:nil
191 fill-column:99
192 End:
193 */
194 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :