Commit 095fc445 authored by Bruno Coudoin's avatar Bruno Coudoin

Added an API entry gc_set_background_by_id to ease

	SVG integration.
	Now the menu uses the svg data from the skin.svg file.


svn path=/branches/gcomprixogoo/; revision=3660
parent 522cfc1b
2009-01-01 Bruno Coudoin,,, <bruno.coudoin@free.fr>
Added an API entry gc_set_background_by_id to ease
SVG integration.
Now the menu uses the svg data from the skin.svg file.
* boards/skins/gartoon/skin.svg:
* src/boards/menu2.c: (menu_start):
* src/gcompris/bar.c: (gc_bar_start):
* src/gcompris/gameutil.h:
* src/gcompris/gcompris.c: (_clear_svg_background),
(_clear_pixmap_background), (gc_set_background),
(gc_set_background_by_id):
* src/gcompris/gcompris.h:
* src/gcompris/skin.c: (gc_skin_rsvg_get):
* src/gcompris/skin.h:
2008-12-22 Bruno coudoin <bruno.coudoin@free.fr>
More work to use more svg
......
......@@ -825,14 +825,14 @@
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.7713475"
inkscape:cx="475.27364"
inkscape:cx="371.55904"
inkscape:cy="214.7962"
inkscape:current-layer="layer1"
id="namedview6255"
inkscape:window-width="768"
inkscape:window-height="713"
inkscape:window-x="50"
inkscape:window-y="6"
inkscape:window-height="726"
inkscape:window-x="361"
inkscape:window-y="25"
showguides="true"
inkscape:guide-bbox="true"
showgrid="false">
......@@ -898,7 +898,7 @@
</g>
<g
id="BUTTON_VERTICAL"
transform="matrix(0.8480242,0,0,1.0177439,-665.61044,-83.993068)">
transform="matrix(0.835729,0,0,1.0177439,-654.5275,-83.993068)">
<rect
transform="matrix(0,-1,1,0,0,0)"
ry="6.491662"
......@@ -940,7 +940,7 @@
</g>
<g
id="BUTTON_HORIZONTAL"
transform="translate(-116.4466,-83.539846)">
transform="matrix(1,0,0,0.857803,-116.4466,-70.99222)">
<rect
ry="14.636374"
y="89.449387"
......
......@@ -215,8 +215,9 @@ static void menu_start (GcomprisBoard *agcomprisBoard)
if(agcomprisBoard != NULL)
{
gchar *img;
RsvgHandle *svg_handle;
printf("menu2 start\n");
gcomprisBoard=agcomprisBoard;
/* set initial values for this level */
......@@ -228,10 +229,11 @@ static void menu_start (GcomprisBoard *agcomprisBoard)
menuitems = g_new(MenuItems, 1);
img = gc_skin_image_get("gcompris-menu2bg.png");
gc_set_background(goo_canvas_get_root_item(gcomprisBoard->canvas),
img);
g_free(img);
svg_handle = gc_skin_rsvg_get();
gc_set_background_by_id (goo_canvas_get_root_item(gcomprisBoard->canvas),
svg_handle,
"#BACKGROUND");
boardRootItem = \
goo_canvas_group_new (goo_canvas_get_root_item(gcomprisBoard->canvas),
......@@ -240,6 +242,18 @@ static void menu_start (GcomprisBoard *agcomprisBoard)
g_object_set_data_full(G_OBJECT (boardRootItem),
"menuitems", menuitems, g_free);
goo_canvas_svg_new (boardRootItem,
svg_handle,
"svg-id", "#BUTTON_VERTICAL",
"pointer-events", GOO_CANVAS_EVENTS_NONE,
NULL);
goo_canvas_svg_new (boardRootItem,
svg_handle,
"svg-id", "#BUTTON_HORIZONTAL",
"pointer-events", GOO_CANVAS_EVENTS_NONE,
NULL);
create_info_area(boardRootItem, menuitems);
create_panel(boardRootItem);
......
......@@ -28,18 +28,6 @@
#include "gcompris_config.h"
#include "about.h"
// Reset the item at its 0,0 coordinate and then translate
// it to x,y
#define SET_ITEM_LOCATION(item, x, y) \
{ \
GooCanvasBounds bounds; \
goo_canvas_item_set_transform(item, NULL); \
goo_canvas_item_get_bounds(item, &bounds); \
goo_canvas_item_translate(item, \
-1 * bounds.x1 + x, \
-1 * bounds.y1 + y); \
}
#define SOUNDLISTFILE PACKAGE
#define BAR_GAP 10 /* Value used to fill space above and under icons in the bar */
......@@ -176,7 +164,7 @@ void gc_bar_start (GooCanvas *theCanvas)
rootitem = goo_canvas_group_new (goo_canvas_get_root_item(theCanvas), NULL);
svg_handle = gc_skin_rsvg_load("skin.svg");
svg_handle = gc_skin_rsvg_get();
bar_item = goo_canvas_svg_new (rootitem,
svg_handle,
"svg-id", "#BAR_BG",
......@@ -185,12 +173,8 @@ void gc_bar_start (GooCanvas *theCanvas)
SET_ITEM_LOCATION(bar_item, 0, 0);
goo_canvas_item_get_bounds(bar_item, &bounds);
printf("height-BAR_GAP=%d\n", height-BAR_GAP);
zoom = (double)(height-BAR_GAP)/(bounds.y2 - bounds.y1);
printf("bar width=%f\n", (bounds.x2 - bounds.x1));
printf("bar height=%f\n", (bounds.y2 - bounds.y1));
buttony = (height-(bounds.y2 - bounds.y1)*zoom)/2 - 20;
printf("zoom=%f buttony=%d\n", zoom, buttony);
/*
* The Order in which buttons are created represents
......@@ -249,7 +233,7 @@ void gc_bar_start (GooCanvas *theCanvas)
svg_handle,
GC_BAR_LEVEL,
"#LEVEL_UP");
goo_canvas_item_translate(item, 45, 0);
goo_canvas_item_translate(item, 50, 0);
g_object_set (item,
"visibility", GOO_CANVAS_ITEM_VISIBLE,
NULL);
......@@ -260,7 +244,7 @@ void gc_bar_start (GooCanvas *theCanvas)
goo_canvas_text_new (rootitem_level,
"",
bounds.x1 - 10,
(bounds.y2 - bounds.y1) / 2,
(bounds.y2 - bounds.y1) / 2 + 4,
-1,
GTK_ANCHOR_CENTER,
"font", gc_skin_font_board_title_bold,
......
......@@ -39,6 +39,21 @@
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#endif
// This is especially usefull for SVG images that are loaded
// by their Ids and that are not at the 0,0 coordinate in the
// source file.
// This reset the item at its 0,0 coordinate and then translate
// it to x,y
#define SET_ITEM_LOCATION(item, x, y) \
{ \
GooCanvasBounds bounds; \
goo_canvas_item_set_transform(item, NULL); \
goo_canvas_item_get_bounds(item, &bounds); \
goo_canvas_item_translate(item, \
-1 * bounds.x1 + x, \
-1 * bounds.y1 + y); \
}
gchar *g_utf8_strndup(gchar*,gint);
gchar *reactivate_newline(char *str);
......
......@@ -44,8 +44,6 @@
#include "gcompris-nsbundle.h"
#endif
#include <librsvg/rsvg.h>
/* get the default database name */
#define DEFAULT_DATABASE "gcompris_sqlite.db"
......@@ -525,6 +523,22 @@ _set_pixmap_background(GooCanvasItem *parent, gchar *file)
}
void _clear_svg_background()
{
if(backgroundsvgimg)
goo_canvas_item_remove(backgroundsvgimg);
backgroundsvgimg = NULL;
}
void _clear_pixmap_background()
{
if(backgroundimg)
goo_canvas_item_remove(backgroundimg);
backgroundimg = NULL;
}
void
gc_set_background(GooCanvasItem *parent, gchar *file)
{
......@@ -542,14 +556,34 @@ gc_set_background(GooCanvasItem *parent, gchar *file)
}
else
{
if(backgroundsvgimg)
goo_canvas_item_remove(backgroundsvgimg);
backgroundsvgimg = NULL;
_clear_svg_background();
_set_pixmap_background(parent, file);
}
}
void
gc_set_background_by_id(GooCanvasItem *parent, RsvgHandle *rsvg_handle,
gchar *id)
{
g_assert(parent);
g_assert(rsvg_handle);
_clear_pixmap_background();
if(backgroundsvgimg)
g_object_set(backgroundsvgimg,
"svg-handle", rsvg_handle,
"svg-id", id,
NULL);
else
backgroundsvgimg = goo_canvas_svg_new (parent,
rsvg_handle,
"svg-id", id,
NULL);
goo_canvas_item_lower(backgroundsvgimg, NULL);
}
/* Redraw the black background
*/
static gboolean
......
......@@ -62,6 +62,8 @@
#include "dmalloc.h"
#endif
#include <librsvg/rsvg.h>
#define BOARDWIDTH 800
#define BOARDHEIGHT 520
#define BARHEIGHT 40
......@@ -84,6 +86,9 @@ void gc_board_end(void);
void gc_bar_start (GooCanvas *theCanvas);
void gc_set_background(GooCanvasItem *parent, gchar *file);
void gc_set_background_by_id(GooCanvasItem *parent,
RsvgHandle *rsvg_handle,
gchar *id);
void gc_bar_set_level (GcomprisBoard *gcomprisBoard);
void gc_bar_set_repeat_icon (GdkPixbuf *pixmap);
......
......@@ -101,6 +101,26 @@ gc_skin_pixmap_load(char *pixmapfile)
return (result_pixbuf);
}
/*
* Return the rsvg_handle of skin.svg from the current
* skin directory.
* If not found, try in the default skin directory
* If not found abort gcompris
*/
RsvgHandle *
gc_skin_rsvg_get()
{
/* Return value is cached, we don't support skin change on the fly */
static RsvgHandle *result_svg = NULL;
if (result_svg)
return result_svg;
result_svg = gc_skin_rsvg_load("skin.svg");
return (result_svg);
}
/*
* Load a pixmap from the current skin directory
* If not found, try in the default skin directory
......
......@@ -46,6 +46,7 @@ extern gchar* gc_skin_font_board_huge_bold;
gchar *gc_skin_image_get(gchar *imagename);
GdkPixbuf *gc_skin_pixmap_load(char *pixmapfile);
RsvgHandle *gc_skin_rsvg_get();
RsvgHandle *gc_skin_rsvg_load(char *pixmapfile);
void gc_skin_load (gchar* skin);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment