[xiph-commits] r10065 - trunk/planarity

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


Author: xiphmont
Date: 2005-09-25 16:28:34 -0700 (Sun, 25 Sep 2005)
New Revision: 10065

Modified:
   trunk/planarity/dialog_level_icons.c
   trunk/planarity/gameboard.h
   trunk/planarity/version.h
Log:
Additional Vlagrind pass

Move level dialog static storageto gameboard struct



Modified: trunk/planarity/dialog_level_icons.c
===================================================================
--- trunk/planarity/dialog_level_icons.c	2005-09-25 12:18:18 UTC (rev 10064)
+++ trunk/planarity/dialog_level_icons.c	2005-09-25 23:28:34 UTC (rev 10065)
@@ -11,28 +11,7 @@
 #include "levelstate.h"
 #include "main.h"
 
-typedef struct {
-  int num;
-  double alpha;
-  cairo_surface_t *icon;
-
-  int x;
-  int y;
-  int w;
-  int h;
-
-} onelevel;
-
-static onelevel level_icons[5];
-static int center_x;
-static int level_lit;
-static int reset_deployed;
-static GdkRectangle text1;
-static GdkRectangle text2;
-static GdkRectangle text3;
-static GdkRectangle text4;
-
-static void draw_forward_arrow(graph *g,onelevel *l, cairo_t *c,int fill){
+static void draw_forward_arrow(graph *g,dialog_level_oneicon *l, cairo_t *c,int fill){
   int w = l->w;
   int h = l->h;
   int cx = w/2;
@@ -60,7 +39,7 @@
   cairo_restore(c);
 }
 
-static void draw_backward_arrow(graph *g,onelevel *l, cairo_t *c,int fill){
+static void draw_backward_arrow(graph *g,dialog_level_oneicon *l, cairo_t *c,int fill){
   int w = l->w;
   int h = l->h;
   int cx = w/2;
@@ -88,12 +67,12 @@
   cairo_restore(c);
 }
 
-static void invalidate_icon(Gameboard *g,onelevel *l){
+static void invalidate_icon(Gameboard *g,dialog_level_oneicon *l){
   int cx = g->g.width/2;
   int cy = g->g.height/2;
   GdkRectangle r;
   
-  r.x=l->x+cx+center_x;
+  r.x=l->x+cx+g->d.center_x;
   r.y=l->y+cy;
   r.width=l->w;
   r.height=l->h;
@@ -101,7 +80,7 @@
   gdk_window_invalidate_rect (GTK_WIDGET(g)->window, &r, FALSE);
 }
 
-static void onelevel_init(Gameboard *g, int num, onelevel *l){
+static void dialog_level_oneicon_init(Gameboard *g, int num, dialog_level_oneicon *l){
   int current = get_level_num();
   l->num = num+current;
 
@@ -119,13 +98,13 @@
 static void deploy_reset_button(Gameboard *g){
   buttonstate *states=g->b.states;
 
-  if(!reset_deployed){
+  if(!g->d.reset_deployed){
     states[10].sweepdeploy += SWEEP_DELTA;
 
     states[2].position = 2; //activate it
     states[2].y_target = states[2].y_active;
    
-    reset_deployed=1;
+    g->d.reset_deployed=1;
   }
   
   // even if the button is already 'deployed', the animation may
@@ -142,12 +121,12 @@
 static void undeploy_reset_button(Gameboard *g){
   buttonstate *states=g->b.states;
 
-  if(reset_deployed){
+  if(g->d.reset_deployed){
 
     states[10].sweepdeploy -= SWEEP_DELTA;
     states[2].y_target = states[2].y_inactive;
     
-    reset_deployed=0;
+    g->d.reset_deployed=0;
   }
 
   // even if the button is already 'undeployed', the animation may
@@ -159,8 +138,8 @@
   } 
 }
 
-static void alpha_update(onelevel *l){
-  int distance = labs(l->x - level_icons[2].x + center_x);
+static void alpha_update(Gameboard *g,dialog_level_oneicon *l){
+  int distance = labs(l->x - g->d.level_icons[2].x + g->d.center_x);
   double alpha = 1. - (distance/300.);
   if(alpha<0.)alpha=0.;
   //if(alpha>1.)alpha=1.;
@@ -171,19 +150,19 @@
   int i;
   
   for(i=0;i<5;i++)
-    onelevel_init(g,i-2,level_icons+i);
+    dialog_level_oneicon_init(g,i-2,g->d.level_icons+i);
 
-  center_x = 0;
-  level_lit = 2;
-  reset_deployed = 0;
+  g->d.center_x = 0;
+  g->d.level_lit = 2;
+  g->d.reset_deployed = 0;
 
   if(levelstate_in_progress())
     deploy_reset_button(g);
 
-  memset(&text1,0,sizeof(text1));
-  memset(&text2,0,sizeof(text2));
-  memset(&text3,0,sizeof(text3));
-  memset(&text4,0,sizeof(text4));
+  memset(&g->d.text1,0,sizeof(g->d.text1));
+  memset(&g->d.text2,0,sizeof(g->d.text2));
+  memset(&g->d.text3,0,sizeof(g->d.text3));
+  memset(&g->d.text4,0,sizeof(g->d.text4));
 }
 
 void render_level_icons(Gameboard *g, cairo_t *c, int ex,int ey, int ew, int eh){
@@ -197,13 +176,13 @@
     int ey2 = ey+eh;
     
     for(i=0;i<5;i++){
-      onelevel *l=level_icons+i;
-      alpha_update(l);
+      dialog_level_oneicon *l=g->d.level_icons+i;
+      alpha_update(g,l);
       if(l->num >= 0 && c){
 	
 	int iw = l->w;
 	int ih = l->h;
-	int ix = l->x+center_x+w/2;	
+	int ix = l->x+g->d.center_x+w/2;	
 	int iy = l->y+h/2;
 	
 	if( l->alpha == 0.) continue;
@@ -218,7 +197,7 @@
 	  cairo_paint_with_alpha(c,l->alpha);
 	}
 
-	if(center_x==0){
+	if(g->d.center_x==0){
 	  if(i==2){
 	    cairo_set_source_rgba (c, B_COLOR);
 	    borderbox_path(c,ix+1.5,iy+1.5,iw-3,ih-3);
@@ -226,21 +205,21 @@
 	  }
 
 	  if(i==1)
-	    draw_backward_arrow(&g->g,l,c,i==level_lit);
+	    draw_backward_arrow(&g->g,l,c,i==g->d.level_lit);
 	  if(i==3)
-	    draw_forward_arrow(&g->g,l,c,i==level_lit);
+	    draw_forward_arrow(&g->g,l,c,i==g->d.level_lit);
 	}
       }
     }
 
     // render level related text
-    if(center_x == 0 && c){
+    if(g->d.center_x == 0 && c){
       char buffer[160];
       cairo_matrix_t ma;
 
       // above text
-      if(text1.width==0 || 
-	 (ey<text1.y+text1.height && ey2>text1.y)){
+      if(g->d.text1.width==0 || 
+	 (ey<g->d.text1.y+g->d.text1.height && ey2>g->d.text1.y)){
 	
 	snprintf(buffer,160,"Level %d:",get_level_num()+1);
 	cairo_select_font_face (c, "Arial",
@@ -249,22 +228,22 @@
 	cairo_matrix_init_scale (&ma, 20.,20.);
 	cairo_set_font_matrix (c,&ma);
 	cairo_set_source_rgba (c, TEXT_COLOR);
-	text1=render_bordertext_centered(c, buffer,w/2,y+45);
+	g->d.text1=render_bordertext_centered(c, buffer,w/2,y+45);
       }
       
-      if(text2.width==0 || 
-	 (ey<text2.y+text2.height && ey2>text2.y)){
+      if(g->d.text2.width==0 || 
+	 (ey<g->d.text2.y+g->d.text2.height && ey2>g->d.text2.y)){
 	cairo_select_font_face (c, "Arial",
 				CAIRO_FONT_SLANT_NORMAL,
 				CAIRO_FONT_WEIGHT_NORMAL);
 	cairo_matrix_init_scale (&ma, 18.,18.);
 	cairo_set_font_matrix (c,&ma);
 	cairo_set_source_rgba (c, TEXT_COLOR);
-	text2=render_bordertext_centered(c, get_level_desc(),w/2,y+70);
+	g->d.text2=render_bordertext_centered(c, get_level_desc(),w/2,y+70);
       }
 
-      if(text3.width==0 || 
-	 (ey<text3.y+text3.height && ey2>text3.y)){
+      if(g->d.text3.width==0 || 
+	 (ey<g->d.text3.y+g->d.text3.height && ey2>g->d.text3.y)){
 	
 	if(levelstate_get_hiscore()==0){
 	  cairo_select_font_face (c, "Arial",
@@ -281,11 +260,11 @@
 	cairo_matrix_init_scale (&ma, 18.,18.);
 	cairo_set_font_matrix (c,&ma);
 	cairo_set_source_rgba (c, TEXT_COLOR);
-	text3=render_bordertext_centered(c, buffer,w/2,y+245);
+	g->d.text3=render_bordertext_centered(c, buffer,w/2,y+245);
       }
 
-      if(text4.width==0 || 
-	 (ey<text4.y+text4.height && ey2>text4.y)){
+      if(g->d.text4.width==0 || 
+	 (ey<g->d.text4.y+g->d.text4.height && ey2>g->d.text4.y)){
 
 	snprintf(buffer,160,"total score all levels: %ld",levelstate_total_hiscore());
 	
@@ -295,13 +274,13 @@
 	cairo_matrix_init_scale (&ma, 18.,18.);
 	cairo_set_font_matrix (c,&ma);
 	cairo_set_source_rgba (c, TEXT_COLOR);
-	text4=render_bordertext_centered(c, buffer,w/2,y+265);
+	g->d.text4=render_bordertext_centered(c, buffer,w/2,y+265);
       }
     }else{
-      memset(&text1,0,sizeof(text1));
-      memset(&text2,0,sizeof(text2));
-      memset(&text3,0,sizeof(text3));
-      memset(&text4,0,sizeof(text4));
+      memset(&g->d.text1,0,sizeof(g->d.text1));
+      memset(&g->d.text2,0,sizeof(g->d.text2));
+      memset(&g->d.text3,0,sizeof(g->d.text3));
+      memset(&g->d.text4,0,sizeof(g->d.text4));
     }      
   }
 }
@@ -310,7 +289,7 @@
   Gameboard *g = GAMEBOARD (ptr);
   int i;
 
-  if(center_x == 0){
+  if(g->d.center_x == 0){
     g_source_remove(g->gtk_timer);
     g->gtk_timer=0;
 
@@ -324,15 +303,15 @@
   }
 
   for(i=0;i<5;i++)
-    if(level_icons[i].alpha)
-      invalidate_icon(g, level_icons+i);
+    if(g->d.level_icons[i].alpha)
+      invalidate_icon(g, g->d.level_icons+i);
 
-  if(center_x < 0){
-    center_x += ICON_DELTA;
-    if(center_x > 0) center_x = 0;
+  if(g->d.center_x < 0){
+    g->d.center_x += ICON_DELTA;
+    if(g->d.center_x > 0) g->d.center_x = 0;
   }else{
-    center_x -= ICON_DELTA;
-    if(center_x < 0) center_x = 0;
+    g->d.center_x -= ICON_DELTA;
+    if(g->d.center_x < 0) g->d.center_x = 0;
   }
 
   // trick 'expose'; run it with a region that does nothing in order
@@ -341,13 +320,13 @@
   render_level_icons(g, 0, 0, 0, 0, 0);
 
   for(i=0;i<5;i++)
-    if(level_icons[i].alpha)
-      invalidate_icon(g, level_icons+i);
+    if(g->d.level_icons[i].alpha)
+      invalidate_icon(g, g->d.level_icons+i);
 
   return 1;
 }
 
-static int find_icon(graph *g, int x, int y){
+static int find_icon(Gameboard *b,graph *g, int x, int y){
   int i;
   int w= g->width;
   int h= g->height;
@@ -356,7 +335,7 @@
   y-=h/2;
 
   for(i=1;i<4;i++){
-    onelevel *l=level_icons+i;
+    dialog_level_oneicon *l=b->d.level_icons+i;
     if(l->num>=0){
       if(x >= l->x && 
 	 x <= l->x + l->w &&
@@ -370,19 +349,19 @@
 
 void local_reset (Gameboard *g){
   levelstate_reset();
-  onelevel_init(g,0,level_icons+2);
-  invalidate_icon(g, level_icons+2);
+  dialog_level_oneicon_init(g,0,g->d.level_icons+2);
+  invalidate_icon(g, g->d.level_icons+2);
   undeploy_reset_button(g);
 }
 
 void level_mouse_motion(Gameboard *g, int x, int y){
 
-  int icon = find_icon(&g->g,x,y);
+  int icon = find_icon(g,&g->g,x,y);
 
-  if(icon != level_lit){
-    invalidate_icon(g, level_icons+level_lit);
-    level_lit = icon;
-    invalidate_icon(g, level_icons+level_lit);
+  if(icon != g->d.level_lit){
+    invalidate_icon(g, g->d.level_icons+g->d.level_lit);
+    g->d.level_lit = icon;
+    invalidate_icon(g, g->d.level_icons+g->d.level_lit);
   }
 }
 
@@ -391,41 +370,43 @@
 
   level_mouse_motion(g, x, y);
 
-  if(level_lit == 1){
+  if(g->d.level_lit == 1){
     if(levelstate_prev()){
-      if(level_icons[4].icon)cairo_surface_destroy(level_icons[4].icon);
+      if(g->d.level_icons[4].icon)
+	cairo_surface_destroy(g->d.level_icons[4].icon);
       for(i=4;i>=1;i--){
-	level_icons[i].num = level_icons[i-1].num;
-	level_icons[i].icon = level_icons[i-1].icon;
+	g->d.level_icons[i].num = g->d.level_icons[i-1].num;
+	g->d.level_icons[i].icon = g->d.level_icons[i-1].icon;
       }
-      level_icons[0].icon=0;
-      onelevel_init(g,-2,level_icons);
+      g->d.level_icons[0].icon=0;
+      dialog_level_oneicon_init(g,-2,g->d.level_icons);
       
-      if(center_x==0)expose_full(g); // only needed to 'undraw' the text
+      if(g->d.center_x==0)expose_full(g); // only needed to 'undraw' the text
 
-      center_x = level_icons[1].x - level_icons[2].x;
+      g->d.center_x = g->d.level_icons[1].x - g->d.level_icons[2].x;
     }
   }
   
-  if(level_lit == 3){
+  if(g->d.level_lit == 3){
     if(levelstate_next()){
       
-      if(level_icons[0].icon)cairo_surface_destroy(level_icons[0].icon);
+      if(g->d.level_icons[0].icon)
+	cairo_surface_destroy(g->d.level_icons[0].icon);
       for(i=0;i<4;i++){
-	level_icons[i].num = level_icons[i+1].num;
-	level_icons[i].icon = level_icons[i+1].icon;
+	g->d.level_icons[i].num = g->d.level_icons[i+1].num;
+	g->d.level_icons[i].icon = g->d.level_icons[i+1].icon;
       }
-      level_icons[4].icon=0;
-      onelevel_init(g,2,level_icons+4);
+      g->d.level_icons[4].icon=0;
+      dialog_level_oneicon_init(g,2,g->d.level_icons+4);
       
-      if(center_x==0)expose_full(g); // only needed to 'undraw' the text
+      if(g->d.center_x==0)expose_full(g); // only needed to 'undraw' the text
 
-      center_x = level_icons[3].x - level_icons[2].x;
+      g->d.center_x = g->d.level_icons[3].x - g->d.level_icons[2].x;
 
     }
   }
 
-  if(center_x){
+  if(g->d.center_x){
     if(g->gtk_timer)
       g_source_remove(g->gtk_timer);
     g->gtk_timer = g_timeout_add(BUTTON_ANIM_INTERVAL, animate_level_frame, (gpointer)g);

Modified: trunk/planarity/gameboard.h
===================================================================
--- trunk/planarity/gameboard.h	2005-09-25 12:18:18 UTC (rev 10064)
+++ trunk/planarity/gameboard.h	2005-09-25 23:28:34 UTC (rev 10065)
@@ -86,6 +86,32 @@
   buttonstate *grabbed;
 } buttongroup;
 
+typedef struct {
+  int num;
+  double alpha;
+  cairo_surface_t *icon;
+
+  int x;
+  int y;
+  int w;
+  int h;
+
+} dialog_level_oneicon;
+
+typedef struct {
+
+  dialog_level_oneicon level_icons[5];
+  int center_x;
+  int level_lit;
+  int reset_deployed;
+  
+  GdkRectangle text1;
+  GdkRectangle text2;
+  GdkRectangle text3;
+  GdkRectangle text4;
+
+} dialog_level_state;
+
 struct _Gameboard{
   GtkWidget w;
 
@@ -118,6 +144,7 @@
   int level_dialog_active;
 
   buttongroup b;
+  dialog_level_state d;
 
   vertex *grabbed_vertex;
   vertex *lit_vertex;

Modified: trunk/planarity/version.h
===================================================================
--- trunk/planarity/version.h	2005-09-25 12:18:18 UTC (rev 10064)
+++ trunk/planarity/version.h	2005-09-25 23:28:34 UTC (rev 10065)
@@ -1,2 +1,2 @@
 #define VERSION "$Id$ "
-/* DO NOT EDIT: Automated versioning hack [Sun Sep 25 08:17:24 EDT 2005] */
+/* DO NOT EDIT: Automated versioning hack [Sun Sep 25 19:07:51 EDT 2005] */



More information about the commits mailing list