[xiph-commits] r12566 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Mon Feb 26 01:34:28 PST 2007


Author: xiphmont
Date: 2007-02-26 01:34:24 -0800 (Mon, 26 Feb 2007)
New Revision: 12566

Modified:
   trunk/sushivision/dimension.c
   trunk/sushivision/internal.h
   trunk/sushivision/panel-1d.c
   trunk/sushivision/panel-2d.c
   trunk/sushivision/panel.c
   trunk/sushivision/plot.c
   trunk/sushivision/plot.h
Log:
First go at printing support.  1d panels not entirely fille din yet,
but 2-d should be 100% implemented.

Correct a serious dimension scaling bug where a dim was being
stretched to fill the whole pane, but the compute iterators weren't
using the call that knew about the stretching.



Modified: trunk/sushivision/dimension.c
===================================================================
--- trunk/sushivision/dimension.c	2007-02-26 02:56:12 UTC (rev 12565)
+++ trunk/sushivision/dimension.c	2007-02-26 09:34:24 UTC (rev 12566)
@@ -69,26 +69,33 @@
   switch(d->type){
   case SUSHIV_DIM_CONTINUOUS:
     {
-      double ceil = d->scale->val_list[d->scale->vals-1] * dimneg;
+      //double ceil = d->scale->val_list[d->scale->vals-1] * dimneg;
       double fl = ((d->flags & SUSHIV_DIM_ZEROINDEX) ? d->scale->val_list[0] : 0.);
       *panel = scalespace_linear(lo, hi, panel_w, spacing, legend);
-      *data = scalespace_linear(lo, hi, data_w, 1, legend);
-      *iter = scalespace_linear(lo-fl, hi-fl, data_w, 1, legend);
 
-      /* if possible, the data/iterator scales should cover the entire pane exposed
-	 by the panel scale so long as there's room left to extend them without
-	 overflowing the lo/hi fenceposts */
-      while(1){
-	double panel2 = scalespace_value(panel,panel->pixels-1)*pneg;
-	double data2 = scalespace_value(data,data_w-1)*pneg;
+      if(panel_w == data_w){
+	
+	*iter = *data = *panel;
 
-	if(data2>=panel2)break;
-	data_w++;
+      }else{
+	*data = scalespace_linear(lo, hi, data_w, 1, legend);
+	*iter = scalespace_linear(lo-fl, hi-fl, data_w, 1, legend);
+	
+	
+	/* if possible, the data/iterator scales should cover the entire pane exposed
+	   by the panel scale so long as there's room left to extend them without
+	   overflowing the lo/hi fenceposts */
+	while(1){
+	  double panel2 = scalespace_value(panel,panel_w-1)*pneg;
+	  double data2 = scalespace_value(data,data_w-1)*pneg;
+	  
+	  if(data2>=panel2)break;
+	  data_w++;
+	}
+	
+	data->pixels = data_w;
+	iter->pixels = data_w;
       }
-
-      data->pixels = data_w;
-      iter->pixels = data_w;
-
     }
     break;
   case SUSHIV_DIM_DISCRETE:

Modified: trunk/sushivision/internal.h
===================================================================
--- trunk/sushivision/internal.h	2007-02-26 02:56:12 UTC (rev 12565)
+++ trunk/sushivision/internal.h	2007-02-26 09:34:24 UTC (rev 12566)
@@ -104,6 +104,7 @@
   int (*compute_action)(sushiv_panel_t *p, _sushiv_bythread_cache *c);
   void (*request_compute)(sushiv_panel_t *p);
   void (*crosshair_action)(sushiv_panel_t *p);
+  void (*data_print)(cairo_t *c, sushiv_panel_t *p);
 
   void (*undo_log)(sushiv_panel_undo_t *u, sushiv_panel_t *p);
   void (*undo_restore)(sushiv_panel_undo_t *u, sushiv_panel_t *p);

Modified: trunk/sushivision/panel-1d.c
===================================================================
--- trunk/sushivision/panel-1d.c	2007-02-26 02:56:12 UTC (rev 12565)
+++ trunk/sushivision/panel-1d.c	2007-02-26 09:34:24 UTC (rev 12566)
@@ -570,8 +570,7 @@
 static void compute_1d(sushiv_panel_t *p, 
 		       int serialno,
 		       int x_d, 
-		       double x_min, 
-		       double x_max, 
+		       scalespace sxi,
 		       int w, 
 		       double *dim_vals,
 		       _sushiv_bythread_cache_1d *c){
@@ -588,8 +587,7 @@
       
       /* by x */
       for(j=0;j<w;j++){
-
-	dim_vals[x_d] = (x_max-x_min) * j / w + x_min;
+	dim_vals[x_d] = scalespace_value(&sxi,j);
 	c->call[i](dim_vals,fout);
 	fout+=step;
       }
@@ -1024,8 +1022,6 @@
   double dim_vals[p->sushi->dimensions];
 
   /* get iterator bounds, use iterator scale */
-  x_min = scalespace_value(&sxi,0);
-  x_max = scalespace_value(&sxi,dw);
   x_d = p1->x_d->number;
 
   if(p1->flip){
@@ -1052,7 +1048,7 @@
   gdk_threads_leave ();
 
   plot_draw_scales(plot);
-  compute_1d(p, serialno, x_d, x_min, x_max, dw, dim_vals, &c->p1);
+  compute_1d(p, serialno, x_d, sxi, dw, dim_vals, &c->p1);
   
   gdk_threads_enter ();
 

Modified: trunk/sushivision/panel-2d.c
===================================================================
--- trunk/sushivision/panel-2d.c	2007-02-26 02:56:12 UTC (rev 12565)
+++ trunk/sushivision/panel-2d.c	2007-02-26 09:34:24 UTC (rev 12566)
@@ -40,8 +40,7 @@
 				     int dw,
 				     int y,
 				     int x_d, 
-				     double x_min, 
-				     double x_max, 
+				     scalespace sxi,
 				     double *dim_vals, 
 				     _sushiv_bythread_cache_2d *c){
 
@@ -58,7 +57,7 @@
     int *onum = p2->y_obj_to_panel;
     
     /* by function */
-    dim_vals[x_d] = (x_max-x_min) * j / dw + x_min;
+    dim_vals[x_d] = scalespace_value(&sxi,j);   
     for(i=0;i<p2->used_functions;i++){
       (*f)->callback(dim_vals,fout);
       fout += (*f)->outputs;
@@ -248,7 +247,7 @@
     if(del2 > scaleden && bin>=0 && bin<dw){
       int rem = total;
 
-      delA[i] = (xymul * (scaleden - del)) / discscale;
+      delA[i] = ((xymul * (scaleden - del)) + (discscale>>1)) / discscale;
       posA[i] = bin;
       rem -= delA[i];
       rem -= xymul*(sizeceil-2);
@@ -706,6 +705,18 @@
   return 1;
 }
 
+// looks like a cop-out but is actually the correct thing to do; the
+// data *must* be WYSIWYG from panel display.
+void sushiv_panel2d_print_bg(cairo_t *c, sushiv_panel_t *p){
+  Plot *plot = PLOT(p->private->graph);
+
+  if(!plot) return;
+
+  cairo_set_source_surface(c, plot->back,0,0);
+  cairo_paint(c);
+
+}
+
 // call while locked
 static void _dirty_map_one_plane(sushiv_panel_t *p, int onum, int y, int z, int v){
   sushiv_panel2d_t *p2 = p->subtype->p2;
@@ -1456,8 +1467,8 @@
   /* unlock for computation */
   gdk_threads_leave ();
     
-  dim_vals[y_d]= (y_max - y_min) / dh * y + y_min;
-  compute_one_data_line_2d(p, serialno, dw, y, x_d, x_min, x_max, dim_vals, &c->p2);
+  dim_vals[y_d]=scalespace_value(&sy_i, y);
+  compute_one_data_line_2d(p, serialno, dw, y, x_d, sx_i, dim_vals, &c->p2);
 
   gdk_threads_enter ();
 
@@ -1782,7 +1793,7 @@
   p->private->compute_action = _sushiv_panel2d_compute;
   p->private->request_compute = _mark_recompute_2d;
   p->private->crosshair_action = _sushiv_panel2d_crosshairs_callback;
-
+  p->private->data_print = sushiv_panel2d_print_bg;
   p->private->undo_log = panel2d_undo_log;
   p->private->undo_restore = panel2d_undo_restore;
 

Modified: trunk/sushivision/panel.c
===================================================================
--- trunk/sushivision/panel.c	2007-02-26 02:56:12 UTC (rev 12565)
+++ trunk/sushivision/panel.c	2007-02-26 09:34:24 UTC (rev 12566)
@@ -78,6 +78,11 @@
   plot_do_escape(PLOT(p->private->graph));
 }
 
+static void wrap_legend(sushiv_panel_t *p){
+  plot_toggle_legend(PLOT(p->private->graph));
+  _sushiv_panel_dirty_legend(p);
+}
+
 static int _sushiv_panel_background_i(sushiv_panel_t *p,
 				      enum sushiv_background bg){
   
@@ -173,23 +178,39 @@
 
 }
 
-static void _pdf_print_handler(GtkPrintOperation *operation,
-			       GtkPrintContext   *context,
-			       gint               page_nr,
-			       gpointer           user_data){
+static void _print_handler(GtkPrintOperation *operation,
+			   GtkPrintContext   *context,
+			   gint               page_nr,
+			   gpointer           user_data){
 
   cairo_t *c;
   gdouble w, h;
-  
+  sushiv_panel_t *p = (sushiv_panel_t *)user_data;
+  double pw = p->private->graph->allocation.width;
+  double ph = p->private->graph->allocation.height;
+  double scale;
+
   c = gtk_print_context_get_cairo_context (context);
   w = gtk_print_context_get_width (context);
   h = gtk_print_context_get_height (context);
   
-  fprintf(stderr,"%f,%f\n",w,h);
+  if(w/pw < h/ph)
+    scale = w/pw;
+  else
+    scale = h/ph;
+
   cairo_rectangle (c, 0, 0, w, h);
+
+  cairo_matrix_t m;
+  cairo_get_matrix(c,&m);
+  cairo_matrix_scale(&m,scale,scale);
+  cairo_set_matrix(c,&m);
+
+  plot_print(PLOT(p->private->graph), c, ph*scale, (void(*)(cairo_t *, void *))p->private->data_print, p);
+
   
-  cairo_set_source_rgb (c, 1., 1., 1.);
-  cairo_fill (c);
+  // XXX render objective scales here
+
 }
 
 static void _sushiv_panel_print(sushiv_panel_t *p){
@@ -201,7 +222,7 @@
   g_signal_connect (op, "begin-print", 
 		    G_CALLBACK (_begin_print_handler), p);
   g_signal_connect (op, "draw-page", 
-		    G_CALLBACK (_pdf_print_handler), p);
+		    G_CALLBACK (_print_handler), p);
 
   GtkPrintOperationResult ret = gtk_print_operation_run (op,GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
 							 NULL,NULL);
@@ -223,7 +244,8 @@
   &(menuitem){"Undo","[<i>bksp</i>]",NULL,&_sushiv_panel_undo_down},
   &(menuitem){"Redo","[<i>space</i>]",NULL,&_sushiv_panel_undo_up},
   &(menuitem){"Start zoom box","[<i>enter</i>]",NULL,&wrap_enter},
-  &(menuitem){"Clear readouts","[<i>escape</i>]",NULL,&wrap_escape},
+  &(menuitem){"Clear selection","[<i>escape</i>]",NULL,&wrap_escape},
+  &(menuitem){"Toggle Legend","[<i>l</i>]",NULL,&wrap_legend},
 
   &(menuitem){"",NULL,NULL,NULL},
 
@@ -301,34 +323,34 @@
   // make sure menu reflects plot configuration
   switch(p->private->bg_type){ 
   case SUSHIV_BG_WHITE:
-    gtk_menu_alter_item_right(GTK_MENU(p->private->popmenu),9,menu_bg[0]->left);
+    gtk_menu_alter_item_right(GTK_MENU(p->private->popmenu),10,menu_bg[0]->left);
     break;
   case SUSHIV_BG_BLACK:
-    gtk_menu_alter_item_right(GTK_MENU(p->private->popmenu),9,menu_bg[1]->left);
+    gtk_menu_alter_item_right(GTK_MENU(p->private->popmenu),10,menu_bg[1]->left);
     break;
   default:
-    gtk_menu_alter_item_right(GTK_MENU(p->private->popmenu),9,menu_bg[2]->left);
+    gtk_menu_alter_item_right(GTK_MENU(p->private->popmenu),10,menu_bg[2]->left);
     break;
   }
 
   switch(PLOT(p->private->graph)->bg_inv){ 
   case 0:
-    gtk_menu_alter_item_right(GTK_MENU(p->private->popmenu),10,menu_text[0]->left);
+    gtk_menu_alter_item_right(GTK_MENU(p->private->popmenu),11,menu_text[0]->left);
     break;
   default:
-    gtk_menu_alter_item_right(GTK_MENU(p->private->popmenu),10,menu_text[1]->left);
+    gtk_menu_alter_item_right(GTK_MENU(p->private->popmenu),11,menu_text[1]->left);
     break;
   }
 
   switch(PLOT(p->private->graph)->grid_mode){ 
   case PLOT_GRID_NORMAL:
-    gtk_menu_alter_item_right(GTK_MENU(p->private->popmenu),11,menu_scales[0]->left);
+    gtk_menu_alter_item_right(GTK_MENU(p->private->popmenu),12,menu_scales[0]->left);
     break;
   case PLOT_GRID_TICS:
-    gtk_menu_alter_item_right(GTK_MENU(p->private->popmenu),11,menu_scales[1]->left);
+    gtk_menu_alter_item_right(GTK_MENU(p->private->popmenu),12,menu_scales[1]->left);
     break;
   default:
-    gtk_menu_alter_item_right(GTK_MENU(p->private->popmenu),11,menu_scales[2]->left);
+    gtk_menu_alter_item_right(GTK_MENU(p->private->popmenu),12,menu_scales[2]->left);
     break;
   }
 
@@ -338,7 +360,7 @@
     if(p->private->def_oversample_n == p->private->oversample_n &&
        p->private->def_oversample_d == p->private->oversample_d)
       strcat(buffer," (default)");
-    gtk_menu_alter_item_right(GTK_MENU(p->private->popmenu),12,buffer);
+    gtk_menu_alter_item_right(GTK_MENU(p->private->popmenu),13,buffer);
   }
 }
 
@@ -424,6 +446,10 @@
   case GDK_p:
     _sushiv_panel_print(p);
     return TRUE;
+
+  case GDK_l:
+    wrap_legend(p);
+    return TRUE;
   } 
 
   return FALSE;
@@ -451,10 +477,10 @@
     GtkWidget *resmenu = gtk_menu_new_twocol(NULL,menu_res,p);
 
     // not thread safe, we're not threading yet
-    menu[9]->submenu = bgmenu;
-    menu[10]->submenu = textmenu;
-    menu[11]->submenu = scalemenu;
-    menu[12]->submenu = resmenu;
+    menu[10]->submenu = bgmenu;
+    menu[11]->submenu = textmenu;
+    menu[12]->submenu = scalemenu;
+    menu[13]->submenu = resmenu;
 
     p->private->popmenu = gtk_menu_new_twocol(p->private->toplevel, menu, p);
     _sushiv_panel_update_menus(p);

Modified: trunk/sushivision/plot.c
===================================================================
--- trunk/sushivision/plot.c	2007-02-26 02:56:12 UTC (rev 12565)
+++ trunk/sushivision/plot.c	2007-02-26 09:34:24 UTC (rev 12566)
@@ -72,32 +72,25 @@
     cairo_set_source_rgba(c,1.,1.,1.,.8);
 }
 
-static void draw_scales_work(cairo_surface_t *s, int inv_text, int grid,
+static void draw_scales_work(cairo_t *c, int w, int h, 
+			     double page_h,
+			     int inv_text, int grid,
 			     scalespace xs, scalespace ys,
 			     scalespace xs_v, scalespace ys_v){
 
-  int w = cairo_image_surface_get_width(s);
-  int h = cairo_image_surface_get_height(s);
-  cairo_t *c = cairo_create(s);
   int i=0,x,y;
   char buffer[80];
   int y_width=0;
   int x_height=0;
   int off = (grid == PLOT_GRID_TICS?6:0);
 
-  cairo_save(c);
-  cairo_set_operator(c,CAIRO_OPERATOR_CLEAR);
-  cairo_set_source_rgba (c, 1,1,1,1);
-  cairo_paint(c);
-  cairo_restore(c);
-
   // draw all axis lines, then stroke
   if(grid){
 
     cairo_set_line_width(c,1.);
     if(grid == PLOT_GRID_NORMAL){
       cairo_save(c);
-      cairo_set_operator(c,CAIRO_OPERATOR_XOR);       
+      //cairo_set_operator(c,CAIRO_OPERATOR_XOR);       
       cairo_set_source_rgba(c,.5,.5,7.,.5);
       
       i=0;
@@ -107,7 +100,7 @@
 	cairo_line_to(c,x+.5,h);
 	x = scale_demark(&xs, &xs_v, i++, NULL);
       }
-      
+
       i=0;
       y = scale_demark(&ys, &ys_v, i++, NULL);
       while(y < h){
@@ -115,11 +108,12 @@
 	cairo_line_to(c,w,y+.5);
 	y = scale_demark(&ys, &ys_v, i++, NULL);
       }
-      
+
       cairo_stroke(c);
       cairo_restore(c);
     }
 
+
     // text number labels
     cairo_select_font_face (c, "Sans",
 			    CAIRO_FONT_SLANT_NORMAL,
@@ -156,25 +150,28 @@
 
   // set sideways text
   cairo_save(c);
-  cairo_matrix_t m = {0.,-1., 1.,0.,  0.,h};
-  cairo_set_matrix(c,&m);
+  cairo_matrix_t a;
+  cairo_get_matrix(c,&a);
+  cairo_matrix_t b = {0.,-1., 1.,0., 0.,page_h+a.y0+a.y0}; // account for border!
+  cairo_matrix_t d;
+  cairo_matrix_multiply(&d,&a,&b);
+  cairo_set_matrix(c,&d);
 
   // text y scale label
   if(ys.legend){
     cairo_text_extents_t extents;
     cairo_text_extents (c, ys.legend, &extents);
-    
-    cairo_move_to(c,h/2 - extents.width/2+extents.x_bearing, y_width-extents.y_bearing+5+off);
+
+    cairo_move_to(c,h/2 - (extents.width/2 +extents.x_bearing), y_width-extents.y_bearing+5+off);
     set_shadow(inv_text,c);
     cairo_text_path (c, ys.legend);  
     cairo_stroke(c);
     
-    cairo_move_to(c,h/2 - extents.width/2+extents.x_bearing, y_width-extents.y_bearing+5+off);
+    cairo_move_to(c,h/2 - (extents.width/2 +extents.x_bearing), y_width-extents.y_bearing+5+off);
     set_text(inv_text,c);
     cairo_show_text (c, ys.legend);
   }
 
-
   if(grid){
     i=0;
     x = scale_demark(&xs, &xs_v, i++, buffer);
@@ -187,12 +184,12 @@
       
       if(x - extents.height > y_width+5 ){
 	
-	cairo_move_to(c,2+off, x+.5-(extents.height/2 + extents.y_bearing));
+	cairo_move_to(c,2+off-extents.x_bearing, x+.5-(extents.height/2 + extents.y_bearing));
 	set_shadow(inv_text,c);
 	cairo_text_path (c, buffer);  
 	cairo_stroke(c);
 	
-	cairo_move_to(c,2+off, x+.5-(extents.height/2 + extents.y_bearing));
+	cairo_move_to(c,2+off-extents.x_bearing, x+.5-(extents.height/2 + extents.y_bearing));
 	set_text(inv_text,c);
 	cairo_show_text (c, buffer);
       }
@@ -207,12 +204,12 @@
     cairo_text_extents_t extents;
     cairo_text_extents (c, xs.legend, &extents);
     
-    cairo_move_to(c,w/2 - extents.width/2+extents.x_bearing, h - x_height+ extents.y_bearing-3-off);
+    cairo_move_to(c,w/2 - (extents.width/2 + extents.x_bearing), h - x_height+ extents.y_bearing-3-off);
     set_shadow(inv_text,c);
     cairo_text_path (c, xs.legend);  
     cairo_stroke(c);
     
-    cairo_move_to(c,w/2 - extents.width/2+extents.x_bearing, h - x_height+ extents.y_bearing-3-off);
+    cairo_move_to(c,w/2 - (extents.width/2 + extents.x_bearing), h - x_height+ extents.y_bearing-3-off);
     set_text(inv_text,c);
     cairo_show_text (c, xs.legend);
   }
@@ -244,17 +241,11 @@
     }
   
     cairo_stroke(c);
-    cairo_restore(c);
   }
-  
-  cairo_destroy(c);
 }
 
-static void draw_legend_work(Plot *p, cairo_surface_t *s){
-  if(p->legend_entries && p->legend_list){
-    int w = cairo_image_surface_get_width(s);
-    //int h = cairo_image_surface_get_height(s);
-    cairo_t *c = cairo_create(s);
+static void draw_legend_work(Plot *p, cairo_t *c, int w){
+  if(p->legend_entries && p->legend_list && p->legend_active){
     int i;
     int textw=0, texth=0;
     int totalh=0;
@@ -288,14 +279,14 @@
 	textw = extents.width;
     }
     
-    y = 10+texth;
+    y = 15+texth;
     texth = ceil(texth * 1.2+3);
     totalh = texth*n;
     
-    x = w - textw - 10;
+    x = w - textw - 15;
 
     // draw the enclosing rectangle
-    cairo_rectangle(c,x-7,5,textw+14,totalh+10);
+    cairo_rectangle(c,x-6.5,5.5,textw+15,totalh+15);
     set_shadow(inv,c);
     cairo_fill_preserve(c);
     set_text(inv,c);
@@ -303,11 +294,10 @@
 
     for(i=0;i<n;i++){
       cairo_text_extents (c, buffer[i], &extents);
-      x = w - extents.width - 10;
+      x = w - extents.width - 15;
       
-      cairo_move_to(c,x, y);
-      cairo_text_path (c, buffer[i]); 
-
+      //cairo_move_to(c,x, y);
+      //cairo_text_path (c, buffer[i]); 
       //set_shadow(inv,c);
       //cairo_set_line_width(c,3);
       //cairo_stroke(c);
@@ -327,10 +317,8 @@
       y+=texth;
     }
     
-    cairo_destroy(c);
     for(i=0;i<n;i++)
       free(buffer[i]);
-
     
   }
 }
@@ -349,9 +337,17 @@
   int grid = p->grid_mode;
   gdk_threads_leave();
   
-  draw_scales_work(s,inv,grid,x,y,xv,yv);
-  draw_legend_work(p,s);
-  
+  cairo_t *c = cairo_create(s);
+  cairo_save(c);
+  cairo_set_operator(c,CAIRO_OPERATOR_CLEAR);
+  cairo_set_source_rgba (c, 1,1,1,1);
+  cairo_paint(c);
+  cairo_restore(c);
+
+  draw_scales_work(c,w,h,h,inv,grid,x,y,xv,yv);
+  draw_legend_work(p,c,w);
+  cairo_destroy(c);
+
   gdk_threads_enter();
   // swap fore/temp
   cairo_surface_t *temp = p->fore;
@@ -428,8 +424,83 @@
 	  y <= vals[1]+vals[3]);
 }
 
+int plot_print(Plot *p, cairo_t *c, double page_h, void (*datarender)(cairo_t *c,void *data), void *data){
+  GtkWidget *widget = GTK_WIDGET(p);
+  int pw = widget->allocation.width;
+  int ph = widget->allocation.height;
+  scalespace x = p->x;
+  scalespace y = p->y;
+  scalespace xv = p->x_v;
+  scalespace yv = p->y_v;
+  int inv = p->bg_inv;
+  int grid = p->grid_mode;
+
+  cairo_save(c);
+  cairo_rectangle(c,0,0,pw,ph);
+  cairo_clip(c);
+
+  // render the background
+  if(datarender)
+    datarender(c,data);
+
+  // render scales
+  draw_scales_work(c,pw,ph,page_h,inv,grid,x,y,xv,yv);
+
+  // render legend
+  draw_legend_work(p,c,pw);
+
+  // transient foreground crosshairs
+  if(p->cross_active){
+    double sx = plot_get_crosshair_xpixel(p);
+    double sy = plot_get_crosshair_ypixel(p);
+    
+    cairo_set_source_rgba(c,.7,.7,.0,.9);
+    cairo_set_line_width(c,1.);
+    
+    if(! (p->flags & PLOT_NO_Y_CROSS)){
+      cairo_move_to(c,0,sy+.5);
+      cairo_line_to(c,widget->allocation.width,sy+.5);
+    }
+    
+    if(! (p->flags & PLOT_NO_X_CROSS)){
+      cairo_move_to(c,sx+.5,0);
+      cairo_line_to(c,sx+.5,widget->allocation.height);
+    }
+    cairo_stroke(c);
+  }
+  
+  // transient foreground box
+  if(p->box_active){
+    double vals[4];
+    box_corners(p,vals);
+    cairo_set_line_width(c,1.);
+    
+    cairo_rectangle(c,vals[0],vals[1],vals[2]+1,vals[3]+1);	
+    if(p->box_active>1)
+      cairo_set_source_rgba(c,.8,.8,.2,.5);
+    else
+      cairo_set_source_rgba(c,.7,.7,.5,.4);
+    cairo_fill(c);
+    cairo_rectangle(c,vals[0]+.5,vals[1]+.5,vals[2],vals[3]);
+    if(p->box_active>1)
+      cairo_set_source_rgba(c,.8,.8,.2,.9);
+    else
+      cairo_set_source_rgba(c,.8,.8,.2,.8);
+    cairo_stroke(c);
+  }
+
+  // put a border on it if the background is white
+  cairo_set_source_rgb(c,0,0,0);
+  cairo_set_line_width(c,1.0);
+  cairo_rectangle(c,0,0,pw,ph);
+  cairo_stroke(c);
+
+  cairo_restore(c);
+  return 0;
+}
+
 static void plot_draw (Plot *p,
-		int x, int y, int w, int h){
+		       int x, int y, int w, int h){
 
   GtkWidget *widget = GTK_WIDGET(p);
   
@@ -772,11 +843,16 @@
   p->button_down=0;
   p->box_active=0;
   p->cross_active=0;
-  plot_legend_clear(p);
+  //plot_legend_clear(p);
   plot_draw_scales(p);
   plot_expose_request(p);
 }
 
+void plot_toggle_legend(Plot *p){
+  p->legend_active = !p->legend_active;
+  plot_expose_request(p);
+}
+
 static gboolean key_press(GtkWidget *widget,
 			  GdkEventKey *event){
   Plot *p = PLOT(widget);
@@ -964,6 +1040,7 @@
   p->flags = flags;
   p->grid_mode = PLOT_GRID_NORMAL;
   p->resizable = 1;
+  p->legend_active = 1;
 
   return p;
 }

Modified: trunk/sushivision/plot.h
===================================================================
--- trunk/sushivision/plot.h	2007-02-26 02:56:12 UTC (rev 12565)
+++ trunk/sushivision/plot.h	2007-02-26 09:34:24 UTC (rev 12566)
@@ -59,6 +59,7 @@
   double selx;
   double sely;
   int cross_active;
+  int legend_active;
 
   double box_x1;
   double box_y1;
@@ -96,6 +97,7 @@
 G_END_DECLS
 
 // the widget subclass half
+int plot_print(Plot *p, cairo_t *c, double page_h, void (*datarender)(cairo_t *c,void *data), void *data);
 void plot_set_bg_invert(Plot *p, int setp);
 void plot_expose_request(Plot *p);
 void plot_expose_request_partial(Plot *p,int x, int y, int w, int h);
@@ -121,6 +123,7 @@
 
 void plot_do_enter(Plot *p);
 void plot_do_escape(Plot *p);
+void plot_toggle_legend(Plot *p);
 
 void plot_resizable(Plot *p, int rp);
 



More information about the commits mailing list