Code

new selection utility methods; refactoring to allow finding grabber without knowing...
[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         gint point_type;
41         gint point_i;  // the stop number of this point ( = 0 POINT_LG_BEGIN and POINT_RG_CENTER)
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();
83         bool isSelected();
85         void moveThisToDraggable (SPItem *item, gint point_type, gint point_i, bool fill_or_stroke, bool write_repr);
86         void moveOtherToDraggable (SPItem *item, gint point_type, gint point_i, bool fill_or_stroke, bool write_repr);
87     void updateMidstopDependencies (GrDraggable *draggable, bool write_repr);
88     void updateDependencies (bool write_repr);
90         bool mayMerge (GrDragger *other);
91         bool mayMerge (GrDraggable *da2);
93         bool isA (gint point_type);
94         bool isA (SPItem *item, gint point_type, gint point_i, bool fill_or_stroke);
96         void fireDraggables (bool write_repr, bool scale_radial = false, bool merging_focus = false);
97 };
99 /**
100 This is the root class of the gradient dragging machinery. It holds lists of GrDraggers
101 and of lines (simple canvas items). It also remembers one of the draggers as selected.
102 */
103 class GrDrag {
104 public: // FIXME: make more of this private!
106     GrDrag(SPDesktop *desktop);
107     ~GrDrag();
109                 bool isNonEmpty() {return (draggers != NULL);}
111     // especially the selection must be private, fix gradient-context to remove direct access to it
112     GList *selected; // list of GrDragger*
113     void setSelected (GrDragger *dragger, bool add_to_selection = false, bool override = true);
114     void setDeselected (GrDragger *dragger);
115     void deselectAll();
116                 void selectAll();
117                 void selectByCoords(std::vector<NR::Point> coords);
118     
119     void deleteSelected (bool just_one = false);
120     
121     bool keep_selection;    
122     
123     GrDragger *getDraggerFor (SPItem *item, gint point_type, gint point_i, bool fill_or_stroke);
125     void grabKnot (SPItem *item, gint point_type, gint point_i, bool fill_or_stroke, gint x, gint y, guint32 etime);
127     bool local_change;
129     SPDesktop *desktop;
131     // lists of edges of selection bboxes, to snap draggers to
132     std::vector<double> hor_levels;
133     std::vector<double> vert_levels;
135     GList *draggers;
136     GSList *lines;
138     void updateDraggers ();
139     void updateLines ();
140     void updateLevels ();
142     void selected_move_nowrite (double x, double y, bool scale_radial);
143     void selected_move (double x, double y, bool write_repr = true, bool scale_radial = false);
144     void selected_move_screen (double x, double y);
146     void select_next ();
147     void select_prev ();
149     void selected_reverse_vector ();
151 private: 
152     void deselect_all();
154     void addLine (NR::Point p1, NR::Point p2, guint32 rgba);
156     void addDragger (GrDraggable *draggable);
158     void addDraggersRadial (SPRadialGradient *rg, SPItem *item, bool fill_or_stroke);
159     void addDraggersLinear (SPLinearGradient *lg, SPItem *item, bool fill_or_stroke);
161     Inkscape::Selection *selection;
162     sigc::connection sel_changed_connection;
163     sigc::connection sel_modified_connection;
165     sigc::connection style_set_connection;
166     sigc::connection style_query_connection;
167 };
169 #endif