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(width
, x
,
74 &control_flow_data
->Time_Window
.start_time
,
78 convert_pixels_to_time(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 lttv_hooks_add(event
, draw_event_hook
, &event_request
);
115 lttv_process_traceset_seek_time(tsc
, start
);
116 lttv_traceset_context_add_hooks(tsc
,
117 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
118 NULL
, NULL
, NULL
, event
, NULL
);
119 lttv_process_traceset(tsc
, end
, G_MAXULONG
);
120 lttv_traceset_context_remove_hooks(tsc
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
121 NULL
, NULL
, NULL
, event
, NULL
);
123 lttv_hooks_destroy(event
);
129 /* Create a new backing pixmap of the appropriate size */
131 configure_event( GtkWidget
*widget
, GdkEventConfigure
*event
,
134 Drawing_t
*Drawing
= (Drawing_t
*)user_data
;
136 /* New Pixmap, size of the configure event */
137 GdkPixmap
*Pixmap
= gdk_pixmap_new(widget
->window
,
138 widget
->allocation
.width
,
139 widget
->allocation
.height
,
142 g_critical("drawing configure event");
144 /* If no old Pixmap present */
145 if(Drawing
->Pixmap
== NULL
)
147 Drawing
->Pixmap
= gdk_pixmap_new(
149 widget
->allocation
.width
,
150 widget
->allocation
.height
,
151 //ProcessList_get_height
152 // (GuiControlFlow_get_Process_List(Drawing->Control_Flow_Data)),
154 Drawing
->width
= widget
->allocation
.width
;
155 Drawing
->height
= widget
->allocation
.height
;
156 g_critical("init data");
157 /* Initial data request */
158 drawing_data_request(Drawing
, &Drawing
->Pixmap
, 0, 0,
159 widget
->allocation
.width
,
160 widget
->allocation
.height
);
163 // /* Draw empty background */
164 // gdk_draw_rectangle (Pixmap,
165 // widget->style->black_gc,
168 // widget->allocation.width,
169 // widget->allocation.height);
171 /* Copy old data to new pixmap */
172 gdk_draw_drawable (Pixmap
,
173 widget
->style
->white_gc
,
179 /* Request data for missing space */
180 g_critical("missing data");
181 drawing_data_request(Drawing
, &Pixmap
, Drawing
->width
, 0,
182 widget
->allocation
.width
- Drawing
->width
,
183 widget
->allocation
.height
);
184 drawing_data_request(Drawing
, &Pixmap
, 0, Drawing
->height
,
186 widget
->allocation
.height
- Drawing
->height
);
188 // gdk_draw_rectangle (Pixmap,
189 // widget->style->white_gc,
191 // Drawing->width, 0,
192 // widget->allocation.width -
194 // widget->allocation.height);
196 // gdk_draw_rectangle (Pixmap,
197 // widget->style->white_gc,
199 // 0, Drawing->height,
200 // Drawing->width, // do not overlap
201 // widget->allocation.height -
207 gdk_pixmap_unref(Drawing
->Pixmap
);
209 Drawing
->Pixmap
= Pixmap
;
210 Drawing
->width
= widget
->allocation
.width
;
211 Drawing
->height
= widget
->allocation
.height
;
217 /* Redraw the screen from the backing pixmap */
219 expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
221 Drawing_t
*Drawing
= (Drawing_t
*)user_data
;
222 g_critical("drawing expose event");
224 gdk_draw_pixmap(widget
->window
,
225 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
227 event
->area
.x
, event
->area
.y
,
228 event
->area
.x
, event
->area
.y
,
229 event
->area
.width
, event
->area
.height
);
234 Drawing_t
*drawing_construct(ControlFlowData
*Control_Flow_Data
)
236 Drawing_t
*Drawing
= g_new(Drawing_t
, 1);
238 Drawing
->Drawing_Area_V
= gtk_drawing_area_new ();
239 Drawing
->Control_Flow_Data
= Control_Flow_Data
;
241 //gtk_widget_set_size_request(Drawing->Drawing_Area_V->window, 50, 50);
242 g_object_set_data_full(
243 G_OBJECT(Drawing
->Drawing_Area_V
),
246 (GDestroyNotify
)drawing_destroy
);
248 //gtk_widget_modify_bg( Drawing->Drawing_Area_V,
250 // &CF_Colors[BLACK]);
252 //gdk_window_get_geometry(Drawing->Drawing_Area_V->window,
254 // &(Drawing->width),
255 // &(Drawing->height),
258 //Drawing->Pixmap = gdk_pixmap_new(
259 // Drawing->Drawing_Area_V->window,
264 Drawing
->Pixmap
= NULL
;
266 // Drawing->Pixmap = gdk_pixmap_new(Drawing->Drawing_Area_V->window,
267 // Drawing->Drawing_Area_V->allocation.width,
268 // Drawing->Drawing_Area_V->allocation.height,
271 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
273 G_CALLBACK (configure_event
),
276 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
278 G_CALLBACK (expose_event
),
284 void drawing_destroy(Drawing_t
*Drawing
)
287 // Do not unref here, Drawing_t destroyed by it's widget.
288 //g_object_unref( G_OBJECT(Drawing->Drawing_Area_V));
293 GtkWidget
*drawing_get_widget(Drawing_t
*Drawing
)
295 return Drawing
->Drawing_Area_V
;
298 /* convert_pixels_to_time
300 * Convert from window pixel and time interval to an absolute time.
302 void convert_pixels_to_time(
305 LttTime
*window_time_begin
,
306 LttTime
*window_time_end
,
309 LttTime window_time_interval
;
311 window_time_interval
= ltt_time_sub(*window_time_end
,
313 *time
= ltt_time_mul(window_time_interval
, (x
/(float)width
));
314 *time
= ltt_time_add(*window_time_begin
, *time
);
319 void convert_time_to_pixels(
320 LttTime window_time_begin
,
321 LttTime window_time_end
,
326 LttTime window_time_interval
;
327 float interval_float
, time_float
;
329 window_time_interval
= ltt_time_sub(window_time_end
,window_time_begin
);
331 time
= ltt_time_sub(time
, window_time_begin
);
333 interval_float
= ltt_time_to_double(window_time_interval
);
334 time_float
= ltt_time_to_double(time
);
336 *x
= (guint
)(time_float
/interval_float
* width
);
340 void drawing_refresh ( Drawing_t
*Drawing
,
342 guint width
, guint height
)
344 g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x
, y
, width
, height
);
345 GdkRectangle update_rect
;
348 Drawing
->Drawing_Area_V
->window
,
349 Drawing
->Drawing_Area_V
->
350 style
->fg_gc
[GTK_WIDGET_STATE (Drawing
->Drawing_Area_V
)],
351 GDK_DRAWABLE(Drawing
->Pixmap
),
358 update_rect
.width
= Drawing
->width
;
359 update_rect
.height
= Drawing
->height
;
360 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);
365 void drawing_draw_line( Drawing_t
*Drawing
,
371 gdk_draw_line (Pixmap
,
379 void drawing_resize(Drawing_t
*Drawing
, guint h
, guint w
)
381 Drawing
->height
= h
;
384 gtk_widget_set_size_request ( Drawing
->Drawing_Area_V
,
392 /* Insert a square corresponding to a new process in the list */
393 /* Applies to whole Drawing->width */
394 void drawing_insert_square(Drawing_t
*Drawing
,
398 GdkRectangle update_rect
;
400 /* Allocate a new pixmap with new height */
401 GdkPixmap
*Pixmap
= gdk_pixmap_new(Drawing
->Drawing_Area_V
->window
,
403 Drawing
->height
+ height
,
406 /* Copy the high region */
407 gdk_draw_drawable (Pixmap
,
408 Drawing
->Drawing_Area_V
->style
->black_gc
,
417 /* add an empty square */
418 gdk_draw_rectangle (Pixmap
,
419 Drawing
->Drawing_Area_V
->style
->black_gc
,
422 Drawing
->width
, // do not overlap
427 /* copy the bottom of the region */
428 gdk_draw_drawable (Pixmap
,
429 Drawing
->Drawing_Area_V
->style
->black_gc
,
433 Drawing
->width
, Drawing
->height
- y
);
439 gdk_pixmap_unref(Drawing
->Pixmap
);
441 Drawing
->Pixmap
= Pixmap
;
443 Drawing
->height
+=height
;
445 /* Rectangle to update, from new Drawing dimensions */
448 update_rect
.width
= Drawing
->width
;
449 update_rect
.height
= Drawing
->height
- y
;
450 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);
454 /* Remove a square corresponding to a removed process in the list */
455 void drawing_remove_square(Drawing_t
*Drawing
,
459 GdkRectangle update_rect
;
461 /* Allocate a new pixmap with new height */
462 GdkPixmap
*Pixmap
= gdk_pixmap_new(
463 Drawing
->Drawing_Area_V
->window
,
465 Drawing
->height
- height
,
468 /* Copy the high region */
469 gdk_draw_drawable (Pixmap
,
470 Drawing
->Drawing_Area_V
->style
->black_gc
,
478 /* Copy up the bottom of the region */
479 gdk_draw_drawable (Pixmap
,
480 Drawing
->Drawing_Area_V
->style
->black_gc
,
484 Drawing
->width
, Drawing
->height
- y
- height
);
488 gdk_pixmap_unref(Drawing
->Pixmap
);
490 Drawing
->Pixmap
= Pixmap
;
492 Drawing
->height
-=height
;
494 /* Rectangle to update, from new Drawing dimensions */
497 update_rect
.width
= Drawing
->width
;
498 update_rect
.height
= Drawing
->height
- y
;
499 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);