[gcompris] maze: add fast_mode toggle button to board



commit 348a387ad19527fde2fda57661a22195c9ed1939
Author: Peter Albrecht <pa-dev gmx de>
Date:   Thu Sep 27 14:15:36 2012 +0200

    maze: add fast_mode toggle button to board
    
    This commit adds a button to the upper left corner of the screen.
    Clicking this button enables/disables fast_mode.
    
    It has the same functionality as clicking on tux.

 src/maze-activity/maze.c                           |   62 +++++++++++++++-----
 .../resources/maze/fast-mode-button.svgz           |  Bin 0 -> 4075 bytes
 2 files changed, 48 insertions(+), 14 deletions(-)
---
diff --git a/src/maze-activity/maze.c b/src/maze-activity/maze.c
index 476e58e..e1829e7 100644
--- a/src/maze-activity/maze.c
+++ b/src/maze-activity/maze.c
@@ -73,14 +73,15 @@ static void game_won(void);
 static void repeat(void);
 
 /* ================================================================ */
-static GooCanvasItem *boardRootItem = NULL;
-static GooCanvasItem *mazegroup     = NULL;
-static GooCanvasItem *tuxgroup      = NULL;
-static GooCanvasItem *wallgroup     = NULL;
+static GooCanvasItem *boardRootItem 	= NULL;
+static GooCanvasItem *mazegroup     	= NULL;
+static GooCanvasItem *tuxgroup      	= NULL;
+static GooCanvasItem *wallgroup     	= NULL;
 
-static GooCanvasItem *warning_item   = NULL;
-static GooCanvasItem *tuxitem        = NULL;
-static GooCanvasItem *tuxshoes       = NULL;
+static GooCanvasItem *warning_item   	= NULL;
+static GooCanvasItem *tuxitem        	= NULL;
+static GooCanvasItem *tuxshoes       	= NULL;
+static GooCanvasItem *fast_mode_button	= NULL;
 
 static GooCanvasItem *maze_create_item(GooCanvasItem *parent);
 static void maze_destroy_all_items(void);
@@ -106,7 +107,12 @@ static gboolean tux_event (GooCanvasItem *item,
 			   GooCanvasItem *target,
 			   GdkEventButton *event,
 			   gpointer data);
+static gboolean on_fast_mode_button_press (GooCanvasItem *item,
+			   GooCanvasItem *target,
+			   GdkEventButton *event,
+			   gpointer data);
 static void update_tux(gint direction);
+static void toggle_fast_mode();
 
 /*---------- 3D stuff ------------*/
 static GooCanvasItem *threedgroup = NULL;
@@ -310,6 +316,18 @@ static void maze_next_level() {
 		        "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL);
   g_object_unref (svg_handle);
 
+  /* Load fast-mode switch button */
+  svg_handle = gc_rsvg_load("maze/fast-mode-button.svgz");
+  fast_mode_button = goo_canvas_svg_new (boardRootItem, svg_handle,
+		        NULL);
+  g_object_unref (svg_handle);
+  goo_canvas_item_scale(fast_mode_button, 0.2, 0.2);
+  goo_canvas_item_translate(fast_mode_button, 100, 100);
+  g_signal_connect(fast_mode_button,
+		   "button_press_event",
+		   (GCallback) on_fast_mode_button_press, NULL);
+  gc_item_focus_init(fast_mode_button, NULL);
+
   /* Draw the target */
   pixmap = gc_pixmap_load("maze/door.png");
   if(pixmap)
@@ -1151,15 +1169,31 @@ tux_event (GooCanvasItem *item,
 	   GdkEventButton *event,
 	   gpointer data)
 {
-  // toggle
-  if(run_fast) {
-	  set_run_fast(FALSE);
-  } else {
-	  set_run_fast(TRUE);
-  }
-  return FALSE;
+	toggle_fast_mode();
+	return TRUE;
 }
 
+static gboolean
+on_fast_mode_button_press (GooCanvasItem *item,
+	   GooCanvasItem *target,
+	   GdkEventButton *event,
+	   gpointer data)
+{
+	toggle_fast_mode();
+	return TRUE;
+}
+
+static void
+toggle_fast_mode ()
+{
+	if(run_fast) {
+		  set_run_fast(FALSE);
+	} else {
+		  set_run_fast(TRUE);
+	}
+}
+
+
 /*---------- 3D stuff below --------------*/
 
 /* bit magic: rotation = bit rotation */
diff --git a/src/maze-activity/resources/maze/fast-mode-button.svgz b/src/maze-activity/resources/maze/fast-mode-button.svgz
new file mode 100644
index 0000000..bf02e5d
Binary files /dev/null and b/src/maze-activity/resources/maze/fast-mode-button.svgz differ



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