[xiph-commits] r12007 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Fri Nov 3 22:18:46 PST 2006


Author: xiphmont
Date: 2006-11-03 22:18:45 -0800 (Fri, 03 Nov 2006)
New Revision: 12007

Modified:
   trunk/sushivision/panel-2d.c
   trunk/sushivision/panel-2d.h
   trunk/sushivision/plot.c
   trunk/sushivision/plot.h
Log:
Add rubberbanding to undo support



Modified: trunk/sushivision/panel-2d.c
===================================================================
--- trunk/sushivision/panel-2d.c	2006-11-04 00:07:23 UTC (rev 12006)
+++ trunk/sushivision/panel-2d.c	2006-11-04 06:18:45 UTC (rev 12007)
@@ -637,22 +637,24 @@
   panel2d_undo_resume(p);
 }
 
-static void box_callback(void *in){
+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;
   Plot *plot = PLOT(p2->graph);
-
+  
   // zoom current dimensions to box
-  double corners[4];
-  plot_box_vals(plot,corners);
-
   panel2d_undo_push(p);
   panel2d_undo_suspend(p);
-
-  slider_set_value(p2->x_scale,0,corners[0]);
-  slider_set_value(p2->x_scale,2,corners[1]);
-  slider_set_value(p2->y_scale,0,corners[2]);
-  slider_set_value(p2->y_scale,2,corners[3]);
+  
+  if(state == 0){
+    plot_box_vals(plot,p2->oldbox);
+    p2->oldbox_active = plot->box_active;
+  }else{ // click, not just create
+    slider_set_value(p2->x_scale,0,p2->oldbox[0]);
+    slider_set_value(p2->x_scale,2,p2->oldbox[1]);
+    slider_set_value(p2->y_scale,0,p2->oldbox[2]);
+    slider_set_value(p2->y_scale,2,p2->oldbox[3]);
+  }
   panel2d_undo_resume(p);
 
 }
@@ -813,7 +815,6 @@
 
 static void panel2d_undo_log(sushiv_panel_t *p){
   sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
-  Plot *plot = PLOT(p2->graph);
   sushiv_panel2d_undo_t *u;
   int i;
 
@@ -849,8 +850,11 @@
   
   u->x_d = p2->x_dnum;
   u->y_d = p2->y_dnum;
-  plot_box_vals(plot,u->box);  
-  u->box_active = plot->box_active;
+  u->box[0] = p2->oldbox[0];
+  u->box[1] = p2->oldbox[1];
+  u->box[2] = p2->oldbox[2];
+  u->box[3] = p2->oldbox[3];
+  u->box_active = p2->oldbox_active;
 }
 
 static void panel2d_undo_restore(sushiv_panel_t *p){

Modified: trunk/sushivision/panel-2d.h
===================================================================
--- trunk/sushivision/panel-2d.h	2006-11-04 00:07:23 UTC (rev 12006)
+++ trunk/sushivision/panel-2d.h	2006-11-04 06:18:45 UTC (rev 12007)
@@ -47,6 +47,8 @@
   scalespace x;
   scalespace y;
   int scales_init;
+  double oldbox[4];
+  int oldbox_active;
 
   mapping *mappings;
   Slider    **range_scales;

Modified: trunk/sushivision/plot.c
===================================================================
--- trunk/sushivision/plot.c	2006-11-04 00:07:23 UTC (rev 12006)
+++ trunk/sushivision/plot.c	2006-11-04 06:18:45 UTC (rev 12007)
@@ -373,6 +373,24 @@
 
 }
 
+static void box_check(Plot *p, int x, int y){
+  if(p->box_active){
+    double vals[4];
+    box_corners(p,vals);
+    
+    if(inside_box(p,x,y) && !p->button_down)
+      p->box_active = 2;
+    else
+      p->box_active = 1;
+    
+    plot_expose_request_partial(p,
+				(int)(vals[0]),
+				(int)(vals[1]),
+				(int)(vals[2]+2),
+				(int)(vals[3]+2));
+  }
+}
+
 static gint mouse_motion(GtkWidget        *widget,
 			 GdkEventMotion   *event){
   Plot *p = PLOT (widget);
@@ -400,23 +418,9 @@
     p->box_x2 = scalespace_value(&p->x,x);
     p->box_y2 = scalespace_value(&p->y,y);
   }
-  
-  if(p->box_active){
-    double vals[4];
-    box_corners(p,vals);
-    
-    if(inside_box(p,x,y) && !p->button_down)
-      p->box_active = 2;
-    else
-      p->box_active = 1;
-    
-    plot_expose_request_partial(p,
-				(int)(vals[0]),
-				(int)(vals[1]),
-				(int)(vals[2]+2),
-				(int)(vals[3]+2));
-  }
 
+  box_check(p,x,y);
+
   return TRUE;
 }
 
@@ -427,7 +431,7 @@
   if(p->box_active && inside_box(p,event->x,event->y)){
 
     if(p->box_callback)
-      p->box_callback(p->cross_data);
+      p->box_callback(p->cross_data,1);
 
     p->button_down=0;
     p->box_active=0;
@@ -456,6 +460,14 @@
   }
 
   p->button_down=0;
+  box_check(p,event->x, event->y);
+
+  if(p->box_active){
+    if(p->box_callback)
+      p->box_callback(p->cross_data,0);
+  }  
+  
+
   return TRUE;
 }
 
@@ -525,7 +537,7 @@
 
 Plot *plot_new (void (*callback)(void *),void *app_data,
 		void (*cross_callback)(void *),void *cross_data,
-		void (*box_callback)(void *),void *box_data) {
+		void (*box_callback)(void *, int),void *box_data) {
   GtkWidget *g = GTK_WIDGET (g_object_new (PLOT_TYPE, NULL));
   Plot *p = PLOT (g);
   p->recompute_callback = callback;
@@ -651,7 +663,7 @@
   p->box_y1=vals[2];
   p->box_y2=vals[3];
   p->box_active = 1;
-
+  
   plot_expose_request(p);
   gdk_threads_leave();
 }

Modified: trunk/sushivision/plot.h
===================================================================
--- trunk/sushivision/plot.h	2006-11-04 00:07:23 UTC (rev 12006)
+++ trunk/sushivision/plot.h	2006-11-04 06:18:45 UTC (rev 12007)
@@ -60,7 +60,7 @@
   double box_y2;
   int box_active;
   void *box_data;
-  void (*box_callback)(void *);
+  void (*box_callback)(void *,int);
   int button_down;
   
   u_int32_t *datarect;
@@ -79,7 +79,7 @@
 GType     plot_get_type        (void);
 Plot     *plot_new (void (*callback)(void *),void *app_data,
 		    void (*cross_callback)(void *),void *cross_data,
-		    void (*box_callback)(void *),void *box_data);
+		    void (*box_callback)(void *,int),void *box_data);
 
 G_END_DECLS
 



More information about the commits mailing list