5 #include <lttv/processTrace.h>
6 #include <lttv/gtkTraceSet.h>
11 #include "CFV-private.h"
12 #include "Event_Hooks.h"
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)
18 /*****************************************************************************
20 *****************************************************************************/
22 //FIXME Colors will need to be dynamic. Graphic context part not done so far.
33 /* Vector of unallocated colors */
34 static GdkColor CF_Colors
[] =
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
44 /* Function responsible for updating the exposed area.
45 * It must call processTrace() to ask for this update.
47 void drawing_data_request(Drawing_t
*Drawing
,
53 if(width
< 0) return ;
54 if(height
< 0) return ;
55 ControlFlowData
*control_flow_data
=
56 (ControlFlowData
*)g_object_get_data(
58 Drawing
->Drawing_Area_V
),
62 LttTime window_end
= ltt_time_add(control_flow_data
->Time_Window
.time_width
,
63 control_flow_data
->Time_Window
.start_time
);
65 g_critical("req : window_end : %u, %u", window_end
.tv_sec
,
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
);
71 g_critical("x is : %i, x+width is : %i", x
, x
+width
);
73 convert_pixels_to_time(Drawing
->Drawing_Area_V
->allocation
.width
, x
,
74 &control_flow_data
->Time_Window
.start_time
,
78 convert_pixels_to_time(Drawing
->Drawing_Area_V
->allocation
.width
, x
+ width
,
79 &control_flow_data
->Time_Window
.start_time
,
83 LttvTracesetContext
* tsc
=
84 get_traceset_context(control_flow_data
->Parent_Window
);
86 gdk_draw_rectangle (*Pixmap
,
87 Drawing
->Drawing_Area_V
->style
->white_gc
,
90 width
, // do not overlap
94 //guicontrolflow_get_process_list(Drawing->Control_Flow_Data),
97 //guicontrolflow_get_process_list(Drawing->Control_Flow_Data),
98 //Drawing, *Pixmap, x, y, width, height);
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
;
106 g_critical("req : start : %u, %u", event_request
.time_begin
.tv_sec
,
107 event_request
.time_begin
.tv_nsec
);
109 g_critical("req : end : %u, %u", event_request
.time_end
.tv_sec
,
110 event_request
.time_end
.tv_nsec
);
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
);
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
);
124 state_remove_event_hooks_api(control_flow_data
->Parent_Window
);
125 lttv_hooks_destroy(event
);
131 /* Create a new backing pixmap of the appropriate size */
133 configure_event( GtkWidget
*widget
, GdkEventConfigure
*event
,
136 Drawing_t
*Drawing
= (Drawing_t
*)user_data
;
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
144 get_time_window(Drawing
->Control_Flow_Data
->Parent_Window
,
145 &Drawing
->Control_Flow_Data
->Time_Window
);
147 /* New Pixmap, size of the configure event */
148 GdkPixmap
*Pixmap
= gdk_pixmap_new(widget
->window
,
149 widget
->allocation
.width
,
150 widget
->allocation
.height
,
153 g_critical("drawing configure event");
155 /* If no old Pixmap present */
156 if(Drawing
->Pixmap
== NULL
)
158 Drawing
->Pixmap
= gdk_pixmap_new(
160 widget
->allocation
.width
,
161 widget
->allocation
.height
,
162 //ProcessList_get_height
163 // (GuiControlFlow_get_Process_List(Drawing->Control_Flow_Data)),
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
);
174 // /* Draw empty background */
175 // gdk_draw_rectangle (Pixmap,
176 // widget->style->black_gc,
179 // widget->allocation.width,
180 // widget->allocation.height);
182 /* Copy old data to new pixmap */
183 gdk_draw_drawable (Pixmap
,
184 widget
->style
->white_gc
,
191 gdk_pixmap_unref(Drawing
->Pixmap
);
193 Drawing
->Pixmap
= Pixmap
;
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 drawing_data_request(Drawing
, &Pixmap
, 0, Drawing
->height
,
202 widget
->allocation
.height
- Drawing
->height
);
204 // gdk_draw_rectangle (Pixmap,
205 // widget->style->white_gc,
207 // Drawing->width, 0,
208 // widget->allocation.width -
210 // widget->allocation.height);
212 // gdk_draw_rectangle (Pixmap,
213 // widget->style->white_gc,
215 // 0, Drawing->height,
216 // Drawing->width, // do not overlap
217 // widget->allocation.height -
220 Drawing
->width
= widget
->allocation
.width
;
221 Drawing
->height
= widget
->allocation
.height
;
227 /* Redraw the screen from the backing pixmap */
229 expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
231 Drawing_t
*Drawing
= (Drawing_t
*)user_data
;
232 g_critical("drawing expose event");
234 gdk_draw_pixmap(widget
->window
,
235 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
237 event
->area
.x
, event
->area
.y
,
238 event
->area
.x
, event
->area
.y
,
239 event
->area
.width
, event
->area
.height
);
244 Drawing_t
*drawing_construct(ControlFlowData
*Control_Flow_Data
)
246 Drawing_t
*Drawing
= g_new(Drawing_t
, 1);
248 Drawing
->Drawing_Area_V
= gtk_drawing_area_new ();
249 Drawing
->Control_Flow_Data
= Control_Flow_Data
;
251 //gtk_widget_set_size_request(Drawing->Drawing_Area_V->window, 50, 50);
252 g_object_set_data_full(
253 G_OBJECT(Drawing
->Drawing_Area_V
),
256 (GDestroyNotify
)drawing_destroy
);
258 //gtk_widget_modify_bg( Drawing->Drawing_Area_V,
260 // &CF_Colors[BLACK]);
262 //gdk_window_get_geometry(Drawing->Drawing_Area_V->window,
264 // &(Drawing->width),
265 // &(Drawing->height),
268 //Drawing->Pixmap = gdk_pixmap_new(
269 // Drawing->Drawing_Area_V->window,
274 Drawing
->Pixmap
= NULL
;
276 // Drawing->Pixmap = gdk_pixmap_new(Drawing->Drawing_Area_V->window,
277 // Drawing->Drawing_Area_V->allocation.width,
278 // Drawing->Drawing_Area_V->allocation.height,
281 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
283 G_CALLBACK (configure_event
),
286 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
288 G_CALLBACK (expose_event
),
294 void drawing_destroy(Drawing_t
*Drawing
)
297 // Do not unref here, Drawing_t destroyed by it's widget.
298 //g_object_unref( G_OBJECT(Drawing->Drawing_Area_V));
303 GtkWidget
*drawing_get_widget(Drawing_t
*Drawing
)
305 return Drawing
->Drawing_Area_V
;
308 /* convert_pixels_to_time
310 * Convert from window pixel and time interval to an absolute time.
312 void convert_pixels_to_time(
315 LttTime
*window_time_begin
,
316 LttTime
*window_time_end
,
319 LttTime window_time_interval
;
321 window_time_interval
= ltt_time_sub(*window_time_end
,
323 *time
= ltt_time_mul(window_time_interval
, (x
/(float)width
));
324 *time
= ltt_time_add(*window_time_begin
, *time
);
329 void convert_time_to_pixels(
330 LttTime window_time_begin
,
331 LttTime window_time_end
,
336 LttTime window_time_interval
;
337 float interval_float
, time_float
;
339 window_time_interval
= ltt_time_sub(window_time_end
,window_time_begin
);
341 time
= ltt_time_sub(time
, window_time_begin
);
343 interval_float
= ltt_time_to_double(window_time_interval
);
344 time_float
= ltt_time_to_double(time
);
346 *x
= (guint
)(time_float
/interval_float
* width
);
350 void drawing_refresh ( Drawing_t
*Drawing
,
352 guint width
, guint height
)
354 g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x
, y
, width
, height
);
355 GdkRectangle update_rect
;
358 Drawing
->Drawing_Area_V
->window
,
359 Drawing
->Drawing_Area_V
->
360 style
->fg_gc
[GTK_WIDGET_STATE (Drawing
->Drawing_Area_V
)],
361 GDK_DRAWABLE(Drawing
->Pixmap
),
368 update_rect
.width
= Drawing
->width
;
369 update_rect
.height
= Drawing
->height
;
370 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);
375 void drawing_draw_line( Drawing_t
*Drawing
,
381 gdk_draw_line (Pixmap
,
389 void drawing_resize(Drawing_t
*Drawing
, guint h
, guint w
)
391 Drawing
->height
= h
;
394 gtk_widget_set_size_request ( Drawing
->Drawing_Area_V
,
402 /* Insert a square corresponding to a new process in the list */
403 /* Applies to whole Drawing->width */
404 void drawing_insert_square(Drawing_t
*Drawing
,
408 GdkRectangle update_rect
;
410 /* Allocate a new pixmap with new height */
411 GdkPixmap
*Pixmap
= gdk_pixmap_new(Drawing
->Drawing_Area_V
->window
,
413 Drawing
->height
+ height
,
416 /* Copy the high region */
417 gdk_draw_drawable (Pixmap
,
418 Drawing
->Drawing_Area_V
->style
->black_gc
,
427 /* add an empty square */
428 gdk_draw_rectangle (Pixmap
,
429 Drawing
->Drawing_Area_V
->style
->black_gc
,
432 Drawing
->width
, // do not overlap
437 /* copy the bottom of the region */
438 gdk_draw_drawable (Pixmap
,
439 Drawing
->Drawing_Area_V
->style
->black_gc
,
443 Drawing
->width
, Drawing
->height
- y
);
449 gdk_pixmap_unref(Drawing
->Pixmap
);
451 Drawing
->Pixmap
= Pixmap
;
453 Drawing
->height
+=height
;
455 /* Rectangle to update, from new Drawing dimensions */
458 update_rect
.width
= Drawing
->width
;
459 update_rect
.height
= Drawing
->height
- y
;
460 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);
464 /* Remove a square corresponding to a removed process in the list */
465 void drawing_remove_square(Drawing_t
*Drawing
,
469 GdkRectangle update_rect
;
471 /* Allocate a new pixmap with new height */
472 GdkPixmap
*Pixmap
= gdk_pixmap_new(
473 Drawing
->Drawing_Area_V
->window
,
475 Drawing
->height
- height
,
478 /* Copy the high region */
479 gdk_draw_drawable (Pixmap
,
480 Drawing
->Drawing_Area_V
->style
->black_gc
,
488 /* Copy up the bottom of the region */
489 gdk_draw_drawable (Pixmap
,
490 Drawing
->Drawing_Area_V
->style
->black_gc
,
494 Drawing
->width
, Drawing
->height
- y
- height
);
498 gdk_pixmap_unref(Drawing
->Pixmap
);
500 Drawing
->Pixmap
= Pixmap
;
502 Drawing
->height
-=height
;
504 /* Rectangle to update, from new Drawing dimensions */
507 update_rect
.width
= Drawing
->width
;
508 update_rect
.height
= Drawing
->height
- y
;
509 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);