[gnome-games] quadrapassel: Update with changes to libgames-support
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] quadrapassel: Update with changes to libgames-support
- Date: Sun, 1 Jan 2012 04:14:27 +0000 (UTC)
commit 954153f957cd87e98cbff48dfe5e32f261f43b24
Author: Robert Ancell <robert ancell canonical com>
Date: Sun Jan 1 15:12:50 2012 +1100
quadrapassel: Update with changes to libgames-support
quadrapassel/data/Makefile.am | 2 +-
quadrapassel/src/Makefile.am | 8 ++++-
quadrapassel/src/main.cpp | 6 ----
quadrapassel/src/scoreframe.cpp | 12 ++++----
quadrapassel/src/sound.cpp | 61 +++++++++++++++++++++++++++++++++++++++
quadrapassel/src/sound.h | 32 ++++++++++++++++++++
quadrapassel/src/tetris.cpp | 36 ++++++++++++-----------
7 files changed, 126 insertions(+), 31 deletions(-)
---
diff --git a/quadrapassel/data/Makefile.am b/quadrapassel/data/Makefile.am
index 4970a1f..2b51050 100644
--- a/quadrapassel/data/Makefile.am
+++ b/quadrapassel/data/Makefile.am
@@ -1,6 +1,6 @@
SUBDIRS = icons
-pixmapdir = $(pkgdatadir)/quadrapassel/pixmaps
+pixmapdir = $(datadir)/quadrapassel/pixmaps
pixmap_DATA = \
quadrapassel.svg \
7blocks-tig.png \
diff --git a/quadrapassel/src/Makefile.am b/quadrapassel/src/Makefile.am
index 8af3e9b..2cdbf5e 100644
--- a/quadrapassel/src/Makefile.am
+++ b/quadrapassel/src/Makefile.am
@@ -17,20 +17,26 @@ quadrapassel_SOURCES = \
renderer.cpp \
renderer.h \
blocks-cache.cpp \
- blocks-cache.h
+ blocks-cache.h \
+ sound.cpp \
+ sound.h
quadrapassel_CPPFLAGS = \
-I$(top_srcdir) \
$(AM_CPPFLAGS)
quadrapassel_CXXFLAGS = \
+ -DDATA_DIRECTORY=\"$(datadir)/quadrapassel\" \
+ -DSOUND_DIRECTORY=\"$(pkgdatadir)/sounds\" \
$(GTK_CFLAGS) \
+ $(CANBERRA_GTK_CFLAGS) \
$(CLUTTER_GTK_CFLAGS) \
$(CLUTTER_CFLAGS) \
$(AM_CXXFLAGS)
quadrapassel_LDADD = \
$(top_builddir)/libgames-support/libgames-support.la \
+ $(CANBERRA_GTK_LIBS) \
$(CLUTTER_GTK_LIBS) \
$(CLUTTER_LIBS) \
$(GTK_LIBS) \
diff --git a/quadrapassel/src/main.cpp b/quadrapassel/src/main.cpp
index 439de36..f9f4939 100644
--- a/quadrapassel/src/main.cpp
+++ b/quadrapassel/src/main.cpp
@@ -23,7 +23,6 @@
#include <libgames-support/games-scores.h>
#include <libgames-support/games-conf.h>
-#include <libgames-support/games-runtime.h>
#include <clutter-gtk/clutter-gtk.h>
#include "tetris.h"
@@ -34,9 +33,6 @@ main(int argc, char *argv[])
gboolean retval;
GError *error = NULL;
- if (!games_runtime_init ("quadrapassel"))
- return 1;
-
#ifdef ENABLE_SETGID
setgid_io_init ();
#endif
@@ -90,7 +86,5 @@ main(int argc, char *argv[])
games_conf_shutdown ();
- games_runtime_shutdown ();
-
return 0;
}
diff --git a/quadrapassel/src/scoreframe.cpp b/quadrapassel/src/scoreframe.cpp
index 0d44463..779f6f6 100644
--- a/quadrapassel/src/scoreframe.cpp
+++ b/quadrapassel/src/scoreframe.cpp
@@ -23,10 +23,10 @@
#include <libgames-support/games-conf.h>
#include <libgames-support/games-frame.h>
-#include <libgames-support/games-sound.h>
#include "scoreframe.h"
#include "tetris.h"
+#include "sound.h"
ScoreFrame::ScoreFrame(int cmdlLevel)
: score(0), lines(0)
@@ -97,7 +97,7 @@ ScoreFrame::scoreLastLineBonus ()
{
incScore (10000*level);
// FIXME: Get it its own sound?
- games_sound_play ("quadrapassel");
+ sound_play ("quadrapassel");
}
int
@@ -111,19 +111,19 @@ ScoreFrame::scoreLines(int newlines)
return level;
case 1:
linescore = 40;
- games_sound_play ("lines1");
+ sound_play ("lines1");
break;
case 2:
linescore = 100;
- games_sound_play ("lines2");
+ sound_play ("lines2");
break;
case 3:
linescore = 300;
- games_sound_play ("lines3");
+ sound_play ("lines3");
break;
case 4:
linescore = 1200;
- games_sound_play ("lines3");
+ sound_play ("lines3");
break;
}
incScore (level*linescore);
diff --git a/quadrapassel/src/sound.cpp b/quadrapassel/src/sound.cpp
new file mode 100644
index 0000000..a80a0b5
--- /dev/null
+++ b/quadrapassel/src/sound.cpp
@@ -0,0 +1,61 @@
+/* -*- mode:C++; tab-width:8; c-basic-offset:8; indent-tabs-mode:true -*- */
+/* sound.cpp - play sounds.
+ *
+ * Copyright 2005 (c) Callum McKenzie
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For more details see the file COPYING.
+ */
+
+#include <config.h>
+
+#include <gdk/gdk.h>
+#include <canberra-gtk.h>
+
+#include "sound.h"
+
+static gboolean enabled = TRUE;
+
+void
+sound_enable (gboolean enable)
+{
+ enabled = enable;
+}
+
+gboolean
+sound_is_enabled (void)
+{
+ return enabled;
+}
+
+void
+sound_play (const gchar *name)
+{
+ gchar *filename, *path;
+
+ if (!enabled)
+ return;
+
+ filename = g_strdup_printf ("%s.ogg", name);
+ path = g_build_filename (SOUND_DIRECTORY, filename, NULL);
+ g_free (filename);
+
+ ca_context_play (ca_gtk_context_get_for_screen (gdk_screen_get_default ()),
+ 0,
+ CA_PROP_MEDIA_NAME, name,
+ CA_PROP_MEDIA_FILENAME, path, NULL);
+ g_free (path);
+}
diff --git a/quadrapassel/src/sound.h b/quadrapassel/src/sound.h
new file mode 100644
index 0000000..18c1b66
--- /dev/null
+++ b/quadrapassel/src/sound.h
@@ -0,0 +1,32 @@
+/* -*- mode:C++; tab-width:8; c-basic-offset:8; indent-tabs-mode:true -*- */
+/* sound.cpp - play sounds.
+ *
+ * Copyright 2005 (c) Callum McKenzie
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For more details see the file COPYING.
+ */
+
+#ifndef _SOUND_H_
+#define _SOUND_H_
+
+void sound_enable (gboolean enable);
+
+gboolean sound_is_enabled (void);
+
+void sound_play (const gchar *name);
+
+#endif
diff --git a/quadrapassel/src/tetris.cpp b/quadrapassel/src/tetris.cpp
index 028ba5d..c8aa14c 100644
--- a/quadrapassel/src/tetris.cpp
+++ b/quadrapassel/src/tetris.cpp
@@ -31,9 +31,6 @@
#include <libgames-support/games-controls.h>
#include <libgames-support/games-frame.h>
-#include <libgames-support/games-help.h>
-#include <libgames-support/games-runtime.h>
-#include <libgames-support/games-sound.h>
#include <libgames-support/games-stock.h>
#include <libgames-support/games-pause-action.h>
@@ -44,6 +41,7 @@
#include "preview.h"
#include "blockops.h"
#include "renderer.h"
+#include "sound.h"
int LINES = 20;
int COLUMNS = 14;
@@ -95,7 +93,6 @@ Tetris::Tetris(int cmdlLevel):
GtkWidget *menubar;
gchar *outdir;
- const char *dname;
const GtkTargetEntry targets[] = {{(gchar*) "text/uri-list", 0, URI_LIST},
{(gchar*) "property/bgimage", 0, URI_LIST},
@@ -149,8 +146,7 @@ Tetris::Tetris(int cmdlLevel):
/* Use default background image, if none found in user's home dir.*/
if (!g_file_test (bgPixmap, G_FILE_TEST_EXISTS)) {
- dname = games_runtime_get_directory (GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY);
- defaultPixmap = g_build_filename (dname, "quadrapassel.svg", NULL);
+ defaultPixmap = g_build_filename (DATA_DIRECTORY, "pixmaps", "quadrapassel.svg", NULL);
default_bgimage = true;
}
@@ -415,7 +411,7 @@ Tetris::initOptions ()
if (startingLevel > 20)
startingLevel = 20;
- games_sound_enable (confGetBoolean (KEY_OPTIONS_GROUP, KEY_SOUND, TRUE));
+ sound_enable (confGetBoolean (KEY_OPTIONS_GROUP, KEY_SOUND, TRUE));
do_preview = confGetBoolean (KEY_OPTIONS_GROUP, KEY_DO_PREVIEW, TRUE);
@@ -462,7 +458,7 @@ Tetris::setOptions ()
gtk_spin_button_set_value (GTK_SPIN_BUTTON (sentry), startingLevel);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (fill_prob_spinner), line_fill_prob);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (fill_height_spinner), line_fill_height);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sound_toggle), games_sound_is_enabled ());
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (sound_toggle), sound_is_enabled ());
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (do_preview_toggle), do_preview);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (random_block_colors_toggle), random_block_colors);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bastard_mode_toggle), bastard_mode);
@@ -662,7 +658,7 @@ Tetris::gameProperties(GtkAction *action, void *d)
t->sound_toggle =
gtk_check_button_new_with_mnemonic (_("_Enable sounds"));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (t->sound_toggle),
- games_sound_is_enabled ());
+ sound_is_enabled ());
g_signal_connect (t->sound_toggle, "clicked",
G_CALLBACK (setSound), d);
gtk_box_pack_start (GTK_BOX (fvbox), t->sound_toggle, 0, 0, 0);
@@ -850,13 +846,13 @@ void
Tetris::manageFallen()
{
field->fallingToLaying();
- games_sound_play ("land");
+ sound_play ("land");
int levelBefore = scoreFrame->getLevel();
int levelAfter = scoreFrame->scoreLines (field->checkFullLines());
if (levelAfter != levelBefore)
- games_sound_play ("quadrapassel");
+ sound_play ("quadrapassel");
if ((levelBefore != levelAfter) || fastFall)
generateTimer(levelAfter);
@@ -918,17 +914,17 @@ Tetris::keyPressHandler(GtkWidget *widget, GdkEvent *event, Tetris *t)
if (keyval == toupper(t->moveLeft)) {
res = t->field->moveBlockLeft();
if (res)
- games_sound_play ("slide");
+ sound_play ("slide");
t->onePause = false;
} else if (keyval == toupper(t->moveRight)) {
res = t->field->moveBlockRight();
if (res)
- games_sound_play ("slide");
+ sound_play ("slide");
t->onePause = false;
} else if (keyval == toupper(t->moveRotate)) {
res = t->field->rotateBlock(rotateCounterClockWise);
if (res)
- games_sound_play ("turn");
+ sound_play ("turn");
t->onePause = false;
} else if (keyval == toupper(t->moveDown)) {
if (!t->fastFall && !t->onePause) {
@@ -1222,7 +1218,7 @@ Tetris::endOfGame()
preview->previewBlock(-1, -1, FALSE);
field->hidePauseMessage();
field->showGameOverMessage();
- games_sound_play ("gameover");
+ sound_play ("gameover");
inPlay = false;
if (scoreFrame->getScore() > 0)
@@ -1274,7 +1270,7 @@ Tetris::gameNew(GtkAction *action, void *d)
t->field->hidePauseMessage();
t->field->hideGameOverMessage();
- games_sound_play ("quadrapassel");
+ sound_play ("quadrapassel");
return TRUE;
}
@@ -1283,7 +1279,13 @@ int
Tetris::gameHelp(GtkAction *action, void *data)
{
Tetris *t = (Tetris*) data;
- games_help_display(t->getWidget(), "quadrapassel", NULL);
+ GError *error = NULL;
+
+ gtk_show_uri (gtk_widget_get_screen (t->getWidget ()), "ghelp:quadrapassel", gtk_get_current_event_time (), &error);
+ if (error)
+ g_warning ("Failed to show help: %s", error->message);
+ g_clear_error (&error);
+
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]