From 18e395fdc99fda1a7bf1cf7473db38b74309914e Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 6 Mar 2009 17:29:01 -0800 Subject: [PATCH] Add simple text indicating whose turn it is to place or move. --- dvonn.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/dvonn.c b/dvonn.c index 896edc3..709d12a 100644 --- a/dvonn.c +++ b/dvonn.c @@ -55,6 +55,7 @@ struct _dvonn_game { int selected_y; PangoFontDescription *font; + PangoFontDescription *ring_font; dvonn_bool_t dual_window_mode; GtkWidget *windows[2]; @@ -77,10 +78,13 @@ on_delete_event_quit (GtkWidget *widget, #define RED_RING_COLOR 0.8, 0.2, 0.2 +#define DVONN_FONT "sans" +#define DVONN_FONT_SIZE 12 + /* Relative to a unit square. */ #define RING_OUTER_RADIUS 0.4 #define RING_INNER_RADIUS 0.2 -#define FONT_SIZE (RING_INNER_RADIUS * 1.5) +#define RING_FONT_SIZE (RING_INNER_RADIUS * 1.5) /* XXX: This really should have an interest rectangle. */ static void @@ -328,6 +332,7 @@ on_expose_event_draw (GtkWidget *widget, dvonn_game_t *game = view->game; cairo_t *cr; int x, y; + PangoLayout *to_move; if (layout->width != widget->allocation.width || layout->height != widget->allocation.height) @@ -349,12 +354,13 @@ on_expose_event_draw (GtkWidget *widget, layout->x_offset = (layout->width - x_size) / 2; layout->y_offset = (layout->height - y_size) / 2; - if (game->font == NULL) { - game->font = pango_font_description_new (); - pango_font_description_set_family (game->font, "sans"); + if (game->ring_font == NULL) { + game->ring_font = pango_font_description_new (); + pango_font_description_set_family (game->ring_font, + DVONN_FONT); } - pango_font_description_set_absolute_size (game->font, - FONT_SIZE * PANGO_SCALE); + pango_font_description_set_absolute_size (game->ring_font, + RING_FONT_SIZE * PANGO_SCALE); } cr = gdk_cairo_create (widget->window); @@ -362,6 +368,24 @@ on_expose_event_draw (GtkWidget *widget, cairo_set_source_rgb (cr, BACKGROUND_COLOR); cairo_paint (cr); + if (game->font == NULL) { + game->font = pango_font_description_new (); + pango_font_description_set_family (game->font, DVONN_FONT); + pango_font_description_set_absolute_size (game->font, DVONN_FONT_SIZE * PANGO_SCALE); + } + to_move = _create_layout_printf (cr, game->font, + "%s to %s.", + game->board.player == DVONN_PLAYER_WHITE ? + "White" : "Black", + game->board.phase == DVONN_PHASE_PLACEMENT ? + "place" : "move"); + cairo_move_to (cr, 2, 2); + if (game->board.player == DVONN_PLAYER_WHITE) + cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); + else + cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); + _show_layout (cr, to_move); + cairo_translate (cr, layout->x_offset, layout->y_offset); cairo_scale (cr, layout->cell_size, layout->cell_size); @@ -415,7 +439,7 @@ on_expose_event_draw (GtkWidget *widget, cairo_move_to (cr, 0.5 - 0.7 * RING_INNER_RADIUS * cos (M_PI_4), 0.5 - 1.2 * RING_INNER_RADIUS * sin (M_PI_4)); - height = _create_layout_printf (cr, game->font, "%d", + height = _create_layout_printf (cr, game->ring_font, "%d", game->board.cells[x][y].height); _show_layout (cr, height); } @@ -440,6 +464,7 @@ dvonn_game_init (dvonn_game_t *game) dvonn_board_init (&game->board); game->font = NULL; + game->ring_font = NULL; game->dual_window_mode = 0; game->windows[0] = NULL; -- 2.43.0