tile_group_t hand;
} player_t;
+typedef struct selection_box {
+ int x1, x2, y1, y2, visible;
+} selection_box_t;
+
#define GAME_MAX_PLAYERS 4
#define GAME_WINDOW_DEFAULT_WIDTH 800
#define GAME_WINDOW_DEFAULT_HEIGHT 600
int num_players;
board_t board;
deck_t deck;
+ selection_box_t selection_box;
RsvgHandle *blanktile;
int current_tile;
int diff_x, diff_y;
int click_x, click_y;
- int release_x, release_y;
+ int release_x, release_y; /*Currently unused*/
} game_t;
+static void selection_box_init(selection_box_t *box)
+{
+ box->x1 = 0;
+ box->x2 = 0;
+ box->y1 = 0;
+ box->y2 = 0;
+ box->visible = 0;
+}
+
+static void selection_box_draw(selection_box_t *box, cairo_t *cr)
+{
+ cairo_rectangle (cr, box->x1, box->y1, box->x2 - box->x1, box->y2 - box->y1);
+ cairo_set_source_rgba(cr, 0.0, 0.1, 0.2, 0.5);
+ cairo_fill (cr);
+}
+
static void tile_init (tile_t *tile, color_t color, int number)
{
tile->color = color;
player_init(&game->players[i]);
game->num_players += 1;
}
-
+
+ selection_box_init(&game->selection_box);
board_init(&game->board);
deck_init(&game->deck);
deck_shuffle(&game->deck);
deck_draw(game, cr, event->region);
+ if (game->selection_box.visible)
+ selection_box_draw(&game->selection_box, cr);
+
hand_draw(game, 0, cr, event->region);
cairo_destroy (cr);
}
if (game->current_tile == -1)
{
+ game->selection_box.visible = 1;
+ /*These next two lines are likely to be replaced by...*/
game->click_x = event->x;
game->click_y = event->y;
+ /*...these two lines*/
+ game->selection_box.x1 = event->x;
+ game->selection_box.y1 = event->y;
}
return TRUE;
}
{
if (game->current_tile == -1)
{
+ selection_box_t *box;
+ box = &game->selection_box;
+
+ int x = MIN(box->x1, box->x2);
+ int y = MIN(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, y, width, height);
+
tile_group_t group;
group.num_tiles = 0;
static gboolean on_button_motion_event (GtkWidget *widget, GdkEventMotion *event,
game_t *game, cairo_t *cr)
{
- tile_t *tile;
+ if (game->current_tile == -1)
+ {
+ selection_box_t *box;
+ box = &game->selection_box;
+ box->visible = 1;
+
+ 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) );
+
+ box->x2 = event->x;
+ box->y2 = event->y;
- tile = &game->deck.tiles[game->current_tile];
+ 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) );
+ }
+ else
+ {
+ tile_t *tile;
+ tile = &game->deck.tiles[game->current_tile];
- /* First, invalidate the region where the tile currently is. */
- gtk_widget_queue_draw_area (widget, tile->x - 1, tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
+ /* First, invalidate the region where the tile currently is. */
+ gtk_widget_queue_draw_area (widget, tile->x - 1, tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
/* Then, move the tile */
- tile->x = event->x - game->diff_x;
- tile->y = event->y - game->diff_y;
+ tile->x = event->x - game->diff_x;
+ tile->y = event->y - game->diff_y;
/* Finally, invalidate the region where the tile is now. */
- gtk_widget_queue_draw_area (widget, tile->x - 1, tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
-
+ gtk_widget_queue_draw_area (widget, tile->x - 1, tile->y - 1, TILE_WIDTH + 1, TILE_HEIGHT + 2);
+ }
return TRUE;
}