Code

Node tool: snap while scaling a selection of nodes. Consider this as experimental...
[inkscape.git] / src / seltrans.h
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 _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<Inkscape::SnapCandidatePoint> _snap_points;
121     std::vector<Inkscape::SnapCandidatePoint> _bbox_points; // the bbox point of the selection as a whole, i.e. max. 4 corners plus optionally some midpoints
122     std::vector<Inkscape::SnapCandidatePoint> _bbox_points_for_translating; // the bbox points of each selected item, only to be used for translating
124     Inkscape::SelCue _selcue;
126     Inkscape::Selection *_selection;
127     State _state;
128     Show _show;
130     bool _grabbed;
131     bool _show_handles;
132     bool _empty;
133     bool _changed;
135     SPItem::BBoxType _snap_bbox_type;
137     Geom::OptRect _bbox;
138     Geom::OptRect _approximate_bbox;
139     Geom::OptRect _geometric_bbox;
140     gdouble _strokewidth;
142     Geom::Matrix _current_relative_affine;
143     Geom::Matrix _absolute_affine;
144     Geom::Matrix _relative_affine;
145     /* According to Merriam - Webster's online dictionary
146      * Affine: a transformation (as a translation, a rotation, or a uniform stretching) that carries straight
147      * lines into straight lines and parallel lines into parallel lines but may alter distance between points
148      * and angles between lines <affine geometry>
149      */
151     Geom::Point _opposite; ///< opposite point to where a scale is taking place
152     Geom::Point _opposite_for_specpoints;
153     Geom::Point _opposite_for_bboxpoints;
154     Geom::Point _origin_for_specpoints;
155     Geom::Point _origin_for_bboxpoints;
157     gdouble _handle_x;
158     gdouble _handle_y;
160     boost::optional<Geom::Point> _center;
161     bool _center_is_set; ///< we've already set _center, no need to reread it from items
163     SPKnot *_shandle[8];
164     SPKnot *_rhandle[8];
165     SPKnot *_chandle;
166     SPCanvasItem *_norm;
167     SPCanvasItem *_grip;
168     SPCanvasItem *_l[4];
169     guint _sel_changed_id;
170     guint _sel_modified_id;
171     GSList *_stamp_cache;
173     Geom::Point _origin; ///< position of origin for transforms
174     Geom::Point _point; ///< original position of the knot being used for the current transform
175     Geom::Point _point_geom; ///< original position of the knot being used for the current transform
176     Inkscape::MessageContext _message_context;
177     sigc::connection _sel_changed_connection;
178     sigc::connection _sel_modified_connection;
179 };
183 #endif
186 /*
187   Local Variables:
188   mode:c++
189   c-file-style:"stroustrup"
190   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
191   indent-tabs-mode:nil
192   fill-column:99
193   End:
194 */
195 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :