From 5edb5be4a163427c619a98e68255eb8331f39e3b Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Sat, 14 Jun 2003 00:37:30 +0000 Subject: [PATCH] Fix message scrolling. Add NOTICE TURN support. Flush notices. --- src/grr_board_view.c | 26 ++++++++++++---- src/grrobot.c | 71 +++++++++++++++++++++++++++++++++----------- 2 files changed, 73 insertions(+), 24 deletions(-) diff --git a/src/grr_board_view.c b/src/grr_board_view.c index 6e71a0f..eaa4db4 100644 --- a/src/grr_board_view.c +++ b/src/grr_board_view.c @@ -594,6 +594,12 @@ grr_board_view_expose (GtkWidget *widget, return FALSE; } +/* +static void +grr_board_view_pointer_coords_to_grid (grr_board_view_t *view, + int pointer_x, int pointer_y, + int *grid_x, af +*/ static gint grr_board_view_button_press (GtkWidget *widget, GdkEventButton *event) @@ -606,8 +612,11 @@ grr_board_view_button_press (GtkWidget *widget, view = GRR_BOARD_VIEW (widget); - /* XXX: grr_board_view_pointer_coords_to_grid (view, event->x, event->y, &i, &j); +/* + grr_board_view_pointer_coords_to_grid (view, event->x, event->y, &i, &j); +*/ +/* if (!view->button && rr_board_has_robot (view->board, i, j)) { @@ -634,18 +643,23 @@ grr_board_view_button_release (GtkWidget *widget, view = GRR_BOARD_VIEW (widget); - if (view->button == event->button) - { + if (view->button == event->button) { +/* gtk_grab_remove (widget); +*/ view->button = 0; - /* XXX: grr_board_view_pointer_coords_to_grid (view, event->x, event->y, &i, &j); */ +/* + grr_board_view_pointer_coords_to_grid (view, event->x, event->y, &i, &j); +*/ /* XXX: Need to compute direction based on (i, j) and old (i, j) */ - /*XXX: rr_client_move (view->client, view->robot, direction); */ +/* + rr_client_move (view->client, view->robot, direction); +*/ - } + } return FALSE; } diff --git a/src/grrobot.c b/src/grrobot.c index a71a319..332cca5 100644 --- a/src/grrobot.c +++ b/src/grrobot.c @@ -44,15 +44,19 @@ typedef struct grr_game { GtkTextBuffer *message_buffer; GtkWidget *message_view; GtkWidget *command_entry; + GtkTextIter message_iter; } grr_game_t; static int -do_gui (grr_game_t *game); +grr_game_start_gui (grr_game_t *game); -void -game_callback (gpointer data, - gint fd, - GdkInputCondition condition); +static void +grr_game_read_callback (gpointer data, + gint fd, + GdkInputCondition condition); + +static void +grr_game_read_notices (grr_game_t *game); int main (int argc, char **argv) @@ -83,26 +87,34 @@ main (int argc, char **argv) gdk_input_add (rr_client_fd (game.client), GDK_INPUT_READ, - game_callback, + grr_game_read_callback, &game); rr_client_show (game.client, &diagram); rr_board_parse (game.board, diagram); free (diagram); - return do_gui (&game); + return grr_game_start_gui (&game); } -void -game_callback (gpointer data, - gint fd, - GdkInputCondition condition) +static void +grr_game_read_callback (gpointer data, + gint fd, + GdkInputCondition condition) { grr_game_t *game = data; + + grr_game_read_notices (game); +} + +static void +grr_game_read_notices (grr_game_t *game) +{ rr_board_t *board = game->board; rr_status_t status; char **notice_s; rr_notice_t *notice; + int i; while (rr_client_notice_pending (game->client)) { status = rr_client_next_notice (game->client, ¬ice_s); @@ -112,6 +124,18 @@ game_callback (gpointer data, gtk_exit (1); return; } + for (i=0; notice_s[i]; i++) { + gtk_text_buffer_insert_at_cursor (game->message_buffer, notice_s[i], -1); + gtk_text_buffer_insert_at_cursor (game->message_buffer, " ", -1); + } + gtk_text_buffer_insert_at_cursor (game->message_buffer, "\n", -1); + gtk_text_buffer_get_iter_at_offset (game->message_buffer, + &game->message_iter, + -1); + gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (game->message_view), + &game->message_iter, + 0.0, FALSE, 0.0, 0.0); + notice = rr_client_parse_notice (game->client, notice_s); switch (notice->type) { case RR_NOTICE_USER: @@ -120,7 +144,6 @@ game_callback (gpointer data, case RR_NOTICE_DISPOSE: case RR_NOTICE_MESSAGE: case RR_NOTICE_GAMESTATE: - case RR_NOTICE_TURN: case RR_NOTICE_JOIN: case RR_NOTICE_WATCH: case RR_NOTICE_PART: @@ -135,29 +158,39 @@ game_callback (gpointer data, case RR_NOTICE_RESET: case RR_NOTICE_SCORE: case RR_NOTICE_ACTIVATE: - /* Ignore these requests */ + /* XXX: Need to actually handle many of these. */ + fprintf (stderr, "Warning: Ignoring notice of type %d\n", notice->type); break; case RR_NOTICE_POSITION: rr_board_position (board, notice->u.position.robot, notice->u.position.x, notice->u.position.y); gtk_widget_queue_draw (GTK_WIDGET (game->window)); break; + case RR_NOTICE_TURN: + rr_board_set_goal_target (board, notice->u.target); + gtk_widget_queue_draw (GTK_WIDGET (game->window)); + break; } free (notice); } } -void +static void command_callback (GtkWidget *widget, grr_game_t *game) { const gchar *entry_text; char **response; - entry_text = gtk_entry_get_text (GTK_ENTRY (widget)); - rr_client_request (game->client, entry_text, &response); - gtk_entry_set_text (GTK_ENTRY (widget), ""); + entry_text = gtk_entry_get_text (GTK_ENTRY (game->command_entry)); gtk_text_buffer_insert_at_cursor (game->message_buffer, entry_text, -1); + gtk_text_buffer_insert_at_cursor (game->message_buffer, "\n", -1); + + rr_client_request (game->client, entry_text, &response); + + gtk_entry_set_text (GTK_ENTRY (game->command_entry), ""); + + grr_game_read_notices (game); /* XXX: Huh? Why is this triggering valgrind? free (response); @@ -166,7 +199,7 @@ command_callback (GtkWidget *widget, } static int -do_gui (grr_game_t *game) +grr_game_start_gui (grr_game_t *game) { GtkWidget *board_frame; GtkWidget *vpaned; @@ -232,6 +265,8 @@ do_gui (grr_game_t *game) gtk_widget_show (window); + grr_game_read_notices (game); + gtk_main (); return 0; -- 2.43.0