7 #include <lttv/processTrace.h>
9 /*****************************************************************************
11 *****************************************************************************/
13 //FIXME Colors will need to be dynamic. Graphic context part not done so far.
24 /* Vector of unallocated colors */
25 static GdkColor CF_Colors
[] =
27 { 0, 0xffff, 0x0000, 0x0000 }, // RED
28 { 0, 0x0000, 0xffff, 0x0000 }, // GREEN
29 { 0, 0x0000, 0x0000, 0xffff }, // BLUE
30 { 0, 0xffff, 0xffff, 0xffff }, // WHITE
31 { 0, 0x0000, 0x0000, 0x0000 } // BLACK
36 // GtkWidget *Drawing_Area_V;
38 // ControlFlowData *Control_Flow_Data;
40 // gint height, width, depth;
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 ;
56 gdk_draw_rectangle (*Pixmap
,
57 Drawing
->Drawing_Area_V
->style
->white_gc
,
60 width
, // do not overlap
64 guicontrolflow_get_process_list(Drawing
->Control_Flow_Data
),
67 guicontrolflow_get_process_list(Drawing
->Control_Flow_Data
),
68 Drawing
, *Pixmap
, x
, y
, width
, height
);
75 /* Create a new backing pixmap of the appropriate size */
77 configure_event( GtkWidget
*widget
, GdkEventConfigure
*event
,
80 Drawing_t
*Drawing
= (Drawing_t
*)user_data
;
82 /* New Pixmap, size of the configure event */
83 GdkPixmap
*Pixmap
= gdk_pixmap_new(widget
->window
,
84 widget
->allocation
.width
,
85 widget
->allocation
.height
,
88 g_critical("drawing configure event");
90 /* If no old Pixmap present */
91 if(Drawing
->Pixmap
== NULL
)
93 Drawing
->Pixmap
= gdk_pixmap_new(
95 widget
->allocation
.width
,
96 widget
->allocation
.height
,
97 //ProcessList_get_height
98 // (GuiControlFlow_get_Process_List(Drawing->Control_Flow_Data)),
100 Drawing
->width
= widget
->allocation
.width
;
101 Drawing
->height
= widget
->allocation
.height
;
102 g_critical("init data");
103 /* Initial data request */
104 drawing_data_request(Drawing
, &Drawing
->Pixmap
, 0, 0,
105 widget
->allocation
.width
,
106 widget
->allocation
.height
);
109 // /* Draw empty background */
110 // gdk_draw_rectangle (Pixmap,
111 // widget->style->black_gc,
114 // widget->allocation.width,
115 // widget->allocation.height);
117 /* Copy old data to new pixmap */
118 gdk_draw_drawable (Pixmap
,
119 widget
->style
->white_gc
,
125 /* Request data for missing space */
126 g_critical("missing data");
127 drawing_data_request(Drawing
, &Pixmap
, Drawing
->width
, 0,
128 widget
->allocation
.width
- Drawing
->width
,
129 widget
->allocation
.height
);
130 drawing_data_request(Drawing
, &Pixmap
, 0, Drawing
->height
,
132 widget
->allocation
.height
- Drawing
->height
);
134 // gdk_draw_rectangle (Pixmap,
135 // widget->style->white_gc,
137 // Drawing->width, 0,
138 // widget->allocation.width -
140 // widget->allocation.height);
142 // gdk_draw_rectangle (Pixmap,
143 // widget->style->white_gc,
145 // 0, Drawing->height,
146 // Drawing->width, // do not overlap
147 // widget->allocation.height -
154 gdk_pixmap_unref(Drawing
->Pixmap
);
156 Drawing
->Pixmap
= Pixmap
;
157 Drawing
->width
= widget
->allocation
.width
;
158 Drawing
->height
= widget
->allocation
.height
;
164 /* Redraw the screen from the backing pixmap */
166 expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
168 Drawing_t
*Drawing
= (Drawing_t
*)user_data
;
169 g_critical("drawing expose event");
171 gdk_draw_pixmap(widget
->window
,
172 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
174 event
->area
.x
, event
->area
.y
,
175 event
->area
.x
, event
->area
.y
,
176 event
->area
.width
, event
->area
.height
);
181 Drawing_t
*drawing_construct(ControlFlowData
*Control_Flow_Data
)
183 Drawing_t
*Drawing
= g_new(Drawing_t
, 1);
185 Drawing
->Drawing_Area_V
= gtk_drawing_area_new ();
186 Drawing
->Control_Flow_Data
= Control_Flow_Data
;
188 //gtk_widget_set_size_request(Drawing->Drawing_Area_V->window, 50, 50);
189 g_object_set_data_full(
190 G_OBJECT(Drawing
->Drawing_Area_V
),
193 (GDestroyNotify
)drawing_destroy
);
195 //gtk_widget_modify_bg( Drawing->Drawing_Area_V,
197 // &CF_Colors[BLACK]);
199 //gdk_window_get_geometry(Drawing->Drawing_Area_V->window,
201 // &(Drawing->width),
202 // &(Drawing->height),
205 //Drawing->Pixmap = gdk_pixmap_new(
206 // Drawing->Drawing_Area_V->window,
211 Drawing
->Pixmap
= NULL
;
213 // Drawing->Pixmap = gdk_pixmap_new(Drawing->Drawing_Area_V->window,
214 // Drawing->Drawing_Area_V->allocation.width,
215 // Drawing->Drawing_Area_V->allocation.height,
218 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
220 G_CALLBACK (configure_event
),
223 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
225 G_CALLBACK (expose_event
),
231 void drawing_destroy(Drawing_t
*Drawing
)
234 // Do not unref here, Drawing_t destroyed by it's widget.
235 //g_object_unref( G_OBJECT(Drawing->Drawing_Area_V));
240 GtkWidget
*drawing_get_widget(Drawing_t
*Drawing
)
242 return Drawing
->Drawing_Area_V
;
245 /* get_time_from_pixels
247 * Get the time interval from window time and pixels, and pixels requested.
249 void convert_pixels_to_time(
252 LttTime
*window_time_begin
,
253 LttTime
*window_time_end
,
256 LttTime window_time_interval
;
258 window_time_interval
= ltt_time_sub(*window_time_end
,
260 *time
= ltt_time_mul(window_time_interval
, (x
/(float)Drawing
->width
));
261 *time
= ltt_time_add(*window_time_begin
, *time
);
266 void convert_time_to_pixels(
267 LttTime window_time_begin
,
268 LttTime window_time_end
,
273 LttTime window_time_interval
;
274 float interval_float
, time_float
;
276 window_time_interval
= ltt_time_sub(window_time_end
,window_time_begin
);
278 time
= ltt_time_sub(time
, window_time_begin
);
280 interval_float
= ltt_time_to_double(window_time_interval
);
281 time_float
= ltt_time_to_double(time
);
283 *x
= (guint
)(time_float
/interval_float
* Drawing
->width
);
287 void drawing_refresh ( Drawing_t
*Drawing
,
289 guint width
, guint height
)
291 GdkRectangle update_rect
;
294 Drawing
->Drawing_Area_V
->window
,
295 Drawing
->Drawing_Area_V
->
296 style
->fg_gc
[GTK_WIDGET_STATE (Drawing
->Drawing_Area_V
)],
297 GDK_DRAWABLE(Drawing
->Pixmap
),
304 update_rect
.width
= Drawing
->width
;
305 update_rect
.height
= Drawing
->height
;
306 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);
311 void drawing_draw_line( Drawing_t
*Drawing
,
317 gdk_draw_line (Pixmap
,
325 void drawing_resize(Drawing_t
*Drawing
, guint h
, guint w
)
327 Drawing
->height
= h
;
330 gtk_widget_set_size_request ( Drawing
->Drawing_Area_V
,
338 /* Insert a square corresponding to a new process in the list */
339 /* Applies to whole Drawing->width */
340 void drawing_insert_square(Drawing_t
*Drawing
,
344 GdkRectangle update_rect
;
346 /* Allocate a new pixmap with new height */
347 GdkPixmap
*Pixmap
= gdk_pixmap_new(Drawing
->Drawing_Area_V
->window
,
349 Drawing
->height
+ height
,
352 /* Copy the high region */
353 gdk_draw_drawable (Pixmap
,
354 Drawing
->Drawing_Area_V
->style
->black_gc
,
363 /* add an empty square */
364 gdk_draw_rectangle (Pixmap
,
365 Drawing
->Drawing_Area_V
->style
->black_gc
,
368 Drawing
->width
, // do not overlap
373 /* copy the bottom of the region */
374 gdk_draw_drawable (Pixmap
,
375 Drawing
->Drawing_Area_V
->style
->black_gc
,
379 Drawing
->width
, Drawing
->height
- y
);
385 gdk_pixmap_unref(Drawing
->Pixmap
);
387 Drawing
->Pixmap
= Pixmap
;
389 Drawing
->height
+=height
;
391 /* Rectangle to update, from new Drawing dimensions */
394 update_rect
.width
= Drawing
->width
;
395 update_rect
.height
= Drawing
->height
- y
;
396 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);
400 /* Remove a square corresponding to a removed process in the list */
401 void drawing_remove_square(Drawing_t
*Drawing
,
405 GdkRectangle update_rect
;
407 /* Allocate a new pixmap with new height */
408 GdkPixmap
*Pixmap
= gdk_pixmap_new(
409 Drawing
->Drawing_Area_V
->window
,
411 Drawing
->height
- height
,
414 /* Copy the high region */
415 gdk_draw_drawable (Pixmap
,
416 Drawing
->Drawing_Area_V
->style
->black_gc
,
424 /* Copy up the bottom of the region */
425 gdk_draw_drawable (Pixmap
,
426 Drawing
->Drawing_Area_V
->style
->black_gc
,
430 Drawing
->width
, Drawing
->height
- y
- height
);
434 gdk_pixmap_unref(Drawing
->Pixmap
);
436 Drawing
->Pixmap
= Pixmap
;
438 Drawing
->height
-=height
;
440 /* Rectangle to update, from new Drawing dimensions */
443 update_rect
.width
= Drawing
->width
;
444 update_rect
.height
= Drawing
->height
- y
;
445 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);