[xiph-commits] r10063 - trunk/planarity

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Sun Sep 25 05:16:36 PDT 2005


Author: xiphmont
Date: 2005-09-25 05:16:33 -0700 (Sun, 25 Sep 2005)
New Revision: 10063

Modified:
   trunk/planarity/Makefile
   trunk/planarity/dialog_level.h
   trunk/planarity/dialog_level_icons.c
   trunk/planarity/gameboard.c
   trunk/planarity/gameboard.h
   trunk/planarity/gameboard_draw_intersection.c
   trunk/planarity/gameboard_logic_button.c
   trunk/planarity/levelstate.c
   trunk/planarity/main.c
   trunk/planarity/version.h
Log:
Multiple resize-related bugfixes
Also fix a resize crash bug (check_verticies called with null arg)



Modified: trunk/planarity/Makefile
===================================================================
--- trunk/planarity/Makefile	2005-09-25 10:08:44 UTC (rev 10062)
+++ trunk/planarity/Makefile	2005-09-25 12:16:33 UTC (rev 10063)
@@ -66,11 +66,11 @@
 	$(STRIP) $(TARGET)
 
 static:    
-	$(MAKE) static-target CFLAGS="-O2 -ffast-math $(GCF) $(ADD_DEF)"
-	$(STRIP) $(TARGET)
+	$(MAKE) static-target CFLAGS="-g -Wall -ffast-math $(GCF) $(ADD_DEF) "	
+#	$(STRIP) $(TARGET)
 
 debug:
-	$(MAKE) target CFLAGS="-g -Wall -W -Wno-unused-parameter -D__NO_MATH_INLINES $(GCF) $(ADD_DEF)" -lefence
+	$(MAKE) debug-target CFLAGS="-g -Wall -W -Wno-unused-parameter -D__NO_MATH_INLINES $(GCF) $(ADD_DEF)"
 
 profile:
 	$(MAKE) target CFLAGS="-pg -g -O2 -ffast-math $(GCF) $(ADD_DEF)" LIBS="$(LIBS) -lgprof-helper "
@@ -92,6 +92,10 @@
 	./touch-version
 	$(LD) $(OBJ) $(CFLAGS) -o $(TARGET) $(LIBS) $(LDF)
 
+debug-target:  $(OBJ) 
+	./touch-version
+	$(LD) $(OBJ) $(CFLAGS) -o $(TARGET) $(LIBS) $(LDF)
+
 static-target: $(OBJ)
 	./touch-version
 	$(LD) $(OBJ) $(CFLAGS) -o $(TARGET) $(SLIBS) $(SLDF) 

Modified: trunk/planarity/dialog_level.h
===================================================================
--- trunk/planarity/dialog_level.h	2005-09-25 10:08:44 UTC (rev 10062)
+++ trunk/planarity/dialog_level.h	2005-09-25 12:16:33 UTC (rev 10063)
@@ -1,6 +1,6 @@
 #define LEVEL_BUTTON_BORDER 35
 #define LEVEL_BUTTON_Y 25
-#define LEVELBOX_WIDTH 556
+#define LEVELBOX_WIDTH 560
 #define LEVELBOX_HEIGHT 370
 
 #define ICON_DELTA 20

Modified: trunk/planarity/dialog_level_icons.c
===================================================================
--- trunk/planarity/dialog_level_icons.c	2005-09-25 10:08:44 UTC (rev 10062)
+++ trunk/planarity/dialog_level_icons.c	2005-09-25 12:16:33 UTC (rev 10063)
@@ -32,13 +32,13 @@
 static GdkRectangle text3;
 static GdkRectangle text4;
 
-static void draw_forward_arrow(onelevel *l, cairo_t *c,int fill){
+static void draw_forward_arrow(graph *g,onelevel *l, cairo_t *c,int fill){
   int w = l->w;
   int h = l->h;
   int cx = w/2;
   int cy = h/2;
   cairo_save(c);
-  cairo_translate(c,l->x+.5,l->y+.5);
+  cairo_translate(c,l->x+g->width/2+.5,l->y+g->height/2+.5);
 
   cairo_set_line_width(c,B_LINE);
 
@@ -60,13 +60,13 @@
   cairo_restore(c);
 }
 
-static void draw_backward_arrow(onelevel *l, cairo_t *c,int fill){
+static void draw_backward_arrow(graph *g,onelevel *l, cairo_t *c,int fill){
   int w = l->w;
   int h = l->h;
   int cx = w/2;
   int cy = h/2;
   cairo_save(c);
-  cairo_translate(c,l->x-.5,l->y+.5);
+  cairo_translate(c,l->x+g->width/2-.5,l->y+g->height/2+.5);
 
   cairo_set_line_width(c,B_LINE);
 
@@ -89,10 +89,14 @@
 }
 
 static void invalidate_icon(Gameboard *g,onelevel *l){
+  int w = l->w;
+  int h = l->h;
+  int cx = g->g.width/2;
+  int cy = g->g.height/2;
   GdkRectangle r;
   
-  r.x=l->x+center_x;
-  r.y=l->y;
+  r.x=l->x+cx+center_x;
+  r.y=l->y+cy;
   r.width=l->w;
   r.height=l->h;
 
@@ -109,8 +113,8 @@
 
   l->w  = ICON_WIDTH;
   l->h  = ICON_HEIGHT;  
-  l->x  =  (g->g.width/2) - (l->w*.5) + num*ICON_WIDTH*1.2;
-  l->y  = (g->g.height - LEVELBOX_HEIGHT) / 2 + 120;
+  l->x  = num*ICON_WIDTH*1.2 - (l->w*.5);
+  l->y  = 120 - (LEVELBOX_HEIGHT) / 2;
   
 }
 
@@ -201,8 +205,8 @@
 	
 	int iw = l->w;
 	int ih = l->h;
-	int ix = l->x+center_x;	
-	int iy = l->y;
+	int ix = l->x+center_x+w/2;	
+	int iy = l->y+h/2;
 	
 	if( l->alpha == 0.) continue;
 
@@ -224,9 +228,9 @@
 	  }
 
 	  if(i==1)
-	    draw_backward_arrow(l,c,i==level_lit);
+	    draw_backward_arrow(&g->g,l,c,i==level_lit);
 	  if(i==3)
-	    draw_forward_arrow(l,c,i==level_lit);
+	    draw_forward_arrow(&g->g,l,c,i==level_lit);
 	}
       }
     }
@@ -345,9 +349,14 @@
   return 1;
 }
 
-static int find_icon(int x, int y){
+static int find_icon(graph *g, int x, int y){
   int i;
-  
+  int w= g->width;
+  int h= g->height;
+
+  x-=w/2;
+  y-=h/2;
+
   for(i=1;i<4;i++){
     onelevel *l=level_icons+i;
     if(l->num>=0){
@@ -370,7 +379,7 @@
 
 void level_mouse_motion(Gameboard *g, int x, int y){
 
-  int icon = find_icon(x,y);
+  int icon = find_icon(&g->g,x,y);
 
   if(icon != level_lit){
     invalidate_icon(g, level_icons+level_lit);

Modified: trunk/planarity/gameboard.c
===================================================================
--- trunk/planarity/gameboard.c	2005-09-25 10:08:44 UTC (rev 10062)
+++ trunk/planarity/gameboard.c	2005-09-25 12:16:33 UTC (rev 10063)
@@ -113,8 +113,8 @@
   cache_curtain(g);
 }
 
-static void gameboard_size_allocate (GtkWidget     *widget,
-				     GtkAllocation *allocation){
+void gameboard_size_allocate (GtkWidget     *widget,
+			      GtkAllocation *allocation){
   Gameboard *g = GAMEBOARD (widget);
   widget->allocation = *allocation;
 
@@ -122,6 +122,9 @@
     int oldw=g->g.width;
     int oldh=g->g.height;
 
+    if(oldw == allocation->width &&
+       oldh == allocation->height) return;
+
     g->g.width = allocation->width;
     g->g.height = allocation->height;
 
@@ -171,21 +174,36 @@
 
     cache_curtain(g);
 
-    // recenter all the verticies; doesn't require recomputation
     {
       vertex *v=g->g.verticies;
+      edge *e=g->g.edges;
       int xd=(widget->allocation.width-oldw)*.5;
       int yd=(widget->allocation.height-oldh)*.5;
 
+      // recenter all the verticies; doesn't require recomputation
       while(v){
 	v->x+=xd;
 	v->y+=yd;
 	v=v->next;
       }
+   
+      // recenter associated intersections as well; they all have
+      // cached location (used only for drawing)
+      while(e){
+	intersection *i = e->i.next;
+	while(i){
+	  if(i->paired > i){
+	    i->x+=xd;
+	    i->y+=yd;    
+	  }
+	  i=i->next;
+	}
+	e=e->next;
+      }
     }
 
     // verify all verticies are onscreen
-    check_verticies();
+    check_verticies(&g->g);
 
     draw_buttonbar_box(g);
     update_score(g);

Modified: trunk/planarity/gameboard.h
===================================================================
--- trunk/planarity/gameboard.h	2005-09-25 10:08:44 UTC (rev 10062)
+++ trunk/planarity/gameboard.h	2005-09-25 12:16:33 UTC (rev 10063)
@@ -250,3 +250,6 @@
 extern GdkRectangle render_text_centered(cairo_t *c, char *s, int x, int y);
 extern GdkRectangle render_border_centered(cairo_t *c, char *s, int x, int y);
 extern GdkRectangle render_bordertext_centered(cairo_t *c, char *s, int x, int y);
+
+extern void gameboard_size_allocate (GtkWidget     *widget,
+				     GtkAllocation *allocation);

Modified: trunk/planarity/gameboard_draw_intersection.c
===================================================================
--- trunk/planarity/gameboard_draw_intersection.c	2005-09-25 10:08:44 UTC (rev 10062)
+++ trunk/planarity/gameboard_draw_intersection.c	2005-09-25 12:16:33 UTC (rev 10063)
@@ -71,9 +71,9 @@
 	  if(ix >= xx && ix <= x2 && iy >= yy && iy <= y2)
 	    draw_intersection(c,ix,iy);
 	}
-	cairo_stroke(c); // incremental stroke!  It's easy to run
-	// the path longer than the X server
-	// allows.
+	cairo_stroke(c); /* incremental stroke!  It's easy to run
+			    the path longer than the X server
+			    allows. */
 	i=i->next;
       }
       e=e->next;

Modified: trunk/planarity/gameboard_logic_button.c
===================================================================
--- trunk/planarity/gameboard_logic_button.c	2005-09-25 10:08:44 UTC (rev 10062)
+++ trunk/planarity/gameboard_logic_button.c	2005-09-25 12:16:33 UTC (rev 10063)
@@ -591,6 +591,8 @@
     g->b.sweeperd = 1;
 
     g->button_callback = callback;
+    if(g->gtk_timer!=0)
+      g_source_remove(g->gtk_timer);
     g->gtk_timer = g_timeout_add(BUTTON_ANIM_INTERVAL, animate_button_frame, (gpointer)g);
     g->b.buttons_ready=1;
   }
@@ -612,6 +614,8 @@
     g->b.sweeperd = -1;
 
     g->button_callback = callback;
+    if(g->gtk_timer!=0)
+      g_source_remove(g->gtk_timer);
     g->gtk_timer = g_timeout_add(BUTTON_ANIM_INTERVAL, animate_button_frame, (gpointer)g);
   }else
     callback(g);

Modified: trunk/planarity/levelstate.c
===================================================================
--- trunk/planarity/levelstate.c	2005-09-25 10:08:44 UTC (rev 10062)
+++ trunk/planarity/levelstate.c	2005-09-25 12:16:33 UTC (rev 10063)
@@ -76,8 +76,8 @@
     // generate a graph we can use to make the icon
     graph g;
     memset(&g,0,sizeof(g));
-    g.width=gameboard->g.width;
-    g.height=gameboard->g.height;
+    g.width=gameboard->g.orig_width;
+    g.height=gameboard->g.orig_height;
     g.orig_width=gameboard->g.orig_width;
     g.orig_height=gameboard->g.orig_height;
 

Modified: trunk/planarity/main.c
===================================================================
--- trunk/planarity/main.c	2005-09-25 10:08:44 UTC (rev 10062)
+++ trunk/planarity/main.c	2005-09-25 12:16:33 UTC (rev 10063)
@@ -40,7 +40,20 @@
 }     
 
 void request_resize(int width, int height){
+  GtkWidget *w = GTK_WIDGET(gameboard);
+
   gtk_window_resize(GTK_WINDOW(toplevel_window),width,height);
+
+  // the toplevel resize *could* fail, for example, if the
+  // windowmanager has forced 'maximize'.  In this case, our graph
+  // size is set to what it wanted to be, but the gameboard window size
+  // is unchanged.  Force the graph to resize itself to the window in
+  // this case.
+
+  if(w->allocation.width != width ||
+     w->allocation.height != height)
+    gameboard_size_allocate (GTK_WIDGET(gameboard),&w->allocation);
+
 }
 
 static void clean_exit(int sig){
@@ -115,8 +128,10 @@
 
   levelstate_resume();
   signal(SIGINT,clean_exit);
-  signal(SIGSEGV,clean_exit);
 
+  //signal(SIGSEGV,clean_exit); /* would be a bad idea; corrupt state
+  //could prevent us from restarting */
+
   gtk_main ();
 
   levelstate_write();

Modified: trunk/planarity/version.h
===================================================================
--- trunk/planarity/version.h	2005-09-25 10:08:44 UTC (rev 10062)
+++ trunk/planarity/version.h	2005-09-25 12:16:33 UTC (rev 10063)
@@ -1,2 +1,2 @@
 #define VERSION "$Id$ "
-/* DO NOT EDIT: Automated versioning hack [Sun Sep 25 06:06:53 EDT 2005] */
+/* DO NOT EDIT: Automated versioning hack [Sun Sep 25 08:15:01 EDT 2005] */



More information about the commits mailing list