[xiph-commits] r12234 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Sun Dec 24 11:37:52 PST 2006


Author: xiphmont
Date: 2006-12-24 11:37:49 -0800 (Sun, 24 Dec 2006)
New Revision: 12234

Modified:
   trunk/sushivision/internal.h
   trunk/sushivision/panel-2d.c
   trunk/sushivision/panel-2d.h
   trunk/sushivision/panel.c
   trunk/sushivision/sushivision.h
Log:
More API futureproofing toward 1d panels



Modified: trunk/sushivision/internal.h
===================================================================
--- trunk/sushivision/internal.h	2006-12-23 16:26:15 UTC (rev 12233)
+++ trunk/sushivision/internal.h	2006-12-24 19:37:49 UTC (rev 12234)
@@ -20,6 +20,29 @@
  */
 
 #include <signal.h>
+#include "sushivision.h"
+#include "panel-2d.h"
+
+union sushiv_panel_subtype {
+  //sushiv_panel1d_t *p1;
+  sushiv_panel2d_t *p2;
+};
+
+struct sushiv_panel_internal {
+  int realized;
+  int maps_dirty;
+  int legend_dirty;
+
+  // function bundles 
+  void (*realize)(sushiv_panel_t *p);
+  void (*map_redraw)(sushiv_panel_t *p);
+  void (*legend_redraw)(sushiv_panel_t *p);
+  int (*compute_action)(sushiv_panel_t *p);
+  void (*request_compute)(sushiv_panel_t *p);
+
+  void (*crosshair_action)(sushiv_panel_t *p);
+};
+
 extern void _sushiv_realize_panel(sushiv_panel_t *p);
 extern void _sushiv_clean_exit(int sig);
 extern int _sushiv_new_panel(sushiv_instance_t *s,

Modified: trunk/sushivision/panel-2d.c
===================================================================
--- trunk/sushivision/panel-2d.c	2006-12-23 16:26:15 UTC (rev 12233)
+++ trunk/sushivision/panel-2d.c	2006-12-24 19:37:49 UTC (rev 12234)
@@ -36,7 +36,6 @@
 #include "plot.h"
 #include "slice.h"
 #include "slider.h"
-#include "panel-2d.h"
 #include "internal.h"
 #include "gtksucks.h"
 
@@ -61,7 +60,7 @@
 }
 
 static void _sushiv_panel2d_remap(sushiv_panel_t *p){
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   Plot *plot = PLOT(p2->graph);
 
   int w,h,x,y,i;
@@ -98,8 +97,8 @@
   }
 }
 
-void _sushiv_panel2d_map_redraw(sushiv_panel_t *p){
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+static void _sushiv_panel2d_map_redraw(sushiv_panel_t *p){
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   Plot *plot = PLOT(p2->graph);
 
   gdk_threads_enter (); // misuse me as a global mutex
@@ -111,8 +110,8 @@
   gdk_threads_leave (); // misuse me as a global mutex
 }
 
-void _sushiv_panel2d_legend_redraw(sushiv_panel_t *p){
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+static void _sushiv_panel2d_legend_redraw(sushiv_panel_t *p){
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   Plot *plot = PLOT(p2->graph);
 
   if(plot)
@@ -130,7 +129,7 @@
 }
 
 static void update_legend(sushiv_panel_t *p){  
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;  
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   Plot *plot = PLOT(p2->graph);
 
   gdk_threads_enter ();
@@ -193,7 +192,7 @@
   sushiv_objective_list_t *optr = (sushiv_objective_list_t *)in;
   //sushiv_objective_t *o = optr->o;
   sushiv_panel_t *p = optr->p;
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   int onum = optr - p->objective_list;
 
   panel2d_undo_push(p);
@@ -217,7 +216,7 @@
   sushiv_objective_list_t *optr = (sushiv_objective_list_t *)in;
   //sushiv_objective_t *o = optr->o;
   sushiv_panel_t *p = optr->p;
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   int onum = optr - p->objective_list;
 
   if(buttonstate == 0){
@@ -237,7 +236,7 @@
 }
 
 static void update_xy_availability(sushiv_panel_t *p){
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   int i;
   // update which x/y buttons are pressable */
   // enable/disable dimension slider thumbs
@@ -309,7 +308,7 @@
 				int w, 
 				double *dim_vals, 
 				u_int32_t *render){
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   double work[w];
   double inv_w = 1./w;
   int i,j;
@@ -542,8 +541,8 @@
 }
 
 // call only from main gtk thread!
-void _mark_recompute_2d(sushiv_panel_t *p){
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+static void _mark_recompute_2d(sushiv_panel_t *p){
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   Plot *plot = PLOT(p2->graph);
   int w = plot->w.allocation.width;
   int h = plot->w.allocation.height;
@@ -612,14 +611,13 @@
 }
 
 static void update_crosshairs(sushiv_panel_t *p){
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   Plot *plot = PLOT(p2->graph);
   double x=0,y=0;
   int i;
   
   for(i=0;i<p->dimensions;i++){
     sushiv_dimension_t *d = p->dimension_list[i].d;
-    sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
     if(d == p2->x_d)
       x = slider_get_value(p2->dim_scales[i],1);
     if(d == p2->y_d)
@@ -633,7 +631,6 @@
   // should be accurate with respect to the crosshairs
   for(i=0;i<p->dimensions;i++){
     sushiv_dimension_t *d = p->dimension_list[i].d;
-    sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
     if(d == p2->x_d)
       d->val = scalespace_value(&plot->x,plot_get_crosshair_xpixel(plot));
     if(d == p2->y_d)
@@ -649,7 +646,7 @@
   sushiv_dimension_list_t *dptr = (sushiv_dimension_list_t *)in;
   sushiv_dimension_t *d = dptr->d;
   sushiv_panel_t *p = dptr->p;
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   //Plot *plot = PLOT(p2->graph);
   int dnum = dptr - p->dimension_list;
   int axisp = (d == p2->x_d || d == p2->y_d);
@@ -677,7 +674,7 @@
   sushiv_dimension_list_t *dptr = (sushiv_dimension_list_t *)in;
   sushiv_dimension_t *d = dptr->d;
   sushiv_panel_t *p = dptr->p;
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   int dnum = dptr - p->dimension_list;
   double lo = slider_get_value(p2->dim_scales[dnum],0);
   double hi = slider_get_value(p2->dim_scales[dnum],2);
@@ -715,7 +712,7 @@
 
 static void dimchange_callback_2d(GtkWidget *button,gpointer in){
   sushiv_panel_t *p = (sushiv_panel_t *)in;
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  sushiv_panel2d_t *p2 = p->subtype->p2;
 
   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))){
 
@@ -731,9 +728,8 @@
   }
 }
 
-void _sushiv_panel2d_crosshairs_callback(void *in){
-  sushiv_panel_t *p = (sushiv_panel_t *)in;
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+static void _sushiv_panel2d_crosshairs_callback(sushiv_panel_t *p){
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   double x=PLOT(p2->graph)->selx;
   double y=PLOT(p2->graph)->sely;
   int i;
@@ -743,7 +739,6 @@
 
   for(i=0;i<p->dimensions;i++){
     sushiv_dimension_t *d = p->dimension_list[i].d;
-    sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
     if(d == p2->x_d){
       slider_set_value(p2->dim_scales[i],1,x);
 
@@ -767,7 +762,7 @@
 
 static void box_callback(void *in, int state){
   sushiv_panel_t *p = (sushiv_panel_t *)in;
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   Plot *plot = PLOT(p2->graph);
   
   switch(state){
@@ -796,8 +791,8 @@
 // called from one/all of the worker threads; the idea is that several
 // of the threads will all call this and they collectively interleave
 // ongoing computation of the pane
-int _sushiv_panel_cooperative_compute_2d(sushiv_panel_t *p){
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+static int _sushiv_panel_cooperative_compute_2d(sushiv_panel_t *p){
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   Plot *plot;
   
   int w,h,i,d;
@@ -941,12 +936,12 @@
 }
 
 static void panel2d_undo_suspend(sushiv_panel_t *p){
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   p2->undo_suspend++;
 }
 
 static void panel2d_undo_resume(sushiv_panel_t *p){
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   p2->undo_suspend--;
   if(p2->undo_suspend<0){
     fprintf(stderr,"Internal error: undo suspend refcount count < 0\n");
@@ -958,7 +953,7 @@
 }
 
 static void panel2d_undo_log(sushiv_panel_t *p){
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   sushiv_panel2d_undo_t *u;
   int i;
 
@@ -1002,7 +997,7 @@
 }
 
 static void panel2d_undo_restore(sushiv_panel_t *p){
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   sushiv_panel2d_undo_t *u = p2->undo_stack[p2->undo_level];
   Plot *plot = PLOT(p2->graph);
   int i;
@@ -1067,7 +1062,7 @@
 }
 
 static void panel2d_undo_push(sushiv_panel_t *p){
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   sushiv_panel2d_undo_t *u;
   int i;
   
@@ -1103,7 +1098,7 @@
 }
 
 static void panel2d_undo_up(sushiv_panel_t *p){
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   
   if(!p2->undo_stack)return;
   if(!p2->undo_stack[p2->undo_level])return;
@@ -1117,7 +1112,7 @@
 }
 
 static void panel2d_undo_down(sushiv_panel_t *p){
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  sushiv_panel2d_t *p2 = p->subtype->p2;
 
   if(!p2->undo_stack)return;
   if(!p2->undo_level)return;
@@ -1133,7 +1128,7 @@
 
 // called with lock
 static void panel2d_find_peak(sushiv_panel_t *p){
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   Plot *plot = PLOT(p2->graph);
   int i,j;
   int w = p2->data_w;
@@ -1231,7 +1226,7 @@
 }
 
 static void update_context_menus(sushiv_panel_t *p){
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  sushiv_panel2d_t *p2 = p->subtype->p2;
 
   // is undo active?
   if(!p2->undo_stack ||
@@ -1263,7 +1258,7 @@
 
 }
 
-void wrap_exit(sushiv_panel_t *dummy){
+static void wrap_exit(sushiv_panel_t *dummy){
   _sushiv_clean_exit(SIGINT);
 }
 
@@ -1291,13 +1286,13 @@
   NULL,
 };
 
-void wrap_enter(sushiv_panel_t *p){
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+static void wrap_enter(sushiv_panel_t *p){
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   plot_do_enter(PLOT(p2->graph));
 }
 
-void wrap_escape(sushiv_panel_t *p){
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+static void wrap_escape(sushiv_panel_t *p){
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   plot_do_escape(PLOT(p2->graph));
 }
 
@@ -1339,8 +1334,8 @@
 };
 
 
-void _sushiv_realize_panel2d(sushiv_panel_t *p){
-  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+static void _sushiv_realize_panel2d(sushiv_panel_t *p){
+  sushiv_panel2d_t *p2 = p->subtype->p2;
   int i;
 
   panel2d_undo_suspend(p);
@@ -1359,7 +1354,7 @@
   
   /* graph */
   p2->graph = GTK_WIDGET(plot_new(recompute_callback_2d,p,
-				  _sushiv_panel2d_crosshairs_callback,p,
+				  (void *)(void *)_sushiv_panel2d_crosshairs_callback,p,
 				  box_callback,p)); 
   gtk_table_attach(GTK_TABLE(p2->top_table),p2->graph,0,5,0,1,
 		   GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,0,5);
@@ -1529,7 +1524,12 @@
   if(ret<0)return ret;
   p = s->panel_list[number];
   p2 = calloc(1, sizeof(*p2));
-  p->internal = p2;
+  p->subtype = 
+    calloc(1, sizeof(*p->subtype)); /* the union is alloced not
+				     embedded as its internal
+				     structure must be hidden */
+  
+  p->subtype->p2 = p2;
   p->type = SUSHIV_PANEL_2D;
 
   // verify all the objectives have scales
@@ -1540,6 +1540,13 @@
     }
   }
 
+  p->private->realize = _sushiv_realize_panel2d;
+  p->private->map_redraw = _sushiv_panel2d_map_redraw;
+  p->private->legend_redraw = _sushiv_panel2d_legend_redraw;
+  p->private->compute_action = _sushiv_panel_cooperative_compute_2d;
+  p->private->request_compute = _mark_recompute_2d;
+  p->private->crosshair_action = _sushiv_panel2d_crosshairs_callback;
+
   return 0;
 }
 

Modified: trunk/sushivision/panel-2d.h
===================================================================
--- trunk/sushivision/panel-2d.h	2006-12-23 16:26:15 UTC (rev 12233)
+++ trunk/sushivision/panel-2d.h	2006-12-24 19:37:49 UTC (rev 12234)
@@ -71,14 +71,11 @@
   int last_line;
   int dirty_flag;
 
-  sushiv_panel2d_undo_t **undo_stack;
+  int peak_count;
+
   int undo_level;
   int undo_suspend;
+  sushiv_panel2d_undo_t **undo_stack;
 
-  int peak_count;
 } sushiv_panel2d_t;
 
-extern void _sushiv_realize_panel2d(sushiv_panel_t *p);
-extern int _sushiv_panel_cooperative_compute_2d(sushiv_panel_t *p);
-extern void _sushiv_panel2d_map_redraw(sushiv_panel_t *p);
-extern void _sushiv_panel2d_legend_redraw(sushiv_panel_t *p);

Modified: trunk/sushivision/panel.c
===================================================================
--- trunk/sushivision/panel.c	2006-12-23 16:26:15 UTC (rev 12233)
+++ trunk/sushivision/panel.c	2006-12-24 19:37:49 UTC (rev 12234)
@@ -35,56 +35,18 @@
 #include "plot.h"
 #include "slice.h"
 #include "slider.h"
-#include "panel-2d.h"
 #include "internal.h"
 
 void _sushiv_realize_panel(sushiv_panel_t *p){
-  if(!p->realized){
-    switch(p->type){
-    case SUSHIV_PANEL_1D:
-      //_sushiv_realize_panel1d(p);
-      break;
-    case SUSHIV_PANEL_2D:
-      _sushiv_realize_panel2d(p);
-      break;
-    }
-    p->realized=1;
+  if(!p->private->realized){
+    p->private->realize(p);
+    p->private->realized=1;
   }
 }
 
-static void _sushiv_panel_map_redraw(sushiv_panel_t *p){
-  if(p->maps_dirty){
-    p->maps_dirty = 0;
-    switch(p->type){
-    case SUSHIV_PANEL_1D:
-      //_sushiv_panel1d_map_redraw(p);
-      break;
-    case SUSHIV_PANEL_2D:
-      _sushiv_panel2d_map_redraw(p);
-      break;
-    }
-  }
-}
-
-static void _sushiv_panel_legend_redraw(sushiv_panel_t *p){
-  if(p->legend_dirty){
-    p->legend_dirty = 0;
-    switch(p->type){
-    case SUSHIV_PANEL_1D:
-      //_sushiv_panel1d_legend_redraw(p);
-      break;
-    case SUSHIV_PANEL_2D:
-      _sushiv_panel2d_legend_redraw(p);
-      break;
-    }
-  }
-}
-
 int _sushiv_panel_cooperative_compute(sushiv_panel_t *p){
-  if(p->realized){
-    if(p->type == SUSHIV_PANEL_2D)
-      return _sushiv_panel_cooperative_compute_2d(p);
-  }
+  if(p->private->realized)
+    return p->private->compute_action(p);
   return 0;
 }
 
@@ -94,9 +56,13 @@
   sushiv_instance_t *s = (sushiv_instance_t *)ptr;
   int i;
   
-  for(i=0;i<s->panels;i++)
-    _sushiv_panel_map_redraw(s->panel_list[i]);
-  
+  for(i=0;i<s->panels;i++){
+    sushiv_panel_t *p = s->panel_list[i];
+    if(p->private->maps_dirty){
+      p->private->maps_dirty = 0;
+      p->private->map_redraw(p);
+    }
+  }  
   return FALSE;
 }
 
@@ -104,20 +70,24 @@
   sushiv_instance_t *s = (sushiv_instance_t *)ptr;
   int i;
   
-  for(i=0;i<s->panels;i++)
-    _sushiv_panel_legend_redraw(s->panel_list[i]);
-  
+  for(i=0;i<s->panels;i++){
+    sushiv_panel_t *p = s->panel_list[i];
+    if(p->private->legend_dirty){
+      p->private->legend_dirty = 0;
+      p->private->legend_redraw(p);
+    }
+  }
   return FALSE;
 }
 
 
 void _sushiv_panel_dirty_map(sushiv_panel_t *p){
-  p->maps_dirty = 1;
+  p->private->maps_dirty = 1;
   g_idle_add(_map_idle_work,p->sushi);
 }
 
 void _sushiv_panel_dirty_legend(sushiv_panel_t *p){
-  p->legend_dirty = 1;
+  p->private->legend_dirty = 1;
   g_idle_add(_legend_idle_work,p->sushi);
 }
 
@@ -157,7 +127,8 @@
   p->name = strdup(name);
   p->flags = flags;
   p->sushi = s;
-  
+  p->private = calloc(1, sizeof(*p->private));
+
   i=0;
   while(objectives && objectives[i]>=0)i++;
   p->objectives = i;

Modified: trunk/sushivision/sushivision.h
===================================================================
--- trunk/sushivision/sushivision.h	2006-12-23 16:26:15 UTC (rev 12233)
+++ trunk/sushivision/sushivision.h	2006-12-24 19:37:49 UTC (rev 12234)
@@ -27,6 +27,8 @@
 typedef struct sushiv_dimension sushiv_dimension_t;
 typedef struct sushiv_objective sushiv_objective_t;
 
+typedef struct sushiv_instance_internal sushiv_instance_internal_t;
+
 typedef struct sushiv_instance {
   int dimensions;
   sushiv_dimension_t **dimension_list;
@@ -37,7 +39,7 @@
   int panels;
   struct sushiv_panel **panel_list;
 
-  void *internal;
+  sushiv_instance_internal_t *private;
 } sushiv_instance_t;
 
 #define SUSHIV_NO_X 0x100
@@ -49,6 +51,8 @@
   char **label_list; 
 };
 
+typedef struct sushiv_panel_internal sushiv_panel_internal_t;
+
 struct sushiv_dimension{ 
   int number;
   char *name;
@@ -60,9 +64,11 @@
   
   int (*callback)(sushiv_dimension_t *);
   sushiv_instance_t *sushi;
-  void *internal;
+  sushiv_panel_internal_t *private;
 };
 
+typedef struct sushiv_objective_internal sushiv_objective_internal_t;
+
 struct sushiv_objective { 
   int number;
   char *name;
@@ -72,10 +78,11 @@
 
   double (*callback)(double[]);
   sushiv_instance_t *sushi;
-  void *internal;
+  sushiv_objective_internal_t *private;
 };
 
-enum sushiv_panel_type { SUSHIV_PANEL_1D, SUSHIV_PANEL_2D };
+enum sushiv_panel_type { SUSHIV_PANEL_1D, SUSHIV_PANEL_2D, SUSHIV_PANEL_XY };
+typedef union sushiv_panel_subtype sushiv_panel_subtype_t;
 
 typedef struct {
   sushiv_dimension_t *d;
@@ -91,9 +98,6 @@
   int number;
   char *name;
   enum sushiv_panel_type type;
-  int realized;
-  int maps_dirty;
-  int legend_dirty;
 
   int dimensions;
   sushiv_dimension_list_t *dimension_list;
@@ -101,8 +105,10 @@
   sushiv_objective_list_t *objective_list;
 
   sushiv_instance_t *sushi;
-  void *internal;
   unsigned flags;
+
+  sushiv_panel_subtype_t *subtype;
+  sushiv_panel_internal_t *private;
 };
 
 extern sushiv_instance_t *sushiv_new_instance(void);



More information about the commits mailing list