gcompris r3662 - in branches/gcomprixogoo: . src/gcompris src/goocanvas/src
- From: bcoudoin svn gnome org
- To: svn-commits-list gnome org
- Subject: gcompris r3662 - in branches/gcomprixogoo: . src/gcompris src/goocanvas/src
- Date: Fri, 2 Jan 2009 13:10:21 +0000 (UTC)
Author: bcoudoin
Date: Fri Jan 2 13:10:21 2009
New Revision: 3662
URL: http://svn.gnome.org/viewvc/gcompris?rev=3662&view=rev
Log:
Added an autocrop feature in the svg goocanvas item.
Modified:
branches/gcomprixogoo/ChangeLog
branches/gcomprixogoo/src/gcompris/config.c
branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.c
branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.h
Modified: branches/gcomprixogoo/src/gcompris/config.c
==============================================================================
--- branches/gcomprixogoo/src/gcompris/config.c (original)
+++ branches/gcomprixogoo/src/gcompris/config.c Fri Jan 2 13:10:21 2009
@@ -34,8 +34,9 @@
static GooCanvasItem *item_timer_text = NULL;
static GooCanvasItem *item_skin_text = NULL;
static GooCanvasItem *item_filter_text = NULL;
-static GdkPixbuf *pixmap_checked = NULL;
-static GdkPixbuf *pixmap_unchecked = NULL;
+static gchar *pixmap_checked = NULL;
+static gchar *pixmap_unchecked = NULL;
+static guint pixmap_width;
static gchar *current_locale = NULL;
static GList *skinlist = NULL;
@@ -194,9 +195,9 @@
"fill-color-rgba", gc_skin_color_title,
NULL);
- pixmap_checked = gc_skin_pixmap_load("button_checked.png");
- pixmap_unchecked = gc_skin_pixmap_load("button_unchecked.png");
-
+ pixmap_checked = "#CHECKED";
+ pixmap_unchecked = "#UNCHECKED";
+ pixmap_width = 30;
x_start += 150;
x_flag_start = x_start + 50;
@@ -209,9 +210,9 @@
display_previous_next(x_start, y_start, "locale_previous", "locale_next");
item_locale_flag = goo_canvas_svg_new (rootitem,
- rsvg_handle_new(),
- NULL);
- y_flag_start = y_start - gdk_pixbuf_get_width(pixmap_checked)/2;
+ rsvg_handle_new(),
+ NULL);
+ y_flag_start = y_start - pixmap_width/2;
/* Display a bad icon if this locale is not available */
item_bad_flag = goo_canvas_svg_new (rootitem,
@@ -221,7 +222,7 @@
NULL);
SET_ITEM_LOCATION(item_bad_flag,
x_flag_start + 5,
- y_start - gdk_pixbuf_get_width(pixmap_checked)/2);
+ y_start - pixmap_width/2);
/*
* The current locale is the one found in the config file
@@ -242,11 +243,12 @@
// Fullscreen / Window
y_start += Y_GAP;
- item = goo_canvas_image_new (rootitem,
- (properties->fullscreen ? pixmap_checked : pixmap_unchecked),
- (double) x_start,
- (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2,
- NULL);
+ item = goo_canvas_svg_new (rootitem,
+ gc_skin_rsvg_get(),
+ "svg-id", (properties->fullscreen ? pixmap_checked : pixmap_unchecked),
+ "autocrop", TRUE,
+ NULL);
+ SET_ITEM_LOCATION(item, x_start, y_start - pixmap_width/2);
g_signal_connect(item, "button_press_event",
(GtkSignalFunc) item_event_ok,
@@ -267,11 +269,12 @@
// Music
y_start += Y_GAP;
- item = goo_canvas_image_new (rootitem,
- (properties->music ? pixmap_checked : pixmap_unchecked),
- (double) x_start,
- (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2,
- NULL);
+ item = goo_canvas_svg_new (rootitem,
+ gc_skin_rsvg_get(),
+ "svg-id", (properties->music ? pixmap_checked : pixmap_unchecked),
+ "autocrop", TRUE,
+ NULL);
+ SET_ITEM_LOCATION(item, x_start, y_start - pixmap_width/2);
g_signal_connect(item, "button_press_event",
(GtkSignalFunc) item_event_ok,
@@ -292,11 +295,12 @@
// Effect
y_start += Y_GAP;
- item = goo_canvas_image_new (rootitem,
- (properties->fx ? pixmap_checked : pixmap_unchecked),
- (double) x_start,
- (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2,
- NULL);
+ item = goo_canvas_svg_new (rootitem,
+ gc_skin_rsvg_get(),
+ "svg-id", (properties->fx ? pixmap_checked : pixmap_unchecked),
+ "autocrop", TRUE,
+ NULL);
+ SET_ITEM_LOCATION(item, x_start, y_start - pixmap_width/2);
g_signal_connect(item, "button_press_event",
(GtkSignalFunc) item_event_ok,
@@ -465,14 +469,6 @@
stars_group = NULL;
- if(pixmap_unchecked)
- gdk_pixbuf_unref(pixmap_unchecked);
- pixmap_unchecked = NULL;
-
- if(pixmap_checked)
- gdk_pixbuf_unref(pixmap_checked);
- pixmap_checked = NULL;
-
/* UnPause the board */
if(is_displayed)
gc_board_pause(FALSE);
@@ -516,35 +512,36 @@
display_previous_next(guint x_start, guint y_start,
gchar *eventname_previous, gchar *eventname_next)
{
- GdkPixbuf *pixmap = NULL;
GooCanvasItem *item;
+ GooCanvasBounds bounds;
- pixmap = gc_skin_pixmap_load("button_backward.png");
- item = goo_canvas_image_new (rootitem,
- pixmap,
- (double) x_start - gdk_pixbuf_get_width(pixmap) - 10,
- (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2,
- NULL);
+ item = goo_canvas_svg_new (rootitem,
+ gc_skin_rsvg_get(),
+ "svg-id", "#PREVIOUS",
+ NULL);
+ goo_canvas_item_get_bounds(item, &bounds);
+ SET_ITEM_LOCATION(item,
+ x_start - (bounds.x2 - bounds.x1) - 10,
+ y_start - pixmap_width/2);
g_signal_connect(item, "button_press_event",
(GtkSignalFunc) item_event_ok,
eventname_previous);
gc_item_focus_init(item, NULL);
- gdk_pixbuf_unref(pixmap);
- pixmap = gc_skin_pixmap_load("button_forward.png");
- item = goo_canvas_image_new (rootitem,
- pixmap,
- (double) x_start,
- (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2,
- NULL);
+ item = goo_canvas_svg_new (rootitem,
+ gc_skin_rsvg_get(),
+ "svg-id", "#NEXT",
+ NULL);
+ SET_ITEM_LOCATION(item,
+ x_start,
+ y_start - pixmap_width/2);
g_signal_connect(item, "button_press_event",
(GtkSignalFunc) item_event_ok,
eventname_next);
gc_item_focus_init(item, NULL);
- gdk_pixbuf_unref(pixmap);
}
static void
@@ -728,7 +725,7 @@
gc_fullscreen_set(properties->fullscreen);
g_object_set (item,
- "pixbuf", (properties->fullscreen ? pixmap_checked : pixmap_unchecked),
+ "svg-id", (properties->fullscreen ? pixmap_checked : pixmap_unchecked),
NULL);
gc_item_focus_init(item, NULL);
@@ -737,7 +734,7 @@
{
properties->music = (properties->music ? 0 : 1);
g_object_set (item,
- "pixbuf", (properties->music ? pixmap_checked : pixmap_unchecked),
+ "svg-id", (properties->music ? pixmap_checked : pixmap_unchecked),
NULL);
if(!properties->music)
{
@@ -753,7 +750,7 @@
{
properties->fx = (properties->fx ? 0 : 1);
g_object_set (item,
- "pixbuf", (properties->fx ? pixmap_checked : pixmap_unchecked),
+ "svg-id", (properties->fx ? pixmap_checked : pixmap_unchecked),
NULL);
gc_item_focus_init(item, NULL);
}
Modified: branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.c
==============================================================================
--- branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.c (original)
+++ branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.c Fri Jan 2 13:10:21 2009
@@ -13,13 +13,14 @@
/* Convenience properties. */
PROP_SVGHANDLE,
PROP_SVG_ID,
+ PROP_AUTOCROP,
};
static void goo_canvas_svg_finalize (GObject *object);
static void goo_canvas_svg_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec);
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
/* Use the GLib convenience macro to define the type. GooCanvasSvg is the
@@ -44,6 +45,46 @@
NULL,
G_PARAM_WRITABLE));
+ g_object_class_install_property (gobject_class, PROP_AUTOCROP,
+ g_param_spec_boolean ("autocrop",
+ "Auto Crop",
+ "Set to True to crop the image, default is False",
+ FALSE,
+ G_PARAM_WRITABLE));
+
+}
+
+/* Return a new surface with the item in src_surface being
+ * assigned to 0,0 coordinate.
+ */
+static cairo_surface_t*
+_autocrop(cairo_surface_t *src_surface,
+ double x1, double x2, double y1, double y2)
+{
+ cairo_surface_t* dst_surface =
+ cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ x2 - x1 + 1,
+ y2 - y1 + 1);
+
+ unsigned char* src_data = cairo_image_surface_get_data(src_surface);
+ unsigned char* dst_data = cairo_image_surface_get_data(dst_surface);
+
+ int src_stride = cairo_image_surface_get_stride(src_surface);
+ int dst_stride = cairo_image_surface_get_stride(dst_surface);
+
+ int x;
+ for (x = x1; x <= x2; x++)
+ {
+ int y;
+ for (y = y1; y <= y2; y++)
+ {
+ guint32 point = *(guint32*)&src_data[y*src_stride + x*4];
+ *(guint32*)&dst_data[((y-(int)y1)*dst_stride)
+ + (x*4 - (int)x1*4)] = point;
+ }
+ }
+
+ return dst_surface;
}
static void _init_surface(GooCanvasSvg *canvas_svg,
@@ -72,7 +113,6 @@
canvas_svg->cr = cairo_create (cst);
rsvg_handle_render_cairo_sub (svg_handle, canvas_svg->cr,
canvas_svg->id);
- canvas_svg->pattern = cairo_pattern_create_for_surface (cst);
/* Get the real coordinates */
canvas_svg->x1 = canvas_svg->width;
@@ -97,6 +137,21 @@
}
}
}
+
+ if(stride > 0 && canvas_svg->autocrop)
+ {
+ canvas_svg->pattern = \
+ cairo_pattern_create_for_surface ( _autocrop(cst,
+ canvas_svg->x1, canvas_svg->x2,
+ canvas_svg->y1, canvas_svg->y2) );
+ canvas_svg->x2 = canvas_svg->x2 - canvas_svg->x1;
+ canvas_svg->y2 = canvas_svg->y2 - canvas_svg->y1;
+ canvas_svg->x1 = 0;
+ canvas_svg->y1 = 0;
+ }
+ else
+ canvas_svg->pattern = cairo_pattern_create_for_surface (cst);
+
cairo_surface_destroy(cst);
}
@@ -113,6 +168,7 @@
canvas_svg->id = NULL;
canvas_svg->cr = NULL;
canvas_svg->pattern = NULL;
+ canvas_svg->autocrop = FALSE;
}
@@ -238,6 +294,8 @@
if (canvas_svg->svg_handle)
_init_surface(canvas_svg, canvas_svg->svg_handle);
break;
+ case PROP_AUTOCROP:
+ canvas_svg->autocrop = g_value_get_boolean (value);
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
Modified: branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.h
==============================================================================
--- branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.h (original)
+++ branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.h Fri Jan 2 13:10:21 2009
@@ -39,6 +39,7 @@
double y1;
double x2;
double y2;
+ guint autocrop : 1;
};
struct _GooCanvasSvgClass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]