canvasitem.c \
canvastext.c \
canvasline.c \
- canvasrect.c
+ canvasrect.c \
+ canvasellipse.c
#include "canvastext.h"
#include "canvasline.h"
#include "canvasrect.h"
+#include "canvasellipse.h"
static void grpt_canvas_class_init (GRptCanvasClass *klass);
static void grpt_canvas_init (GRptCanvas *canvas);
G_TYPE_NONE,
1,
G_TYPE_POINTER);
+ klass->selection_changed_signal_id = g_signal_new ("selection-changed",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_POINTER);
}
static void
RPT_OBJ_TEXT (rpt_object),
NULL);
}
+ else if (IS_RPT_OBJ_ELLIPSE (rpt_object))
+ {
+ item = grpt_canvas_ellipse_new (priv->root,
+ x, y,
+ width, height,
+ RPT_OBJ_ELLIPSE (rpt_object),
+ NULL);
+ }
else if (IS_RPT_OBJ_RECT (rpt_object))
{
item = grpt_canvas_rect_new (priv->root,
GdkEventButton *event,
gpointer user_data)
{
- GRptCanvasPrivate *priv = GRPT_CANVAS_GET_PRIVATE ((GRptCanvas *)user_data);
+ GRptCanvas *grpt_canvas = (GRptCanvas *)user_data;
+
+ GRptCanvasPrivate *priv = GRPT_CANVAS_GET_PRIVATE (grpt_canvas);
+ GRptCanvasClass *klass = GRPT_CANVAS_GET_CLASS (grpt_canvas);
if (event->button == 1)
{
{
if (!grpt_canvas_item_is_selected (GRPT_CANVAS_ITEM (item)))
{
+ GList *sel = NULL;
+
grpt_canvas_item_set_selected (GRPT_CANVAS_ITEM (item), TRUE);
+
+ sel = g_list_append (sel, item);
+ g_signal_emit (grpt_canvas, klass->selection_changed_signal_id, 0,
+ sel);
+
+ g_list_free (sel);
}
priv->in_selection = FALSE;
RptPoint position;
GRptCanvas *grpt_canvas = (GRptCanvas *)user_data;
+
GRptCanvasPrivate *priv = GRPT_CANVAS_GET_PRIVATE (grpt_canvas);
+ GRptCanvasClass *klass = GRPT_CANVAS_GET_CLASS (grpt_canvas);
if (event->button == 1)
{
case TOOL_RECT:
rpt_object = rpt_obj_rect_new (get_new_object_name (priv->tool), position);
break;
+
+ case TOOL_ELLIPSE:
+ rpt_object = rpt_obj_ellipse_new (get_new_object_name (priv->tool), position);
+ break;
}
if (rpt_object != NULL)
{
objects = g_list_next (objects);
}
+
+ objects = g_list_first (objects);
+ g_signal_emit (grpt_canvas, klass->selection_changed_signal_id, 0,
+ objects);
+
g_list_free (objects);
}
else
void
grpt_canvas_remove_item (GRptCanvas *grpt_canvas, GRptCanvasItem *grpt_canvas_item)
{
+ RptObject *rpt_obj;
+
RptReportSection section = grpt_canvas_item_get_section (grpt_canvas_item);
GRptCanvasPrivate *priv = GRPT_CANVAS_GET_PRIVATE (grpt_canvas);
break;
}
+ rpt_obj = grpt_canvas_item_get_rpt_object (grpt_canvas_item);
+ rpt_report_remove_object (priv->rpt_report, rpt_obj);
+ g_object_unref (rpt_obj);
+
g_signal_emit (grpt_canvas, klass->object_removed_signal_id, 0,
grpt_canvas_item);
--- /dev/null
+/*
+ * Copyright (C) 2007 Andrea Zagli <azagli@inwind.it>
+ *
+ * This program 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.
+ */
+
+#include "canvasellipse.h"
+
+
+static void grpt_canvas_ellipse_class_init (GRptCanvasEllipseClass *klass);
+static void grpt_canvas_ellipse_init (GRptCanvasEllipse *grpt_canvas_ellipse);
+
+
+static void grpt_canvas_ellipse_paint (GooCanvasItemSimple *simple,
+ cairo_t *cr,
+ const GooCanvasBounds *bounds);
+
+static RptObject *grpt_canvas_ellipse_get_rpt_object (GRptCanvasItem *grpt_canvas_item);
+
+
+#define GRPT_CANVAS_ELLIPSE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GRPT_TYPE_CANVAS_ELLIPSE, GRptCanvasEllipsePrivate))
+
+
+typedef struct _GRptCanvasEllipsePrivate GRptCanvasEllipsePrivate;
+struct _GRptCanvasEllipsePrivate
+ {
+ RptObjEllipse *rpt_object_ellipse;
+ };
+
+GType
+grpt_canvas_ellipse_get_type (void)
+{
+ static GType grpt_canvas_ellipse_type = 0;
+
+ if (!grpt_canvas_ellipse_type)
+ {
+ static const GTypeInfo grpt_canvas_ellipse_info =
+ {
+ sizeof (GRptCanvasEllipseClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc) grpt_canvas_ellipse_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (GRptCanvasEllipse),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) grpt_canvas_ellipse_init,
+ NULL
+ };
+
+ grpt_canvas_ellipse_type = g_type_register_static (GRPT_TYPE_CANVAS_ITEM, "GRptCanvasEllipse",
+ &grpt_canvas_ellipse_info, 0);
+ }
+
+ return grpt_canvas_ellipse_type;
+}
+
+static void
+grpt_canvas_ellipse_class_init (GRptCanvasEllipseClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GRptCanvasItemClass *canvas_item_class = GRPT_CANVAS_ITEM_CLASS (klass);
+ GooCanvasItemSimpleClass *simple_class = (GooCanvasItemSimpleClass *)klass;
+
+ g_type_class_add_private (object_class, sizeof (GRptCanvasEllipsePrivate));
+
+ canvas_item_class->paint = grpt_canvas_ellipse_paint;
+ canvas_item_class->get_rpt_object = grpt_canvas_ellipse_get_rpt_object;
+}
+
+static void
+grpt_canvas_ellipse_init (GRptCanvasEllipse *grpt_canvas_ellipse)
+{
+}
+
+GRptCanvasItem
+*grpt_canvas_ellipse_new (GooCanvasItem *parent, gdouble x, gdouble y, gdouble width, gdouble height, RptObjEllipse *rpt_object_ellipse, ...)
+{
+ GRptCanvasItem *item;
+ GRptCanvasEllipse *grpt_canvas_ellipse;
+
+ RptPoint position;
+ RptSize size;
+
+ const char *first_property;
+ va_list var_args;
+ GRptCanvasEllipsePrivate *priv;
+
+ item = g_object_new (GRPT_TYPE_CANVAS_ELLIPSE, NULL);
+
+ grpt_canvas_ellipse = (GRptCanvasEllipse *)item;
+
+ priv = GRPT_CANVAS_ELLIPSE_GET_PRIVATE (grpt_canvas_ellipse);
+ priv->rpt_object_ellipse = g_object_ref (rpt_object_ellipse);
+
+ va_start (var_args, rpt_object_ellipse);
+ first_property = va_arg (var_args, char*);
+ if (first_property)
+ {
+ g_object_set_valist ((GObject *)item, first_property, var_args);
+ }
+ va_end (var_args);
+
+ if (parent)
+ {
+ goo_canvas_item_add_child (parent, GOO_CANVAS_ITEM (item), -1);
+ g_object_unref (item);
+ }
+
+ position.x = x;
+ position.y = y;
+ grpt_canvas_item_set_position (item, position);
+
+ size.width = width;
+ size.height = height;
+ grpt_canvas_item_set_size (item, size);
+
+ return item;
+}
+
+static void
+grpt_canvas_ellipse_paint (GooCanvasItemSimple *simple, cairo_t *cr, const GooCanvasBounds *bounds)
+{
+ RptPoint *position = NULL;
+ RptSize *size = NULL;
+ RptRotation *rotation = NULL;
+ RptStroke *stroke = NULL;
+ RptColor *fill_color = NULL;
+
+ GRptCanvasEllipse *grpt_canvas_ellipse = (GRptCanvasEllipse *)simple;
+
+ GRptCanvasItem *grpt_canvas_item = (GRptCanvasItem *)simple;
+
+ GRptCanvasEllipsePrivate *priv = GRPT_CANVAS_ELLIPSE_GET_PRIVATE (grpt_canvas_ellipse);
+
+ g_object_get (G_OBJECT (priv->rpt_object_ellipse),
+ "position", &position,
+ "size", &size,
+ "rotation", &rotation,
+ "stroke", &stroke,
+ "fill-color", &fill_color,
+ NULL);
+
+ if (position == NULL || size == NULL)
+ {
+ return;
+ }
+ if (stroke == NULL)
+ {
+ stroke = (RptStroke *)g_malloc0 (sizeof (RptStroke));
+ stroke->width = 1.0;
+ stroke->color = (RptColor *)g_malloc0 (sizeof (RptColor));
+ stroke->color->a = 1.0;
+ stroke->style = NULL;
+ }
+
+ if (rotation != NULL)
+ {
+ /* TO DO */
+ /*rpt_print_rotate (rpt_print, position, size, rotation->angle);*/
+ }
+
+ /* TO DO */
+ /*cairo_set_line_width (priv->cr, stroke.width);*/
+ cairo_rectangle (cr, position->x, position->y, size->width, size->height);
+
+ if (fill_color != NULL)
+ {
+ cairo_set_source_rgba (cr, fill_color->r, fill_color->g, fill_color->b, fill_color->a);
+ cairo_fill_preserve (cr);
+ }
+
+ if (stroke->style != NULL)
+ {
+ gdouble *dash = rpt_common_style_to_array (stroke->style);
+ cairo_set_dash (cr, dash, stroke->style->len, 0.0);
+ }
+
+ cairo_set_source_rgba (cr, stroke->color->r, stroke->color->g, stroke->color->b, stroke->color->a);
+ cairo_stroke (cr);
+}
+
+static RptObject
+*grpt_canvas_ellipse_get_rpt_object (GRptCanvasItem *grpt_canvas_item)
+{
+ GRptCanvasEllipsePrivate *priv = GRPT_CANVAS_ELLIPSE_GET_PRIVATE (GRPT_CANVAS_ELLIPSE (grpt_canvas_item));
+
+ return RPT_OBJECT (priv->rpt_object_ellipse);
+}
--- /dev/null
+/*
+ * Copyright (C) 2007 Andrea Zagli <azagli@inwind.it>
+ *
+ * This program 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.
+ */
+
+#ifndef __GRPT_CANVAS_ELLIPSE_H__
+#define __GRPT_CANVAS_ELLIPSE_H__
+
+#include <gtk/gtk.h>
+#include <libreptool.h>
+
+#include "canvasitem.h"
+
+
+G_BEGIN_DECLS
+
+
+#define GRPT_TYPE_CANVAS_ELLIPSE (grpt_canvas_ellipse_get_type ())
+#define GRPT_CANVAS_ELLIPSE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GRPT_TYPE_CANVAS_ELLIPSE, GRptCanvasEllipse))
+#define GRPT_CANVAS_ELLIPSE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GRPT_TYPE_CANVAS_ELLIPSE, GRptCanvasEllipseClass))
+#define GRPT_IS_CANVAS_ELLIPSE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GRPT_TYPE_CANVAS_ELLIPSE))
+#define GRPT_IS_CANVAS_ELLIPSE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GRPT_TYPE_CANVAS_ELLIPSE))
+#define GRPT_CANVAS_ELLIPSE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GRPT_TYPE_CANVAS_ELLIPSE, GRptCanvasEllipseClass))
+
+
+typedef struct _GRptCanvasEllipse GRptCanvasEllipse;
+typedef struct _GRptCanvasEllipseClass GRptCanvasEllipseClass;
+
+struct _GRptCanvasEllipse
+{
+ GRptCanvasItem parent;
+};
+
+struct _GRptCanvasEllipseClass
+{
+ GRptCanvasItemClass parent_class;
+};
+
+GType grpt_canvas_ellipse_get_type (void) G_GNUC_CONST;
+
+GRptCanvasItem *grpt_canvas_ellipse_new (GooCanvasItem *parent,
+ gdouble x,
+ gdouble y,
+ gdouble width,
+ gdouble height,
+ RptObjEllipse *rpt_object_ellipse,
+ ...);
+
+
+G_END_DECLS
+
+
+#endif /* __GRPT_CANVAS_ELLIPSE_H__ */
void report_on_canvas_object_removed (GRptCanvas *grpt_canvas,
GRptCanvasItem *item,
gpointer user_data);
+void report_on_canvas_selection_changed (GRptCanvas *grpt_canvas,
+ GList *items,
+ gpointer user_data);
static gchar *report_filename;
g_signal_connect (grpt_canvas, "object-added", G_CALLBACK (report_on_canvas_object_added), NULL);
g_signal_connect (grpt_canvas, "object-removed", G_CALLBACK (report_on_canvas_object_removed), NULL);
+ g_signal_connect (grpt_canvas, "selection-changed", G_CALLBACK (report_on_canvas_selection_changed), NULL);
gtk_container_add (GTK_CONTAINER (vbox), canvas_widget);
gtk_box_reorder_child (GTK_BOX (vbox), canvas_widget, 3);
g_signal_connect (grpt_canvas, "object-added", G_CALLBACK (report_on_canvas_object_added), NULL);
g_signal_connect (grpt_canvas, "object-removed", G_CALLBACK (report_on_canvas_object_removed), NULL);
+ g_signal_connect (grpt_canvas, "selection-changed", G_CALLBACK (report_on_canvas_selection_changed), NULL);
gtk_container_add (GTK_CONTAINER (vbox), canvas_widget);
gtk_box_reorder_child (GTK_BOX (vbox), canvas_widget, 3);
grpt_objects_tree_remove_item (objects_tree, item);
}
+void
+report_on_canvas_selection_changed (GRptCanvas *grpt_canvas,
+ GList *items,
+ gpointer user_data)
+{
+ g_fprintf(stderr,"selection changed\n");
+}
+
/* PUBLIC */
Tool
get_current_tool ()