[Commit] grrobot/src grr_board_view.c,1.1.1.1,1.2 grrobot.c,1.1.1.1,1.2

Carl Worth commit at keithp.com
Fri Jun 13 18:37:33 PDT 2003


Committed by: cworth

Update of /local/src/CVS/grrobot/src
In directory home.keithp.com:/tmp/cvs-serv12490/src

Modified Files:
	grr_board_view.c grrobot.c 
Log Message:
Fix message scrolling. Add NOTICE TURN support. Flush notices.

Index: grr_board_view.c
===================================================================
RCS file: /local/src/CVS/grrobot/src/grr_board_view.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- grr_board_view.c	13 Jun 2003 10:38:50 -0000	1.1.1.1
+++ grr_board_view.c	14 Jun 2003 00:37:30 -0000	1.2
@@ -594,6 +594,12 @@
     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 @@
 
   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 @@
 
   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;
 }

Index: grrobot.c
===================================================================
RCS file: /local/src/CVS/grrobot/src/grrobot.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- grrobot.c	13 Jun 2003 10:38:48 -0000	1.1.1.1
+++ grrobot.c	14 Jun 2003 00:37:30 -0000	1.2
@@ -44,15 +44,19 @@
     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 @@
 
     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, &notice_s);
@@ -112,6 +124,18 @@
 	    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 @@
 	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 @@
 	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 @@
 }
 
 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 @@
 
     gtk_widget_show (window);
     
+    grr_game_read_notices (game);
+
     gtk_main ();
     
     return 0;




More information about the Commit mailing list