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
;
138 /* New Pixmap, size of the configure event */
139 GdkPixmap
*Pixmap
= gdk_pixmap_new(widget
->window
,
140 widget
->allocation
.width
,
141 widget
->allocation
.height
,
144 g_critical("drawing configure event");
146 /* If no old Pixmap present */
147 if(Drawing
->Pixmap
== NULL
)
149 Drawing
->Pixmap
= gdk_pixmap_new(
151 widget
->allocation
.width
,
152 widget
->allocation
.height
,
153 //ProcessList_get_height
154 // (GuiControlFlow_get_Process_List(Drawing->Control_Flow_Data)),
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
);
165 // /* Draw empty background */
166 // gdk_draw_rectangle (Pixmap,
167 // widget->style->black_gc,
170 // widget->allocation.width,
171 // widget->allocation.height);
173 /* Copy old data to new pixmap */
174 gdk_draw_drawable (Pixmap
,
175 widget
->style
->white_gc
,
182 gdk_pixmap_unref(Drawing
->Pixmap
);
184 Drawing
->Pixmap
= Pixmap
;
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
,
193 widget
->allocation
.height
- Drawing
->height
);
195 // gdk_draw_rectangle (Pixmap,
196 // widget->style->white_gc,
198 // Drawing->width, 0,
199 // widget->allocation.width -
201 // widget->allocation.height);
203 // gdk_draw_rectangle (Pixmap,
204 // widget->style->white_gc,
206 // 0, Drawing->height,
207 // Drawing->width, // do not overlap
208 // widget->allocation.height -
213 Drawing
->width
= widget
->allocation
.width
;
214 Drawing
->height
= widget
->allocation
.height
;
220 /* Redraw the screen from the backing pixmap */
222 expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
224 Drawing_t
*Drawing
= (Drawing_t
*)user_data
;
225 g_critical("drawing expose event");
227 gdk_draw_pixmap(widget
->window
,
228 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
230 event
->area
.x
, event
->area
.y
,
231 event
->area
.x
, event
->area
.y
,
232 event
->area
.width
, event
->area
.height
);
237 Drawing_t
*drawing_construct(ControlFlowData
*Control_Flow_Data
)
239 Drawing_t
*Drawing
= g_new(Drawing_t
, 1);
241 Drawing
->Drawing_Area_V
= gtk_drawing_area_new ();
242 Drawing
->Control_Flow_Data
= Control_Flow_Data
;
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
),
249 (GDestroyNotify
)drawing_destroy
);
251 //gtk_widget_modify_bg( Drawing->Drawing_Area_V,
253 // &CF_Colors[BLACK]);
255 //gdk_window_get_geometry(Drawing->Drawing_Area_V->window,
257 // &(Drawing->width),
258 // &(Drawing->height),
261 //Drawing->Pixmap = gdk_pixmap_new(
262 // Drawing->Drawing_Area_V->window,
267 Drawing
->Pixmap
= NULL
;
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,
274 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
276 G_CALLBACK (configure_event
),
279 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
281 G_CALLBACK (expose_event
),
287 void drawing_destroy(Drawing_t
*Drawing
)
290 // Do not unref here, Drawing_t destroyed by it's widget.
291 //g_object_unref( G_OBJECT(Drawing->Drawing_Area_V));
296 GtkWidget
*drawing_get_widget(Drawing_t
*Drawing
)
298 return Drawing
->Drawing_Area_V
;
301 /* convert_pixels_to_time
303 * Convert from window pixel and time interval to an absolute time.
305 void convert_pixels_to_time(
308 LttTime
*window_time_begin
,
309 LttTime
*window_time_end
,
312 LttTime window_time_interval
;
314 window_time_interval
= ltt_time_sub(*window_time_end
,
316 *time
= ltt_time_mul(window_time_interval
, (x
/(float)width
));
317 *time
= ltt_time_add(*window_time_begin
, *time
);
322 void convert_time_to_pixels(
323 LttTime window_time_begin
,
324 LttTime window_time_end
,
329 LttTime window_time_interval
;
330 float interval_float
, time_float
;
332 window_time_interval
= ltt_time_sub(window_time_end
,window_time_begin
);
334 time
= ltt_time_sub(time
, window_time_begin
);
336 interval_float
= ltt_time_to_double(window_time_interval
);
337 time_float
= ltt_time_to_double(time
);
339 *x
= (guint
)(time_float
/interval_float
* width
);
343 void drawing_refresh ( Drawing_t
*Drawing
,
345 guint width
, guint height
)
347 g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x
, y
, width
, height
);
348 GdkRectangle update_rect
;
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
),
361 update_rect
.width
= Drawing
->width
;
362 update_rect
.height
= Drawing
->height
;
363 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);
368 void drawing_draw_line( Drawing_t
*Drawing
,
374 gdk_draw_line (Pixmap
,
382 void drawing_resize(Drawing_t
*Drawing
, guint h
, guint w
)
384 Drawing
->height
= h
;
387 gtk_widget_set_size_request ( Drawing
->Drawing_Area_V
,
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
,
401 GdkRectangle update_rect
;
403 /* Allocate a new pixmap with new height */
404 GdkPixmap
*Pixmap
= gdk_pixmap_new(Drawing
->Drawing_Area_V
->window
,
406 Drawing
->height
+ height
,
409 /* Copy the high region */
410 gdk_draw_drawable (Pixmap
,
411 Drawing
->Drawing_Area_V
->style
->black_gc
,
420 /* add an empty square */
421 gdk_draw_rectangle (Pixmap
,
422 Drawing
->Drawing_Area_V
->style
->black_gc
,
425 Drawing
->width
, // do not overlap
430 /* copy the bottom of the region */
431 gdk_draw_drawable (Pixmap
,
432 Drawing
->Drawing_Area_V
->style
->black_gc
,
436 Drawing
->width
, Drawing
->height
- y
);
442 gdk_pixmap_unref(Drawing
->Pixmap
);
444 Drawing
->Pixmap
= Pixmap
;
446 Drawing
->height
+=height
;
448 /* Rectangle to update, from new Drawing dimensions */
451 update_rect
.width
= Drawing
->width
;
452 update_rect
.height
= Drawing
->height
- y
;
453 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);
457 /* Remove a square corresponding to a removed process in the list */
458 void drawing_remove_square(Drawing_t
*Drawing
,
462 GdkRectangle update_rect
;
464 /* Allocate a new pixmap with new height */
465 GdkPixmap
*Pixmap
= gdk_pixmap_new(
466 Drawing
->Drawing_Area_V
->window
,
468 Drawing
->height
- height
,
471 /* Copy the high region */
472 gdk_draw_drawable (Pixmap
,
473 Drawing
->Drawing_Area_V
->style
->black_gc
,
481 /* Copy up the bottom of the region */
482 gdk_draw_drawable (Pixmap
,
483 Drawing
->Drawing_Area_V
->style
->black_gc
,
487 Drawing
->width
, Drawing
->height
- y
- height
);
491 gdk_pixmap_unref(Drawing
->Pixmap
);
493 Drawing
->Pixmap
= Pixmap
;
495 Drawing
->height
-=height
;
497 /* Rectangle to update, from new Drawing dimensions */
500 update_rect
.width
= Drawing
->width
;
501 update_rect
.height
= Drawing
->height
- y
;
502 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);