Code

Split SPCanvasItem and SPCanvasGroup to individual .h files. Removed forward header.
[inkscape.git] / src / knot.h
1 #ifndef __SP_KNOT_H__
2 #define __SP_KNOT_H__
4 /** \file
5  * Declarations for SPKnot: Desktop-bound visual control object.
6  */
7 /*
8  * Authors:
9  *   Lauris Kaplinski <lauris@kaplinski.com>
10  *
11  * Copyright (C) 1999-2002 authors
12  * Copyright (C) 2001-2002 Ximian, Inc.
13  *
14  * Released under GNU GPL, read the file 'COPYING' for more information
15  */
17 #include <gdk/gdk.h>
18 #include <gtk/gtkenums.h>
19 #include "forward.h"
20 #include <2geom/point.h>
21 #include "knot-enums.h"
22 #include <sigc++/sigc++.h>
24 class SPKnot;
25 class SPKnotClass;
26 struct SPCanvasItem;
28 #define SP_TYPE_KNOT            (sp_knot_get_type())
29 #define SP_KNOT(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), SP_TYPE_KNOT, SPKnot))
30 #define SP_KNOT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), SP_TYPE_KNOT, SPKnotClass))
31 #define SP_IS_KNOT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_KNOT))
32 #define SP_IS_KNOT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_KNOT))
34 /**
35  * Desktop-bound visual control object.
36  *
37  * A knot is a draggable object, with callbacks to change something by
38  * dragging it, visuably represented by a canvas item (mostly square).
39  */
40 struct SPKnot : GObject {
41     SPDesktop *desktop;   /**< Desktop we are on. */
42     SPCanvasItem *item;   /**< Our CanvasItem. */
43     guint flags;
45     guint size;      /**< Always square. */
46     Geom::Point pos;   /**< Our desktop coordinates. */
47     Geom::Point grabbed_rel_pos;  /**< Grabbed relative position. */
48     Geom::Point drag_origin;      /**< Origin of drag. */
49     GtkAnchorType anchor;    /**< Anchor. */
51     SPKnotShapeType shape;   /**< Shape type. */
52     SPKnotModeType mode;
54     guint32 fill[SP_KNOT_VISIBLE_STATES];
55     guint32 stroke[SP_KNOT_VISIBLE_STATES];
56     guchar *image[SP_KNOT_VISIBLE_STATES];
58     GdkCursor *cursor[SP_KNOT_VISIBLE_STATES];
60     GdkCursor *saved_cursor;
61     gpointer pixbuf;
63     gchar *tip;
65     gulong _event_handler_id;
67     double pressure; /**< The tablet pen pressure when the knot is being dragged. */
69     // C++ signals
70     /**
71     sigc::signal<void, Geom::Point const &, Geom::Point const &, guint> _moved_signal;
72     sigc::signal<void, guint> _click_signal;
73     sigc::signal<Geom::Point> _ungrabbed_signal;
74     **/
75     sigc::signal<void, SPKnot *, Geom::Point const &, guint> _moved_signal;
76     sigc::signal<void, SPKnot *, guint> _click_signal;
77     sigc::signal<void, SPKnot *> _ungrabbed_signal;
79     //TODO: all the members above should eventualle become private, accessible via setters/getters
80     inline void setSize (guint i) {size = i;}
81     inline void setShape (guint i) {shape = (SPKnotShapeType) i;}
82     inline void setAnchor (guint i) {anchor = (GtkAnchorType) i;}
83     inline void setMode (guint i) {mode = (SPKnotModeType) i;}
84     inline void setPixbuf (gpointer p) {pixbuf = p;}
85     inline void setFill (guint32 normal, guint32 mouseover, guint32 dragging) {
86         fill[SP_KNOT_STATE_NORMAL] = normal;
87         fill[SP_KNOT_STATE_MOUSEOVER] = mouseover;
88         fill[SP_KNOT_STATE_DRAGGING] = dragging;
89     }
90     inline void setStroke (guint32 normal, guint32 mouseover, guint32 dragging) {
91         stroke[SP_KNOT_STATE_NORMAL] = normal;
92         stroke[SP_KNOT_STATE_MOUSEOVER] = mouseover;
93         stroke[SP_KNOT_STATE_DRAGGING] = dragging;
94     }
95     inline void setImage (guchar* normal, guchar* mouseover, guchar* dragging) {
96         image[SP_KNOT_STATE_NORMAL] = normal;
97         image[SP_KNOT_STATE_MOUSEOVER] = mouseover;
98         image[SP_KNOT_STATE_DRAGGING] = dragging;
99     }
100     inline void setCursor (GdkCursor* normal, GdkCursor* mouseover, GdkCursor* dragging) {
101         if (cursor[SP_KNOT_STATE_NORMAL]) {
102             gdk_cursor_unref(cursor[SP_KNOT_STATE_NORMAL]);
103         }
104         cursor[SP_KNOT_STATE_NORMAL] = normal;
105         if (normal) {
106             gdk_cursor_ref(normal);
107         }
109         if (cursor[SP_KNOT_STATE_MOUSEOVER]) {
110             gdk_cursor_unref(cursor[SP_KNOT_STATE_MOUSEOVER]);
111         }
112         cursor[SP_KNOT_STATE_MOUSEOVER] = mouseover;
113         if (mouseover) {
114             gdk_cursor_ref(mouseover);
115         }
117         if (cursor[SP_KNOT_STATE_DRAGGING]) {
118             gdk_cursor_unref(cursor[SP_KNOT_STATE_DRAGGING]);
119         }
120         cursor[SP_KNOT_STATE_DRAGGING] = dragging;
121         if (dragging) {
122             gdk_cursor_ref(dragging);
123         }
124     }
126 };
128 /// The SPKnot vtable.
129 struct SPKnotClass {
130     GObjectClass parent_class;
131     gint (* event) (SPKnot *knot, GdkEvent *event);
133     /*
134      * These are unconditional.
135      */
137     void (* clicked) (SPKnot *knot, guint state);
138     void (* doubleclicked) (SPKnot *knot, guint state);
139     void (* grabbed) (SPKnot *knot, guint state);
140     void (* ungrabbed) (SPKnot *knot, guint state);
141     void (* moved) (SPKnot *knot, Geom::Point const &position, guint state);
142     void (* stamped) (SPKnot *know, guint state);
144     /** Request knot to move to absolute position. */
145     bool (* request) (SPKnot *knot, Geom::Point const &pos, guint state);
147     /** Find complex distance from knot to point. */
148     gdouble (* distance) (SPKnot *knot, Geom::Point const &pos, guint state);
149 };
151 GType sp_knot_get_type();
153 SPKnot *sp_knot_new(SPDesktop *desktop, gchar const *tip = NULL);
155 #define SP_KNOT_IS_VISIBLE(k) ((k->flags & SP_KNOT_VISIBLE) != 0)
156 #define SP_KNOT_IS_MOUSEOVER(k) ((k->flags & SP_KNOT_MOUSEOVER) != 0)
157 #define SP_KNOT_IS_DRAGGING(k) ((k->flags & SP_KNOT_DRAGGING) != 0)
158 #define SP_KNOT_IS_GRABBED(k) ((k->flags & SP_KNOT_GRABBED) != 0)
160 void sp_knot_show(SPKnot *knot);
161 void sp_knot_hide(SPKnot *knot);
163 void sp_knot_set_flag(SPKnot *knot, guint flag, bool set);
164 void sp_knot_update_ctrl(SPKnot *knot);
166 void sp_knot_request_position(SPKnot *knot, Geom::Point const &pos, guint state);
167 gdouble sp_knot_distance(SPKnot *knot, Geom::Point const &p, guint state);
169 void sp_knot_start_dragging(SPKnot *knot, Geom::Point const &p, gint x, gint y, guint32 etime);
171 /** Moves knot and emits "moved" signal. */
172 void sp_knot_set_position(SPKnot *knot, Geom::Point const &p, guint state);
174 /** Moves knot without any signal. */
175 void sp_knot_moveto(SPKnot *knot, Geom::Point const &p);
177 void sp_knot_handler_request_position(GdkEvent *event, SPKnot *knot);
178 Geom::Point sp_knot_position(SPKnot const *knot);
181 #endif /* !__SP_KNOT_H__ */
183 /*
184   Local Variables:
185   mode:c++
186   c-file-style:"stroustrup"
187   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
188   indent-tabs-mode:nil
189   fill-column:99
190   End:
191 */
192 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :