aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-01-08 12:00:53 -0500
committerSteven Rostedt <rostedt@goodmis.org>2010-01-08 12:00:53 -0500
commit01ccb483a82d876ce655b3a79f12489deb7d21c4 (patch)
treee60bd0a8179c361e812c3d656708424bbffde513
parent1d38003f5b84304485a6c96574154676de8c7ae5 (diff)
trace-graph: Allow selection before graph for zooming
It is difficult to zoom in from the beginning of the graph, because you must move the pointer right to zoom. To ease zooming in at the start of the graph, this patch now allows the user to select on the CPU drawing, and move the pointer over the graph to make the selection. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--trace-graph.c125
1 files changed, 108 insertions, 17 deletions
diff --git a/trace-graph.c b/trace-graph.c
index 4a65fb5..e5b22a8 100644
--- a/trace-graph.c
+++ b/trace-graph.c
@@ -595,6 +595,81 @@ button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
595 return TRUE; 595 return TRUE;
596} 596}
597 597
598static gboolean
599info_button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
600{
601 struct graph_info *ginfo = data;
602
603 printf("hi\n");
604 if (event->button != 1)
605 return FALSE;
606
607 /* check for double click */
608 if (event->type == GDK_2BUTTON_PRESS)
609 return FALSE;
610
611 ginfo->press_x = 0;
612 ginfo->last_x = 0;
613
614 draw_line(ginfo->draw, 0, ginfo);
615
616 ginfo->line_active = TRUE;
617
618 return FALSE;
619}
620
621static gboolean
622info_motion_notify_event(GtkWidget *widget, GdkEventMotion *event, gpointer data)
623{
624 struct graph_info *ginfo = data;
625 GdkModifierType state;
626 gint x, y;
627
628 if (!ginfo->line_active)
629 return FALSE;
630
631 if (!ginfo->curr_pixmap)
632 return FALSE;
633
634 update_with_backend(ginfo, ginfo->cpu_data_x, ginfo->cpu_data_y,
635 ginfo->cpu_data_w, ginfo->cpu_data_h);
636 if (event->is_hint)
637 gdk_window_get_pointer(event->window, &x, &y, &state);
638 else {
639 x = event->x;
640 y = event->y;
641 }
642
643 /* Position x relative to the location in the drawing area */
644 x -= ginfo->scrollwin->allocation.x - ginfo->info_scrollwin->allocation.x;
645
646 if (x < 0)
647 return FALSE;
648
649 if (ginfo->last_x)
650 clear_last_line(ginfo->draw, ginfo);
651 ginfo->last_x = x;
652 draw_line(ginfo->draw, ginfo->press_x, ginfo);
653 draw_line(ginfo->draw, x, ginfo);
654
655 return FALSE;
656}
657
658static void activate_zoom(struct graph_info *ginfo, gint x);
659
660static gboolean
661info_button_release_event(GtkWidget *widget, GdkEventMotion *event, gpointer data)
662{
663 struct graph_info *ginfo = data;
664 gint x;
665
666 x = event->x - ginfo->scrollwin->allocation.x - ginfo->info_scrollwin->allocation.x;
667
668 activate_zoom(ginfo, x);
669
670 return FALSE;
671}
672
598static void print_rec_info(struct record *record, struct pevent *pevent, int cpu) 673static void print_rec_info(struct record *record, struct pevent *pevent, int cpu)
599{ 674{
600 struct trace_seq s; 675 struct trace_seq s;
@@ -1172,26 +1247,32 @@ static void zoom_out_window(struct graph_info *ginfo, gint start, gint end)
1172 1247
1173 ginfo->hadj_value = start_x; 1248 ginfo->hadj_value = start_x;
1174} 1249}
1250static void activate_zoom(struct graph_info *ginfo, gint x)
1251{
1252
1253 if (!ginfo->line_active)
1254 return;
1255
1256 ginfo->line_active = FALSE;
1257 clear_last_line(ginfo->draw, ginfo);
1258 ginfo->last_x = ginfo->press_x;
1259 clear_last_line(ginfo->draw, ginfo);
1260
1261 if (x > ginfo->press_x) {
1262 /* make a decent zoom */
1263 if (x - ginfo->press_x < 10)
1264 return;
1265 zoom_in_window(ginfo, ginfo->press_x, x);
1266 } else if (x < ginfo->press_x)
1267 zoom_out_window(ginfo, ginfo->press_x, x);
1268}
1175 1269
1176static gboolean 1270static gboolean
1177button_release_event(GtkWidget *widget, GdkEventMotion *event, gpointer data) 1271button_release_event(GtkWidget *widget, GdkEventMotion *event, gpointer data)
1178{ 1272{
1179 struct graph_info *ginfo = data; 1273 struct graph_info *ginfo = data;
1180 1274
1181 if (ginfo->line_active) { 1275 activate_zoom(ginfo, event->x);
1182 ginfo->line_active = FALSE;
1183 clear_last_line(widget, ginfo);
1184 ginfo->last_x = ginfo->press_x;
1185 clear_last_line(widget, ginfo);
1186
1187 if (event->x > ginfo->press_x) {
1188 /* make a decent zoom */
1189 if (event->x - ginfo->press_x < 10)
1190 return TRUE;
1191 zoom_in_window(ginfo, ginfo->press_x, event->x);
1192 } else if (event->x < ginfo->press_x)
1193 zoom_out_window(ginfo, ginfo->press_x, event->x);
1194 }
1195 1276
1196 return TRUE; 1277 return TRUE;
1197} 1278}
@@ -1203,6 +1284,7 @@ leave_notify_event(GtkWidget *widget, GdkEventCrossing *event, gpointer data)
1203 1284
1204 update_with_backend(ginfo, ginfo->cpu_data_x, ginfo->cpu_data_y, 1285 update_with_backend(ginfo, ginfo->cpu_data_x, ginfo->cpu_data_y,
1205 ginfo->cpu_data_w, ginfo->cpu_data_h); 1286 ginfo->cpu_data_w, ginfo->cpu_data_h);
1287
1206 return FALSE; 1288 return FALSE;
1207} 1289}
1208 1290
@@ -1863,8 +1945,18 @@ create_graph_info(struct graph_info *ginfo)
1863 (GtkSignalFunc) info_expose_event, ginfo); 1945 (GtkSignalFunc) info_expose_event, ginfo);
1864 gtk_signal_connect(GTK_OBJECT(info), "configure_event", 1946 gtk_signal_connect(GTK_OBJECT(info), "configure_event",
1865 (GtkSignalFunc) info_configure_event, ginfo); 1947 (GtkSignalFunc) info_configure_event, ginfo);
1866 1948 gtk_signal_connect(GTK_OBJECT(info), "button_press_event",
1867 gtk_widget_set_events(info, GDK_EXPOSURE_MASK); 1949 (GtkSignalFunc) info_button_press_event, ginfo);
1950 gtk_signal_connect(GTK_OBJECT(info), "motion_notify_event",
1951 (GtkSignalFunc) info_motion_notify_event, ginfo);
1952 gtk_signal_connect(GTK_OBJECT(info), "button_release_event",
1953 (GtkSignalFunc) info_button_release_event, ginfo);
1954
1955 gtk_widget_set_events(info, GDK_EXPOSURE_MASK
1956 | GDK_BUTTON_PRESS_MASK
1957 | GDK_BUTTON_RELEASE_MASK
1958 | GDK_POINTER_MOTION_MASK
1959 | GDK_POINTER_MOTION_HINT_MASK);
1868 1960
1869 return info; 1961 return info;
1870} 1962}
@@ -1980,7 +2072,6 @@ trace_graph_create_with_callbacks(struct tracecmd_input *handle,
1980 | GDK_POINTER_MOTION_HINT_MASK 2072 | GDK_POINTER_MOTION_HINT_MASK
1981 | GDK_LEAVE_NOTIFY_MASK); 2073 | GDK_LEAVE_NOTIFY_MASK);
1982 2074
1983
1984 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(ginfo->scrollwin), 2075 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(ginfo->scrollwin),
1985 ginfo->draw); 2076 ginfo->draw);
1986 gtk_widget_show(ginfo->draw); 2077 gtk_widget_show(ginfo->draw);