Code

hasSelection method
[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);}
110                 bool hasSelection() {return (selected != NULL);}
112     // especially the selection must be private, fix gradient-context to remove direct access to it
113     GList *selected; // list of GrDragger*
114     void setSelected (GrDragger *dragger, bool add_to_selection = false, bool override = true);
115     void setDeselected (GrDragger *dragger);
116     void deselectAll();
117                 void selectAll();
118                 void selectByCoords(std::vector<NR::Point> coords);
119     
120     void deleteSelected (bool just_one = false);
121     
122     bool keep_selection;    
123     
124     GrDragger *getDraggerFor (SPItem *item, gint point_type, gint point_i, bool fill_or_stroke);
126     void grabKnot (SPItem *item, gint point_type, gint point_i, bool fill_or_stroke, gint x, gint y, guint32 etime);
128     bool local_change;
130     SPDesktop *desktop;
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_nowrite (double x, double y, bool scale_radial);
144     void selected_move (double x, double y, bool write_repr = true, bool scale_radial = false);
145     void selected_move_screen (double x, double y);
147     void select_next ();
148     void select_prev ();
150     void selected_reverse_vector ();
152 private: 
153     void deselect_all();
155     void addLine (NR::Point p1, NR::Point p2, guint32 rgba);
157     void addDragger (GrDraggable *draggable);
159     void addDraggersRadial (SPRadialGradient *rg, SPItem *item, bool fill_or_stroke);
160     void addDraggersLinear (SPLinearGradient *lg, SPItem *item, bool fill_or_stroke);
162     Inkscape::Selection *selection;
163     sigc::connection sel_changed_connection;
164     sigc::connection sel_modified_connection;
166     sigc::connection style_set_connection;
167     sigc::connection style_query_connection;
168 };
170 #endif