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 // we do not request data vertically!
201 // drawing_data_request(Drawing, &Pixmap, 0, Drawing->height,
203 // widget->allocation.height - Drawing->height);
205 // gdk_draw_rectangle (Pixmap,
206 // widget->style->white_gc,
208 // Drawing->width, 0,
209 // widget->allocation.width -
211 // widget->allocation.height);
213 // Clear the bottom part of the image
214 gdk_draw_rectangle (Pixmap
,
215 widget
->style
->white_gc
,
218 Drawing
->width
, // do not overlap
219 widget
->allocation
.height
- Drawing
->height
);
221 Drawing
->width
= widget
->allocation
.width
;
222 Drawing
->height
= widget
->allocation
.height
;
228 /* Redraw the screen from the backing pixmap */
230 expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
232 Drawing_t
*Drawing
= (Drawing_t
*)user_data
;
233 g_critical("drawing expose event");
235 gdk_draw_pixmap(widget
->window
,
236 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
238 event
->area
.x
, event
->area
.y
,
239 event
->area
.x
, event
->area
.y
,
240 event
->area
.width
, event
->area
.height
);
245 Drawing_t
*drawing_construct(ControlFlowData
*Control_Flow_Data
)
247 Drawing_t
*Drawing
= g_new(Drawing_t
, 1);
249 Drawing
->Drawing_Area_V
= gtk_drawing_area_new ();
250 Drawing
->Control_Flow_Data
= Control_Flow_Data
;
252 //gtk_widget_set_size_request(Drawing->Drawing_Area_V->window, 50, 50);
253 g_object_set_data_full(
254 G_OBJECT(Drawing
->Drawing_Area_V
),
257 (GDestroyNotify
)drawing_destroy
);
259 //gtk_widget_modify_bg( Drawing->Drawing_Area_V,
261 // &CF_Colors[BLACK]);
263 //gdk_window_get_geometry(Drawing->Drawing_Area_V->window,
265 // &(Drawing->width),
266 // &(Drawing->height),
269 //Drawing->Pixmap = gdk_pixmap_new(
270 // Drawing->Drawing_Area_V->window,
275 Drawing
->Pixmap
= NULL
;
277 // Drawing->Pixmap = gdk_pixmap_new(Drawing->Drawing_Area_V->window,
278 // Drawing->Drawing_Area_V->allocation.width,
279 // Drawing->Drawing_Area_V->allocation.height,
282 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
284 G_CALLBACK (configure_event
),
287 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
289 G_CALLBACK (expose_event
),
295 void drawing_destroy(Drawing_t
*Drawing
)
298 // Do not unref here, Drawing_t destroyed by it's widget.
299 //g_object_unref( G_OBJECT(Drawing->Drawing_Area_V));
304 GtkWidget
*drawing_get_widget(Drawing_t
*Drawing
)
306 return Drawing
->Drawing_Area_V
;
309 /* convert_pixels_to_time
311 * Convert from window pixel and time interval to an absolute time.
313 void convert_pixels_to_time(
316 LttTime
*window_time_begin
,
317 LttTime
*window_time_end
,
320 LttTime window_time_interval
;
322 window_time_interval
= ltt_time_sub(*window_time_end
,
324 *time
= ltt_time_mul(window_time_interval
, (x
/(float)width
));
325 *time
= ltt_time_add(*window_time_begin
, *time
);
330 void convert_time_to_pixels(
331 LttTime window_time_begin
,
332 LttTime window_time_end
,
337 LttTime window_time_interval
;
338 float interval_float
, time_float
;
340 window_time_interval
= ltt_time_sub(window_time_end
,window_time_begin
);
342 time
= ltt_time_sub(time
, window_time_begin
);
344 interval_float
= ltt_time_to_double(window_time_interval
);
345 time_float
= ltt_time_to_double(time
);
347 *x
= (guint
)(time_float
/interval_float
* width
);
351 void drawing_refresh ( Drawing_t
*Drawing
,
353 guint width
, guint height
)
355 g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x
, y
, width
, height
);
356 GdkRectangle update_rect
;
359 Drawing
->Drawing_Area_V
->window
,
360 Drawing
->Drawing_Area_V
->
361 style
->fg_gc
[GTK_WIDGET_STATE (Drawing
->Drawing_Area_V
)],
362 GDK_DRAWABLE(Drawing
->Pixmap
),
369 update_rect
.width
= Drawing
->width
;
370 update_rect
.height
= Drawing
->height
;
371 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);
376 void drawing_draw_line( Drawing_t
*Drawing
,
382 gdk_draw_line (Pixmap
,
390 void drawing_resize(Drawing_t
*Drawing
, guint h
, guint w
)
392 Drawing
->height
= h
;
395 gtk_widget_set_size_request ( Drawing
->Drawing_Area_V
,
403 /* Insert a square corresponding to a new process in the list */
404 /* Applies to whole Drawing->width */
405 void drawing_insert_square(Drawing_t
*Drawing
,
409 GdkRectangle update_rect
;
411 /* Allocate a new pixmap with new height */
412 GdkPixmap
*Pixmap
= gdk_pixmap_new(Drawing
->Drawing_Area_V
->window
,
414 Drawing
->height
+ height
,
417 /* Copy the high region */
418 gdk_draw_drawable (Pixmap
,
419 Drawing
->Drawing_Area_V
->style
->black_gc
,
428 /* add an empty square */
429 gdk_draw_rectangle (Pixmap
,
430 Drawing
->Drawing_Area_V
->style
->black_gc
,
433 Drawing
->width
, // do not overlap
438 /* copy the bottom of the region */
439 gdk_draw_drawable (Pixmap
,
440 Drawing
->Drawing_Area_V
->style
->black_gc
,
444 Drawing
->width
, Drawing
->height
- y
);
450 gdk_pixmap_unref(Drawing
->Pixmap
);
452 Drawing
->Pixmap
= Pixmap
;
454 Drawing
->height
+=height
;
456 /* Rectangle to update, from new Drawing dimensions */
459 update_rect
.width
= Drawing
->width
;
460 update_rect
.height
= Drawing
->height
- y
;
461 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);
465 /* Remove a square corresponding to a removed process in the list */
466 void drawing_remove_square(Drawing_t
*Drawing
,
470 GdkRectangle update_rect
;
472 /* Allocate a new pixmap with new height */
473 GdkPixmap
*Pixmap
= gdk_pixmap_new(
474 Drawing
->Drawing_Area_V
->window
,
476 Drawing
->height
- height
,
479 /* Copy the high region */
480 gdk_draw_drawable (Pixmap
,
481 Drawing
->Drawing_Area_V
->style
->black_gc
,
489 /* Copy up the bottom of the region */
490 gdk_draw_drawable (Pixmap
,
491 Drawing
->Drawing_Area_V
->style
->black_gc
,
495 Drawing
->width
, Drawing
->height
- y
- height
);
499 gdk_pixmap_unref(Drawing
->Pixmap
);
501 Drawing
->Pixmap
= Pixmap
;
503 Drawing
->height
-=height
;
505 /* Rectangle to update, from new Drawing dimensions */
508 update_rect
.width
= Drawing
->width
;
509 update_rect
.height
= Drawing
->height
- y
;
510 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);