c66aba1698f7fbc6c79309fc832390440578255a
1 #ifndef __GRADIENT_DRAG_H__
2 #define __GRADIENT_DRAG_H__
4 /*
5 * On-canvas gradient dragging
6 *
7 * Authors:
8 * bulia byak <bulia@users.sf.net>
9 *
10 * Copyright (C) 2005 Authors
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information
13 */
15 #include <glib/gslist.h>
16 #include <sigc++/sigc++.h>
17 #include <vector>
19 #include <forward.h>
20 #include <knot-enums.h>
22 struct SPItem;
23 struct SPKnot;
24 namespace NR {
25 class Point;
26 }
28 /**
29 This class represents a single draggable point of a gradient. It remembers the item
30 which has the gradient, whether it's fill or stroke, the point type (from the
31 GrPointType enum), and the point number (needed if more than 2 stops are present).
32 */
33 struct GrDraggable {
34 GrDraggable(SPItem *item, guint point_type, guint point_i, bool fill_or_stroke);
35 ~GrDraggable();
37 SPItem *item;
38 guint point_type;
39 guint point_i; // the stop number of this point ( = 0 for all types except POINT_LG_MID)
40 bool fill_or_stroke;
42 bool mayMerge (GrDraggable *da2);
44 inline int equals (GrDraggable *other) {
45 return ((item == other->item) && (point_type == other->point_type) && (point_i == other->point_i) && (fill_or_stroke == other->fill_or_stroke));
46 }
47 };
49 struct GrDrag;
51 /**
52 This class holds together a visible on-canvas knot and a list of draggables that need to
53 be moved when the knot moves. Normally there's one draggable in the list, but there may
54 be more when draggers are snapped together.
55 */
56 struct GrDragger {
57 GrDragger (GrDrag *parent, NR::Point p, GrDraggable *draggable);
58 ~GrDragger();
60 GrDrag *parent;
62 SPKnot *knot;
64 // position of the knot, desktop coords
65 NR::Point point;
66 // position of the knot before it began to drag; updated when released
67 NR::Point point_original;
69 /** Connection to \a knot's "moved" signal, for blocking it (unused?). */
70 guint handler_id;
72 GSList *draggables;
74 void addDraggable(GrDraggable *draggable);
76 void updateKnotShape();
77 void updateTip();
79 void select();
80 void deselect();
82 void moveThisToDraggable (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke, bool write_repr);
83 void moveOtherToDraggable (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke, bool write_repr);
84 void updateMidstopDependencies (GrDraggable *draggable, bool write_repr);
85 void updateDependencies (bool write_repr);
87 bool mayMerge (GrDragger *other);
88 bool mayMerge (GrDraggable *da2);
90 bool isA (guint point_type);
91 bool isA (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke);
93 void fireDraggables (bool write_repr, bool scale_radial = false, bool merging_focus = false);
94 };
96 /**
97 This is the root class of the gradient dragging machinery. It holds lists of GrDraggers
98 and of lines (simple canvas items). It also remembers one of the draggers as selected.
99 */
100 struct GrDrag {
101 GrDrag(SPDesktop *desktop);
102 ~GrDrag();
104 void addLine (NR::Point p1, NR::Point p2, guint32 rgba);
106 void addDragger (GrDraggable *draggable);
108 void addDraggersRadial (SPRadialGradient *rg, SPItem *item, bool fill_or_stroke);
109 void addDraggersLinear (SPLinearGradient *lg, SPItem *item, bool fill_or_stroke);
111 GList *selected; // list of GrDragger*
112 void setSelected (GrDragger *dragger, bool add_to_selection = false, bool override = true);
113 void setDeselected (GrDragger *dragger);
114 void deselect_all();
116 bool keep_selection;
118 GrDragger *getDraggerFor (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke);
120 void grabKnot (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke, gint x, gint y, guint32 etime);
122 bool local_change;
124 SPDesktop *desktop;
125 Inkscape::Selection *selection;
126 sigc::connection sel_changed_connection;
127 sigc::connection sel_modified_connection;
129 sigc::connection style_set_connection;
130 sigc::connection style_query_connection;
132 // lists of edges of selection bboxes, to snap draggers to
133 std::vector<double> hor_levels;
134 std::vector<double> vert_levels;
136 GList *draggers;
137 GSList *lines;
139 void updateDraggers ();
140 void updateLines ();
141 void updateLevels ();
143 void selected_move (double x, double y);
144 void selected_move_screen (double x, double y);
146 void select_next ();
147 void select_prev ();
149 void selected_reverse_vector ();
150 };
152 #endif