Code

make win32 compile using libxslt
[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  *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
10  *
11  * Copyright (C) 2007 Johan Engelen
12  * Copyright (C) 2005 Authors
13  *
14  * Released under GNU GPL, read the file 'COPYING' for more information
15  */
17 #include <glib/gslist.h>
18 #include <sigc++/sigc++.h>
19 #include <vector>
21 #include <forward.h>
22 #include <knot-enums.h>
24 struct SPItem;
25 struct SPKnot;
26 namespace NR {
27 class Point;
28 }
30 /**
31 This class represents a single draggable point of a gradient. It remembers the item
32 which has the gradient, whether it's fill or stroke, the point type (from the
33 GrPointType enum), and the point number (needed if more than 2 stops are present).
34 */
35 struct GrDraggable {
36         GrDraggable(SPItem *item, guint point_type, guint point_i, bool fill_or_stroke);
37         ~GrDraggable();
39         SPItem *item;
40         guint point_type;
41         guint point_i;  // the stop number of this point ( = 0 for all types except POINT_LG_MID)
42         bool fill_or_stroke;
44         bool mayMerge (GrDraggable *da2);
46     inline int equals (GrDraggable *other) {
47                 return ((item == other->item) && (point_type == other->point_type) && (point_i == other->point_i) && (fill_or_stroke == other->fill_or_stroke));
48     }
49 };
51 class GrDrag;
53 /**
54 This class holds together a visible on-canvas knot and a list of draggables that need to
55 be moved when the knot moves. Normally there's one draggable in the list, but there may
56 be more when draggers are snapped together.
57 */
58 struct GrDragger {
59         GrDragger (GrDrag *parent, NR::Point p, GrDraggable *draggable);
60         ~GrDragger();
62         GrDrag *parent;
64         SPKnot *knot;
66         // position of the knot, desktop coords
67         NR::Point point;
68         // position of the knot before it began to drag; updated when released
69         NR::Point point_original;
71         /** Connection to \a knot's "moved" signal, for blocking it (unused?). */
72         guint   handler_id;
74         GSList *draggables;
76         void addDraggable(GrDraggable *draggable);
78         void updateKnotShape();
79         void updateTip();
80         
81         void select();
82         void deselect();
84         void moveThisToDraggable (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke, bool write_repr);
85         void moveOtherToDraggable (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke, bool write_repr);
86     void updateMidstopDependencies (GrDraggable *draggable, bool write_repr);
87     void updateDependencies (bool write_repr);
89         bool mayMerge (GrDragger *other);
90         bool mayMerge (GrDraggable *da2);
92         bool isA (guint point_type);
93         bool isA (SPItem *item, guint point_type, guint point_i, bool fill_or_stroke);
95         void fireDraggables (bool write_repr, bool scale_radial = false, bool merging_focus = false);
96 };
98 /**
99 This is the root class of the gradient dragging machinery. It holds lists of GrDraggers
100 and of lines (simple canvas items). It also remembers one of the draggers as selected.
101 */
102 class GrDrag {
103 public: // FIXME: make more of this private!
105     GrDrag(SPDesktop *desktop);
106     ~GrDrag();
108     // especially the selection must be private, fix gradient-context to remove direct access to it
109     GList *selected; // list of GrDragger*
110     void setSelected (GrDragger *dragger, bool add_to_selection = false, bool override = true);
111     void setDeselected (GrDragger *dragger);
112     void deselectAll();
113     
114     void deleteSelected (bool just_one = false);
115     
116     bool keep_selection;    
117     
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;
126     // lists of edges of selection bboxes, to snap draggers to
127     std::vector<double> hor_levels;
128     std::vector<double> vert_levels;
130     GList *draggers;
131     GSList *lines;
133     void updateDraggers ();
134     void updateLines ();
135     void updateLevels ();
137     void selected_move (double x, double y);
138     void selected_move_screen (double x, double y);
140     void select_next ();
141     void select_prev ();
143     void selected_reverse_vector ();
145 private: 
146     void deselect_all();
148     void addLine (NR::Point p1, NR::Point p2, guint32 rgba);
150     void addDragger (GrDraggable *draggable);
152     void addDraggersRadial (SPRadialGradient *rg, SPItem *item, bool fill_or_stroke);
153     void addDraggersLinear (SPLinearGradient *lg, SPItem *item, bool fill_or_stroke);
155     Inkscape::Selection *selection;
156     sigc::connection sel_changed_connection;
157     sigc::connection sel_modified_connection;
159     sigc::connection style_set_connection;
160     sigc::connection style_query_connection;
161 };
163 #endif