1
/* gcompris - gcompris.c
3
* Time-stamp: <2002/04/13 23:54:29 bruno>
5
* Copyright (C) 2000,2001 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.
25
#include <popt-gnome.h>
30
GtkWidget *drawing_area;
32
GnomeCanvas *canvas_bar;
33
GnomeCanvas *canvas_bg;
35
//static gint pause_board_cb (GtkWidget *widget, gpointer data);
36
static void quit_cb (GtkWidget *widget, gpointer data);
37
static gint board_widget_key_press_callback (GtkWidget *widget,
39
gpointer client_data);
41
GcomprisProperties *properties = NULL;
42
GcomprisBoard *gcomprisBoardMenu = NULL;
44
/****************************************************************************/
47
static GnomeCanvasItem *backgroundimg = NULL;
48
static gchar *gcompris_locale = NULL;
50
/****************************************************************************/
51
/* Command line params */
53
#define P_FULLSCREEN 101
60
struct poptOption command_line[] = {
61
{"fullscreen", 'f', POPT_ARGFLAG_ONEDASH, NULL, P_FULLSCREEN,
62
N_("run gcompris in fullscreen mode.")},
63
{"window", 'w', POPT_ARGFLAG_ONEDASH, NULL, P_WINDOW,
64
N_("run gcompris in window mode.")},
65
{"sound", 's', POPT_ARGFLAG_ONEDASH, NULL, P_SOUND,
66
N_("run gcompris with sound enabled.")},
67
{"mute", 'm', POPT_ARGFLAG_ONEDASH, NULL, P_MUTE,
68
N_("run gcompris without sound.")},
69
{"cursor", 'c', POPT_ARGFLAG_ONEDASH, NULL, P_CURSOR,
70
N_("run gcompris with the default gnome cursor.")},
71
{"version", 'v', POPT_ARGFLAG_ONEDASH, NULL, P_VERSION,
72
N_("Prints the version of " PACKAGE)},
73
POPT_AUTOHELP {NULL, 0, 0, NULL, 0}
78
/****************************************************************************/
81
board_widget_key_press_callback (GtkWidget *widget,
86
switch (event->keyval)
91
// quit_cb(NULL, NULL);
95
if (get_current_board_plugin()!=NULL && get_current_board_plugin()->ok)
97
get_current_board_plugin()->ok ();
101
/* If the board needs to receive key pressed */
102
if (get_current_board_plugin()!=NULL && get_current_board_plugin()->key_press)
104
return(get_current_board_plugin()->key_press (event->keyval));
112
* Return the main canvas we run in
114
GnomeCanvas *gcompris_get_canvas()
119
GtkWidget *gcompris_get_window()
125
GnomeCanvasItem *gcompris_set_background(GnomeCanvasGroup *parent, gchar *file)
127
GdkPixbuf *background_pixmap = NULL;
129
background_pixmap = gcompris_load_pixmap (file);
132
gtk_object_destroy (GTK_OBJECT(backgroundimg));
134
backgroundimg=gnome_canvas_item_new (parent,
135
gnome_canvas_pixbuf_get_type (),
136
"pixbuf", background_pixmap,
139
"width", (double) BOARDWIDTH,
140
"height", (double) BOARDHEIGHT,
142
gnome_canvas_item_lower_to_bottom(backgroundimg);
144
gdk_pixbuf_unref(background_pixmap);
146
return (backgroundimg);
149
static void init_background()
151
double xratio, yratio;
154
yratio=gdk_screen_height()/(float)(BOARDHEIGHT+BARHEIGHT);
155
xratio=gdk_screen_width()/(float)BOARDWIDTH;
156
printf("The gdk_screen_width()=%f gdk_screen_height()=%f\n",
157
(double)gdk_screen_width(), (double)gdk_screen_height());
158
printf("The xratio=%f yratio=%f\n", xratio, yratio);
160
yratio=xratio=MIN(xratio, yratio);
162
/* The canvas does not look pretty when resized above 1 ratio. Avoid that */
163
xratio=MIN(1.0, xratio);
165
printf("Calculated x ratio xratio=%f\n", xratio);
167
/* Background area if ratio above 1 */
168
if(xratio>=1.0 && properties->fullscreen)
170
/* First, Remove the gnome crash dialog because it locks the user when in full screen */
171
signal(SIGSEGV, SIG_DFL);
173
gnome_canvas_set_scroll_region (canvas_bg,
176
gdk_screen_height());
178
gtk_widget_set_usize (GTK_WIDGET(canvas_bg), gdk_screen_width(), gdk_screen_height());
180
/* Create a black box for the background */
181
gnome_canvas_item_new (gnome_canvas_root(canvas_bg),
182
gnome_canvas_rect_get_type (),
185
"x2", (double) gdk_screen_width(),
186
"y2", (double) gdk_screen_height(),
187
"fill_color", "black",
191
/* Create a vertical box in which I put first the play board area, then the button bar */
192
vbox = gtk_vbox_new (FALSE, 0);
194
if(xratio<1.0 || properties->fullscreen==FALSE)
195
gnome_app_set_contents (GNOME_APP (window), GTK_WIDGET(vbox));
197
gtk_widget_show (GTK_WIDGET(vbox));
198
gtk_widget_show (GTK_WIDGET(canvas));
199
gtk_widget_show (GTK_WIDGET(canvas_bar));
201
gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET(canvas), TRUE, TRUE, 0);
202
gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET(canvas_bar), TRUE, TRUE, 0);
204
if(xratio>=1.0 && properties->fullscreen)
206
gnome_canvas_item_new (gnome_canvas_root(canvas_bg),
207
gnome_canvas_widget_get_type (),
209
"x", (double) (gdk_screen_width()-BOARDWIDTH)/2,
210
"y", (double) (gdk_screen_height()-BOARDHEIGHT-BARHEIGHT)/2,
215
/* Create the drawing area */
216
gnome_canvas_set_pixels_per_unit (canvas, xratio);
218
gnome_canvas_set_scroll_region (canvas,
223
gtk_widget_set_usize (GTK_WIDGET(canvas), BOARDWIDTH*xratio, BOARDHEIGHT*xratio);
225
/* Create the spot for the bar */
226
gnome_canvas_set_pixels_per_unit (canvas_bar, xratio);
227
gnome_canvas_set_scroll_region (canvas_bar,
231
gtk_widget_set_usize (GTK_WIDGET(canvas_bar), BOARDWIDTH*xratio, BARHEIGHT*xratio);
235
void gcompris_set_cursor(guint gdk_cursor_type)
239
// Little hack to force gcompris to use the default gnome cursor
240
if(gdk_cursor_type==GCOMPRIS_DEFAULT_CURSOR)
241
gdk_cursor_type=properties->defaultcursor;
243
// I suppose there is less than GCOMPRIS_FIRST_CUSTOM_CURSOR cursors defined in gdkcursors.h !
244
if (gdk_cursor_type < GCOMPRIS_FIRST_CUSTOM_CURSOR) {
245
cursor = gdk_cursor_new(gdk_cursor_type);
246
gdk_window_set_cursor (window->window, cursor);
247
gdk_cursor_destroy(cursor);
248
} else { // we use a custom cursor
250
// static const gchar * cursor;
251
static const gchar ** bits;
253
switch (gdk_cursor_type) {
254
case GCOMPRIS_BIG_RED_ARROW_CURSOR :
255
bits = big_red_arrow_cursor_bits;
257
case GCOMPRIS_BIRD_CURSOR :
258
bits = bird_cursor_bits;
260
case GCOMPRIS_LINE_CURSOR :
261
bits = big_red_line_cursor_bits;
263
case GCOMPRIS_RECT_CURSOR :
264
bits = big_red_rectangle_cursor_bits;
266
case GCOMPRIS_FILLRECT_CURSOR :
267
bits = big_red_filledrectangle_cursor_bits;
269
case GCOMPRIS_CIRCLE_CURSOR :
270
bits = big_red_circle_cursor_bits;
272
case GCOMPRIS_FILLCIRCLE_CURSOR :
273
bits = big_red_filledcircle_cursor_bits;
275
case GCOMPRIS_FILL_CURSOR :
276
bits = big_red_fill_cursor_bits;
278
case GCOMPRIS_DEL_CURSOR :
279
bits = big_red_del_cursor_bits;
281
case GCOMPRIS_SELECT_CURSOR :
282
bits = big_red_select_cursor_bits;
284
default : bits = big_red_arrow_cursor_bits;
287
gdk_color_parse("rgb:FFFF/FFFF/FFFF",&fg);
288
gdk_color_parse("rgb:FFFF/3FFF/0000",&bg);
289
cursor = gdk_cursor_new_from_data(bits, 40 , 40, &fg, &bg, 0, 0);
290
gdk_window_set_cursor(window->window, cursor);
291
gdk_cursor_destroy(cursor);
295
static void setup_window ()
297
window = gnome_app_new (PACKAGE, _("GCompris I Have Understood"));
299
gtk_window_set_policy (GTK_WINDOW (window), FALSE, FALSE, TRUE);
301
gtk_widget_realize (window);
303
gtk_signal_connect (GTK_OBJECT (window), "delete_event",
304
GTK_SIGNAL_FUNC (quit_cb), NULL);
305
gtk_signal_connect (GTK_OBJECT (window), "key_press_event",
306
GTK_SIGNAL_FUNC (board_widget_key_press_callback), 0);
310
if(properties->fullscreen)
311
gnome_win_hints_set_layer (GTK_WIDGET (window), WIN_LAYER_ABOVE_DOCK);
312
// gnome_win_hints_set_state(GTK_WIDGET (window), WIN_STATE_FIXED_POSITION);
315
gcompris_set_cursor(GCOMPRIS_DEFAULT_CURSOR);
319
/* For non anti alias canvas */
320
gtk_widget_push_visual (gdk_rgb_get_visual ());
321
gtk_widget_push_colormap (gdk_rgb_get_cmap ());
323
/* For anti alias canvas */
325
gtk_widget_push_visual(gdk_rgb_get_visual());
326
gtk_widget_push_colormap(gdk_rgb_get_cmap());
329
/* For non anti alias canvas */
330
canvas = GNOME_CANVAS(gnome_canvas_new ());
331
canvas_bar = GNOME_CANVAS(gnome_canvas_new ());
332
canvas_bg = GNOME_CANVAS(gnome_canvas_new ());
334
/* For anti alias canvas */
336
canvas = GNOME_CANVAS(gnome_canvas_new_aa ());
337
canvas_bar = GNOME_CANVAS(gnome_canvas_new_aa ());
338
canvas_bg = GNOME_CANVAS(gnome_canvas_new_aa ());
342
gnome_app_set_contents (GNOME_APP (window), GTK_WIDGET(canvas_bg));
344
gtk_widget_pop_colormap ();
345
gtk_widget_pop_visual ();
348
gtk_widget_show (GTK_WIDGET(canvas_bg));
350
if(properties->fullscreen)
352
gdk_window_set_decorations (window->window, 0);
353
gdk_window_set_functions (window->window, 0);
354
gtk_widget_set_uposition (window, 0, 0);
359
/* Load and Run the menu */
360
gcomprisBoardMenu = gcompris_read_xml_file(PACKAGE_DATA_DIR "/menu.xml");
361
if(!board_check_file(gcomprisBoardMenu))
362
g_error("Cant't find the menu board or plugin execution error");
365
gcompris_bar_start(canvas_bar);
367
board_play (gcomprisBoardMenu);
372
void gcompris_end_board()
374
if (get_current_gcompris_board()->previous_board == NULL)
376
/* We are in the upper menu: leave GCompris? */
379
/* Oups, the user changed his mind : restart the menu */
380
board_play (get_current_gcompris_board());
384
/* Run the previous board */
385
board_play (get_current_gcompris_board()->previous_board);
388
static void quit_cb (GtkWidget *widget, gpointer data)
390
// FIXME: Should be implemented as a canvas dialog window
391
// if (end_board_box ())
394
/* cleanup_plugins(); */
395
gcompris_properties_save(properties);
401
static void load_properties ()
403
properties = gcompris_properties_new ();
407
* This returns the locale for which text must be displayed
410
gchar *gcompris_get_locale()
414
/* First check locale got overrided by the user */
415
if(gcompris_locale != NULL)
416
return(gcompris_locale);
418
locale = getenv("LC_ALL");
420
locale = getenv("LANG");
429
* This set the locale for which text must be displayed
432
void gcompris_set_locale(gchar *locale)
435
gcompris_locale = g_strdup(setlocale(LC_ALL, locale));
436
printf("gcompris_set_locale requested %s got %s\n", locale, gcompris_locale);
437
/* WARNING: This does not update gettext translation */
440
/*****************************************
446
main (int argc, char *argv[])
451
/* To have some real random behaviour */
454
bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
455
textdomain (PACKAGE);
459
// Set the default gcompris cursor
460
properties->defaultcursor = GCOMPRIS_DEFAULT_CURSOR;
462
// Set the user's choice locale
463
gcompris_set_locale(properties->locale);
467
gnome_init_with_popt_table (PACKAGE, VERSION, argc, argv, command_line, 0, &optCon);
469
optCon = poptGetContext (NULL, argc, argv, command_line, 0);
471
/*------------------------------------------------------------*/
472
while ((c = poptGetNextOpt (optCon)) != -1)
477
printf (_("GCompris\nVersion: %s\nLicence: GPL\n"
478
"More infos on http://ofset.sourceforge.net/gcompris\n"),
484
properties->fullscreen = TRUE;
488
properties->fullscreen = FALSE;
492
g_warning("Sound disabled");
493
properties->music = FALSE;
494
properties->fx = FALSE;
498
g_warning("Sound enabled");
499
properties->music = TRUE;
500
properties->fx = TRUE;
504
g_warning("Default gnome cursor enabled");
505
properties->defaultcursor = GDK_LEFT_PTR;
512
/* an error occurred during option processing */
513
fprintf (stderr, "%s: %s\n",
514
poptBadOption (optCon, POPT_BADOPTION_NOALIAS),
519
/*------------------------------------------------------------*/
522
gnome_sound_init(NULL);
529
gtk_widget_show (window);
531
if (properties->music)
533
gcompris_play_ogg("intro", "welcome", NULL);
536
gcompris_play_ogg("welcome", NULL);
543
/* Local Variables: */
545
/* eval:(load-library "time-stamp") */
546
/* eval:(make-local-variable 'write-file-hooks) */
547
/* eval:(add-hook 'write-file-hooks 'time-stamp) */
548
/* eval:(setq time-stamp-format '(time-stamp-yyyy/mm/dd time-stamp-hh:mm:ss user-login-name)) */