From 320ef475fdad0ee5db34de1698a01cd75b747f54 Mon Sep 17 00:00:00 2001 From: Kevin Worth Date: Sat, 18 Jul 2009 11:07:39 -0400 Subject: [PATCH] Neatly rearrange tile group after selected. In this code there are two methods of achieving this rearrangement. The first is complicated and likely overkill but it keeps the checks for run and set intact. It is currently commented out and thus the second method is being used. The second method is slicker and cleaner, using pointers instead of an excessive number of loops. But it needs to be tweaked as the group of pointers is incompatible with the current checks for run and set. --- kub.c | 49 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/kub.c b/kub.c index 91ca7fb..558a280 100644 --- a/kub.c +++ b/kub.c @@ -602,8 +602,11 @@ static gboolean on_button_release_event (GtkWidget *widget, GdkEventButton *even box->visible = 0; gtk_widget_queue_draw_area (widget, x_min, y_min, width, height); - tile_group_t group; - group.num_tiles = 0; +// tile_group_t group; +// group.num_tiles = 0; + + tile_t* group[TILE_GROUP_MAX_TILES]; + int num_tiles = 0; int i, tile_x, tile_y, tile_x2, tile_y2; for (i = 0; i < game->deck.num_tiles; i++) @@ -636,15 +639,45 @@ static gboolean on_button_release_event (GtkWidget *widget, GdkEventButton *even /*or bottom edge*/ (x_min >= tile_x && x_min <= tile_x2 && y_min >= tile_y && y_min <= tile_y) ) - { - group.tiles[group.num_tiles] = game->deck.tiles[i]; - group.num_tiles++; + { +// group.tiles[group.num_tiles] = game->deck.tiles[i]; +// group.num_tiles++; + + group[num_tiles] = &game->deck.tiles[i];; + num_tiles++; } } - printf("is run %d\n", tile_group_is_run_one(&group) ); - printf("is set %d\n", tile_group_is_set(&group) ); + //printf("is run %d\n", tile_group_is_run_one(&group) ); + //printf("is set %d\n", tile_group_is_set(&group) ); + +// int matching_y = y_min; + +// for (i = 0; i < group.num_tiles; i++) + for (i = 0; i < num_tiles; i++) + { +// tile_print(group.tiles[i]); + gtk_widget_queue_draw_area (widget, group[i]->x - 1 , group[i]->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2); + group[i]->x = x_min + (i * (TILE_WIDTH)); + group[i]->y = y_min; + gtk_widget_queue_draw_area (widget, group[i]->x - 1 , group[i]->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2); + } +/* int j; + int new_x = 0; for (i = 0; i < group.num_tiles; i++) - tile_print(group.tiles[i]); + { + for (j = 0; j < game->deck.num_tiles; j++) + { + if (group.tiles[i].x == game->deck.tiles[j].x && + group.tiles[i].y == game->deck.tiles[j].y) + { + new_x = x_min + (i * (TILE_WIDTH)); + gtk_widget_queue_draw_area (widget, game->deck.tiles[j].x - 1 , game->deck.tiles[j].y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2); + game->deck.tiles[j].x = new_x; + game->deck.tiles[j].y = matching_y; + gtk_widget_queue_draw_area (widget, new_x - 1 , matching_y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2); + } + } + }*/ } game->select_mode = 1; -- 2.43.0