3
* Time-stamp: <2001/10/15 01:10:21 bruno>
5
* Copyright (C) 2002 Bruno coudoin
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
#define SOUNDLISTFILE PACKAGE
30
static double subratio;
32
static TimerList type;
33
GnomeCanvasItem *item;
34
static gint timer_increment (GtkWidget *widget, gpointer data);
35
static gint subtimer_increment (GtkWidget *widget, gpointer data);
36
static GnomeCanvasGroup *boardRootItem = NULL;
37
static gint animate_id = 0;
38
static gint subanimate_id = 0;
39
static GcomprisTimerEnd gcomprisTimerEnd;
41
void gcompris_timer_display(int ax, int ay, TimerList atype, int second, GcomprisTimerEnd agcomprisTimerEnd)
44
GdkPixbuf *pixmap = NULL;
46
gdk_font = gdk_font_load (FONT_BOARD_MEDIUM);
50
boardRootItem = GNOME_CANVAS_GROUP(
51
gnome_canvas_item_new (gnome_canvas_root(gcompris_get_canvas()),
52
gnome_canvas_group_get_type (),
63
gcomprisTimerEnd = agcomprisTimerEnd;
67
case GCOMPRIS_TIMER_SAND:
68
case GCOMPRIS_TIMER_CLOCK:
69
if(type==GCOMPRIS_TIMER_SAND)
70
pixmap = gcompris_load_pixmap("gcompris/timers/sablier10.png");
72
pixmap = gcompris_load_pixmap("gcompris/timers/clock10.png");
74
item = gnome_canvas_item_new (boardRootItem,
75
gnome_canvas_pixbuf_get_type (),
80
gdk_pixbuf_unref(pixmap);
82
case GCOMPRIS_TIMER_TEXT:
83
/* Display the value for this timer */
84
item = gnome_canvas_item_new (boardRootItem,
85
gnome_canvas_text_get_type (),
86
"text", g_strdup_printf("Remaining Time = %d", timer),
90
"anchor", GTK_ANCHOR_CENTER,
91
"fill_color", "white",
94
case GCOMPRIS_TIMER_BALLOON:
95
pixmap = gcompris_load_pixmap("gcompris/misc/tuxballoon.png");
96
item = gnome_canvas_item_new (boardRootItem,
97
gnome_canvas_pixbuf_get_type (),
103
/* Calc the number of step needed to reach the sea based on user y and second */
104
ystep = (BOARDHEIGHT-y-gdk_pixbuf_get_height(pixmap))/second;
106
gdk_pixbuf_unref(pixmap);
108
pixmap = gcompris_load_pixmap("gcompris/misc/sea.png");
109
gnome_canvas_item_new (boardRootItem,
110
gnome_canvas_pixbuf_get_type (),
113
"y", (double) BOARDHEIGHT - gdk_pixbuf_get_height(pixmap),
114
"width", (double) gdk_pixbuf_get_width(pixmap),
115
"height", (double) gdk_pixbuf_get_height(pixmap),
117
gdk_pixbuf_unref(pixmap);
119
/* Perform under second animation */
121
subanimate_id = gtk_timeout_add (1000/subratio, (GtkFunction) subtimer_increment, NULL);
128
animate_id = gtk_timeout_add (1000, (GtkFunction) timer_increment, NULL);
131
void gcompris_timer_add(int second)
136
void gcompris_timer_end()
138
if(boardRootItem!=NULL)
139
gtk_object_destroy (GTK_OBJECT(boardRootItem));
140
boardRootItem = NULL;
143
gtk_timeout_remove (animate_id);
147
gtk_timeout_remove (subanimate_id);
151
static void display_time_ellapsed()
155
case GCOMPRIS_TIMER_TEXT:
156
/* Display the value for this timer */
158
gnome_canvas_item_set(item,
159
"text", _("Time Ellapsed"),
169
static gint subtimer_increment(GtkWidget *widget, gpointer data)
173
case GCOMPRIS_TIMER_BALLOON:
174
/* Display the value for this timer */
177
gnome_canvas_item_set(item,
180
// gnome_canvas_update_now(gcompris_get_canvas());
188
static gint timer_increment(GtkWidget *widget, gpointer data)
194
display_time_ellapsed();
195
if(gcomprisTimerEnd!=NULL)
197
/* Call the callback */
206
case GCOMPRIS_TIMER_SAND:
207
case GCOMPRIS_TIMER_CLOCK:
210
GdkPixbuf *pixmap = NULL;
211
gchar *filefull = NULL;
212
gchar *filename = NULL;
215
fileid = (gint)timer/ratio;
216
if(type==GCOMPRIS_TIMER_SAND)
217
filename = g_strdup_printf("gcompris/timers/sablier%d.png", fileid);
219
filename = g_strdup_printf("gcompris/timers/clock%d.png", fileid);
221
filefull = g_strdup_printf("%s/%s", PACKAGE_DATA_DIR, filename);
222
if (g_file_exists (filefull))
224
pixmap = gcompris_load_pixmap(filename);
225
gnome_canvas_item_set(item,
228
gdk_pixbuf_unref(pixmap);
234
case GCOMPRIS_TIMER_TEXT:
235
/* Display the value for this timer */
237
gnome_canvas_item_set(item,
238
"text", g_strdup_printf(_("Remaining Time = %d"), timer),
241
case GCOMPRIS_TIMER_BALLOON: