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_getWidget(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. This
248 * function uses TimeMul, which should only be used if the float value is lower
249 * that 4, and here it's always lower than 1, so it's ok.
251 void convert_pixels_to_time(
254 LttTime
*window_time_begin
,
255 LttTime
*window_time_end
,
258 LttTime window_time_interval
;
260 TimeSub(window_time_interval
, *window_time_end
, *window_time_begin
);
263 TimeMul(*time
, window_time_interval
,
264 (x
/(float)Drawing
->width
));
265 TimeAdd(*time
, *window_time_begin
, *time
);
271 void convert_time_to_pixels(
272 LttTime window_time_begin
,
273 LttTime window_time_end
,
278 LttTime window_time_interval
;
279 float interval_float
, time_float
;
281 TimeSub(window_time_interval
, window_time_end
, window_time_begin
);
283 TimeSub(time
, time
, window_time_begin
);
285 interval_float
= (window_time_interval
.tv_sec
* NANSECOND_CONST
)
286 + window_time_interval
.tv_nsec
;
287 time_float
= (time
.tv_sec
* NANSECOND_CONST
)
290 *x
= (guint
)(time_float
/interval_float
* Drawing
->width
);
294 void Drawing_Refresh ( Drawing_t
*Drawing
,
296 guint width
, guint height
)
298 GdkRectangle update_rect
;
301 Drawing
->Drawing_Area_V
->window
,
302 Drawing
->Drawing_Area_V
->
303 style
->fg_gc
[GTK_WIDGET_STATE (Drawing
->Drawing_Area_V
)],
304 GDK_DRAWABLE(Drawing
->Pixmap
),
311 update_rect
.width
= Drawing
->width
;
312 update_rect
.height
= Drawing
->height
;
313 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);
318 void Drawing_draw_line( Drawing_t
*Drawing
,
324 gdk_draw_line (Pixmap
,
332 void Drawing_Resize(Drawing_t
*Drawing
, guint h
, guint w
)
334 Drawing
->height
= h
;
337 gtk_widget_set_size_request ( Drawing
->Drawing_Area_V
,
345 /* Insert a square corresponding to a new process in the list */
346 /* Applies to whole Drawing->width */
347 void Drawing_Insert_Square(Drawing_t
*Drawing
,
351 GdkRectangle update_rect
;
353 /* Allocate a new pixmap with new height */
354 GdkPixmap
*Pixmap
= gdk_pixmap_new(Drawing
->Drawing_Area_V
->window
,
356 Drawing
->height
+ height
,
359 /* Copy the high region */
360 gdk_draw_drawable (Pixmap
,
361 Drawing
->Drawing_Area_V
->style
->black_gc
,
370 /* add an empty square */
371 gdk_draw_rectangle (Pixmap
,
372 Drawing
->Drawing_Area_V
->style
->black_gc
,
375 Drawing
->width
, // do not overlap
380 /* copy the bottom of the region */
381 gdk_draw_drawable (Pixmap
,
382 Drawing
->Drawing_Area_V
->style
->black_gc
,
386 Drawing
->width
, Drawing
->height
- y
);
392 gdk_pixmap_unref(Drawing
->Pixmap
);
394 Drawing
->Pixmap
= Pixmap
;
396 Drawing
->height
+=height
;
398 /* Rectangle to update, from new Drawing dimensions */
401 update_rect
.width
= Drawing
->width
;
402 update_rect
.height
= Drawing
->height
- y
;
403 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);
407 /* Remove a square corresponding to a removed process in the list */
408 void Drawing_Remove_Square(Drawing_t
*Drawing
,
412 GdkRectangle update_rect
;
414 /* Allocate a new pixmap with new height */
415 GdkPixmap
*Pixmap
= gdk_pixmap_new(
416 Drawing
->Drawing_Area_V
->window
,
418 Drawing
->height
- height
,
421 /* Copy the high region */
422 gdk_draw_drawable (Pixmap
,
423 Drawing
->Drawing_Area_V
->style
->black_gc
,
431 /* Copy up the bottom of the region */
432 gdk_draw_drawable (Pixmap
,
433 Drawing
->Drawing_Area_V
->style
->black_gc
,
437 Drawing
->width
, Drawing
->height
- y
- height
);
441 gdk_pixmap_unref(Drawing
->Pixmap
);
443 Drawing
->Pixmap
= Pixmap
;
445 Drawing
->height
-=height
;
447 /* Rectangle to update, from new Drawing dimensions */
450 update_rect
.width
= Drawing
->width
;
451 update_rect
.height
= Drawing
->height
- y
;
452 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);