[xiph-commits] r12046 - trunk/sushivision
xiphmont at svn.xiph.org
xiphmont at svn.xiph.org
Mon Nov 6 14:06:18 PST 2006
Author: xiphmont
Date: 2006-11-06 14:06:17 -0800 (Mon, 06 Nov 2006)
New Revision: 12046
Modified:
trunk/sushivision/plot.c
Log:
Add more keypress bindings; Enter mimics an on/off mouse button, arrow
key and shift-arrow for manual selection, escape for unbox.
Correct a Y polarity bug in rubberbanding
Modified: trunk/sushivision/plot.c
===================================================================
--- trunk/sushivision/plot.c 2006-11-06 21:32:02 UTC (rev 12045)
+++ trunk/sushivision/plot.c 2006-11-06 22:06:17 UTC (rev 12046)
@@ -192,10 +192,13 @@
}
static void box_corners(Plot *p, double vals[4]){
+ GtkWidget *widget = GTK_WIDGET(p);
double x1 = scalespace_pixel(&p->x,p->box_x1);
double x2 = scalespace_pixel(&p->x,p->box_x2);
- double y1 = scalespace_pixel(&p->y,p->box_y1);
- double y2 = scalespace_pixel(&p->y,p->box_y2);
+ double y1 = widget->allocation.height-
+ scalespace_pixel(&p->y,p->box_y1);
+ double y2 = widget->allocation.height-
+ scalespace_pixel(&p->y,p->box_y2);
vals[0] = (x1<x2 ? x1 : x2);
vals[1] = (y1<y2 ? y1 : y2);
@@ -309,62 +312,6 @@
requisition->height = 200; // XXX
}
-static gboolean key_press(GtkWidget *widget,
- GdkEventKey *event){
- Plot *p = PLOT(widget);
-
- int shift = (event->state&GDK_SHIFT_MASK);
- if(event->state&GDK_MOD1_MASK) return FALSE;
- if(event->state&GDK_CONTROL_MASK)return FALSE;
-
- /* non-control keypresses */
- switch(event->keyval){
-
- case GDK_Return:
- // if box is active, effect it
- if(p->box_active){
-
- if(p->box_callback)
- p->box_callback(p->cross_data,1);
-
- p->button_down=0;
- p->box_active=0;
- }
- return TRUE;
-
- case GDK_Left:
- {
- double x = scalespace_pixel(&p->x,p->selx)-1;
- if(shift)
- x-=9;
- p->selx = scalespace_value(&p->x,x);
- if(p->crosshairs_callback)
- p->crosshairs_callback(p->cross_data);
- plot_expose_request(p);
- }
- return TRUE;
-
- case GDK_Right:
- {
- double x = scalespace_pixel(&p->x,p->selx)+1;
- if(shift)
- x+=9;
- p->selx = scalespace_value(&p->x,x);
- if(p->crosshairs_callback)
- p->crosshairs_callback(p->cross_data);
- plot_expose_request(p);
-
- }
- return TRUE;
- case GDK_Up:
- case GDK_Down:
- break;
- }
-
-
- return FALSE;
-}
-
static void plot_realize (GtkWidget *widget){
GdkWindowAttr attributes;
gint attributes_mask;
@@ -491,7 +438,7 @@
}
p->box_x2 = scalespace_value(&p->x,x);
- p->box_y2 = scalespace_value(&p->y,y);
+ p->box_y2 = scalespace_value(&p->y,widget->allocation.height-y);
}
box_check(p,x,y);
@@ -503,7 +450,7 @@
GdkEventButton *event){
Plot *p = PLOT (widget);
- if(p->box_active && inside_box(p,event->x,event->y)){
+ if(p->box_active && inside_box(p,event->x,event->y) && !p->button_down){
if(p->box_callback)
p->box_callback(p->cross_data,1);
@@ -512,8 +459,8 @@
p->box_active=0;
}else{
- p->box_x1 = scalespace_value(&p->x,event->x);
- p->box_y1 = scalespace_value(&p->y,event->y);
+ p->box_x2=p->box_x1 = scalespace_value(&p->x,event->x);
+ p->box_y2=p->box_y1 = scalespace_value(&p->y,widget->allocation.height-event->y);
p->box_active = 0;
p->button_down=1;
}
@@ -547,18 +494,122 @@
return TRUE;
}
-static gboolean plot_enter (GtkWidget *widget,
- GdkEventCrossing *event){
- //Plot *p = PLOT (widget);
+static gboolean key_press(GtkWidget *widget,
+ GdkEventKey *event){
+ Plot *p = PLOT(widget);
- return TRUE;
-}
+ int shift = (event->state&GDK_SHIFT_MASK);
+ if(event->state&GDK_MOD1_MASK) return FALSE;
+ if(event->state&GDK_CONTROL_MASK)return FALSE;
+
+ /* non-control keypresses */
+ switch(event->keyval){
+ case GDK_Escape:
+ p->button_down=0;
+ p->box_active=0;
+ plot_expose_request(p);
-static gboolean plot_leave (GtkWidget *widget,
- GdkEventCrossing *event){
- //Plot *p = PLOT (widget);
+ return TRUE;
+ case GDK_Return:
+ // if box is active, effect it
+ if(p->box_active){
+
+ if(p->box_callback)
+ p->box_callback(p->cross_data,1);
+
+ p->button_down=0;
+ p->box_active=0;
+ }else{
+ GdkEventButton event;
+ event.x = scalespace_pixel(&p->x,p->selx);
+ event.y = widget->allocation.height-
+ scalespace_pixel(&p->y,p->sely);
+ if(p->button_down)
+ mouse_release(widget,&event);
+ else
+ mouse_press(widget,&event);
+ }
+ return TRUE;
- return TRUE;
+ case GDK_Left:
+ {
+ double x = scalespace_pixel(&p->x,p->selx)-1;
+ if(shift)
+ x-=9;
+ p->selx = scalespace_value(&p->x,x);
+ if(p->crosshairs_callback)
+ p->crosshairs_callback(p->cross_data);
+
+ if(p->button_down){
+ p->box_active=1;
+ p->box_x2 = p->selx;
+ }else
+ p->box_active=0;
+
+ plot_expose_request(p);
+ }
+ return TRUE;
+
+ case GDK_Right:
+ {
+ double x = scalespace_pixel(&p->x,p->selx)+1;
+ if(shift)
+ x+=9;
+ p->selx = scalespace_value(&p->x,x);
+ if(p->crosshairs_callback)
+ p->crosshairs_callback(p->cross_data);
+
+ if(p->button_down){
+ p->box_active=1;
+ p->box_x2 = p->selx;
+ }else
+ p->box_active=0;
+
+ plot_expose_request(p);
+
+ }
+ return TRUE;
+ case GDK_Up:
+ {
+ double y = widget->allocation.height - scalespace_pixel(&p->y,p->sely)-1;
+ if(shift)
+ y-=9;
+ p->sely = scalespace_value(&p->y,widget->allocation.height - y);
+ if(p->crosshairs_callback)
+ p->crosshairs_callback(p->cross_data);
+
+ if(p->button_down){
+ p->box_active=1;
+ p->box_y2 = p->sely;
+ }else
+ p->box_active=0;
+
+ plot_expose_request(p);
+ }
+ return TRUE;
+ case GDK_Down:
+ {
+ double y = widget->allocation.height - scalespace_pixel(&p->y,p->sely)+1;
+ if(shift)
+ y+=9;
+ p->sely = scalespace_value(&p->y,widget->allocation.height - y);
+ if(p->crosshairs_callback)
+ p->crosshairs_callback(p->cross_data);
+
+ if(p->button_down){
+ p->box_active=1;
+ p->box_y2 = p->sely;
+ }else
+ p->box_active=0;
+
+ plot_expose_request(p);
+
+ }
+ return TRUE;
+ }
+
+
+ return FALSE;
}
static gboolean plot_unfocus(GtkWidget *widget,
More information about the commits
mailing list