~danieljabailey/inkscape/arc_node_editor

« back to all changes in this revision

Viewing changes to src/seltrans.h

  • Committer: scislac
  • Date: 2009-08-12 07:57:52 UTC
  • Revision ID: scislac@users.sourceforge.net-20090812075752-3zt99jgeqr3bm16j
much better quality multi-size windows icon, thanks ChrisMorgan

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef SEEN_SELTRANS_H
2
 
#define SEEN_SELTRANS_H
 
1
#ifndef __SELTRANS_H__
 
2
#define __SELTRANS_H__
3
3
 
4
4
/*
5
5
 * Helper object for transforming selected items
15
15
 * Released under GNU GPL, read the file 'COPYING' for more information
16
16
 */
17
17
 
 
18
#include <sigc++/sigc++.h>
18
19
#include <2geom/point.h>
19
 
#include <2geom/affine.h>
 
20
#include <2geom/matrix.h>
20
21
#include <2geom/rect.h>
21
 
#include <cstddef>
22
 
#include <sigc++/sigc++.h>
23
 
#include <vector>
24
 
 
25
22
#include "knot.h"
 
23
#include "forward.h"
 
24
#include "selcue.h"
26
25
#include "message-context.h"
27
 
#include "seltrans-handles.h"
28
 
#include "selcue.h"
29
 
#include "sp-item.h"
30
 
 
31
 
 
32
 
class  SPKnot;
33
 
class  SPDesktop;
34
 
struct SPCanvasItem;
35
 
struct SPCtrlLine;
36
 
struct SPSelTransHandle;
37
 
 
38
 
namespace Inkscape {
 
26
#include <vector>
 
27
 
 
28
struct SPKnot;
 
29
class SPDesktop;
 
30
class SPCanvasItem;
 
31
class SPSelTransHandle;
 
32
 
 
33
namespace Inkscape
 
34
{
39
35
 
40
36
Geom::Scale calcScaleFactors(Geom::Point const &initial_point, Geom::Point const &new_point, Geom::Point const &origin, bool const skew = false);
41
37
 
42
 
namespace XML {
43
 
    class Node;
 
38
namespace XML
 
39
{
 
40
  class Node;
44
41
}
45
42
 
46
43
class SelTrans
56
53
    void increaseState();
57
54
    void resetState();
58
55
    void setCenter(Geom::Point const &p);
59
 
    void grab(Geom::Point const &p, double x, double y, bool show_handles, bool translating);
60
 
    void transform(Geom::Affine const &rel_affine, Geom::Point const &norm);
 
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);
61
58
    void ungrab();
62
59
    void stamp();
63
 
    void moveTo(Geom::Point const &xy, unsigned int state);
64
 
    void stretch(SPSelTransHandle const &handle, Geom::Point &pt, unsigned int state);
65
 
    void scale(Geom::Point &pt, unsigned int state);
66
 
    void skew(SPSelTransHandle const &handle, Geom::Point &pt, unsigned int state);
67
 
    void rotate(Geom::Point &pt, unsigned int state);
68
 
    int request(SPSelTransHandle const &handle, Geom::Point &pt, unsigned int state);
69
 
    int scaleRequest(Geom::Point &pt, unsigned int state);
70
 
    int stretchRequest(SPSelTransHandle const &handle, Geom::Point &pt, unsigned int state);
71
 
    int skewRequest(SPSelTransHandle const &handle, Geom::Point &pt, unsigned int state);
72
 
    int rotateRequest(Geom::Point &pt, unsigned int state);
73
 
    int centerRequest(Geom::Point &pt, unsigned int state);
 
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);
74
70
 
75
 
    int handleRequest(SPKnot *knot, Geom::Point *position, unsigned int state, SPSelTransHandle const &handle);
76
 
    void handleGrab(SPKnot *knot, unsigned int state, SPSelTransHandle const &handle);
77
 
    void handleClick(SPKnot *knot, unsigned int state, SPSelTransHandle const &handle);
78
 
    void handleNewEvent(SPKnot *knot, Geom::Point *position, unsigned int state, SPSelTransHandle const &handle);
 
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);
79
75
 
80
76
    enum Show
81
77
    {
92
88
    bool isGrabbed() {
93
89
        return _grabbed;
94
90
    }
95
 
    bool centerIsVisible() {
96
 
        return ( SP_KNOT_IS_VISIBLE (knots[0]) );
97
 
    }
98
 
 
99
 
    void getNextClosestPoint(bool reverse);
 
91
        bool centerIsVisible() {
 
92
                return ( _chandle && SP_KNOT_IS_VISIBLE (_chandle) );
 
93
        }
100
94
 
101
95
private:
102
 
    class BoundingBoxPrefsObserver: public Preferences::Observer
103
 
    {
104
 
    public:
105
 
        BoundingBoxPrefsObserver(SelTrans &sel_trans);
106
 
 
107
 
        void notify(Preferences::Entry const &val);
108
 
 
109
 
    private:
110
 
        SelTrans &_sel_trans;
111
 
    };
112
 
 
113
 
    friend class Inkscape::SelTrans::BoundingBoxPrefsObserver;
114
 
 
115
96
    void _updateHandles();
116
97
    void _updateVolatileState();
117
98
    void _selChanged(Inkscape::Selection *selection);
118
 
    void _selModified(Inkscape::Selection *selection, unsigned int flags);
119
 
    void _boundingBoxPrefsChanged(int prefs_bbox);
120
 
    void _makeHandles();
121
 
    void _showHandles(SPSelTransType type);
 
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);
122
102
    Geom::Point _getGeomHandlePos(Geom::Point const &visual_handle_pos);
123
103
    Geom::Point _calcAbsAffineDefault(Geom::Scale const default_scale);
124
104
    Geom::Point _calcAbsAffineGeom(Geom::Scale const geom_scale);
125
 
    void _keepClosestPointOnly(Geom::Point const &p);
 
105
    void _keepClosestPointOnly(std::vector<std::pair<Geom::Point, int> > &points, const Geom::Point &reference);
 
106
    void _display_snapsource();
126
107
 
127
108
    enum State {
128
109
        STATE_SCALE, //scale or stretch
133
114
 
134
115
    std::vector<SPItem *> _items;
135
116
    std::vector<SPItem const *> _items_const;
136
 
    std::vector<Geom::Affine> _items_affines;
 
117
    std::vector<Geom::Matrix> _items_affines;
137
118
    std::vector<Geom::Point> _items_centers;
138
119
 
139
 
    std::vector<Inkscape::SnapCandidatePoint> _snap_points;
140
 
    std::vector<Inkscape::SnapCandidatePoint> _bbox_points;
141
 
    std::vector<Inkscape::SnapCandidatePoint> _all_snap_sources_sorted;
142
 
    std::vector<Inkscape::SnapCandidatePoint>::iterator _all_snap_sources_iter;
 
120
    std::vector<std::pair<Geom::Point, int> > _snap_points;
 
121
    std::vector<std::pair<Geom::Point, int> > _bbox_points; // the bbox point of the selection as a whole, i.e. max. 4 corners plus optionally some midpoints
 
122
    std::vector<std::pair<Geom::Point, int> > _bbox_points_for_translating; // the bbox points of each selected item, only to be used for translating
 
123
 
143
124
    Inkscape::SelCue _selcue;
144
125
 
145
126
    Inkscape::Selection *_selection;
154
135
    SPItem::BBoxType _snap_bbox_type;
155
136
 
156
137
    Geom::OptRect _bbox;
157
 
    Geom::OptRect _visual_bbox;
 
138
    Geom::OptRect _approximate_bbox;
158
139
    Geom::OptRect _geometric_bbox;
159
 
    double _strokewidth;
 
140
    gdouble _strokewidth;
160
141
 
161
 
    Geom::Affine _current_relative_affine;
162
 
    Geom::Affine _absolute_affine;
163
 
    Geom::Affine _relative_affine;
 
142
    Geom::Matrix _current_relative_affine;
 
143
    Geom::Matrix _absolute_affine;
 
144
    Geom::Matrix _relative_affine;
164
145
    /* According to Merriam - Webster's online dictionary
165
146
     * Affine: a transformation (as a translation, a rotation, or a uniform stretching) that carries straight
166
147
     * lines into straight lines and parallel lines into parallel lines but may alter distance between points
173
154
    Geom::Point _origin_for_specpoints;
174
155
    Geom::Point _origin_for_bboxpoints;
175
156
 
176
 
    double _handle_x;
177
 
    double _handle_y;
 
157
    gdouble _handle_x;
 
158
    gdouble _handle_y;
178
159
 
179
160
    boost::optional<Geom::Point> _center;
180
161
    bool _center_is_set; ///< we've already set _center, no need to reread it from items
181
 
    int  _center_handle;
182
162
 
183
 
    SPKnot *knots[NUMHANDS];
 
163
    SPKnot *_shandle[8];
 
164
    SPKnot *_rhandle[8];
 
165
    SPKnot *_chandle;
184
166
    SPCanvasItem *_norm;
185
167
    SPCanvasItem *_grip;
186
 
    SPCtrlLine *_l[4];
187
 
    unsigned int _sel_changed_id;
188
 
    unsigned int _sel_modified_id;
189
 
    std::vector<SPItem*> _stamp_cache;
 
168
    SPCanvasItem *_l[4];
 
169
    guint _sel_changed_id;
 
170
    guint _sel_modified_id;
 
171
    GSList *_stamp_cache;
190
172
 
191
173
    Geom::Point _origin; ///< position of origin for transforms
192
174
    Geom::Point _point; ///< original position of the knot being used for the current transform
194
176
    Inkscape::MessageContext _message_context;
195
177
    sigc::connection _sel_changed_connection;
196
178
    sigc::connection _sel_modified_connection;
197
 
    BoundingBoxPrefsObserver _bounding_box_prefs_observer;
198
179
};
199
180
 
200
181
}
201
182
 
202
 
#endif // SEEN_SELTRANS_H
 
183
#endif
203
184
 
204
185
 
205
186
/*