From 388d3ca2a4b0f2d2ff5c0f06f5fd32241475c4dd Mon Sep 17 00:00:00 2001 From: Kevin Worth Date: Wed, 6 May 2009 19:04:41 -0400 Subject: [PATCH] Click-n-drag to select multiple tiles The main purpose here is to facilitate testing of the functions tile_group_is_set and tile_group_is_run. Eventually it will be improved for general UI purposes. Grouped tiles are printed to terminal. XXX There is a bug here XXX Selections must: (a)start above the highest tile and catch all the top left corners of each tile OR (b)start below the lowest tile and catch all the bottom left corners of each tile --- kub.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/kub.c b/kub.c index 2b659b0..69be1d2 100644 --- a/kub.c +++ b/kub.c @@ -93,6 +93,8 @@ typedef struct game { int current_tile; int diff_x, diff_y; + int click_x, click_y; + int release_x, release_y; } game_t; static void tile_init (tile_t *tile, color_t color, int number) @@ -445,7 +447,10 @@ static void game_init(game_t *game) if (error) FATAL_ERROR (error->message); - game->current_tile = game->deck.num_tiles - 1; + /*This line appears to be useless, has been replaced by line below*/ + //game->current_tile = game->deck.num_tiles - 1; + game->current_tile = -1; + game->diff_x = game->diff_y = 0; } @@ -487,12 +492,39 @@ static gboolean on_button_press_event (GtkWidget *widget, GdkEventButton *event, game->diff_y = event->y - tile_y; } } - + if (game->current_tile == -1) + { + game->click_x = event->x; + game->click_y = event->y; + } return TRUE; } static gboolean on_button_release_event (GtkWidget *widget, GdkEventButton *event, game_t *game) { + if (game->current_tile == -1) + { + tile_group_t group; + group.num_tiles = 0; + + int i, tile_x, tile_y; + 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 && game->click_x <= tile_x && + event->y >= tile_y && game->click_y <= tile_y) || + (event->x >= tile_x && game->click_x <= tile_x && + event->y <= (tile_y + TILE_HEIGHT) && game->click_y >= tile_y) ) + { + group.tiles[group.num_tiles] = game->deck.tiles[i]; + group.num_tiles++; + } + } + for (i = 0; i < group.num_tiles; i++) + tile_print(group.tiles[i]); + } + game->current_tile = -1; printf ("You released button %d\n", event->button); -- 2.43.0