ce0214a6 |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 Mathieu Desnoyers |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License Version 2 as |
6 | * published by the Free Software Foundation; |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
16 | * MA 02111-1307, USA. |
17 | */ |
fa2c4dbe |
18 | |
76a67e8a |
19 | #include <gtk/gtk.h> |
20 | #include <gdk/gdk.h> |
f0d936c0 |
21 | |
2a2fa4f0 |
22 | #include <lttv/lttv.h> |
831a876d |
23 | #include <lttv/processTrace.h> |
cef97e7c |
24 | #include <lttv/gtktraceset.h> |
f66eba62 |
25 | #include <lttv/hook.h> |
831a876d |
26 | |
d66666fe |
27 | #include "drawing.h" |
28 | #include "cfv.h" |
29 | #include "cfv-private.h" |
30 | #include "eventhooks.h" |
6d5ed1c3 |
31 | |
32 | #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format) |
33 | #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format) |
34 | |
f0d936c0 |
35 | /***************************************************************************** |
501d5405 |
36 | * drawing functions * |
f0d936c0 |
37 | *****************************************************************************/ |
38 | |
3cb8b205 |
39 | static gboolean |
40 | expose_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data ); |
41 | |
d287af9a |
42 | static gboolean |
43 | motion_notify_ruler(GtkWidget *widget, GdkEventMotion *event, gpointer user_data); |
3cb8b205 |
44 | |
45 | |
831a876d |
46 | //FIXME Colors will need to be dynamic. Graphic context part not done so far. |
f0d936c0 |
47 | typedef enum |
48 | { |
a56a1ba4 |
49 | RED, |
50 | GREEN, |
51 | BLUE, |
52 | WHITE, |
53 | BLACK |
f0d936c0 |
54 | |
55 | } ControlFlowColors; |
56 | |
57 | /* Vector of unallocated colors */ |
58 | static GdkColor CF_Colors [] = |
59 | { |
a56a1ba4 |
60 | { 0, 0xffff, 0x0000, 0x0000 }, // RED |
61 | { 0, 0x0000, 0xffff, 0x0000 }, // GREEN |
62 | { 0, 0x0000, 0x0000, 0xffff }, // BLUE |
63 | { 0, 0xffff, 0xffff, 0xffff }, // WHITE |
64 | { 0, 0x0000, 0x0000, 0x0000 } // BLACK |
f0d936c0 |
65 | }; |
66 | |
67 | |
831a876d |
68 | /* Function responsible for updating the exposed area. |
69 | * It must call processTrace() to ask for this update. |
432a7065 |
70 | * Note : this function cannot clear the background, because it may |
71 | * erase drawing already present (SAFETY). |
831a876d |
72 | */ |
501d5405 |
73 | void drawing_data_request(Drawing_t *drawing, |
b6db18f8 |
74 | GdkPixmap **pixmap, |
a56a1ba4 |
75 | gint x, gint y, |
76 | gint width, |
77 | gint height) |
847b479d |
78 | { |
d9b7ca88 |
79 | if(width < 0) return ; |
80 | if(height < 0) return ; |
a56a1ba4 |
81 | ControlFlowData *control_flow_data = |
82 | (ControlFlowData*)g_object_get_data( |
83 | G_OBJECT( |
501d5405 |
84 | drawing->drawing_area), |
68997a22 |
85 | "control_flow_data"); |
a56a1ba4 |
86 | |
87 | LttTime start, end; |
ba90bc77 |
88 | LttTime window_end = ltt_time_add(control_flow_data->time_window.time_width, |
89 | control_flow_data->time_window.start_time); |
a56a1ba4 |
90 | |
2a2fa4f0 |
91 | g_debug("req : window_end : %u, %u", window_end.tv_sec, |
a56a1ba4 |
92 | window_end.tv_nsec); |
93 | |
2a2fa4f0 |
94 | g_debug("req : time width : %u, %u", control_flow_data->time_window.time_width.tv_sec, |
ba90bc77 |
95 | control_flow_data->time_window.time_width.tv_nsec); |
a56a1ba4 |
96 | |
2a2fa4f0 |
97 | g_debug("x is : %i, x+width is : %i", x, x+width); |
a56a1ba4 |
98 | |
501d5405 |
99 | convert_pixels_to_time(drawing->drawing_area->allocation.width, x, |
ba90bc77 |
100 | &control_flow_data->time_window.start_time, |
a56a1ba4 |
101 | &window_end, |
102 | &start); |
103 | |
501d5405 |
104 | convert_pixels_to_time(drawing->drawing_area->allocation.width, x + width, |
ba90bc77 |
105 | &control_flow_data->time_window.start_time, |
a56a1ba4 |
106 | &window_end, |
107 | &end); |
108 | |
109 | LttvTracesetContext * tsc = |
ba90bc77 |
110 | get_traceset_context(control_flow_data->mw); |
d52cfc84 |
111 | LttvTracesetState * tss = |
d0cd7f09 |
112 | (LttvTracesetState*)tsc; |
a56a1ba4 |
113 | |
432a7065 |
114 | //send_test_process( |
501d5405 |
115 | //guicontrolflow_get_process_list(drawing->control_flow_data), |
116 | //drawing); |
f66eba62 |
117 | //send_test_drawing( |
501d5405 |
118 | //guicontrolflow_get_process_list(drawing->control_flow_data), |
119 | //drawing, *pixmap, x, y, width, height); |
a56a1ba4 |
120 | |
121 | // Let's call processTrace() !! |
122 | EventRequest event_request; // Variable freed at the end of the function. |
68997a22 |
123 | event_request.control_flow_data = control_flow_data; |
a56a1ba4 |
124 | event_request.time_begin = start; |
125 | event_request.time_end = end; |
126 | event_request.x_begin = x; |
127 | event_request.x_end = x+width; |
128 | |
2a2fa4f0 |
129 | g_debug("req : start : %u, %u", event_request.time_begin.tv_sec, |
a56a1ba4 |
130 | event_request.time_begin.tv_nsec); |
131 | |
2a2fa4f0 |
132 | g_debug("req : end : %u, %u", event_request.time_end.tv_sec, |
a56a1ba4 |
133 | event_request.time_end.tv_nsec); |
134 | |
135 | LttvHooks *event = lttv_hooks_new(); |
136 | LttvHooks *after_event = lttv_hooks_new(); |
137 | LttvHooks *after_traceset = lttv_hooks_new(); |
138 | lttv_hooks_add(after_traceset, after_data_request, &event_request); |
139 | lttv_hooks_add(event, draw_event_hook, &event_request); |
140 | //Modified by xiangxiu: state update hooks are added by the main window |
ba90bc77 |
141 | //state_add_event_hooks_api(control_flow_data->mw); |
a56a1ba4 |
142 | lttv_hooks_add(after_event, draw_after_hook, &event_request); |
143 | |
d52cfc84 |
144 | //lttv_process_traceset_seek_time(tsc, start); |
145 | lttv_state_traceset_seek_time_closest(tss, start); |
a56a1ba4 |
146 | // FIXME : would like to place the after_traceset hook after the traceset, |
147 | // but the traceset context state is not valid anymore. |
148 | lttv_traceset_context_add_hooks(tsc, |
d0cd7f09 |
149 | NULL, after_traceset, NULL, NULL, NULL, NULL, |
150 | //NULL, NULL, NULL, NULL, NULL, NULL, |
151 | NULL, NULL, NULL, event, after_event); |
a56a1ba4 |
152 | lttv_process_traceset(tsc, end, G_MAXULONG); |
153 | //after_data_request((void*)&event_request,(void*)tsc); |
154 | lttv_traceset_context_remove_hooks(tsc, |
d0cd7f09 |
155 | NULL, after_traceset, NULL, NULL, NULL, NULL, |
156 | // NULL, NULL, NULL, NULL, NULL, NULL, |
157 | NULL, NULL, NULL, event, after_event); |
a56a1ba4 |
158 | //Modified by xiangxiu: state update hooks are removed by the main window |
ba90bc77 |
159 | //state_remove_event_hooks_api(control_flow_data->mw); |
a56a1ba4 |
160 | |
161 | lttv_hooks_destroy(after_traceset); |
162 | lttv_hooks_destroy(event); |
163 | lttv_hooks_destroy(after_event); |
164 | |
165 | |
847b479d |
166 | } |
a56a1ba4 |
167 | |
847b479d |
168 | /* Callbacks */ |
169 | |
170 | |
171 | /* Create a new backing pixmap of the appropriate size */ |
bd24a9af |
172 | /* As the scaling will always change, it's of no use to copy old |
173 | * pixmap. |
174 | */ |
847b479d |
175 | static gboolean |
176 | configure_event( GtkWidget *widget, GdkEventConfigure *event, |
a56a1ba4 |
177 | gpointer user_data) |
f0d936c0 |
178 | { |
501d5405 |
179 | Drawing_t *drawing = (Drawing_t*)user_data; |
f0d936c0 |
180 | |
86c520a7 |
181 | |
a56a1ba4 |
182 | /* First, get the new time interval of the main window */ |
183 | /* we assume (see documentation) that the main window |
184 | * has updated the time interval before this configure gets |
185 | * executed. |
186 | */ |
501d5405 |
187 | get_time_window(drawing->control_flow_data->mw, |
188 | &drawing->control_flow_data->time_window); |
a56a1ba4 |
189 | |
b6db18f8 |
190 | /* New pixmap, size of the configure event */ |
191 | //GdkPixmap *pixmap = gdk_pixmap_new(widget->window, |
a56a1ba4 |
192 | // widget->allocation.width + SAFETY, |
193 | // widget->allocation.height + SAFETY, |
194 | // -1); |
195 | |
2a2fa4f0 |
196 | g_debug("drawing configure event"); |
197 | g_debug("New draw size : %i by %i",widget->allocation.width, widget->allocation.height); |
a56a1ba4 |
198 | |
199 | |
501d5405 |
200 | if (drawing->pixmap) |
201 | gdk_pixmap_unref(drawing->pixmap); |
a56a1ba4 |
202 | |
b6db18f8 |
203 | /* If no old pixmap present */ |
501d5405 |
204 | //if(drawing->pixmap == NULL) |
847b479d |
205 | { |
501d5405 |
206 | drawing->pixmap = gdk_pixmap_new( |
a56a1ba4 |
207 | widget->window, |
208 | widget->allocation.width + SAFETY, |
209 | widget->allocation.height + SAFETY, |
210 | //ProcessList_get_height |
501d5405 |
211 | // (GuiControlFlow_get_process_list(drawing->control_flow_data)), |
a56a1ba4 |
212 | -1); |
501d5405 |
213 | drawing->width = widget->allocation.width; |
214 | drawing->height = widget->allocation.height; |
a56a1ba4 |
215 | |
216 | |
217 | // Clear the image |
501d5405 |
218 | gdk_draw_rectangle (drawing->pixmap, |
cfe526b1 |
219 | widget->style->black_gc, |
a56a1ba4 |
220 | TRUE, |
221 | 0, 0, |
222 | widget->allocation.width+SAFETY, |
223 | widget->allocation.height+SAFETY); |
224 | |
225 | //g_info("init data request"); |
226 | |
227 | |
228 | /* Initial data request */ |
229 | // Do not need to ask for data of 1 pixel : not synchronized with |
230 | // main window time at this moment. |
501d5405 |
231 | drawing_data_request(drawing, &drawing->pixmap, 0, 0, |
a56a1ba4 |
232 | widget->allocation.width, |
233 | widget->allocation.height); |
234 | |
501d5405 |
235 | drawing->width = widget->allocation.width; |
236 | drawing->height = widget->allocation.height; |
a56a1ba4 |
237 | |
238 | return TRUE; |
bd24a9af |
239 | |
240 | |
847b479d |
241 | |
242 | } |
bd24a9af |
243 | #ifdef NOTUSE |
847b479d |
244 | // /* Draw empty background */ |
b6db18f8 |
245 | // gdk_draw_rectangle (pixmap, |
a56a1ba4 |
246 | // widget->style->black_gc, |
247 | // TRUE, |
248 | // 0, 0, |
249 | // widget->allocation.width, |
250 | // widget->allocation.height); |
251 | |
252 | /* Copy old data to new pixmap */ |
b6db18f8 |
253 | gdk_draw_drawable (pixmap, |
cfe526b1 |
254 | widget->style->black_gc, |
501d5405 |
255 | drawing->pixmap, |
a56a1ba4 |
256 | 0, 0, |
257 | 0, 0, |
258 | -1, -1); |
259 | |
501d5405 |
260 | if (drawing->pixmap) |
261 | gdk_pixmap_unref(drawing->pixmap); |
80a52ff8 |
262 | |
501d5405 |
263 | drawing->pixmap = pixmap; |
a56a1ba4 |
264 | |
265 | // Clear the bottom part of the image (SAFETY) |
b6db18f8 |
266 | gdk_draw_rectangle (pixmap, |
cfe526b1 |
267 | widget->style->black_gc, |
a56a1ba4 |
268 | TRUE, |
501d5405 |
269 | 0, drawing->height+SAFETY, |
270 | drawing->width+SAFETY, // do not overlap |
271 | (widget->allocation.height) - drawing->height); |
bd24a9af |
272 | |
a56a1ba4 |
273 | // Clear the right part of the image (SAFETY) |
b6db18f8 |
274 | gdk_draw_rectangle (pixmap, |
cfe526b1 |
275 | widget->style->black_gc, |
a56a1ba4 |
276 | TRUE, |
501d5405 |
277 | drawing->width+SAFETY, 0, |
278 | (widget->allocation.width) - drawing->width, // do not overlap |
279 | drawing->height+SAFETY); |
a56a1ba4 |
280 | |
281 | /* Clear the backgound for data request, but not SAFETY */ |
b6db18f8 |
282 | gdk_draw_rectangle (pixmap, |
cfe526b1 |
283 | drawing->drawing_area->style->black_gc, |
a56a1ba4 |
284 | TRUE, |
501d5405 |
285 | drawing->width + SAFETY, 0, |
286 | widget->allocation.width - drawing->width, // do not overlap |
a56a1ba4 |
287 | widget->allocation.height+SAFETY); |
bd24a9af |
288 | |
432a7065 |
289 | /* Request data for missing space */ |
a56a1ba4 |
290 | g_info("missing data request"); |
501d5405 |
291 | drawing_data_request(drawing, &pixmap, drawing->width, 0, |
292 | widget->allocation.width - drawing->width, |
a56a1ba4 |
293 | widget->allocation.height); |
294 | |
501d5405 |
295 | drawing->width = widget->allocation.width; |
296 | drawing->height = widget->allocation.height; |
847b479d |
297 | |
298 | return TRUE; |
bd24a9af |
299 | #endif //NOTUSE |
847b479d |
300 | } |
301 | |
302 | |
303 | /* Redraw the screen from the backing pixmap */ |
304 | static gboolean |
305 | expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data ) |
306 | { |
501d5405 |
307 | Drawing_t *drawing = (Drawing_t*)user_data; |
a56a1ba4 |
308 | ControlFlowData *control_flow_data = |
309 | (ControlFlowData*)g_object_get_data( |
310 | G_OBJECT(widget), |
68997a22 |
311 | "control_flow_data"); |
8b90e648 |
312 | |
2a2fa4f0 |
313 | g_debug("drawing expose event"); |
a56a1ba4 |
314 | |
315 | guint x=0; |
ba90bc77 |
316 | LttTime* current_time = |
a56a1ba4 |
317 | guicontrolflow_get_current_time(control_flow_data); |
318 | |
ba90bc77 |
319 | LttTime window_end = ltt_time_add(control_flow_data->time_window.time_width, |
320 | control_flow_data->time_window.start_time); |
a56a1ba4 |
321 | |
322 | convert_time_to_pixels( |
ba90bc77 |
323 | control_flow_data->time_window.start_time, |
a56a1ba4 |
324 | window_end, |
ba90bc77 |
325 | *current_time, |
a56a1ba4 |
326 | widget->allocation.width, |
327 | &x); |
328 | |
847b479d |
329 | gdk_draw_pixmap(widget->window, |
a56a1ba4 |
330 | widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
501d5405 |
331 | drawing->pixmap, |
a56a1ba4 |
332 | event->area.x, event->area.y, |
333 | event->area.x, event->area.y, |
334 | event->area.width, event->area.height); |
335 | |
336 | if(x >= event->area.x && x <= event->area.x+event->area.width) |
337 | { |
853dbdb8 |
338 | gint8 dash_list[] = { 1, 2 }; |
501d5405 |
339 | GdkGC *gc = gdk_gc_new(control_flow_data->drawing->pixmap); |
0e492a24 |
340 | gdk_gc_copy(gc, widget->style->white_gc); |
341 | gdk_gc_set_line_attributes(gc, |
342 | 1, |
343 | GDK_LINE_ON_OFF_DASH, |
344 | GDK_CAP_BUTT, |
345 | GDK_JOIN_MITER); |
853dbdb8 |
346 | gdk_gc_set_dashes(gc, |
347 | 0, |
348 | dash_list, |
349 | 2); |
a56a1ba4 |
350 | drawing_draw_line(NULL, widget->window, |
351 | x, event->area.y, |
352 | x, event->area.y+event->area.height, |
353 | gc); |
354 | gdk_gc_unref(gc); |
355 | } |
847b479d |
356 | return FALSE; |
357 | } |
358 | |
8b90e648 |
359 | /* mouse click */ |
360 | static gboolean |
361 | button_press_event( GtkWidget *widget, GdkEventButton *event, gpointer user_data ) |
362 | { |
a56a1ba4 |
363 | ControlFlowData *control_flow_data = |
364 | (ControlFlowData*)g_object_get_data( |
365 | G_OBJECT(widget), |
68997a22 |
366 | "control_flow_data"); |
501d5405 |
367 | Drawing_t *drawing = control_flow_data->drawing; |
8b90e648 |
368 | |
369 | |
2a2fa4f0 |
370 | g_debug("click"); |
a56a1ba4 |
371 | if(event->button == 1) |
372 | { |
373 | LttTime time; |
8b90e648 |
374 | |
ba90bc77 |
375 | LttTime window_end = ltt_time_add(control_flow_data->time_window.time_width, |
376 | control_flow_data->time_window.start_time); |
8b90e648 |
377 | |
378 | |
a56a1ba4 |
379 | /* left mouse button click */ |
2a2fa4f0 |
380 | g_debug("x click is : %f", event->x); |
8b90e648 |
381 | |
a56a1ba4 |
382 | convert_pixels_to_time(widget->allocation.width, (guint)event->x, |
ba90bc77 |
383 | &control_flow_data->time_window.start_time, |
a56a1ba4 |
384 | &window_end, |
385 | &time); |
8b90e648 |
386 | |
ba90bc77 |
387 | set_current_time(control_flow_data->mw, &time); |
8b90e648 |
388 | |
a56a1ba4 |
389 | } |
ebf4f735 |
390 | |
391 | set_focused_pane(control_flow_data->mw, gtk_widget_get_parent(control_flow_data->scrolled_window)); |
a56a1ba4 |
392 | |
393 | return FALSE; |
8b90e648 |
394 | } |
395 | |
396 | |
397 | |
398 | |
68997a22 |
399 | Drawing_t *drawing_construct(ControlFlowData *control_flow_data) |
847b479d |
400 | { |
501d5405 |
401 | Drawing_t *drawing = g_new(Drawing_t, 1); |
3cb8b205 |
402 | |
501d5405 |
403 | drawing->control_flow_data = control_flow_data; |
a56a1ba4 |
404 | |
3cb8b205 |
405 | drawing->vbox = gtk_vbox_new(FALSE, 1); |
3cb8b205 |
406 | drawing->ruler = gtk_drawing_area_new (); |
407 | gtk_widget_set_size_request(drawing->ruler, -1, 27); |
3cb8b205 |
408 | |
409 | drawing->drawing_area = gtk_drawing_area_new (); |
410 | |
411 | gtk_box_pack_start(GTK_BOX(drawing->vbox), drawing->ruler, |
412 | FALSE, FALSE, 0); |
3cb8b205 |
413 | gtk_box_pack_end(GTK_BOX(drawing->vbox), drawing->drawing_area, |
414 | TRUE, TRUE, 0); |
3cb8b205 |
415 | |
501d5405 |
416 | drawing->pango_layout = |
417 | gtk_widget_create_pango_layout(drawing->drawing_area, NULL); |
a56a1ba4 |
418 | |
501d5405 |
419 | //gtk_widget_set_size_request(drawing->drawing_area->window, 50, 50); |
a56a1ba4 |
420 | g_object_set_data_full( |
501d5405 |
421 | G_OBJECT(drawing->drawing_area), |
422 | "Link_drawing_Data", |
423 | drawing, |
a56a1ba4 |
424 | (GDestroyNotify)drawing_destroy); |
425 | |
3cb8b205 |
426 | g_object_set_data( |
427 | G_OBJECT(drawing->ruler), |
428 | "drawing", |
429 | drawing); |
430 | |
431 | |
501d5405 |
432 | //gtk_widget_modify_bg( drawing->drawing_area, |
a56a1ba4 |
433 | // GTK_STATE_NORMAL, |
434 | // &CF_Colors[BLACK]); |
435 | |
501d5405 |
436 | //gdk_window_get_geometry(drawing->drawing_area->window, |
a56a1ba4 |
437 | // NULL, NULL, |
501d5405 |
438 | // &(drawing->width), |
439 | // &(drawing->height), |
a56a1ba4 |
440 | // -1); |
441 | |
501d5405 |
442 | //drawing->pixmap = gdk_pixmap_new( |
443 | // drawing->drawing_area->window, |
444 | // drawing->width, |
445 | // drawing->height, |
446 | // drawing->depth); |
a56a1ba4 |
447 | |
501d5405 |
448 | drawing->pixmap = NULL; |
a56a1ba4 |
449 | |
501d5405 |
450 | // drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window, |
451 | // drawing->drawing_area->allocation.width, |
452 | // drawing->drawing_area->allocation.height, |
a56a1ba4 |
453 | // -1); |
454 | |
501d5405 |
455 | gtk_widget_add_events(drawing->drawing_area, GDK_BUTTON_PRESS_MASK); |
a56a1ba4 |
456 | |
501d5405 |
457 | g_signal_connect (G_OBJECT(drawing->drawing_area), |
a56a1ba4 |
458 | "configure_event", |
459 | G_CALLBACK (configure_event), |
501d5405 |
460 | (gpointer)drawing); |
3cb8b205 |
461 | |
462 | g_signal_connect (G_OBJECT(drawing->ruler), |
463 | "expose_event", |
464 | G_CALLBACK(expose_ruler), |
465 | (gpointer)drawing); |
466 | |
d287af9a |
467 | gtk_widget_add_events(drawing->ruler, GDK_POINTER_MOTION_MASK); |
468 | |
469 | g_signal_connect (G_OBJECT(drawing->ruler), |
470 | "motion-notify-event", |
471 | G_CALLBACK(motion_notify_ruler), |
472 | (gpointer)drawing); |
473 | |
474 | |
501d5405 |
475 | g_signal_connect (G_OBJECT(drawing->drawing_area), |
a56a1ba4 |
476 | "expose_event", |
477 | G_CALLBACK (expose_event), |
501d5405 |
478 | (gpointer)drawing); |
a56a1ba4 |
479 | |
501d5405 |
480 | g_signal_connect (G_OBJECT(drawing->drawing_area), |
a56a1ba4 |
481 | "button-press-event", |
482 | G_CALLBACK (button_press_event), |
501d5405 |
483 | (gpointer)drawing); |
3cb8b205 |
484 | |
485 | gtk_widget_show(drawing->ruler); |
486 | gtk_widget_show(drawing->drawing_area); |
487 | |
a56a1ba4 |
488 | |
501d5405 |
489 | return drawing; |
f0d936c0 |
490 | } |
491 | |
501d5405 |
492 | void drawing_destroy(Drawing_t *drawing) |
f0d936c0 |
493 | { |
494 | |
a56a1ba4 |
495 | // Do not unref here, Drawing_t destroyed by it's widget. |
501d5405 |
496 | //g_object_unref( G_OBJECT(drawing->drawing_area)); |
a56a1ba4 |
497 | |
501d5405 |
498 | g_free(drawing->pango_layout); |
499 | g_free(drawing); |
f0d936c0 |
500 | } |
501 | |
3cb8b205 |
502 | GtkWidget *drawing_get_drawing_area(Drawing_t *drawing) |
76a67e8a |
503 | { |
501d5405 |
504 | return drawing->drawing_area; |
76a67e8a |
505 | } |
506 | |
3cb8b205 |
507 | GtkWidget *drawing_get_widget(Drawing_t *drawing) |
508 | { |
509 | return drawing->vbox; |
510 | } |
511 | |
f66eba62 |
512 | /* convert_pixels_to_time |
f0d936c0 |
513 | * |
f66eba62 |
514 | * Convert from window pixel and time interval to an absolute time. |
f0d936c0 |
515 | */ |
fa2c4dbe |
516 | void convert_pixels_to_time( |
a56a1ba4 |
517 | gint width, |
518 | guint x, |
519 | LttTime *window_time_begin, |
520 | LttTime *window_time_end, |
521 | LttTime *time) |
f0d936c0 |
522 | { |
a56a1ba4 |
523 | LttTime window_time_interval; |
524 | |
525 | window_time_interval = ltt_time_sub(*window_time_end, |
308711e5 |
526 | *window_time_begin); |
a56a1ba4 |
527 | *time = ltt_time_mul(window_time_interval, (x/(float)width)); |
528 | *time = ltt_time_add(*window_time_begin, *time); |
fa2c4dbe |
529 | } |
530 | |
531 | |
532 | |
533 | void convert_time_to_pixels( |
a56a1ba4 |
534 | LttTime window_time_begin, |
535 | LttTime window_time_end, |
536 | LttTime time, |
537 | int width, |
538 | guint *x) |
fa2c4dbe |
539 | { |
a56a1ba4 |
540 | LttTime window_time_interval; |
541 | float interval_float, time_float; |
542 | |
543 | window_time_interval = ltt_time_sub(window_time_end,window_time_begin); |
544 | |
545 | time = ltt_time_sub(time, window_time_begin); |
546 | |
547 | interval_float = ltt_time_to_double(window_time_interval); |
548 | time_float = ltt_time_to_double(time); |
549 | |
550 | *x = (guint)(time_float/interval_float * width); |
551 | |
f0d936c0 |
552 | } |
553 | |
501d5405 |
554 | void drawing_refresh ( Drawing_t *drawing, |
a56a1ba4 |
555 | guint x, guint y, |
556 | guint width, guint height) |
847b479d |
557 | { |
a56a1ba4 |
558 | g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x, y, width, height); |
559 | GdkRectangle update_rect; |
560 | |
561 | gdk_draw_drawable( |
501d5405 |
562 | drawing->drawing_area->window, |
563 | drawing->drawing_area-> |
564 | style->fg_gc[GTK_WIDGET_STATE (drawing->drawing_area)], |
565 | GDK_DRAWABLE(drawing->pixmap), |
a56a1ba4 |
566 | x, y, |
567 | x, y, |
568 | width, height); |
569 | |
570 | update_rect.x = 0 ; |
571 | update_rect.y = 0 ; |
501d5405 |
572 | update_rect.width = drawing->width; |
573 | update_rect.height = drawing->height ; |
574 | gtk_widget_draw( drawing->drawing_area, &update_rect); |
f7afe191 |
575 | |
847b479d |
576 | } |
577 | |
578 | |
501d5405 |
579 | void drawing_draw_line( Drawing_t *drawing, |
b6db18f8 |
580 | GdkPixmap *pixmap, |
a56a1ba4 |
581 | guint x1, guint y1, |
582 | guint x2, guint y2, |
583 | GdkGC *GC) |
847b479d |
584 | { |
b6db18f8 |
585 | gdk_draw_line (pixmap, |
a56a1ba4 |
586 | GC, |
587 | x1, y1, x2, y2); |
847b479d |
588 | } |
589 | |
590 | |
fa2c4dbe |
591 | |
592 | |
501d5405 |
593 | void drawing_resize(Drawing_t *drawing, guint h, guint w) |
f0d936c0 |
594 | { |
501d5405 |
595 | drawing->height = h ; |
596 | drawing->width = w ; |
a56a1ba4 |
597 | |
501d5405 |
598 | gtk_widget_set_size_request ( drawing->drawing_area, |
599 | drawing->width, |
600 | drawing->height); |
a56a1ba4 |
601 | |
602 | |
f0d936c0 |
603 | } |
847b479d |
604 | |
605 | |
5f16133f |
606 | /* Insert a square corresponding to a new process in the list */ |
501d5405 |
607 | /* Applies to whole drawing->width */ |
608 | void drawing_insert_square(Drawing_t *drawing, |
a56a1ba4 |
609 | guint y, |
610 | guint height) |
5f16133f |
611 | { |
a56a1ba4 |
612 | //GdkRectangle update_rect; |
5f16133f |
613 | |
a56a1ba4 |
614 | /* Allocate a new pixmap with new height */ |
501d5405 |
615 | GdkPixmap *pixmap = gdk_pixmap_new(drawing->drawing_area->window, |
616 | drawing->width + SAFETY, |
617 | drawing->height + height + SAFETY, |
a56a1ba4 |
618 | -1); |
619 | |
620 | /* Copy the high region */ |
b6db18f8 |
621 | gdk_draw_drawable (pixmap, |
501d5405 |
622 | drawing->drawing_area->style->black_gc, |
623 | drawing->pixmap, |
a56a1ba4 |
624 | 0, 0, |
625 | 0, 0, |
501d5405 |
626 | drawing->width + SAFETY, y); |
5f16133f |
627 | |
628 | |
629 | |
5f16133f |
630 | |
a56a1ba4 |
631 | /* add an empty square */ |
b6db18f8 |
632 | gdk_draw_rectangle (pixmap, |
cfe526b1 |
633 | drawing->drawing_area->style->black_gc, |
a56a1ba4 |
634 | TRUE, |
635 | 0, y, |
501d5405 |
636 | drawing->width + SAFETY, // do not overlap |
a56a1ba4 |
637 | height); |
5f16133f |
638 | |
639 | |
5f16133f |
640 | |
a56a1ba4 |
641 | /* copy the bottom of the region */ |
b6db18f8 |
642 | gdk_draw_drawable (pixmap, |
501d5405 |
643 | drawing->drawing_area->style->black_gc, |
644 | drawing->pixmap, |
a56a1ba4 |
645 | 0, y, |
646 | 0, y + height, |
501d5405 |
647 | drawing->width+SAFETY, drawing->height - y + SAFETY); |
5f16133f |
648 | |
649 | |
650 | |
5f16133f |
651 | |
501d5405 |
652 | if (drawing->pixmap) |
653 | gdk_pixmap_unref(drawing->pixmap); |
5f16133f |
654 | |
501d5405 |
655 | drawing->pixmap = pixmap; |
a56a1ba4 |
656 | |
501d5405 |
657 | drawing->height+=height; |
a56a1ba4 |
658 | |
501d5405 |
659 | /* Rectangle to update, from new drawing dimensions */ |
a56a1ba4 |
660 | //update_rect.x = 0 ; |
661 | //update_rect.y = y ; |
501d5405 |
662 | //update_rect.width = drawing->width; |
663 | //update_rect.height = drawing->height - y ; |
664 | //gtk_widget_draw( drawing->drawing_area, &update_rect); |
5f16133f |
665 | } |
666 | |
667 | |
668 | /* Remove a square corresponding to a removed process in the list */ |
501d5405 |
669 | void drawing_remove_square(Drawing_t *drawing, |
a56a1ba4 |
670 | guint y, |
671 | guint height) |
5f16133f |
672 | { |
a56a1ba4 |
673 | //GdkRectangle update_rect; |
674 | |
675 | /* Allocate a new pixmap with new height */ |
b6db18f8 |
676 | GdkPixmap *pixmap = gdk_pixmap_new( |
501d5405 |
677 | drawing->drawing_area->window, |
678 | drawing->width + SAFETY, |
679 | drawing->height - height + SAFETY, |
a56a1ba4 |
680 | -1); |
681 | |
682 | /* Copy the high region */ |
b6db18f8 |
683 | gdk_draw_drawable (pixmap, |
501d5405 |
684 | drawing->drawing_area->style->black_gc, |
685 | drawing->pixmap, |
a56a1ba4 |
686 | 0, 0, |
687 | 0, 0, |
501d5405 |
688 | drawing->width + SAFETY, y); |
a56a1ba4 |
689 | |
690 | |
691 | |
692 | /* Copy up the bottom of the region */ |
b6db18f8 |
693 | gdk_draw_drawable (pixmap, |
501d5405 |
694 | drawing->drawing_area->style->black_gc, |
695 | drawing->pixmap, |
a56a1ba4 |
696 | 0, y + height, |
697 | 0, y, |
501d5405 |
698 | drawing->width, drawing->height - y - height + SAFETY); |
a56a1ba4 |
699 | |
700 | |
501d5405 |
701 | if (drawing->pixmap) |
702 | gdk_pixmap_unref(drawing->pixmap); |
a56a1ba4 |
703 | |
501d5405 |
704 | drawing->pixmap = pixmap; |
a56a1ba4 |
705 | |
501d5405 |
706 | drawing->height-=height; |
a56a1ba4 |
707 | |
501d5405 |
708 | /* Rectangle to update, from new drawing dimensions */ |
a56a1ba4 |
709 | //update_rect.x = 0 ; |
710 | //update_rect.y = y ; |
501d5405 |
711 | //update_rect.width = drawing->width; |
712 | //update_rect.height = drawing->height - y ; |
713 | //gtk_widget_draw( drawing->drawing_area, &update_rect); |
5f16133f |
714 | } |
189a5d08 |
715 | |
3cb8b205 |
716 | void drawing_update_ruler(Drawing_t *drawing, TimeWindow *time_window) |
717 | { |
718 | GtkRequisition req; |
719 | GdkRectangle rect; |
720 | |
721 | req.width = drawing->ruler->allocation.width; |
722 | req.height = drawing->ruler->allocation.height; |
723 | |
724 | |
725 | rect.x = 0; |
726 | rect.y = 0; |
727 | rect.width = req.width; |
728 | rect.height = req.height; |
729 | |
730 | gtk_widget_queue_draw(drawing->ruler); |
731 | //gtk_widget_draw( drawing->ruler, &rect); |
732 | } |
733 | |
734 | /* Redraw the ruler */ |
735 | static gboolean |
736 | expose_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data ) |
737 | { |
738 | Drawing_t *drawing = (Drawing_t*)user_data; |
739 | |
740 | gchar text[255]; |
741 | |
742 | PangoContext *context; |
743 | PangoLayout *layout; |
744 | PangoAttribute *attribute; |
745 | PangoFontDescription *FontDesc; |
746 | gint Font_Size; |
747 | PangoRectangle ink_rect; |
748 | guint global_width=0; |
749 | GdkColor foreground = { 0, 0, 0, 0 }; |
750 | GdkColor background = { 0, 0xffff, 0xffff, 0xffff }; |
751 | |
752 | LttTime window_end = |
753 | ltt_time_add(drawing->control_flow_data->time_window.time_width, |
754 | drawing->control_flow_data->time_window.start_time); |
755 | LttTime half_width = |
756 | ltt_time_div(drawing->control_flow_data->time_window.time_width,2.0); |
757 | LttTime window_middle = |
758 | ltt_time_add(half_width, |
759 | drawing->control_flow_data->time_window.start_time); |
2a2fa4f0 |
760 | g_debug("ruler expose event"); |
3cb8b205 |
761 | |
762 | gdk_draw_rectangle (drawing->ruler->window, |
763 | drawing->ruler->style->white_gc, |
764 | TRUE, |
765 | event->area.x, event->area.y, |
766 | event->area.width, |
767 | event->area.height); |
768 | |
769 | GdkGC *gc = gdk_gc_new(drawing->ruler->window); |
770 | gdk_gc_copy(gc, drawing->ruler->style->black_gc); |
771 | gdk_gc_set_line_attributes(gc, |
772 | 2, |
773 | GDK_LINE_SOLID, |
774 | GDK_CAP_BUTT, |
775 | GDK_JOIN_MITER); |
776 | gdk_draw_line (drawing->ruler->window, |
777 | gc, |
778 | event->area.x, 1, |
779 | event->area.x + event->area.width, 1); |
780 | |
781 | |
782 | snprintf(text, 255, "%lus\n%luns", |
783 | drawing->control_flow_data->time_window.start_time.tv_sec, |
784 | drawing->control_flow_data->time_window.start_time.tv_nsec); |
785 | |
786 | layout = gtk_widget_create_pango_layout(drawing->drawing_area, NULL); |
787 | |
788 | context = pango_layout_get_context(layout); |
789 | FontDesc = pango_context_get_font_description(context); |
790 | |
791 | pango_font_description_set_size(FontDesc, 6*PANGO_SCALE); |
792 | pango_layout_context_changed(layout); |
793 | |
794 | pango_layout_set_text(layout, text, -1); |
795 | pango_layout_get_pixel_extents(layout, &ink_rect, NULL); |
796 | global_width += ink_rect.width; |
797 | |
798 | gdk_draw_layout_with_colors(drawing->ruler->window, |
799 | gc, |
800 | 0, |
801 | 6, |
802 | layout, &foreground, &background); |
803 | |
804 | gdk_gc_set_line_attributes(gc, |
805 | 2, |
806 | GDK_LINE_SOLID, |
807 | GDK_CAP_ROUND, |
808 | GDK_JOIN_ROUND); |
809 | |
810 | gdk_draw_line (drawing->ruler->window, |
811 | gc, |
812 | 1, 1, |
813 | 1, 7); |
814 | |
815 | |
816 | snprintf(text, 255, "%lus\n%luns", window_end.tv_sec, |
817 | window_end.tv_nsec); |
818 | |
819 | pango_layout_set_text(layout, text, -1); |
820 | pango_layout_get_pixel_extents(layout, &ink_rect, NULL); |
821 | global_width += ink_rect.width; |
822 | |
823 | if(global_width <= drawing->ruler->allocation.width) |
824 | { |
825 | gdk_draw_layout_with_colors(drawing->ruler->window, |
826 | gc, |
827 | drawing->ruler->allocation.width - ink_rect.width, |
828 | 6, |
829 | layout, &foreground, &background); |
830 | |
831 | gdk_gc_set_line_attributes(gc, |
832 | 2, |
833 | GDK_LINE_SOLID, |
834 | GDK_CAP_ROUND, |
835 | GDK_JOIN_ROUND); |
836 | |
837 | gdk_draw_line (drawing->ruler->window, |
838 | gc, |
839 | drawing->ruler->allocation.width-1, 1, |
840 | drawing->ruler->allocation.width-1, 7); |
841 | } |
842 | |
843 | |
844 | snprintf(text, 255, "%lus\n%luns", window_middle.tv_sec, |
845 | window_middle.tv_nsec); |
846 | |
847 | pango_layout_set_text(layout, text, -1); |
848 | pango_layout_get_pixel_extents(layout, &ink_rect, NULL); |
849 | global_width += ink_rect.width; |
850 | |
851 | if(global_width <= drawing->ruler->allocation.width) |
852 | { |
853 | gdk_draw_layout_with_colors(drawing->ruler->window, |
854 | gc, |
855 | (drawing->ruler->allocation.width - ink_rect.width)/2, |
856 | 6, |
857 | layout, &foreground, &background); |
858 | |
859 | gdk_gc_set_line_attributes(gc, |
860 | 2, |
861 | GDK_LINE_SOLID, |
862 | GDK_CAP_ROUND, |
863 | GDK_JOIN_ROUND); |
864 | |
865 | gdk_draw_line (drawing->ruler->window, |
866 | gc, |
867 | drawing->ruler->allocation.width/2, 1, |
868 | drawing->ruler->allocation.width/2, 7); |
869 | |
870 | |
871 | |
872 | |
873 | } |
874 | |
875 | gdk_gc_unref(gc); |
876 | g_object_unref(layout); |
877 | |
878 | return FALSE; |
879 | } |
880 | |
189a5d08 |
881 | |
d287af9a |
882 | /* notify mouse on ruler */ |
883 | static gboolean |
884 | motion_notify_ruler(GtkWidget *widget, GdkEventMotion *event, gpointer user_data) |
885 | { |
2a2fa4f0 |
886 | //g_debug("motion"); |
d287af9a |
887 | //eventually follow mouse and show time here |
888 | } |