~philip-peitsch/gweled/play-while-animating

« back to all changes in this revision

Viewing changes to src/callbacks.c

  • Committer: Daniele Napolitano
  • Date: 2010-08-06 00:54:14 UTC
  • Revision ID: dnax88@gmail.com-20100806005414-srt4dexad795gwo3
Sound handling rewritten. Now open audio device only if sound or music are enabled. Do not segfault on audio errors. This fix bug #345304 and bug #614135.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include <gtk/gtk.h>
26
26
#include <glib/gi18n-lib.h>
27
 
#include <mikmod.h>
28
27
 
29
28
#include "main.h"
30
 
#include "music.h"
 
29
#include "sound.h"
31
30
#include "sge_core.h"
32
31
#include "board_engine.h"
33
32
#include "graphic_engine.h"
43
42
extern GtkWidget *g_drawing_area;
44
43
extern GdkPixmap *g_buffer_pixmap;
45
44
extern GtkWidget *g_menu_pause;
 
45
extern GtkWidget *g_pref_music_button;
 
46
extern GtkWidget *g_pref_sounds_button;
46
47
 
47
48
extern gint gi_gem_clicked;
48
49
extern gint gi_x_click;
55
56
extern guint board_engine_id;
56
57
extern GweledPrefs prefs;
57
58
 
58
 
SAMPLE *click_sfx;
59
 
 
60
59
static gint gi_dragging = 0;
61
60
 
62
61
static gboolean game_mode_changed = FALSE;
234
233
                        gi_gem_clicked = -1;
235
234
                        gi_dragging = -1;
236
235
 
237
 
                        if(click_sfx && prefs.sounds_on == TRUE)
238
 
                                Sample_Play(click_sfx, 0, 0);
 
236
                        if(prefs.sounds_on)
 
237
                            sound_play_sample(CLICK_EVENT);
239
238
                }
240
239
                break;
241
240
 
374
373
void
375
374
on_music_checkbutton_toggled (GtkToggleButton * togglebutton, gpointer user_data)
376
375
{
377
 
        if (gtk_toggle_button_get_active (togglebutton))
378
 
                music_play();
379
 
        else
380
 
                music_stop();
 
376
        if (gtk_toggle_button_get_active (togglebutton)) {
 
377
            prefs.music_on = TRUE;
 
378
            if(sound_get_enabled() == FALSE) {
 
379
                sound_init();
 
380
                    if(sound_get_enabled() == FALSE) {
 
381
                    gtk_widget_set_sensitive(g_pref_music_button, FALSE);
 
382
                    gtk_widget_set_sensitive(g_pref_sounds_button, FALSE);
 
383
                }
 
384
                }
 
385
                sound_music_play();
 
386
        } else {
 
387
            prefs.music_on = FALSE;
 
388
                sound_music_stop();
 
389
                if(prefs.sounds_on == FALSE)
 
390
                    sound_destroy();
 
391
    }
381
392
}
382
393
 
383
394
void
384
395
on_sounds_checkbutton_toggled (GtkToggleButton * togglebutton, gpointer user_data)
385
396
{
386
 
        if (gtk_toggle_button_get_active (togglebutton))
 
397
        if (gtk_toggle_button_get_active (togglebutton)) {
387
398
                prefs.sounds_on = TRUE;
388
 
        else
 
399
                if(sound_get_enabled() == FALSE) {
 
400
                sound_init();
 
401
                    if(sound_get_enabled() == FALSE) {
 
402
                    gtk_widget_set_sensitive(g_pref_music_button, FALSE);
 
403
                    gtk_widget_set_sensitive(g_pref_sounds_button, FALSE);
 
404
                }
 
405
                }
 
406
                sound_load_samples();
 
407
        } else {
389
408
                prefs.sounds_on = FALSE;
 
409
                sound_unload_samples();
 
410
                if(prefs.music_on == FALSE)
 
411
                    sound_destroy();
 
412
    }
390
413
}