Code

Avoid crash by uninitialized perspectives.
[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>
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, bool translating);
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<Inkscape::SnapCandidatePoint> &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<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 :