summaryrefslogtreecommitdiffstats
path: root/ganv
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-12-09 05:48:35 +0000
committerDavid Robillard <d@drobilla.net>2011-12-09 05:48:35 +0000
commit985d9b8babb2faac0de62cb684fc14c7910e9909 (patch)
treee59ebd3ae5144f503795aadbcbd4fb570c22377e /ganv
parent00df069cdf55e115ea734119c0ba97b78192cfcc (diff)
downloadganv-985d9b8babb2faac0de62cb684fc14c7910e9909.tar.gz
ganv-985d9b8babb2faac0de62cb684fc14c7910e9909.tar.bz2
ganv-985d9b8babb2faac0de62cb684fc14c7910e9909.zip
Remove GnomeCanvas dependency.
git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@3842 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'ganv')
-rw-r--r--ganv/Canvas.hpp4
-rw-r--r--ganv/Circle.hpp4
-rw-r--r--ganv/Edge.hpp7
-rw-r--r--ganv/Item.hpp26
-rw-r--r--ganv/Module.hpp4
-rw-r--r--ganv/Node.hpp4
-rw-r--r--ganv/Port.hpp2
-rw-r--r--ganv/box.h3
-rw-r--r--ganv/canvas-base.h524
-rw-r--r--ganv/canvas.h20
-rw-r--r--ganv/circle.h3
-rw-r--r--ganv/edge.h14
-rw-r--r--ganv/module.h3
-rw-r--r--ganv/node.h9
-rw-r--r--ganv/port.h3
-rw-r--r--ganv/text.h9
-rw-r--r--ganv/types.h1
-rw-r--r--ganv/widget.h63
-rw-r--r--ganv/wrap.hpp6
19 files changed, 638 insertions, 71 deletions
diff --git a/ganv/Canvas.hpp b/ganv/Canvas.hpp
index 7e3c031..0b5a95c 100644
--- a/ganv/Canvas.hpp
+++ b/ganv/Canvas.hpp
@@ -39,7 +39,7 @@ class Port;
/** @defgroup Ganv Ganv
*
- * A generic dataflow widget using libgnomecanvas.
+ * A canvas widget for graph-like UIs.
*/
/** The 'master' canvas widget which contains all other objects.
@@ -135,7 +135,7 @@ public:
GQuark wrapper_key();
- GnomeCanvasGroup* root();
+ GanvGroup* root();
GdkCursor* move_cursor();
diff --git a/ganv/Circle.hpp b/ganv/Circle.hpp
index 73a7eb5..0c3d8e8 100644
--- a/ganv/Circle.hpp
+++ b/ganv/Circle.hpp
@@ -54,8 +54,8 @@ public:
bool show_title)
: Node(&canvas,
GANV_NODE(
- gnome_canvas_item_new(
- GNOME_CANVAS_GROUP(canvas.root()),
+ ganv_item_new(
+ GANV_GROUP(canvas.root()),
ganv_circle_get_type(),
"x", x,
"y", y,
diff --git a/ganv/Edge.hpp b/ganv/Edge.hpp
index 01b5b66..ee2423c 100644
--- a/ganv/Edge.hpp
+++ b/ganv/Edge.hpp
@@ -18,10 +18,9 @@
#include <stdint.h>
-#include <libgnomecanvas/gnome-canvas.h>
-
#include <gdk/gdkevents.h>
+#include "ganv/canvas-base.h"
#include "ganv/Canvas.hpp"
#include "ganv/Item.hpp"
#include "ganv/Node.hpp"
@@ -46,7 +45,7 @@ public:
uint32_t color,
bool show_arrowhead = false,
bool curved = true)
- : Item(GNOME_CANVAS_ITEM(
+ : Item(GANV_ITEM(
g_object_ref(
ganv_edge_new(
canvas.gobj(),
@@ -59,7 +58,7 @@ public:
{}
Edge(GanvEdge* gobj)
- : Item(GNOME_CANVAS_ITEM(g_object_ref(gobj)))
+ : Item(GANV_ITEM(g_object_ref(gobj)))
{}
virtual ~Edge() {
diff --git a/ganv/Item.hpp b/ganv/Item.hpp
index 503aa98..7dacf01 100644
--- a/ganv/Item.hpp
+++ b/ganv/Item.hpp
@@ -19,11 +19,11 @@
#include <assert.h>
#include <glib.h>
-#include <libgnomecanvas/gnome-canvas.h>
#include <sigc++/signal.h>
#include <sigc++/trackable.h>
+#include "ganv/canvas-base.h"
#include "ganv/wrap.hpp"
#include "ganv/Canvas.hpp"
@@ -35,7 +35,7 @@ class Canvas;
*/
class Item : public sigc::trackable {
public:
- Item(GnomeCanvasItem* gobj)
+ Item(GanvItem* gobj)
: _gobj(gobj)
{
GQuark wrapper_key = g_quark_from_string("ganvmm");
@@ -50,13 +50,13 @@ public:
RW_PROPERTY(double, x)
RW_PROPERTY(double, y)
- METHOD0(gnome_canvas_item, show);
- METHOD0(gnome_canvas_item, hide);
- METHOD0(gnome_canvas_item, raise_to_top);
- METHOD2(gnome_canvas_item, move, double, dx, double, dy);
+ METHOD0(ganv_item, show);
+ METHOD0(ganv_item, hide);
+ METHOD0(ganv_item, raise_to_top);
+ METHOD2(ganv_item, move, double, dx, double, dy);
- GnomeCanvasItem* property_parent() const {
- GnomeCanvasItem* parent;
+ GanvItem* property_parent() const {
+ GanvItem* parent;
g_object_get(G_OBJECT(_gobj), "parent", &parent, NULL);
return parent;
}
@@ -65,19 +65,19 @@ public:
return Glib::wrap(GANV_CANVAS(_gobj->canvas));
}
- GnomeCanvasItem* gobj() const { return _gobj; }
+ GanvItem* gobj() const { return _gobj; }
SIGNAL(event, GdkEvent*)
SIGNAL(click, GdkEventButton*)
protected:
- GnomeCanvasItem* const _gobj;
+ GanvItem* const _gobj;
private:
static gboolean
- on_item_event(GnomeCanvasItem* canvasitem,
- GdkEvent* ev,
- void* item)
+ on_item_event(GanvItem* canvasitem,
+ GdkEvent* ev,
+ void* item)
{
return ((Item*)item)->on_event(ev);
}
diff --git a/ganv/Module.hpp b/ganv/Module.hpp
index 628a3c1..7e3ca7c 100644
--- a/ganv/Module.hpp
+++ b/ganv/Module.hpp
@@ -46,8 +46,8 @@ public:
bool show_title = true,
bool show_port_labels = true)
: Box(&canvas, GANV_BOX(
- gnome_canvas_item_new(
- GNOME_CANVAS_GROUP(canvas.root()),
+ ganv_item_new(
+ GANV_GROUP(canvas.root()),
ganv_module_get_type(),
"x", x,
"y", y,
diff --git a/ganv/Node.hpp b/ganv/Node.hpp
index c36a8db..6bdb96c 100644
--- a/ganv/Node.hpp
+++ b/ganv/Node.hpp
@@ -17,9 +17,9 @@
#define GANV_NODE_HPP
#include <glib.h>
-#include <libgnomecanvas/gnome-canvas.h>
#include <assert.h>
+#include "ganv/canvas-base.h"
#include "ganv/node.h"
#include "ganv/Item.hpp"
@@ -35,7 +35,7 @@ class Node;
class Node : public Item {
public:
Node(Canvas* canvas, GanvNode* gobj)
- : Item(GNOME_CANVAS_ITEM(g_object_ref(gobj)))
+ : Item(GANV_ITEM(g_object_ref(gobj)))
{
g_signal_connect(gobj, "moved", G_CALLBACK(on_moved), this);
}
diff --git a/ganv/Port.hpp b/ganv/Port.hpp
index 94a272e..ed3b8a1 100644
--- a/ganv/Port.hpp
+++ b/ganv/Port.hpp
@@ -20,9 +20,9 @@
#include <string>
-#include <libgnomecanvas/gnome-canvas.h>
#include <gdkmm/types.h>
+#include "ganv/canvas-base.h"
#include "ganv/Box.hpp"
#include "ganv/port.h"
diff --git a/ganv/box.h b/ganv/box.h
index f97788f..3925cea 100644
--- a/ganv/box.h
+++ b/ganv/box.h
@@ -30,8 +30,7 @@ G_BEGIN_DECLS
typedef struct _GanvBoxClass GanvBoxClass;
typedef struct _GanvBoxImpl GanvBoxImpl;
-struct _GanvBox
-{
+struct _GanvBox {
GanvNode node;
GanvBoxImpl* impl;
};
diff --git a/ganv/canvas-base.h b/ganv/canvas-base.h
new file mode 100644
index 0000000..38a2ffe
--- /dev/null
+++ b/ganv/canvas-base.h
@@ -0,0 +1,524 @@
+/* This file is part of Ganv.
+ * Copyright 2007-2011 David Robillard <http://drobilla.net>
+ *
+ * Ganv is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or any later version.
+ *
+ * Ganv is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with Ganv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* Based on GnomeCanvas, by Federico Mena <federico@nuclecu.unam.mx>
+ * and Raph Levien <raph@gimp.org>
+ * Copyright 1997-2000 Free Software Foundation
+ */
+
+#ifndef GANV_CANVAS_BASE_H
+#define GANV_CANVAS_BASE_H
+
+#include <gtk/gtk.h>
+#include <stdarg.h>
+#include <libart_lgpl/art_misc.h>
+#include <libart_lgpl/art_rect.h>
+#include <libart_lgpl/art_svp.h>
+#include <libart_lgpl/art_uta.h>
+#include <libart_lgpl/art_affine.h>
+
+G_BEGIN_DECLS
+
+
+/* "Small" value used by canvas stuff */
+#define GANV_CANVAS_BASE_EPSILON 1e-10
+
+typedef struct _GanvCanvasBase GanvCanvasBase;
+typedef struct _GanvCanvasBaseClass GanvCanvasBaseClass;
+typedef struct _GanvItem GanvItem;
+typedef struct _GanvItemClass GanvItemClass;
+typedef struct _GanvGroup GanvGroup;
+typedef struct _GanvGroupClass GanvGroupClass;
+
+
+/* GanvItem - base item class for canvas items
+ *
+ * All canvas items are derived from GanvItem. The only information a
+ * GanvItem contains is its parent canvas, its parent canvas item group,
+ * its bounding box in world coordinates, and its current affine transformation.
+ *
+ * Items inside a canvas are organized in a tree of GanvItemGroup nodes
+ * and GanvItem leaves. Each canvas has a single root group, which can
+ * be obtained with the ganv_canvas_base_get_root() function.
+ *
+ * The abstract GanvItem class does not have any configurable or
+ * queryable attributes.
+ */
+
+/* Object flags for items */
+enum {
+ GANV_ITEM_REALIZED = 1 << 4,
+ GANV_ITEM_MAPPED = 1 << 5,
+ GANV_ITEM_ALWAYS_REDRAW = 1 << 6,
+ GANV_ITEM_VISIBLE = 1 << 7,
+ GANV_ITEM_NEED_UPDATE = 1 << 8,
+ GANV_ITEM_NEED_AFFINE = 1 << 9,
+ GANV_ITEM_NEED_CLIP = 1 << 10,
+ GANV_ITEM_NEED_VIS = 1 << 11,
+ GANV_ITEM_AFFINE_FULL = 1 << 12
+};
+
+/* Update flags for items */
+enum {
+ GANV_CANVAS_BASE_UPDATE_REQUESTED = 1 << 0,
+ GANV_CANVAS_BASE_UPDATE_AFFINE = 1 << 1,
+ GANV_CANVAS_BASE_UPDATE_CLIP = 1 << 2,
+ GANV_CANVAS_BASE_UPDATE_VISIBILITY = 1 << 3,
+ GANV_CANVAS_BASE_UPDATE_IS_VISIBLE = 1 << 4 /* Deprecated. FIXME: remove this */
+};
+
+#define GANV_TYPE_ITEM (ganv_item_get_type())
+#define GANV_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GANV_TYPE_ITEM, GanvItem))
+#define GANV_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GANV_TYPE_ITEM, GanvItemClass))
+#define GANV_IS_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GANV_TYPE_ITEM))
+#define GANV_IS_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GANV_TYPE_ITEM))
+#define GANV_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GANV_TYPE_ITEM, GanvItemClass))
+
+struct _GanvItem {
+ GtkObject object;
+
+ /* Parent canvas for this item */
+ GanvCanvasBase* canvas;
+
+ /* Parent canvas group for this item (a GanvGroup) */
+ GanvItem* parent;
+
+ /* If NULL, assumed to be the identity tranform. If flags does not have
+ * AFFINE_FULL, then a two-element array containing a translation. If
+ * flags contains AFFINE_FULL, a six-element array containing an affine
+ * transformation.
+ */
+ double* xform;
+
+ /* Bounding box for this item (in canvas coordinates) */
+ double x1, y1, x2, y2;
+};
+
+struct _GanvItemClass {
+ GtkObjectClass parent_class;
+
+ /* Tell the item to update itself. The flags are from the update flags
+ * defined above. The item should update its internal state from its
+ * queued state, and recompute and request its repaint area. The
+ * affine, if used, is a pointer to a 6-element array of doubles. The
+ * update method also recomputes the bounding box of the item.
+ */
+ void (* update)(GanvItem* item, double* affine, ArtSVP* clip_path, int flags);
+
+ /* Realize an item -- create GCs, etc. */
+ void (* realize)(GanvItem* item);
+
+ /* Unrealize an item */
+ void (* unrealize)(GanvItem* item);
+
+ /* Map an item - normally only need by items with their own GdkWindows */
+ void (* map)(GanvItem* item);
+
+ /* Unmap an item */
+ void (* unmap)(GanvItem* item);
+
+ /* Return the microtile coverage of the item */
+ ArtUta* (*coverage)(GanvItem * item);
+
+ /* Draw an item of this type. (x, y) are the upper-left canvas pixel
+ * coordinates of the drawable, a temporary pixmap, where things get
+ * drawn. (width, height) are the dimensions of the drawable.
+ */
+ void (* draw)(GanvItem* item, GdkDrawable* drawable,
+ int x, int y, int width, int height);
+
+ /* Calculate the distance from an item to the specified point. It also
+ * returns a canvas item which is the item itself in the case of the
+ * object being an actual leaf item, or a child in case of the object
+ * being a canvas group. (cx, cy) are the canvas pixel coordinates that
+ * correspond to the item-relative coordinates (x, y).
+ */
+ double (* point)(GanvItem* item, double x, double y, int cx, int cy,
+ GanvItem** actual_item);
+
+ /* Fetch the item's bounding box (need not be exactly tight). This
+ * should be in item-relative coordinates.
+ */
+ void (* bounds)(GanvItem* item, double* x1, double* y1, double* x2, double* y2);
+
+ /* Signal: an event occurred for an item of this type. The (x, y)
+ * coordinates are in the canvas world coordinate system.
+ */
+ gboolean (* event)(GanvItem* item, GdkEvent* event);
+
+ /* Reserved for future expansion */
+ gpointer spare_vmethods [4];
+};
+
+
+GType ganv_item_get_type(void) G_GNUC_CONST;
+
+/* Create a canvas item using the standard Gtk argument mechanism. The item is
+ * automatically inserted at the top of the specified canvas group. The last
+ * argument must be a NULL pointer.
+ */
+GanvItem* ganv_item_new(GanvGroup* parent, GType type,
+ const gchar* first_arg_name, ...);
+
+/* Constructors for use in derived classes and language wrappers */
+void ganv_item_construct(GanvItem* item, GanvGroup* parent,
+ const gchar* first_arg_name, va_list args);
+
+/* Configure an item using the standard Gtk argument mechanism. The last
+ * argument must be a NULL pointer.
+ */
+void ganv_item_set(GanvItem* item, const gchar* first_arg_name, ...);
+
+/* Used only for language wrappers and the like */
+void ganv_item_set_valist(GanvItem* item,
+ const gchar* first_arg_name, va_list args);
+
+/* Move an item by the specified amount */
+void ganv_item_move(GanvItem* item, double dx, double dy);
+
+/* Apply a relative affine transformation to the item. */
+void ganv_item_affine_relative(GanvItem* item, const double affine[6]);
+
+/* Apply an absolute affine transformation to the item. */
+void ganv_item_affine_absolute(GanvItem* item, const double affine[6]);
+
+/* Raise an item in the z-order of its parent group by the specified number of
+ * positions.
+ */
+void ganv_item_raise(GanvItem* item, int positions);
+
+/* Lower an item in the z-order of its parent group by the specified number of
+ * positions.
+ */
+void ganv_item_lower(GanvItem* item, int positions);
+
+/* Raise an item to the top of its parent group's z-order. */
+void ganv_item_raise_to_top(GanvItem* item);
+
+/* Lower an item to the bottom of its parent group's z-order */
+void ganv_item_lower_to_bottom(GanvItem* item);
+
+/* Show an item (make it visible). If the item is already shown, it has no
+ * effect.
+ */
+void ganv_item_show(GanvItem* item);
+
+/* Hide an item (make it invisible). If the item is already invisible, it has
+ * no effect.
+ */
+void ganv_item_hide(GanvItem* item);
+
+/* Grab the mouse for the specified item. Only the events in event_mask will be
+ * reported. If cursor is non-NULL, it will be used during the duration of the
+ * grab. Time is a proper X event time parameter. Returns the same values as
+ * XGrabPointer().
+ */
+int ganv_item_grab(GanvItem* item, unsigned int event_mask,
+ GdkCursor* cursor, guint32 etime);
+
+/* Ungrabs the mouse -- the specified item must be the same that was passed to
+ * ganv_item_grab(). Time is a proper X event time parameter.
+ */
+void ganv_item_ungrab(GanvItem* item, guint32 etime);
+
+/* These functions convert from a coordinate system to another. "w" is world
+ * coordinates and "i" is item coordinates.
+ */
+void ganv_item_w2i(GanvItem* item, double* x, double* y);
+void ganv_item_i2w(GanvItem* item, double* x, double* y);
+
+/* Gets the affine transform that converts from item-relative coordinates to
+ * world coordinates.
+ */
+void ganv_item_i2w_affine(GanvItem* item, double affine[6]);
+
+/* Gets the affine transform that converts from item-relative coordinates to
+ * canvas pixel coordinates.
+ */
+void ganv_item_i2c_affine(GanvItem* item, double affine[6]);
+
+/* Remove the item from its parent group and make the new group its parent. The
+ * item will be put on top of all the items in the new group. The item's
+ * coordinates relative to its new parent to *not* change -- this means that the
+ * item could potentially move on the screen.
+ *
+ * The item and the group must be in the same canvas. An item cannot be
+ * reparented to a group that is the item itself or that is an inferior of the
+ * item.
+ */
+void ganv_item_reparent(GanvItem* item, GanvGroup* new_group);
+
+/* Used to send all of the keystroke events to a specific item as well as
+ * GDK_FOCUS_CHANGE events.
+ */
+void ganv_item_grab_focus(GanvItem* item);
+
+/* Fetch the bounding box of the item. The bounding box may not be exactly
+ * tight, but the canvas items will do the best they can. The returned bounding
+ * box is in the coordinate system of the item's parent.
+ */
+void ganv_item_get_bounds(GanvItem* item,
+ double* x1, double* y1, double* x2, double* y2);
+
+/* Request that the update method eventually get called. This should be used
+ * only by item implementations.
+ */
+void ganv_item_request_update(GanvItem* item);
+
+
+/* GanvGroup - a group of canvas items
+ *
+ * A group is a node in the hierarchical tree of groups/items inside a canvas.
+ * Groups serve to give a logical structure to the items.
+ *
+ * Consider a circuit editor application that uses the canvas for its schematic
+ * display. Hierarchically, there would be canvas groups that contain all the
+ * components needed for an "adder", for example -- this includes some logic
+ * gates as well as wires. You can move stuff around in a convenient way by
+ * doing a ganv_item_move() of the hierarchical groups -- to move an
+ * adder, simply move the group that represents the adder.
+ *
+ * The following arguments are available:
+ *
+ * name type read/write description
+ * --------------------------------------------------------------------------------
+ * x double RW X coordinate of group's origin
+ * y double RW Y coordinate of group's origin
+ */
+
+
+#define GANV_TYPE_GROUP (ganv_group_get_type())
+#define GANV_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GANV_TYPE_GROUP, GanvGroup))
+#define GANV_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GANV_TYPE_GROUP, GanvGroupClass))
+#define GANV_IS_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GANV_TYPE_GROUP))
+#define GANV_IS_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GANV_TYPE_GROUP))
+#define GANV_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GANV_TYPE_GROUP, GanvGroupClass))
+
+
+struct _GanvGroup {
+ GanvItem item;
+
+ /* Children of the group */
+ GList* item_list;
+ GList* item_list_end;
+};
+
+struct _GanvGroupClass {
+ GanvItemClass parent_class;
+};
+
+
+GType ganv_group_get_type(void) G_GNUC_CONST;
+
+
+/*** GanvCanvasBase ***/
+
+
+#define GANV_TYPE_CANVAS_BASE (ganv_canvas_base_get_type())
+#define GANV_CANVAS_BASE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GANV_TYPE_CANVAS_BASE, GanvCanvasBase))
+#define GANV_CANVAS_BASE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GANV_TYPE_CANVAS_BASE, GanvCanvasBaseClass))
+#define GANV_IS_CANVAS_BASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GANV_TYPE_CANVAS_BASE))
+#define GANV_IS_CANVAS_BASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GANV_TYPE_CANVAS_BASE))
+#define GANV_CANVAS_BASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GANV_TYPE_CANVAS_BASE, GanvCanvasBaseClass))
+
+
+struct _GanvCanvasBase {
+ GtkLayout layout;
+
+ /* Root canvas group */
+ GanvItem* root;
+
+ /* Area that needs redrawing, stored as a microtile array */
+ ArtUta* redraw_area;
+
+ /* The item containing the mouse pointer, or NULL if none */
+ GanvItem* current_item;
+
+ /* Item that is about to become current (used to track deletions and such) */
+ GanvItem* new_current_item;
+
+ /* Item that holds a pointer grab, or NULL if none */
+ GanvItem* grabbed_item;
+
+ /* If non-NULL, the currently focused item */
+ GanvItem* focused_item;
+
+ /* GC for temporary draw pixmap */
+ GdkGC* pixmap_gc;
+
+ /* Event on which selection of current item is based */
+ GdkEvent pick_event;
+
+ /* Scrolling region */
+ double scroll_x1, scroll_y1;
+ double scroll_x2, scroll_y2;
+
+ /* Scaling factor to be used for display */
+ double pixels_per_unit;
+
+ /* Idle handler ID */
+ guint idle_id;
+
+ /* Signal handler ID for destruction of the root item */
+ guint root_destroy_id;
+
+ /* Area that is being redrawn. Contains (x1, y1) but not (x2, y2).
+ * Specified in canvas pixel coordinates.
+ */
+ int redraw_x1, redraw_y1;
+ int redraw_x2, redraw_y2;
+
+ /* Offsets of the temprary drawing pixmap */
+ int draw_xofs, draw_yofs;
+
+ /* Internal pixel offsets when zoomed out */
+ int zoom_xofs, zoom_yofs;
+
+ /* Last known modifier state, for deferred repick when a button is down */
+ int state;
+
+ /* Event mask specified when grabbing an item */
+ guint grabbed_event_mask;
+
+ /* Tolerance distance for picking items */
+ int close_enough;
+
+ /* Whether the canvas should center the scroll region in the middle of
+ * the window if the scroll region is smaller than the window.
+ */
+ unsigned int center_scroll_region : 1;
+
+ /* Whether items need update at next idle loop iteration */
+ unsigned int need_update : 1;
+
+ /* Whether the canvas needs redrawing at the next idle loop iteration */
+ unsigned int need_redraw : 1;
+
+ /* Whether current item will be repicked at next idle loop iteration */
+ unsigned int need_repick : 1;
+
+ /* For use by internal pick_current_item() function */
+ unsigned int left_grabbed_item : 1;
+
+ /* For use by internal pick_current_item() function */
+ unsigned int in_repick : 1;
+};
+
+struct _GanvCanvasBaseClass {
+ GtkLayoutClass parent_class;
+
+ /* Draw the background for the area given. This method is only used
+ * for non-antialiased canvases.
+ */
+ void (* draw_background)(GanvCanvasBase* canvas, GdkDrawable* drawable,
+ int x, int y, int width, int height);
+
+ /* Private Virtual methods for groping the canvas inside bonobo */
+ void (* request_update)(GanvCanvasBase* canvas);
+
+ /* Reserved for future expansion */
+ gpointer spare_vmethods [4];
+};
+
+
+GType ganv_canvas_base_get_type(void) G_GNUC_CONST;
+
+/* Creates a new canvas. You should check that the canvas is created with the
+ * proper visual and colormap. Any visual will do unless you intend to insert
+ * gdk_imlib images into it, in which case you should use the gdk_imlib visual.
+ *
+ * You should call ganv_canvas_base_set_scroll_region() soon after calling this
+ * function to set the desired scrolling limits for the canvas.
+ */
+GtkWidget* ganv_canvas_base_new(void);
+
+/* Returns the root canvas item group of the canvas */
+GanvGroup* ganv_canvas_base_root(GanvCanvasBase* canvas);
+
+/* Sets the limits of the scrolling region, in world coordinates */
+void ganv_canvas_base_set_scroll_region(GanvCanvasBase* canvas,
+ double x1, double y1, double x2, double y2);
+
+/* Gets the limits of the scrolling region, in world coordinates */
+void ganv_canvas_base_get_scroll_region(GanvCanvasBase* canvas,
+ double* x1, double* y1, double* x2, double* y2);
+
+/* Whether the canvas centers the scroll region if it is smaller than the window */
+void ganv_canvas_base_set_center_scroll_region(GanvCanvasBase* canvas, gboolean center_scroll_region);
+
+/* Returns whether the canvas is set to center the scroll region if it is smaller than the window */
+gboolean ganv_canvas_base_get_center_scroll_region(GanvCanvasBase* canvas);
+
+/* Sets the number of pixels that correspond to one unit in world coordinates */
+void ganv_canvas_base_set_pixels_per_unit(GanvCanvasBase* canvas, double n);
+
+/* Scrolls the canvas to the specified offsets, given in canvas pixel coordinates */
+void ganv_canvas_base_scroll_to(GanvCanvasBase* canvas, int cx, int cy);
+
+/* Returns the scroll offsets of the canvas in canvas pixel coordinates. You
+ * can specify NULL for any of the values, in which case that value will not be
+ * queried.
+ */
+void ganv_canvas_base_get_scroll_offsets(GanvCanvasBase* canvas, int* cx, int* cy);
+
+/* Requests that the canvas be repainted immediately instead of in the idle
+ * loop.
+ */
+void ganv_canvas_base_update_now(GanvCanvasBase* canvas);
+
+/* Returns the item that is at the specified position in world coordinates, or
+ * NULL if no item is there.
+ */
+GanvItem* ganv_canvas_base_get_item_at(GanvCanvasBase* canvas, double x, double y);
+
+/* For use only by item type implementations. Request that the canvas eventually
+ * redraw the specified region. The region is specified as a microtile
+ * array. This function takes over responsibility for freeing the uta argument.
+ */
+void ganv_canvas_base_request_redraw_uta(GanvCanvasBase* canvas, ArtUta* uta);
+
+/* For use only by item type implementations. Request that the canvas
+ * eventually redraw the specified region, specified in canvas pixel
+ * coordinates. The region contains (x1, y1) but not (x2, y2).
+ */
+void ganv_canvas_base_request_redraw(GanvCanvasBase* canvas, int x1, int y1, int x2, int y2);
+
+/* Gets the affine transform that converts world coordinates into canvas pixel
+ * coordinates.
+ */
+void ganv_canvas_base_w2c_affine(GanvCanvasBase* canvas, double affine[6]);
+
+/* These functions convert from a coordinate system to another. "w" is world
+ * coordinates, "c" is canvas pixel coordinates (pixel coordinates that are
+ * (0,0) for the upper-left scrolling limit and something else for the
+ * lower-left scrolling limit).
+ */
+void ganv_canvas_base_w2c(GanvCanvasBase* canvas, double wx, double wy, int* cx, int* cy);
+void ganv_canvas_base_w2c_d(GanvCanvasBase* canvas, double wx, double wy, double* cx, double* cy);
+void ganv_canvas_base_c2w(GanvCanvasBase* canvas, int cx, int cy, double* wx, double* wy);
+
+/* This function takes in coordinates relative to the GTK_LAYOUT
+ * (canvas)->bin_window and converts them to world coordinates.
+ */
+void ganv_canvas_base_window_to_world(GanvCanvasBase* canvas,
+ double winx, double winy, double* worldx, double* worldy);
+
+/* This is the inverse of ganv_canvas_base_window_to_world() */
+void ganv_canvas_base_world_to_window(GanvCanvasBase* canvas,
+ double worldx, double worldy, double* winx, double* winy);
+
+G_END_DECLS
+
+#endif
diff --git a/ganv/canvas.h b/ganv/canvas.h
index 906f7c4..08ec2f9 100644
--- a/ganv/canvas.h
+++ b/ganv/canvas.h
@@ -16,16 +16,7 @@
#ifndef GANV_CANVAS_H
#define GANV_CANVAS_H
-/**
- * SECTION:ganv
- *
- * @version: 1.0.0
- * @Version: 1.0.0
- *
- * #GanvCanvas is possibly the greatest thing, ever.
- */
-#include <libgnomecanvas/libgnomecanvas.h>
-
+#include "ganv/canvas-base.h"
#include "ganv/types.h"
#include "ganv/edge.h"
@@ -55,9 +46,8 @@ typedef enum {
GANV_DIRECTION_RIGHT
} GanvDirection;
-struct _GanvCanvas
-{
- GnomeCanvas canvas;
+struct _GanvCanvas {
+ GanvCanvasBase canvas;
struct GanvCanvasImpl* impl;
GanvDirection direction;
double width;
@@ -66,7 +56,7 @@ struct _GanvCanvas
};
struct _GanvCanvasClass {
- GnomeCanvasClass parent_class;
+ GanvCanvasBaseClass parent_class;
};
GType ganv_canvas_get_type(void);
@@ -80,7 +70,7 @@ ganv_canvas_resize(GanvCanvas* canvas, double width, double height);
* ganv_canvas_get_root:
* Return value: (transfer none): The root group of @canvas.
*/
-GnomeCanvasGroup*
+GanvGroup*
ganv_canvas_get_root(const GanvCanvas* canvas);
void
diff --git a/ganv/circle.h b/ganv/circle.h
index 8347525..2b756df 100644
--- a/ganv/circle.h
+++ b/ganv/circle.h
@@ -37,8 +37,7 @@ typedef struct _GanvCircleImpl GanvCircleImpl;
* A circular #GanvNode. A #GanvCircle is a leaf, that is, it does not contain
* any child nodes (though, like any #GanvNode, it may have a label).
*/
-struct _GanvCircle
-{
+struct _GanvCircle {
GanvNode node;
GanvCircleImpl* impl;
};
diff --git a/ganv/edge.h b/ganv/edge.h
index 6fd2ffe..9a409b2 100644
--- a/ganv/edge.h
+++ b/ganv/edge.h
@@ -16,10 +16,9 @@
#ifndef GANV_EDGE_H
#define GANV_EDGE_H
-#include <libgnomecanvas/libgnomecanvas.h>
-
-#include "ganv/types.h"
+#include "ganv/canvas-base.h"
#include "ganv/node.h"
+#include "ganv/types.h"
G_BEGIN_DECLS
@@ -33,14 +32,13 @@ G_BEGIN_DECLS
typedef struct _GanvEdgeClass GanvEdgeClass;
typedef struct _GanvEdgeImpl GanvEdgeImpl;
-struct _GanvEdge
-{
- GnomeCanvasItem item;
- GanvEdgeImpl* impl;
+struct _GanvEdge {
+ GanvItem item;
+ GanvEdgeImpl* impl;
};
struct _GanvEdgeClass {
- GnomeCanvasItemClass parent_class;
+ GanvItemClass parent_class;
};
GType ganv_edge_get_type(void);
diff --git a/ganv/module.h b/ganv/module.h
index 718756b..7520722 100644
--- a/ganv/module.h
+++ b/ganv/module.h
@@ -35,8 +35,7 @@ typedef struct _GanvModuleImpl GanvModuleImpl;
typedef void (*GanvPortFunction)(GanvPort* port, void* data);
-struct _GanvModule
-{
+struct _GanvModule {
GanvBox box;
GanvModuleImpl* impl;
};
diff --git a/ganv/node.h b/ganv/node.h
index c814c8c..e1f39ac 100644
--- a/ganv/node.h
+++ b/ganv/node.h
@@ -16,8 +16,7 @@
#ifndef GANV_NODE_H
#define GANV_NODE_H
-#include <libgnomecanvas/libgnomecanvas.h>
-
+#include "ganv/canvas-base.h"
#include "ganv/types.h"
#include "ganv/text.h"
@@ -34,12 +33,12 @@ typedef struct _GanvNodeClass GanvNodeClass;
typedef struct _GanvNodeImpl GanvNodeImpl;
struct _GanvNode {
- GnomeCanvasGroup group;
- GanvNodeImpl* impl;
+ GanvGroup group;
+ GanvNodeImpl* impl;
};
struct _GanvNodeClass {
- GnomeCanvasGroupClass parent_class;
+ GanvGroupClass parent_class;
void (*tick)(GanvNode* self,
double seconds);
diff --git a/ganv/port.h b/ganv/port.h
index 5052012..402c67a 100644
--- a/ganv/port.h
+++ b/ganv/port.h
@@ -32,8 +32,7 @@ G_BEGIN_DECLS
typedef struct _GanvPortClass GanvPortClass;
typedef struct _GanvPortImpl GanvPortImpl;
-struct _GanvPort
-{
+struct _GanvPort {
GanvBox box;
GanvPortImpl* impl;
};
diff --git a/ganv/text.h b/ganv/text.h
index 78b25ba..d4ea79c 100644
--- a/ganv/text.h
+++ b/ganv/text.h
@@ -16,7 +16,7 @@
#ifndef GANV_TEXT_H
#define GANV_TEXT_H
-#include <libgnomecanvas/libgnomecanvas.h>
+#include "ganv/canvas-base.h"
G_BEGIN_DECLS
@@ -31,14 +31,13 @@ typedef struct _GanvText GanvText;
typedef struct _GanvTextClass GanvTextClass;
typedef struct _GanvTextImpl GanvTextImpl;
-struct _GanvText
-{
- GnomeCanvasItem item;
+struct _GanvText {
+ GanvItem item;
GanvTextImpl* impl;
};
struct _GanvTextClass {
- GnomeCanvasItemClass parent_class;
+ GanvItemClass parent_class;
};
GType ganv_text_get_type(void);
diff --git a/ganv/types.h b/ganv/types.h
index f669fbc..1e679d5 100644
--- a/ganv/types.h
+++ b/ganv/types.h
@@ -18,7 +18,6 @@
typedef struct _GanvCanvas GanvCanvas;
typedef struct _GanvEdge GanvEdge;
-typedef struct _GanvItem GanvItem;
typedef struct _GanvModule GanvModule;
typedef struct _GanvNode GanvNode;
typedef struct _GanvPort GanvPort;
diff --git a/ganv/widget.h b/ganv/widget.h
new file mode 100644
index 0000000..010528e
--- /dev/null
+++ b/ganv/widget.h
@@ -0,0 +1,63 @@
+/* This file is part of Ganv.
+ * Copyright 2007-2011 David Robillard <http://drobilla.net>
+ *
+ * Ganv is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or any later version.
+ *
+ * Ganv is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with Ganv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* Based on GnomeCanvasWidget, by Federico Mena <federico@nuclecu.unam.mx>
+ * Copyright 1997-2000 Free Software Foundation
+ */
+
+#ifndef GANV_WIDGET_H
+#define GANV_WIDGET_H
+
+#include "ganv/canvas-base.h"
+
+G_BEGIN_DECLS
+
+#define GANV_TYPE_WIDGET (ganv_widget_get_type ())
+#define GANV_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GANV_TYPE_WIDGET, GanvWidget))
+#define GANV_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GANV_TYPE_WIDGET, GanvWidgetClass))
+#define GANV_IS_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GANV_TYPE_WIDGET))
+#define GANV_IS_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GANV_TYPE_WIDGET))
+#define GANV_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GANV_TYPE_WIDGET, GanvWidgetClass))
+
+typedef struct _GanvWidget GanvWidget;
+typedef struct _GanvWidgetClass GanvWidgetClass;
+
+struct _GanvWidget {
+ GanvItem item;
+
+ GtkWidget* widget; /* The child widget */
+
+ double x, y; /* Position at anchor */
+ double width, height; /* Dimensions of widget */
+ GtkAnchorType anchor; /* Anchor side for widget */
+
+ int cx, cy; /* Top-left canvas coordinates for widget */
+ int cwidth, cheight; /* Size of widget in pixels */
+
+ guint destroy_id; /* Signal connection id for destruction of child widget */
+
+ guint size_pixels : 1; /* Is size specified in (unchanging) pixels or units (get scaled)? */
+ guint in_destroy : 1; /* Is child widget being destroyed? */
+};
+
+struct _GanvWidgetClass {
+ GanvItemClass parent_class;
+};
+
+GType ganv_widget_get_type(void);
+
+G_END_DECLS
+
+#endif /* GANV_WIDGET_H */
diff --git a/ganv/wrap.hpp b/ganv/wrap.hpp
index 9409f0f..3d5d0e3 100644
--- a/ganv/wrap.hpp
+++ b/ganv/wrap.hpp
@@ -36,9 +36,9 @@
} \
void set_##name(type value) { \
if (!_gobj) return; \
- gnome_canvas_item_set(GNOME_CANVAS_ITEM(_gobj), \
- #name, value->gobj(), \
- NULL); \
+ ganv_item_set(GANV_ITEM(_gobj), \
+ #name, value->gobj(), \
+ NULL); \
}
#define METHOD0(prefix, name) \