[xiph-commits] r11986 - trunk/sushivision
xiphmont at svn.xiph.org
xiphmont at svn.xiph.org
Wed Nov 1 14:36:10 PST 2006
Author: xiphmont
Date: 2006-11-01 14:36:07 -0800 (Wed, 01 Nov 2006)
New Revision: 11986
Modified:
trunk/sushivision/plot.c
trunk/sushivision/plot.h
Log:
Add rubber-banding selection to 2d panel
Modified: trunk/sushivision/plot.c
===================================================================
--- trunk/sushivision/plot.c 2006-11-01 14:40:26 UTC (rev 11985)
+++ trunk/sushivision/plot.c 2006-11-01 22:36:07 UTC (rev 11986)
@@ -190,6 +190,15 @@
}
+static int inside_box(Plot *p, int x, int y){
+ int bx = (p->boxA_x<p->boxB_x ? p->boxA_x : p->boxB_x)+.5;
+ int by = (p->boxA_y<p->boxB_y ? p->boxA_y : p->boxB_y)+.5;
+ int bw = abs(p->boxA_x-p->boxB_x);
+ int bh = abs(p->boxA_y-p->boxB_y);
+
+ return (x >= bx && x <= bx+bw && y >= by && y <= by+bh);
+}
+
static void plot_draw (Plot *p,
int x, int y, int w, int h){
@@ -207,7 +216,7 @@
cairo_fill(c);
// transient foreground
- cairo_set_source_rgba(c,1.,1.,1.,.6);
+ cairo_set_source_rgba(c,1.,1.,1.,.8);
cairo_set_line_width(c,1.);
cairo_move_to(c,0,p->sely+.5);
cairo_line_to(c,widget->allocation.width,p->sely+.5);
@@ -215,6 +224,26 @@
cairo_line_to(c,p->selx+.5,widget->allocation.height);
cairo_stroke(c);
+ if(p->box_active){
+ int bx = (p->boxA_x<p->boxB_x ? p->boxA_x : p->boxB_x);
+ int by = (p->boxA_y<p->boxB_y ? p->boxA_y : p->boxB_y);
+ int bw = abs(p->boxA_x-p->boxB_x)+1;
+ int bh = abs(p->boxA_y-p->boxB_y)+1;
+
+ cairo_rectangle(c,bx,by,bw,bh);
+ if(p->box_active>1)
+ cairo_set_source_rgba(c,1.,1.,.6,.4);
+ else
+ cairo_set_source_rgba(c,1.,1.,1.,.3);
+ cairo_fill(c);
+ cairo_rectangle(c,bx+.5,by+.5,bw-1,bh-1);
+ if(p->box_active>1)
+ cairo_set_source_rgba(c,1.,1.,.6,.9);
+ else
+ cairo_set_source_rgba(c,1.,1.,1.,.8);
+ cairo_stroke(c);
+ }
+
cairo_destroy(c);
// blit to window
@@ -330,16 +359,63 @@
static gint mouse_motion(GtkWidget *widget,
GdkEventMotion *event){
- //Plot *p = PLOT (widget);
+ Plot *p = PLOT (widget);
+ int x = event->x;
+ int y = event->y;
+
+ if(p->button_down){
+ if(abs(p->boxA_x - x)>5 ||
+ abs(p->boxA_y - y)>5)
+ p->box_active = 1;
+
+
+ if(p->box_active){
+ int bx = (p->boxA_x<p->boxB_x ? p->boxA_x : p->boxB_x);
+ int by = (p->boxA_y<p->boxB_y ? p->boxA_y : p->boxB_y);
+ int bw = abs(p->boxA_x-p->boxB_x)+1;
+ int bh = abs(p->boxA_y-p->boxB_y)+1;
+ plot_expose_request_partial(p,bx,by,bw,bh);
+ }
+
+ p->boxB_x = x;
+ p->boxB_y = y;
+ }
+
+ if(inside_box(p,x,y))
+ p->box_active = 2;
+ else
+ p->box_active = 1;
+
+ if(p->box_active){
+ int bx = (p->boxA_x<p->boxB_x ? p->boxA_x : p->boxB_x);
+ int by = (p->boxA_y<p->boxB_y ? p->boxA_y : p->boxB_y);
+ int bw = abs(p->boxA_x-p->boxB_x)+1;
+ int bh = abs(p->boxA_y-p->boxB_y)+1;
+ plot_expose_request_partial(p,bx,by,bw,bh);
+ }
+
return TRUE;
}
static gboolean mouse_press (GtkWidget *widget,
GdkEventButton *event){
- //Plot *p = PLOT (widget);
+ Plot *p = PLOT (widget);
+ if(p->box_active && inside_box(p,event->x,event->y)){
+ if(p->box_callback)
+ p->box_callback(p->cross_data);
+
+ p->button_down=0;
+ p->box_active=0;
+
+ }else{
+ p->boxA_x = event->x;
+ p->boxA_y = event->y;
+ p->box_active = 0;
+ p->button_down=1;
+ }
return TRUE;
}
@@ -347,15 +423,19 @@
GdkEventButton *event){
Plot *p = PLOT (widget);
plot_expose_request(p);
- p->selx = event->x;
- p->sely = event->y;
- p->selx_val = scalespace_value(&p->x,p->selx);
- p->sely_val = scalespace_value(&p->y,widget->allocation.height-p->sely);
- if(p->crosshairs_callback)
- p->crosshairs_callback(p->cross_data);
- plot_expose_request(p);
+ if(!p->box_active){
+ p->selx = event->x;
+ p->sely = event->y;
+ p->selx_val = scalespace_value(&p->x,p->selx);
+ p->sely_val = scalespace_value(&p->y,widget->allocation.height-p->sely);
+ if(p->crosshairs_callback)
+ p->crosshairs_callback(p->cross_data);
+ plot_expose_request(p);
+ }
+
+ p->button_down=0;
return TRUE;
}
@@ -449,6 +529,21 @@
gdk_threads_leave();
}
+void plot_expose_request_partial(Plot *p,int x, int y, int w, int h){
+ gdk_threads_enter();
+
+ GtkWidget *widget = GTK_WIDGET(p);
+ GdkRectangle r;
+
+ r.x=x;
+ r.y=y;
+ r.width=w;
+ r.height=h;
+
+ gdk_window_invalidate_rect (widget->window, &r, FALSE);
+ gdk_threads_leave();
+}
+
void plot_expose_request_line(Plot *p, int num){
gdk_threads_enter();
GtkWidget *widget = GTK_WIDGET(p);
Modified: trunk/sushivision/plot.h
===================================================================
--- trunk/sushivision/plot.h 2006-11-01 14:40:26 UTC (rev 11985)
+++ trunk/sushivision/plot.h 2006-11-01 22:36:07 UTC (rev 11986)
@@ -56,6 +56,15 @@
double selx;
double sely;
+ double boxA_x;
+ double boxA_y;
+ double boxB_x;
+ double boxB_y;
+ int box_active;
+ void *box_data;
+ void (*box_callback)(void *);
+ int button_down;
+
u_int32_t *datarect;
void *app_data;
void (*recompute_callback)(void *);
@@ -78,6 +87,7 @@
// the widget subclass half
void plot_expose_request(Plot *p);
void plot_expose_request_line(Plot *p, int num);
+void plot_expose_request_partial(Plot *p,int x, int y, int w, int h);
void plot_set_x_scale(Plot *p, scalespace x);
void plot_set_y_scale(Plot *p, scalespace y);
void plot_set_x_name(Plot *p, char *name);
More information about the commits
mailing list