summaryrefslogtreecommitdiffstats
path: root/ganv
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2014-01-11 22:35:56 +0000
committerDavid Robillard <d@drobilla.net>2014-01-11 22:35:56 +0000
commit2c07b0df01c7b8ca9e9d5ea1730b09ca3cf801de (patch)
treee1a58dd99261b26be3bfbe8090afe3f0e78784b6 /ganv
parentafdb578607526ca82cf03ec04cb4f410f11692c1 (diff)
downloadganv-2c07b0df01c7b8ca9e9d5ea1730b09ca3cf801de.tar.gz
ganv-2c07b0df01c7b8ca9e9d5ea1730b09ca3cf801de.tar.bz2
ganv-2c07b0df01c7b8ca9e9d5ea1730b09ca3cf801de.zip
Merge GanvCanvasBase and GanvCanvas.
git-svn-id: http://svn.drobilla.net/lad/trunk/ganv@5302 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'ganv')
-rw-r--r--ganv/canvas-base.h213
-rw-r--r--ganv/canvas.h170
-rw-r--r--ganv/group.h4
-rw-r--r--ganv/item.h56
4 files changed, 158 insertions, 285 deletions
diff --git a/ganv/canvas-base.h b/ganv/canvas-base.h
deleted file mode 100644
index 8299132..0000000
--- a/ganv/canvas-base.h
+++ /dev/null
@@ -1,213 +0,0 @@
-/* This file is part of Ganv.
- * Copyright 2007-2012 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 <stdarg.h>
-
-#include <cairo.h>
-#include <gtk/gtk.h>
-
-#include "ganv/item.h"
-
-G_BEGIN_DECLS
-
-typedef struct _GanvCanvasBase GanvCanvasBase;
-typedef struct _GanvCanvasBaseClass GanvCanvasBaseClass;
-
-/* Update flags for items */
-enum {
- GANV_CANVAS_BASE_UPDATE_REQUESTED = 1 << 0,
- GANV_CANVAS_BASE_UPDATE_AFFINE = 1 << 1,
- GANV_CANVAS_BASE_UPDATE_VISIBILITY = 1 << 2,
-};
-
-#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 item */
- GanvItem* root;
-
- /* Region that needs redrawing (list of rectangles) */
- GSList* redraw_region;
-
- /* 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;
-
- /* 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 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,
- 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);
-
-/* 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);
-
-/* Gets the affine transform that converts world coordinates into canvas pixel
- * coordinates.
- */
-void ganv_canvas_base_w2c_affine(GanvCanvasBase* canvas, cairo_matrix_t* matrix);
-
-/* 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 37fdc5d..d0a1eeb 100644
--- a/ganv/canvas.h
+++ b/ganv/canvas.h
@@ -16,9 +16,15 @@
#ifndef GANV_CANVAS_H
#define GANV_CANVAS_H
-#include "ganv/canvas-base.h"
+#include <stdarg.h>
+
+#include <cairo.h>
+#include <gtk/gtk.h>
+
+#include "ganv/canvas.h"
#include "ganv/types.h"
#include "ganv/edge.h"
+#include "ganv/item.h"
G_BEGIN_DECLS
@@ -47,43 +53,159 @@ typedef enum {
} GanvDirection;
struct _GanvCanvas {
- GanvCanvasBase canvas;
+ GtkLayout layout;
+
struct GanvCanvasImpl* impl;
- GanvDirection direction;
- double width;
- double height;
- gboolean locked;
+
+ /* Root canvas item */
+ GanvItem* root;
+
+ /* Region that needs redrawing (list of rectangles) */
+ GSList* redraw_region;
+
+ /* 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;
+
+ /* Flow direction */
+ GanvDirection direction;
+
+ /* Canvas width */
+ double width;
+
+ /* Canvas height */
+ double height;
+
+ /* Disable changes to canvas */
+ gboolean locked;
+
#ifdef GANV_FDGL
guint layout_idle_id;
#endif
};
struct _GanvCanvasClass {
- GanvCanvasBaseClass parent_class;
+ GtkLayoutClass parent_class;
+
+ /* Private Virtual methods for groping the canvas inside bonobo */
+ void (* request_update)(GanvCanvas* canvas);
+
+ /* Reserved for future expansion */
+ gpointer spare_vmethods [4];
};
-GType ganv_canvas_get_type(void);
+GType ganv_canvas_get_type(void) G_GNUC_CONST;
GanvCanvas* ganv_canvas_new(double width, double height);
-/**
- * ganv_canvas_resize:
- * Resize the canvas to the given dimensions.
- */
+GanvItem* ganv_canvas_root(GanvCanvas* canvas);
+
+void ganv_canvas_set_scroll_region(GanvCanvas* canvas,
+ double x1, double y1, double x2, double y2);
+
+void ganv_canvas_get_scroll_region(GanvCanvas* canvas,
+ double* x1, double* y1, double* x2, double* y2);
+
+void ganv_canvas_set_center_scroll_region(GanvCanvas* canvas, gboolean center_scroll_region);
+
+gboolean ganv_canvas_get_center_scroll_region(GanvCanvas* canvas);
+
+void ganv_canvas_set_pixels_per_unit(GanvCanvas* canvas, double n);
+
+void ganv_canvas_scroll_to(GanvCanvas* canvas, int cx, int cy);
+
+void ganv_canvas_get_scroll_offsets(GanvCanvas* canvas, int* cx, int* cy);
+
+GanvItem* ganv_canvas_get_item_at(GanvCanvas* canvas, double x, double y);
+
+void ganv_canvas_w2c_affine(GanvCanvas* canvas, cairo_matrix_t* matrix);
+
+void ganv_canvas_w2c(GanvCanvas* canvas, double wx, double wy, int* cx, int* cy);
+
+void ganv_canvas_w2c_d(GanvCanvas* canvas, double wx, double wy, double* cx, double* cy);
+
+void ganv_canvas_c2w(GanvCanvas* canvas, int cx, int cy, double* wx, double* wy);
+
+void ganv_canvas_window_to_world(GanvCanvas* canvas,
+ double winx, double winy, double* worldx, double* worldy);
+
+void ganv_canvas_world_to_window(GanvCanvas* canvas,
+ double worldx, double worldy, double* winx, double* winy);
+
void
ganv_canvas_resize(GanvCanvas* canvas, double width, double height);
void
ganv_canvas_contents_changed(GanvCanvas* canvas);
-/**
- * ganv_canvas_get_root:
- *
- * Return value: (transfer none): The root group of @canvas.
- */
-GanvItem*
-ganv_canvas_get_root(const GanvCanvas* canvas);
-
void
ganv_canvas_add_node(GanvCanvas* canvas,
GanvNode* node);
@@ -92,12 +214,6 @@ void
ganv_canvas_remove_node(GanvCanvas* canvas,
GanvNode* node);
-/**
- * ganv_canvas_get_edge:
- * Get the edge between two nodes, or NULL if none exists.
- *
- * Return value: (transfer none): The root group of @canvas.
- */
GanvEdge*
ganv_canvas_get_edge(GanvCanvas* canvas,
GanvNode* tail,
@@ -112,7 +228,6 @@ ganv_canvas_remove_edge_between(GanvCanvas* canvas,
GanvNode* tail,
GanvNode* head);
-/** Get the default font size in points. */
double
ganv_canvas_get_default_font_size(const GanvCanvas* canvas);
@@ -125,7 +240,6 @@ ganv_canvas_clear_selection(GanvCanvas* canvas);
void
ganv_canvas_arrange(GanvCanvas* canvas);
-/** Write a Graphviz DOT description of the canvas to @c filename. */
void
ganv_canvas_export_dot(GanvCanvas* canvas, const char* filename);
diff --git a/ganv/group.h b/ganv/group.h
index 4bde530..678eacf 100644
--- a/ganv/group.h
+++ b/ganv/group.h
@@ -18,6 +18,8 @@
#include "ganv/item.h"
+G_BEGIN_DECLS
+
/* Based on GnomeCanvasGroup, by Federico Mena <federico@nuclecu.unam.mx>
* and Raph Levien <raph@gimp.org>
* Copyright 1997-2000 Free Software Foundation
@@ -47,4 +49,6 @@ struct _GanvGroupClass {
GType ganv_group_get_type(void) G_GNUC_CONST;
+G_END_DECLS
+
#endif /* GANV_GROUP_H */
diff --git a/ganv/item.h b/ganv/item.h
index d75435a..6a77378 100644
--- a/ganv/item.h
+++ b/ganv/item.h
@@ -28,21 +28,6 @@
G_BEGIN_DECLS
-/**
- * GanvItem: Base class for all canvas items.
- *
- * All canvas items are derived from GanvItem. The only information a GanvItem
- * contains is its parent canvas, its parent canvas item, its bounding box in
- * world coordinates, and its current affine transformation.
- *
- * Items inside a canvas are organized in a tree, where leaves are items
- * without any children. Each canvas has a single root item, which can be
- * obtained with the ganv_canvas_base_get_root() function.
- *
- * The abstract GanvItem class does not have any configurable or queryable
- * attributes.
- */
-
typedef struct _GanvItem GanvItem;
typedef struct _GanvItemClass GanvItemClass;
@@ -67,7 +52,7 @@ struct _GanvItem {
GtkObject object;
/* Parent canvas for this item */
- struct _GanvCanvasBase* canvas;
+ struct _GanvCanvas* canvas;
/* Parent for this item */
GanvItem* parent;
@@ -88,18 +73,13 @@ struct _GanvItem {
struct _GanvItemClass {
GtkObjectClass parent_class;
- /**
- * Add a child to this item (optional).
- */
+ /* Add a child to this item (optional). */
void (*add)(GanvItem* item, GanvItem* child);
- /**
- * Remove a child from this item (optional).
- */
+ /* Remove a child from this item (optional). */
void (*remove)(GanvItem* item, GanvItem* child);
- /**
- * Tell the item to update itself.
+ /* 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
@@ -108,28 +88,19 @@ struct _GanvItemClass {
*/
void (*update)(GanvItem* item, int flags);
- /**
- * Realize an item (create GCs, etc.).
- */
+ /* Realize an item (create GCs, etc.). */
void (*realize)(GanvItem* item);
- /**
- * Unrealize an item.
- */
+ /* Unrealize an item. */
void (*unrealize)(GanvItem* item);
- /**
- * Map an item - normally only need by items with their own GdkWindows.
- */
+ /* Map an item - normally only need by items with their own GdkWindows. */
void (*map)(GanvItem* item);
- /**
- * Unmap an item
- */
+ /* Unmap an item */
void (*unmap)(GanvItem* item);
- /**
- * Draw an item of this type.
+ /* Draw an item of this type.
*
* (x, y) are the upper-left canvas pixel coordinates of the drawable.
* (width, height) are the dimensions of the drawable.
@@ -141,8 +112,7 @@ struct _GanvItemClass {
int width,
int height);
- /**
- * Calculate the distance from an item to the specified point.
+ /* Calculate the distance from an item to the specified point.
*
* It also 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
@@ -156,15 +126,13 @@ struct _GanvItemClass {
int cy,
GanvItem** actual_item);
- /**
- * Fetch the item's bounding box (need not be exactly tight).
+ /* 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.
+ /* Signal: an event occurred for an item of this type.
*
* The (x, y) coordinates are in the canvas world coordinate system.
*/