Add "mute sound" option to sudoku game, on request from a user.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@5675 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Michael R Sweet 2007-02-08 16:37:03 +00:00
parent 0e76ede449
commit 3d54048d52
2 changed files with 32 additions and 8 deletions

View File

@ -2,6 +2,7 @@ CHANGES IN FLTK 1.1.8
- Documentation fixes (STR #1454, STR #1455, STR #1456, - Documentation fixes (STR #1454, STR #1455, STR #1456,
STR #1457, STR #1458, STR #1460, STR #1481, STR #1578) STR #1457, STR #1458, STR #1460, STR #1481, STR #1578)
- Added "mute sound" option to Sudoku game.
- Updated the bundled zlib to v1.2.3. - Updated the bundled zlib to v1.2.3.
- Updated the bundled libpng to v1.2.16. - Updated the bundled libpng to v1.2.16.
- "make install" now uses the install command (or the - "make install" now uses the install command (or the

View File

@ -3,7 +3,7 @@
// //
// Sudoku game using the Fast Light Tool Kit (FLTK). // Sudoku game using the Fast Light Tool Kit (FLTK).
// //
// Copyright 2005-2006 by Michael Sweet. // Copyright 2005-2007 by Michael Sweet.
// //
// This library is free software; you can redistribute it and/or // This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public // modify it under the terms of the GNU Library General Public
@ -177,6 +177,7 @@ class Sudoku : public Fl_Window {
static void diff_cb(Fl_Widget *widget, void *d); static void diff_cb(Fl_Widget *widget, void *d);
static void update_helpers_cb(Fl_Widget *, void *); static void update_helpers_cb(Fl_Widget *, void *);
static void help_cb(Fl_Widget *, void *); static void help_cb(Fl_Widget *, void *);
static void mute_cb(Fl_Widget *widget, void *);
static void new_cb(Fl_Widget *widget, void *); static void new_cb(Fl_Widget *widget, void *);
static void reset_cb(Fl_Widget *widget, void *); static void reset_cb(Fl_Widget *widget, void *);
static void restart_cb(Fl_Widget *widget, void *); static void restart_cb(Fl_Widget *widget, void *);
@ -638,14 +639,15 @@ Sudoku::Sudoku()
{ "&Check Game", FL_COMMAND | 'c', check_cb, 0, 0 }, { "&Check Game", FL_COMMAND | 'c', check_cb, 0, 0 },
{ "&Restart Game", FL_COMMAND | 'r', restart_cb, 0, 0 }, { "&Restart Game", FL_COMMAND | 'r', restart_cb, 0, 0 },
{ "&Solve Game", FL_COMMAND | 's', solve_cb, 0, FL_MENU_DIVIDER }, { "&Solve Game", FL_COMMAND | 's', solve_cb, 0, FL_MENU_DIVIDER },
{ "&Update Helpers", 0, update_helpers_cb, 0, 0 },
{ "&Mute Sound", FL_COMMAND | 'm', mute_cb, 0, FL_MENU_TOGGLE | FL_MENU_DIVIDER },
{ "&Quit", FL_COMMAND | 'q', close_cb, 0, 0 }, { "&Quit", FL_COMMAND | 'q', close_cb, 0, 0 },
{ 0 }, { 0 },
{ "&Difficulty", 0, 0, 0, FL_SUBMENU }, { "&Difficulty", 0, 0, 0, FL_SUBMENU },
{ "&Easy", 0, diff_cb, (void *)"0", FL_MENU_RADIO }, { "&Easy", 0, diff_cb, (void *)"0", FL_MENU_RADIO },
{ "&Medium", 0, diff_cb, (void *)"1", FL_MENU_RADIO }, { "&Medium", 0, diff_cb, (void *)"1", FL_MENU_RADIO },
{ "&Hard", 0, diff_cb, (void *)"2", FL_MENU_RADIO }, { "&Hard", 0, diff_cb, (void *)"2", FL_MENU_RADIO },
{ "&Impossible", 0, diff_cb, (void *)"3", FL_MENU_RADIO | FL_MENU_DIVIDER }, { "&Impossible", 0, diff_cb, (void *)"3", FL_MENU_RADIO },
{ "&Update Helpers", 0, update_helpers_cb, 0, 0 },
{ 0 }, { 0 },
{ "&Help", 0, 0, 0, FL_SUBMENU }, { "&Help", 0, 0, 0, FL_SUBMENU },
{ "&About Sudoku", FL_F + 1, help_cb, 0, 0 }, { "&About Sudoku", FL_F + 1, help_cb, 0, 0 },
@ -655,7 +657,12 @@ Sudoku::Sudoku()
// Setup sound output... // Setup sound output...
sound_ = new SudokuSound(); prefs_.get("mute_sound", i, 0);
if (i) {
// Mute sound?
sound_ = NULL;
items[6].flags |= FL_MENU_VALUE;
} else sound_ = new SudokuSound();
// Menubar... // Menubar...
prefs_.get("difficulty", difficulty_, 0); prefs_.get("difficulty", difficulty_, 0);
@ -726,7 +733,7 @@ Sudoku::Sudoku()
// Destroy the sudoku window... // Destroy the sudoku window...
Sudoku::~Sudoku() { Sudoku::~Sudoku() {
delete sound_; if (sound_) delete sound_;
} }
@ -813,7 +820,7 @@ Sudoku::check_game(bool highlight) {
cell->readonly(1); cell->readonly(1);
} }
sound_->play('A' + grid_cells_[i][8]->value() - 1); if (sound_) sound_->play('A' + grid_cells_[i][8]->value() - 1);
} }
} }
} }
@ -1031,6 +1038,22 @@ Sudoku::load_game() {
} }
// Mute/unmute sound...
void
Sudoku::mute_cb(Fl_Widget *widget, void *) {
Sudoku *s = (Sudoku *)(widget->window() ? widget->window() : widget);
if (s->sound_) {
delete s->sound_;
s->sound_ = NULL;
prefs_.set("mute_sound", 1);
} else {
s->sound_ = new SudokuSound();
prefs_.set("mute_sound", 0);
}
}
// Create a new game... // Create a new game...
void void
Sudoku::new_cb(Fl_Widget *widget, void *) { Sudoku::new_cb(Fl_Widget *widget, void *) {
@ -1216,7 +1239,7 @@ Sudoku::restart_cb(Fl_Widget *widget, void *) {
int v = cell->value(); int v = cell->value();
cell->value(0); cell->value(0);
cell->color(FL_LIGHT3); cell->color(FL_LIGHT3);
if (v) s->sound_->play('A' + v - 1); if (v && s->sound_) s->sound_->play('A' + v - 1);
} }
} }
@ -1285,7 +1308,7 @@ Sudoku::solve_game() {
cell->color(FL_GRAY); cell->color(FL_GRAY);
} }
sound_->play('A' + grid_cells_[i][8]->value() - 1); if (sound_) sound_->play('A' + grid_cells_[i][8]->value() - 1);
} }
} }