printf ("There are %d tiles in the deck\n" , deck->num_tiles);
}
-static void deck_draw(game_t *game, cairo_t *cr)
+static void deck_spread(deck_t *deck)
{
int i, j;
-
- for (i = 0; i < 8; ++i)
+ for (i = 0; i < 8; i++)
{
- for (j = 0; j < 13; ++j)
+ for (j = 0; j < 13; j++)
{
- tile_draw(game, &game->deck.tiles[j + (i * 13)], cr);
+ deck->tiles[j + (i * 13)].x = j * 50;
+ deck->tiles[j + (i * 13)].y = i * 60;
}
}
+}
+
+static void deck_draw(game_t *game, cairo_t *cr)
+{
+ int i;
+ for (i = 0; i < game->deck.num_tiles; i++)
+ {
+ tile_draw(game, &game->deck.tiles[i], cr);
+ }
}
static void hand_print(game_t *game)
static gboolean on_button_press_event (GtkWidget *widget, GdkEventButton *event, game_t *game)
{
- tile_t *tile;
+ int i, tile_x, tile_y;
- 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);
+ for (i = 0; i < game->deck.num_tiles; i++)
+ {
+ tile_x = game->deck.tiles[i].x;
+ tile_y = game->deck.tiles[i].y;
+ if (event->x >= tile_x && event->x <= (tile_x + TILE_WIDTH) &&
+ event->y >= tile_y && event->y <= (tile_y + TILE_HEIGHT) )
- game->current_tile--;
- if (game->current_tile < 0)
- game->current_tile = game->deck.num_tiles - 1;
+ game->current_tile = i;
+ }
return TRUE;
}
return TRUE;
}
+static gboolean on_button_motion_event (GtkWidget *widget, GdkEventMotion *event,
+ game_t *game, cairo_t *cr)
+{
+ tile_t *tile;
+
+ tile = &game->deck.tiles[game->current_tile];
+
+ /* First, invalidate the region where the tile currently is. */
+ gtk_widget_queue_draw_area (widget, tile->x - 1, tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
+
+ /* 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 - 1, tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
+
+ return TRUE;
+}
+
int main(int argc, char *argv[])
{
GtkWidget *window;
game_init(&game);
deck_print(&game.deck);
+ deck_spread(&game.deck);
//deck_deal(&game, &game.deck);
- hand_print(&game);
- deck_print(&game.deck);
+ //hand_print(&game);
+ //deck_print(&game.deck);
/* Create a new window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_events (window,
GDK_EXPOSURE_MASK |
GDK_KEY_PRESS_MASK |
+ GDK_BUTTON_MOTION_MASK |
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK);
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), "motion_notify_event",
+ G_CALLBACK (on_button_motion_event), &game);
+
gtk_widget_show_all (window);
gtk_main ();