we can show dots
[lttv.git] / ltt / branches / poly / lttv / modules / guiControlFlow / Drawing.c
CommitLineData
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 23typedef enum
24{
25 RED,
26 GREEN,
27 BLUE,
28 WHITE,
29 BLACK
30
31} ControlFlowColors;
32
33/* Vector of unallocated colors */
34static 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 47void 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
e9a9c513 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
80a52ff8 73 convert_pixels_to_time(Drawing->Drawing_Area_V->allocation.width, x,
f66eba62 74 &control_flow_data->Time_Window.start_time,
75 &window_end,
76 &start);
77
80a52ff8 78 convert_pixels_to_time(Drawing->Drawing_Area_V->allocation.width, x + width,
f66eba62 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
f7afe191 86 gdk_draw_rectangle (*Pixmap,
847b479d 87 Drawing->Drawing_Area_V->style->white_gc,
88 TRUE,
89 x, y,
90 width, // do not overlap
91 height);
92
e9a9c513 93 //send_test_process(
94 //guicontrolflow_get_process_list(Drawing->Control_Flow_Data),
95 //Drawing);
f66eba62 96 //send_test_drawing(
97 //guicontrolflow_get_process_list(Drawing->Control_Flow_Data),
98 //Drawing, *Pixmap, x, y, width, height);
831a876d 99
8d088fb2 100 // Let's call processTrace() !!
f66eba62 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
e9a9c513 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
f66eba62 112 LttvHooks *event = lttv_hooks_new();
80a52ff8 113 state_add_event_hooks_api(control_flow_data->Parent_Window);
f66eba62 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
80a52ff8 124 state_remove_event_hooks_api(control_flow_data->Parent_Window);
f66eba62 125 lttv_hooks_destroy(event);
847b479d 126}
127
128/* Callbacks */
129
130
131/* Create a new backing pixmap of the appropriate size */
132static gboolean
133configure_event( GtkWidget *widget, GdkEventConfigure *event,
134 gpointer user_data)
f0d936c0 135{
847b479d 136 Drawing_t *Drawing = (Drawing_t*)user_data;
f0d936c0 137
f7afe191 138 /* New Pixmap, size of the configure event */
847b479d 139 GdkPixmap *Pixmap = gdk_pixmap_new(widget->window,
140 widget->allocation.width,
141 widget->allocation.height,
142 -1);
143
f7afe191 144 g_critical("drawing configure event");
145
146 /* If no old Pixmap present */
847b479d 147 if(Drawing->Pixmap == NULL)
148 {
f7afe191 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);
847b479d 156 Drawing->width = widget->allocation.width;
157 Drawing->height = widget->allocation.height;
f7afe191 158g_critical("init data");
847b479d 159 /* Initial data request */
4c69e0cc 160 drawing_data_request(Drawing, &Drawing->Pixmap, 0, 0,
847b479d 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
80a52ff8 181 if (Drawing->Pixmap)
182 gdk_pixmap_unref(Drawing->Pixmap);
183
184 Drawing->Pixmap = Pixmap;
185
847b479d 186 /* Request data for missing space */
f7afe191 187g_critical("missing data");
4c69e0cc 188 drawing_data_request(Drawing, &Pixmap, Drawing->width, 0,
847b479d 189 widget->allocation.width - Drawing->width,
190 widget->allocation.height);
4c69e0cc 191 drawing_data_request(Drawing, &Pixmap, 0, Drawing->height,
847b479d 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
847b479d 211
847b479d 212
847b479d 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 */
221static gboolean
222expose_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
4c69e0cc 237Drawing_t *drawing_construct(ControlFlowData *Control_Flow_Data)
847b479d 238{
76a67e8a 239 Drawing_t *Drawing = g_new(Drawing_t, 1);
f0d936c0 240
241 Drawing->Drawing_Area_V = gtk_drawing_area_new ();
f7afe191 242 Drawing->Control_Flow_Data = Control_Flow_Data;
243
847b479d 244 //gtk_widget_set_size_request(Drawing->Drawing_Area_V->window, 50, 50);
f0d936c0 245 g_object_set_data_full(
246 G_OBJECT(Drawing->Drawing_Area_V),
76a67e8a 247 "Link_Drawing_Data",
f0d936c0 248 Drawing,
3cff8cc1 249 (GDestroyNotify)drawing_destroy);
f0d936c0 250
847b479d 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
847b479d 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
f0d936c0 284 return Drawing;
285}
286
4c69e0cc 287void drawing_destroy(Drawing_t *Drawing)
f0d936c0 288{
289
76a67e8a 290 // Do not unref here, Drawing_t destroyed by it's widget.
291 //g_object_unref( G_OBJECT(Drawing->Drawing_Area_V));
f0d936c0 292
293 g_free(Drawing);
294}
295
4c69e0cc 296GtkWidget *drawing_get_widget(Drawing_t *Drawing)
76a67e8a 297{
298 return Drawing->Drawing_Area_V;
299}
300
f66eba62 301/* convert_pixels_to_time
f0d936c0 302 *
f66eba62 303 * Convert from window pixel and time interval to an absolute time.
f0d936c0 304 */
fa2c4dbe 305void convert_pixels_to_time(
e9a9c513 306 gint width,
fa2c4dbe 307 guint x,
308 LttTime *window_time_begin,
309 LttTime *window_time_end,
76a67e8a 310 LttTime *time)
f0d936c0 311{
fa2c4dbe 312 LttTime window_time_interval;
f0d936c0 313
308711e5 314 window_time_interval = ltt_time_sub(*window_time_end,
315 *window_time_begin);
e9a9c513 316 *time = ltt_time_mul(window_time_interval, (x/(float)width));
308711e5 317 *time = ltt_time_add(*window_time_begin, *time);
fa2c4dbe 318}
319
320
321
322void convert_time_to_pixels(
323 LttTime window_time_begin,
324 LttTime window_time_end,
325 LttTime time,
e9a9c513 326 int width,
76a67e8a 327 guint *x)
fa2c4dbe 328{
329 LttTime window_time_interval;
76a67e8a 330 float interval_float, time_float;
fa2c4dbe 331
308711e5 332 window_time_interval = ltt_time_sub(window_time_end,window_time_begin);
fa2c4dbe 333
308711e5 334 time = ltt_time_sub(time, window_time_begin);
fa2c4dbe 335
308711e5 336 interval_float = ltt_time_to_double(window_time_interval);
337 time_float = ltt_time_to_double(time);
76a67e8a 338
e9a9c513 339 *x = (guint)(time_float/interval_float * width);
f0d936c0 340
341}
342
4c69e0cc 343void drawing_refresh ( Drawing_t *Drawing,
847b479d 344 guint x, guint y,
345 guint width, guint height)
346{
6d5ed1c3 347 g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x, y, width, height);
f7afe191 348 GdkRectangle update_rect;
349
847b479d 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);
f7afe191 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
847b479d 365}
366
367
4c69e0cc 368void drawing_draw_line( Drawing_t *Drawing,
847b479d 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
fa2c4dbe 380
381
4c69e0cc 382void drawing_resize(Drawing_t *Drawing, guint h, guint w)
f0d936c0 383{
f0d936c0 384 Drawing->height = h ;
76a67e8a 385 Drawing->width = w ;
f0d936c0 386
76a67e8a 387 gtk_widget_set_size_request ( Drawing->Drawing_Area_V,
388 Drawing->width,
f0d936c0 389 Drawing->height);
390
391
392}
847b479d 393
394
5f16133f 395/* Insert a square corresponding to a new process in the list */
396/* Applies to whole Drawing->width */
4c69e0cc 397void drawing_insert_square(Drawing_t *Drawing,
5f16133f 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,
1ab3d149 422 Drawing->Drawing_Area_V->style->black_gc,
5f16133f 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 */
4c69e0cc 458void drawing_remove_square(Drawing_t *Drawing,
5f16133f 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}
189a5d08 504
505
This page took 0.046145 seconds and 4 git commands to generate.