]> git.cworth.org Git - kub/commitdiff
Use mouse clicks to position tiles one by one.
authorCarl Worth <cworth@cworth.org>
Thu, 1 Mar 2007 15:09:58 +0000 (07:09 -0800)
committerCarl Worth <cworth@cworth.org>
Thu, 1 Mar 2007 15:10:25 +0000 (07:10 -0800)
kub.c

diff --git a/kub.c b/kub.c
index c15d850bc7c5c014e5b480364e4068f8c5ab3b79..afaf21106396e0c93510bbce678229fc4004eb3e 100644 (file)
--- a/kub.c
+++ b/kub.c
@@ -90,6 +90,8 @@ typedef struct game {
     board_t board;
     deck_t deck;
     RsvgHandle *blanktile;
+
+    int current_tile;
 } game_t;
 
 static void
@@ -399,6 +401,8 @@ static void game_init(game_t *game)
     game->blanktile = rsvg_handle_new_from_file ("tiles/blanktile.svg", &error);
     if (error)
        FATAL_ERROR (error->message);
+
+    game->current_tile = game->deck.num_tiles - 1;
 }
 
 static gboolean on_expose_event (GtkWidget *widget, GdkEventExpose *event, game_t *game)
@@ -423,7 +427,25 @@ static gboolean on_key_press_event (GtkWidget *widget, GdkEventKey *event, game_
 
 static gboolean on_button_press_event (GtkWidget *widget, GdkEventButton *event, game_t *game)
 {
-    printf ("You pressed button %d\n", event->button);
+    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;
 }