X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=dvonn.c;h=896edc36ab49a346e98af873ea16f7bcae518d1e;hb=ad4d9127c5dd419f84da2329c60b3f785c068e66;hp=1442923c0acf27243f9ce42fc6de2766abb453bf;hpb=2c8c385d00f60fad7a4b74b0b66516fbce62c50f;p=dvonn diff --git a/dvonn.c b/dvonn.c index 1442923..896edc3 100644 --- a/dvonn.c +++ b/dvonn.c @@ -55,6 +55,9 @@ struct _dvonn_game { int selected_y; PangoFontDescription *font; + + dvonn_bool_t dual_window_mode; + GtkWidget *windows[2]; }; static gboolean @@ -72,6 +75,8 @@ on_delete_event_quit (GtkWidget *widget, /* Something like buff */ #define BACKGROUND_COLOR 0.89, 0.70, 0.40 +#define RED_RING_COLOR 0.8, 0.2, 0.2 + /* Relative to a unit square. */ #define RING_OUTER_RADIUS 0.4 #define RING_INNER_RADIUS 0.2 @@ -155,6 +160,26 @@ on_button_press_event (GtkWidget *widget, int x, y; char *error; + /* Ignore events from the non-player. (Obviously when we add more + * interaction abilities, we will want to allow those even for the + * non-player---things like quit, etc.). */ + if (game->dual_window_mode && + widget->parent != game->windows[game->board.player]) + { + return TRUE; + } + + /* Ignore double and triple clicks. */ + if (event->type >= GDK_2BUTTON_PRESS) + return TRUE; + + /* Right-click means pass, (yes, it would be better to add some + * actual UI elements... */ + if (event->button == 3) { + dvonn_board_pass (&game->board); + return TRUE; + } + x = event->x; y = event->y; layout_device_to_board (layout, &x, &y); @@ -183,12 +208,14 @@ on_button_press_event (GtkWidget *widget, } if (! game->has_selected) { - if (game->board.cells[x][y].type == game->board.player) { - game->has_selected = TRUE; - game->selected_x = x; - game->selected_y = y; - dvonn_game_update_windows (game); - } + if (game->board.cells[x][y].type == game->board.player && + ! dvonn_board_cell_surrounded (&game->board, x, y)) + { + game->has_selected = TRUE; + game->selected_x = x; + game->selected_y = y; + dvonn_game_update_windows (game); + } return TRUE; } @@ -350,6 +377,14 @@ on_expose_event_draw (GtkWidget *widget, cairo_translate(cr, x + (y - DVONN_BOARD_Y_SIZE/2) / 2.0, M_SQRT1_2 * y); + if (cell.contains_red && cell.type != DVONN_CELL_RED) { + cairo_new_sub_path (cr); + cairo_arc (cr, 0.5, 0.5, + (RING_INNER_RADIUS + RING_OUTER_RADIUS)/2.0, + 0, 2 * M_PI); + cairo_set_source_rgb (cr, RED_RING_COLOR); + cairo_fill (cr); + } ring_path (cr); switch (cell.type) { case DVONN_CELL_WHITE: @@ -359,7 +394,7 @@ on_expose_event_draw (GtkWidget *widget, cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */ break; case DVONN_CELL_RED: - cairo_set_source_rgb (cr, 0.8, 0.2, 0.2); /* red */ + cairo_set_source_rgb (cr, RED_RING_COLOR); break; case DVONN_CELL_EMPTY: default: @@ -375,10 +410,10 @@ on_expose_event_draw (GtkWidget *widget, } cairo_fill (cr); - if (game->board.cells[x][y].height) { + if (game->board.cells[x][y].height > 1) { PangoLayout *height; cairo_move_to (cr, - 0.5 - 0.8 * RING_INNER_RADIUS * cos (M_PI_4), + 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", game->board.cells[x][y].height); @@ -405,6 +440,10 @@ dvonn_game_init (dvonn_game_t *game) dvonn_board_init (&game->board); game->font = NULL; + + game->dual_window_mode = 0; + game->windows[0] = NULL; + game->windows[1] = NULL; } static void @@ -417,7 +456,7 @@ view_init (view_t *view, dvonn_game_t *game, GtkWidget *window) view->layout.height = 0; } -static void +static GtkWidget* dvonn_game_create_view (dvonn_game_t *game) { view_t *view; @@ -460,20 +499,50 @@ dvonn_game_create_view (dvonn_game_t *game) G_CALLBACK (on_button_press_event), view); gtk_widget_show_all (window); + + return window; } int main (int argc, char *argv[]) { + GtkWidget *window0, *window1; + GdkDisplay *display; + GdkScreen *screen; dvonn_game_t game; dvonn_game_init (&game); gtk_init (&argc, &argv); - /* Create two views of the game (one for each player) */ - dvonn_game_create_view (&game); - dvonn_game_create_view (&game); + /* Create a view for player 1. */ + window0 = dvonn_game_create_view (&game); + + /* Ugly little hack to get Xauthority data from keithp. Obviously + * won't work for any other user. + * + setenv ("XAUTHORITY", "/home/keithp/.Xauthority", 1); + */ + + /* Also ugly that localhost:10.0 is hard-coded, but this will work + * for many situations--both for when keithp attaches to my + * machine, and for when I connect to anyone's machine and then + * connect back, (assuming I haven't made other X forwardings + * first). + * + * Clearly we'll want some actual UI to select the right thing + * here. + */ + display = gdk_display_open ("localhost:10.0"); + if (display) { + screen = gdk_display_get_default_screen (display); + window1 = dvonn_game_create_view (&game); + gtk_window_set_screen (GTK_WINDOW (window1), screen); + + game.dual_window_mode = 1; + game.windows[0] = window0; + game.windows[1] = window1; + } gtk_main ();