Code

* knot.h, knot.cpp, connector-context.cpp:
[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 "display/display-forward.h"
20 #include "forward.h"
21 #include <libnr/nr-point.h>
22 #include "knot-enums.h"
24 class SPKnot;
25 class SPKnotClass;
27 #define SP_TYPE_KNOT            (sp_knot_get_type())
28 #define SP_KNOT(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), SP_TYPE_KNOT, SPKnot))
29 #define SP_KNOT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), SP_TYPE_KNOT, SPKnotClass))
30 #define SP_IS_KNOT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_KNOT))
31 #define SP_IS_KNOT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_KNOT))
33 /**
34  * Desktop-bound visual control object.
35  * 
36  * A knot is a draggable object, with callbacks to change something by
37  * dragging it, visuably represented by a canvas item (mostly square).
38  */
39 struct SPKnot : GObject {
40     SPDesktop *desktop;   /**< Desktop we are on. */
41     SPCanvasItem *item;   /**< Our CanvasItem. */
42     guint flags;
44     guint size;      /**< Always square. */
45     NR::Point pos;   /**< Our desktop coordinates. */
46     NR::Point grabbed_rel_pos;  /**< Grabbed relative position. */
47     NR::Point drag_origin;      /**< Origin of drag. */
48     GtkAnchorType anchor;    /**< Anchor. */
50     SPKnotShapeType shape;   /**< Shape type. */
51     SPKnotModeType mode;
53     guint32 fill[SP_KNOT_VISIBLE_STATES];
54     guint32 stroke[SP_KNOT_VISIBLE_STATES];
55     guchar *image[SP_KNOT_VISIBLE_STATES];
57     GdkCursor *cursor[SP_KNOT_VISIBLE_STATES];
59     GdkCursor *saved_cursor;
60     gpointer pixbuf;
62     gchar *tip;
64     gulong _event_handler_id;
66     //TODO: all the members above should eventualle become private, accessible via setters/getters
67     inline void setSize (guint i) {size = i;}
68     inline void setShape (guint i) {shape = (SPKnotShapeType) i;}
69     inline void setAnchor (guint i) {anchor = (GtkAnchorType) i;}
70     inline void setMode (guint i) {mode = (SPKnotModeType) i;}
71     inline void setPixbuf (gpointer p) {pixbuf = p;}
72     inline void setFill (guint32 normal, guint32 mouseover, guint32 dragging) {
73         fill[SP_KNOT_STATE_NORMAL] = normal;
74         fill[SP_KNOT_STATE_MOUSEOVER] = mouseover;
75         fill[SP_KNOT_STATE_DRAGGING] = dragging;
76     }
77     inline void setStroke (guint32 normal, guint32 mouseover, guint32 dragging) {
78         stroke[SP_KNOT_STATE_NORMAL] = normal;
79         stroke[SP_KNOT_STATE_MOUSEOVER] = mouseover;
80         stroke[SP_KNOT_STATE_DRAGGING] = dragging;
81     }
82     inline void setImage (guchar* normal, guchar* mouseover, guchar* dragging) {
83         image[SP_KNOT_STATE_NORMAL] = normal;
84         image[SP_KNOT_STATE_MOUSEOVER] = mouseover;
85         image[SP_KNOT_STATE_DRAGGING] = dragging;
86     }
87     inline void setCursor (GdkCursor* normal, GdkCursor* mouseover, GdkCursor* dragging) {
88         if (cursor[SP_KNOT_STATE_NORMAL]) {
89             gdk_cursor_unref(cursor[SP_KNOT_STATE_NORMAL]);
90         }
91         cursor[SP_KNOT_STATE_NORMAL] = normal;
92         if (normal) {
93             gdk_cursor_ref(normal);
94         }
96         if (cursor[SP_KNOT_STATE_MOUSEOVER]) {
97             gdk_cursor_unref(cursor[SP_KNOT_STATE_MOUSEOVER]);
98         }
99         cursor[SP_KNOT_STATE_MOUSEOVER] = mouseover;
100         if (mouseover) {
101             gdk_cursor_ref(mouseover);
102         }
104         if (cursor[SP_KNOT_STATE_DRAGGING]) {
105             gdk_cursor_unref(cursor[SP_KNOT_STATE_DRAGGING]);
106         }
107         cursor[SP_KNOT_STATE_DRAGGING] = dragging;
108         if (dragging) {
109             gdk_cursor_ref(dragging);
110         }
111     }
113 };
115 /// The SPKnot vtable.
116 struct SPKnotClass {
117     GObjectClass parent_class;
118     gint (* event) (SPKnot *knot, GdkEvent *event);
120     /*
121      * These are unconditional.
122      */
124     void (* clicked) (SPKnot *knot, guint state);
125     void (* doubleclicked) (SPKnot *knot, guint state);
126     void (* grabbed) (SPKnot *knot, guint state);
127     void (* ungrabbed) (SPKnot *knot, guint state);
128     void (* moved) (SPKnot *knot, NR::Point *position, guint state);
129     void (* stamped) (SPKnot *know, guint state);
131     /** Request knot to move to absolute position. */
132     bool (* request) (SPKnot *knot, NR::Point *pos, guint state);
134     /** Find complex distance from knot to point. */
135     gdouble (* distance) (SPKnot *knot, NR::Point *pos, guint state);
136 };
138 GType sp_knot_get_type();
140 SPKnot *sp_knot_new(SPDesktop *desktop, gchar const *tip = NULL);
142 #define SP_KNOT_IS_VISIBLE(k) ((k->flags & SP_KNOT_VISIBLE) != 0)
143 #define SP_KNOT_IS_MOUSEOVER(k) ((k->flags & SP_KNOT_MOUSEOVER) != 0)
144 #define SP_KNOT_IS_DRAGGING(k) ((k->flags & SP_KNOT_DRAGGING) != 0)
145 #define SP_KNOT_IS_GRABBED(k) ((k->flags & SP_KNOT_GRABBED) != 0)
147 void sp_knot_show(SPKnot *knot);
148 void sp_knot_hide(SPKnot *knot);
150 void sp_knot_set_flag(SPKnot *knot, guint flag, bool set);
151 void sp_knot_update_ctrl(SPKnot *knot);
153 void sp_knot_request_position(SPKnot *knot, NR::Point *pos, guint state);
154 gdouble sp_knot_distance(SPKnot *knot, NR::Point *p, guint state);
156 void sp_knot_start_dragging(SPKnot *knot, NR::Point p, gint x, gint y, guint32 etime);
158 /** Moves knot and emits "moved" signal. */
159 void sp_knot_set_position(SPKnot *knot, NR::Point *p, guint state);
161 /** Moves knot without any signal. */
162 void sp_knot_moveto(SPKnot *knot, NR::Point *p);
164 NR::Point sp_knot_position(SPKnot const *knot);
167 #endif /* !__SP_KNOT_H__ */
169 /*
170   Local Variables:
171   mode:c++
172   c-file-style:"stroustrup"
173   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
174   indent-tabs-mode:nil
175   fill-column:99
176   End:
177 */
178 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :