7 #include <lttv/processTrace.h>
10 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
11 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
14 /*****************************************************************************
16 *****************************************************************************/
18 //FIXME Colors will need to be dynamic. Graphic context part not done so far.
29 /* Vector of unallocated colors */
30 static GdkColor CF_Colors
[] =
32 { 0, 0xffff, 0x0000, 0x0000 }, // RED
33 { 0, 0x0000, 0xffff, 0x0000 }, // GREEN
34 { 0, 0x0000, 0x0000, 0xffff }, // BLUE
35 { 0, 0xffff, 0xffff, 0xffff }, // WHITE
36 { 0, 0x0000, 0x0000, 0x0000 } // BLACK
41 // GtkWidget *Drawing_Area_V;
43 // ControlFlowData *Control_Flow_Data;
45 // gint height, width, depth;
49 /* Function responsible for updating the exposed area.
50 * It must call processTrace() to ask for this update.
52 void drawing_data_request(Drawing_t
*Drawing
,
58 if(width
< 0) return ;
59 if(height
< 0) return ;
61 gdk_draw_rectangle (*Pixmap
,
62 Drawing
->Drawing_Area_V
->style
->white_gc
,
65 width
, // do not overlap
69 guicontrolflow_get_process_list(Drawing
->Control_Flow_Data
),
72 guicontrolflow_get_process_list(Drawing
->Control_Flow_Data
),
73 Drawing
, *Pixmap
, x
, y
, width
, height
);
80 /* Create a new backing pixmap of the appropriate size */
82 configure_event( GtkWidget
*widget
, GdkEventConfigure
*event
,
85 Drawing_t
*Drawing
= (Drawing_t
*)user_data
;
87 /* New Pixmap, size of the configure event */
88 GdkPixmap
*Pixmap
= gdk_pixmap_new(widget
->window
,
89 widget
->allocation
.width
,
90 widget
->allocation
.height
,
93 g_critical("drawing configure event");
95 /* If no old Pixmap present */
96 if(Drawing
->Pixmap
== NULL
)
98 Drawing
->Pixmap
= gdk_pixmap_new(
100 widget
->allocation
.width
,
101 widget
->allocation
.height
,
102 //ProcessList_get_height
103 // (GuiControlFlow_get_Process_List(Drawing->Control_Flow_Data)),
105 Drawing
->width
= widget
->allocation
.width
;
106 Drawing
->height
= widget
->allocation
.height
;
107 g_critical("init data");
108 /* Initial data request */
109 drawing_data_request(Drawing
, &Drawing
->Pixmap
, 0, 0,
110 widget
->allocation
.width
,
111 widget
->allocation
.height
);
114 // /* Draw empty background */
115 // gdk_draw_rectangle (Pixmap,
116 // widget->style->black_gc,
119 // widget->allocation.width,
120 // widget->allocation.height);
122 /* Copy old data to new pixmap */
123 gdk_draw_drawable (Pixmap
,
124 widget
->style
->white_gc
,
130 /* Request data for missing space */
131 g_critical("missing data");
132 drawing_data_request(Drawing
, &Pixmap
, Drawing
->width
, 0,
133 widget
->allocation
.width
- Drawing
->width
,
134 widget
->allocation
.height
);
135 drawing_data_request(Drawing
, &Pixmap
, 0, Drawing
->height
,
137 widget
->allocation
.height
- Drawing
->height
);
139 // gdk_draw_rectangle (Pixmap,
140 // widget->style->white_gc,
142 // Drawing->width, 0,
143 // widget->allocation.width -
145 // widget->allocation.height);
147 // gdk_draw_rectangle (Pixmap,
148 // widget->style->white_gc,
150 // 0, Drawing->height,
151 // Drawing->width, // do not overlap
152 // widget->allocation.height -
159 gdk_pixmap_unref(Drawing
->Pixmap
);
161 Drawing
->Pixmap
= Pixmap
;
162 Drawing
->width
= widget
->allocation
.width
;
163 Drawing
->height
= widget
->allocation
.height
;
169 /* Redraw the screen from the backing pixmap */
171 expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
173 Drawing_t
*Drawing
= (Drawing_t
*)user_data
;
174 g_critical("drawing expose event");
176 gdk_draw_pixmap(widget
->window
,
177 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
179 event
->area
.x
, event
->area
.y
,
180 event
->area
.x
, event
->area
.y
,
181 event
->area
.width
, event
->area
.height
);
186 Drawing_t
*drawing_construct(ControlFlowData
*Control_Flow_Data
)
188 Drawing_t
*Drawing
= g_new(Drawing_t
, 1);
190 Drawing
->Drawing_Area_V
= gtk_drawing_area_new ();
191 Drawing
->Control_Flow_Data
= Control_Flow_Data
;
193 //gtk_widget_set_size_request(Drawing->Drawing_Area_V->window, 50, 50);
194 g_object_set_data_full(
195 G_OBJECT(Drawing
->Drawing_Area_V
),
198 (GDestroyNotify
)drawing_destroy
);
200 //gtk_widget_modify_bg( Drawing->Drawing_Area_V,
202 // &CF_Colors[BLACK]);
204 //gdk_window_get_geometry(Drawing->Drawing_Area_V->window,
206 // &(Drawing->width),
207 // &(Drawing->height),
210 //Drawing->Pixmap = gdk_pixmap_new(
211 // Drawing->Drawing_Area_V->window,
216 Drawing
->Pixmap
= NULL
;
218 // Drawing->Pixmap = gdk_pixmap_new(Drawing->Drawing_Area_V->window,
219 // Drawing->Drawing_Area_V->allocation.width,
220 // Drawing->Drawing_Area_V->allocation.height,
223 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
225 G_CALLBACK (configure_event
),
228 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
230 G_CALLBACK (expose_event
),
236 void drawing_destroy(Drawing_t
*Drawing
)
239 // Do not unref here, Drawing_t destroyed by it's widget.
240 //g_object_unref( G_OBJECT(Drawing->Drawing_Area_V));
245 GtkWidget
*drawing_get_widget(Drawing_t
*Drawing
)
247 return Drawing
->Drawing_Area_V
;
250 /* get_time_from_pixels
252 * Get the time interval from window time and pixels, and pixels requested.
254 void convert_pixels_to_time(
257 LttTime
*window_time_begin
,
258 LttTime
*window_time_end
,
261 LttTime window_time_interval
;
263 window_time_interval
= ltt_time_sub(*window_time_end
,
265 *time
= ltt_time_mul(window_time_interval
, (x
/(float)Drawing
->width
));
266 *time
= ltt_time_add(*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 window_time_interval
= ltt_time_sub(window_time_end
,window_time_begin
);
283 time
= ltt_time_sub(time
, window_time_begin
);
285 interval_float
= ltt_time_to_double(window_time_interval
);
286 time_float
= ltt_time_to_double(time
);
288 *x
= (guint
)(time_float
/interval_float
* Drawing
->width
);
292 void drawing_refresh ( Drawing_t
*Drawing
,
294 guint width
, guint height
)
296 g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x
, y
, width
, height
);
297 GdkRectangle update_rect
;
300 Drawing
->Drawing_Area_V
->window
,
301 Drawing
->Drawing_Area_V
->
302 style
->fg_gc
[GTK_WIDGET_STATE (Drawing
->Drawing_Area_V
)],
303 GDK_DRAWABLE(Drawing
->Pixmap
),
310 update_rect
.width
= Drawing
->width
;
311 update_rect
.height
= Drawing
->height
;
312 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);
317 void drawing_draw_line( Drawing_t
*Drawing
,
323 gdk_draw_line (Pixmap
,
331 void drawing_resize(Drawing_t
*Drawing
, guint h
, guint w
)
333 Drawing
->height
= h
;
336 gtk_widget_set_size_request ( Drawing
->Drawing_Area_V
,
344 /* Insert a square corresponding to a new process in the list */
345 /* Applies to whole Drawing->width */
346 void drawing_insert_square(Drawing_t
*Drawing
,
350 GdkRectangle update_rect
;
352 /* Allocate a new pixmap with new height */
353 GdkPixmap
*Pixmap
= gdk_pixmap_new(Drawing
->Drawing_Area_V
->window
,
355 Drawing
->height
+ height
,
358 /* Copy the high region */
359 gdk_draw_drawable (Pixmap
,
360 Drawing
->Drawing_Area_V
->style
->black_gc
,
369 /* add an empty square */
370 gdk_draw_rectangle (Pixmap
,
371 Drawing
->Drawing_Area_V
->style
->black_gc
,
374 Drawing
->width
, // do not overlap
379 /* copy the bottom of the region */
380 gdk_draw_drawable (Pixmap
,
381 Drawing
->Drawing_Area_V
->style
->black_gc
,
385 Drawing
->width
, Drawing
->height
- y
);
391 gdk_pixmap_unref(Drawing
->Pixmap
);
393 Drawing
->Pixmap
= Pixmap
;
395 Drawing
->height
+=height
;
397 /* Rectangle to update, from new Drawing dimensions */
400 update_rect
.width
= Drawing
->width
;
401 update_rect
.height
= Drawing
->height
- y
;
402 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);
406 /* Remove a square corresponding to a removed process in the list */
407 void drawing_remove_square(Drawing_t
*Drawing
,
411 GdkRectangle update_rect
;
413 /* Allocate a new pixmap with new height */
414 GdkPixmap
*Pixmap
= gdk_pixmap_new(
415 Drawing
->Drawing_Area_V
->window
,
417 Drawing
->height
- height
,
420 /* Copy the high region */
421 gdk_draw_drawable (Pixmap
,
422 Drawing
->Drawing_Area_V
->style
->black_gc
,
430 /* Copy up the bottom of the region */
431 gdk_draw_drawable (Pixmap
,
432 Drawing
->Drawing_Area_V
->style
->black_gc
,
436 Drawing
->width
, Drawing
->height
- y
- height
);
440 gdk_pixmap_unref(Drawing
->Pixmap
);
442 Drawing
->Pixmap
= Pixmap
;
444 Drawing
->height
-=height
;
446 /* Rectangle to update, from new Drawing dimensions */
449 update_rect
.width
= Drawing
->width
;
450 update_rect
.height
= Drawing
->height
- y
;
451 gtk_widget_draw( Drawing
->Drawing_Area_V
, &update_rect
);