+ if (game->select_mode)
+ {
+ game->select_mode = 0;
+ selection_box_t *box;
+ box = &game->selection_box;
+
+ int x_min = MIN(box->x1, box->x2);
+ int x_max = MAX(box->x1, box->x2);
+ int y_min = MIN(box->y1, box->y2);
+ int y_max = MAX(box->y1, box->y2);
+ int width = abs(box->x2 - box->x1);
+ int height = abs(box->y2 - box->y1);
+
+ box->visible = 0;
+ gtk_widget_queue_draw_area (widget, x_min, y_min, width, height);
+
+ tile_group_t group;
+ group.num_tiles = 0;
+
+ int i, tile_x, tile_y, tile_x2, tile_y2;
+ int tiles_to_remove[game->deck.num_tiles];
+ for (i = 0; i < game->deck.num_tiles; i++)
+ {
+ tile_x = game->deck.tiles[i].x;
+ tile_y = game->deck.tiles[i].y;
+ tile_x2 = tile_x + TILE_WIDTH;
+ tile_y2 = tile_y + TILE_HEIGHT;
+ if (/*If top-left corner*/
+ (tile_x >= x_min && tile_x <= x_max &&
+ tile_y >= y_min && tile_y <= y_max) ||
+ /*or bottom-right corner*/
+ (tile_x2 >= x_min && tile_x2 <= x_max &&
+ tile_y2 >= y_min && tile_y2 <= y_max) ||
+ /*or bottom-left corner*/
+ (tile_x >= x_min && tile_x <= x_max &&
+ tile_y2 >= y_min && tile_y2 <= y_max) ||
+ /*or top-right corner*/
+ (tile_x2 >= x_min && tile_x2 <= x_max &&
+ tile_y >= y_min && tile_y <= y_max) ||
+ /*or left edge*/
+ (y_min >= tile_y && y_min <= tile_y2 &&
+ x_min <= tile_x && x_max >= tile_x) ||
+ /*or top edge*/
+ (x_min >= tile_x && x_min <= tile_x2 &&
+ y_min <= tile_y && y_max >= tile_y) ||
+ /*or right edge*/
+ (y_min >= tile_y && y_min <= tile_y2 &&
+ x_min >= tile_x && x_min <= tile_x2) ||
+ /*or bottom edge of tile selected*/
+ (x_min >= tile_x && x_min <= tile_x2 &&
+ y_min >= tile_y && y_min <= tile_y) )
+ {
+ tiles_to_remove[group.num_tiles] = i;
+
+ group.tiles[group.num_tiles] = game->deck.tiles[i];
+ group.num_tiles++;
+ }
+ }
+ printf("is run %d\n", tile_group_is_run_one(&group) );
+ printf("is set %d\n", tile_group_is_set(&group) );
+
+ qsort (tiles_to_remove, group.num_tiles, sizeof (int), int_compare);
+
+ for (i = 0; i < group.num_tiles; i++)
+ {
+ tile_print(group.tiles[i]);
+ gtk_widget_queue_draw_area (widget, group.tiles[i].x - 1,
+ group.tiles[i].y - 1, TILE_WIDTH + 1,
+ TILE_HEIGHT + 2);
+
+ group.tiles[i].x = x_min + (i * (TILE_WIDTH));
+ group.tiles[i].y = y_min;
+
+ gtk_widget_queue_draw_area (widget, group.tiles[i].x - 1,
+ group.tiles[i].y - 1, TILE_WIDTH + 1,
+ TILE_HEIGHT + 2);
+
+ //Remove tile from deck
+ if (tiles_to_remove[i] != game->deck.num_tiles - 1)
+ game->deck.tiles[tiles_to_remove[i]] = game->deck.tiles[game->deck.num_tiles-1];
+ game->deck.num_tiles--;
+ }
+
+ if (group.num_tiles > 0)
+ {
+ game->board.groups[game->board.num_groups] = group;
+ game->board.num_groups++;
+ }
+ board_print(game);
+ printf("\nBut is the board valid?\t\t%s\n", board_valid(&game->board) ? "yes" : "no");
+ }
+ game->select_mode = 1;
+
+ return TRUE;
+}
+
+static gboolean on_button_motion_event (GtkWidget *widget, GdkEventMotion *event,
+ game_t *game, cairo_t *cr)
+{
+ if (game->select_mode)
+ {
+ selection_box_t *box;
+ box = &game->selection_box;
+ box->visible = 1;
+
+ int x_min = MIN(box->x1, box->x2);
+ int x_max = MAX(box->x1, box->x2);
+ int y_min = MIN(box->y1, box->y2);
+ int y_max = MAX(box->y1, box->y2);
+ int width = abs(box->x2 - box->x1);
+ int height = abs(box->y2 - box->y1);
+
+ gtk_widget_queue_draw_area ( widget, x_min, y_min, width, height );
+
+ box->x2 = event->x;
+ box->y2 = event->y;
+
+ gtk_widget_queue_draw_area ( widget, MIN(box->x1, box->x2), MIN(box->y1, box->y2), abs(box->x2 - box->x1), abs(box->y2 - box->y1) );
+
+ int i, tile_x, tile_y, tile_x2, tile_y2;
+ tile_t *curr_tile;
+ for (i = 0; i < game->deck.num_tiles; i++)
+ {
+ curr_tile = &game->deck.tiles[i];
+
+ tile_x = game->deck.tiles[i].x;
+ tile_y = game->deck.tiles[i].y;
+ tile_x2 = tile_x + TILE_WIDTH;
+ tile_y2 = tile_y + TILE_HEIGHT;
+ if (/*If top-left corner*/
+ (tile_x >= x_min && tile_x <= x_max &&
+ tile_y >= y_min && tile_y <= y_max) ||
+ /*or bottom-right corner*/
+ (tile_x2 >= x_min && tile_x2 <= x_max &&
+ tile_y2 >= y_min && tile_y2 <= y_max) ||
+ /*or bottom-left corner*/
+ (tile_x >= x_min && tile_x <= x_max &&
+ tile_y2 >= y_min && tile_y2 <= y_max) ||
+ /*or top-right corner*/
+ (tile_x2 >= x_min && tile_x2 <= x_max &&
+ tile_y >= y_min && tile_y <= y_max) ||
+ /*or left edge*/
+ (y_min >= tile_y && y_min <= tile_y2 &&
+ x_min <= tile_x && x_max >= tile_x) ||
+ /*or top edge*/
+ (x_min >= tile_x && x_min <= tile_x2 &&
+ y_min <= tile_y && y_max >= tile_y) ||
+ /*or right edge*/
+ (y_min >= tile_y && y_min <= tile_y2 &&
+ x_min >= tile_x && x_min <= tile_x2) ||
+ /*or bottom edge of tile selected*/
+ (x_min >= tile_x && x_min <= tile_x2 &&
+ y_min >= tile_y && y_min <= tile_y) )
+ {
+ curr_tile->selected = 1;
+ gtk_widget_queue_draw_area (widget, curr_tile->x - 1, curr_tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
+ }