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 convert_pixels_to_time(Drawing
, x
,
66 &control_flow_data
->Time_Window
.start_time
,
70 convert_pixels_to_time(Drawing
, x
+ width
,
71 &control_flow_data
->Time_Window
.start_time
,
75 LttvTracesetContext
* tsc
=
76 get_traceset_context(control_flow_data
->Parent_Window
);
78 gdk_draw_rectangle (*Pixmap
,
79 Drawing
->Drawing_Area_V
->style
->white_gc
,
82 width
, // do not overlap
86 guicontrolflow_get_process_list(Drawing
->Control_Flow_Data
),
89 //guicontrolflow_get_process_list(Drawing->Control_Flow_Data),
90 //Drawing, *Pixmap, x, y, width, height);
92 // Let's call processTrace() !!
93 EventRequest event_request
; // Variable freed at the end of the function.
94 event_request
.Control_Flow_Data
= control_flow_data
;
95 event_request
.time_begin
= start
;
96 event_request
.time_end
= end
;
98 LttvHooks
*event
= lttv_hooks_new();
99 lttv_hooks_add(event
, draw_event_hook
, &event_request
);
101 lttv_process_traceset_seek_time(tsc
, start
);
102 lttv_traceset_context_add_hooks(tsc
,
103 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
104 NULL
, NULL
, NULL
, event
, NULL
);
105 lttv_process_traceset(tsc
, end
, G_MAXULONG
);
106 lttv_traceset_context_remove_hooks(tsc
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
107 NULL
, NULL
, NULL
, event
, NULL
);
109 lttv_hooks_destroy(event
);
115 /* Create a new backing pixmap of the appropriate size */
117 configure_event( GtkWidget
*widget
, GdkEventConfigure
*event
,
120 Drawing_t
*Drawing
= (Drawing_t
*)user_data
;
122 /* New Pixmap, size of the configure event */
123 GdkPixmap
*Pixmap
= gdk_pixmap_new(widget
->window
,
124 widget
->allocation
.width
,
125 widget
->allocation
.height
,
128 g_critical("drawing configure event");
130 /* If no old Pixmap present */
131 if(Drawing
->Pixmap
== NULL
)
133 Drawing
->Pixmap
= gdk_pixmap_new(
135 widget
->allocation
.width
,
136 widget
->allocation
.height
,
137 //ProcessList_get_height
138 // (GuiControlFlow_get_Process_List(Drawing->Control_Flow_Data)),
140 Drawing
->width
= widget
->allocation
.width
;
141 Drawing
->height
= widget
->allocation
.height
;
142 g_critical("init data");
143 /* Initial data request */
144 drawing_data_request(Drawing
, &Drawing
->Pixmap
, 0, 0,
145 widget
->allocation
.width
,
146 widget
->allocation
.height
);
149 // /* Draw empty background */
150 // gdk_draw_rectangle (Pixmap,
151 // widget->style->black_gc,
154 // widget->allocation.width,
155 // widget->allocation.height);
157 /* Copy old data to new pixmap */
158 gdk_draw_drawable (Pixmap
,
159 widget
->style
->white_gc
,
165 /* Request data for missing space */
166 g_critical("missing data");
167 drawing_data_request(Drawing
, &Pixmap
, Drawing
->width
, 0,
168 widget
->allocation
.width
- Drawing
->width
,
169 widget
->allocation
.height
);
170 drawing_data_request(Drawing
, &Pixmap
, 0, Drawing
->height
,
172 widget
->allocation
.height
- Drawing
->height
);
174 // gdk_draw_rectangle (Pixmap,
175 // widget->style->white_gc,
177 // Drawing->width, 0,
178 // widget->allocation.width -
180 // widget->allocation.height);
182 // gdk_draw_rectangle (Pixmap,
183 // widget->style->white_gc,
185 // 0, Drawing->height,
186 // Drawing->width, // do not overlap
187 // widget->allocation.height -
193 gdk_pixmap_unref(Drawing
->Pixmap
);
195 Drawing
->Pixmap
= Pixmap
;
196 Drawing
->width
= widget
->allocation
.width
;
197 Drawing
->height
= widget
->allocation
.height
;
203 /* Redraw the screen from the backing pixmap */
205 expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
207 Drawing_t
*Drawing
= (Drawing_t
*)user_data
;
208 g_critical("drawing expose event");
210 gdk_draw_pixmap(widget
->window
,
211 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
213 event
->area
.x
, event
->area
.y
,
214 event
->area
.x
, event
->area
.y
,
215 event
->area
.width
, event
->area
.height
);
220 Drawing_t
*drawing_construct(ControlFlowData
*Control_Flow_Data
)
222 Drawing_t
*Drawing
= g_new(Drawing_t
, 1);
224 Drawing
->Drawing_Area_V
= gtk_drawing_area_new ();
225 Drawing
->Control_Flow_Data
= Control_Flow_Data
;
227 //gtk_widget_set_size_request(Drawing->Drawing_Area_V->window, 50, 50);
228 g_object_set_data_full(
229 G_OBJECT(Drawing
->Drawing_Area_V
),
232 (GDestroyNotify
)drawing_destroy
);
234 //gtk_widget_modify_bg( Drawing->Drawing_Area_V,
236 // &CF_Colors[BLACK]);
238 //gdk_window_get_geometry(Drawing->Drawing_Area_V->window,
240 // &(Drawing->width),
241 // &(Drawing->height),
244 //Drawing->Pixmap = gdk_pixmap_new(
245 // Drawing->Drawing_Area_V->window,
250 Drawing
->Pixmap
= NULL
;
252 // Drawing->Pixmap = gdk_pixmap_new(Drawing->Drawing_Area_V->window,
253 // Drawing->Drawing_Area_V->allocation.width,
254 // Drawing->Drawing_Area_V->allocation.height,
257 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
259 G_CALLBACK (configure_event
),
262 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
264 G_CALLBACK (expose_event
),
270 void drawing_destroy(Drawing_t
*Drawing
)
273 // Do not unref here, Drawing_t destroyed by it's widget.
274 //g_object_unref( G_OBJECT(Drawing->Drawing_Area_V));
279 GtkWidget
*drawing_get_widget(Drawing_t
*Drawing
)
281 return Drawing
->Drawing_Area_V
;
284 /* convert_pixels_to_time
286 * Convert from window pixel and time interval to an absolute time.
288 void convert_pixels_to_time(
291 LttTime
*window_time_begin
,
292 LttTime
*window_time_end
,
295 LttTime window_time_interval
;
297 window_time_interval
= ltt_time_sub(*window_time_end
,
299 *time
= ltt_time_mul(window_time_interval
, (x
/(float)Drawing
->width
));
300 *time
= ltt_time_add(*window_time_begin
, *time
);
305 void convert_time_to_pixels(
306 LttTime window_time_begin
,
307 LttTime window_time_end
,
312 LttTime window_time_interval
;
313 float interval_float
, time_float
;
315 window_time_interval
= ltt_time_sub(window_time_end
,window_time_begin
);
317 time
= ltt_time_sub(time
, window_time_begin
);
319 interval_float
= ltt_time_to_double(window_time_interval
);
320 time_float
= ltt_time_to_double(time
);
322 *x
= (guint
)(time_float
/interval_float
* Drawing
->width
);
326 void drawing_refresh ( Drawing_t
*Drawing
,
328 guint width
, guint height
)
330 g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x
, y
, width
, height
);
331 GdkRectangle update_rect
;
334 Drawing
->Drawing_Area_V
->window
,
335 Drawing
->Drawing_Area_V
->
336 style
->fg_gc
[GTK_WIDGET_STATE (Drawing
->Drawing_Area_V
)],
337 GDK_DRAWABLE(Drawing
->Pixmap
),
344 update_rect
.width
= Drawing
->width
;
345 update_rect
.height
= Drawing
->height
;
346 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);
351 void drawing_draw_line( Drawing_t
*Drawing
,
357 gdk_draw_line (Pixmap
,
365 void drawing_resize(Drawing_t
*Drawing
, guint h
, guint w
)
367 Drawing
->height
= h
;
370 gtk_widget_set_size_request ( Drawing
->Drawing_Area_V
,
378 /* Insert a square corresponding to a new process in the list */
379 /* Applies to whole Drawing->width */
380 void drawing_insert_square(Drawing_t
*Drawing
,
384 GdkRectangle update_rect
;
386 /* Allocate a new pixmap with new height */
387 GdkPixmap
*Pixmap
= gdk_pixmap_new(Drawing
->Drawing_Area_V
->window
,
389 Drawing
->height
+ height
,
392 /* Copy the high region */
393 gdk_draw_drawable (Pixmap
,
394 Drawing
->Drawing_Area_V
->style
->black_gc
,
403 /* add an empty square */
404 gdk_draw_rectangle (Pixmap
,
405 Drawing
->Drawing_Area_V
->style
->black_gc
,
408 Drawing
->width
, // do not overlap
413 /* copy the bottom of the region */
414 gdk_draw_drawable (Pixmap
,
415 Drawing
->Drawing_Area_V
->style
->black_gc
,
419 Drawing
->width
, Drawing
->height
- y
);
425 gdk_pixmap_unref(Drawing
->Pixmap
);
427 Drawing
->Pixmap
= Pixmap
;
429 Drawing
->height
+=height
;
431 /* Rectangle to update, from new Drawing dimensions */
434 update_rect
.width
= Drawing
->width
;
435 update_rect
.height
= Drawing
->height
- y
;
436 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);
440 /* Remove a square corresponding to a removed process in the list */
441 void drawing_remove_square(Drawing_t
*Drawing
,
445 GdkRectangle update_rect
;
447 /* Allocate a new pixmap with new height */
448 GdkPixmap
*Pixmap
= gdk_pixmap_new(
449 Drawing
->Drawing_Area_V
->window
,
451 Drawing
->height
- height
,
454 /* Copy the high region */
455 gdk_draw_drawable (Pixmap
,
456 Drawing
->Drawing_Area_V
->style
->black_gc
,
464 /* Copy up the bottom of the region */
465 gdk_draw_drawable (Pixmap
,
466 Drawing
->Drawing_Area_V
->style
->black_gc
,
470 Drawing
->width
, Drawing
->height
- y
- height
);
474 gdk_pixmap_unref(Drawing
->Pixmap
);
476 Drawing
->Pixmap
= Pixmap
;
478 Drawing
->height
-=height
;
480 /* Rectangle to update, from new Drawing dimensions */
483 update_rect
.width
= Drawing
->width
;
484 update_rect
.height
= Drawing
->height
- y
;
485 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);