fa2c4dbe |
1 | |
76a67e8a |
2 | #include <gtk/gtk.h> |
3 | #include <gdk/gdk.h> |
f0d936c0 |
4 | |
831a876d |
5 | #include <lttv/processTrace.h> |
f66eba62 |
6 | #include <lttv/gtkTraceSet.h> |
7 | #include <lttv/hook.h> |
831a876d |
8 | |
f66eba62 |
9 | #include "Drawing.h" |
10 | #include "CFV.h" |
11 | #include "CFV-private.h" |
12 | #include "Event_Hooks.h" |
6d5ed1c3 |
13 | |
14 | #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format) |
15 | #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format) |
16 | |
17 | |
f0d936c0 |
18 | /***************************************************************************** |
19 | * Drawing functions * |
20 | *****************************************************************************/ |
21 | |
831a876d |
22 | //FIXME Colors will need to be dynamic. Graphic context part not done so far. |
f0d936c0 |
23 | typedef enum |
24 | { |
25 | RED, |
26 | GREEN, |
27 | BLUE, |
28 | WHITE, |
29 | BLACK |
30 | |
31 | } ControlFlowColors; |
32 | |
33 | /* Vector of unallocated colors */ |
34 | static GdkColor CF_Colors [] = |
35 | { |
36 | { 0, 0xffff, 0x0000, 0x0000 }, // RED |
37 | { 0, 0x0000, 0xffff, 0x0000 }, // GREEN |
38 | { 0, 0x0000, 0x0000, 0xffff }, // BLUE |
39 | { 0, 0xffff, 0xffff, 0xffff }, // WHITE |
40 | { 0, 0x0000, 0x0000, 0x0000 } // BLACK |
41 | }; |
42 | |
43 | |
831a876d |
44 | /* Function responsible for updating the exposed area. |
45 | * It must call processTrace() to ask for this update. |
46 | */ |
4c69e0cc |
47 | void drawing_data_request(Drawing_t *Drawing, |
f7afe191 |
48 | GdkPixmap **Pixmap, |
847b479d |
49 | gint x, gint y, |
4c69e0cc |
50 | gint width, |
847b479d |
51 | gint height) |
52 | { |
d9b7ca88 |
53 | if(width < 0) return ; |
54 | if(height < 0) return ; |
f66eba62 |
55 | ControlFlowData *control_flow_data = |
56 | (ControlFlowData*)g_object_get_data( |
57 | G_OBJECT( |
58 | Drawing->Drawing_Area_V), |
59 | "Control_Flow_Data"); |
60 | |
61 | LttTime start, end; |
62 | LttTime window_end = ltt_time_add(control_flow_data->Time_Window.time_width, |
63 | control_flow_data->Time_Window.start_time); |
64 | |
65 | convert_pixels_to_time(Drawing, x, |
66 | &control_flow_data->Time_Window.start_time, |
67 | &window_end, |
68 | &start); |
69 | |
70 | convert_pixels_to_time(Drawing, x + width, |
71 | &control_flow_data->Time_Window.start_time, |
72 | &window_end, |
73 | &end); |
74 | |
75 | LttvTracesetContext * tsc = |
76 | get_traceset_context(control_flow_data->Parent_Window); |
77 | |
f7afe191 |
78 | gdk_draw_rectangle (*Pixmap, |
847b479d |
79 | Drawing->Drawing_Area_V->style->white_gc, |
80 | TRUE, |
81 | x, y, |
82 | width, // do not overlap |
83 | height); |
84 | |
f7afe191 |
85 | send_test_process( |
4c69e0cc |
86 | guicontrolflow_get_process_list(Drawing->Control_Flow_Data), |
f7afe191 |
87 | Drawing); |
f66eba62 |
88 | //send_test_drawing( |
89 | //guicontrolflow_get_process_list(Drawing->Control_Flow_Data), |
90 | //Drawing, *Pixmap, x, y, width, height); |
831a876d |
91 | |
8d088fb2 |
92 | // Let's call processTrace() !! |
f66eba62 |
93 | EventRequest event_request; // Variable freed at the end of the function. |
94 | event_request.Control_Flow_Data = control_flow_data; |
95 | event_request.time_begin = start; |
96 | event_request.time_end = end; |
97 | |
98 | LttvHooks *event = lttv_hooks_new(); |
99 | lttv_hooks_add(event, draw_event_hook, &event_request); |
100 | |
101 | lttv_process_traceset_seek_time(tsc, start); |
102 | lttv_traceset_context_add_hooks(tsc, |
103 | NULL, NULL, NULL, NULL, NULL, NULL, |
104 | NULL, NULL, NULL, event, NULL); |
105 | lttv_process_traceset(tsc, end, G_MAXULONG); |
106 | lttv_traceset_context_remove_hooks(tsc, NULL, NULL, NULL, NULL, NULL, NULL, |
107 | NULL, NULL, NULL, event, NULL); |
108 | |
109 | lttv_hooks_destroy(event); |
847b479d |
110 | } |
111 | |
112 | /* Callbacks */ |
113 | |
114 | |
115 | /* Create a new backing pixmap of the appropriate size */ |
116 | static gboolean |
117 | configure_event( GtkWidget *widget, GdkEventConfigure *event, |
118 | gpointer user_data) |
f0d936c0 |
119 | { |
847b479d |
120 | Drawing_t *Drawing = (Drawing_t*)user_data; |
f0d936c0 |
121 | |
f7afe191 |
122 | /* New Pixmap, size of the configure event */ |
847b479d |
123 | GdkPixmap *Pixmap = gdk_pixmap_new(widget->window, |
124 | widget->allocation.width, |
125 | widget->allocation.height, |
126 | -1); |
127 | |
f7afe191 |
128 | g_critical("drawing configure event"); |
129 | |
130 | /* If no old Pixmap present */ |
847b479d |
131 | if(Drawing->Pixmap == NULL) |
132 | { |
f7afe191 |
133 | Drawing->Pixmap = gdk_pixmap_new( |
134 | widget->window, |
135 | widget->allocation.width, |
136 | widget->allocation.height, |
137 | //ProcessList_get_height |
138 | // (GuiControlFlow_get_Process_List(Drawing->Control_Flow_Data)), |
139 | -1); |
847b479d |
140 | Drawing->width = widget->allocation.width; |
141 | Drawing->height = widget->allocation.height; |
f7afe191 |
142 | g_critical("init data"); |
847b479d |
143 | /* Initial data request */ |
4c69e0cc |
144 | drawing_data_request(Drawing, &Drawing->Pixmap, 0, 0, |
847b479d |
145 | widget->allocation.width, |
146 | widget->allocation.height); |
147 | |
148 | } |
149 | // /* Draw empty background */ |
150 | // gdk_draw_rectangle (Pixmap, |
151 | // widget->style->black_gc, |
152 | // TRUE, |
153 | // 0, 0, |
154 | // widget->allocation.width, |
155 | // widget->allocation.height); |
156 | |
157 | /* Copy old data to new pixmap */ |
158 | gdk_draw_drawable (Pixmap, |
159 | widget->style->white_gc, |
160 | Drawing->Pixmap, |
161 | 0, 0, |
162 | 0, 0, |
163 | -1, -1); |
164 | |
165 | /* Request data for missing space */ |
f7afe191 |
166 | g_critical("missing data"); |
4c69e0cc |
167 | drawing_data_request(Drawing, &Pixmap, Drawing->width, 0, |
847b479d |
168 | widget->allocation.width - Drawing->width, |
169 | widget->allocation.height); |
4c69e0cc |
170 | drawing_data_request(Drawing, &Pixmap, 0, Drawing->height, |
847b479d |
171 | Drawing->width, |
172 | widget->allocation.height - Drawing->height); |
173 | |
174 | // gdk_draw_rectangle (Pixmap, |
175 | // widget->style->white_gc, |
176 | // TRUE, |
177 | // Drawing->width, 0, |
178 | // widget->allocation.width - |
179 | // Drawing->width, |
180 | // widget->allocation.height); |
181 | |
182 | // gdk_draw_rectangle (Pixmap, |
183 | // widget->style->white_gc, |
184 | // TRUE, |
185 | // 0, Drawing->height, |
186 | // Drawing->width, // do not overlap |
187 | // widget->allocation.height - |
188 | // Drawing->height); |
189 | |
847b479d |
190 | |
847b479d |
191 | |
192 | if (Drawing->Pixmap) |
193 | gdk_pixmap_unref(Drawing->Pixmap); |
194 | |
195 | Drawing->Pixmap = Pixmap; |
196 | Drawing->width = widget->allocation.width; |
197 | Drawing->height = widget->allocation.height; |
198 | |
199 | return TRUE; |
200 | } |
201 | |
202 | |
203 | /* Redraw the screen from the backing pixmap */ |
204 | static gboolean |
205 | expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data ) |
206 | { |
207 | Drawing_t *Drawing = (Drawing_t*)user_data; |
208 | g_critical("drawing expose event"); |
209 | |
210 | gdk_draw_pixmap(widget->window, |
211 | widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
212 | Drawing->Pixmap, |
213 | event->area.x, event->area.y, |
214 | event->area.x, event->area.y, |
215 | event->area.width, event->area.height); |
216 | |
217 | return FALSE; |
218 | } |
219 | |
4c69e0cc |
220 | Drawing_t *drawing_construct(ControlFlowData *Control_Flow_Data) |
847b479d |
221 | { |
76a67e8a |
222 | Drawing_t *Drawing = g_new(Drawing_t, 1); |
f0d936c0 |
223 | |
224 | Drawing->Drawing_Area_V = gtk_drawing_area_new (); |
f7afe191 |
225 | Drawing->Control_Flow_Data = Control_Flow_Data; |
226 | |
847b479d |
227 | //gtk_widget_set_size_request(Drawing->Drawing_Area_V->window, 50, 50); |
f0d936c0 |
228 | g_object_set_data_full( |
229 | G_OBJECT(Drawing->Drawing_Area_V), |
76a67e8a |
230 | "Link_Drawing_Data", |
f0d936c0 |
231 | Drawing, |
3cff8cc1 |
232 | (GDestroyNotify)drawing_destroy); |
f0d936c0 |
233 | |
847b479d |
234 | //gtk_widget_modify_bg( Drawing->Drawing_Area_V, |
235 | // GTK_STATE_NORMAL, |
236 | // &CF_Colors[BLACK]); |
237 | |
238 | //gdk_window_get_geometry(Drawing->Drawing_Area_V->window, |
239 | // NULL, NULL, |
240 | // &(Drawing->width), |
241 | // &(Drawing->height), |
242 | // -1); |
243 | |
244 | //Drawing->Pixmap = gdk_pixmap_new( |
245 | // Drawing->Drawing_Area_V->window, |
246 | // Drawing->width, |
247 | // Drawing->height, |
248 | // Drawing->depth); |
249 | |
250 | Drawing->Pixmap = NULL; |
251 | |
252 | // Drawing->Pixmap = gdk_pixmap_new(Drawing->Drawing_Area_V->window, |
253 | // Drawing->Drawing_Area_V->allocation.width, |
254 | // Drawing->Drawing_Area_V->allocation.height, |
255 | // -1); |
256 | |
847b479d |
257 | g_signal_connect (G_OBJECT(Drawing->Drawing_Area_V), |
258 | "configure_event", |
259 | G_CALLBACK (configure_event), |
260 | (gpointer)Drawing); |
261 | |
262 | g_signal_connect (G_OBJECT(Drawing->Drawing_Area_V), |
263 | "expose_event", |
264 | G_CALLBACK (expose_event), |
265 | (gpointer)Drawing); |
266 | |
f0d936c0 |
267 | return Drawing; |
268 | } |
269 | |
4c69e0cc |
270 | void drawing_destroy(Drawing_t *Drawing) |
f0d936c0 |
271 | { |
272 | |
76a67e8a |
273 | // Do not unref here, Drawing_t destroyed by it's widget. |
274 | //g_object_unref( G_OBJECT(Drawing->Drawing_Area_V)); |
f0d936c0 |
275 | |
276 | g_free(Drawing); |
277 | } |
278 | |
4c69e0cc |
279 | GtkWidget *drawing_get_widget(Drawing_t *Drawing) |
76a67e8a |
280 | { |
281 | return Drawing->Drawing_Area_V; |
282 | } |
283 | |
f66eba62 |
284 | /* convert_pixels_to_time |
f0d936c0 |
285 | * |
f66eba62 |
286 | * Convert from window pixel and time interval to an absolute time. |
f0d936c0 |
287 | */ |
fa2c4dbe |
288 | void convert_pixels_to_time( |
289 | Drawing_t *Drawing, |
290 | guint x, |
291 | LttTime *window_time_begin, |
292 | LttTime *window_time_end, |
76a67e8a |
293 | LttTime *time) |
f0d936c0 |
294 | { |
fa2c4dbe |
295 | LttTime window_time_interval; |
f0d936c0 |
296 | |
308711e5 |
297 | window_time_interval = ltt_time_sub(*window_time_end, |
298 | *window_time_begin); |
299 | *time = ltt_time_mul(window_time_interval, (x/(float)Drawing->width)); |
300 | *time = ltt_time_add(*window_time_begin, *time); |
fa2c4dbe |
301 | } |
302 | |
303 | |
304 | |
305 | void convert_time_to_pixels( |
306 | LttTime window_time_begin, |
307 | LttTime window_time_end, |
308 | LttTime time, |
309 | Drawing_t *Drawing, |
76a67e8a |
310 | guint *x) |
fa2c4dbe |
311 | { |
312 | LttTime window_time_interval; |
76a67e8a |
313 | float interval_float, time_float; |
fa2c4dbe |
314 | |
308711e5 |
315 | window_time_interval = ltt_time_sub(window_time_end,window_time_begin); |
fa2c4dbe |
316 | |
308711e5 |
317 | time = ltt_time_sub(time, window_time_begin); |
fa2c4dbe |
318 | |
308711e5 |
319 | interval_float = ltt_time_to_double(window_time_interval); |
320 | time_float = ltt_time_to_double(time); |
76a67e8a |
321 | |
322 | *x = (guint)(time_float/interval_float * Drawing->width); |
f0d936c0 |
323 | |
324 | } |
325 | |
4c69e0cc |
326 | void drawing_refresh ( Drawing_t *Drawing, |
847b479d |
327 | guint x, guint y, |
328 | guint width, guint height) |
329 | { |
6d5ed1c3 |
330 | g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x, y, width, height); |
f7afe191 |
331 | GdkRectangle update_rect; |
332 | |
847b479d |
333 | gdk_draw_drawable( |
334 | Drawing->Drawing_Area_V->window, |
335 | Drawing->Drawing_Area_V-> |
336 | style->fg_gc[GTK_WIDGET_STATE (Drawing->Drawing_Area_V)], |
337 | GDK_DRAWABLE(Drawing->Pixmap), |
338 | x, y, |
339 | x, y, |
340 | width, height); |
f7afe191 |
341 | |
342 | update_rect.x = 0 ; |
343 | update_rect.y = 0 ; |
344 | update_rect.width = Drawing->width; |
345 | update_rect.height = Drawing->height ; |
346 | gtk_widget_draw( Drawing->Drawing_Area_V, &update_rect); |
347 | |
847b479d |
348 | } |
349 | |
350 | |
4c69e0cc |
351 | void drawing_draw_line( Drawing_t *Drawing, |
847b479d |
352 | GdkPixmap *Pixmap, |
353 | guint x1, guint y1, |
354 | guint x2, guint y2, |
355 | GdkGC *GC) |
356 | { |
357 | gdk_draw_line (Pixmap, |
358 | GC, |
359 | x1, y1, x2, y2); |
360 | } |
361 | |
362 | |
fa2c4dbe |
363 | |
364 | |
4c69e0cc |
365 | void drawing_resize(Drawing_t *Drawing, guint h, guint w) |
f0d936c0 |
366 | { |
f0d936c0 |
367 | Drawing->height = h ; |
76a67e8a |
368 | Drawing->width = w ; |
f0d936c0 |
369 | |
76a67e8a |
370 | gtk_widget_set_size_request ( Drawing->Drawing_Area_V, |
371 | Drawing->width, |
f0d936c0 |
372 | Drawing->height); |
373 | |
374 | |
375 | } |
847b479d |
376 | |
377 | |
5f16133f |
378 | /* Insert a square corresponding to a new process in the list */ |
379 | /* Applies to whole Drawing->width */ |
4c69e0cc |
380 | void drawing_insert_square(Drawing_t *Drawing, |
5f16133f |
381 | guint y, |
382 | guint height) |
383 | { |
384 | GdkRectangle update_rect; |
385 | |
386 | /* Allocate a new pixmap with new height */ |
387 | GdkPixmap *Pixmap = gdk_pixmap_new(Drawing->Drawing_Area_V->window, |
388 | Drawing->width, |
389 | Drawing->height + height, |
390 | -1); |
391 | |
392 | /* Copy the high region */ |
393 | gdk_draw_drawable (Pixmap, |
394 | Drawing->Drawing_Area_V->style->black_gc, |
395 | Drawing->Pixmap, |
396 | 0, 0, |
397 | 0, 0, |
398 | Drawing->width, y); |
399 | |
400 | |
401 | |
402 | |
403 | /* add an empty square */ |
404 | gdk_draw_rectangle (Pixmap, |
1ab3d149 |
405 | Drawing->Drawing_Area_V->style->black_gc, |
5f16133f |
406 | TRUE, |
407 | 0, y, |
408 | Drawing->width, // do not overlap |
409 | height); |
410 | |
411 | |
412 | |
413 | /* copy the bottom of the region */ |
414 | gdk_draw_drawable (Pixmap, |
415 | Drawing->Drawing_Area_V->style->black_gc, |
416 | Drawing->Pixmap, |
417 | 0, y, |
418 | 0, y + height, |
419 | Drawing->width, Drawing->height - y); |
420 | |
421 | |
422 | |
423 | |
424 | if (Drawing->Pixmap) |
425 | gdk_pixmap_unref(Drawing->Pixmap); |
426 | |
427 | Drawing->Pixmap = Pixmap; |
428 | |
429 | Drawing->height+=height; |
430 | |
431 | /* Rectangle to update, from new Drawing dimensions */ |
432 | update_rect.x = 0 ; |
433 | update_rect.y = y ; |
434 | update_rect.width = Drawing->width; |
435 | update_rect.height = Drawing->height - y ; |
436 | gtk_widget_draw( Drawing->Drawing_Area_V, &update_rect); |
437 | } |
438 | |
439 | |
440 | /* Remove a square corresponding to a removed process in the list */ |
4c69e0cc |
441 | void drawing_remove_square(Drawing_t *Drawing, |
5f16133f |
442 | guint y, |
443 | guint height) |
444 | { |
445 | GdkRectangle update_rect; |
446 | |
447 | /* Allocate a new pixmap with new height */ |
448 | GdkPixmap *Pixmap = gdk_pixmap_new( |
449 | Drawing->Drawing_Area_V->window, |
450 | Drawing->width, |
451 | Drawing->height - height, |
452 | -1); |
453 | |
454 | /* Copy the high region */ |
455 | gdk_draw_drawable (Pixmap, |
456 | Drawing->Drawing_Area_V->style->black_gc, |
457 | Drawing->Pixmap, |
458 | 0, 0, |
459 | 0, 0, |
460 | Drawing->width, y); |
461 | |
462 | |
463 | |
464 | /* Copy up the bottom of the region */ |
465 | gdk_draw_drawable (Pixmap, |
466 | Drawing->Drawing_Area_V->style->black_gc, |
467 | Drawing->Pixmap, |
468 | 0, y + height, |
469 | 0, y, |
470 | Drawing->width, Drawing->height - y - height); |
471 | |
472 | |
473 | if (Drawing->Pixmap) |
474 | gdk_pixmap_unref(Drawing->Pixmap); |
475 | |
476 | Drawing->Pixmap = Pixmap; |
477 | |
478 | Drawing->height-=height; |
479 | |
480 | /* Rectangle to update, from new Drawing dimensions */ |
481 | update_rect.x = 0 ; |
482 | update_rect.y = y ; |
483 | update_rect.width = Drawing->width; |
484 | update_rect.height = Drawing->height - y ; |
485 | gtk_widget_draw( Drawing->Drawing_Area_V, &update_rect); |
486 | } |
189a5d08 |
487 | |
488 | |