knot.h revision 6d8430ca47c35cff45dee59e1f9c025567d0af49
1029N/A#ifndef SEEN_SP_KNOT_H
1029N/A#define SEEN_SP_KNOT_H
1407N/A
1029N/A/** \file
246N/A * Declarations for SPKnot: Desktop-bound visual control object.
246N/A */
246N/A/*
281N/A * Authors:
281N/A * Lauris Kaplinski <lauris@kaplinski.com>
246N/A *
131N/A * Copyright (C) 1999-2002 authors
131N/A * Copyright (C) 2001-2002 Ximian, Inc.
131N/A *
131N/A * Released under GNU GPL, read the file 'COPYING' for more information
1086N/A */
131N/A
725N/A#include <gdk/gdk.h>
131N/A#include <2geom/point.h>
758N/A#include "knot-enums.h"
131N/A#include <stddef.h>
131N/A#include <sigc++/sigc++.h>
131N/A#include "enums.h"
131N/A#include <gtk/gtk.h>
500N/A#include "sp-item.h"
131N/A
131N/Aclass SPDesktop;
131N/Aclass SPKnot;
131N/Aclass SPKnotClass;
131N/Astruct SPCanvasItem;
131N/A
131N/A#define SP_TYPE_KNOT (sp_knot_get_type())
144N/A#define SP_KNOT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SP_TYPE_KNOT, SPKnot))
131N/A#define SP_KNOT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SP_TYPE_KNOT, SPKnotClass))
1029N/A#define SP_IS_KNOT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_KNOT))
131N/A#define SP_IS_KNOT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_KNOT))
246N/A
929N/A
1097N/A/**
1456N/A * Desktop-bound visual control object.
1425N/A *
1318N/A * A knot is a draggable object, with callbacks to change something by
1318N/A * dragging it, visuably represented by a canvas item (mostly square).
1318N/A */
1318N/Astruct SPKnot : GObject {
131N/A SPDesktop *desktop; /**< Desktop we are on. */
131N/A SPCanvasItem *item; /**< Our CanvasItem. */
131N/A SPItem *owner; /**< Optional Owner Item */
131N/A guint flags;
131N/A
246N/A guint size; /**< Always square. */
929N/A Geom::Point pos; /**< Our desktop coordinates. */
1097N/A Geom::Point grabbed_rel_pos; /**< Grabbed relative position. */
131N/A Geom::Point drag_origin; /**< Origin of drag. */
340N/A SPAnchorType anchor; /**< Anchor. */
1318N/A
1318N/A SPKnotShapeType shape; /**< Shape type. */
340N/A SPKnotModeType mode;
131N/A
131N/A guint32 fill[SP_KNOT_VISIBLE_STATES];
131N/A guint32 stroke[SP_KNOT_VISIBLE_STATES];
1029N/A guchar *image[SP_KNOT_VISIBLE_STATES];
1029N/A
920N/A GdkCursor *cursor[SP_KNOT_VISIBLE_STATES];
920N/A
131N/A GdkCursor *saved_cursor;
131N/A gpointer pixbuf;
131N/A
214N/A gchar *tip;
214N/A
131N/A gulong _event_handler_id;
131N/A
131N/A double pressure; /**< The tablet pen pressure when the knot is being dragged. */
131N/A
131N/A // C++ signals
131N/A /**
131N/A sigc::signal<void, Geom::Point const &, Geom::Point const &, guint> _moved_signal;
131N/A sigc::signal<void, guint> _click_signal;
131N/A sigc::signal<Geom::Point> _ungrabbed_signal;
131N/A **/
131N/A sigc::signal<void, SPKnot *, Geom::Point const &, guint> _moved_signal;
927N/A sigc::signal<void, SPKnot *, guint> _click_signal;
131N/A sigc::signal<void, SPKnot *> _ungrabbed_signal;
131N/A
131N/A //TODO: all the members above should eventualle become private, accessible via setters/getters
131N/A inline void setSize (guint i) {size = i;}
131N/A inline void setShape (guint i) {shape = (SPKnotShapeType) i;}
131N/A inline void setAnchor (guint i) {anchor = (SPAnchorType) i;}
131N/A inline void setMode (guint i) {mode = (SPKnotModeType) i;}
131N/A inline void setPixbuf (gpointer p) {pixbuf = p;}
1318N/A inline void setFill (guint32 normal, guint32 mouseover, guint32 dragging) {
131N/A fill[SP_KNOT_STATE_NORMAL] = normal;
131N/A fill[SP_KNOT_STATE_MOUSEOVER] = mouseover;
131N/A fill[SP_KNOT_STATE_DRAGGING] = dragging;
131N/A }
131N/A inline void setStroke (guint32 normal, guint32 mouseover, guint32 dragging) {
131N/A stroke[SP_KNOT_STATE_NORMAL] = normal;
131N/A stroke[SP_KNOT_STATE_MOUSEOVER] = mouseover;
1380N/A stroke[SP_KNOT_STATE_DRAGGING] = dragging;
131N/A }
131N/A inline void setImage (guchar* normal, guchar* mouseover, guchar* dragging) {
895N/A image[SP_KNOT_STATE_NORMAL] = normal;
1456N/A image[SP_KNOT_STATE_MOUSEOVER] = mouseover;
1456N/A image[SP_KNOT_STATE_DRAGGING] = dragging;
131N/A }
131N/A inline void setCursor (GdkCursor* normal, GdkCursor* mouseover, GdkCursor* dragging) {
131N/A if (cursor[SP_KNOT_STATE_NORMAL]) {
131N/A#if GTK_CHECK_VERSION(3,0,0)
g_object_unref(cursor[SP_KNOT_STATE_NORMAL]);
#else
gdk_cursor_unref(cursor[SP_KNOT_STATE_NORMAL]);
#endif
}
cursor[SP_KNOT_STATE_NORMAL] = normal;
if (normal) {
#if GTK_CHECK_VERSION(3,0,0)
g_object_ref(normal);
#else
gdk_cursor_ref(normal);
#endif
}
if (cursor[SP_KNOT_STATE_MOUSEOVER]) {
#if GTK_CHECK_VERSION(3,0,0)
g_object_unref(cursor[SP_KNOT_STATE_MOUSEOVER]);
#else
gdk_cursor_unref(cursor[SP_KNOT_STATE_MOUSEOVER]);
#endif
}
cursor[SP_KNOT_STATE_MOUSEOVER] = mouseover;
if (mouseover) {
#if GTK_CHECK_VERSION(3,0,0)
g_object_ref(mouseover);
#else
gdk_cursor_ref(mouseover);
#endif
}
if (cursor[SP_KNOT_STATE_DRAGGING]) {
#if GTK_CHECK_VERSION(3,0,0)
g_object_unref(cursor[SP_KNOT_STATE_DRAGGING]);
#else
gdk_cursor_unref(cursor[SP_KNOT_STATE_DRAGGING]);
#endif
}
cursor[SP_KNOT_STATE_DRAGGING] = dragging;
if (dragging) {
#if GTK_CHECK_VERSION(3,0,0)
g_object_ref(dragging);
#else
gdk_cursor_ref(dragging);
#endif
}
}
};
/// The SPKnot vtable.
struct SPKnotClass {
GObjectClass parent_class;
gint (* event) (SPKnot *knot, GdkEvent *event);
/*
* These are unconditional.
*/
void (* clicked) (SPKnot *knot, guint state);
void (* doubleclicked) (SPKnot *knot, guint state);
void (* grabbed) (SPKnot *knot, guint state);
void (* ungrabbed) (SPKnot *knot, guint state);
void (* moved) (SPKnot *knot, Geom::Point const &position, guint state);
void (* stamped) (SPKnot *know, guint state);
/** Request knot to move to absolute position. */
bool (* request) (SPKnot *knot, Geom::Point const &pos, guint state);
/** Find complex distance from knot to point. */
gdouble (* distance) (SPKnot *knot, Geom::Point const &pos, guint state);
};
/**
* Registers SPKnot class and returns its type number.
*/
GType sp_knot_get_type();
/**
* Return new knot object.
*/
SPKnot *sp_knot_new(SPDesktop *desktop, gchar const *tip = NULL);
#define SP_KNOT_IS_VISIBLE(k) ((k->flags & SP_KNOT_VISIBLE) != 0)
#define SP_KNOT_IS_MOUSEOVER(k) ((k->flags & SP_KNOT_MOUSEOVER) != 0)
#define SP_KNOT_IS_DRAGGING(k) ((k->flags & SP_KNOT_DRAGGING) != 0)
#define SP_KNOT_IS_GRABBED(k) ((k->flags & SP_KNOT_GRABBED) != 0)
/**
* Show knot on its canvas.
*/
void sp_knot_show(SPKnot *knot);
/**
* Hide knot on its canvas.
*/
void sp_knot_hide(SPKnot *knot);
/**
* Set flag in knot, with side effects.
*/
void sp_knot_set_flag(SPKnot *knot, guint flag, bool set);
/**
* Update knot's pixbuf and set its control state.
*/
void sp_knot_update_ctrl(SPKnot *knot);
/**
* Request or set new position for knot.
*/
void sp_knot_request_position(SPKnot *knot, Geom::Point const &pos, guint state);
/**
* Return distance of point to knot's position; unused.
*/
gdouble sp_knot_distance(SPKnot *knot, Geom::Point const &p, guint state);
/**
* Update knot for dragging and tell canvas an item was grabbed.
*/
void sp_knot_start_dragging(SPKnot *knot, Geom::Point const &p, gint x, gint y, guint32 etime);
/**
* Move knot to new position and emits "moved" signal.
*/
void sp_knot_set_position(SPKnot *knot, Geom::Point const &p, guint state);
/**
* Move knot to new position, without emitting a MOVED signal.
*/
void sp_knot_moveto(SPKnot *knot, Geom::Point const &p);
void sp_knot_handler_request_position(GdkEvent *event, SPKnot *knot);
/**
* Returns position of knot.
*/
Geom::Point sp_knot_position(SPKnot const *knot);
#endif // SEEN_SP_KNOT_H
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :