Code

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