gcompris r3611 - in branches/gcomprixogoo/src: goocanvas/src watercycle-activity
- From: bcoudoin svn gnome org
- To: svn-commits-list gnome org
- Subject: gcompris r3611 - in branches/gcomprixogoo/src: goocanvas/src watercycle-activity
- Date: Tue, 11 Nov 2008 00:47:15 +0000 (UTC)
Author: bcoudoin
Date: Tue Nov 11 00:47:15 2008
New Revision: 3611
URL: http://svn.gnome.org/viewvc/gcompris?rev=3611&view=rev
Log:
implemented a bounding calculation to make the item connect and focus
works also on svg items by ID
Modified:
branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.c
branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.h
branches/gcomprixogoo/src/watercycle-activity/watercycle.py
Modified: branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.c
==============================================================================
--- branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.c (original)
+++ branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.c Tue Nov 11 00:47:15 2008
@@ -67,8 +67,33 @@
canvas_svg->width,
canvas_svg->height);
canvas_svg->cr = cairo_create (cst);
- rsvg_handle_render_cairo (svg_handle, canvas_svg->cr);
+ 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;
+ canvas_svg->x2 = 0;
+ canvas_svg->y1 = canvas_svg->height;
+ canvas_svg->y2 = 0;
+ unsigned char* data = cairo_image_surface_get_data(cst);
+ int x;
+ int stride = cairo_image_surface_get_stride(cst);
+ for (x=0; x<stride/4; x++)
+ {
+ int y;
+ for (y=0; y<canvas_svg->height; y++)
+ {
+ guint32 point = *(guint32*)&data[y*stride + x*4];
+ if (point != 0)
+ {
+ ((x > canvas_svg->x2) ? canvas_svg->x2 = x : x);
+ ((x < canvas_svg->x1) ? canvas_svg->x1 = x : x);
+ ((y > canvas_svg->y2) ? canvas_svg->y2 = y : y);
+ ((y < canvas_svg->y1) ? canvas_svg->y1 = y : y);
+ }
+ }
+ }
cairo_surface_destroy(cst);
}
@@ -78,6 +103,10 @@
{
canvas_svg->width = 0.0;
canvas_svg->height = 0.0;
+ canvas_svg->x1 = 0.0;
+ canvas_svg->y1 = 0.0;
+ canvas_svg->x2 = 0.0;
+ canvas_svg->y2 = 0.0;
canvas_svg->id = NULL;
canvas_svg->cr = NULL;
canvas_svg->pattern = NULL;
@@ -100,16 +129,16 @@
item = g_object_new (GOO_TYPE_CANVAS_SVG, NULL);
- canvas_svg = (GooCanvasSvg*) item;
- if(svg_handle)
- _init_surface(canvas_svg, svg_handle);
-
va_start (var_args, svg_handle);
first_property = va_arg (var_args, char*);
if (first_property)
g_object_set_valist ((GObject*) item, first_property, var_args);
va_end (var_args);
+ canvas_svg = (GooCanvasSvg*) item;
+ if(svg_handle)
+ _init_surface(canvas_svg, svg_handle);
+
if (parent)
{
goo_canvas_item_add_child (parent, item, -1);
@@ -131,10 +160,10 @@
GooCanvasSvg *canvas_svg = (GooCanvasSvg*) simple;
/* Compute the new bounds. */
- simple->bounds.x1 = 0;
- simple->bounds.y1 = 0;
- simple->bounds.x2 = canvas_svg->width;
- simple->bounds.y2 = canvas_svg->height;
+ simple->bounds.x1 = canvas_svg->x1;
+ simple->bounds.y1 = canvas_svg->y1;
+ simple->bounds.x2 = canvas_svg->x2;
+ simple->bounds.y2 = canvas_svg->y2;
}
@@ -239,7 +268,8 @@
{
GooCanvasSvg *canvas_svg = (GooCanvasSvg*) simple;
- if ((x > canvas_svg->width) || (y > canvas_svg->height))
+ if (x < canvas_svg->x1 || (x > canvas_svg->y2)
+ || y < canvas_svg->y1 || (y > canvas_svg->y2))
return FALSE;
/* Don't do hit-detection for now. */
Modified: branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.h
==============================================================================
--- branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.h (original)
+++ branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.h Tue Nov 11 00:47:15 2008
@@ -34,6 +34,10 @@
gchar *id;
cairo_t *cr;
cairo_pattern_t *pattern;
+ double x1;
+ double y1;
+ double x2;
+ double y2;
};
struct _GooCanvasSvgClass
Modified: branches/gcomprixogoo/src/watercycle-activity/watercycle.py
==============================================================================
--- branches/gcomprixogoo/src/watercycle-activity/watercycle.py (original)
+++ branches/gcomprixogoo/src/watercycle-activity/watercycle.py Tue Nov 11 00:47:15 2008
@@ -65,48 +65,42 @@
svghandle = gcompris.utils.load_svg("watercycle/watercycle.svgz")
goocanvas.Svg(
parent = self.rootitem,
- svg_handle = svghandle
+ svg_handle = svghandle,
+ svg_id = "#BACKGROUND"
)
# Take care, the items are stacked on each other in the order you add them.
# If you need, you can reorder them later with raise and lower functions.
# The River
- self.riveritem = \
- goocanvas.Image(
- parent = self.rootitem,
- pixbuf = gcompris.utils.load_pixmap("watercycle/riverempty.png"),
- x=150.0,
- y=50.0
+ self.riveritem = goocanvas.Svg(
+ parent = self.rootitem,
+ svg_handle = svghandle,
+ svg_id = "#RIVERWATER"
)
+ self.riveritem.props.visibility = goocanvas.ITEM_INVISIBLE
self.riverfull = 0
# The bad water
- self.badwateritem = \
- goocanvas.Image(
- parent = self.rootitem,
- pixbuf = gcompris.utils.load_pixmap("watercycle/badwater_off.png"),
- x=360.0,
- y=292.0
+ self.badwateritem = goocanvas.Svg(
+ parent = self.rootitem,
+ svg_handle = svghandle,
+ svg_id = "#DIRTYWATER"
)
# The clean water
- self.cleanwateritem = \
- goocanvas.Image(
- parent = self.rootitem,
- pixbuf = gcompris.utils.load_pixmap("watercycle/cleanwater_off.png"),
- x=470.0,
- y=130.0
+ self.cleanwateritem = goocanvas.Svg(
+ parent = self.rootitem,
+ svg_handle = svghandle,
+ svg_id = "#CLEANWATER"
)
self.cleanwaterstatus = 0
# The Sun
- self.sunitem = \
- goocanvas.Image(
- parent = self.rootitem,
- pixbuf = gcompris.utils.load_pixmap("watercycle/sun.png"),
- x=10.0,
- y=70.0
+ self.sunitem = goocanvas.Svg(
+ parent = self.rootitem,
+ svg_handle = svghandle,
+ svg_id = "#SUN"
)
self.sunitem.connect("button_press_event", self.sun_item_event)
# This item is clickeable and it must be seen
@@ -114,46 +108,28 @@
self.sun_direction = -1
self.sun_on = 0
- # The sun mask object to simulate the see
-
- goocanvas.Rect(
- parent = self.rootitem,
- x=10.0,
- y=89.0,
- width=80.0,
- height=66.0,
- fill_color_rgba=0x0099FFFFL,
- line_width=0.0
- )
-
# The Snow
- self.snowitem = \
- goocanvas.Image(
- parent = self.rootitem,
- pixbuf = gcompris.utils.load_pixmap("watercycle/snow.png"),
- x=180.0,
- y=3.0
+ self.snowitem = goocanvas.Svg(
+ parent = self.rootitem,
+ svg_handle = svghandle,
+ svg_id = "#SNOW"
)
self.snowitem.props.visibility = goocanvas.ITEM_INVISIBLE
# The rain
- self.rainitem = \
- goocanvas.Image(
- parent = self.rootitem,
- pixbuf = gcompris.utils.load_pixmap("watercycle/rain.png"),
- x=40.0,
- y=70.0
+ self.rainitem = goocanvas.Svg(
+ parent = self.rootitem,
+ svg_handle = svghandle,
+ svg_id = "#RAIN"
)
self.rainitem.props.visibility = goocanvas.ITEM_INVISIBLE
self.rain_on = 0
# The cloud
- self.clouditem = \
- goocanvas.Image(
- parent = self.rootitem,
- pixbuf = gcompris.utils.load_pixmap("watercycle/cloud.png"),
- x=10.0,
- y=10.0
+ self.clouditem = goocanvas.Svg(
+ parent = self.rootitem,
+ svg_handle = svghandle,
+ svg_id = "#CLOUD"
)
self.clouditem.props.visibility = goocanvas.ITEM_INVISIBLE
self.clouditem.connect("button_press_event", self.cloud_item_event)
@@ -162,22 +138,18 @@
self.cloud_on = 0
# The vapor
- self.vaporitem = \
- goocanvas.Image(
- parent = self.rootitem,
- pixbuf = gcompris.utils.load_pixmap("watercycle/vapor.png"),
- x=35.0,
- y=150.0
+ self.vaporitem = goocanvas.Svg(
+ parent = self.rootitem,
+ svg_handle = svghandle,
+ svg_id = "#VAPOR"
)
self.vaporitem.props.visibility = goocanvas.ITEM_INVISIBLE
# The Waterpump
- self.waterpumpitem = \
- goocanvas.Image(
- parent = self.rootitem,
- pixbuf = gcompris.utils.load_pixmap("watercycle/waterpump.png"),
- x=165.0,
- y=120.0
+ self.waterpumpitem = goocanvas.Svg(
+ parent = self.rootitem,
+ svg_handle = svghandle,
+ svg_id = "#PUMPSTATION"
)
self.waterpumpitem.connect("button_press_event", self.waterpump_item_event)
# This item is clickeable and it must be seen
@@ -185,21 +157,17 @@
self.waterpump_on = 0
# The pump water
- self.pumpwateritem = \
- goocanvas.Image(
- parent = self.rootitem,
- pixbuf = gcompris.utils.load_pixmap("watercycle/pumpwater_off.png"),
- x=270.0,
- y=133.0
+ self.pumpwateritem = goocanvas.Svg(
+ parent = self.rootitem,
+ svg_handle = svghandle,
+ svg_id = "#CLEANWATER"
)
# The WaterCleaning
- self.watercleaningitem = \
- goocanvas.Image(
- parent = self.rootitem,
- pixbuf = gcompris.utils.load_pixmap("watercycle/watercleaning.png"),
- x=520.0,
- y=380.0
+ self.watercleaningitem = goocanvas.Svg(
+ parent = self.rootitem,
+ svg_handle = svghandle,
+ svg_id = "#CLEANSTATION"
)
self.watercleaningitem.connect("button_press_event", self.watercleaning_item_event)
# This item is clickeable and it must be seen
@@ -216,12 +184,10 @@
self.tuxboatcanvas.props.y = 430.0
# Tux in the shower (without water)
- self.tuxshoweritem = \
- goocanvas.Image(
- parent = self.rootitem,
- pixbuf = gcompris.utils.load_pixmap("watercycle/minitux.png"),
- x=569.0,
- y=239.0
+ self.tuxshoweritem = goocanvas.Svg(
+ parent = self.rootitem,
+ svg_handle = svghandle,
+ svg_id = "#SHOWER"
)
self.tuxshoweritem.props.visibility = goocanvas.ITEM_INVISIBLE
self.tuxisinshower = 0
@@ -289,6 +255,12 @@
self.rainitem.raise_(None)
self.clouditem.raise_(None)
+# goocanvas.Svg(
+# parent = self.rootitem,
+# svg_handle = svghandle,
+# svg_id = "#FOREGROUND"
+# )
+
# Ready GO
self.move_boat()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]