[xiph-commits] r12583 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Tue Feb 27 15:12:56 PST 2007


Author: xiphmont
Date: 2007-02-27 15:12:52 -0800 (Tue, 27 Feb 2007)
New Revision: 12583

Modified:
   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:
Alter somewhat the abstraction arrangement of printing calls to ease
addition of objective scale legends to 2d panels.

Numerous small menu tweaks.



Modified: trunk/sushivision/internal.h
===================================================================
--- trunk/sushivision/internal.h	2007-02-27 22:36:00 UTC (rev 12582)
+++ trunk/sushivision/internal.h	2007-02-27 23:12:52 UTC (rev 12583)
@@ -97,6 +97,8 @@
   int def_oversample_n;
   int def_oversample_d;
 
+  int menu_cursamp;
+
   // function bundles 
   void (*realize)(sushiv_panel_t *p);
   int (*map_action)(sushiv_panel_t *p, _sushiv_bythread_cache *c);
@@ -104,7 +106,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 (*print_action)(sushiv_panel_t *p, cairo_t *c, int w, int h);
 
   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-27 22:36:00 UTC (rev 12582)
+++ trunk/sushivision/panel-1d.c	2007-02-27 23:12:52 UTC (rev 12583)
@@ -349,11 +349,23 @@
   return 1;
 }
 
-void sushiv_panel1d_print_bg(cairo_t *c, sushiv_panel_t *p){
+static void sushiv_panel1d_print(sushiv_panel_t *p, cairo_t *c, int w, int h){
   Plot *plot = PLOT(p->private->graph);
+  double pw = p->private->graph->allocation.width;
+  double ph = p->private->graph->allocation.height;
+  double scale;
 
-  if(!plot) return;
-  _sushiv_panel1d_remap(p,c);
+  if(w/pw < h/ph)
+    scale = w/pw;
+  else
+    scale = h/ph;
+
+  cairo_matrix_t m;
+  cairo_get_matrix(c,&m);
+  cairo_matrix_scale(&m,scale,scale);
+  cairo_set_matrix(c,&m);
+
+  plot_print(plot, c, ph*scale, (void(*)(void *, cairo_t *))_sushiv_panel1d_remap, p);
 }
 
 static void update_legend(sushiv_panel_t *p){  
@@ -371,14 +383,19 @@
 
     // add each dimension to the legend
     for(i=0;i<p->dimensions;i++){
+      sushiv_dimension_t *d = p->dimension_list[i].d;
       // display decimal precision relative to bracket
       //int depth = del_depth(p->dimension_list[i].d->bracket[0],
       //		    p->dimension_list[i].d->bracket[1]) + offset;
-      snprintf(buffer,320,"%s = %+.*f",
-	       p->dimension_list[i].d->name,
-	       depth,
-	       p->dimension_list[i].d->val);
-      plot_legend_add(plot,buffer);
+      if( d!=p1->x_d ||
+	  plot->cross_active){
+	
+	snprintf(buffer,320,"%s = %+.*f",
+		 p->dimension_list[i].d->name,
+		 depth,
+		 p->dimension_list[i].d->val);
+	plot_legend_add(plot,buffer);
+      }
     }
 
     // linked? add the linked dimension value to the legend
@@ -1442,7 +1459,7 @@
   p->private->compute_action = _sushiv_panel1d_compute;
   p->private->request_compute = _mark_recompute_1d;
   p->private->crosshair_action = crosshair_callback;
-  p->private->data_print = sushiv_panel1d_print_bg;
+  p->private->print_action = sushiv_panel1d_print;
 
   p->private->undo_log = panel1d_undo_log;
   p->private->undo_restore = panel1d_undo_restore;

Modified: trunk/sushivision/panel-2d.c
===================================================================
--- trunk/sushivision/panel-2d.c	2007-02-27 22:36:00 UTC (rev 12582)
+++ trunk/sushivision/panel-2d.c	2007-02-27 23:12:52 UTC (rev 12583)
@@ -727,7 +727,7 @@
 
 // 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){
+static void sushiv_panel2d_print_bg(sushiv_panel_t *p, cairo_t *c){
   Plot *plot = PLOT(p->private->graph);
 
   if(!plot) return;
@@ -737,6 +737,27 @@
 
 }
 
+static void sushiv_panel2d_print(sushiv_panel_t *p, cairo_t *c, int w, int h){
+  Plot *plot = PLOT(p->private->graph);
+  double pw = p->private->graph->allocation.width;
+  double ph = p->private->graph->allocation.height;
+  double scale;
+
+  if(w/pw < h/ph)
+    scale = w/pw;
+  else
+    scale = h/ph;
+
+  cairo_matrix_t m;
+  cairo_get_matrix(c,&m);
+  cairo_matrix_scale(&m,scale,scale);
+  cairo_set_matrix(c,&m);
+
+  plot_print(plot, c, ph*scale, (void(*)(void *, cairo_t *))sushiv_panel2d_print_bg, p);
+
+  // XXX print objective scales
+}
+
 // 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;
@@ -815,16 +836,22 @@
     int depth = 0;
     plot_legend_clear(plot);
 
-    // add each dimension to the legend
+    // potentially add each dimension to the legend; add axis
+    // dimensions only if crosshairs are active
+
     // display decimal precision relative to display scales
     if(3-p2->x.decimal_exponent > depth) depth = 3-p2->x.decimal_exponent;
     if(3-p2->y.decimal_exponent > depth) depth = 3-p2->y.decimal_exponent;
     for(i=0;i<p->dimensions;i++){
-      snprintf(buffer,320,"%s = %+.*f",
-	       p->dimension_list[i].d->name,
-	       depth,
-	       p->dimension_list[i].d->val);
-      plot_legend_add(plot,buffer);
+      sushiv_dimension_t *d = p->dimension_list[i].d;
+      if( (d!=p2->x_d && d!=p2->y_d) ||
+	  plot->cross_active){
+	snprintf(buffer,320,"%s = %+.*f",
+		 p->dimension_list[i].d->name,
+		 depth,
+		 p->dimension_list[i].d->val);
+	plot_legend_add(plot,buffer);
+      }
     }
     
     // one space 
@@ -1813,7 +1840,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->print_action = sushiv_panel2d_print;
   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-27 22:36:00 UTC (rev 12582)
+++ trunk/sushivision/panel.c	2007-02-27 23:12:52 UTC (rev 12583)
@@ -76,6 +76,7 @@
 
 static void wrap_escape(sushiv_panel_t *p){
   plot_do_escape(PLOT(p->private->graph));
+  _sushiv_panel_dirty_legend(p);
 }
 
 static void wrap_legend(sushiv_panel_t *p){
@@ -105,6 +106,33 @@
 static void checked_bg(sushiv_panel_t *p){
   _sushiv_panel_background_i(p,SUSHIV_BG_CHECKS);
 }
+static void cycle_bg(sushiv_panel_t *p){
+  switch(p->private->bg_type){
+  case 0:
+    black_bg(p);
+    break;
+  case 1:
+    checked_bg(p);
+    break;
+  default:
+    white_bg(p);
+    break;
+  }
+}
+static void cycleB_bg(sushiv_panel_t *p){
+  switch(p->private->bg_type){
+  case 0:
+    checked_bg(p);
+    break;
+  case 1:
+    white_bg(p);
+    break;
+  default:
+    black_bg(p);
+    break;
+  }
+}
+
 static void black_text(sushiv_panel_t *p){
   plot_set_bg_invert(PLOT(p->private->graph),0);
   _sushiv_panel_update_menus(p);
@@ -115,6 +143,17 @@
   _sushiv_panel_update_menus(p);
   refg_if_running(p);
 }
+static void cycle_text(sushiv_panel_t *p){
+  switch(PLOT(p->private->graph)->bg_inv){
+  case 0:
+    white_text(p);
+    break;
+  default:
+    black_text(p);
+    break;
+  }
+}
+
 static void grid_scale(sushiv_panel_t *p){
   plot_set_grid(PLOT(p->private->graph),PLOT_GRID_NORMAL);
   _sushiv_panel_update_menus(p);
@@ -130,6 +169,32 @@
   _sushiv_panel_update_menus(p);
   refg_if_running(p);
 }
+static void cycle_grid(sushiv_panel_t *p){
+  switch(PLOT(p->private->graph)->grid_mode){
+  case PLOT_GRID_NORMAL:
+    tic_scale(p);
+    break;
+  case PLOT_GRID_TICS:
+    no_scale(p);
+    break;
+  default:
+    grid_scale(p);
+    break;
+  }
+}
+static void cycleB_grid(sushiv_panel_t *p){
+  switch(PLOT(p->private->graph)->grid_mode){
+  case PLOT_GRID_NORMAL:
+    no_scale(p);
+    break;
+  case PLOT_GRID_TICS:
+    grid_scale(p);
+    break;
+  default:
+    tic_scale(p);
+    break;
+  }
+}
 
 static void res_set(sushiv_panel_t *p, int n, int d){
   if(n != p->private->oversample_n ||
@@ -142,33 +207,106 @@
 }
 
 static void res_def(sushiv_panel_t *p){
+  p->private->menu_cursamp=0;
   res_set(p,p->private->def_oversample_n,p->private->def_oversample_d);
 }
 static void res_1_32(sushiv_panel_t *p){
+  p->private->menu_cursamp=1;
   res_set(p,1,32);
 }
 static void res_1_16(sushiv_panel_t *p){
+  p->private->menu_cursamp=2;
   res_set(p,1,16);
 }
 static void res_1_8(sushiv_panel_t *p){
+  p->private->menu_cursamp=3;
   res_set(p,1,8);
 }
 static void res_1_4(sushiv_panel_t *p){
+  p->private->menu_cursamp=4;
   res_set(p,1,4);
 }
 static void res_1_2(sushiv_panel_t *p){
+  p->private->menu_cursamp=5;
   res_set(p,1,2);
 }
 static void res_1_1(sushiv_panel_t *p){
+  p->private->menu_cursamp=6;
   res_set(p,1,1);
 }
 static void res_2_1(sushiv_panel_t *p){
+  p->private->menu_cursamp=7;
   res_set(p,2,1);
 }
 static void res_4_1(sushiv_panel_t *p){
+  p->private->menu_cursamp=8;
   res_set(p,4,1);
 }
 
+static void cycle_res(sushiv_panel_t *p){
+  switch(p->private->menu_cursamp){
+  case 0:
+    res_1_32(p);
+    break;
+  case 1:
+    res_1_16(p);
+    break;
+  case 2:
+    res_1_8(p);
+    break;
+  case 3:
+    res_1_4(p);
+    break;
+  case 4:
+    res_1_2(p);
+    break;
+  case 5:
+    res_1_1(p);
+    break;
+  case 6:
+    res_2_1(p);
+    break;
+  case 7:
+    res_4_1(p);
+    break;
+  case 8:
+    res_def(p);
+    break;
+  }
+}
+
+static void cycleB_res(sushiv_panel_t *p){
+  switch(p->private->menu_cursamp){
+  case 2:
+    res_1_32(p);
+    break;
+  case 3:
+    res_1_16(p);
+    break;
+  case 4:
+    res_1_8(p);
+    break;
+  case 5:
+    res_1_4(p);
+    break;
+  case 6:
+    res_1_2(p);
+    break;
+  case 7:
+    res_1_1(p);
+    break;
+  case 8:
+    res_2_1(p);
+    break;
+  case 0:
+    res_4_1(p);
+    break;
+  case 1:
+    res_def(p);
+    break;
+  }
+}
+
 static GtkPrintSettings *printset=NULL;
 static void _begin_print_handler (GtkPrintOperation *op,
 				  GtkPrintContext   *context,
@@ -186,31 +324,12 @@
   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);
   
-  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);
-
-  
-  // XXX render objective scales here
-
+  p->private->print_action(p,c,w,h);
 }
 
 static void _sushiv_panel_print(sushiv_panel_t *p){
@@ -273,35 +392,35 @@
 };
 
 static menuitem *menu_bg[]={
-  &(menuitem){"<span foreground=\"white\">white</span>",NULL,NULL,&white_bg},
-  &(menuitem){"<span foreground=\"black\">black</span>",NULL,NULL,&black_bg},
-  &(menuitem){"checks",NULL,NULL,&checked_bg},
+  &(menuitem){"<span foreground=\"white\">white</span>","[<i>b</i>]",NULL,&white_bg},
+  &(menuitem){"<span foreground=\"black\">black</span>","[<i>b</i>]",NULL,&black_bg},
+  &(menuitem){"checks","[<i>b</i>]",NULL,&checked_bg},
   &(menuitem){NULL,NULL,NULL,NULL}
 };
 
 static menuitem *menu_text[]={
-  &(menuitem){"<span foreground=\"black\">dark</span>",NULL,NULL,&black_text},
-  &(menuitem){"<span foreground=\"white\">light</span>",NULL,NULL,&white_text},
+  &(menuitem){"<span foreground=\"black\">dark</span>","[<i>t</i>]",NULL,&black_text},
+  &(menuitem){"<span foreground=\"white\">light</span>","[<i>t</i>]",NULL,&white_text},
   &(menuitem){NULL,NULL,NULL,NULL}
 };
 
 static menuitem *menu_scales[]={
-  &(menuitem){"full",NULL,NULL,grid_scale},
-  &(menuitem){"tics",NULL,NULL,tic_scale},
-  &(menuitem){"none",NULL,NULL,no_scale},
+  &(menuitem){"full","[<i>g</i>]",NULL,grid_scale},
+  &(menuitem){"tics","[<i>g</i>]",NULL,tic_scale},
+  &(menuitem){"none","[<i>g</i>]",NULL,no_scale},
   &(menuitem){NULL,NULL,NULL,NULL}
 };
 
 static menuitem *menu_res[]={
-  &(menuitem){"default",NULL,NULL,res_def},
-  &(menuitem){"1:32",NULL,NULL,res_1_32},
-  &(menuitem){"1:16",NULL,NULL,res_1_16},
-  &(menuitem){"1:8",NULL,NULL,res_1_8},
-  &(menuitem){"1:4",NULL,NULL,res_1_4},
-  &(menuitem){"1:2",NULL,NULL,res_1_2},
-  &(menuitem){"1",NULL,NULL,res_1_1},
-  &(menuitem){"2:1",NULL,NULL,res_2_1},
-  &(menuitem){"4:1",NULL,NULL,res_4_1},
+  &(menuitem){"default","[<i>m</i>]",NULL,res_def},
+  &(menuitem){"1:32","[<i>m</i>]",NULL,res_1_32},
+  &(menuitem){"1:16","[<i>m</i>]",NULL,res_1_16},
+  &(menuitem){"1:8","[<i>m</i>]",NULL,res_1_8},
+  &(menuitem){"1:4","[<i>m</i>]",NULL,res_1_4},
+  &(menuitem){"1:2","[<i>m</i>]",NULL,res_1_2},
+  &(menuitem){"1","[<i>m</i>]",NULL,res_1_1},
+  &(menuitem){"2:1","[<i>m</i>]",NULL,res_2_1},
+  &(menuitem){"4:1","[<i>m</i>]",NULL,res_4_1},
   &(menuitem){NULL,NULL,NULL,NULL}
 };
 
@@ -412,7 +531,6 @@
   case GDK_Tab:case GDK_KP_Tab:
   case GDK_ISO_Left_Tab:
   case GDK_Delete:case GDK_KP_Delete:
-  case GDK_Return:case GDK_ISO_Enter:
   case GDK_Insert:case GDK_KP_Insert:
     return FALSE;
   }
@@ -422,19 +540,41 @@
     switch(event->keyval){
     case GDK_BackSpace:
     case GDK_e:case GDK_E:
+    case GDK_Return:case GDK_ISO_Enter:
       return FALSE;
     }
   }
         
   /* non-control keypresses */
   switch(event->keyval){
-
+  case GDK_b:
+    cycle_bg(p);
+    return TRUE;
+  case GDK_B:
+    cycleB_bg(p);
+    return TRUE;
+  case GDK_t:case GDK_T:
+    cycle_text(p);
+    return TRUE;
+  case GDK_g:
+    cycle_grid(p);
+    return TRUE;
+  case GDK_G:
+    cycleB_grid(p);
+    return TRUE;
+  case GDK_m:
+    cycle_res(p);
+    return TRUE;
+  case GDK_M:
+    cycleB_res(p);
+    return TRUE;
+    
    case GDK_Escape:
-     plot_do_escape(PLOT(p->private->graph));
+     wrap_escape(p);
     return TRUE;
 
-  case GDK_Return:
-    plot_do_enter(PLOT(p->private->graph));
+  case GDK_Return:case GDK_ISO_Enter:
+    wrap_enter(p);
     return TRUE;
    
   case GDK_Q:

Modified: trunk/sushivision/plot.c
===================================================================
--- trunk/sushivision/plot.c	2007-02-27 22:36:00 UTC (rev 12582)
+++ trunk/sushivision/plot.c	2007-02-27 23:12:52 UTC (rev 12583)
@@ -286,22 +286,26 @@
     x = w - textw - 15;
 
     // draw the enclosing rectangle
-    cairo_rectangle(c,x-6.5,5.5,textw+15,totalh+15);
-    set_shadow(inv,c);
-    cairo_fill_preserve(c);
-    set_text(inv,c);
-    cairo_stroke(c);
+    if(p->legend_active==2){
+      cairo_rectangle(c,x-6.5,5.5,textw+15,totalh+15);
+      set_shadow(inv,c);
+      cairo_fill_preserve(c);
+      set_text(inv,c);
+      cairo_stroke(c);
+    }
 
     for(i=0;i<n;i++){
       cairo_text_extents (c, buffer[i], &extents);
       x = w - extents.width - 15;
-      
-      //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);
 
+      if(p->legend_active==1){
+	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);
+      }
+
       if(colors[i] == 0xffffffffUL){
 	set_text(inv,c);
       }else{
@@ -424,7 +428,7 @@
 	  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){
+int plot_print(Plot *p, cairo_t *c, double page_h, void (*datarender)(void *, cairo_t *), void *data){
   GtkWidget *widget = GTK_WIDGET(p);
   int pw = widget->allocation.width;
   int ph = widget->allocation.height;
@@ -445,7 +449,7 @@
 
   // render the background
   if(datarender)
-    datarender(c,data);
+    datarender(data,c);
 
   // render scales
   draw_scales_work(c,pw,ph,page_h,inv,grid,x,y,xv,yv);
@@ -826,9 +830,10 @@
   
   if(p->box_active){
     
-    if(p->box_callback)
+    if(p->box_callback){
+      p->box_callback(p->cross_data,0);
       p->box_callback(p->cross_data,1);
-    
+    }
     p->button_down=0;
     p->box_active=0;
   }else{
@@ -857,7 +862,9 @@
 }
 
 void plot_toggle_legend(Plot *p){
-  p->legend_active = !p->legend_active;
+  p->legend_active++;
+  if (p->legend_active>2)
+    p->legend_active=0;
   plot_expose_request(p);
 }
 
@@ -871,12 +878,6 @@
   
   /* non-control keypresses */
   switch(event->keyval){
-  case GDK_Escape:
-    plot_do_escape(p);
-    return TRUE;
-  case GDK_Return:
-    plot_do_enter(p);
-    return TRUE;
 
   case GDK_Left:
     {

Modified: trunk/sushivision/plot.h
===================================================================
--- trunk/sushivision/plot.h	2007-02-27 22:36:00 UTC (rev 12582)
+++ trunk/sushivision/plot.h	2007-02-27 23:12:52 UTC (rev 12583)
@@ -97,7 +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);
+int plot_print(Plot *p, cairo_t *c, double page_h, void (*datarender)(void *data,cairo_t *c), 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);



More information about the commits mailing list