Code

Gradient nodes progress...
[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, 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 moveThisToDraggable (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke, bool write_repr);
80         void moveOtherToDraggable (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke, bool write_repr);
81         void updateDependencies (bool write_repr);
83         bool mayMerge (GrDragger *other);
84         bool mayMerge (GrDraggable *da2);
86         bool isA (guint point_type);
87         bool isA (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke);
89         void fireDraggables (bool write_repr, bool scale_radial = false, bool merging_focus = false);
90 };
92 /**
93 This is the root class of the gradient dragging machinery. It holds lists of GrDraggers
94 and of lines (simple canvas items). It also remembers one of the draggers as selected.
95 */
96 struct GrDrag {
97         GrDrag(SPDesktop *desktop);
98         ~GrDrag();
100         void addLine (NR::Point p1, NR::Point p2, guint32 rgba);
102         void addDragger (GrDraggable *draggable);
104         void addDraggersRadial (SPRadialGradient *rg, SPItem *item, bool fill_or_stroke);
105         void addDraggersLinear (SPLinearGradient *lg, SPItem *item, bool fill_or_stroke);
107         GrDragger *selected;
108         void setSelected (GrDragger *dragger);
110         GrDragger *getDraggerFor (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke);
112         void grabKnot (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke, gint x, gint y, guint32 etime);
114         bool local_change;
116         SPDesktop *desktop;
117         Inkscape::Selection *selection;
118         sigc::connection sel_changed_connection;
119         sigc::connection sel_modified_connection;
121         sigc::connection style_set_connection;
122         sigc::connection style_query_connection;
124         // lists of edges of selection bboxes, to snap draggers to
125         std::vector<double> hor_levels;
126         std::vector<double> vert_levels;
128         GList *draggers;
129         GSList *lines;
131         void updateDraggers ();
132         void updateLines ();
133         void updateLevels ();
135         void selected_move (double x, double y);
136         void selected_move_screen (double x, double y);
138         void select_next ();
139         void select_prev ();
141         void selected_reverse_vector ();
142 };
144 #endif