summaryrefslogtreecommitdiffstats
path: root/ganv
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-12-13 22:55:42 +0000
committerDavid Robillard <d@drobilla.net>2011-12-13 22:55:42 +0000
commit677f884681b567377304b3d5c55a4eb02899f2de (patch)
treebd38af36ef6d52d9a97342b2ba0658113041bc10 /ganv
parent635cf8f91b2405dec530ac813d02a7440c3c836b (diff)
downloadganv-677f884681b567377304b3d5c55a4eb02899f2de.tar.gz
ganv-677f884681b567377304b3d5c55a4eb02899f2de.tar.bz2
ganv-677f884681b567377304b3d5c55a4eb02899f2de.zip
Move group implementation to separate files.
git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@3870 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'ganv')
-rw-r--r--ganv/Canvas.hpp2
-rw-r--r--ganv/canvas-base.h94
-rw-r--r--ganv/canvas.h2
-rw-r--r--ganv/ganv.h1
-rw-r--r--ganv/group.h51
-rw-r--r--ganv/node.h1
6 files changed, 74 insertions, 77 deletions
diff --git a/ganv/Canvas.hpp b/ganv/Canvas.hpp
index 0b5a95c..e017d70 100644
--- a/ganv/Canvas.hpp
+++ b/ganv/Canvas.hpp
@@ -135,7 +135,7 @@ public:
GQuark wrapper_key();
- GanvGroup* root();
+ GanvItem* root();
GdkCursor* move_cursor();
diff --git a/ganv/canvas-base.h b/ganv/canvas-base.h
index a6abe5f..8f6d39c 100644
--- a/ganv/canvas-base.h
+++ b/ganv/canvas-base.h
@@ -36,8 +36,6 @@ 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
@@ -61,17 +59,14 @@ enum {
GANV_ITEM_ALWAYS_REDRAW = 1 << 3,
GANV_ITEM_VISIBLE = 1 << 4,
GANV_ITEM_NEED_UPDATE = 1 << 5,
- GANV_ITEM_NEED_CLIP = 1 << 6,
- GANV_ITEM_NEED_VIS = 1 << 7,
+ GANV_ITEM_NEED_VIS = 1 << 6,
};
/* 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 */
+ GANV_CANVAS_BASE_UPDATE_VISIBILITY = 1 << 2,
};
#define GANV_TYPE_ITEM (ganv_item_get_type())
@@ -87,7 +82,7 @@ struct _GanvItem {
/* Parent canvas for this item */
GanvCanvasBase* canvas;
- /* Parent canvas group for this item (a GanvGroup) */
+ /* Parent for this item */
GanvItem* parent;
/* Position in parent-relative coordinates. */
@@ -100,6 +95,12 @@ struct _GanvItem {
struct _GanvItemClass {
GtkObjectClass parent_class;
+ /* Add a child to this item (optional) */
+ void (* add)(GanvItem* item, GanvItem* child);
+
+ /* Remove a child from this item (optional) */
+ void (* remove)(GanvItem* item, GanvItem* child);
+
/* 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 update
@@ -127,10 +128,10 @@ struct _GanvItemClass {
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).
+ * returns a canvas item which is actual item the point is within, which
+ * may not be equal to @item if @item has children. (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);
@@ -152,9 +153,8 @@ struct _GanvItemClass {
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.
+/* Create a canvas item using the standard Gtk argument mechanism. The item
+ * automatically added to @parent. The last argument must be a NULL pointer.
*/
GanvItem* ganv_item_new(GanvItem* parent, GType type,
const gchar* first_arg_name, ...);
@@ -175,10 +175,10 @@ void ganv_item_set_valist(GanvItem* item,
/* Move an item by the specified amount */
void ganv_item_move(GanvItem* item, double dx, double dy);
-/* Raise an item to the top of its parent group's z-order. */
+/* Raise an item to the top of its parent's z-order. */
void ganv_item_raise_to_top(GanvItem* item);
-/* Lower an item to the bottom of its parent group's z-order */
+/* Lower an item to the bottom of its parent'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
@@ -220,17 +220,6 @@ void ganv_item_i2w_affine(GanvItem* item, cairo_matrix_t* matrix);
*/
void ganv_item_i2c_affine(GanvItem* item, cairo_matrix_t* matrix);
-/* 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.
*/
@@ -249,51 +238,6 @@ void ganv_item_get_bounds(GanvItem* item,
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 ***/
@@ -415,8 +359,8 @@ GType ganv_canvas_base_get_type(void) G_GNUC_CONST;
*/
GtkWidget* ganv_canvas_base_new(void);
-/* Returns the root canvas item group of the canvas */
-GanvGroup* ganv_canvas_base_root(GanvCanvasBase* canvas);
+/* Returns the root item of the canvas */
+GanvItem* 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,
diff --git a/ganv/canvas.h b/ganv/canvas.h
index 08ec2f9..ddd420b 100644
--- a/ganv/canvas.h
+++ b/ganv/canvas.h
@@ -70,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.
*/
-GanvGroup*
+GanvItem*
ganv_canvas_get_root(const GanvCanvas* canvas);
void
diff --git a/ganv/ganv.h b/ganv/ganv.h
index 3b84935..5becce7 100644
--- a/ganv/ganv.h
+++ b/ganv/ganv.h
@@ -21,6 +21,7 @@
#include "ganv/circle.h"
#include "ganv/edge.h"
#include "ganv/ganv.h"
+#include "ganv/group.h"
#include "ganv/module.h"
#include "ganv/node.h"
#include "ganv/port.h"
diff --git a/ganv/group.h b/ganv/group.h
new file mode 100644
index 0000000..273bdea
--- /dev/null
+++ b/ganv/group.h
@@ -0,0 +1,51 @@
+/* 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/>.
+ */
+
+#ifndef GANV_GROUP_H
+#define GANV_GROUP_H
+
+#include "ganv/canvas-base.h"
+
+/* Based on GnomeCanvasGroup, by Federico Mena <federico@nuclecu.unam.mx>
+ * and Raph Levien <raph@gimp.org>
+ * Copyright 1997-2000 Free Software Foundation
+ */
+
+#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))
+
+typedef struct _GanvGroup GanvGroup;
+typedef struct _GanvGroupClass 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;
+
+#endif /* GANV_GROUP_H */
diff --git a/ganv/node.h b/ganv/node.h
index 7c14b53..c0e2302 100644
--- a/ganv/node.h
+++ b/ganv/node.h
@@ -19,6 +19,7 @@
#include "ganv/canvas-base.h"
#include "ganv/types.h"
#include "ganv/text.h"
+#include "ganv/group.h"
G_BEGIN_DECLS