we can show dots
[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 /* New Pixmap, size of the configure event */
139 GdkPixmap *Pixmap = gdk_pixmap_new(widget->window,
140 widget->allocation.width,
141 widget->allocation.height,
142 -1);
143
144 g_critical("drawing configure event");
145
146 /* If no old Pixmap present */
147 if(Drawing->Pixmap == NULL)
148 {
149 Drawing->Pixmap = gdk_pixmap_new(
150 widget->window,
151 widget->allocation.width,
152 widget->allocation.height,
153 //ProcessList_get_height
154 // (GuiControlFlow_get_Process_List(Drawing->Control_Flow_Data)),
155 -1);
156 Drawing->width = widget->allocation.width;
157 Drawing->height = widget->allocation.height;
158 g_critical("init data");
159 /* Initial data request */
160 drawing_data_request(Drawing, &Drawing->Pixmap, 0, 0,
161 widget->allocation.width,
162 widget->allocation.height);
163
164 }
165 // /* Draw empty background */
166 // gdk_draw_rectangle (Pixmap,
167 // widget->style->black_gc,
168 // TRUE,
169 // 0, 0,
170 // widget->allocation.width,
171 // widget->allocation.height);
172
173 /* Copy old data to new pixmap */
174 gdk_draw_drawable (Pixmap,
175 widget->style->white_gc,
176 Drawing->Pixmap,
177 0, 0,
178 0, 0,
179 -1, -1);
180
181 if (Drawing->Pixmap)
182 gdk_pixmap_unref(Drawing->Pixmap);
183
184 Drawing->Pixmap = Pixmap;
185
186 /* Request data for missing space */
187 g_critical("missing data");
188 drawing_data_request(Drawing, &Pixmap, Drawing->width, 0,
189 widget->allocation.width - Drawing->width,
190 widget->allocation.height);
191 drawing_data_request(Drawing, &Pixmap, 0, Drawing->height,
192 Drawing->width,
193 widget->allocation.height - Drawing->height);
194
195 // gdk_draw_rectangle (Pixmap,
196 // widget->style->white_gc,
197 // TRUE,
198 // Drawing->width, 0,
199 // widget->allocation.width -
200 // Drawing->width,
201 // widget->allocation.height);
202
203 // gdk_draw_rectangle (Pixmap,
204 // widget->style->white_gc,
205 // TRUE,
206 // 0, Drawing->height,
207 // Drawing->width, // do not overlap
208 // widget->allocation.height -
209 // Drawing->height);
210
211
212
213 Drawing->width = widget->allocation.width;
214 Drawing->height = widget->allocation.height;
215
216 return TRUE;
217 }
218
219
220 /* Redraw the screen from the backing pixmap */
221 static gboolean
222 expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
223 {
224 Drawing_t *Drawing = (Drawing_t*)user_data;
225 g_critical("drawing expose event");
226
227 gdk_draw_pixmap(widget->window,
228 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
229 Drawing->Pixmap,
230 event->area.x, event->area.y,
231 event->area.x, event->area.y,
232 event->area.width, event->area.height);
233
234 return FALSE;
235 }
236
237 Drawing_t *drawing_construct(ControlFlowData *Control_Flow_Data)
238 {
239 Drawing_t *Drawing = g_new(Drawing_t, 1);
240
241 Drawing->Drawing_Area_V = gtk_drawing_area_new ();
242 Drawing->Control_Flow_Data = Control_Flow_Data;
243
244 //gtk_widget_set_size_request(Drawing->Drawing_Area_V->window, 50, 50);
245 g_object_set_data_full(
246 G_OBJECT(Drawing->Drawing_Area_V),
247 "Link_Drawing_Data",
248 Drawing,
249 (GDestroyNotify)drawing_destroy);
250
251 //gtk_widget_modify_bg( Drawing->Drawing_Area_V,
252 // GTK_STATE_NORMAL,
253 // &CF_Colors[BLACK]);
254
255 //gdk_window_get_geometry(Drawing->Drawing_Area_V->window,
256 // NULL, NULL,
257 // &(Drawing->width),
258 // &(Drawing->height),
259 // -1);
260
261 //Drawing->Pixmap = gdk_pixmap_new(
262 // Drawing->Drawing_Area_V->window,
263 // Drawing->width,
264 // Drawing->height,
265 // Drawing->depth);
266
267 Drawing->Pixmap = NULL;
268
269 // Drawing->Pixmap = gdk_pixmap_new(Drawing->Drawing_Area_V->window,
270 // Drawing->Drawing_Area_V->allocation.width,
271 // Drawing->Drawing_Area_V->allocation.height,
272 // -1);
273
274 g_signal_connect (G_OBJECT(Drawing->Drawing_Area_V),
275 "configure_event",
276 G_CALLBACK (configure_event),
277 (gpointer)Drawing);
278
279 g_signal_connect (G_OBJECT(Drawing->Drawing_Area_V),
280 "expose_event",
281 G_CALLBACK (expose_event),
282 (gpointer)Drawing);
283
284 return Drawing;
285 }
286
287 void drawing_destroy(Drawing_t *Drawing)
288 {
289
290 // Do not unref here, Drawing_t destroyed by it's widget.
291 //g_object_unref( G_OBJECT(Drawing->Drawing_Area_V));
292
293 g_free(Drawing);
294 }
295
296 GtkWidget *drawing_get_widget(Drawing_t *Drawing)
297 {
298 return Drawing->Drawing_Area_V;
299 }
300
301 /* convert_pixels_to_time
302 *
303 * Convert from window pixel and time interval to an absolute time.
304 */
305 void convert_pixels_to_time(
306 gint width,
307 guint x,
308 LttTime *window_time_begin,
309 LttTime *window_time_end,
310 LttTime *time)
311 {
312 LttTime window_time_interval;
313
314 window_time_interval = ltt_time_sub(*window_time_end,
315 *window_time_begin);
316 *time = ltt_time_mul(window_time_interval, (x/(float)width));
317 *time = ltt_time_add(*window_time_begin, *time);
318 }
319
320
321
322 void convert_time_to_pixels(
323 LttTime window_time_begin,
324 LttTime window_time_end,
325 LttTime time,
326 int width,
327 guint *x)
328 {
329 LttTime window_time_interval;
330 float interval_float, time_float;
331
332 window_time_interval = ltt_time_sub(window_time_end,window_time_begin);
333
334 time = ltt_time_sub(time, window_time_begin);
335
336 interval_float = ltt_time_to_double(window_time_interval);
337 time_float = ltt_time_to_double(time);
338
339 *x = (guint)(time_float/interval_float * width);
340
341 }
342
343 void drawing_refresh ( Drawing_t *Drawing,
344 guint x, guint y,
345 guint width, guint height)
346 {
347 g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x, y, width, height);
348 GdkRectangle update_rect;
349
350 gdk_draw_drawable(
351 Drawing->Drawing_Area_V->window,
352 Drawing->Drawing_Area_V->
353 style->fg_gc[GTK_WIDGET_STATE (Drawing->Drawing_Area_V)],
354 GDK_DRAWABLE(Drawing->Pixmap),
355 x, y,
356 x, y,
357 width, height);
358
359 update_rect.x = 0 ;
360 update_rect.y = 0 ;
361 update_rect.width = Drawing->width;
362 update_rect.height = Drawing->height ;
363 gtk_widget_draw( Drawing->Drawing_Area_V, &update_rect);
364
365 }
366
367
368 void drawing_draw_line( Drawing_t *Drawing,
369 GdkPixmap *Pixmap,
370 guint x1, guint y1,
371 guint x2, guint y2,
372 GdkGC *GC)
373 {
374 gdk_draw_line (Pixmap,
375 GC,
376 x1, y1, x2, y2);
377 }
378
379
380
381
382 void drawing_resize(Drawing_t *Drawing, guint h, guint w)
383 {
384 Drawing->height = h ;
385 Drawing->width = w ;
386
387 gtk_widget_set_size_request ( Drawing->Drawing_Area_V,
388 Drawing->width,
389 Drawing->height);
390
391
392 }
393
394
395 /* Insert a square corresponding to a new process in the list */
396 /* Applies to whole Drawing->width */
397 void drawing_insert_square(Drawing_t *Drawing,
398 guint y,
399 guint height)
400 {
401 GdkRectangle update_rect;
402
403 /* Allocate a new pixmap with new height */
404 GdkPixmap *Pixmap = gdk_pixmap_new(Drawing->Drawing_Area_V->window,
405 Drawing->width,
406 Drawing->height + height,
407 -1);
408
409 /* Copy the high region */
410 gdk_draw_drawable (Pixmap,
411 Drawing->Drawing_Area_V->style->black_gc,
412 Drawing->Pixmap,
413 0, 0,
414 0, 0,
415 Drawing->width, y);
416
417
418
419
420 /* add an empty square */
421 gdk_draw_rectangle (Pixmap,
422 Drawing->Drawing_Area_V->style->black_gc,
423 TRUE,
424 0, y,
425 Drawing->width, // do not overlap
426 height);
427
428
429
430 /* copy the bottom of the region */
431 gdk_draw_drawable (Pixmap,
432 Drawing->Drawing_Area_V->style->black_gc,
433 Drawing->Pixmap,
434 0, y,
435 0, y + height,
436 Drawing->width, Drawing->height - y);
437
438
439
440
441 if (Drawing->Pixmap)
442 gdk_pixmap_unref(Drawing->Pixmap);
443
444 Drawing->Pixmap = Pixmap;
445
446 Drawing->height+=height;
447
448 /* Rectangle to update, from new Drawing dimensions */
449 update_rect.x = 0 ;
450 update_rect.y = y ;
451 update_rect.width = Drawing->width;
452 update_rect.height = Drawing->height - y ;
453 gtk_widget_draw( Drawing->Drawing_Area_V, &update_rect);
454 }
455
456
457 /* Remove a square corresponding to a removed process in the list */
458 void drawing_remove_square(Drawing_t *Drawing,
459 guint y,
460 guint height)
461 {
462 GdkRectangle update_rect;
463
464 /* Allocate a new pixmap with new height */
465 GdkPixmap *Pixmap = gdk_pixmap_new(
466 Drawing->Drawing_Area_V->window,
467 Drawing->width,
468 Drawing->height - height,
469 -1);
470
471 /* Copy the high region */
472 gdk_draw_drawable (Pixmap,
473 Drawing->Drawing_Area_V->style->black_gc,
474 Drawing->Pixmap,
475 0, 0,
476 0, 0,
477 Drawing->width, y);
478
479
480
481 /* Copy up the bottom of the region */
482 gdk_draw_drawable (Pixmap,
483 Drawing->Drawing_Area_V->style->black_gc,
484 Drawing->Pixmap,
485 0, y + height,
486 0, y,
487 Drawing->width, Drawing->height - y - height);
488
489
490 if (Drawing->Pixmap)
491 gdk_pixmap_unref(Drawing->Pixmap);
492
493 Drawing->Pixmap = Pixmap;
494
495 Drawing->height-=height;
496
497 /* Rectangle to update, from new Drawing dimensions */
498 update_rect.x = 0 ;
499 update_rect.y = y ;
500 update_rect.width = Drawing->width;
501 update_rect.height = Drawing->height - y ;
502 gtk_widget_draw( Drawing->Drawing_Area_V, &update_rect);
503 }
504
505
This page took 0.064168 seconds and 4 git commands to generate.