gnome-games r8356 - trunk/aisleriot



Author: chpe
Date: Fri Dec  5 23:03:07 2008
New Revision: 8356
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8356&view=rev

Log:
Add setting to enable animations. Add UI to change the settings.

Modified:
   trunk/aisleriot/aisleriot.schemas.in
   trunk/aisleriot/board.c
   trunk/aisleriot/board.h
   trunk/aisleriot/conf.c
   trunk/aisleriot/conf.h
   trunk/aisleriot/window.c

Modified: trunk/aisleriot/aisleriot.schemas.in
==============================================================================
--- trunk/aisleriot/aisleriot.schemas.in	(original)
+++ trunk/aisleriot/aisleriot.schemas.in	Fri Dec  5 23:03:07 2008
@@ -61,6 +61,19 @@
 
 
     <schema>
+      <key>/schemas/apps/aisleriot/animations</key>
+      <applyto>/apps/aisleriot/animations</applyto>
+      <owner>aisleriot</owner>
+      <type>bool</type>
+      <default>false</default>
+      <locale name="C">
+        <short>Animations</short>
+        <long>Whether or not to animate card moves.</long>
+      </locale>
+    </schema>
+
+
+    <schema>
       <key>/schemas/apps/aisleriot/game_file</key>
       <applyto>/apps/aisleriot/game_file</applyto>
       <owner>aisleriot</owner>

Modified: trunk/aisleriot/board.c
==============================================================================
--- trunk/aisleriot/board.c	(original)
+++ trunk/aisleriot/board.c	Fri Dec  5 23:03:07 2008
@@ -208,6 +208,9 @@
   guint scalable_cards : 1;
 
   guint force_geometry_update : 1;
+
+  guint animation_mode : 1;    /* user setting */
+  guint animations_enabled: 1; /* gtk setting  */
 };
 
 typedef struct _RemovedCard RemovedCard;
@@ -848,6 +851,9 @@
   Slot *slot;
   GArray *animations = g_array_new (FALSE, FALSE, sizeof (AisleriotAnimStart));
 
+  if (!priv->animation_mode || !priv->animations_enabled)
+    return;
+
   slots = aisleriot_game_get_slots (priv->game);
 
   /* Find any cards that have been removed from the top of the
@@ -1449,6 +1455,7 @@
                                  AisleriotBoard *board)
 {
   AisleriotBoardPrivate *priv = board->priv;
+  gboolean animations_enabled;
 #ifndef HAVE_HILDON
   gboolean touchscreen_mode;
 #endif /* !HAVE_HILDON */
@@ -1456,11 +1463,14 @@
    /* Set up the double-click detection. */
   g_object_get (settings,
                 "gtk-double-click-time", &priv->double_click_time,
+                "gtk-enable-animations", &animations_enabled,
 #ifndef HAVE_HILDON 
                 "gtk-touchscreen-mode", &touchscreen_mode,
 #endif /* !HAVE_HILDON */
                 NULL);
 
+  priv->animations_enabled = animations_enabled;
+
 #ifndef HAVE_HILDON
   priv->touchscreen_mode = touchscreen_mode != FALSE;
 #endif /* !HAVE_HILDON */
@@ -2585,12 +2595,15 @@
   aisleriot_board_settings_update (settings, NULL, board);
   g_signal_connect (settings, "notify::gtk-double-click-time",
                     G_CALLBACK (aisleriot_board_settings_update), board);
+  g_signal_connect (settings, "notify::gtk-enable-animations",
+                    G_CALLBACK (aisleriot_board_settings_update), board);
 #ifndef HAVE_HILDON 
   g_signal_connect (settings, "notify::gtk-touchscreen-mode",
                     G_CALLBACK (aisleriot_board_settings_update), board);
 #endif /* !HAVE_HILDON */
 
 #if GTK_CHECK_VERSION (2, 10, 0)
+  /* FIXMEchpe: this can be replaced by a simple style-set handler! */
   aisleriot_board_screen_font_options_changed (screen, NULL, board);
   g_signal_connect (screen, "notify::font-options",
                     G_CALLBACK (aisleriot_board_screen_font_options_changed), board);
@@ -3127,6 +3140,7 @@
 
   priv->click_to_move = FALSE;
   priv->show_selection = FALSE;
+  priv->animation_mode = FALSE;
 
   priv->show_card_id = -1;
 
@@ -3552,6 +3566,21 @@
 }
 
 void
+aisleriot_board_set_animation_mode (AisleriotBoard *board,
+                                    gboolean enabled)
+{
+  AisleriotBoardPrivate *priv = board->priv;
+
+  enabled = enabled != FALSE;
+  if (priv->animation_mode == enabled)
+    return;
+
+  priv->animation_mode = enabled;
+
+  /* FIXME: stop in-progress animations? */
+}
+
+void
 aisleriot_board_abort_move (AisleriotBoard *board)
 {
   clear_state (board);

Modified: trunk/aisleriot/board.h
==============================================================================
--- trunk/aisleriot/board.h	(original)
+++ trunk/aisleriot/board.h	Fri Dec  5 23:03:07 2008
@@ -69,6 +69,9 @@
 void aisleriot_board_set_click_to_move (AisleriotBoard * board,
                                         gboolean click_to_move);
 
+void aisleriot_board_set_animation_mode (AisleriotBoard *board,
+                                         gboolean enable);
+
 void aisleriot_board_abort_move (AisleriotBoard * board);
 
 void aisleriot_board_set_pixbuf_drawing (AisleriotBoard * board,

Modified: trunk/aisleriot/conf.c
==============================================================================
--- trunk/aisleriot/conf.c	(original)
+++ trunk/aisleriot/conf.c	Fri Dec  5 23:03:07 2008
@@ -37,10 +37,11 @@
   "show_toolbar\0"
   "click_to_move\0"
   "sound\0"
-  "show_statusbar";
+  "show_statusbar\0"
+  "animations";
 
 static const guint8 key_name_offsets[] = {
-  0, 11, 21, 39, 52, 66, 72
+  0, 11, 21, 39, 52, 66, 72, 87
 };
 
 static const char statistics_key[] = "/apps/aisleriot/statistics";
@@ -54,10 +55,11 @@
   "ShowToolbar\0"
   "ClickToMove\0"
   "Sound\0"
-  "ShowStatusbar";
+  "ShowStatusbar\0"
+  "Animations";
 
 static const guint8 key_name_offsets[] = {
-  0, 6, 16, 23, 35, 47, 53
+  0, 6, 16, 23, 35, 47, 53, 67
 };
 
 #endif /* HAVE_GNOME */
@@ -175,6 +177,8 @@
     /* Set defaults */
     games_conf_set_boolean (NULL, aisleriot_conf_get_key (CONF_SHOW_TOOLBAR), TRUE);
     games_conf_set_boolean (NULL, aisleriot_conf_get_key (CONF_SHOW_STATUSBAR), TRUE);
+    games_conf_set_boolean (NULL, aisleriot_conf_get_key (CONF_SOUND), TRUE);
+    games_conf_set_boolean (NULL, aisleriot_conf_get_key (CONF_ANIMATIONS), TRUE);
 
 #ifdef HAVE_HILDON
     games_conf_set_boolean (NULL, aisleriot_conf_get_key (CONF_CLICK_TO_MOVE), TRUE);

Modified: trunk/aisleriot/conf.h
==============================================================================
--- trunk/aisleriot/conf.h	(original)
+++ trunk/aisleriot/conf.h	Fri Dec  5 23:03:07 2008
@@ -32,6 +32,7 @@
   CONF_CLICK_TO_MOVE,
   CONF_SOUND,
   CONF_SHOW_STATUSBAR,
+  CONF_ANIMATIONS,
   CONF_STATISTICS /* must be last */
 } AisleriotConfKey;
 

Modified: trunk/aisleriot/window.c
==============================================================================
--- trunk/aisleriot/window.c	(original)
+++ trunk/aisleriot/window.c	Fri Dec  5 23:03:07 2008
@@ -1056,6 +1056,24 @@
   games_conf_set_boolean (NULL, aisleriot_conf_get_key (CONF_SOUND), sound_enabled);
 }
 
+#ifdef HAVE_CLUTTER
+
+static void
+animations_toggle_cb (GtkToggleAction *action,
+                      AisleriotWindow *window)
+{
+  AisleriotWindowPrivate *priv = window->priv;
+  gboolean enabled;
+
+  enabled = gtk_toggle_action_get_active (action);
+
+  aisleriot_board_set_animation_mode (priv->board, enabled);
+  
+  games_conf_set_boolean (NULL, aisleriot_conf_get_key (CONF_ANIMATIONS), enabled);
+}
+
+#endif /* HAVE_CLUTTER */
+
 static void
 show_hint_cb (GtkAction *action,
               AisleriotWindow *window)
@@ -1851,6 +1869,52 @@
   gtk_widget_show (dialog);
 }
 
+#ifdef HAVE_CLUTTER
+
+static void
+settings_changed_cb (GtkSettings *settings,
+                     GParamSpec *pspec,
+                     AisleriotWindow *window)
+{
+  AisleriotWindowPrivate *priv = window->priv;
+  GtkAction *action;
+  gboolean enabled;
+
+  g_object_get (settings, "gtk-enable-animations", &enabled, NULL);
+
+  action = gtk_action_group_get_action (priv->action_group, "Animations");
+  gtk_action_set_visible (action, enabled);
+}
+
+static void
+screen_changed_cb (GtkWidget *widget,
+                   GdkScreen *previous_screen,
+                   AisleriotWindow *window)
+{
+  GdkScreen *screen;
+  GtkSettings *settings;
+
+  screen = gtk_widget_get_screen (widget);
+  if (screen == previous_screen)
+    return;
+
+  if (previous_screen) {
+    g_signal_handlers_disconnect_by_func (gtk_settings_get_for_screen (previous_screen),
+                                          G_CALLBACK (settings_changed_cb),
+                                          window);
+  }
+  
+  if (screen == NULL)
+    return;
+
+  settings = gtk_widget_get_settings (widget);
+  settings_changed_cb (settings, NULL, window);
+  g_signal_connect (settings, "notify::gtk-enable-animations",
+                    G_CALLBACK (settings_changed_cb), window);
+}
+  
+#endif /* HAVE_CLUTTER */
+
 /* Class implementation */
 
 #ifdef HAVE_HILDON
@@ -2030,10 +2094,16 @@
       ACTION_TOOLTIP (N_("Pick up and drop cards by clicking")),
       G_CALLBACK (clickmove_toggle_cb),
       FALSE /* not active by default */ },
-   { "Sound", NULL, N_("_Enable sounds"), NULL,
-      ACTION_TOOLTIP (N_("Whether or not to play event sounds.")),
+   { "Sound", NULL, N_("_Sound"), NULL,
+      ACTION_TOOLTIP (N_("Whether or not to play event sounds")),
       G_CALLBACK (sound_toggle_cb),
       FALSE /* not active by default */ },
+#ifdef HAVE_CLUTTER
+   { "Animations", NULL, N_("_Animations"), NULL,
+      ACTION_TOOLTIP (N_("Whether or not to animate card moves")),
+      G_CALLBACK (animations_toggle_cb),
+      FALSE /* not active by default */ },
+#endif /* HAVE_CLUTTER */
 #ifdef ENABLE_DEBUG_UI
     { "DebugPixbufDrawing", NULL, "_Pixbuf drawing", NULL, NULL,
       G_CALLBACK (debug_pixbuf_drawing_cb),
@@ -2126,6 +2196,9 @@
           "<separator/>"
           "<menuitem action='ClickToMove'/>"
           "<menuitem action='Sound'/>"
+#ifdef HAVE_CLUTTER
+          "<menuitem action='Animations'/>"
+#endif
         "</menu>"
         "<menu action='OptionsMenu'/>"
         "<menu action='HelpMenu'>"
@@ -2380,6 +2453,15 @@
 
   set_fullscreen_actions (window, FALSE);
 
+#ifdef HAVE_CLUTTER
+  action = gtk_action_group_get_action (priv->action_group, "Animations");
+  gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
+                                games_conf_get_boolean (NULL, aisleriot_conf_get_key (CONF_ANIMATIONS), NULL));
+
+  /* Set the action visibility and listen for animation mode changes */
+  screen_changed_cb (GTK_WIDGET (window), NULL, window);
+#endif /* HAVE_CLUTTER */
+
   /* Now set up the widgets */
   main_vbox = gtk_vbox_new (FALSE, 0);
   gtk_container_add (GTK_CONTAINER (window), main_vbox);
@@ -2464,6 +2546,12 @@
   AisleriotWindow *window = AISLERIOT_WINDOW (object);
   AisleriotWindowPrivate *priv = window->priv;
 
+#ifdef HAVE_CLUTTER
+  g_signal_handlers_disconnect_by_func (gtk_widget_get_settings (GTK_WIDGET (window)),
+                                        G_CALLBACK (settings_changed_cb),
+                                        window);
+#endif /* HAVE_CLUTTER */
+
 #ifndef HAVE_HILDON
   if (priv->hint_dialog) {
     gtk_widget_destroy (priv->hint_dialog);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]