]> git.cworth.org Git - kub/commitdiff
Move tile movement/redraw code from on_button_press_event to on_button_motion_event
authorCarl Worth <cworth@cworth.org>
Wed, 14 Mar 2007 14:35:26 +0000 (07:35 -0700)
committerCarl Worth <cworth@cworth.org>
Wed, 14 Mar 2007 14:35:26 +0000 (07:35 -0700)
We queue redraws rather than calling draw_tile directly so that we
only draw in the idle loop, for much better performance, (and for
proper interaction with GTK+'s double buffering).

kub.c

diff --git a/kub.c b/kub.c
index e879e8b1f5f86c5bbf52e8149806669f43392093..f2fe3b22746238219b22931ef13c621e9154495d 100644 (file)
--- a/kub.c
+++ b/kub.c
@@ -447,26 +447,6 @@ static gboolean on_button_press_event (GtkWidget *widget, GdkEventButton *event,
 
            game->current_tile = i;
     }
-    /*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,10 +461,19 @@ 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_t *tile;
+
+    tile = &game->deck.tiles[game->current_tile];
 
-    tile_draw(game, &game->deck.tiles[game->current_tile], cr);    
+    /* 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;
 }