diff --git a/foocanvas/additional_files/Makefile.am.patch b/foocanvas/additional_files/Makefile.am.patch deleted file mode 100755 index 64a785631ca145eaf48a5615276598dadae8fe8d..0000000000000000000000000000000000000000 --- a/foocanvas/additional_files/Makefile.am.patch +++ /dev/null @@ -1,23 +0,0 @@ -Index: Makefile.am -=================================================================== -RCS file: /cvs/gnome/foocanvas/libfoocanvas/Makefile.am,v -retrieving revision 1.8 -diff -u -w -r1.8 Makefile.am ---- Makefile.am 1 Apr 2005 10:44:08 -0000 1.8 -+++ Makefile.am 18 Oct 2006 18:17:41 -0000 -@@ -22,6 +22,7 @@ - - libfoocanvasinclude_HEADERS = \ - foo-canvas-line.h \ -+ foozmap-canvas-line-glyph.h \ - foo-canvas-pixbuf.h \ - foo-canvas-polygon.h \ - foo-canvas-rect-ellipse.h \ -@@ -36,6 +37,7 @@ - foo-canvas-marshal.list \ - foo-canvas-i18n.h \ - foo-canvas-line.c \ -+ foozmap-canvas-line-glyph.c \ - foo-canvas-pixbuf.c \ - foo-canvas-polygon.c \ - foo-canvas-rect-ellipse.c \ diff --git a/foocanvas/additional_files/build.patch b/foocanvas/additional_files/build.patch deleted file mode 100755 index 62116b0557b923b80c9a744e1449a5117231eae0..0000000000000000000000000000000000000000 --- a/foocanvas/additional_files/build.patch +++ /dev/null @@ -1,53 +0,0 @@ -? COPYING -? INSTALL -? depcomp -? gtk-doc.make -? install-sh -? missing -? mkinstalldirs -? demos/.deps -? demos/.libs -? libfoocanvas/.deps -? libfoocanvas/.libs -? libfoocanvas/foo-canvas-line.lo -? libfoocanvas/foo-canvas-marshal.lo -? libfoocanvas/foo-canvas-pixbuf.lo -? libfoocanvas/foo-canvas-polygon.lo -? libfoocanvas/foo-canvas-rect-ellipse.lo -? libfoocanvas/foo-canvas-text.lo -? libfoocanvas/foo-canvas-util.lo -? libfoocanvas/foo-canvas-widget.lo -? libfoocanvas/foo-canvas.lo -? libfoocanvas/libfoocanvas.la -? libfoocanvas/libfoocanvastypes.lo -? po/Makefile.in.in -Index: autogen.sh -=================================================================== -RCS file: /cvs/gnome/foocanvas/autogen.sh,v -retrieving revision 1.2 -diff -u -r1.2 autogen.sh ---- autogen.sh 21 Feb 2005 12:18:37 -0000 1.2 -+++ autogen.sh 26 Mar 2006 13:12:40 -0000 -@@ -41,5 +41,5 @@ - exit 1 - fi - --REQUIRED_AUTOMAKE_VERSION=1.5 -+REQUIRED_AUTOMAKE_VERSION=1.9 - GNOME_DATADIR="$gnome_datadir" USE_GNOME2_MACROS=1 . $gnome_autogen -Index: configure.in -=================================================================== -RCS file: /cvs/gnome/foocanvas/configure.in,v -retrieving revision 1.7 -diff -u -r1.7 configure.in ---- configure.in 18 Sep 2005 20:18:11 -0000 1.7 -+++ configure.in 26 Mar 2006 13:12:41 -0000 -@@ -3,7 +3,7 @@ - AC_CONFIG_SRCDIR([libfoocanvas/foo-canvas.c]) - - AC_CONFIG_HEADERS([config.h]) --AM_INIT_AUTOMAKE([dist-bz2]) -+AM_INIT_AUTOMAKE([]) - - AM_MAINTAINER_MODE - diff --git a/foocanvas/additional_files/foozmap-canvas-floating-group.c b/foocanvas/additional_files/foozmap-canvas-floating-group.c deleted file mode 100755 index 1f2463d992c3aaa44dde64a4ad9b85714e40ecc3..0000000000000000000000000000000000000000 --- a/foocanvas/additional_files/foozmap-canvas-floating-group.c +++ /dev/null @@ -1,449 +0,0 @@ -/* File: foozmap-canvas-floating-group.c - * Author: Roy Storey (rds@sanger.ac.uk) - * Copyright (c) 2008: Genome Research Ltd. - *------------------------------------------------------------------- - * ZMap 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 2 - * of the License, or (at your option) any later version. - * - * This program 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 more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * or see the on-line version at http://www.gnu.org/copyleft/gpl.txt - *------------------------------------------------------------------- - * This file is part of the ZMap genome database package - * originally written by: - * - * Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk, - * Roy Storey (Sanger Institute, UK) rds@sanger.ac.uk - * - * Description: - * - * Exported functions: See XXXXXXXXXXXXX.h - * HISTORY: - * Last edited: Mar 23 16:47 2008 (rds) - * Created: Thu Jan 24 08:36:25 2008 (rds) - * CVS info: $Id: foozmap-canvas-floating-group.c,v 1.3 2008-03-23 16:49:04 rds Exp $ - *------------------------------------------------------------------- - */ - - -#include "foozmap-canvas-floating-group.h" - -enum - { - PROP_0, - PROP_FLOAT_MIN_X, - PROP_FLOAT_MAX_X, - PROP_FLOAT_MIN_Y, - PROP_FLOAT_MAX_Y, - PROP_FLOAT_AXIS - }; - -static void foo_canvas_float_group_class_init (FooCanvasFloatGroupClass *class); -static void foo_canvas_float_group_init (FooCanvasFloatGroup *group); -static void foo_canvas_float_group_set_property (GObject *gobject, guint param_id, - const GValue *value, GParamSpec *pspec); -static void foo_canvas_float_group_get_property(GObject *gobject, guint param_id, - GValue *value, GParamSpec *pspec); -static void foo_canvas_float_group_destroy(GtkObject *object); -static void foo_canvas_float_group_realize (FooCanvasItem *item); -static void foo_canvas_float_group_draw(FooCanvasItem *item, - GdkDrawable *drawable, - GdkEventExpose *expose); -static void foo_canvas_float_group_update(FooCanvasItem *item, - double i2w_dx, - double i2w_dy, - int flags); -static void save_scroll_region(FooCanvasItem *item); -static GType float_group_axis_get_type (void); - - -static FooCanvasItemClass *parent_class_G; - -/** - * foo_canvas_float_group_get_type: - * - * Registers the &FooCanvasGroup class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &FooCanvasGroup class. - **/ -GType -foo_canvas_float_group_get_type (void) -{ - static GType group_type = 0; - - if (!group_type) { - static const GTypeInfo group_info = { - sizeof (FooCanvasFloatGroupClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) foo_canvas_float_group_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (FooCanvasFloatGroup), - 0, /* n_preallocs */ - (GInstanceInitFunc) foo_canvas_float_group_init - - - }; - - group_type = g_type_register_static (foo_canvas_group_get_type (), - "FooCanvasFloatGroup", - &group_info, - 0); - } - - return group_type; -} - -/* Class initialization function for FooCanvasGroupClass */ -static void foo_canvas_float_group_class_init (FooCanvasFloatGroupClass *class) -{ - GObjectClass *gobject_class; - GtkObjectClass *object_class; - FooCanvasItemClass *item_class; - - gobject_class = (GObjectClass *) class; - object_class = (GtkObjectClass *) class; - item_class = (FooCanvasItemClass *) class; - - parent_class_G = gtk_type_class (foo_canvas_group_get_type ()); - - gobject_class->set_property = foo_canvas_float_group_set_property; - gobject_class->get_property = foo_canvas_float_group_get_property; - - g_object_class_install_property(gobject_class, - PROP_FLOAT_MIN_X, - g_param_spec_double("min-x", - NULL, NULL, - -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - g_object_class_install_property(gobject_class, - PROP_FLOAT_MAX_X, - g_param_spec_double("max-x", - NULL, NULL, - -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - g_object_class_install_property(gobject_class, - PROP_FLOAT_MIN_Y, - g_param_spec_double("min-y", - NULL, NULL, - -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - g_object_class_install_property(gobject_class, - PROP_FLOAT_MAX_Y, - g_param_spec_double("max-y", - NULL, NULL, - -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - g_object_class_install_property(gobject_class, - PROP_FLOAT_AXIS, - g_param_spec_enum ("float-axis", NULL, NULL, - float_group_axis_get_type(), - ZMAP_FLOAT_AXIS_Y, - G_PARAM_READWRITE)); - - - object_class->destroy = foo_canvas_float_group_destroy; - - item_class->draw = foo_canvas_float_group_draw; - item_class->update = foo_canvas_float_group_update; - item_class->realize = foo_canvas_float_group_realize; - - return ; -} - -/* Object initialization function for FooCanvasGroup */ -static void foo_canvas_float_group_init (FooCanvasFloatGroup *group) -{ - FooCanvasItem *item; - - item = FOO_CANVAS_ITEM(group); - - group->zoom_x = 0.0; - group->zoom_y = 0.0; - group->scr_x1 = 0.0; - group->scr_y1 = 0.0; - group->scr_x2 = 0.0; - group->scr_y2 = 0.0; - - if(item->canvas) - { - group->zoom_x = item->canvas->pixels_per_unit_x; - group->zoom_y = item->canvas->pixels_per_unit_y; - } - - /* y axis only! */ - group->float_axis = ZMAP_FLOAT_AXIS_Y; - - return ; -} - -/* Set_property handler for canvas groups */ -static void foo_canvas_float_group_set_property (GObject *gobject, guint param_id, - const GValue *value, GParamSpec *pspec) -{ - FooCanvasFloatGroup *group; - double d; - - group = FOO_CANVAS_FLOAT_GROUP(gobject); - - switch (param_id) - { - case PROP_FLOAT_MIN_X: - group->scr_x1 = g_value_get_double (value); - foo_canvas_item_i2w(FOO_CANVAS_ITEM(gobject), &(group->scr_x1), &d); - group->min_x_set = TRUE; - break; - case PROP_FLOAT_MAX_X: - group->scr_x2 = g_value_get_double (value); - foo_canvas_item_i2w(FOO_CANVAS_ITEM(gobject), &(group->scr_x2), &d); - group->max_x_set = TRUE; - break; - case PROP_FLOAT_MIN_Y: - group->scr_y1 = g_value_get_double (value); - foo_canvas_item_i2w(FOO_CANVAS_ITEM(gobject), &d, &(group->scr_y1)); - group->min_y_set = TRUE; - break; - case PROP_FLOAT_MAX_Y: - group->scr_y2 = g_value_get_double (value); - foo_canvas_item_i2w(FOO_CANVAS_ITEM(gobject), &d, &(group->scr_y2)); - group->max_y_set = TRUE; - break; - case PROP_FLOAT_AXIS: - { - int axis = g_value_get_enum(value); - group->float_axis = axis; - } - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec); - break; - } - - return ; -} - -/* Get_property handler for canvas groups */ -static void foo_canvas_float_group_get_property(GObject *gobject, guint param_id, - GValue *value, GParamSpec *pspec) -{ - switch (param_id) - { - case PROP_FLOAT_MIN_X: - break; - case PROP_FLOAT_MAX_X: - break; - case PROP_FLOAT_MIN_Y: - break; - case PROP_FLOAT_MAX_Y: - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec); - break; - } - - return ; -} - - -static void foo_canvas_float_group_destroy(GtkObject *object) -{ - - if(GTK_OBJECT_CLASS(parent_class_G)->destroy) - (* GTK_OBJECT_CLASS(parent_class_G)->destroy)(object); - return ; -} - -static void foo_canvas_float_group_realize (FooCanvasItem *item) -{ - FooCanvasFloatGroup *group; - - group = FOO_CANVAS_FLOAT_GROUP(item); - - if(item->canvas) - { - group->zoom_x = item->canvas->pixels_per_unit_x; - group->zoom_y = item->canvas->pixels_per_unit_y; - save_scroll_region(item); - } - - if (parent_class_G->realize) - (* parent_class_G->realize) (item); -} - -/* Draw handler for canvas groups */ -static void foo_canvas_float_group_draw(FooCanvasItem *item, - GdkDrawable *drawable, - GdkEventExpose *expose) -{ - FooCanvasFloatGroup *floating; - FooCanvasGroup *group; - double x1, x2, y1, y2, xpos, ypos; - - group = FOO_CANVAS_GROUP (item); - floating = FOO_CANVAS_FLOAT_GROUP(item); - - /* If the group x,y is outside the scroll region, move it back in! */ - foo_canvas_get_scroll_region(item->canvas, &x1, &y1, &x2, &y2); - xpos = group->xpos; - ypos = group->ypos; - /* convert x,y position to world coord space */ - foo_canvas_item_i2w(item, &xpos, &ypos); - - /* round down to whole bases... We need to do this in a few places! */ - x1 = (double)((int)x1); - y1 = (double)((int)y1); - - /* conditionally update the x,y position of the group */ - if((floating->float_axis & ZMAP_FLOAT_AXIS_X) && (xpos != x1)) - xpos = ((x1 > floating->scr_x1) ? - (x1) : - (double)((int)(floating->scr_x1))); - if((floating->float_axis & ZMAP_FLOAT_AXIS_Y) && (ypos != y1)) - ypos = ((y1 > floating->scr_y1) ? - (y1) : - (double)((int)(floating->scr_y1))); - - /* convert back to item coord space */ - foo_canvas_item_w2i(item, &xpos, &ypos); - - /* actually move the group [if necessary] */ - if(xpos != group->xpos || ypos != group->ypos) - { - /* round down. If no floating is happening... */ - xpos = (double)((int)xpos); - ypos = (double)((int)ypos); - - g_object_set(G_OBJECT(item), "x", xpos, "y", ypos, NULL); - } - - /* parent->draw? */ - if(parent_class_G->draw) - (*parent_class_G->draw)(item, drawable, expose); - - return ; -} - -static void foo_canvas_float_group_update(FooCanvasItem *item, - double i2w_dx, - double i2w_dy, - int flags) -{ - FooCanvasFloatGroup *group; - gboolean force_intersect = TRUE; - - group = FOO_CANVAS_FLOAT_GROUP(item); - - if(parent_class_G->update) - (*parent_class_G->update)(item, i2w_dx, i2w_dy, flags); - - if(force_intersect && (item->object.flags & FOO_CANVAS_ITEM_VISIBLE)) - { - int cx1, cx2, cy1, cy2; - - foo_canvas_w2c(item->canvas, group->scr_x1, group->scr_y1, &cx1, &cy1); - foo_canvas_w2c(item->canvas, group->scr_x2, group->scr_y2, &cx2, &cy2); - - /* These must be set in order to make the group intersect with any - * rectangle within the whole of the scroll region */ - if(group->float_axis & ZMAP_FLOAT_AXIS_X) - { - item->x1 = cx1; //group->scr_x1; - item->x2 = cx2; //group->scr_x2; - } - if(group->float_axis & ZMAP_FLOAT_AXIS_Y) - { - item->y1 = cy1; //group->scr_y1; - item->y2 = cy2; //group->scr_y2; - } - } - - /* unfortunately we need to run through this again :o( */ - if(item->object.flags & FOO_CANVAS_ITEM_VISIBLE) - { - FooCanvasGroup *real_group = FOO_CANVAS_GROUP(item); - FooCanvasItem *i; - GList *list; - for (list = real_group->item_list; list; list = list->next) - { - i = list->data; - if(FOO_CANVAS_ITEM_GET_CLASS(i)->update) - FOO_CANVAS_ITEM_GET_CLASS(i)->update(i, i2w_dx, i2w_dy, flags); - item->x1 = MIN(item->x1, i->x1); - item->y1 = MIN(item->y1, i->y1); - item->x2 = MAX(item->x2, i->x2); - item->y2 = MAX(item->y2, i->y2); - } - } - - return ; -} - -static void save_scroll_region(FooCanvasItem *item) -{ - FooCanvasFloatGroup *group; - double x1, y1, x2, y2; - double *x1_ptr, *y1_ptr, *x2_ptr, *y2_ptr; - - group = FOO_CANVAS_FLOAT_GROUP(item); - - foo_canvas_get_scroll_region(item->canvas, &x1, &y1, &x2, &y2); - - x1_ptr = &(group->scr_x1); - y1_ptr = &(group->scr_y1); - x2_ptr = &(group->scr_x2); - y2_ptr = &(group->scr_y2); - - if(item->canvas->pixels_per_unit_x <= group->zoom_x) - { - if(!group->min_x_set) - group->scr_x1 = x1; - else - x1_ptr = &x1; - if(!group->max_x_set) - group->scr_x2 = x2; - else - x2_ptr = &x2; - } - - if(item->canvas->pixels_per_unit_y <= group->zoom_y) - { - if(!group->min_y_set) - group->scr_y1 = y1; - else - y1_ptr = &y1; - if(!group->max_y_set) - group->scr_y2 = y2; - else - y2_ptr = &y2; - } - - foo_canvas_item_w2i(item, x1_ptr, y1_ptr); - foo_canvas_item_w2i(item, x2_ptr, y2_ptr); - - return ; -} - - -static GType float_group_axis_get_type (void) -{ - static GType etype = 0; - if (etype == 0) { - static const GEnumValue values[] = { - { ZMAP_FLOAT_AXIS_X, "ZMAP_FLOAT_AXIS_X", "x-axis" }, - { ZMAP_FLOAT_AXIS_Y, "ZMAP_FLOAT_AXIS_Y", "y-axis" }, - { 0, NULL, NULL } - }; - etype = g_enum_register_static ("FooCanvasFloatGroupAxis", values); - } - return etype; -} diff --git a/foocanvas/additional_files/foozmap-canvas-floating-group.h b/foocanvas/additional_files/foozmap-canvas-floating-group.h deleted file mode 100755 index 57ac0a04f58b44d313350bdd0495497b26f67ca3..0000000000000000000000000000000000000000 --- a/foocanvas/additional_files/foozmap-canvas-floating-group.h +++ /dev/null @@ -1,89 +0,0 @@ -/* File: foozmap-canvas-floating-group.h - * Author: Roy Storey (rds@sanger.ac.uk) - * Copyright (c) 2008: Genome Research Ltd. - *------------------------------------------------------------------- - * ZMap 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 2 - * of the License, or (at your option) any later version. - * - * This program 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 more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * or see the on-line version at http://www.gnu.org/copyleft/gpl.txt - *------------------------------------------------------------------- - * This file is part of the ZMap genome database package - * originally written by: - * - * Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk, - * Roy Storey (Sanger Institute, UK) rds@sanger.ac.uk - * - * Description: - * - * Exported functions: See XXXXXXXXXXXXX.h - * HISTORY: - * Last edited: Jan 25 09:59 2008 (rds) - * Created: Thu Jan 24 08:39:05 2008 (rds) - * CVS info: $Id: foozmap-canvas-floating-group.h,v 1.1 2008-03-11 10:28:42 rds Exp $ - *------------------------------------------------------------------- - */ - -#ifndef FOO_CANVAS_FLOAT_GROUP_H -#define FOO_CANVAS_FLOAT_GROUP_H - -#include <libfoocanvas/foo-canvas.h> - -G_BEGIN_DECLS - -/* Extended FooCanvasGroup */ - -enum -{ - ZMAP_FLOAT_AXIS_NONE = 0, - ZMAP_FLOAT_AXIS_X = 1, - ZMAP_FLOAT_AXIS_Y = 2 -}; - -#define FOO_TYPE_CANVAS_FLOAT_GROUP (foo_canvas_float_group_get_type ()) -#define FOO_CANVAS_FLOAT_GROUP(obj) (GTK_CHECK_CAST ((obj), FOO_TYPE_CANVAS_FLOAT_GROUP, FooCanvasFloatGroup)) -#define FOO_CANVAS_FLOAT_GROUP_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), FOO_TYPE_CANVAS_FLOAT_GROUP, FooCanvasFloatGroupClass)) -#define FOO_IS_CANVAS_FLOAT_GROUP(obj) (GTK_CHECK_TYPE ((obj), FOO_TYPE_CANVAS_FLOAT_GROUP)) -#define FOO_IS_CANVAS_FLOAT_GROUP_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), FOO_TYPE_CANVAS_FLOAT_GROUP)) -#define FOO_CANVAS_FLOAT_GROUP_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), FOO_TYPE_CANVAS_FLOAT_GROUP, FooCanvasFloatGroupClass)) - -typedef struct _FooCanvasFloatGroup FooCanvasFloatGroup; -typedef struct _FooCanvasFloatGroupClass FooCanvasFloatGroupClass; - -struct _FooCanvasFloatGroup -{ - FooCanvasGroup group; - - double zoom_x, zoom_y; - /* world coords scroll region, also sets min/max x/y positions */ - double scr_x1, scr_y1, scr_x2, scr_y2; - - unsigned int min_x_set : 1; - unsigned int max_x_set : 1; - unsigned int min_y_set : 1; - unsigned int max_y_set : 1; - - unsigned int float_axis : 2; -}; - -struct _FooCanvasFloatGroupClass -{ - FooCanvasItemClass parent_class; -}; - - -/* Standard Gtk function */ -GType foo_canvas_float_group_get_type (void) G_GNUC_CONST; - -G_END_DECLS - -#endif diff --git a/foocanvas/additional_files/foozmap-canvas-line-glyph.c b/foocanvas/additional_files/foozmap-canvas-line-glyph.c deleted file mode 100755 index e72dba2a51aaa5ca3441eb15841586dc54a52ed2..0000000000000000000000000000000000000000 --- a/foocanvas/additional_files/foozmap-canvas-line-glyph.c +++ /dev/null @@ -1,1480 +0,0 @@ -/* Last edited: Oct 3 14:00 2006 (edgrif) */ -/* - * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation - * All rights reserved. - * - * This file is part of the Gnome Library. - * - * The Gnome Library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * The Gnome Library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with the Gnome Library; see the file COPYING.LIB. If not, - * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -/* - @NOTATION@ - */ - - -/* This code is all over the place, it works for the simple stick shaped glyphs - * but nothing else. Lots of stuff is #defined out and it all needs some sorting - * out. */ - - - -/* Glyphs made from lines, they are constant scale so show at all zoom levels. - * - * FooCanvas is basically a port of the Tk toolkit's most excellent canvas widget. Tk is - * copyrighted by the Regents of the University of California, Sun Microsystems, and other parties. - * - * - * Author: Ed Griffiths <edgrif@sanger.ac.uk> - */ - -#include <config.h> -#include <math.h> -#include <string.h> -#include "libfoocanvas.h" -#include "foozmap-canvas-line-glyph.h" - -#define noVERBOSE - -#define NUM_STATIC_POINTS 256 /* number of static points to use to avoid allocating arrays */ - - -#define GROW_BOUNDS(bx1, by1, bx2, by2, x, y) { \ - if (x < bx1) \ - bx1 = x; \ - \ - if (x > bx2) \ - bx2 = x; \ - \ - if (y < by1) \ - by1 = y; \ - \ - if (y > by2) \ - by2 = y; \ -} - - -enum { - PROP_0, - PROP_X, - PROP_Y, - PROP_POINTS, - PROP_FILL_COLOR, - PROP_FILL_COLOR_GDK, - PROP_FILL_COLOR_RGBA, - PROP_FILL_STIPPLE, - PROP_WIDTH_PIXELS, - PROP_CAP_STYLE, - PROP_JOIN_STYLE, - PROP_LINE_STYLE -}; - - -static void foo_canvas_line_glyph_class_init (FooCanvasLineGlyphClass *class_glyph); -static void foo_canvas_line_glyph_init (FooCanvasLineGlyph *line_glyph); -static void foo_canvas_line_glyph_destroy (GtkObject *object); -static void foo_canvas_line_glyph_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); -static void foo_canvas_line_glyph_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); - -static void foo_canvas_line_glyph_update (FooCanvasItem *item, - double i2w_dx, double i2w_dy, - int flags); -static void foo_canvas_line_glyph_realize (FooCanvasItem *item); -static void foo_canvas_line_glyph_unrealize (FooCanvasItem *item); -static void foo_canvas_line_glyph_draw (FooCanvasItem *item, GdkDrawable *drawable, - GdkEventExpose *event); -static double foo_canvas_line_glyph_point (FooCanvasItem *item, double x, double y, - int cx, int cy, FooCanvasItem **actual_item); -static void foo_canvas_line_glyph_translate (FooCanvasItem *item, double dx, double dy); -static void foo_canvas_line_glyph_bounds (FooCanvasItem *item, double *x1, double *y1, double *x2, double *y2); - - -static FooCanvasItemClass *parent_class; - - -GtkType -foo_canvas_line_glyph_get_type (void) -{ - static GtkType line_type = 0; - - if (!line_type) { - /* FIXME: Convert to gobject style. */ - static const GtkTypeInfo line_info = { - (char *)"FooCanvasLineGlyph", - sizeof (FooCanvasLineGlyph), - sizeof (FooCanvasLineGlyphClass), - (GtkClassInitFunc) foo_canvas_line_glyph_class_init, - (GtkObjectInitFunc) foo_canvas_line_glyph_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - line_type = gtk_type_unique (foo_canvas_item_get_type (), &line_info); - } - - return line_type; -} - -static void -foo_canvas_line_glyph_class_init (FooCanvasLineGlyphClass *class) -{ - GObjectClass *gobject_class; - GtkObjectClass *object_class; - FooCanvasItemClass *item_class; - - gobject_class = (GObjectClass *) class; - object_class = (GtkObjectClass *) class; - item_class = (FooCanvasItemClass *) class; - - parent_class = gtk_type_class (foo_canvas_item_get_type ()); - - gobject_class->set_property = foo_canvas_line_glyph_set_property; - gobject_class->get_property = foo_canvas_line_glyph_get_property; - - g_object_class_install_property - (gobject_class, - PROP_X, - g_param_spec_double ("x", NULL, NULL, - -G_MAXDOUBLE, G_MAXDOUBLE, 0, - G_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, - PROP_Y, - g_param_spec_double ("y", NULL, NULL, - -G_MAXDOUBLE, G_MAXDOUBLE, 0, - G_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, - PROP_POINTS, - g_param_spec_boxed ("points", NULL, NULL, - FOO_TYPE_CANVAS_POINTS, - G_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, - PROP_FILL_COLOR, - g_param_spec_string ("fill-color", NULL, NULL, - NULL, - G_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, - PROP_FILL_COLOR_GDK, - g_param_spec_boxed ("fill-color-gdk", NULL, NULL, - GDK_TYPE_COLOR, - G_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, - PROP_FILL_COLOR_RGBA, - g_param_spec_uint ("fill-color-rgba", NULL, NULL, - 0, G_MAXUINT, 0, - G_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, - PROP_FILL_STIPPLE, - g_param_spec_object ("fill-stipple", NULL, NULL, - GDK_TYPE_DRAWABLE, - G_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, - PROP_WIDTH_PIXELS, - g_param_spec_uint ("width-pixels", NULL, NULL, - 0, G_MAXUINT, 0, - G_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, - PROP_CAP_STYLE, - g_param_spec_enum ("cap-style", NULL, NULL, - GDK_TYPE_CAP_STYLE, - GDK_CAP_BUTT, - G_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, - PROP_JOIN_STYLE, - g_param_spec_enum ("join-style", NULL, NULL, - GDK_TYPE_JOIN_STYLE, - GDK_JOIN_MITER, - G_PARAM_READWRITE)); - g_object_class_install_property - (gobject_class, - PROP_LINE_STYLE, - g_param_spec_enum ("line-style", NULL, NULL, - GDK_TYPE_LINE_STYLE, - GDK_LINE_SOLID, - G_PARAM_READWRITE)); - - object_class->destroy = foo_canvas_line_glyph_destroy; - - item_class->update = foo_canvas_line_glyph_update; - item_class->realize = foo_canvas_line_glyph_realize; - item_class->unrealize = foo_canvas_line_glyph_unrealize; - item_class->draw = foo_canvas_line_glyph_draw; - item_class->point = foo_canvas_line_glyph_point; - item_class->translate = foo_canvas_line_glyph_translate; - item_class->bounds = foo_canvas_line_glyph_bounds; -} - -static void -foo_canvas_line_glyph_init (FooCanvasLineGlyph *line) -{ - line->x = line->y = 0.0 ; - line->width = 0.0; - line->cap = GDK_CAP_BUTT; - line->join = GDK_JOIN_MITER; - line->line_style = GDK_LINE_SOLID; -} - -static void -foo_canvas_line_glyph_destroy (GtkObject *object) -{ - FooCanvasLineGlyph *line; - - g_return_if_fail (object != NULL); - g_return_if_fail (FOO_IS_CANVAS_LINE_GLYPH (object)); - - line = FOO_CANVAS_LINE_GLYPH (object); - - /* remember, destroy can be run multiple times! */ - - if (line->coords) - g_free (line->coords); - line->coords = NULL; - - if (line->stipple) - g_object_unref (line->stipple); - line->stipple = NULL; - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE -/* Computes the bounding box of the glyph. Assumes that the number of - * points in the line is not zero. - */ -static void -get_bounds (FooCanvasLineGlyph *line, double *bx1, double *by1, double *bx2, double *by2) -{ - double *coords; - double x1, y1, x2, y2; - double width; - int i; - - if (!line->coords) { - *bx1 = *by1 = *bx2 = *by2 = 0.0; - return; - } - - /* Find bounding box of line's points */ - - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE - x1 = x2 = line->coords[0]; - y1 = y2 = line->coords[1]; - - for (i = 1, coords = line->coords + 2; i < line->num_points; i++, coords += 2) - GROW_BOUNDS (x1, y1, x2, y2, coords[0], coords[1]); -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - - - x1 = x2 = line->x + line->coords[0]; - y1 = y2 = line->y + line->coords[1]; - - for (i = 1, coords = line->coords + 2; i < line->num_points; i++, coords += 2) - GROW_BOUNDS (x1, y1, x2, y2, line->x + coords[0], line->y + coords[1]); - - - - /* Add possible over-estimate for wide lines */ -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE - if (line->width_pixels) - width = line->width / line->item.canvas->pixels_per_unit_x; - else - width = line->width; -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - width = line->width / line->item.canvas->pixels_per_unit_x; - - - x1 -= width; - y1 -= width; - x2 += width; - y2 += width; - - - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE - /* Forget this for now.... */ - - /* For mitered lines, make a second pass through all the points. Compute the location of - * the two miter vertex points and add them to the bounding box. - */ - - if (line->join == GDK_JOIN_MITER) - for (i = line->num_points, coords = line->coords; i >= 3; i--, coords += 2) { - double mx1, my1, mx2, my2; - - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE - if (foo_canvas_get_miter_points (coords[0], coords[1], - coords[2], coords[3], - coords[4], coords[5], - width, - &mx1, &my1, &mx2, &my2)) { - GROW_BOUNDS (x1, y1, x2, y2, mx1, my1); - GROW_BOUNDS (x1, y1, x2, y2, mx2, my2); - } -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - - - if (foo_canvas_get_miter_points (line->x + coords[0], line->y + coords[1], - line->x + coords[2], line->y + coords[3], - line->x + coords[4], line->y + coords[5], - width, - &mx1, &my1, &mx2, &my2)) { - GROW_BOUNDS (x1, y1, x2, y2, mx1, my1); - GROW_BOUNDS (x1, y1, x2, y2, mx2, my2); - } - - - } -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - - - /* Done */ - - *bx1 = x1; - *by1 = y1; - *bx2 = x2; - *by2 = y2; - -} -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - -/* Computes the bounding box of the glyph. Assumes that the number of - * points in the line is not zero. - */ -static void -get_bounds (FooCanvasLineGlyph *line, double *bx1, double *by1, double *bx2, double *by2) -{ - double *coords; - double x1, y1, x2, y2; - double width; - - if (!line->coords) { - *bx1 = *by1 = *bx2 = *by2 = 0.0; - return; - } - - /* Find bounding box of line's points */ - /* extract topleft/botright.... */ - coords = line->coords; - x1 = line->x + coords[0]; - x2 = line->x + coords[2]; - if (coords[5] < coords[3]) - { - y1 = line->y + coords[5]; - y2 = line->y + coords[3]; - } - else - { - y1 = line->y + coords[3]; - y2 = line->y + coords[5]; - } - - - /* Add possible over-estimate for wide lines */ -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE - if (line->width_pixels) - width = line->width / line->item.canvas->pixels_per_unit_x; - else - width = line->width; -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - width = line->width / line->item.canvas->pixels_per_unit_x; - - x1 -= width; - y1 -= width; - x2 += width; - y2 += width; - - -#ifdef VERBOSE - printf("get_bounds %g, %g ---> %g, %g\n", x1, y1, x2, y2) ; -#endif - - - /* Done */ - - *bx1 = x1; - *by1 = y1; - *bx2 = x2; - *by2 = y2; - -} - - - - -/* Computes the bounding box of the line, in canvas coordinates. Assumes that the number of points in the polygon is - * not zero. - */ -static void -get_bounds_canvas (FooCanvasLineGlyph *line, - double *bx1, double *by1, double *bx2, double *by2, - double i2w_dx, double i2w_dy) -{ - FooCanvasItem *item; - double bbox_x0, bbox_y0, bbox_x1, bbox_y1; - double glyph_x, glyph_y ; - double width, height ; - double *coords; - - item = FOO_CANVAS_ITEM (line); - - get_bounds (line, &bbox_x0, &bbox_y0, &bbox_x1, &bbox_y1); - - bbox_x0 += i2w_dx; - bbox_y0 += i2w_dy; - bbox_x1 += i2w_dx; - bbox_y1 += i2w_dy; - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE - /* You can't just do this as it scales everything. */ - foo_canvas_w2c_rect_d (item->canvas, - &bbox_x0, &bbox_y0, &bbox_x1, &bbox_y1); -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - - /* Calculate position of glyph in its group.... */ - foo_canvas_w2c_d (item->canvas, - line->x + i2w_dx, - line->y + i2w_dy, - &glyph_x, &glyph_y); - - width = bbox_x1 - bbox_x0 ; - height = bbox_y1 - bbox_y0 ; - - bbox_x0 = glyph_x; - bbox_x1 = glyph_x + width; - - /* Have to take account of whether box is up or down. */ - coords = line->coords; - if (coords[5] > coords[3]) - { - bbox_y0 = glyph_y; - bbox_y1 = glyph_y + height; - } - else - { - bbox_y0 = glyph_y - height; - bbox_y1 = glyph_y; - } - - /* include 1 pixel of fudge */ - *bx1 = bbox_x0 - 1; - *by1 = bbox_y0 - 1; - *bx2 = bbox_x1 + 1; - *by2 = bbox_y1 + 1; -} - - - -/* Convenience function to set the line's GC's foreground color */ -static void -set_line_glyph_gc_foreground (FooCanvasLineGlyph *line) -{ - GdkColor c; - - if (!line->gc) - return; - - c.pixel = line->fill_pixel; - gdk_gc_set_foreground (line->gc, &c); -} - -/* Recalculate the line's width and set it in its GC */ -static void -set_line_glyph_gc_width (FooCanvasLineGlyph *line) -{ - int width; - - if (!line->gc) - return; - - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE - if (line->width_pixels) - width = (int) line->width; - else - width = (int) (line->width * line->item.canvas->pixels_per_unit_x + 0.5); -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - width = (int) line->width; - - gdk_gc_set_line_attributes (line->gc, - width, - line->line_style, - line->cap, - line->join); -} - -/* Sets the stipple pattern for the line */ -static void -set_stipple (FooCanvasLineGlyph *line, GdkBitmap *stipple, int reconfigure) -{ - if (line->stipple && !reconfigure) - g_object_unref (line->stipple); - - line->stipple = stipple; - if (stipple && !reconfigure) - g_object_ref (stipple); - - if (line->gc) { - if (stipple) { - gdk_gc_set_stipple (line->gc, stipple); - gdk_gc_set_fill (line->gc, GDK_STIPPLED); - } else - gdk_gc_set_fill (line->gc, GDK_SOLID); - } -} - -static void -foo_canvas_line_glyph_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - FooCanvasItem *item; - FooCanvasLineGlyph *line; - FooCanvasPoints *points; - GdkColor color = { 0, 0, 0, 0, }; - GdkColor *pcolor; - gboolean color_changed; - int have_pixel; - - g_return_if_fail (object != NULL); - g_return_if_fail (FOO_IS_CANVAS_LINE_GLYPH (object)); - - item = FOO_CANVAS_ITEM (object); - line = FOO_CANVAS_LINE_GLYPH (object); - - color_changed = FALSE; - have_pixel = FALSE; - - switch (param_id) { - case PROP_X: - line->x = g_value_get_double (value); - - foo_canvas_item_request_update (item); - break; - - case PROP_Y: - line->y = g_value_get_double (value); - - foo_canvas_item_request_update (item); - break; - - case PROP_POINTS: - points = g_value_get_boxed (value); - - - if (line->coords) { - g_free (line->coords); - line->coords = NULL; - } - - if (!points) - line->num_points = 0; - else { - line->num_points = points->num_points; - line->coords = g_new (double, 2 * line->num_points); - memcpy (line->coords, points->coords, 2 * line->num_points * sizeof (double)); - } - - - - /* Since the line's points have changed, we need to recalculate the bounds. - */ - foo_canvas_item_request_update (item); - break; - - case PROP_FILL_COLOR: - if (g_value_get_string (value)) - gdk_color_parse (g_value_get_string (value), &color); - line->fill_rgba = ((color.red & 0xff00) << 16 | - (color.green & 0xff00) << 8 | - (color.blue & 0xff00) | - 0xff); - color_changed = TRUE; - break; - - case PROP_FILL_COLOR_GDK: - pcolor = g_value_get_boxed (value); - if (pcolor) { - GdkColormap *colormap; - color = *pcolor; - - colormap = gtk_widget_get_colormap (GTK_WIDGET (item->canvas)); - gdk_rgb_find_color (colormap, &color); - - have_pixel = TRUE; - } - - line->fill_rgba = ((color.red & 0xff00) << 16 | - (color.green & 0xff00) << 8 | - (color.blue & 0xff00) | - 0xff); - color_changed = TRUE; - break; - - case PROP_FILL_COLOR_RGBA: - line->fill_rgba = g_value_get_uint (value); - color_changed = TRUE; - break; - - case PROP_FILL_STIPPLE: - set_stipple (line, (GdkBitmap *) g_value_get_object (value), FALSE); - foo_canvas_item_request_redraw (item); - break; - - case PROP_WIDTH_PIXELS: - line->width = g_value_get_uint (value); - set_line_glyph_gc_width (line); - foo_canvas_item_request_update (item); - break; - - case PROP_CAP_STYLE: - line->cap = g_value_get_enum (value); - foo_canvas_item_request_update (item); - break; - - case PROP_JOIN_STYLE: - line->join = g_value_get_enum (value); - foo_canvas_item_request_update (item); - break; - - case PROP_LINE_STYLE: - line->line_style = g_value_get_enum (value); - set_line_glyph_gc_width (line); - foo_canvas_item_request_update (item); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } - - if (color_changed) { - if (have_pixel) - line->fill_pixel = color.pixel; - else - line->fill_pixel = foo_canvas_get_color_pixel (item->canvas, - line->fill_rgba); - - set_line_glyph_gc_foreground (line); - - foo_canvas_item_request_redraw (item); - } -} - -/* Returns a copy of the line's points. - */ -static FooCanvasPoints * -get_points (FooCanvasLineGlyph *line) -{ - FooCanvasPoints *points; - int start_ofs, end_ofs; - - if (line->num_points == 0) - return NULL; - - start_ofs = end_ofs = 0; - - points = foo_canvas_points_new (line->num_points); - - memcpy (points->coords + 2 * start_ofs, - line->coords + 2 * start_ofs, - 2 * (line->num_points - (start_ofs + end_ofs)) * sizeof (double)); - - return points; -} - -static void -foo_canvas_line_glyph_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - FooCanvasLineGlyph *line; - - g_return_if_fail (object != NULL); - g_return_if_fail (FOO_IS_CANVAS_LINE_GLYPH (object)); - - line = FOO_CANVAS_LINE_GLYPH (object); - - switch (param_id) { - case PROP_X: - g_value_set_double (value, line->x); - break; - - case PROP_Y: - g_value_set_double (value, line->y); - break; - - case PROP_POINTS: - g_value_set_boxed (value, get_points (line)); - break; - - case PROP_FILL_COLOR: - //g_value_take_string (value, - // g_strdup_printf ("#%02x%02x%02x", - // line->fill_rgba >> 24, - // (line->fill_rgba >> 16) & 0xff, - // (line->fill_rgba >> 8) & 0xff)); - break; - - case PROP_FILL_COLOR_GDK: { - FooCanvas *canvas = FOO_CANVAS_ITEM (line)->canvas; - GdkColormap *colormap = gtk_widget_get_colormap (GTK_WIDGET (canvas)); - GdkColor color; - - gdk_colormap_query_color (colormap, line->fill_pixel, &color); - g_value_set_boxed (value, &color); - break; - } - - case PROP_FILL_COLOR_RGBA: - g_value_set_uint (value, line->fill_rgba); - break; - - case PROP_FILL_STIPPLE: - g_value_set_object (value, line->stipple); - break; - - case PROP_WIDTH_PIXELS: - g_value_set_uint (value, line->width); - break; - - case PROP_CAP_STYLE: - g_value_set_enum (value, line->cap); - break; - - case PROP_JOIN_STYLE: - g_value_set_enum (value, line->join); - break; - - case PROP_LINE_STYLE: - g_value_set_enum (value, line->line_style); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - -static void -foo_canvas_line_glyph_update (FooCanvasItem *item, double i2w_dx, double i2w_dy, int flags) -{ - FooCanvasLineGlyph *line; - double x1, y1, x2, y2; - - line = FOO_CANVAS_LINE_GLYPH (item); - - if (parent_class->update) - (* parent_class->update) (item, i2w_dx, i2w_dy, flags); - - set_line_glyph_gc_foreground (line); - set_line_glyph_gc_width (line); - set_stipple (line, line->stipple, TRUE); - - get_bounds_canvas (line, &x1, &y1, &x2, &y2, i2w_dx, i2w_dy); - foo_canvas_update_bbox (item, x1, y1, x2, y2); -} - -static void -foo_canvas_line_glyph_realize (FooCanvasItem *item) -{ - FooCanvasLineGlyph *line; - - line = FOO_CANVAS_LINE_GLYPH (item); - - if (parent_class->realize) - (* parent_class->realize) (item); - - line->gc = gdk_gc_new (item->canvas->layout.bin_window); -#warning "FIXME: Need to recalc pixel values, set colours, etc." - -#if 0 - (* FOO_CANVAS_ITEM_CLASS (item->object.klass)->update) (item, NULL, NULL, 0); -#endif -} - -static void -foo_canvas_line_glyph_unrealize (FooCanvasItem *item) -{ - FooCanvasLineGlyph *line; - - line = FOO_CANVAS_LINE_GLYPH (item); - - g_object_unref (line->gc); - line->gc = NULL; - - if (parent_class->unrealize) - (* parent_class->unrealize) (item); -} - - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE -static void -item_to_canvas (FooCanvas *canvas, - double *item_coords, GdkPoint *canvas_coords, int num_points, - int *num_drawn_points, double i2w_dx, double i2w_dy) -{ - int i; - int old_cx, old_cy; - int cx, cy; - - /* the first point is always drawn */ - foo_canvas_w2c (canvas, - item_coords[0] + i2w_dx, - item_coords[1] + i2w_dy, - &canvas_coords->x, &canvas_coords->y); - - - old_cx = canvas_coords->x; - old_cy = canvas_coords->y; - canvas_coords++; - *num_drawn_points = 1; - - for (i = 1; i < num_points; i++) { - - foo_canvas_w2c (canvas, - item_coords[i*2] + i2w_dx, - item_coords[i*2+1] + i2w_dy, - &cx, &cy); - - - if (old_cx != cx || old_cy != cy) { - canvas_coords->x = cx; - canvas_coords->y = cy; - old_cx = cx; - old_cy = cy; - canvas_coords++; - (*num_drawn_points)++; - } - } -} -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - -static void -item_to_canvas (FooCanvas *canvas, - double x, double y, - double *item_coords, GdkPoint *canvas_coords, int num_points, - int *num_drawn_points, double i2w_dx, double i2w_dy) -{ - int i; - int old_cx, old_cy; - int cx, cy; - - - int glyph_x, glypy_y ; - - /* Calculate position of glyph in its group.... */ - foo_canvas_w2c (canvas, - x + i2w_dx, - y + i2w_dy, - &glyph_x, &glypy_y); - - - /* the first point is always drawn */ - - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE - foo_canvas_w2c (canvas, - item_coords[0] + i2w_dx, - item_coords[1] + i2w_dy, - &canvas_coords->x, &canvas_coords->y); -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - - canvas_coords->x = glyph_x + item_coords[0] ; - canvas_coords->y = glypy_y + item_coords[1] ; - - old_cx = canvas_coords->x; - old_cy = canvas_coords->y; - canvas_coords++; - *num_drawn_points = 1; - - for (i = 1; i < num_points; i++) { - - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE - foo_canvas_w2c (canvas, - item_coords[i*2] + i2w_dx, - item_coords[i*2+1] + i2w_dy, - &cx, &cy); -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - - cx = glyph_x + item_coords[i*2] ; - cy = glypy_y + item_coords[i*2+1] ; - - - if (old_cx != cx || old_cy != cy) { - canvas_coords->x = cx; - canvas_coords->y = cy; - old_cx = cx; - old_cy = cy; - canvas_coords++; - (*num_drawn_points)++; - } - } -} - - -static void -foo_canvas_line_glyph_draw (FooCanvasItem *item, GdkDrawable *drawable, - GdkEventExpose *event) -{ - FooCanvasLineGlyph *line; - GdkPoint static_points[NUM_STATIC_POINTS]; - GdkPoint *points; - int actual_num_points_drawn; - double i2w_dx, i2w_dy; - - line = FOO_CANVAS_LINE_GLYPH (item); - - if (line->num_points == 0) - return; - - /* Build array of canvas pixel coordinates */ - - if (line->num_points <= NUM_STATIC_POINTS) - points = static_points; - else - points = g_new (GdkPoint, line->num_points); - - i2w_dx = 0.0; - i2w_dy = 0.0; - foo_canvas_item_i2w (item, &i2w_dx, &i2w_dy); - - item_to_canvas (item->canvas, line->x, line->y, line->coords, points, line->num_points, - &actual_num_points_drawn, i2w_dx, i2w_dy); - - if (line->stipple) - foo_canvas_set_stipple_origin (item->canvas, line->gc); - - gdk_draw_lines (drawable, line->gc, points, actual_num_points_drawn); - - if (points != static_points) - g_free (points); - -} - - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE -static double -foo_canvas_line_glyph_point (FooCanvasItem *item, double x, double y, - int cx, int cy, FooCanvasItem **actual_item) -{ - FooCanvasLineGlyph *line; - double *line_points = NULL, *coords; - double static_points[2 * NUM_STATIC_POINTS]; - double poly[10]; - double best, dist; - double dx, dy; - double width; - int num_points = 0, i; - int changed_miter_to_bevel; - -#ifdef VERBOSE - g_print ("foo_canvas_line_glyph_point x, y = (%g, %g); cx, cy = (%d, %d)\n", x, y, cx, cy); -#endif - - line = FOO_CANVAS_LINE_GLYPH (item); - - *actual_item = item; - - best = 1.0e36; - - num_points = line->num_points; - line_points = line->coords; - - - /* Compute a polygon for each edge of the line and test the point against it. The effective - * width of the line is adjusted so that it will be at least one pixel thick (so that zero - * pixel-wide lines can be picked up as well). - */ -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE - if (line->width_pixels) - width = line->width / item->canvas->pixels_per_unit_x; - else - width = line->width; -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - width = line->width / item->canvas->pixels_per_unit_x; - - if (width < (1.0 / item->canvas->pixels_per_unit_x)) - width = 1.0 / item->canvas->pixels_per_unit_x; - - changed_miter_to_bevel = 0; - - for (i = num_points, coords = line_points; i >= 2; i--, coords += 2) { - /* If rounding is done around the first point, then compute distance between the - * point and the first point. - */ - - if (((line->cap == GDK_CAP_ROUND) && (i == num_points)) - || ((line->join == GDK_JOIN_ROUND) && (i != num_points))) { - dx = coords[0] - x; - dy = coords[1] - y; - - dist = sqrt (dx * dx + dy * dy) - width / 2.0; - if (dist < FOO_CANVAS_EPSILON) { - best = 0.0; - goto done; - } else if (dist < best) - best = dist; - } - - /* Compute the polygonal shape corresponding to this edge, with two points for the - * first point of the edge and two points for the last point of the edge. - */ - - if (i == num_points) - foo_canvas_get_butt_points (coords[2], coords[3], coords[0], coords[1], - width, (line->cap == GDK_CAP_PROJECTING), - poly, poly + 1, poly + 2, poly + 3); - else if ((line->join == GDK_JOIN_MITER) && !changed_miter_to_bevel) { - poly[0] = poly[6]; - poly[1] = poly[7]; - poly[2] = poly[4]; - poly[3] = poly[5]; - } else { - foo_canvas_get_butt_points (coords[2], coords[3], coords[0], coords[1], - width, FALSE, - poly, poly + 1, poly + 2, poly + 3); - - /* If this line uses beveled joints, then check the distance to a polygon - * comprising the last two points of the previous polygon and the first two - * from this polygon; this checks the wedges that fill the mitered point. - */ - - if ((line->join == GDK_JOIN_BEVEL) || changed_miter_to_bevel) { - poly[8] = poly[0]; - poly[9] = poly[1]; - - dist = foo_canvas_polygon_to_point (poly, 5, x, y); - if (dist < FOO_CANVAS_EPSILON) { - best = 0.0; - goto done; - } else if (dist < best) - best = dist; - - changed_miter_to_bevel = FALSE; - } - } - - if (i == 2) - foo_canvas_get_butt_points (coords[0], coords[1], coords[2], coords[3], - width, (line->cap == GDK_CAP_PROJECTING), - poly + 4, poly + 5, poly + 6, poly + 7); - else if (line->join == GDK_JOIN_MITER) { - if (!foo_canvas_get_miter_points (coords[0], coords[1], - coords[2], coords[3], - coords[4], coords[5], - width, - poly + 4, poly + 5, poly + 6, poly + 7)) { - changed_miter_to_bevel = TRUE; - foo_canvas_get_butt_points (coords[0], coords[1], coords[2], coords[3], - width, FALSE, - poly + 4, poly + 5, poly + 6, poly + 7); - } - } else - foo_canvas_get_butt_points (coords[0], coords[1], coords[2], coords[3], - width, FALSE, - poly + 4, poly + 5, poly + 6, poly + 7); - - poly[8] = poly[0]; - poly[9] = poly[1]; - - dist = foo_canvas_polygon_to_point (poly, 5, x, y); - if (dist < FOO_CANVAS_EPSILON) { - best = 0.0; - goto done; - } else if (dist < best) - best = dist; - } - - /* If caps are rounded, check the distance to the cap around the final end point of the line */ - - if (line->cap == GDK_CAP_ROUND) { - dx = coords[0] - x; - dy = coords[1] - y; - dist = sqrt (dx * dx + dy * dy) - width / 2.0; - if (dist < FOO_CANVAS_EPSILON) { - best = 0.0; - goto done; - } else - best = dist; - } - -done: - - if ((line_points != static_points) && (line_points != line->coords)) - g_free (line_points); - - return best; -} -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - - - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE -static double -foo_canvas_line_glyph_point (FooCanvasItem *item, double x, double y, - int cx, int cy, FooCanvasItem **actual_item) -{ - FooCanvasLineGlyph *line; - double *line_points = NULL, *coords; - double static_points[2 * NUM_STATIC_POINTS]; - double poly[10]; - double best, dist; - double dx, dy; - double width; - int num_points = 0, i; - int changed_miter_to_bevel; - -#ifdef VERBOSE - g_print ("foo_canvas_line_glyph_point x, y = (%g, %g); cx, cy = (%d, %d)\n", x, y, cx, cy); -#endif - - line = FOO_CANVAS_LINE_GLYPH (item); - - *actual_item = item; - - best = 1.0e36; - - num_points = line->num_points; - line_points = line->coords; - - - /* Compute a polygon for each edge of the line and test the point against it. The effective - * width of the line is adjusted so that it will be at least one pixel thick (so that zero - * pixel-wide lines can be picked up as well). - */ -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE - if (line->width_pixels) - width = line->width / item->canvas->pixels_per_unit_x; - else - width = line->width; -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - width = line->width / item->canvas->pixels_per_unit_x; - - if (width < (1.0 / item->canvas->pixels_per_unit_x)) - width = 1.0 / item->canvas->pixels_per_unit_x; - - changed_miter_to_bevel = 0; - - for (i = num_points, coords = line_points; i >= 2; i--, coords += 2) { - /* If rounding is done around the first point, then compute distance between the - * point and the first point. - */ - - if (((line->cap == GDK_CAP_ROUND) && (i == num_points)) - || ((line->join == GDK_JOIN_ROUND) && (i != num_points))) { - - dx = line->x + coords[0] - x; - dy = line->y + coords[1] - y; - - dist = sqrt (dx * dx + dy * dy) - width / 2.0; - if (dist < FOO_CANVAS_EPSILON) { - best = 0.0; - goto done; - } else if (dist < best) - best = dist; - } - - /* Compute the polygonal shape corresponding to this edge, with two points for the - * first point of the edge and two points for the last point of the edge. - */ - - if (i == num_points) - foo_canvas_get_butt_points (line->x + coords[2], line->y + coords[3], - line->x + coords[0], line->y + coords[1], - width, (line->cap == GDK_CAP_PROJECTING), - poly, poly + 1, poly + 2, poly + 3); - else if ((line->join == GDK_JOIN_MITER) && !changed_miter_to_bevel) { - poly[0] = poly[6]; - poly[1] = poly[7]; - poly[2] = poly[4]; - poly[3] = poly[5]; - } else { - foo_canvas_get_butt_points (line->x + coords[2], line->y + coords[3], - line->x + coords[0], line->y + coords[1], - width, FALSE, - poly, poly + 1, poly + 2, poly + 3); - - /* If this line uses beveled joints, then check the distance to a polygon - * comprising the last two points of the previous polygon and the first two - * from this polygon; this checks the wedges that fill the mitered point. - */ - - if ((line->join == GDK_JOIN_BEVEL) || changed_miter_to_bevel) { - poly[8] = poly[0]; - poly[9] = poly[1]; - - dist = foo_canvas_polygon_to_point (poly, 5, x, y); - if (dist < FOO_CANVAS_EPSILON) { - best = 0.0; - goto done; - } else if (dist < best) - best = dist; - - changed_miter_to_bevel = FALSE; - } - } - - if (i == 2) - foo_canvas_get_butt_points (line->x + coords[0], line->y + coords[1], - line->x + coords[2], line->y + coords[3], - width, (line->cap == GDK_CAP_PROJECTING), - poly + 4, poly + 5, poly + 6, poly + 7); - else if (line->join == GDK_JOIN_MITER) { - if (!foo_canvas_get_miter_points (line->x + coords[0], line->y + coords[1], - line->x + coords[2], line->y + coords[3], - line->x + coords[4], line->y + coords[5], - width, - poly + 4, poly + 5, poly + 6, poly + 7)) { - changed_miter_to_bevel = TRUE; - foo_canvas_get_butt_points (line->x + coords[0], line->y + coords[1], - line->x + coords[2], line->y + coords[3], - width, FALSE, - poly + 4, poly + 5, poly + 6, poly + 7); - } - } else - foo_canvas_get_butt_points (line->x + coords[0], line->y + coords[1], - line->x + coords[2], line->y + coords[3], - width, FALSE, - poly + 4, poly + 5, poly + 6, poly + 7); - - poly[8] = poly[0]; - poly[9] = poly[1]; - - dist = foo_canvas_polygon_to_point (poly, 5, x, y); - if (dist < FOO_CANVAS_EPSILON) { - best = 0.0; - goto done; - } else if (dist < best) - best = dist; - } - - /* If caps are rounded, check the distance to the cap around the final end point of the line */ - - if (line->cap == GDK_CAP_ROUND) { - dx = line->x + coords[0] - x; - dy = line->y + coords[1] - y; - dist = sqrt (dx * dx + dy * dy) - width / 2.0; - if (dist < FOO_CANVAS_EPSILON) { - best = 0.0; - goto done; - } else - best = dist; - } - -done: - - if ((line_points != static_points) && (line_points != line->coords)) - g_free (line_points); - - -#ifdef VERBOSE - printf("foo_canvas_line_glyph_point x, y = (%g, %g); distance = %g\n", x, y, best) ; -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - - - return best; -} -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - - - - -static double -foo_canvas_line_glyph_point (FooCanvasItem *item, double x, double y, int cx, int cy, FooCanvasItem **actual_item) -{ - double result = 0.0 ; - FooCanvasLineGlyph *line; - double *coords = NULL; - double x1, y1, x2, y2; - double hwidth; - double dx, dy; - -#ifdef VERBOSE - g_print ("foo_canvas_line_glyph_point x, y = (%g, %g); cx, cy = (%d, %d)\n", x, y, cx, cy); -#endif - - line = FOO_CANVAS_LINE_GLYPH (item); - - *actual_item = item; - - /* Find the bounds for the rectangle plus its outline width */ - - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE - x1 = re->x1; - y1 = re->y1; - x2 = re->x2; - y2 = re->y2; -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - - /* extract topleft/botright.... */ - coords = line->coords; - x1 = line->x + coords[0]; - x2 = line->x + coords[2]; - if (coords[5] < coords[3]) - { - y1 = line->y + coords[5]; - y2 = line->y + coords[3]; - } - else - { - y1 = line->y + coords[3]; - y2 = line->y + coords[5]; - } - - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE - - /* This is all about the line width....add later... */ - - if (re->outline_set) { - if (re->width_pixels) - hwidth = (re->width / item->canvas->pixels_per_unit_x) / 2.0; - else - hwidth = re->width / 2.0; - - x1 -= hwidth; - y1 -= hwidth; - x2 += hwidth; - y2 += hwidth; - } else - hwidth = 0.0; -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - - hwidth = 0.0; - - - /* Is point inside rectangle (which can be hollow if it has no fill set)? */ - - if ((x >= x1) && (y >= y1) && (x <= x2) && (y <= y2)) { - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE - if (re->fill_set || !re->outline_set) - result = 0.0; -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - - result = 0.0 ; - -#ifdef ED_G_NEVER_INCLUDE_THIS_CODE - dx = x - x1; - tmp = x2 - x; - if (tmp < dx) - dx = tmp; - - dy = y - y1; - tmp = y2 - y; - if (tmp < dy) - dy = tmp; - - if (dy < dx) - dx = dy; - - dx -= 2.0 * hwidth; - - if (dx < 0.0) - result = 0.0; - else - result = dx; -#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */ - - } - else - { - /* Point is outside rectangle */ - - if (x < x1) - dx = x1 - x; - else if (x > x2) - dx = x - x2; - else - dx = 0.0; - - if (y < y1) - dy = y1 - y; - else if (y > y2) - dy = y - y2; - else - dy = 0.0; - - result = sqrt (dx * dx + dy * dy); - } - - -#ifdef VERBOSE - printf("x,y: %g,%g distance: %g\n", x, y, result) ; -#endif - - - return result ; -} - - -static void -foo_canvas_line_glyph_translate (FooCanvasItem *item, double dx, double dy) -{ - FooCanvasLineGlyph *line; - int i; - double *coords; - - line = FOO_CANVAS_LINE_GLYPH (item); - - for (i = 0, coords = line->coords; i < line->num_points; i++, coords += 2) { - coords[0] += dx; - coords[1] += dy; - } - -} - -static void -foo_canvas_line_glyph_bounds (FooCanvasItem *item, double *x1, double *y1, double *x2, double *y2) -{ - FooCanvasLineGlyph *line; - - line = FOO_CANVAS_LINE_GLYPH (item); - - if (line->num_points == 0) { - *x1 = *y1 = *x2 = *y2 = 0.0; - return; - } - - get_bounds (line, x1, y1, x2, y2); - -#ifdef VERBOSE - printf("Glyph Bounds: %f %f -> %f %f\n", *x1, *y1, *x2, *y2) ; -#endif - -} diff --git a/foocanvas/additional_files/foozmap-canvas-line-glyph.h b/foocanvas/additional_files/foozmap-canvas-line-glyph.h deleted file mode 100755 index 952c189ae0b7afe82fcb0b48b0e992119d14a702..0000000000000000000000000000000000000000 --- a/foocanvas/additional_files/foozmap-canvas-line-glyph.h +++ /dev/null @@ -1,126 +0,0 @@ -/* Last edited: Oct 3 14:00 2006 (edgrif) */ -/* - * Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation - * All rights reserved. - * - * This file is part of the Gnome Library. - * - * The Gnome Library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * The Gnome Library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with the Gnome Library; see the file COPYING.LIB. If not, - * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -/* - @NOTATION@ - */ - -/* Glyphs made from lines, they are constant scale so show at all zoom levels. - * - * FooCanvas is basically a port of the Tk toolkit's most excellent canvas widget. Tk is - * copyrighted by the Regents of the University of California, Sun Microsystems, and other parties. - * - * - * Author: Ed Griffiths <edgrif@sanger.ac.uk> - */ - -#ifndef FOOZMAP_CANVAS_LINE_GLYPH_H -#define FOOZMAP_CANVAS_LINE_GLYPH_H - - -#include <libfoocanvas/foo-canvas.h> - - -G_BEGIN_DECLS - - -/* Line glyph item for the canvas. This is a glyph made up from lines with configurable width, cap/join styles. - * - * The following object arguments are available: - * - * name type read/write description - * ------------------------------------------------------------------------------------------ - - * CURRENTLY NOT TRUE...ITS THE POSITION OF THE LEFT/MIDDLE OF FEATURE.... - * x double RW X position of middle of glyph. - * y double RW Y position of middle of glyph. - - - - * points FooCanvasPoints* RW Pointer to a FooCanvasPoints structure. - * This can be created by a call to - * foo_canvas_points_new() (in foo-canvas-util.h). - * X coordinates are in the even indices of the - * points->coords array, Y coordinates are in - * the odd indices. - * fill_color string W X color specification for line. - * fill_color_gdk GdkColor* RW Pointer to an allocated GdkColor. - * fill_stipple GdkBitmap* RW Stipple pattern for the line. - * width_pixels uint R Width of the line in pixels. The line width - * will not be scaled when the canvas zoom factor changes. - * cap_style GdkCapStyle RW Cap ("endpoint") style for the line. - * join_style GdkJoinStyle RW Join ("vertex") style for the line. - * line_style GdkLineStyle RW Line dash style - */ - - -#define FOO_TYPE_CANVAS_LINE_GLYPH (foo_canvas_line_glyph_get_type ()) -#define FOO_CANVAS_LINE_GLYPH(obj) (GTK_CHECK_CAST ((obj), FOO_TYPE_CANVAS_LINE_GLYPH, FooCanvasLineGlyph)) -#define FOO_CANVAS_LINE_GLYPH_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), FOO_TYPE_CANVAS_LINE_GLYPH, FooCanvasLineGlyphClass)) -#define FOO_IS_CANVAS_LINE_GLYPH(obj) (GTK_CHECK_TYPE ((obj), FOO_TYPE_CANVAS_LINE_GLYPH)) -#define FOO_IS_CANVAS_LINE_GLYPH_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), FOO_TYPE_CANVAS_LINE_GLYPH)) -#define FOO_CANVAS_LINE_GLYPH_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), FOO_TYPE_CANVAS_LINE_GLYPH, FooCanvasLineGlyphClass)) - - -typedef struct _FooCanvasLineGlyph FooCanvasLineGlyph; -typedef struct _FooCanvasLineGlyphClass FooCanvasLineGlyphClass; - -struct _FooCanvasLineGlyph { - FooCanvasItem item; - - double x, y ; /* Position of item */ - - double *coords; /* Array of coordinates for the line_glyph's points. X coords are in the - * even indices, Y coords are in the odd indices. This is derived - * from x,y and offsets. */ - - GdkGC *gc; /* GC for drawing line_glyph */ - - GdkBitmap *stipple; /* Stipple pattern */ - - double width; /* Width of the line_glyph */ - - GdkCapStyle cap; /* Cap style for line_glyph */ - GdkJoinStyle join; /* Join style for line_glyph */ - GdkLineStyle line_style;/* Style for the line_glyph */ - - gulong fill_pixel; /* Color for line_glyph */ - - guint32 fill_rgba; /* RGBA color for outline */ /*AA*/ - - int num_points; /* Number of points in the line_glyph */ - guint fill_color; /* Fill color, RGBA */ - -}; - -struct _FooCanvasLineGlyphClass { - FooCanvasItemClass parent_class; -}; - - -/* Standard Gtk function */ -GtkType foo_canvas_line_glyph_get_type (void) G_GNUC_CONST; - - -G_END_DECLS - -#endif diff --git a/foocanvas/additional_files/foozmap-canvas-text.c b/foocanvas/additional_files/foozmap-canvas-text.c deleted file mode 100755 index eda411f78c712995ac573153343b4733186ae45e..0000000000000000000000000000000000000000 --- a/foocanvas/additional_files/foozmap-canvas-text.c +++ /dev/null @@ -1,1356 +0,0 @@ -/* File: foozmap-canvas-text.c - * Author: Roy Storey (rds@sanger.ac.uk) - * Copyright (c) 2008: Genome Research Ltd. - *------------------------------------------------------------------- - * ZMap 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 2 - * of the License, or (at your option) any later version. - * - * This program 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 more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * or see the on-line version at http://www.gnu.org/copyleft/gpl.txt - *------------------------------------------------------------------- - * This file is part of the ZMap genome database package - * originally written by: - * - * Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk, - * Roy Storey (Sanger Institute, UK) rds@sanger.ac.uk - * - * Description: - * - * Exported functions: See XXXXXXXXXXXXX.h - * HISTORY: - * Last edited: Mar 22 08:06 2008 (rds) - * Created: Fri Jan 25 12:01:12 2008 (rds) - * CVS info: $Id: foozmap-canvas-text.c,v 1.5 2008-03-23 16:49:41 rds Exp $ - *------------------------------------------------------------------- - */ - -#include <config.h> -#include <math.h> -#include <string.h> -#include "foo-canvas-text.h" -#include "foozmap-canvas-text.h" - -#include "foo-canvas-util.h" -#include "foo-canvas-i18n.h" - -/* Object argument IDs */ -enum { - PROP_0, - - PROP_WRAP_MODE, - - PROP_TEXT_ALLOCATE_FUNC, - PROP_TEXT_FETCH_TEXT_FUNC, - PROP_TEXT_CALLBACK_DATA, - - PROP_TEXT_REQUESTED_WIDTH, - PROP_TEXT_REQUESTED_HEIGHT -}; - -enum - { - NO_NOTIFY_MASK = 0, - ZOOM_NOTIFY_MASK = 1, - SCROLL_REGION_NOTIFY_MASK = 2, - KEEP_WITHIN_SCROLL_REGION = 4 - }; - -struct _FooCanvasZMapTextPrivate { - /* a fixed size array buffer_size long */ - char *buffer; - gint buffer_size; - - double requested_width; - double requested_height; - /* unsure why these two are here, remove?? */ - double zx,zy; - - /* a cache of the drawing extents/scroll region etc... */ - ZMapTextDrawDataStruct update_cache; - ZMapTextDrawDataStruct draw_cache; - /* the extents that should be used instead of the */ - PangoRectangle char_extents; - FooCanvasZMapAllocateCB allocate_func; - FooCanvasZMapFetchTextCB fetch_text_func; - gpointer callback_data; /* user data for the allocate_func & fetch_text_func */ - unsigned int flags : 3; - unsigned int allocated : 1; - unsigned int text_fetched : 1; -}; - -static void foo_canvas_zmap_text_class_init (FooCanvasZMapTextClass *class); -static void foo_canvas_zmap_text_init (FooCanvasZMapText *text); -static void foo_canvas_zmap_text_destroy (GtkObject *object); -static void foo_canvas_zmap_text_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); -static void foo_canvas_zmap_text_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); - -static void foo_canvas_zmap_text_realize (FooCanvasItem *item); -static void foo_canvas_zmap_text_unrealize (FooCanvasItem *item); -static void foo_canvas_zmap_text_draw (FooCanvasItem *item, - GdkDrawable *drawable, - GdkEventExpose *expose); -static void foo_canvas_zmap_text_update(FooCanvasItem *item, - double i2w_dx, - double i2w_dy, - int flags); -static void foo_canvas_zmap_text_bounds (FooCanvasItem *item, - double *x1, double *y1, - double *x2, double *y2); - -/* */ -static void allocate_buffer_size(FooCanvasZMapText *zmap); -static void run_update_cycle_loop(FooCanvasItem *item); -static gboolean canvas_has_changed(FooCanvasItem *item, ZMapTextDrawData draw_data); -static gboolean invoke_get_text(FooCanvasItem *item); -static void invoke_allocate_width_height(FooCanvasItem *item); -static void save_origin(FooCanvasItem *item); -static void sync_data(ZMapTextDrawData from, ZMapTextDrawData to); - -/* print out cached data functions */ -static void print_private_data(FooCanvasZMapTextPrivate *private_data); -static void print_draw_data(ZMapTextDrawData draw_data); -static void print_calculate_buffer_data(FooCanvasZMapText *zmap, - ZMapTextDrawData draw_data, - int cx1, int cy1, - int cx2, int cy2); - - -/* ************** our gdk drawing functions *************** */ -static PangoRenderer *zmap_get_renderer(GdkDrawable *drawable, - GdkGC *gc, - GdkColor *foreground, - GdkColor *background); -static void zmap_release_renderer (PangoRenderer *renderer); -static void zmap_pango_renderer_draw_layout_get_size (PangoRenderer *renderer, - PangoLayout *layout, - int x, - int y, - GdkEventExpose *expose, - GdkRectangle *size_in_out); -static void zmap_gdk_draw_layout_get_size_within_expose(GdkDrawable *drawable, - GdkGC *gc, - int x, - int y, - PangoLayout *layout, - GdkEventExpose *expose, - int *width_max_in_out, - int *height_max_in_out); -/* ******************************************************* */ - -static gboolean debug_allocate = FALSE; -static gboolean debug_functions = FALSE; -static gboolean debug_area = FALSE; -static gboolean debug_table = FALSE; - -static FooCanvasItemClass *parent_class_G; - - -/** - * foo_canvas_zmap_text_get_type: - * @void: - * - * Registers the &FooCanvasZMapText class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &FooCanvasZMapText class. - **/ -GtkType -foo_canvas_zmap_text_get_type (void) -{ - static GtkType text_type = 0; - - if (!text_type) { - /* FIXME: Convert to gobject style. */ - static const GtkTypeInfo text_info = { - (char *)"FooCanvasZMapText", - sizeof (FooCanvasZMapText), - sizeof (FooCanvasZMapTextClass), - (GtkClassInitFunc) foo_canvas_zmap_text_class_init, - (GtkObjectInitFunc) foo_canvas_zmap_text_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - text_type = gtk_type_unique (foo_canvas_text_get_type (), &text_info); - } - - return text_type; -} - -void foo_canvas_pango2item(FooCanvas *canvas, int px, int py, double *ix, double *iy) -{ - double zoom_x, zoom_y; - - g_return_if_fail (FOO_IS_CANVAS (canvas)); - - zoom_x = canvas->pixels_per_unit_x; - zoom_y = canvas->pixels_per_unit_y; - - if (ix) - *ix = ((((double)px) / PANGO_SCALE) / zoom_x); - if (iy) - *iy = ((((double)py) / PANGO_SCALE) / zoom_y); - - return ; -} - -gboolean foo_canvas_item_text_index2item(FooCanvasItem *item, - int index, - double *item_coords_out) -{ - FooCanvasZMapText *zmap; - gboolean index_found; - - if(FOO_IS_CANVAS_ZMAP_TEXT(item) && - (zmap = FOO_CANVAS_ZMAP_TEXT(item))) - { - FooCanvasZMapTextPrivate *private_data; - FooCanvasGroup *parent_group; - ZMapTextDrawData draw_data; - double w, h; - int row_idx, row, width; - double x1, x2, y1, y2; - - foo_canvas_item_get_bounds(item, &x1, &y1, &x2, &y2); - - parent_group = FOO_CANVAS_GROUP(item->parent); - -#ifdef NOT_OUR_RESPONSIBILITY - /* We are actually only drawing from parent_group->ypos so index must be reduced. */ - index -= parent_group->ypos; -#endif /* NOT_OUR_RESPONSIBILITY */ - - private_data = zmap->priv; - draw_data = &(private_data->update_cache); - - if(draw_data->table.truncated) - width = draw_data->table.untruncated_width; - else - width = draw_data->table.width; - - row_idx = index % width; - row = (index - row_idx) / width; - - if(row_idx == 0) - { - row--; - row_idx = draw_data->table.width; - } - - if(row_idx > draw_data->table.width) - row_idx = draw_data->table.width; - - row_idx--; /* zero based. */ - - if(item_coords_out) - { - w = (draw_data->table.ch_width / draw_data->zx); - h = ((draw_data->table.ch_height + draw_data->table.spacing) / draw_data->zy); - (item_coords_out[0]) = row_idx * w; - (item_coords_out[1]) = row * h; - row++; - row_idx++; - (item_coords_out[2]) = row_idx * w; - (item_coords_out[3]) = row * h; - - index_found = TRUE; - } - } - else - index_found = FALSE; - - return index_found; -} - -int foo_canvas_item_world2text_index(FooCanvasItem *item, double x, double y) -{ - int index = -1; - - foo_canvas_item_w2i(item, &x, &y); - - index = foo_canvas_item_item2text_index(item, x, y); - - return index; -} - -int foo_canvas_item_item2text_index(FooCanvasItem *item, double x, double y) -{ - FooCanvasZMapText *zmap; - int index = -1; - - if(FOO_IS_CANVAS_ZMAP_TEXT(item) && - (zmap = FOO_CANVAS_ZMAP_TEXT(item))) - { - double x1, x2, y1, y2; - gboolean min = FALSE, max = FALSE; - foo_canvas_item_get_bounds(item, &x1, &y1, &x2, &y2); - - min = (x < x1); - max = (x > x2); - - if(!(y < y1 || y > y2)) - { - FooCanvasZMapTextPrivate *private_data; - ZMapTextDrawData draw_data; - double ix, iy, w, h; - int row_idx, row, width; - - ix = x - x1; - iy = y - y1; - - private_data = zmap->priv; - draw_data = &(private_data->update_cache); - - if(draw_data->table.truncated) - width = draw_data->table.untruncated_width; - else - width = draw_data->table.width; - - w = (draw_data->table.ch_width / draw_data->zx); - h = ((draw_data->table.ch_height + draw_data->table.spacing) / draw_data->zy); - - row_idx = (int)(ix / w); - row = (int)(iy / h); - - if(min){ row_idx = 0; } - if(max){ row_idx = width - 1; } - - index = row * width + row_idx; - } - } - else - g_warning("Item _must_ be a FOO_CANVAS_ZMAP_TEXT item."); - - return index; -} - -/* Class initialization function for the text item */ -static void foo_canvas_zmap_text_class_init (FooCanvasZMapTextClass *class) -{ - GObjectClass *gobject_class; - GtkObjectClass *object_class; - FooCanvasItemClass *item_class; - FooCanvasItemClass *parent_class; - - gobject_class = (GObjectClass *) class; - object_class = (GtkObjectClass *) class; - item_class = (FooCanvasItemClass *) class; - - parent_class_G = gtk_type_class(foo_canvas_text_get_type()); - parent_class = gtk_type_class(foo_canvas_text_get_type()); - - gobject_class->set_property = foo_canvas_zmap_text_set_property; - gobject_class->get_property = foo_canvas_zmap_text_get_property; - - g_object_class_install_property(gobject_class, - PROP_TEXT_ALLOCATE_FUNC, - g_param_spec_pointer("allocate-func", - _("Size Allocate text area."), - _("User function to allocate the correct table cell dimensions (not-implemented)"), - G_PARAM_READWRITE)); - - g_object_class_install_property(gobject_class, - PROP_TEXT_FETCH_TEXT_FUNC, - g_param_spec_pointer("fetch-text-func", - _("Get Text Function"), - _("User function to copy text to buffer"), - G_PARAM_READWRITE)); - - g_object_class_install_property(gobject_class, - PROP_TEXT_CALLBACK_DATA, - g_param_spec_pointer("callback-data", - _("Get Text Function Data"), - _("User function data to use to copy text to buffer"), - G_PARAM_READWRITE)); - - g_object_class_install_property(gobject_class, - PROP_TEXT_REQUESTED_WIDTH, - g_param_spec_double("full-width", - NULL, NULL, - -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - g_object_class_install_property(gobject_class, - PROP_TEXT_REQUESTED_HEIGHT, - g_param_spec_double("full-height", - NULL, NULL, - -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - g_object_class_install_property(gobject_class, - PROP_WRAP_MODE, - g_param_spec_enum ("wrap-mode", NULL, NULL, - PANGO_TYPE_WRAP_MODE, PANGO_WRAP_WORD, - G_PARAM_READWRITE)); - - object_class->destroy = foo_canvas_zmap_text_destroy; - - item_class->realize = foo_canvas_zmap_text_realize; - item_class->unrealize = foo_canvas_zmap_text_unrealize; - item_class->draw = foo_canvas_zmap_text_draw; - item_class->update = foo_canvas_zmap_text_update; - item_class->bounds = foo_canvas_zmap_text_bounds; - - return ; -} - -/* Object initialization function for the text item */ -static void foo_canvas_zmap_text_init (FooCanvasZMapText *text) -{ - text->priv = g_new0 (FooCanvasZMapTextPrivate, 1); - text->priv->flags = (ZOOM_NOTIFY_MASK | - SCROLL_REGION_NOTIFY_MASK | - KEEP_WITHIN_SCROLL_REGION); - return ; -} - -/* Destroy handler for the text item */ -static void foo_canvas_zmap_text_destroy (GtkObject *object) -{ - FooCanvasZMapText *text; - - g_return_if_fail (FOO_IS_CANVAS_ZMAP_TEXT (object)); - - text = FOO_CANVAS_ZMAP_TEXT (object); - - /* remember, destroy can be run multiple times! */ - - g_free (text->priv); - text->priv = NULL; - - if (GTK_OBJECT_CLASS (parent_class_G)->destroy) - (* GTK_OBJECT_CLASS (parent_class_G)->destroy) (object); - - return ; -} - -/* Set_arg handler for the text item */ -static void foo_canvas_zmap_text_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - FooCanvasItem *item; - FooCanvasZMapText *text; - - g_return_if_fail (object != NULL); - g_return_if_fail (FOO_IS_CANVAS_ZMAP_TEXT (object)); - - text = FOO_CANVAS_ZMAP_TEXT (object); - item = FOO_CANVAS_ITEM(object); - - switch (param_id) - { - case PROP_TEXT_ALLOCATE_FUNC: - text->priv->allocate_func = g_value_get_pointer(value); - break; - case PROP_TEXT_FETCH_TEXT_FUNC: - text->priv->fetch_text_func = g_value_get_pointer(value); - break; - case PROP_TEXT_CALLBACK_DATA: - text->priv->callback_data = g_value_get_pointer(value); - break; - case PROP_TEXT_REQUESTED_WIDTH: - text->priv->requested_width = g_value_get_double(value); - break; - case PROP_TEXT_REQUESTED_HEIGHT: - text->priv->requested_height = g_value_get_double(value); - break; - case PROP_WRAP_MODE: - { - FooCanvasText *parent_text = FOO_CANVAS_TEXT(object); - int mode = g_value_get_enum(value); - - if(!parent_text->layout) - parent_text->layout = - gtk_widget_create_pango_layout(GTK_WIDGET(item->canvas), NULL); - - pango_layout_set_wrap(parent_text->layout, mode); - } - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } - - foo_canvas_item_request_update (item); - - return ; -} - -/* Get_arg handler for the text item */ -static void foo_canvas_zmap_text_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - FooCanvasZMapText *text; - - g_return_if_fail (object != NULL); - g_return_if_fail (FOO_IS_CANVAS_ZMAP_TEXT (object)); - - text = FOO_CANVAS_ZMAP_TEXT (object); - - switch (param_id) - { - case PROP_TEXT_ALLOCATE_FUNC: - g_value_set_pointer(value, text->priv->allocate_func); - break; - case PROP_TEXT_FETCH_TEXT_FUNC: - g_value_set_pointer(value, text->priv->fetch_text_func); - break; - case PROP_TEXT_CALLBACK_DATA: - g_value_set_pointer(value, text->priv->callback_data); - break; - case PROP_TEXT_REQUESTED_WIDTH: - g_value_set_double(value, text->priv->requested_width); - break; - case PROP_TEXT_REQUESTED_HEIGHT: - g_value_set_double(value, text->priv->requested_height); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } - - return ; -} - -/* Realize handler for the text item */ -static void foo_canvas_zmap_text_realize (FooCanvasItem *item) -{ - FooCanvasZMapText *text; - PangoLayout *layout = FOO_CANVAS_TEXT(item)->layout; - PangoLayoutIter *iter = NULL; - const char *current = NULL; - int l = 0; - - text = FOO_CANVAS_ZMAP_TEXT (item); - -#ifdef __GNUC__ - if(debug_functions) - printf("%s\n", __PRETTY_FUNCTION__); -#endif /* __GNUC__ */ - - /* First time it's realized */ - save_origin(item); - - if((current = pango_layout_get_text(layout)) && (l = strlen(current)) == 0) - { - current = NULL; - pango_layout_set_text(layout, "0", 1); - } - - if((iter = pango_layout_get_iter(layout))) - { - pango_layout_iter_get_char_extents(iter, &(text->priv->char_extents)); - - pango_layout_iter_free(iter); - } - - if(!current) - pango_layout_set_text(layout, "", 0); - - allocate_buffer_size(text); - - if (parent_class_G->realize) - (* parent_class_G->realize) (item); - - return ; -} - -/* Unrealize handler for the text item */ -static void foo_canvas_zmap_text_unrealize (FooCanvasItem *item) -{ - FooCanvasZMapText *text; - text = FOO_CANVAS_ZMAP_TEXT (item); - -#ifdef __GNUC__ - if(debug_functions) - printf("%s\n", __PRETTY_FUNCTION__); -#endif /* __GNUC__ */ - - /* make sure it's all zeros */ - if(text->priv && text->priv->buffer) - memset(text->priv->buffer, 0, text->priv->buffer_size); - - if (parent_class_G->unrealize) - (* parent_class_G->unrealize) (item); - - return ; -} - -/* Draw handler for the text item */ -static void foo_canvas_zmap_text_draw (FooCanvasItem *item, - GdkDrawable *drawable, - GdkEventExpose *expose) -{ - FooCanvasZMapText *zmap; - FooCanvasText *text; - GdkRectangle rect; - - zmap = FOO_CANVAS_ZMAP_TEXT (item); - text = FOO_CANVAS_TEXT(item); - -#ifdef __GNUC__ - if(debug_functions) - printf("%s\n", __PRETTY_FUNCTION__); -#endif /* __GNUC__ */ - - /* from here is identical logic to parent, but calls internal - * zmap_gdk_draw_layout_to_expose instead of gdk_draw_layout */ - - if (text->clip) - { - rect.x = text->clip_cx; - rect.y = text->clip_cy; - rect.width = text->clip_cwidth; - rect.height = text->clip_cheight; - - gdk_gc_set_clip_rectangle (text->gc, &rect); - } - - if (text->stipple) - foo_canvas_set_stipple_origin (item->canvas, text->gc); - - { - gboolean text_changed = FALSE; - - text_changed = invoke_get_text(item); - - /* This is faster than the gdk_draw_layout as it filters based on - * the intersection of lines within the expose region. */ - zmap_gdk_draw_layout_get_size_within_expose (drawable, text->gc, - text->cx, text->cy, - text->layout, - expose, - &(text->max_width), - &(text->height)); - } - - if (text->clip) - gdk_gc_set_clip_rectangle (text->gc, NULL); - - - - return ; -} - -static void foo_canvas_zmap_text_update(FooCanvasItem *item, - double i2w_dx, - double i2w_dy, - int flags) -{ - FooCanvasZMapText *zmap; - - zmap = FOO_CANVAS_ZMAP_TEXT(item); - -#ifdef __GNUC__ - if(debug_functions) - printf("%s\n", __PRETTY_FUNCTION__); -#endif /* __GNUC__ */ - - run_update_cycle_loop(item); - - if(parent_class_G->update) - (*parent_class_G->update)(item, i2w_dx, i2w_dy, flags); - - return ; -} - - -static void foo_canvas_zmap_text_bounds (FooCanvasItem *item, - double *x1, double *y1, - double *x2, double *y2) -{ - FooCanvasZMapText *zmap = NULL; - FooCanvasText *text = NULL; - - zmap = FOO_CANVAS_ZMAP_TEXT(item); - text = FOO_CANVAS_TEXT(item); - -#ifdef __GNUC__ - if(debug_functions) - printf("%s\n", __PRETTY_FUNCTION__); -#endif /* __GNUC__ */ - - run_update_cycle_loop(item); - - if(parent_class_G->bounds) - (*parent_class_G->bounds)(item, x1, y1, x2, y2); - -#ifdef __GNUC__ - if(debug_area) - printf("%s: %f %f %f %f\n", __PRETTY_FUNCTION__, *x1, *y1, *x2, *y2); -#endif /* __GNUC__ */ - - return ; -} - -static void print_draw_data(ZMapTextDrawData draw_data) -{ - - printf(" zoom x, y : %f, %f\n", draw_data->zx, draw_data->zy); - printf(" world x, y : %f, %f\n", draw_data->wx, draw_data->wy); - printf(" scr x1,x2,r: %f, %f, %f\n", draw_data->x1, draw_data->x2, draw_data->x2 - draw_data->x1 + 1); - printf(" scr y1,y2,r: %f, %f, %f\n", draw_data->y1, draw_data->y2, draw_data->y2 - draw_data->y1 + 1); - - return ; -} - -static void print_private_data(FooCanvasZMapTextPrivate *private_data) -{ - if(debug_area || debug_table) - { - printf("Private Data\n"); - printf(" buffer size: %d\n", private_data->buffer_size); - printf(" req height : %f\n", private_data->requested_height); - printf(" req width : %f\n", private_data->requested_width); - printf(" zx, zy : %f, %f\n", private_data->zx, private_data->zy); - printf(" char w, h : %d, %d\n", private_data->char_extents.width, private_data->char_extents.height); - - printf("Update draw data\n"); - print_draw_data(&(private_data->update_cache)); - - printf("Draw draw data\n"); - print_draw_data(&(private_data->draw_cache)); - } - - return ; -} - -static void print_calculate_buffer_data(FooCanvasZMapText *zmap, - ZMapTextDrawData draw_data, - int cx1, int cy1, - int cx2, int cy2) -{ - if(debug_table) - { - printf("foo y1,y2,r: %d, %d, %d\n", - cy1, cy2, cy2 - cy1 + 1); - printf("world range/canvas range = %f\n", - ((draw_data->y2 - draw_data->y1 + 1) / (cy2 - cy1 + 1))); - printf("world range (txt)/canvas range = %f\n", - (((draw_data->y2 - draw_data->y1 + 1) * draw_data->table.ch_height) / ((cy2 - cy1 + 1)))); - } - - return ; -} - -int foo_canvas_zmap_text_calculate_zoom_buffer_size(FooCanvasItem *item, - ZMapTextDrawData draw_data, - int max_buffer_size) -{ - FooCanvasZMapText *zmap = FOO_CANVAS_ZMAP_TEXT(item); - int buffer_size = max_buffer_size; - int char_per_line, line_count; - int cx1, cy1, cx2, cy2, cx, cy; /* canvas coords of scroll region and item */ - int table; - int width, height; - double world_range, raw_chars_per_line, raw_lines; - int real_chars_per_line, canvas_range; - int real_lines, real_lines_space; - - if(draw_data->y1 < 0.0) - { - double t = 0.0 - draw_data->y1; - draw_data->y1 = 0.0; - draw_data->y2 -= t; - } - - foo_canvas_w2c(item->canvas, draw_data->x1, draw_data->y1, &cx1, &cy1); - foo_canvas_w2c(item->canvas, draw_data->x2, draw_data->y2, &cx2, &cy2); - foo_canvas_w2c(item->canvas, draw_data->wx, draw_data->wy, &cx, &cy); - - /* We need to know the extents of a character */ - width = draw_data->table.ch_width; - height = draw_data->table.ch_height; - - /* possibly print out some debugging info */ - print_calculate_buffer_data(zmap, draw_data, cx1, cy1, cx2, cy2); - print_private_data(zmap->priv); - - /* world & canvas range to work out rough chars per line */ - world_range = (draw_data->y2 - draw_data->y1 + 1); - canvas_range = (cy2 - cy1 + 1); - raw_chars_per_line = ((world_range * height) / canvas_range); - - if((double)(real_chars_per_line = (int)raw_chars_per_line) < raw_chars_per_line) - real_chars_per_line++; - - raw_lines = world_range / real_chars_per_line; - - if((double)(real_lines = (int)raw_lines) < raw_lines) - real_lines++; - - real_lines_space = real_lines * height; - - if(real_lines_space > canvas_range) - { - real_lines--; - real_lines_space = real_lines * height; - } - - if(real_lines_space < canvas_range) - { - double spacing_dbl = canvas_range; - double delta_factor = 0.15; - int spacing; - spacing_dbl -= (real_lines * height); - spacing_dbl /= real_lines; - - /* need a fudge factor here! We want to round up if we're - * within delta factor of next integer */ - - if(((double)(spacing = (int)spacing_dbl) < spacing_dbl) && - ((spacing_dbl + delta_factor) > (double)(spacing + 1))) - spacing_dbl = (double)(spacing + 1); - - draw_data->table.spacing = (int)(spacing_dbl * PANGO_SCALE); - draw_data->table.spacing = spacing_dbl; - } - - line_count = real_lines; - - char_per_line = (int)(zmap->priv->requested_width); - - draw_data->table.untruncated_width = real_chars_per_line; - - if(real_chars_per_line <= char_per_line) - { - char_per_line = real_chars_per_line; - draw_data->table.truncated = FALSE; - } - else - { - draw_data->table.truncated = TRUE; - } - - draw_data->table.width = char_per_line; - draw_data->table.height = line_count; - - table = char_per_line * line_count; - - buffer_size = MIN(buffer_size, table); - - return buffer_size; -} - -static void allocate_buffer_size(FooCanvasZMapText *zmap) -{ - FooCanvasZMapTextPrivate *private_data; - - private_data = zmap->priv; - - if(private_data->buffer_size == 0) - { - FooCanvasText *parent_text = FOO_CANVAS_TEXT(zmap); - int char_per_line, line_count; - int pixel_size_x, pixel_size_y; - int spacing, max_canvas; - - /* work out how big the buffer should be. */ - pango_layout_get_pixel_size(parent_text->layout, - &pixel_size_x, &pixel_size_y); - spacing = pango_layout_get_spacing(parent_text->layout); - - char_per_line = pixel_size_y + spacing; - line_count = 1 << 15; /* 32768 Maximum canvas size ever */ - max_canvas = 1 << 15; - - /* This is on the side of caution, but possibly by a factor of 10. */ - private_data->buffer_size = char_per_line * line_count; - - /* The most that can really be displayed is the requested width - * when the zoom allows drawing this at exactly at the height of - * the text. The canvas will never be bigger than 32768 so that - * means 32768 / pixel_size_y * requested_width - */ - private_data->buffer_size = max_canvas / char_per_line * private_data->requested_width; - - private_data->buffer = g_new0(char, private_data->buffer_size + 1); - -#ifdef __GNUC__ - if(debug_allocate) - printf("%s: allocated %d.\n", __PRETTY_FUNCTION__, private_data->buffer_size); -#endif /* __GNUC__ */ - } - - return ; -} - -static void run_update_cycle_loop(FooCanvasItem *item) -{ - FooCanvasZMapText *zmap; - FooCanvasZMapTextPrivate *private_data; - gboolean canvas_changed = FALSE; - - zmap = FOO_CANVAS_ZMAP_TEXT(item); - private_data = zmap->priv; - canvas_changed = canvas_has_changed(item, &(private_data->update_cache)); - - if(canvas_changed) - { - PangoLayout *layout = FOO_CANVAS_TEXT(item)->layout; - ZMapTextDrawDataStruct clear = {0}; - - /* This simple bit of code speeds everything up ;) */ - pango_layout_set_text(layout, "", 0); - - invoke_allocate_width_height(item); - - /* clear the draw cache... to absolutely guarantee the draw - * code sees the canvas has changed! */ - private_data->draw_cache = clear; - } - - return ; -} - -static void invoke_allocate_width_height(FooCanvasItem *item) -{ - FooCanvasZMapText *zmap; - FooCanvasZMapTextPrivate *private_data; - ZMapTextDrawData draw_data; - ZMapTextDrawDataStruct draw_data_stack = {}; - FooCanvasText *text; - int spacing, width, height, actual_size; - - zmap = FOO_CANVAS_ZMAP_TEXT(item); - text = FOO_CANVAS_TEXT(item); - - private_data = zmap->priv; - draw_data = &(private_data->update_cache); - - draw_data_stack = *draw_data; /* struct copy! */ - - /* We need to know the extents of a character */ - draw_data_stack.table.ch_width = PANGO_PIXELS(zmap->priv->char_extents.width); - draw_data_stack.table.ch_height = PANGO_PIXELS(zmap->priv->char_extents.height); - - if(private_data->allocate_func) - actual_size = (private_data->allocate_func)(item, &draw_data_stack, - (int)(private_data->requested_width), - private_data->buffer_size, - private_data->callback_data); - else - actual_size = foo_canvas_zmap_text_calculate_zoom_buffer_size(item, - &draw_data_stack, - private_data->buffer_size); - - /* The only part we allow to be copied back... */ - draw_data->table = draw_data_stack.table; /* struct copy */ - - if(actual_size > 0) - { - double ztmp; - if(actual_size != (draw_data->table.width * draw_data->table.height)) - g_warning("Allocated size of %d does not match table allocation of %d x %d.", - actual_size, draw_data->table.width, draw_data->table.height); - - if(private_data->buffer_size <= (draw_data->table.width * draw_data->table.height)) - { - g_warning("Allocated size of %d is _too_ big. Buffer is only %d long!", - actual_size, private_data->buffer_size); - - draw_data->table.height = private_data->buffer_size / draw_data->table.width; - actual_size = draw_data->table.width * draw_data->table.height; - g_warning("Reducing table size to %d by reducing rows to %d. Please fix %p.", - actual_size, draw_data->table.height, private_data->allocate_func); - } - - if(debug_table) - printf("spacing %f = %f\n", - draw_data_stack.table.spacing, - draw_data_stack.table.spacing * PANGO_SCALE); - - spacing = (int)(draw_data_stack.table.spacing * PANGO_SCALE); - width = (int)(draw_data_stack.table.ch_width * - draw_data_stack.table.width * PANGO_SCALE); - - /* Need to add the spacing otherwise we lose the last bits as the update/bounds - * calculation which group_draw filters on will not draw the extra bit between - * (height * rows) and ((height + spacing) * rows). - */ - ztmp = (draw_data_stack.zy > 1.0 ? draw_data_stack.zy : 1.0); - - height = (int)((draw_data_stack.table.ch_height + - draw_data_stack.table.spacing) * ztmp * - draw_data_stack.table.height * PANGO_SCALE); - - - /* I'm seriously unsure about the width & height calculations here. - * ( mainly the height one as zoom is always fixed in x for us ;) ) - * Without the conditional (zoom factor @ high factors) text doesn't get drawn - * below a certain point, but including the zoom factor when < 1.0 has the same - * effect @ lower factors. I haven't investigated enough to draw a good conclusion - * and there doesn't seem to be any affect on speed. So it's been left in! - * - * Thoughts are it could be to do with scroll offsets or rounding or some - * interaction with the floating group. - * RDS - */ - - pango_layout_set_spacing(text->layout, spacing); - - pango_layout_set_width(text->layout, width); - - width = PANGO_PIXELS(width); - height= PANGO_PIXELS(height); - text->max_width = width; - text->height = height; - } - - return ; -} - -static gboolean invoke_get_text(FooCanvasItem *item) -{ - FooCanvasText *parent_text; - FooCanvasZMapText *zmap; - FooCanvasZMapTextPrivate *private_data; - gboolean got_text = FALSE; - gboolean changed = FALSE; - - parent_text = FOO_CANVAS_TEXT(item); - zmap = FOO_CANVAS_ZMAP_TEXT(item); - private_data = zmap->priv; - - run_update_cycle_loop(item); - - /* has the canvas changed according to the last time we drew */ - if(private_data->fetch_text_func && - (changed = canvas_has_changed(item, &(private_data->draw_cache)))) - { - ZMapTextDrawData draw_data; - ZMapTextDrawDataStruct draw_data_stack = {}; - int actual_size = 0; - - sync_data(&(private_data->update_cache), - &(private_data->draw_cache)); - - draw_data = &(private_data->draw_cache); - draw_data_stack = *draw_data; /* struct copy! */ - - /* item coords. */ - draw_data_stack.wx = parent_text->x; - draw_data_stack.wy = parent_text->y; - - /* translate to world... */ - foo_canvas_item_i2w(item, - &(draw_data_stack.wx), - &(draw_data_stack.wy)); - - /* try and get the text from the user specified callback. */ - actual_size = (private_data->fetch_text_func)(item, - &draw_data_stack, - private_data->buffer, - private_data->buffer_size, - private_data->callback_data); - - draw_data->table = draw_data_stack.table; /* struct copy */ - - if(actual_size > 0 && private_data->buffer[0] != '\0') - { - /* If actual size is too big Pango will be slower than it needs to be. */ - if(actual_size > (draw_data->table.width * draw_data->table.height)) - g_warning("Returned size of %d is _too_ big. Text table is only %d.", - actual_size, (draw_data->table.width * draw_data->table.height)); - if(actual_size > private_data->buffer_size) - g_warning("Returned size of %d is _too_ big. Buffer is only %d long!", - actual_size, private_data->buffer_size); - - /* So that foo_canvas_zmap_text_get_property() returns text. */ - parent_text->text = private_data->buffer; - /* Set the text in the pango layout */ - pango_layout_set_text(parent_text->layout, private_data->buffer, actual_size); - - foo_canvas_item_request_update(item); - } - } - - if(parent_text->text) - got_text = TRUE; - - return got_text; -} - -static gboolean canvas_has_changed(FooCanvasItem *item, - ZMapTextDrawData draw_data) -{ - FooCanvasText *parent_text; - FooCanvasZMapText *zmap; - FooCanvasZMapTextPrivate *private_data; - gboolean canvas_changed = FALSE; - int no_change = 0; - - zmap = FOO_CANVAS_ZMAP_TEXT(item); - parent_text = FOO_CANVAS_TEXT(item); - private_data = zmap->priv; - - if((private_data->flags & ZOOM_NOTIFY_MASK)) - { - if(draw_data->zy == item->canvas->pixels_per_unit_y && - draw_data->zx == item->canvas->pixels_per_unit_x) - { - no_change |= ZOOM_NOTIFY_MASK; - } - else - { - draw_data->zx = item->canvas->pixels_per_unit_x; - draw_data->zy = item->canvas->pixels_per_unit_y; - } - } - - if((private_data->flags & SCROLL_REGION_NOTIFY_MASK)) - { - double sx1, sy1, sx2, sy2; - - foo_canvas_get_scroll_region(item->canvas, &sx1, &sy1, &sx2, &sy2); - - if((draw_data->x1 != sx1) || - (draw_data->y1 != sy1) || - (draw_data->x2 != sx2) || - (draw_data->y2 != sy2)) - { - draw_data->x1 = sx1; - draw_data->y1 = sy1; - draw_data->x2 = sx2; - draw_data->y2 = sy2; - } - else - no_change |= SCROLL_REGION_NOTIFY_MASK; - } - - /* if no change in zoom and scroll region */ - if((no_change & (ZOOM_NOTIFY_MASK)) && - (no_change & (SCROLL_REGION_NOTIFY_MASK))) - canvas_changed = FALSE; - else - canvas_changed = TRUE; - - return canvas_changed; -} - - -static void save_origin(FooCanvasItem *item) -{ - FooCanvasZMapText *text; - FooCanvasText *parent; - - text = FOO_CANVAS_ZMAP_TEXT (item); - parent = FOO_CANVAS_TEXT(item); - - text->priv->update_cache.wx = parent->x; - text->priv->update_cache.wy = parent->y; - - foo_canvas_get_scroll_region(item->canvas, - &(text->priv->update_cache.x1), - &(text->priv->update_cache.y1), - &(text->priv->update_cache.x2), - &(text->priv->update_cache.y2)); - - sync_data(&(text->priv->update_cache), - &(text->priv->draw_cache)); - - return ; -} - -static void sync_data(ZMapTextDrawData from, ZMapTextDrawData to) -{ - /* Straight forward copy... */ - to->wx = from->wx; - to->wy = from->wy; - - to->x1 = from->x1; - to->y1 = from->y1; - to->x2 = from->x2; - to->y2 = from->y2; - - to->table = from->table; /* struct copy */ - - return ; -} - -/* ******** faster gdk drawing code. ******** */ - -/* direct copy of get_renderer from gdkpango.c */ -static PangoRenderer *zmap_get_renderer(GdkDrawable *drawable, - GdkGC *gc, - GdkColor *foreground, - GdkColor *background) -{ - GdkScreen *screen = gdk_drawable_get_screen (drawable); - PangoRenderer *renderer = gdk_pango_renderer_get_default (screen); - GdkPangoRenderer *gdk_renderer = GDK_PANGO_RENDERER (renderer); - - gdk_pango_renderer_set_drawable (gdk_renderer, drawable); - gdk_pango_renderer_set_gc (gdk_renderer, gc); - - gdk_pango_renderer_set_override_color (gdk_renderer, - PANGO_RENDER_PART_FOREGROUND, - foreground); - gdk_pango_renderer_set_override_color (gdk_renderer, - PANGO_RENDER_PART_UNDERLINE, - foreground); - gdk_pango_renderer_set_override_color (gdk_renderer, - PANGO_RENDER_PART_STRIKETHROUGH, - foreground); - - gdk_pango_renderer_set_override_color (gdk_renderer, - PANGO_RENDER_PART_BACKGROUND, - background); - - pango_renderer_activate (renderer); - - return renderer; -} - -/* direct copy of release_renderer from gdkpango.c */ -static void zmap_release_renderer (PangoRenderer *renderer) -{ - GdkPangoRenderer *gdk_renderer = GDK_PANGO_RENDERER (renderer); - - pango_renderer_deactivate (renderer); - - gdk_pango_renderer_set_override_color (gdk_renderer, - PANGO_RENDER_PART_FOREGROUND, - NULL); - gdk_pango_renderer_set_override_color (gdk_renderer, - PANGO_RENDER_PART_UNDERLINE, - NULL); - gdk_pango_renderer_set_override_color (gdk_renderer, - PANGO_RENDER_PART_STRIKETHROUGH, - NULL); - gdk_pango_renderer_set_override_color (gdk_renderer, - PANGO_RENDER_PART_BACKGROUND, - NULL); - - gdk_pango_renderer_set_drawable (gdk_renderer, NULL); - gdk_pango_renderer_set_gc (gdk_renderer, NULL); - - return ; -} - -/* based on pango_renderer_draw_layout, but additionally filters based - * on the expose region */ -static void zmap_pango_renderer_draw_layout_get_size (PangoRenderer *renderer, - PangoLayout *layout, - int x, - int y, - GdkEventExpose *expose, - GdkRectangle *size_in_out) -{ - PangoLayoutIter *iter; - g_return_if_fail (PANGO_IS_RENDERER (renderer)); - g_return_if_fail (PANGO_IS_LAYOUT (layout)); - - /* some missing code here that deals with matrices, but as none is - * used for the canvas, its removed. */ - - pango_renderer_activate (renderer); - - iter = pango_layout_get_iter (layout); - - do - { - GdkRectangle line_rect; - GdkOverlapType overlap; - PangoRectangle logical_rect; - PangoLayoutLine *line; - int baseline; - - line = pango_layout_iter_get_line (iter); - - pango_layout_iter_get_line_extents (iter, NULL, &logical_rect); - baseline = pango_layout_iter_get_baseline (iter); - - line_rect.x = PANGO_PIXELS(x + logical_rect.x); - line_rect.y = PANGO_PIXELS(y + logical_rect.y); - line_rect.width = PANGO_PIXELS(logical_rect.width); - line_rect.height = PANGO_PIXELS(logical_rect.height); - - /* additionally in this code we want to get the size of the text. */ - if(size_in_out) - gdk_rectangle_union(&line_rect, size_in_out, size_in_out); - - if((overlap = gdk_region_rect_in(expose->region, &line_rect)) != GDK_OVERLAP_RECTANGLE_OUT) - { - pango_renderer_draw_layout_line (renderer, - line, - x + logical_rect.x, - y + baseline); - } - } - while (pango_layout_iter_next_line (iter)); - - pango_layout_iter_free (iter); - - pango_renderer_deactivate (renderer); - - return ; -} - -/* similar to gdk_draw_layout/gdk_draw_layout_with_colours, but calls - * the functions above. */ -static void zmap_gdk_draw_layout_get_size_within_expose(GdkDrawable *drawable, - GdkGC *gc, - int x, - int y, - PangoLayout *layout, - GdkEventExpose *expose, - int *width_max_in_out, - int *height_max_in_out) -{ - GdkRectangle size = {0}, *size_ptr = NULL; - PangoRenderer *renderer; - GdkColor *foreground = NULL; - GdkColor *background = NULL; - - /* gdk_draw_layout just calls gdk_draw_layout_with_colours, which is - * the source of this function. */ - - /* get_renderer */ - renderer = zmap_get_renderer (drawable, gc, foreground, background); - - if(width_max_in_out && height_max_in_out) - { - size.x = x; - size.y = y; - size.width = *width_max_in_out; - size.height = *height_max_in_out; - size_ptr = &size; - } - - /* draw_lines of text */ - zmap_pango_renderer_draw_layout_get_size(renderer, layout, - x * PANGO_SCALE, - y * PANGO_SCALE, - expose, - size_ptr); - - if(size_ptr) - { - *width_max_in_out = size_ptr->width; - *height_max_in_out = size_ptr->height; - } - - /* release renderer */ - zmap_release_renderer (renderer); - - return ; -} diff --git a/foocanvas/additional_files/foozmap-canvas-text.h b/foocanvas/additional_files/foozmap-canvas-text.h deleted file mode 100755 index d444a32746b7cbff9e10f6993635b089d8b9620f..0000000000000000000000000000000000000000 --- a/foocanvas/additional_files/foozmap-canvas-text.h +++ /dev/null @@ -1,132 +0,0 @@ -/* File: foozmap-canvas-text.h - * Author: Roy Storey (rds@sanger.ac.uk) - * Copyright (c) 2008: Genome Research Ltd. - *------------------------------------------------------------------- - * ZMap 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 2 - * of the License, or (at your option) any later version. - * - * This program 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 more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * or see the on-line version at http://www.gnu.org/copyleft/gpl.txt - *------------------------------------------------------------------- - * This file is part of the ZMap genome database package - * originally written by: - * - * Ed Griffiths (Sanger Institute, UK) edgrif@sanger.ac.uk, - * Roy Storey (Sanger Institute, UK) rds@sanger.ac.uk - * - * Description: - * - * Exported functions: See XXXXXXXXXXXXX.h - * HISTORY: - * Last edited: Mar 17 09:20 2008 (rds) - * Created: Thu Jan 24 08:36:51 2008 (rds) - * CVS info: $Id: foozmap-canvas-text.h,v 1.4 2008-03-20 13:22:12 rds Exp $ - *------------------------------------------------------------------- - */ - -#ifndef FOO_CANVAS_ZMAP_TEXT_H -#define FOO_CANVAS_ZMAP_TEXT_H - - -#include <libfoocanvas/foo-canvas.h> - - -G_BEGIN_DECLS - -/* Extended FooCanvasText Item. - * Specialised to call a callback before drawing. - */ - -#define FOO_TYPE_CANVAS_ZMAP_TEXT (foo_canvas_zmap_text_get_type ()) -#define FOO_CANVAS_ZMAP_TEXT(obj) (GTK_CHECK_CAST ((obj), FOO_TYPE_CANVAS_ZMAP_TEXT, FooCanvasZMapText)) -#define FOO_CANVAS_ZMAP_TEXT_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), FOO_TYPE_CANVAS_ZMAP_TEXT, FooCanvasZMapTextClass)) -#define FOO_IS_CANVAS_ZMAP_TEXT(obj) (GTK_CHECK_TYPE ((obj), FOO_TYPE_CANVAS_ZMAP_TEXT)) -#define FOO_IS_CANVAS_ZMAP_TEXT_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), FOO_TYPE_CANVAS_ZMAP_TEXT)) -#define FOO_CANVAS_ZMAP_TEXT_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), FOO_TYPE_CANVAS_ZMAP_TEXT, FooCanvasZMapTextClass)) - - -typedef struct _FooCanvasZMapText FooCanvasZMapText; -typedef struct _FooCanvasZMapTextClass FooCanvasZMapTextClass; - -typedef struct _FooCanvasZMapTextPrivate FooCanvasZMapTextPrivate; - -typedef struct _ZMapTextDrawDataStruct *ZMapTextDrawData ; - -typedef struct -{ - double spacing; /* spacing between lines in canvas coord space. N.B. double! */ - int ch_width, ch_height; /* individual cell dimensions (canvas size)*/ - int width, height; /* table dimensions in number of cells */ - int untruncated_width; - gboolean truncated; -}ZMapTextTableStruct, *ZMapTextTable; - -typedef struct _ZMapTextDrawDataStruct -{ - double zx, zy; /* zoom factor */ - double x1, x2, y1, y2; /* scroll region */ - double wx, wy; /* world position of item */ - ZMapTextTableStruct table; -} ZMapTextDrawDataStruct ; - -struct _FooCanvasZMapText -{ - FooCanvasText text; - - FooCanvasZMapTextPrivate *priv; -}; - -struct _FooCanvasZMapTextClass -{ - FooCanvasItemClass parent_class; -}; - -typedef gint (* FooCanvasZMapAllocateCB)(FooCanvasItem *item, - ZMapTextDrawData draw_data, - gint max_width, - gint buffer_size, - gpointer user_data); - -typedef gint (* FooCanvasZMapFetchTextCB)(FooCanvasItem *item, - ZMapTextDrawData draw_data, - char *buffer, - gint buffer_size, - gpointer user_data); - - -typedef gboolean (* FooCanvasTextLineFunc)(FooCanvasItem *item, /* foocanvas item */ - PangoLayoutIter *iter, /* pango layout iter used for foreach iteration */ - PangoLayoutLine *line, /* current line of iteration, saves pango_layout_iter_get_line() */ - PangoRectangle *logical_rect, /* logical rect of line as from pango_layout_iter_get_line_extents() */ - int iter_line_index, /* index of line in layout, pango_layout_get_line() compatible */ - double wx, /* world x */ - double wy, /* world y */ - gpointer user_data); /* user data. */ - -/* Standard Gtk function */ -GtkType foo_canvas_zmap_text_get_type (void) G_GNUC_CONST; - -void foo_canvas_pango2item(FooCanvas *canvas, int px, int py, double *ix, double *iy); - -int foo_canvas_zmap_text_calculate_zoom_buffer_size(FooCanvasItem *item, - ZMapTextDrawData draw_data, - int max_buffer_size); - -int foo_canvas_item_world2text_index(FooCanvasItem *item, double x, double y); -int foo_canvas_item_item2text_index(FooCanvasItem *item, double x, double y); -gboolean foo_canvas_item_text_index2item(FooCanvasItem *item, - int index, - double *item_coords_out); - -G_END_DECLS - -#endif