6 #include <lttv/processTrace.h>
8 /*****************************************************************************
10 *****************************************************************************/
12 //FIXME Colors will need to be dynamic. Graphic context part not done so far.
23 /* Vector of unallocated colors */
24 static GdkColor CF_Colors
[] =
26 { 0, 0xffff, 0x0000, 0x0000 }, // RED
27 { 0, 0x0000, 0xffff, 0x0000 }, // GREEN
28 { 0, 0x0000, 0x0000, 0xffff }, // BLUE
29 { 0, 0xffff, 0xffff, 0xffff }, // WHITE
30 { 0, 0x0000, 0x0000, 0x0000 } // BLACK
35 GtkWidget
*Drawing_Area_V
;
38 gint height
, width
, depth
;
42 /* Function responsible for updating the exposed area.
43 * It must call processTrace() to ask for this update.
45 void Drawing_Data_Request(Drawing_t
*Drawing
,
51 if(width
< 0) return ;
52 if(height
< 0) return ;
54 gdk_draw_rectangle (Pixmap
,
55 Drawing
->Drawing_Area_V
->style
->white_gc
,
58 width
, // do not overlap
61 Drawing_draw_line(Drawing
, Pixmap
, 10, 10, 50, 10,
62 Drawing
->Drawing_Area_V
->style
->black_gc
);
70 /* Create a new backing pixmap of the appropriate size */
72 configure_event( GtkWidget
*widget
, GdkEventConfigure
*event
,
75 Drawing_t
*Drawing
= (Drawing_t
*)user_data
;
77 GdkPixmap
*Pixmap
= gdk_pixmap_new(widget
->window
,
78 widget
->allocation
.width
,
79 widget
->allocation
.height
,
82 if(Drawing
->Pixmap
== NULL
)
84 Drawing
->Pixmap
= gdk_pixmap_new(widget
->window
,
85 widget
->allocation
.width
,
86 widget
->allocation
.height
,
88 Drawing
->width
= widget
->allocation
.width
;
89 Drawing
->height
= widget
->allocation
.height
;
91 /* Initial data request */
92 Drawing_Data_Request(Drawing
, Drawing
->Pixmap
, 0, 0,
93 widget
->allocation
.width
,
94 widget
->allocation
.height
);
97 // /* Draw empty background */
98 // gdk_draw_rectangle (Pixmap,
99 // widget->style->black_gc,
102 // widget->allocation.width,
103 // widget->allocation.height);
105 /* Copy old data to new pixmap */
106 gdk_draw_drawable (Pixmap
,
107 widget
->style
->white_gc
,
113 /* Request data for missing space */
114 Drawing_Data_Request(Drawing
, Pixmap
, Drawing
->width
, 0,
115 widget
->allocation
.width
- Drawing
->width
,
116 widget
->allocation
.height
);
117 Drawing_Data_Request(Drawing
, Pixmap
, 0, Drawing
->height
,
119 widget
->allocation
.height
- Drawing
->height
);
121 // gdk_draw_rectangle (Pixmap,
122 // widget->style->white_gc,
124 // Drawing->width, 0,
125 // widget->allocation.width -
127 // widget->allocation.height);
129 // gdk_draw_rectangle (Pixmap,
130 // widget->style->white_gc,
132 // 0, Drawing->height,
133 // Drawing->width, // do not overlap
134 // widget->allocation.height -
139 g_critical("drawing configure event");
143 gdk_pixmap_unref(Drawing
->Pixmap
);
145 Drawing
->Pixmap
= Pixmap
;
146 Drawing
->width
= widget
->allocation
.width
;
147 Drawing
->height
= widget
->allocation
.height
;
153 /* Redraw the screen from the backing pixmap */
155 expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
157 Drawing_t
*Drawing
= (Drawing_t
*)user_data
;
158 g_critical("drawing expose event");
160 gdk_draw_pixmap(widget
->window
,
161 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
163 event
->area
.x
, event
->area
.y
,
164 event
->area
.x
, event
->area
.y
,
165 event
->area
.width
, event
->area
.height
);
170 Drawing_t
*Drawing_construct(void)
172 Drawing_t
*Drawing
= g_new(Drawing_t
, 1);
174 Drawing
->Drawing_Area_V
= gtk_drawing_area_new ();
176 //gtk_widget_set_size_request(Drawing->Drawing_Area_V->window, 50, 50);
177 g_object_set_data_full(
178 G_OBJECT(Drawing
->Drawing_Area_V
),
181 (GDestroyNotify
)Drawing_destroy
);
183 //gtk_widget_modify_bg( Drawing->Drawing_Area_V,
185 // &CF_Colors[BLACK]);
187 //gdk_window_get_geometry(Drawing->Drawing_Area_V->window,
189 // &(Drawing->width),
190 // &(Drawing->height),
193 //Drawing->Pixmap = gdk_pixmap_new(
194 // Drawing->Drawing_Area_V->window,
199 Drawing
->Pixmap
= NULL
;
201 // Drawing->Pixmap = gdk_pixmap_new(Drawing->Drawing_Area_V->window,
202 // Drawing->Drawing_Area_V->allocation.width,
203 // Drawing->Drawing_Area_V->allocation.height,
207 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
209 G_CALLBACK (configure_event
),
212 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
214 G_CALLBACK (expose_event
),
220 void Drawing_destroy(Drawing_t
*Drawing
)
223 // Do not unref here, Drawing_t destroyed by it's widget.
224 //g_object_unref( G_OBJECT(Drawing->Drawing_Area_V));
229 GtkWidget
*Drawing_getWidget(Drawing_t
*Drawing
)
231 return Drawing
->Drawing_Area_V
;
234 /* get_time_from_pixels
236 * Get the time interval from window time and pixels, and pixels requested. This
237 * function uses TimeMul, which should only be used if the float value is lower
238 * that 4, and here it's always lower than 1, so it's ok.
240 void convert_pixels_to_time(
243 LttTime
*window_time_begin
,
244 LttTime
*window_time_end
,
247 LttTime window_time_interval
;
249 TimeSub(window_time_interval
, *window_time_end
, *window_time_begin
);
252 TimeMul(*time
, window_time_interval
,
253 (x
/(float)Drawing
->width
));
254 TimeAdd(*time
, *window_time_begin
, *time
);
260 void convert_time_to_pixels(
261 LttTime window_time_begin
,
262 LttTime window_time_end
,
267 LttTime window_time_interval
;
268 float interval_float
, time_float
;
270 TimeSub(window_time_interval
, window_time_end
, window_time_begin
);
272 TimeSub(time
, time
, window_time_begin
);
274 interval_float
= (window_time_interval
.tv_sec
* NANSECOND_CONST
)
275 + window_time_interval
.tv_nsec
;
276 time_float
= (time
.tv_sec
* NANSECOND_CONST
)
279 *x
= (guint
)(time_float
/interval_float
* Drawing
->width
);
283 void Drawing_Refresh ( Drawing_t
*Drawing
,
285 guint width
, guint height
)
288 Drawing
->Drawing_Area_V
->window
,
289 Drawing
->Drawing_Area_V
->
290 style
->fg_gc
[GTK_WIDGET_STATE (Drawing
->Drawing_Area_V
)],
291 GDK_DRAWABLE(Drawing
->Pixmap
),
298 void Drawing_draw_line( Drawing_t
*Drawing
,
304 gdk_draw_line (Pixmap
,
312 void Drawing_Resize(Drawing_t
*Drawing
, guint h
, guint w
)
314 Drawing
->height
= h
;
317 gtk_widget_set_size_request ( Drawing
->Drawing_Area_V
,