Code

Various snapping cleanups and bug fixes.
[inkscape.git] / src / gradient-drag.h
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, and the point number (from the
31 GrPoint enum).
32 */
33 struct GrDraggable {
34         GrDraggable(SPItem *item, guint point_num, bool fill_or_stroke);
35         ~GrDraggable();
37         SPItem *item;
38         guint point_num;
39         bool fill_or_stroke;
41         bool mayMerge (GrDraggable *da2);
43     inline int equals (GrDraggable *other) {
44                 return ((item == other->item) && (point_num == other->point_num) && (fill_or_stroke == other->fill_or_stroke));
45     }
46 };
48 struct GrDrag;
50 /**
51 This class holds together a visible on-canvas knot and a list of draggables that need to
52 be moved when the knot moves. Normally there's one draggable in the list, but there may
53 be more when draggers are snapped together.
54 */
55 struct GrDragger {
56         GrDragger (GrDrag *parent, NR::Point p, GrDraggable *draggable);
57         ~GrDragger();
59         GrDrag *parent;
61         SPKnot *knot;
63         // position of the knot, desktop coords
64         NR::Point point;
65         // position of the knot before it began to drag; updated when released
66         NR::Point point_original;
68         /** Connection to \a knot's "moved" signal, for blocking it (unused?). */
69         guint   handler_id;
71         GSList *draggables;
73         void addDraggable(GrDraggable *draggable);
75         void updateKnotShape();
76         void updateTip();
78         void moveThisToDraggable (SPItem *item, guint point_num, bool fill_or_stroke, bool write_repr);
79         void moveOtherToDraggable (SPItem *item, guint point_num, bool fill_or_stroke, bool write_repr);
80         void updateDependencies (bool write_repr);
82         bool mayMerge (GrDragger *other);
83         bool mayMerge (GrDraggable *da2);
85         bool isA (guint point_num);
86         bool isA (SPItem *item, guint point_num, bool fill_or_stroke);
88         void fireDraggables (bool write_repr, bool scale_radial = false, bool merging_focus = false);
89 };
91 /**
92 This is the root class of the gradient dragging machinery. It holds lists of GrDraggers
93 and of lines (simple canvas items). It also remembers one of the draggers as selected.
94 */
95 struct GrDrag {
96         GrDrag(SPDesktop *desktop);
97         ~GrDrag();
99         void addLine (NR::Point p1, NR::Point p2, guint32 rgba);
101         void addDragger (GrDraggable *draggable);
103         void addDraggersRadial (SPRadialGradient *rg, SPItem *item, bool fill_or_stroke);
104         void addDraggersLinear (SPLinearGradient *lg, SPItem *item, bool fill_or_stroke);
106         GrDragger *selected;
107         void setSelected (GrDragger *dragger);
109         GrDragger *getDraggerFor (SPItem *item, guint point_num, bool fill_or_stroke);
111         void grabKnot (SPItem *item, guint point_num, bool fill_or_stroke, gint x, gint y, guint32 etime);
113         bool local_change;
115         SPDesktop *desktop;
116         Inkscape::Selection *selection;
117         sigc::connection sel_changed_connection;
118         sigc::connection sel_modified_connection;
120         sigc::connection style_set_connection;
121         sigc::connection style_query_connection;
123         // lists of edges of selection bboxes, to snap draggers to
124         std::vector<double> hor_levels;
125         std::vector<double> vert_levels;
127         GList *draggers;
128         GSList *lines;
130         void updateDraggers ();
131         void updateLines ();
132         void updateLevels ();
134         void selected_move (double x, double y);
135         void selected_move_screen (double x, double y);
137         void select_next ();
138         void select_prev ();
140         void selected_reverse_vector ();
141 };
143 #endif