~ik5/inkscape/makefile

« back to all changes in this revision

Viewing changes to src/knot.h

  • Committer: Markus Engel
  • Date: 2014-03-27 23:18:25 UTC
  • Revision ID: markus.engel@tum.de-20140327231825-1wrp1kn5d6ritdks
First step of refactoring SPKnot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
class SPDesktop;
27
27
struct SPCanvasItem;
28
28
 
29
 
#define SP_TYPE_KNOT            (sp_knot_get_type())
30
 
#define SP_KNOT(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), SP_TYPE_KNOT, SPKnot))
31
 
#define SP_KNOT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), SP_TYPE_KNOT, SPKnotClass))
32
 
#define SP_IS_KNOT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_KNOT))
33
 
#define SP_IS_KNOT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_KNOT))
 
29
#define SP_KNOT(obj) (dynamic_cast<SPKnot*>(static_cast<SPKnot*>(obj)))
 
30
#define SP_IS_KNOT(obj) (dynamic_cast<const SPKnot*>(static_cast<const SPKnot*>(obj)) != NULL)
34
31
 
35
32
 
36
33
/**
39
36
 * A knot is a draggable object, with callbacks to change something by
40
37
 * dragging it, visuably represented by a canvas item (mostly square).
41
38
 */
42
 
struct SPKnot : GObject {
 
39
class SPKnot {
 
40
public:
 
41
    SPKnot(SPDesktop *desktop, const gchar *tip);
 
42
    virtual ~SPKnot();
 
43
 
 
44
 
 
45
    int ref_count;
 
46
 
 
47
 
43
48
    SPDesktop *desktop;   /**< Desktop we are on. */
44
49
    SPCanvasItem *item;   /**< Our CanvasItem. */
45
50
    SPItem *owner;        /**< Optional Owner Item */
69
74
 
70
75
    double pressure; /**< The tablet pen pressure when the knot is being dragged. */
71
76
 
72
 
    // C++ signals
73
 
    /**
74
 
    sigc::signal<void, Geom::Point const &, Geom::Point const &, guint> _moved_signal;
75
 
    sigc::signal<void, guint> _click_signal;
76
 
    sigc::signal<Geom::Point> _ungrabbed_signal;
77
 
    **/
 
77
    sigc::signal<void, SPKnot *, guint> _click_signal;
 
78
    sigc::signal<void, SPKnot*, guint> _doubleclicked_signal;
 
79
    sigc::signal<void, SPKnot*, guint> _grabbed_signal;
 
80
    sigc::signal<void, SPKnot *, guint> _ungrabbed_signal;
78
81
    sigc::signal<void, SPKnot *, Geom::Point const &, guint> _moved_signal;
79
 
    sigc::signal<void, SPKnot *, guint> _click_signal;
80
 
    sigc::signal<void, SPKnot *> _ungrabbed_signal;
 
82
    sigc::signal<bool, SPKnot*, GdkEvent*> _event_signal;
 
83
 
 
84
    sigc::signal<bool, SPKnot*, Geom::Point*, guint> _request_signal;
 
85
 
81
86
 
82
87
    //TODO: all the members above should eventualle become private, accessible via setters/getters
83
 
    inline void setSize (guint i) {size = i;}
84
 
    inline void setShape (guint i) {shape = (SPKnotShapeType) i;}
85
 
    inline void setAnchor (guint i) {anchor = (SPAnchorType) i;}
86
 
    inline void setMode (guint i) {mode = (SPKnotModeType) i;}
87
 
    inline void setPixbuf (gpointer p) {pixbuf = p;}
88
 
    inline void setFill (guint32 normal, guint32 mouseover, guint32 dragging) {
89
 
        fill[SP_KNOT_STATE_NORMAL] = normal;
90
 
        fill[SP_KNOT_STATE_MOUSEOVER] = mouseover;
91
 
        fill[SP_KNOT_STATE_DRAGGING] = dragging;
92
 
    }
93
 
    inline void setStroke (guint32 normal, guint32 mouseover, guint32 dragging) {
94
 
        stroke[SP_KNOT_STATE_NORMAL] = normal;
95
 
        stroke[SP_KNOT_STATE_MOUSEOVER] = mouseover;
96
 
        stroke[SP_KNOT_STATE_DRAGGING] = dragging;
97
 
    }
98
 
    inline void setImage (guchar* normal, guchar* mouseover, guchar* dragging) {
99
 
        image[SP_KNOT_STATE_NORMAL] = normal;
100
 
        image[SP_KNOT_STATE_MOUSEOVER] = mouseover;
101
 
        image[SP_KNOT_STATE_DRAGGING] = dragging;
102
 
    }
103
 
    inline void setCursor (GdkCursor* normal, GdkCursor* mouseover, GdkCursor* dragging) {
104
 
        if (cursor[SP_KNOT_STATE_NORMAL]) {
105
 
#if GTK_CHECK_VERSION(3,0,0)
106
 
            g_object_unref(cursor[SP_KNOT_STATE_NORMAL]);
107
 
#else
108
 
            gdk_cursor_unref(cursor[SP_KNOT_STATE_NORMAL]);
109
 
#endif
110
 
        }
111
 
        cursor[SP_KNOT_STATE_NORMAL] = normal;
112
 
        if (normal) {
113
 
#if GTK_CHECK_VERSION(3,0,0)
114
 
            g_object_ref(normal);
115
 
#else
116
 
            gdk_cursor_ref(normal);
117
 
#endif
118
 
        }
119
 
 
120
 
        if (cursor[SP_KNOT_STATE_MOUSEOVER]) {
121
 
#if GTK_CHECK_VERSION(3,0,0)
122
 
            g_object_unref(cursor[SP_KNOT_STATE_MOUSEOVER]);
123
 
#else
124
 
            gdk_cursor_unref(cursor[SP_KNOT_STATE_MOUSEOVER]);
125
 
#endif
126
 
        }
127
 
        cursor[SP_KNOT_STATE_MOUSEOVER] = mouseover;
128
 
        if (mouseover) {
129
 
#if GTK_CHECK_VERSION(3,0,0)
130
 
            g_object_ref(mouseover);
131
 
#else
132
 
            gdk_cursor_ref(mouseover);
133
 
#endif
134
 
        }
135
 
 
136
 
        if (cursor[SP_KNOT_STATE_DRAGGING]) {
137
 
#if GTK_CHECK_VERSION(3,0,0)
138
 
            g_object_unref(cursor[SP_KNOT_STATE_DRAGGING]);
139
 
#else
140
 
            gdk_cursor_unref(cursor[SP_KNOT_STATE_DRAGGING]);
141
 
#endif
142
 
        }
143
 
        cursor[SP_KNOT_STATE_DRAGGING] = dragging;
144
 
        if (dragging) {
145
 
#if GTK_CHECK_VERSION(3,0,0)
146
 
            g_object_ref(dragging);
147
 
#else
148
 
            gdk_cursor_ref(dragging);
149
 
#endif
150
 
        }
151
 
    }
152
 
 
153
 
};
154
 
 
155
 
/// The SPKnot vtable.
156
 
struct SPKnotClass {
157
 
    GObjectClass parent_class;
158
 
    gint (* event) (SPKnot *knot, GdkEvent *event);
159
 
 
160
 
    /*
161
 
     * These are unconditional.
162
 
     */
163
 
 
164
 
    void (* clicked) (SPKnot *knot, guint state);
165
 
    void (* doubleclicked) (SPKnot *knot, guint state);
166
 
    void (* grabbed) (SPKnot *knot, guint state);
167
 
    void (* ungrabbed) (SPKnot *knot, guint state);
168
 
    void (* moved) (SPKnot *knot, Geom::Point const &position, guint state);
169
 
    void (* stamped) (SPKnot *know, guint state);
170
 
 
171
 
    /** Request knot to move to absolute position. */
172
 
    bool (* request) (SPKnot *knot, Geom::Point const &pos, guint state);
173
 
 
174
 
    /** Find complex distance from knot to point. */
175
 
    gdouble (* distance) (SPKnot *knot, Geom::Point const &pos, guint state);
176
 
};
177
 
 
178
 
/**
179
 
 * Registers SPKnot class and returns its type number.
180
 
 */
181
 
GType sp_knot_get_type();
182
 
 
183
 
/**
184
 
 * Return new knot object.
185
 
 */
186
 
SPKnot *sp_knot_new(SPDesktop *desktop, gchar const *tip = NULL);
 
88
    void setSize(guint i);
 
89
    void setShape(guint i);
 
90
    void setAnchor(guint i);
 
91
    void setMode(guint i);
 
92
    void setPixbuf(gpointer p);
 
93
 
 
94
    void setFill(guint32 normal, guint32 mouseover, guint32 dragging);
 
95
    void setStroke(guint32 normal, guint32 mouseover, guint32 dragging);
 
96
    void setImage(guchar* normal, guchar* mouseover, guchar* dragging);
 
97
 
 
98
    void setCursor(GdkCursor* normal, GdkCursor* mouseover, GdkCursor* dragging);
 
99
 
 
100
    /**
 
101
     * Show knot on its canvas.
 
102
     */
 
103
    void show();
 
104
 
 
105
    /**
 
106
     * Hide knot on its canvas.
 
107
     */
 
108
    void hide();
 
109
 
 
110
    /**
 
111
     * Set flag in knot, with side effects.
 
112
     */
 
113
    void set_flag(guint flag, bool set);
 
114
 
 
115
    /**
 
116
     * Update knot's pixbuf and set its control state.
 
117
     */
 
118
    void update_ctrl();
 
119
 
 
120
    /**
 
121
     * Request or set new position for knot.
 
122
     */
 
123
    void request_position(Geom::Point const &pos, guint state);
 
124
 
 
125
    /**
 
126
     * Update knot for dragging and tell canvas an item was grabbed.
 
127
     */
 
128
    void start_dragging(Geom::Point const &p, gint x, gint y, guint32 etime);
 
129
 
 
130
    /**
 
131
     * Move knot to new position and emits "moved" signal.
 
132
     */
 
133
    void set_position(Geom::Point const &p, guint state);
 
134
 
 
135
    /**
 
136
     * Move knot to new position, without emitting a MOVED signal.
 
137
     */
 
138
    void moveto(Geom::Point const &p);
 
139
 
 
140
    /**
 
141
     * Returns position of knot.
 
142
     */
 
143
    Geom::Point position() const;
 
144
 
 
145
private:
 
146
    SPKnot(const SPKnot&);
 
147
    SPKnot& operator=(const SPKnot&);
 
148
 
 
149
    /**
 
150
     * Set knot control state (dragging/mouseover/normal).
 
151
     */
 
152
    void set_ctrl_state();
 
153
};
 
154
 
 
155
void knot_ref(SPKnot* knot);
 
156
void knot_unref(SPKnot* knot);
187
157
 
188
158
#define SP_KNOT_IS_VISIBLE(k) ((k->flags & SP_KNOT_VISIBLE) != 0)
189
159
#define SP_KNOT_IS_MOUSEOVER(k) ((k->flags & SP_KNOT_MOUSEOVER) != 0)
190
160
#define SP_KNOT_IS_DRAGGING(k) ((k->flags & SP_KNOT_DRAGGING) != 0)
191
161
#define SP_KNOT_IS_GRABBED(k) ((k->flags & SP_KNOT_GRABBED) != 0)
192
162
 
193
 
/**
194
 
 * Show knot on its canvas.
195
 
 */
196
 
void sp_knot_show(SPKnot *knot);
197
 
 
198
 
/**
199
 
 * Hide knot on its canvas.
200
 
 */
201
 
void sp_knot_hide(SPKnot *knot);
202
 
 
203
 
/**
204
 
 * Set flag in knot, with side effects.
205
 
 */
206
 
void sp_knot_set_flag(SPKnot *knot, guint flag, bool set);
207
 
 
208
 
/**
209
 
 * Update knot's pixbuf and set its control state.
210
 
 */
211
 
void sp_knot_update_ctrl(SPKnot *knot);
212
 
 
213
 
/**
214
 
 * Request or set new position for knot.
215
 
 */
216
 
void sp_knot_request_position(SPKnot *knot, Geom::Point const &pos, guint state);
217
 
 
218
 
/**
219
 
 * Return distance of point to knot's position; unused.
220
 
 */
221
 
gdouble sp_knot_distance(SPKnot *knot, Geom::Point const &p, guint state);
222
 
 
223
 
/**
224
 
 * Update knot for dragging and tell canvas an item was grabbed.
225
 
 */
226
 
void sp_knot_start_dragging(SPKnot *knot, Geom::Point const &p, gint x, gint y, guint32 etime);
227
 
 
228
 
/**
229
 
 * Move knot to new position and emits "moved" signal.
230
 
 */
231
 
void sp_knot_set_position(SPKnot *knot, Geom::Point const &p, guint state);
232
 
 
233
 
/**
234
 
 * Move knot to new position, without emitting a MOVED signal.
235
 
 */
236
 
void sp_knot_moveto(SPKnot *knot, Geom::Point const &p);
237
 
 
238
163
void sp_knot_handler_request_position(GdkEvent *event, SPKnot *knot);
239
164
 
240
 
/**
241
 
 * Returns position of knot.
242
 
 */
243
 
Geom::Point sp_knot_position(SPKnot const *knot);
244
 
 
245
 
 
246
165
#endif // SEEN_SP_KNOT_H
247
166
 
248
167
/*