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