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
int current_tile;
int diff_x, diff_y;
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)
} game_t;
static void tile_init (tile_t *tile, color_t color, int number)
if (error)
FATAL_ERROR (error->message);
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;
}
game->diff_x = game->diff_y = 0;
}
game->diff_y = event->y - tile_y;
}
}
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)
{
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);
game->current_tile = -1;
printf ("You released button %d\n", event->button);