[xiph-commits] r10129 - trunk/planarity

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Wed Oct 5 04:37:36 PDT 2005


Author: xiphmont
Date: 2005-10-05 04:37:32 -0700 (Wed, 05 Oct 2005)
New Revision: 10129

Modified:
   trunk/planarity/gameboard.h
   trunk/planarity/gameboard_draw_edge.c
   trunk/planarity/gameboard_draw_main.c
   trunk/planarity/gameboard_draw_selection.c
   trunk/planarity/gameboard_draw_vertex.c
   trunk/planarity/gameboard_logic_mouse.c
   trunk/planarity/graph.c
   trunk/planarity/graph.h
   trunk/planarity/graph_generate.c
   trunk/planarity/main.c
   trunk/planarity/version.h
Log:
Make sure solution check is done after group moves
Group moves now also move lines like with single vertex moves; cworth
  requested this so the Cairo developers would have a case top optimize



Modified: trunk/planarity/gameboard.h
===================================================================
--- trunk/planarity/gameboard.h	2005-10-05 10:25:42 UTC (rev 10128)
+++ trunk/planarity/gameboard.h	2005-10-05 11:37:32 UTC (rev 10129)
@@ -292,7 +292,7 @@
 extern void invalidate_vertex_off(GtkWidget *widget, vertex *v, int dx, int dy);
 extern void invalidate_vertex(Gameboard *g, vertex *v);
 extern void invalidate_attached(GtkWidget *widget, vertex *v);
-extern void invalidate_edges(GtkWidget *widget, vertex *v);
+extern void invalidate_edges(GtkWidget *widget, vertex *v, int offx, int offy);
 extern void draw_selection_rectangle(Gameboard *g,cairo_t *c);
 extern void invalidate_selection(GtkWidget *widget);
 extern void invalidate_verticies_selection(GtkWidget *widget);
@@ -308,6 +308,7 @@
 extern void setup_background_edge(cairo_t *c);
 extern void setup_foreground_edge(cairo_t *c);
 extern void draw_edge(cairo_t *c,edge *e);
+extern void draw_edges(cairo_t *c, vertex *v, int offx, int offy);
 extern void finish_edge(cairo_t *c);
 
 extern cairo_surface_t *gameboard_read_icon(char *filename, char *ext,Gameboard *b);

Modified: trunk/planarity/gameboard_draw_edge.c
===================================================================
--- trunk/planarity/gameboard_draw_edge.c	2005-10-05 10:25:42 UTC (rev 10128)
+++ trunk/planarity/gameboard_draw_edge.c	2005-10-05 11:37:32 UTC (rev 10129)
@@ -58,20 +58,53 @@
   cairo_stroke(c);
 }
 
+void draw_edges(cairo_t *c, vertex *v, int offx, int offy){  
+  if(v){
+    edge_list *el=v->edges;
+    while (el){
+      edge *e=el->edge;
+
+      if(e->A->grabbed==0 || e->B->grabbed==0 || v==e->A){
+	if(e->A->grabbed)
+	  cairo_move_to(c,e->A->x+offx,e->A->y+offy);
+	else
+	  cairo_move_to(c,e->A->x,e->A->y);
+	
+	if(e->B->grabbed)
+	  cairo_line_to(c,e->B->x+offx,e->B->y+offy);
+	else
+	  cairo_line_to(c,e->B->x,e->B->y);
+      }
+      el=el->next;
+    }
+  }
+}
+
+
+
 /* invalidate edge region for efficient expose *******************/
 
-void invalidate_edges(GtkWidget *widget, vertex *v){
+void invalidate_edges(GtkWidget *widget, vertex *v, int offx, int offy){
   GdkRectangle r;
   
   if(v){
     edge_list *el=v->edges;
     while (el){
       edge *e=el->edge;
-      r.x = min(e->A->x,e->B->x) - E_LINE;
-      r.y = min(e->A->y,e->B->y) - E_LINE;
-      r.width  = labs(e->B->x - e->A->x) + 1 + E_LINE*2;
-      r.height = labs(e->B->y - e->A->y) + 1 + E_LINE*2;
-      gdk_window_invalidate_rect (widget->window, &r, FALSE);
+
+      if(e->A->grabbed==0 || e->B->grabbed==0 || v==e->A){
+	int Ax = e->A->x + (e->A->grabbed?offx:0);
+	int Ay = e->A->y + (e->A->grabbed?offy:0);
+	int Bx = e->B->x + (e->B->grabbed?offx:0);
+	int By = e->B->y + (e->B->grabbed?offy:0);
+	
+	r.x = min(Ax,Bx) - E_LINE;
+	r.y = min(Ay,By) - E_LINE;
+	r.width  = labs(Bx - Ax) + 1 + E_LINE*2;
+	r.height = labs(By - Ay) + 1 + E_LINE*2;
+	
+	gdk_window_invalidate_rect (widget->window, &r, FALSE);
+      }
       el=el->next;
     }
   }

Modified: trunk/planarity/gameboard_draw_main.c
===================================================================
--- trunk/planarity/gameboard_draw_main.c	2005-10-05 10:25:42 UTC (rev 10128)
+++ trunk/planarity/gameboard_draw_main.c	2005-10-05 11:37:32 UTC (rev 10129)
@@ -50,10 +50,7 @@
    respectively.  These are prerendered surfaces that are blitted onto
    the foreground during exposes */
 
-/* the midground is a group of elements that may currently be animated
-   (thus rendered to the foreground) or not (thus rendered to the
-   background) */
-static void draw_midground(Gameboard *g,cairo_t *c,int x,int y,int w,int h){
+void draw_foreground(Gameboard *g,cairo_t *c,int x,int y,int w,int h){
 
   /* Edges attached to the grabbed vertex are drawn here */
 
@@ -63,12 +60,27 @@
     while(el){
       edge *e=el->edge;
       /* no need to check rectangle; if they're to be drawn, they'll
-	 always be in the rect */
+	 always be in the rect due to expose combining */
       draw_edge(c,e);
       el=el->next;
     }
     finish_edge(c);
   }
+
+  if(g->group_drag){
+    vertex *v = g->g.verticies;
+    setup_foreground_edge(c);
+
+    while(v){
+      if(v->grabbed){
+	/* no need to check rectangle; if they're to be drawn, they'll
+	   always be in the rect due to expose combining */
+	draw_edges(c,v,g->dragx,g->dragy);
+      }
+      v=v->next;
+    }
+    finish_edge(c);
+  }
   
   /* verticies drawn over the edges */
   {
@@ -82,33 +94,46 @@
     
     while(v){
 
-      /* is the vertex in the expose rectangle? */
-      if(v->x>=clipx && v->x<=clipw &&
-	 v->y>=clipy && v->y<=cliph){
-	
-	if(v == g->grabbed_vertex && !g->group_drag) {
-	  draw_vertex(c,v,g->vertex_grabbed);      
-	} else if( v->selected ){
-	  draw_vertex(c,v,g->vertex_sel);
-	} else if ( v == g->lit_vertex){
-	  draw_vertex(c,v,g->vertex_lit);
-	} else if (v->attached_to_grabbed && !g->group_drag){
-	  draw_vertex(c,v,g->vertex_attached);
-	}else{
-	  draw_vertex(c,v,g->vertex);
-	  if(v->fading)
-	    draw_vertex_with_alpha(c,v,g->vertex_attached,alpha);
+      if(v->grabbed && g->group_drag){
+	vertex tv;
+	tv.x=v->x+g->dragx;
+	tv.y=v->y+g->dragy;
+	/* is the vertex in the expose rectangle? */
+	if(tv.x>=clipx && tv.x<=clipw &&
+	   tv.y>=clipy && tv.y<=cliph){
+	  
+	  draw_vertex(c,&tv,g->vertex_ghost);
 	}
+      }else{ 
+	/* is the vertex in the expose rectangle? */
+	if(v->x>=clipx && v->x<=clipw &&
+	   v->y>=clipy && v->y<=cliph){
+	  
+	  if(v == g->grabbed_vertex && !g->group_drag) {
+	    draw_vertex(c,v,g->vertex_grabbed);      
+	  } else if( v->selected ){
+	    draw_vertex(c,v,g->vertex_sel);
+	  } else if ( v == g->lit_vertex){
+	    draw_vertex(c,v,g->vertex_lit);
+	  } else if (v->attached_to_grabbed && !g->group_drag){
+	    draw_vertex(c,v,g->vertex_attached);
+	  }else{
+	    draw_vertex(c,v,g->vertex);
+	    if(v->fading)
+	      draw_vertex_with_alpha(c,v,g->vertex_attached,alpha);
+	  }
+	}
       }
       
       v=v->next;
     }
   }
+
+  if(g->selection_grab)
+    draw_selection_rectangle(g,c);
 }
 
 static void draw_background(Gameboard *g,cairo_t *c){
-  int width=g->g.width;
-  int height=g->g.height;
   edge *e=g->g.edges;
 
   cairo_set_source_rgb(c,1,1,1);
@@ -124,42 +149,9 @@
     }
     finish_edge(c);
   }
-
-  // if there's a a group drag in progress, midground is drawn here
-  if(g->group_drag)
-    draw_midground(g,c,0,0,width,height);
-
 }
 
-/* This draws the nominal foreground, that is, the elements that are
-   always foreground except when a 'background push' (dialog and
-   curtain over the board) is in place. */
-void draw_foreground(Gameboard *g,cairo_t *c,
-		     int x,int y,int width,int height){
-  
-  /* if a group drag is in progress, draw the group 
-     ghosted in the foreground */
 
-  if(g->group_drag){ 
-    vertex *v = g->g.verticies;
-    while(v){
-      
-      if( v->selected ){
-	vertex tv;
-	tv.x=v->x+g->dragx;
-	tv.y=v->y+g->dragy;
-	draw_vertex(c,&tv,g->vertex_ghost);
-      }
-
-      v=v->next;
-    }
-  }else
-    draw_midground(g,c,x,y,width,height);    
-
-  if(g->selection_grab)
-    draw_selection_rectangle(g,c);
-}
-
 /* Several very-high-level drawing sequences triggered by various
    actions in the game *********************************************/
 

Modified: trunk/planarity/gameboard_draw_selection.c
===================================================================
--- trunk/planarity/gameboard_draw_selection.c	2005-10-05 10:25:42 UTC (rev 10128)
+++ trunk/planarity/gameboard_draw_selection.c	2005-10-05 11:37:32 UTC (rev 10129)
@@ -64,8 +64,10 @@
   Gameboard *g = GAMEBOARD (widget);
   vertex *v=g->g.verticies;
   while(v){
-    if(v->selected)
+    if(v->selected){
       invalidate_vertex_off(widget,v,g->dragx,g->dragy);
+      invalidate_edges(widget,v,g->dragx,g->dragy);
+    }
     v=v->next;
   }
 }

Modified: trunk/planarity/gameboard_draw_vertex.c
===================================================================
--- trunk/planarity/gameboard_draw_vertex.c	2005-10-05 10:25:42 UTC (rev 10128)
+++ trunk/planarity/gameboard_draw_vertex.c	2005-10-05 11:37:32 UTC (rev 10129)
@@ -172,15 +172,19 @@
   
   cairo_set_line_width(c,V_LINE);
   cairo_arc(c,V_RADIUS+V_LINE,V_RADIUS+V_LINE,V_RADIUS,0,2*M_PI);
-  cairo_set_source_rgba(c,V_LINE_COLOR,.2);
+  cairo_set_source_rgb(c,V_FILL_LIT_COLOR);
   cairo_fill_preserve(c);
-  cairo_set_source_rgba(c,V_LINE_COLOR,.4);
+  cairo_set_source_rgb(c,V_LINE_COLOR);
   cairo_stroke(c);
+  cairo_arc(c,V_RADIUS+V_LINE,V_RADIUS+V_LINE,V_RADIUS*.5,0,2*M_PI);
+  cairo_set_source_rgb(c,V_FILL_ADJ_COLOR);
+  cairo_fill(c);
 
   cairo_destroy(c);
   return ret;
 }
 
+
 /* region invalidation operations; do exposes efficiently! **********/
 
 // invalidate the box around a single offset vertex

Modified: trunk/planarity/gameboard_logic_mouse.c
===================================================================
--- trunk/planarity/gameboard_logic_mouse.c	2005-10-05 10:25:42 UTC (rev 10128)
+++ trunk/planarity/gameboard_logic_mouse.c	2005-10-05 11:37:32 UTC (rev 10129)
@@ -67,10 +67,10 @@
     g->dragy = y-g->graby;
     
     invalidate_vertex(g,g->grabbed_vertex);
-    invalidate_edges(widget,g->grabbed_vertex);
+    invalidate_edges(widget,g->grabbed_vertex,0,0);
     move_vertex(&g->g,g->grabbed_vertex,x+g->graboffx,y+g->graboffy);
     invalidate_vertex(g,g->grabbed_vertex);
-    invalidate_edges(widget,g->grabbed_vertex);
+    invalidate_edges(widget,g->grabbed_vertex,0,0);
     return TRUE;
 
   }
@@ -93,7 +93,7 @@
   }
 
   /* if a selected vertex is grabbed (group drag) we're dragging
-     the ghosted selection */
+     the whole selection and its lines */
   
   if(g->group_drag){
     invalidate_verticies_selection(widget);
@@ -211,8 +211,11 @@
 	g->graby = (int)event->y;
 	g->dragx = 0;
 	g->dragy = 0;
-	// put the verticies into the background for faster update
-	update_full(g); 
+	// highlight vertex immediately; update the background after the
+	// vertex change
+	grab_selected(&g->g);
+	invalidate_verticies_selection(widget);
+	update_full_delayed(g);
 	return TRUE;
       }
       
@@ -238,7 +241,7 @@
 	
 	grab_vertex(&g->g,g->grabbed_vertex);
 	invalidate_attached(widget,g->grabbed_vertex);
-	invalidate_edges(widget,g->grabbed_vertex);
+	invalidate_edges(widget,g->grabbed_vertex,0,0);
 	fade_cancel(g);
 	// highlight vertex immediately; update the background after the
 	// vertex change
@@ -330,9 +333,15 @@
     /* case: release a group drag */
     if(g->group_drag){
       move_selected_verticies(&g->g,g->dragx,g->dragy);
+      ungrab_verticies(&g->g);
       update_full(g); // cheating
       update_score(g);
       g->group_drag=0;
+
+      if(g->g.active_intersections<=g->g.objective)
+	deploy_check(g);
+      else
+	undeploy_check(g);
     }
   }
 

Modified: trunk/planarity/graph.c
===================================================================
--- trunk/planarity/graph.c	2005-10-05 10:25:42 UTC (rev 10128)
+++ trunk/planarity/graph.c	2005-10-05 11:37:32 UTC (rev 10129)
@@ -515,6 +515,25 @@
   v->grabbed=1;
 }
 
+void grab_selected(graph *g){
+  vertex *v = g->verticies;
+  while(v){
+    if(v->selected){
+      //edge_list *el=v->edges;
+      deactivate_vertex(g,v);
+      //while(el){
+      //edge_list *next=el->next;
+      //edge *e=el->edge;
+      //vertex *other=(e->A==v?e->B:e->A);
+	//other->attached_to_grabbed=1;
+	//el=next;
+      //}
+      v->grabbed=1;
+    }
+    v=v->next;
+  }
+}
+
 void ungrab_vertex(graph *g,vertex *v){
   edge_list *el=v->edges;
   activate_vertex(g,v);
@@ -528,6 +547,25 @@
   v->grabbed=0;
 }
 
+void ungrab_verticies(graph *g){
+  vertex *v = g->verticies;
+  while(v){
+    if(v->grabbed){
+      //edge_list *el=v->edges;
+      activate_vertex(g,v);
+      //while(el){
+      //edge_list *next=el->next;
+      //edge *e=el->edge;
+      //vertex *other=(e->A==v?e->B:e->A);
+	//other->attached_to_grabbed=1;
+	//el=next;
+      //}
+      v->grabbed=0;
+    }
+    v=v->next;
+  }
+}
+
 vertex *find_vertex(graph *g, int x, int y){
   vertex *v = g->verticies;
   vertex *match = 0;
@@ -717,15 +755,7 @@
 
 void move_selected_verticies(graph *g,int dx, int dy){
   vertex *v = g->verticies;
-  /* deactivate selected verticies */
-  while(v){
-    vertex *next=v->next;
-    if(v->selected)
-      deactivate_vertex(g,v);
-    v=next;
-  }
-
-  /* move selected verticies and reactivate */
+  /* move selected verticies; do not reactivate, done during ungrab */
   v=g->verticies;
   while(v){
     vertex *next=v->next;
@@ -733,7 +763,7 @@
       v->x+=dx;
       v->y+=dy;
       check_vertex(g,v);
-      activate_vertex(g,v);
+      //activate_vertex(g,v);
     }
     v=next;
   }

Modified: trunk/planarity/graph.h
===================================================================
--- trunk/planarity/graph.h	2005-10-05 10:25:42 UTC (rev 10128)
+++ trunk/planarity/graph.h	2005-10-05 11:37:32 UTC (rev 10129)
@@ -115,7 +115,9 @@
 
 extern void move_vertex(graph *g, vertex *v, int x, int y);
 extern void grab_vertex(graph *g, vertex *v);
+extern void grab_selected(graph *g);
 extern void ungrab_vertex(graph *g,vertex *v);
+extern void ungrab_verticies(graph *g);
 extern void activate_vertex(graph *g, vertex *v);
 extern void deactivate_vertex(graph *g, vertex *v);
 extern void select_verticies(graph *g, int x1, int y1, int x2, int y2);

Modified: trunk/planarity/graph_generate.c
===================================================================
--- trunk/planarity/graph_generate.c	2005-10-05 10:25:42 UTC (rev 10128)
+++ trunk/planarity/graph_generate.c	2005-10-05 11:37:32 UTC (rev 10129)
@@ -49,9 +49,9 @@
   {"simple",   3, "Larger But Not Harder",                          generate_simple,    1.,1., 2 }, // 4
   {"crest",    5, "The Trick Is It's Easy",                         generate_crest,     1.,1., 2 }, // 5
 
-  {"simple",   4, "Practice Before the Handbasket: One of Three",   generate_simple,    1.,1., 1 }, // 6
-  {"simple",   5, "Practice Before the Handbasket: Two of Three",   generate_simple,    1.,1., 1 }, // 7
-  {"simple",   6, "Practice Before the Handbasket: Three of Three", generate_simple,    1.,1., 1 }, // 8
+  {"simple",   4, "Practice Before the Handbasket: One of Three",   generate_simple,    1.,1., 2 }, // 6
+  {"simple",   5, "Practice Before the Handbasket: Two of Three",   generate_simple,    1.,1., 2 }, // 7
+  {"simple",   6, "Practice Before the Handbasket: Three of Three", generate_simple,    1.,1., 2 }, // 8
 
   {"sparse",   4, "Tough and Stringy",                              generate_sparse,    1.2,1., 2 }, // 9
   {"sparse",   5, "Threadbare",                                     generate_sparse,    1.2,1., 2 }, // 10

Modified: trunk/planarity/main.c
===================================================================
--- trunk/planarity/main.c	2005-10-05 10:25:42 UTC (rev 10128)
+++ trunk/planarity/main.c	2005-10-05 11:37:32 UTC (rev 10129)
@@ -224,14 +224,12 @@
     cairo_text_extents (c, test_string, &ex);
     adjust_x_normal = 1058 / ex.width;
     adjust_y_normal = -37 / ex.y_bearing;
-    fprintf(stderr,"%f,%f\n",ex.width,ex.y_bearing);
 
 
     cairo_set_font_face (c, bold_face);
     cairo_text_extents (c, test_string, &ex);
     adjust_x_bold = 1130 / ex.width;
     adjust_y_bold = -37 / ex.y_bearing;
-    fprintf(stderr,"%f,%f\n",ex.width,ex.y_bearing);
 
 
     cairo_destroy(c);

Modified: trunk/planarity/version.h
===================================================================
--- trunk/planarity/version.h	2005-10-05 10:25:42 UTC (rev 10128)
+++ trunk/planarity/version.h	2005-10-05 11:37:32 UTC (rev 10129)
@@ -1,2 +1,2 @@
 #define VERSION "$Id$ "
-/* DO NOT EDIT: Automated versioning hack [Wed Oct  5 06:16:08 EDT 2005] */
+/* DO NOT EDIT: Automated versioning hack [Wed Oct  5 07:33:25 EDT 2005] */



More information about the commits mailing list