A group of tiles can now be selected by overlapping the
selection_box with any corner of each tile(top-left,
bottom-right, etc)
Bug fix: previously, the corners of the selection_box were
not being updated if the mouse was clicked without being
dragged. Now, with each click, x2 is set equal to x1, and
y2 to y1. Then, as before, they are updated as the mouse
is dragged.
game->click_y = event->y;
/*...these two lines*/
game->selection_box.x1 = event->x;
game->click_y = event->y;
/*...these two lines*/
game->selection_box.x1 = event->x;
+ game->selection_box.x2 = event->x;
game->selection_box.y1 = event->y;
game->selection_box.y1 = event->y;
+ game->selection_box.y2 = event->y;
selection_box_t *box;
box = &game->selection_box;
selection_box_t *box;
box = &game->selection_box;
- int x = MIN(box->x1, box->x2);
- int y = MIN(box->y1, box->y2);
+ 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;
int width = abs(box->x2 - box->x1);
int height = abs(box->y2 - box->y1);
box->visible = 0;
- gtk_widget_queue_draw_area (widget, x, y, width, height);
+ 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;
+ int i, tile_x, tile_y, tile_x2, tile_y2;
for (i = 0; i < game->deck.num_tiles; i++)
{
tile_x = game->deck.tiles[i].x;
tile_y = game->deck.tiles[i].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) )
+ 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 of tile selected*/
+ (tile_x2 >= x_min && tile_x2 <= x_max &&
+ tile_y >= y_min && tile_y <= y_max) )
{
group.tiles[group.num_tiles] = game->deck.tiles[i];
group.num_tiles++;
{
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]);
}
for (i = 0; i < group.num_tiles; i++)
tile_print(group.tiles[i]);
}
game->select_mode = 1;
return TRUE;
game->select_mode = 1;
return TRUE;