[xiph-commits] r12126 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Fri Nov 17 05:09:33 PST 2006


Author: xiphmont
Date: 2006-11-17 05:07:28 -0800 (Fri, 17 Nov 2006)
New Revision: 12126

Modified:
   trunk/sushivision/gtksucks.c
   trunk/sushivision/gtksucks.h
   trunk/sushivision/panel-2d.c
   trunk/sushivision/panel-2d.h
   trunk/sushivision/plot.c
   trunk/sushivision/plot.h
Log:
2d panel has complete context menus now



Modified: trunk/sushivision/gtksucks.c
===================================================================
--- trunk/sushivision/gtksucks.c	2006-11-17 12:35:07 UTC (rev 12125)
+++ trunk/sushivision/gtksucks.c	2006-11-17 13:07:28 UTC (rev 12126)
@@ -262,23 +262,24 @@
       item = gtk_separator_menu_item_new();
       gtk_menu_shell_append(GTK_MENU_SHELL(ret),item);
     }else{
+      GtkWidget *box = gtk_hbox_new(0,10);
+      GtkWidget *left = gtk_label_new(*ptr);
+      GtkWidget *right = NULL;
+
+      item = gtk_menu_item_new();
+      gtk_container_add(GTK_CONTAINER(item),box);
+      gtk_box_pack_start(GTK_BOX(box),left,0,0,5);
+      
       if(sptr && *sptr){
-	GtkWidget *box = gtk_hbox_new(0,10);
-	GtkWidget *left = gtk_label_new(*ptr);
-	GtkWidget *right = gtk_label_new(NULL);
-
 	char *markup = g_markup_printf_escaped ("<i>%s</i>", *sptr);
+	right = gtk_label_new(NULL);
+	
 	gtk_label_set_markup (GTK_LABEL (right), markup);
 	g_free (markup);
 	
-	item = gtk_menu_item_new();
-	gtk_container_add(GTK_CONTAINER(item),box);
-	gtk_box_pack_start(GTK_BOX(box),left,0,0,5);
 	gtk_box_pack_end(GTK_BOX(box),right,0,0,5);
+      }
 
-      }else{
-	item = gtk_menu_item_new_with_label(*ptr);
-      }
       gtk_menu_shell_append(GTK_MENU_SHELL(ret),item);
       if(callbacks && *callbacks)
 	g_signal_connect_swapped (G_OBJECT (item), "activate",
@@ -317,3 +318,25 @@
 
   return NULL;
 }
+
+void gtk_menu_alter_item_label(GtkMenu *m, int pos, char *text){
+  GList *l;
+  GtkWidget *box=NULL;
+  GtkWidget *label=NULL;
+  GtkWidget *item = gtk_menu_get_item(m, pos);
+  if(!item)return;
+
+  l=gtk_container_get_children (GTK_CONTAINER(item));    
+  box = l->data;
+  g_list_free(l);
+
+  if(!box)return;
+
+  l=gtk_container_get_children (GTK_CONTAINER(box));    
+  label = l->data;
+  g_list_free(l);
+
+  if(!label)return;
+
+  gtk_label_set_label(GTK_LABEL(label),text);
+}

Modified: trunk/sushivision/gtksucks.h
===================================================================
--- trunk/sushivision/gtksucks.h	2006-11-17 12:35:07 UTC (rev 12125)
+++ trunk/sushivision/gtksucks.h	2006-11-17 13:07:28 UTC (rev 12126)
@@ -32,5 +32,6 @@
 				      void (*callbacks[])(void *),
 				      void *callback_data);
 extern GtkWidget *gtk_menu_get_item(GtkMenu *m, int pos);
+extern void gtk_menu_alter_item_label(GtkMenu *m, int pos, char *text);
 
 #endif

Modified: trunk/sushivision/panel-2d.c
===================================================================
--- trunk/sushivision/panel-2d.c	2006-11-17 12:35:07 UTC (rev 12125)
+++ trunk/sushivision/panel-2d.c	2006-11-17 13:07:28 UTC (rev 12126)
@@ -44,7 +44,7 @@
 static void panel2d_undo_push(sushiv_panel_t *p);
 static void panel2d_undo_suspend(sushiv_panel_t *p);
 static void panel2d_undo_resume(sushiv_panel_t *p);
-static void update_context_menu(sushiv_panel_t *p);
+static void update_context_menus(sushiv_panel_t *p);
 
 static void render_checks(int w, int y, u_int32_t *render){
   int x,j;
@@ -784,6 +784,7 @@
     panel2d_undo_resume(p);
     break;
   }
+  update_context_menus(p);
 }
 
 // called from one/all of the worker threads; the idea is that several
@@ -1088,7 +1089,7 @@
   p2->undo_level++;
   p2->undo_stack[p2->undo_level]=0;
   p2->undo_stack[p2->undo_level+1]=0;
-  update_context_menu(p);
+  update_context_menus(p);
 
 }
 
@@ -1103,7 +1104,7 @@
   panel2d_undo_suspend(p);
   panel2d_undo_restore(p);
   panel2d_undo_resume(p);
-  update_context_menu(p);
+  update_context_menus(p);
 }
 
 static void panel2d_undo_down(sushiv_panel_t *p){
@@ -1118,7 +1119,7 @@
   panel2d_undo_suspend(p);
   panel2d_undo_restore(p);
   panel2d_undo_resume(p);
-  update_context_menu(p);
+  update_context_menus(p);
 }
 
 // called with lock
@@ -1221,50 +1222,108 @@
   return FALSE;
 }
 
-static void update_context_menu(sushiv_panel_t *p){
+static void update_context_menus(sushiv_panel_t *p){
   sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
-  
+
   // is undo active?
   if(!p2->undo_stack ||
-     !p2->undo_level)
+     !p2->undo_level){
     gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p2->popmenu),0),FALSE);
-  else
+    gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p2->graphmenu),0),FALSE);
+  }else{
     gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p2->popmenu),0),TRUE);
+    gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p2->graphmenu),0),TRUE);
+  }
 
   // is redo active?
   if(!p2->undo_stack ||
      !p2->undo_stack[p2->undo_level] ||
-     !p2->undo_stack[p2->undo_level+1])
+     !p2->undo_stack[p2->undo_level+1]){
     gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p2->popmenu),1),FALSE);
-  else
+    gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p2->graphmenu),1),FALSE);
+  }else{
     gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p2->popmenu),1),TRUE);
+    gtk_widget_set_sensitive(gtk_menu_get_item(GTK_MENU(p2->graphmenu),1),TRUE);
+  }
+
+  // are we starting or enacting a zoom box?
+  if(p2->oldbox_active){ 
+    gtk_menu_alter_item_label(GTK_MENU(p2->graphmenu),3,"Zoom to box");
+  }else{
+    gtk_menu_alter_item_label(GTK_MENU(p2->graphmenu),3,"Start zoom box");
+  }
+
 }
 
 void wrap_exit(sushiv_panel_t *dummy){
   _sushiv_clean_exit(SIGINT);
 }
 
-static char *menulist[]={
+static char *panel_menulist[]={
   "Undo",
   "Redo",
+  "",
+  "Quit",
+  NULL
+};
+
+static char *panel_shortlist[]={
+  "Backspace",
+  "Space",
+  NULL,
+  "q",
+  NULL
+};
+
+static void (*panel_calllist[])(sushiv_panel_t *)={
+  &panel2d_undo_down,
+  &panel2d_undo_up,
+  NULL,
+  &wrap_exit,
+  NULL,
+};
+
+void wrap_enter(sushiv_panel_t *p){
+  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  plot_do_enter(PLOT(p2->graph));
+}
+
+void wrap_escape(sushiv_panel_t *p){
+  sushiv_panel2d_t *p2 = (sushiv_panel2d_t *)p->internal;
+  plot_do_escape(PLOT(p2->graph));
+}
+
+static char *graph_menulist[]={
+  "Undo",
+  "Redo",
+  "",
+  "Start zoom box",
+  "Clear box and crosshairs",
   "Find peaks",
   "",
   "Quit",
   NULL
 };
 
-static char *shortlist[]={
+static char *graph_shortlist[]={
   "Backspace",
   "Space",
+  NULL,
+  "Enter",
+  "Escape",
   "p",
   NULL,
   "q",
   NULL
 };
 
-static void (*calllist[])(sushiv_panel_t *)={
+static void (*graph_calllist[])(sushiv_panel_t *)={
   &panel2d_undo_down,
   &panel2d_undo_up,
+  NULL,
+
+  &wrap_enter,
+  &wrap_escape,
   &panel2d_find_peak,
   NULL,
   &wrap_exit,
@@ -1419,10 +1478,19 @@
   }
   update_xy_availability(p);
 
-  p2->popmenu = gtk_menu_new_twocol(p2->toplevel,menulist,shortlist,
-				    (void *)(void *)calllist,p);
-  update_context_menu(p);
+  p2->popmenu = gtk_menu_new_twocol(p2->toplevel,
+				    panel_menulist,
+				    panel_shortlist,
+				    (void *)(void *)panel_calllist,
+				    p);
+  p2->graphmenu = gtk_menu_new_twocol(p2->graph,
+				      graph_menulist,
+				      graph_shortlist,
+				      (void *)(void *)graph_calllist,
+				      p);
 
+  update_context_menus(p);
+
   g_signal_connect (G_OBJECT (p2->toplevel), "key-press-event",
                     G_CALLBACK (panel2d_keypress), p);
   gtk_window_set_title (GTK_WINDOW (p2->toplevel), p->name);

Modified: trunk/sushivision/panel-2d.h
===================================================================
--- trunk/sushivision/panel-2d.h	2006-11-17 12:35:07 UTC (rev 12125)
+++ trunk/sushivision/panel-2d.h	2006-11-17 13:07:28 UTC (rev 12126)
@@ -40,6 +40,7 @@
   GtkWidget *top_table;
   GtkWidget *dim_table;
   GtkWidget *popmenu;
+  GtkWidget *graphmenu;
 
   int data_w;
   int data_h;

Modified: trunk/sushivision/plot.c
===================================================================
--- trunk/sushivision/plot.c	2006-11-17 12:35:07 UTC (rev 12125)
+++ trunk/sushivision/plot.c	2006-11-17 13:07:28 UTC (rev 12126)
@@ -610,6 +610,40 @@
   return TRUE;
 }
 
+void plot_do_enter(Plot *p){
+  // 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{
+    if(p->button_down){
+      GdkEventButton event;
+      event.x = scalespace_pixel(&p->x,p->selx);
+      event.y = GTK_WIDGET(p)->allocation.height-
+	scalespace_pixel(&p->y,p->sely);
+      
+      mouse_release(GTK_WIDGET(p),&event);
+    }else{
+      p->box_x2=p->box_x1 = p->selx;
+      p->box_y2=p->box_y1 = p->sely;
+      p->box_active = 1;
+      p->button_down=1; 
+    }
+  }
+}
+
+void plot_do_escape(Plot *p){
+  p->button_down=0;
+  p->box_active=0;
+  p->cross_active=0;
+  plot_expose_request(p);
+}
+
 static gboolean key_press(GtkWidget *widget,
 			  GdkEventKey *event){
   Plot *p = PLOT(widget);
@@ -621,36 +655,10 @@
   /* non-control keypresses */
   switch(event->keyval){
   case GDK_Escape:
-    p->button_down=0;
-    p->box_active=0;
-    p->cross_active=0;
-    plot_expose_request(p);
-
+    plot_do_escape(p);
     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{
-      if(p->button_down){
-	GdkEventButton event;
-	event.x = scalespace_pixel(&p->x,p->selx);
-	event.y = widget->allocation.height-
-	  scalespace_pixel(&p->y,p->sely);
-	
-	mouse_release(widget,&event);
-      }else{
-	p->box_x2=p->box_x1 = p->selx;
-	p->box_y2=p->box_y1 = p->sely;
-	p->box_active = 1;
-	p->button_down=1; 
-      }
-    }
+    plot_do_enter(p);
     return TRUE;
 
   case GDK_Left:

Modified: trunk/sushivision/plot.h
===================================================================
--- trunk/sushivision/plot.h	2006-11-17 12:35:07 UTC (rev 12125)
+++ trunk/sushivision/plot.h	2006-11-17 13:07:28 UTC (rev 12126)
@@ -106,3 +106,6 @@
 void plot_legend_clear(Plot *p);
 int plot_get_crosshair_xpixel(Plot *p);
 int plot_get_crosshair_ypixel(Plot *p);
+
+void plot_do_enter(Plot *p);
+void plot_do_escape(Plot *p);



More information about the commits mailing list