diff options
author | Steven Rostedt <rostedt@goodmis.org> | 2009-12-22 15:18:35 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2009-12-22 15:18:35 -0500 |
commit | 50cc61439893bc8d60f8ec310a50b53a5178c5dc (patch) | |
tree | 64489207ce2803e67c6a9ea742d194f08eb4dcef | |
parent | 1fe08affbfcac4b6f5324633f58de654b8f05079 (diff) |
trace-graph: Add cursor line
This patch adds a cursor line when double clicked. This allows the user
to keep a reference to a location when zooming in and out.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r-- | trace-graph.c | 64 | ||||
-rw-r--r-- | trace-graph.h | 2 |
2 files changed, 55 insertions, 11 deletions
diff --git a/trace-graph.c b/trace-graph.c index e4e50b2..d97c4d1 100644 --- a/trace-graph.c +++ b/trace-graph.c | |||
@@ -127,6 +127,21 @@ static void draw_cpu_labels(struct graph_info *ginfo) | |||
127 | __draw_cpu_label(ginfo, cpu); | 127 | __draw_cpu_label(ginfo, cpu); |
128 | } | 128 | } |
129 | 129 | ||
130 | static void draw_cursor(struct graph_info *ginfo) | ||
131 | { | ||
132 | gint x; | ||
133 | |||
134 | if (ginfo->cursor < ginfo->view_start_time || | ||
135 | ginfo->cursor > ginfo->view_end_time) | ||
136 | return; | ||
137 | |||
138 | x = (ginfo->cursor - ginfo->view_start_time) | ||
139 | * ginfo->resolution; | ||
140 | |||
141 | gdk_draw_line(ginfo->draw->window, ginfo->draw->style->mid_gc[3], | ||
142 | x, 0, x, ginfo->draw->allocation.width); | ||
143 | } | ||
144 | |||
130 | static void update_with_backend(struct graph_info *ginfo, | 145 | static void update_with_backend(struct graph_info *ginfo, |
131 | gint x, gint y, | 146 | gint x, gint y, |
132 | gint width, gint height) | 147 | gint width, gint height) |
@@ -134,6 +149,10 @@ static void update_with_backend(struct graph_info *ginfo, | |||
134 | gint cpu; | 149 | gint cpu; |
135 | 150 | ||
136 | __update_with_backend(ginfo, x, y, width, height); | 151 | __update_with_backend(ginfo, x, y, width, height); |
152 | |||
153 | if (ginfo->cursor) | ||
154 | draw_cursor(ginfo); | ||
155 | |||
137 | for (cpu = 0; cpu < ginfo->cpus; cpu++ ) { | 156 | for (cpu = 0; cpu < ginfo->cpus; cpu++ ) { |
138 | if (y <= CPU_BOTTOM(cpu) && | 157 | if (y <= CPU_BOTTOM(cpu) && |
139 | y + height > CPU_TOP(cpu) && | 158 | y + height > CPU_TOP(cpu) && |
@@ -162,6 +181,17 @@ draw_line(GtkWidget *widget, gdouble x, struct graph_info *ginfo) | |||
162 | x, 0, x, widget->allocation.width); | 181 | x, 0, x, widget->allocation.width); |
163 | } | 182 | } |
164 | 183 | ||
184 | static void clear_last_line(GtkWidget *widget, struct graph_info *ginfo) | ||
185 | { | ||
186 | gint x; | ||
187 | |||
188 | x = ginfo->last_x; | ||
189 | if (x) | ||
190 | x--; | ||
191 | |||
192 | update_with_backend(ginfo, x, 0, x+2, widget->allocation.height); | ||
193 | } | ||
194 | |||
165 | static gboolean | 195 | static gboolean |
166 | button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data) | 196 | button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data) |
167 | { | 197 | { |
@@ -172,6 +202,29 @@ button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data) | |||
172 | if (event->button != 1) | 202 | if (event->button != 1) |
173 | return TRUE; | 203 | return TRUE; |
174 | 204 | ||
205 | /* check for double click */ | ||
206 | if (event->type==GDK_2BUTTON_PRESS) { | ||
207 | if (ginfo->line_active) { | ||
208 | ginfo->line_active = FALSE; | ||
209 | clear_last_line(widget, ginfo); | ||
210 | ginfo->last_x = ginfo->press_x; | ||
211 | clear_last_line(widget, ginfo); | ||
212 | } | ||
213 | if (ginfo->cursor >= ginfo->view_start_time && | ||
214 | ginfo->cursor <= ginfo->view_end_time) { | ||
215 | ginfo->last_x = (ginfo->cursor - ginfo->view_start_time) | ||
216 | * ginfo->resolution; | ||
217 | ginfo->cursor = 0; | ||
218 | clear_last_line(widget, ginfo); | ||
219 | } | ||
220 | |||
221 | ginfo->cursor = event->x / ginfo->resolution + | ||
222 | ginfo->view_start_time; | ||
223 | draw_cursor(ginfo); | ||
224 | return TRUE; | ||
225 | } | ||
226 | |||
227 | |||
175 | ginfo->press_x = event->x; | 228 | ginfo->press_x = event->x; |
176 | ginfo->last_x = 0; | 229 | ginfo->last_x = 0; |
177 | 230 | ||
@@ -182,17 +235,6 @@ button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer data) | |||
182 | return TRUE; | 235 | return TRUE; |
183 | } | 236 | } |
184 | 237 | ||
185 | static void clear_last_line(GtkWidget *widget, struct graph_info *ginfo) | ||
186 | { | ||
187 | gint x; | ||
188 | |||
189 | x = ginfo->last_x; | ||
190 | if (x) | ||
191 | x--; | ||
192 | |||
193 | update_with_backend(ginfo, x, 0, x+2, widget->allocation.height); | ||
194 | } | ||
195 | |||
196 | static void print_rec_info(struct record *record, struct pevent *pevent, int cpu) | 238 | static void print_rec_info(struct record *record, struct pevent *pevent, int cpu) |
197 | { | 239 | { |
198 | struct trace_seq s; | 240 | struct trace_seq s; |
diff --git a/trace-graph.h b/trace-graph.h index 61f5546..dd5f58b 100644 --- a/trace-graph.h +++ b/trace-graph.h | |||
@@ -16,6 +16,8 @@ struct graph_info { | |||
16 | guint64 view_end_time; /* visible end time */ | 16 | guint64 view_end_time; /* visible end time */ |
17 | gint start_x; /* virutal start of visible area */ | 17 | gint start_x; /* virutal start of visible area */ |
18 | 18 | ||
19 | guint64 cursor; /* time of cursor (double clicked) */ | ||
20 | |||
19 | gdouble resolution; /* pixels / time */ | 21 | gdouble resolution; /* pixels / time */ |
20 | 22 | ||
21 | gint press_x; /* x where button is pressed */ | 23 | gint press_x; /* x where button is pressed */ |