*
* Author: Federico Mena <federico@nuclecu.unam.mx>
*/
-
-
+
+
#include <string.h> /* for memcpy() */
#include <math.h>
#include <stdio.h>
#include "libart_lgpl/art_rgb_pixbuf_affine.h"
#include "canvas-imageframe.h"
#include <libgnomecanvas/gnome-canvas-util.h>
-#include <libgnomecanvas/gnome-canvastypebuiltins.h>
+#include "gettext.h"
+#define _(Text) dgettext (PACKAGE,Text)
+
+//GTK2FIX
+//#include <libgnomecanvas/gnome-canvastypebuiltins.h>
enum {
- ARG_0,
- ARG_PIXBUF,
- ARG_X,
- ARG_Y,
- ARG_WIDTH,
- ARG_HEIGHT,
- ARG_DRAWWIDTH,
- ARG_ANCHOR
+ PROP_0,
+ PROP_PIXBUF,
+ PROP_X,
+ PROP_Y,
+ PROP_WIDTH,
+ PROP_HEIGHT,
+ PROP_DRAWWIDTH,
+ PROP_ANCHOR
};
static void gnome_canvas_imageframe_class_init(GnomeCanvasImageFrameClass* class) ;
static void gnome_canvas_imageframe_init(GnomeCanvasImageFrame* image) ;
static void gnome_canvas_imageframe_destroy(GtkObject* object) ;
-static void gnome_canvas_imageframe_set_arg(GtkObject* object, GtkArg* arg, guint arg_id) ;
-static void gnome_canvas_imageframe_get_arg(GtkObject* object, GtkArg* arg, guint arg_id) ;
-
+static void gnome_canvas_imageframe_set_property(GObject* object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gnome_canvas_imageframe_get_property(GObject* object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
static void gnome_canvas_imageframe_update(GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) ;
static void gnome_canvas_imageframe_realize(GnomeCanvasItem *item) ;
static void gnome_canvas_imageframe_unrealize(GnomeCanvasItem *item) ;
static void gnome_canvas_imageframe_draw(GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) ;
static double gnome_canvas_imageframe_point(GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item) ;
-static void gnome_canvas_imageframe_translate(GnomeCanvasItem *item, double dx, double dy) ;
static void gnome_canvas_imageframe_bounds(GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2) ;
static void gnome_canvas_imageframe_render(GnomeCanvasItem *item, GnomeCanvasBuf *buf) ;
static GnomeCanvasItemClass *parent_class;
-GtkType
+GType
gnome_canvas_imageframe_get_type (void)
{
- static GtkType imageframe_type = 0;
+ static GType imageframe_type = 0;
if (!imageframe_type) {
GtkTypeInfo imageframe_info = {
static void
gnome_canvas_imageframe_class_init (GnomeCanvasImageFrameClass *class)
{
+ GObjectClass *gobject_class;
GtkObjectClass *object_class;
GnomeCanvasItemClass *item_class;
+ gobject_class = (GObjectClass *) class;
object_class = (GtkObjectClass *) class;
item_class = (GnomeCanvasItemClass *) class;
parent_class = gtk_type_class (gnome_canvas_item_get_type ());
- gtk_object_add_arg_type ("GnomeCanvasImageFrame::pixbuf", GTK_TYPE_BOXED, GTK_ARG_WRITABLE, ARG_PIXBUF);
- gtk_object_add_arg_type ("GnomeCanvasImageFrame::x", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_X);
- gtk_object_add_arg_type ("GnomeCanvasImageFrame::y", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_Y);
- gtk_object_add_arg_type ("GnomeCanvasImageFrame::width", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_WIDTH);
- gtk_object_add_arg_type ("GnomeCanvasImageFrame::drawwidth", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_DRAWWIDTH);
- gtk_object_add_arg_type ("GnomeCanvasImageFrame::height", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_HEIGHT);
- gtk_object_add_arg_type ("GnomeCanvasImageFrame::anchor", GTK_TYPE_ANCHOR_TYPE, GTK_ARG_READWRITE, ARG_ANCHOR);
+ gobject_class->set_property = gnome_canvas_imageframe_set_property;
+ gobject_class->get_property = gnome_canvas_imageframe_get_property;
+
+ g_object_class_install_property (gobject_class,
+ PROP_PIXBUF,
+ g_param_spec_pointer ("pixbuf",
+ _("pixbuf"),
+ _("the pixbuf"),
+ G_PARAM_WRITABLE));
+ g_object_class_install_property (gobject_class,
+ PROP_X,
+ g_param_spec_double ("x",
+ _("x"),
+ _("x coordinate of upper left corner of rect"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE,
+ 0.0,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_Y,
+ g_param_spec_double ("y",
+ _("y"),
+ _("y coordinate of upper left corner of rect "),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE,
+ 0.0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class,
+ PROP_WIDTH,
+ g_param_spec_double ("width",
+ _("width"),
+ _("the width"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE,
+ 0.0,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_DRAWWIDTH,
+ g_param_spec_double ("drawwidth",
+ _("drawwidth"),
+ _("drawn width"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE,
+ 0.0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class,
+ PROP_HEIGHT,
+ g_param_spec_double ("height",
+ _("height"),
+ _("the height"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE,
+ 0.0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class,
+ PROP_ANCHOR,
+ g_param_spec_enum ("anchor",
+ _("anchor"),
+ _("the anchor"),
+ GTK_TYPE_ANCHOR_TYPE,
+ GTK_ANCHOR_NW,
+ G_PARAM_READWRITE));
object_class->destroy = gnome_canvas_imageframe_destroy;
- object_class->set_arg = gnome_canvas_imageframe_set_arg;
- object_class->get_arg = gnome_canvas_imageframe_get_arg;
item_class->update = gnome_canvas_imageframe_update;
item_class->realize = gnome_canvas_imageframe_realize;
item_class->unrealize = gnome_canvas_imageframe_unrealize;
item_class->draw = gnome_canvas_imageframe_draw;
item_class->point = gnome_canvas_imageframe_point;
- item_class->translate = gnome_canvas_imageframe_translate;
item_class->bounds = gnome_canvas_imageframe_bounds;
item_class->render = gnome_canvas_imageframe_render;
}
image->height = 0.0;
image->drawwidth = 0.0;
image->anchor = GTK_ANCHOR_CENTER;
- GNOME_CANVAS_ITEM(image)->object.flags |= GNOME_CANVAS_ITEM_NO_AUTO_REDRAW;
}
static void
g_return_if_fail (GNOME_CANVAS_IS_CANVAS_IMAGEFRAME (object));
image = GNOME_CANVAS_IMAGEFRAME (object);
-
+
image->cwidth = 0;
image->cheight = 0;
}
static void
-get_bounds (GnomeCanvasImageFrame *image, double *px1, double *py1, double *px2, double *py2)
-{
- GnomeCanvasItem *item;
- double i2c[6];
- ArtDRect i_bbox, c_bbox;
-
- item = GNOME_CANVAS_ITEM (image);
-
- gnome_canvas_item_i2c_affine (item, i2c);
-
- get_bounds_item_relative (image, &i_bbox.x0, &i_bbox.y0, &i_bbox.x1, &i_bbox.y1);
- art_drect_affine_transform (&c_bbox, &i_bbox, i2c);
-
- /* add a fudge factor */
- *px1 = c_bbox.x0 - 1;
- *py1 = c_bbox.y0 - 1;
- *px2 = c_bbox.x1 + 1;
- *py2 = c_bbox.y1 + 1;
-}
-
-/* deprecated */
-static void
-recalc_bounds (GnomeCanvasImageFrame *image)
-{
- GnomeCanvasItem *item;
-
- item = GNOME_CANVAS_ITEM (image);
-
- get_bounds (image, &item->x1, &item->y1, &item->x2, &item->y2);
-
- item->x1 = image->cx;
- item->y1 = image->cy;
- item->x2 = image->cx + image->cwidth;
- item->y2 = image->cy + image->cheight;
-
- gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item);
-}
-
-static void
-gnome_canvas_imageframe_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
+gnome_canvas_imageframe_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
GnomeCanvasItem *item;
GnomeCanvasImageFrame *image;
update = FALSE;
calc_bounds = FALSE;
- switch (arg_id) {
- case ARG_PIXBUF:
- if (item->canvas->aa && GTK_VALUE_BOXED (*arg)) {
+ switch (prop_id) {
+ case PROP_PIXBUF:
+ if (item->canvas->aa && g_value_get_pointer (value)) {
if (image->pixbuf != NULL)
art_pixbuf_free (image->pixbuf);
- image->pixbuf = GTK_VALUE_BOXED (*arg);
+ image->pixbuf = g_value_get_pointer (value);
}
update = TRUE;
break;
- case ARG_X:
- image->x = GTK_VALUE_DOUBLE (*arg);
+ case PROP_X:
+ image->x = g_value_get_double (value);
update = TRUE;
break;
- case ARG_Y:
- image->y = GTK_VALUE_DOUBLE (*arg);
+ case PROP_Y:
+ image->y = g_value_get_double (value);
update = TRUE;
break;
- case ARG_WIDTH:
- image->width = fabs (GTK_VALUE_DOUBLE (*arg));
+ case PROP_WIDTH:
+ image->width = fabs (g_value_get_double (value));
update = TRUE;
break;
- case ARG_HEIGHT:
- image->height = fabs (GTK_VALUE_DOUBLE (*arg));
+ case PROP_HEIGHT:
+ image->height = fabs (g_value_get_double (value));
update = TRUE;
break;
-
- case ARG_DRAWWIDTH:
- image->drawwidth = fabs (GTK_VALUE_DOUBLE (*arg));
+
+ case PROP_DRAWWIDTH:
+ image->drawwidth = fabs (g_value_get_double (value));
update = TRUE;
break;
- case ARG_ANCHOR:
- image->anchor = GTK_VALUE_ENUM (*arg);
+ case PROP_ANCHOR:
+ image->anchor = g_value_get_enum (value);
update = TRUE;
break;
break;
}
-#ifdef OLD_XFORM
- if (update)
- (* GNOME_CANVAS_ITEM_CLASS (item->object.klass)->update) (item, NULL, NULL, 0);
-
- if (calc_bounds)
- recalc_bounds (image);
-#else
if (update)
gnome_canvas_item_request_update (item);
-#endif
}
static void
-gnome_canvas_imageframe_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
+gnome_canvas_imageframe_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GnomeCanvasImageFrame *image;
image = GNOME_CANVAS_IMAGEFRAME (object);
- switch (arg_id) {
+ switch (prop_id) {
- case ARG_X:
- GTK_VALUE_DOUBLE (*arg) = image->x;
+ case PROP_X:
+ g_value_set_double (value, image->x);
break;
- case ARG_Y:
- GTK_VALUE_DOUBLE (*arg) = image->y;
+ case PROP_Y:
+ g_value_set_double (value, image->y);
break;
- case ARG_WIDTH:
- GTK_VALUE_DOUBLE (*arg) = image->width;
+ case PROP_WIDTH:
+ g_value_set_double (value, image->width);
break;
- case ARG_HEIGHT:
- GTK_VALUE_DOUBLE (*arg) = image->height;
+ case PROP_HEIGHT:
+ g_value_set_double (value, image->height);
break;
-
- case ARG_DRAWWIDTH:
- GTK_VALUE_DOUBLE (*arg) = image->drawwidth;
+
+ case PROP_DRAWWIDTH:
+ g_value_set_double (value, image->drawwidth);
break;
- case ARG_ANCHOR:
- GTK_VALUE_ENUM (*arg) = image->anchor;
+ case PROP_ANCHOR:
+ g_value_set_enum (value, image->anchor);
break;
default:
- arg->type = GTK_TYPE_INVALID;
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
image->need_recalc = TRUE ;
}
-#ifdef OLD_XFORM
- recalc_bounds (image);
-#else
get_bounds_item_relative (image, &i_bbox.x0, &i_bbox.y0, &i_bbox.x1, &i_bbox.y1);
art_drect_affine_transform (&c_bbox, &i_bbox, affine);
image->affine[3] = (affine[3] * image->height) / h;
image->affine[4] = i_bbox.x0 * affine[0] + i_bbox.y0 * affine[2] + affine[4];
image->affine[5] = i_bbox.x0 * affine[1] + i_bbox.y0 * affine[3] + affine[5];
-
-#endif
}
static void
gnome_canvas_imageframe_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
int x, int y, int width, int height)
{
- fprintf(stderr, "please don't use the CanvasImageFrame item in a non-aa Canvas\n") ;
- abort() ;
}
static double
return sqrt (dx * dx + dy * dy) / item->canvas->pixels_per_unit;
}
-static void
-gnome_canvas_imageframe_translate (GnomeCanvasItem *item, double dx, double dy)
-{
-#ifdef OLD_XFORM
- GnomeCanvasImageFrame *image;
-
- image = GNOME_CANVAS_IMAGEFRAME (item);
-
- image->x += dx;
- image->y += dy;
-
- recalc_bounds (image);
-#endif
-}
-
static void
gnome_canvas_imageframe_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2)
{