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 gdk_draw_rectangle (Pixmap
,
52 Drawing
->Drawing_Area_V
->style
->white_gc
,
55 width
, // do not overlap
58 Drawing_draw_line(Drawing
, Pixmap
, 10, 10, 50, 10,
59 Drawing
->Drawing_Area_V
->style
->black_gc
);
67 /* Create a new backing pixmap of the appropriate size */
69 configure_event( GtkWidget
*widget
, GdkEventConfigure
*event
,
72 Drawing_t
*Drawing
= (Drawing_t
*)user_data
;
74 GdkPixmap
*Pixmap
= gdk_pixmap_new(widget
->window
,
75 widget
->allocation
.width
,
76 widget
->allocation
.height
,
79 if(Drawing
->Pixmap
== NULL
)
81 Drawing
->Pixmap
= gdk_pixmap_new(widget
->window
,
82 widget
->allocation
.width
,
83 widget
->allocation
.height
,
85 Drawing
->width
= widget
->allocation
.width
;
86 Drawing
->height
= widget
->allocation
.height
;
88 /* Initial data request */
89 Drawing_Data_Request(Drawing
, Drawing
->Pixmap
, 0, 0,
90 widget
->allocation
.width
,
91 widget
->allocation
.height
);
94 // /* Draw empty background */
95 // gdk_draw_rectangle (Pixmap,
96 // widget->style->black_gc,
99 // widget->allocation.width,
100 // widget->allocation.height);
102 /* Copy old data to new pixmap */
103 gdk_draw_drawable (Pixmap
,
104 widget
->style
->white_gc
,
110 /* Request data for missing space */
111 Drawing_Data_Request(Drawing
, Pixmap
, Drawing
->width
, 0,
112 widget
->allocation
.width
- Drawing
->width
,
113 widget
->allocation
.height
);
114 Drawing_Data_Request(Drawing
, Pixmap
, 0, Drawing
->height
,
116 widget
->allocation
.height
- Drawing
->height
);
118 // gdk_draw_rectangle (Pixmap,
119 // widget->style->white_gc,
121 // Drawing->width, 0,
122 // widget->allocation.width -
124 // widget->allocation.height);
126 // gdk_draw_rectangle (Pixmap,
127 // widget->style->white_gc,
129 // 0, Drawing->height,
130 // Drawing->width, // do not overlap
131 // widget->allocation.height -
136 g_critical("drawing configure event");
140 gdk_pixmap_unref(Drawing
->Pixmap
);
142 Drawing
->Pixmap
= Pixmap
;
143 Drawing
->width
= widget
->allocation
.width
;
144 Drawing
->height
= widget
->allocation
.height
;
150 /* Redraw the screen from the backing pixmap */
152 expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
154 Drawing_t
*Drawing
= (Drawing_t
*)user_data
;
155 g_critical("drawing expose event");
157 gdk_draw_pixmap(widget
->window
,
158 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
160 event
->area
.x
, event
->area
.y
,
161 event
->area
.x
, event
->area
.y
,
162 event
->area
.width
, event
->area
.height
);
167 Drawing_t
*Drawing_construct(void)
169 Drawing_t
*Drawing
= g_new(Drawing_t
, 1);
171 Drawing
->Drawing_Area_V
= gtk_drawing_area_new ();
173 //gtk_widget_set_size_request(Drawing->Drawing_Area_V->window, 50, 50);
174 g_object_set_data_full(
175 G_OBJECT(Drawing
->Drawing_Area_V
),
178 (GDestroyNotify
)Drawing_destroy
);
180 //gtk_widget_modify_bg( Drawing->Drawing_Area_V,
182 // &CF_Colors[BLACK]);
184 //gdk_window_get_geometry(Drawing->Drawing_Area_V->window,
186 // &(Drawing->width),
187 // &(Drawing->height),
190 //Drawing->Pixmap = gdk_pixmap_new(
191 // Drawing->Drawing_Area_V->window,
196 Drawing
->Pixmap
= NULL
;
198 // Drawing->Pixmap = gdk_pixmap_new(Drawing->Drawing_Area_V->window,
199 // Drawing->Drawing_Area_V->allocation.width,
200 // Drawing->Drawing_Area_V->allocation.height,
204 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
206 G_CALLBACK (configure_event
),
209 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
211 G_CALLBACK (expose_event
),
217 void Drawing_destroy(Drawing_t
*Drawing
)
220 // Do not unref here, Drawing_t destroyed by it's widget.
221 //g_object_unref( G_OBJECT(Drawing->Drawing_Area_V));
226 GtkWidget
*Drawing_getWidget(Drawing_t
*Drawing
)
228 return Drawing
->Drawing_Area_V
;
231 /* get_time_from_pixels
233 * Get the time interval from window time and pixels, and pixels requested. This
234 * function uses TimeMul, which should only be used if the float value is lower
235 * that 4, and here it's always lower than 1, so it's ok.
237 void convert_pixels_to_time(
240 LttTime
*window_time_begin
,
241 LttTime
*window_time_end
,
244 LttTime window_time_interval
;
246 TimeSub(window_time_interval
, *window_time_end
, *window_time_begin
);
249 TimeMul(*time
, window_time_interval
,
250 (x
/(float)Drawing
->width
));
251 TimeAdd(*time
, *window_time_begin
, *time
);
257 void convert_time_to_pixels(
258 LttTime window_time_begin
,
259 LttTime window_time_end
,
264 LttTime window_time_interval
;
265 float interval_float
, time_float
;
267 TimeSub(window_time_interval
, window_time_end
, window_time_begin
);
269 TimeSub(time
, time
, window_time_begin
);
271 interval_float
= (window_time_interval
.tv_sec
* NANSECOND_CONST
)
272 + window_time_interval
.tv_nsec
;
273 time_float
= (time
.tv_sec
* NANSECOND_CONST
)
276 *x
= (guint
)(time_float
/interval_float
* Drawing
->width
);
280 void Drawing_Refresh ( Drawing_t
*Drawing
,
282 guint width
, guint height
)
285 Drawing
->Drawing_Area_V
->window
,
286 Drawing
->Drawing_Area_V
->
287 style
->fg_gc
[GTK_WIDGET_STATE (Drawing
->Drawing_Area_V
)],
288 GDK_DRAWABLE(Drawing
->Pixmap
),
295 void Drawing_draw_line( Drawing_t
*Drawing
,
301 gdk_draw_line (Pixmap
,
309 void Drawing_Resize(Drawing_t
*Drawing
, guint h
, guint w
)
311 Drawing
->height
= h
;
314 gtk_widget_set_size_request ( Drawing
->Drawing_Area_V
,