Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
seltrans.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifndef SEEN_SELTRANS_H
3#define SEEN_SELTRANS_H
4
5/*
6 * Helper object for transforming selected items
7 *
8 * Authors:
9 * Lauris Kaplinski <lauris@kaplinski.com>
10 * Carl Hetherington <inkscape@carlh.net>
11 * Diederik van Lierop <mail@diedenrezi.nl>
12 *
13 * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
14 * Copyright (C) 1999-2002 Lauris Kaplinski
15 *
16 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
17 */
18
19#include <array>
20#include <vector>
21#include <2geom/point.h>
22#include <2geom/affine.h>
23#include <2geom/rect.h>
24#include <cstddef>
25#include <sigc++/sigc++.h>
26
27#include "message-context.h"
28#include "seltrans-handles.h"
29#include "selcue.h"
30
31#include "object/sp-item.h"
32#include "ui/knot/knot.h"
33
34class SPDesktop;
35struct SPCanvasItem;
36struct SPSelTransHandle;
37
38namespace Inkscape {
39
40class CanvasItemCtrl;
41class CanvasItemCurve;
42
43Geom::Scale calcScaleFactors(Geom::Point const &initial_point, Geom::Point const &new_point, Geom::Point const &origin, bool const skew = false);
44
45namespace XML {
46 class Node;
47}
48
50{
51public:
53 ~SelTrans();
54
55 void increaseState();
56 void resetState();
57 void setCenter(Geom::Point const &p);
58 void grab(Geom::Point const &p, double x, double y, bool show_handles, bool translating);
59 void transform(Geom::Affine const &rel_affine, Geom::Point const &norm);
60 void ungrab();
61 void stamp(bool clone = false);
62 void moveTo(Geom::Point const &xy, unsigned int state);
63 void stretch(SPSelTransHandle const &handle, Geom::Point &pt, unsigned int state);
64 void scale(Geom::Point &pt, unsigned int state);
65 void skew(SPSelTransHandle const &handle, Geom::Point &pt, unsigned int state);
66 void rotate(Geom::Point &pt, unsigned int state);
67 void align(guint state, SPSelTransHandle const &handle);
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);
74
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);
79
85
86 void setShow(Show s) {
87 _show = s;
88 }
89 bool isEmpty() {
90 return _empty;
91 }
92 bool isGrabbed() {
93 return _grabbed;
94 }
96 return ( knots[0]->is_visible());
97 }
98
99 void getNextClosestPoint(bool reverse);
100
101private:
103 {
104 public:
106
107 void notify(Preferences::Entry const &val) override;
108
109 private:
111 };
112
114 void _clear_stamp();
115 void _updateHandles();
117 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);
122 Geom::Point _getGeomHandlePos(Geom::Point const &visual_handle_pos);
123 Geom::Point _calcAbsAffineDefault(Geom::Scale const default_scale);
125 void _keepClosestPointOnly(Geom::Point const &p);
126
127 enum State {
128 STATE_SCALE, //scale or stretch
129 STATE_ROTATE, //rotate or skew
130 STATE_ALIGN //on canvas align
131 };
132
134
135 std::vector<SPItem *> _items;
136 std::vector<SPObject const *> _objects_const;
137 std::vector<Geom::Affine> _items_affines;
138 std::vector<Geom::Point> _items_centers;
139
140 std::vector<Inkscape::SnapCandidatePoint> _snap_points;
141 std::vector<Inkscape::SnapCandidatePoint> _bbox_points;
142 std::vector<Inkscape::SnapCandidatePoint> _all_snap_sources_sorted;
143 std::vector<Inkscape::SnapCandidatePoint>::iterator _all_snap_sources_iter;
145
149
150 bool _grabbed = false;
151 bool _show_handles = true;
152 bool _empty;
154
156
161
165 /* According to Merriam - Webster's online dictionary
166 * Affine: a transformation (as a translation, a rotation, or a uniform stretching) that carries straight
167 * lines into straight lines and parallel lines into parallel lines but may alter distance between points
168 * and angles between lines <affine geometry>
169 */
170
176
177 double _handle_x;
178 double _handle_y;
179
180 std::optional<Geom::Point> _center;
182
186 std::array<CanvasItemPtr<CanvasItemCurve>, 4> _l;
187 std::vector<SPItem*> _stamp_cache;
188 bool _stamped = false;
193 sigc::connection _sel_changed_connection;
194 sigc::connection _sel_modified_connection;
196};
197
198}
199
200#endif // SEEN_SELTRANS_H
201
202
203/*
204 Local Variables:
205 mode:c++
206 c-file-style:"stroustrup"
207 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
208 indent-tabs-mode:nil
209 fill-column:99
210 End:
211*/
212// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Cartesian point / 2D vector and related operations.
Point origin
Definition aa.cpp:227
3x3 affine transformation matrix.
std::unique_ptr< T, CanvasItemUnlinkDeleter > CanvasItemPtr
Smart pointer used to hold CanvasItems, like std::unique_ptr.
3x3 matrix representing an affine transformation.
Definition affine.h:70
Axis-aligned rectangle that can be empty.
Definition rect.h:203
Two-dimensional point that doubles as a vector.
Definition point.h:66
Scaling from the origin.
Definition transforms.h:150
A convenience class for working with MessageStacks.
Data type representing a typeless value of a preference.
Base class for preference observers.
Definition preferences.h:82
void notify(Preferences::Entry const &val) override
Notification about a preference change.
Definition seltrans.cpp:99
void moveTo(Geom::Point const &xy, unsigned int state)
SPDesktop * _desktop
Definition seltrans.h:133
std::vector< SPItem * > _items
Definition seltrans.h:135
void align(guint state, SPSelTransHandle const &handle)
Geom::Affine _absolute_affine
Definition seltrans.h:163
std::vector< Inkscape::SnapCandidatePoint > _all_snap_sources_sorted
Definition seltrans.h:142
void handleGrab(SPKnot *knot, unsigned int state, SPSelTransHandle const &handle)
Definition seltrans.cpp:905
void setShow(Show s)
Definition seltrans.h:86
void stretch(SPSelTransHandle const &handle, Geom::Point &pt, unsigned int state)
Geom::OptRect _stroked_bbox
Definition seltrans.h:158
void setCenter(Geom::Point const &p)
Definition seltrans.cpp:220
Geom::Point _getGeomHandlePos(Geom::Point const &visual_handle_pos)
BoundingBoxPrefsObserver _bounding_box_prefs_observer
Definition seltrans.h:195
Geom::Affine _current_relative_affine
Definition seltrans.h:162
std::vector< Geom::Affine > _items_affines
Definition seltrans.h:137
Geom::Point _opposite_for_specpoints
Definition seltrans.h:172
bool _center_is_set
we've already set _center, no need to reread it from items
Definition seltrans.h:181
void rotate(Geom::Point &pt, unsigned int state)
Geom::Point _calcAbsAffineDefault(Geom::Scale const default_scale)
int rotateRequest(Geom::Point &pt, unsigned int state)
Inkscape::Selection * _selection
Definition seltrans.h:146
int handleRequest(SPKnot *knot, Geom::Point *position, unsigned int state, SPSelTransHandle const &handle)
Definition seltrans.cpp:962
CanvasItemPtr< CanvasItemCtrl > _grip
Definition seltrans.h:185
int skewRequest(SPSelTransHandle const &handle, Geom::Point &pt, unsigned int state)
sigc::connection _sel_modified_connection
Definition seltrans.h:194
Geom::Affine _relative_affine
Definition seltrans.h:164
void _boundingBoxPrefsChanged(int prefs_bbox)
Geom::Point _opposite
opposite point to where a scale is taking place
Definition seltrans.h:171
void getNextClosestPoint(bool reverse)
Geom::OptRect _bbox
Definition seltrans.h:157
Geom::Point _point_geom
original position of the knot being used for the current transform
Definition seltrans.h:191
Geom::Point _origin_for_specpoints
Definition seltrans.h:174
sigc::connection _sel_changed_connection
Definition seltrans.h:193
void _showHandles(SPSelTransType type)
Definition seltrans.cpp:741
std::vector< Inkscape::SnapCandidatePoint > _snap_points
Definition seltrans.h:140
SPItem::BBoxType _snap_bbox_type
Definition seltrans.h:155
CanvasItemPtr< CanvasItemCtrl > _norm
Definition seltrans.h:184
Geom::Point _point
original position of the knot being used for the current transform
Definition seltrans.h:190
Geom::Point _origin_for_bboxpoints
Definition seltrans.h:175
std::vector< Inkscape::SnapCandidatePoint > _bbox_points
Definition seltrans.h:141
void skew(SPSelTransHandle const &handle, Geom::Point &pt, unsigned int state)
void _selChanged(Inkscape::Selection *selection)
Definition seltrans.cpp:998
std::vector< SPObject const * > _objects_const
Definition seltrans.h:136
std::vector< Inkscape::SnapCandidatePoint >::iterator _all_snap_sources_iter
Definition seltrans.h:143
Geom::Point _origin
position of origin for transforms
Definition seltrans.h:189
void handleNewEvent(SPKnot *knot, Geom::Point *position, unsigned int state, SPSelTransHandle const &handle)
Definition seltrans.cpp:925
void _updateVolatileState()
Definition seltrans.cpp:719
void _keepClosestPointOnly(Geom::Point const &p)
void handleClick(SPKnot *knot, unsigned int state, SPSelTransHandle const &handle)
Definition seltrans.cpp:867
std::vector< SPItem * > _stamp_cache
Definition seltrans.h:187
Inkscape::SelCue _selcue
Definition seltrans.h:144
std::optional< Geom::Point > _center
Definition seltrans.h:180
SPKnot * knots[NUMHANDS]
Definition seltrans.h:183
void grab(Geom::Point const &p, double x, double y, bool show_handles, bool translating)
Definition seltrans.cpp:235
Geom::Point _opposite_for_bboxpoints
Definition seltrans.h:173
std::vector< Geom::Point > _items_centers
Definition seltrans.h:138
Geom::OptRect _geometric_bbox
Definition seltrans.h:159
void scale(Geom::Point &pt, unsigned int state)
Geom::Point _calcAbsAffineGeom(Geom::Scale const geom_scale)
void stamp(bool clone=false)
Definition seltrans.cpp:525
int centerRequest(Geom::Point &pt, unsigned int state)
int stretchRequest(SPSelTransHandle const &handle, Geom::Point &pt, unsigned int state)
Inkscape::MessageContext _message_context
Definition seltrans.h:192
bool centerIsVisible()
Definition seltrans.h:95
std::array< CanvasItemPtr< CanvasItemCurve >, 4 > _l
Definition seltrans.h:186
int request(SPSelTransHandle const &handle, Geom::Point &pt, unsigned int state)
void _selModified(Inkscape::Selection *selection, unsigned int flags)
void transform(Geom::Affine const &rel_affine, Geom::Point const &norm)
Definition seltrans.cpp:365
int scaleRequest(Geom::Point &pt, unsigned int state)
The set of selected SPObjects for a given document and layer model.
Definition selection.h:80
To do: update description of desktop.
Definition desktop.h:149
Desktop-bound visual control object.
Definition knot.h:51
Declarations for SPKnot: Desktop-bound visual control object.
Interface for locally managing a current status message.
Helper class to stream background task notifications as a series of messages.
Geom::Scale calcScaleFactors(Geom::Point const &initial_point, Geom::Point const &new_point, Geom::Point const &origin, bool const skew=false)
Axis-aligned rectangle.
int const NUMHANDS
SPSelTransType
Some things pertinent to all visible shapes: SPItem, SPItemView, SPItemCtx.
SPDesktop * desktop