1 #ifndef __SELTRANS_H__
2 #define __SELTRANS_H__
4 /*
5 * Helper object for transforming selected items
6 *
7 * Author:
8 * Lauris Kaplinski <lauris@kaplinski.com>
9 * Carl Hetherington <inkscape@carlh.net>
10 *
11 * Copyright (C) 1999-2002 Lauris Kaplinski
12 *
13 * Released under GNU GPL, read the file 'COPYING' for more information
14 */
16 #include <sigc++/sigc++.h>
17 #include <libnr/nr-point.h>
18 #include <libnr/nr-matrix.h>
19 #include <libnr/nr-rect.h>
20 #include "forward.h"
21 #include "selcue.h"
22 #include "message-context.h"
23 #include <vector>
25 struct SPKnot;
26 class SPDesktop;
27 class SPCanvasItem;
28 class SPSelTransHandle;
30 namespace Inkscape
31 {
33 namespace XML
34 {
35 class Node;
36 }
38 class SelTrans
39 {
40 public:
41 SelTrans(SPDesktop *desktop);
42 ~SelTrans();
44 Inkscape::MessageContext &messageContext() {
45 return _message_context;
46 }
48 void increaseState();
49 void resetState();
50 void setCenter(NR::Point const &p);
51 void grab(NR::Point const &p, gdouble x, gdouble y, bool show_handles);
52 void transform(NR::Matrix const &rel_affine, NR::Point const &norm);
53 void ungrab();
54 void stamp();
55 void moveTo(NR::Point const &xy, guint state);
56 void stretch(SPSelTransHandle const &handle, NR::Point &pt, guint state);
57 void scale(NR::Point &pt, guint state);
58 void skew(SPSelTransHandle const &handle, NR::Point &pt, guint state);
59 void rotate(NR::Point &pt, guint state);
60 gboolean scaleRequest(NR::Point &pt, guint state);
61 gboolean stretchRequest(SPSelTransHandle const &handle, NR::Point &pt, guint state);
62 gboolean skewRequest(SPSelTransHandle const &handle, NR::Point &pt, guint state);
63 gboolean rotateRequest(NR::Point &pt, guint state);
64 gboolean centerRequest(NR::Point &pt, guint state);
66 gboolean handleRequest(SPKnot *knot, NR::Point *position, guint state, SPSelTransHandle const &handle);
67 void handleGrab(SPKnot *knot, guint state, SPSelTransHandle const &handle);
68 void handleClick(SPKnot *knot, guint state, SPSelTransHandle const &handle);
69 void handleNewEvent(SPKnot *knot, NR::Point *position, guint state, SPSelTransHandle const &handle);
71 enum Show
72 {
73 SHOW_CONTENT,
74 SHOW_OUTLINE
75 };
77 void setShow(Show s) {
78 _show = s;
79 }
80 bool isEmpty() {
81 return _empty;
82 }
84 private:
85 void _updateHandles();
86 void _updateVolatileState();
87 void _selChanged(Inkscape::Selection *selection);
88 void _selModified(Inkscape::Selection *selection, guint flags);
89 void _showHandles(SPKnot *knot[], SPSelTransHandle const handle[], gint num,
90 gchar const *even_tip, gchar const *odd_tip);
92 enum State {
93 STATE_SCALE,
94 STATE_ROTATE
95 };
97 SPDesktop *_desktop;
99 std::vector<std::pair<SPItem *, NR::Matrix> > _items;
100 std::vector<std::pair<SPItem *, NR::Point> > _items_centers;
102 std::vector<NR::Point> _snap_points;
103 std::vector<NR::Point> _bbox_points;
105 Inkscape::SelCue _selcue;
107 Inkscape::Selection *_selection;
108 State _state;
109 Show _show;
111 bool _grabbed;
112 bool _show_handles;
113 bool _empty;
114 bool _changed;
116 NR::Rect _box;
117 gdouble _strokewidth;
118 NR::Matrix _current;
119 NR::Point _opposite; ///< opposite point to where a scale is taking place
121 NR::Point _center;
122 bool _center_is_set; ///< we've already set _center, no need to reread it from items
124 SPKnot *_shandle[8];
125 SPKnot *_rhandle[8];
126 SPKnot *_chandle;
127 SPCanvasItem *_norm;
128 SPCanvasItem *_grip;
129 SPCanvasItem *_l[4];
130 guint _sel_changed_id;
131 guint _sel_modified_id;
132 GSList *_stamp_cache;
134 NR::Point _origin; ///< position of origin for transforms
135 NR::Point _point; ///< original position of the knot being used for the current transform
136 Inkscape::MessageContext _message_context;
137 SigC::Connection _sel_changed_connection;
138 SigC::Connection _sel_modified_connection;
139 };
141 }
143 #endif
146 /*
147 Local Variables:
148 mode:c++
149 c-file-style:"stroustrup"
150 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
151 indent-tabs-mode:nil
152 fill-column:99
153 End:
154 */
155 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :