]> git.cworth.org Git - kub/blobdiff - kub.c
Fixed bug so that when no tile is clicked, no tile moves.
[kub] / kub.c
diff --git a/kub.c b/kub.c
index 9494a466914ee64632d202053419adc907d820f4..bb29e6f05cd7b72939fd0f6bfedb7de8d7f5125c 100644 (file)
--- a/kub.c
+++ b/kub.c
@@ -446,27 +446,9 @@ static gboolean on_button_press_event (GtkWidget *widget, GdkEventButton *event,
            event->y >= tile_y && event->y <= (tile_y + TILE_HEIGHT) )
 
            game->current_tile = i;
+       else 
+           game->current_tile = -1;
     }
-    /*Carl's Code*/
-    tile_t *tile;
-
-    tile = &game->deck.tiles[game->current_tile];
-
-    printf ("Placing tile #%d\n", game->current_tile);
-
-    /* First, invalidate the region where the tile currently is. */
-    gtk_widget_queue_draw_area (widget, tile->x, tile->y, TILE_WIDTH, TILE_HEIGHT);
-                       
-    /* Then, move the tile */
-    tile->x = event->x;
-    tile->y = event->y;
-
-    /* Finally, invalidate the region where the tile is now. */
-    gtk_widget_queue_draw_area (widget, tile->x, tile->y, TILE_WIDTH, TILE_HEIGHT);
-
-    game->current_tile--;
-    if (game->current_tile < 0)
-       game->current_tile = game->deck.num_tiles - 1;
 
     return TRUE;
 }
@@ -481,11 +463,21 @@ static gboolean on_button_release_event (GtkWidget *widget, GdkEventButton *even
 static gboolean on_button_motion_event (GtkWidget *widget, GdkEventMotion *event, 
                                        game_t *game, cairo_t *cr)
 {
-    game->deck.tiles[game->current_tile].x = event->x;
-    game->deck.tiles[game->current_tile].y = event->y;
-
-    tile_draw(game, &game->deck.tiles[game->current_tile], cr);    
-
+    tile_t *tile;
+    if (game->current_tile >= 0)
+    {
+       tile = &game->deck.tiles[game->current_tile];
+
+       /* First, invalidate the region where the tile currently is. */
+       gtk_widget_queue_draw_area (widget, tile->x, tile->y, TILE_WIDTH, TILE_HEIGHT);
+       
+       /* Then, move the tile */
+       tile->x = event->x;
+       tile->y = event->y;
+       
+       /* Finally, invalidate the region where the tile is now. */
+       gtk_widget_queue_draw_area (widget, tile->x, tile->y, TILE_WIDTH, TILE_HEIGHT);
+    }
     return TRUE;
 }
 
@@ -528,7 +520,7 @@ int main(int argc, char *argv[])
                      G_CALLBACK (on_button_press_event), &game);
     g_signal_connect (G_OBJECT (window), "button_release_event",
                      G_CALLBACK (on_button_release_event), &game);
-    g_signal_connect (G_OBJECT (window), "button_motion_event",
+    g_signal_connect (G_OBJECT (window), "motion_notify_event",
                      G_CALLBACK (on_button_motion_event), &game);