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