tile_group_t hand;
} player_t;
+typedef struct selection_rectangle {
+ int x, y, width, height, visible;
+} selection_rectangle_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_rectangle_t selection_rectangle;
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_rectangle_init(selection_rectangle_t *rect)
+{
+ rect->x = 0;
+ rect->y = 0;
+ rect->width = 0;
+ rect->height = 0;
+ rect->visible = 0;
+}
+
+static void selection_rectangle_draw(selection_rectangle_t *select_rect, cairo_t *cr)
+{
+ /************Fix this***************/
+ cairo_rectangle (cr, select_rect->x, select_rect->y, select_rect->width, select_rect->height);
+ cairo_set_source_rgba(cr, 0.0, 0.1, 0.2, 0.0);
+ 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_rectangle_init(&game->selection_rectangle);
board_init(&game->board);
deck_init(&game->deck);
deck_shuffle(&game->deck);
deck_draw(game, cr, event->region);
+ selection_rectangle_draw(&game->selection_rectangle, cr);
+
hand_draw(game, 0, cr, event->region);
cairo_destroy (cr);
}
if (game->current_tile == -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_rectangle.x = event->x;
+ game->selection_rectangle.y = event->y;
}
return TRUE;
}
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_rectangle_t *select;
+ select = &game->selection_rectangle;
+ select->visible = 1;
- tile = &game->deck.tiles[game->current_tile];
+ gtk_widget_queue_draw_area (widget, select->x - 1, select->y - 1, select->width + 1, select->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);
+ select->width = event->x - select->x;
+ select->height = event->y - select->y;
+
+ gtk_widget_queue_draw_area (widget, select->x - 1, select->y - 1, select->width + 1, select->height + 2);
+ }
+ 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);
/* 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;
}