6 /*****************************************************************************
8 *****************************************************************************/
20 /* Vector of unallocated colors */
21 static GdkColor CF_Colors
[] =
23 { 0, 0xffff, 0x0000, 0x0000 }, // RED
24 { 0, 0x0000, 0xffff, 0x0000 }, // GREEN
25 { 0, 0x0000, 0x0000, 0xffff }, // BLUE
26 { 0, 0xffff, 0xffff, 0xffff }, // WHITE
27 { 0, 0x0000, 0x0000, 0x0000 } // BLACK
32 GtkWidget
*Drawing_Area_V
;
35 gint height
, width
, depth
;
39 void test_draw(Drawing_t
*Drawing
)
41 GdkRectangle update_rect
;
42 // GdkColor color = { 0, 65535, 65535, 65535 };
44 // gdk_colormap_alloc_color(gdk_rgb_get_cmap(), &color, 0, 1);
47 // Drawing->Drawing_Area_V->
48 // style->fg_gc[GTK_WIDGET_STATE (Drawing->Drawing_Area_V)];
49 // gdk_gc_set_foreground(gc, &color);
52 update_rect
.width
= 1000;
53 update_rect
.height
= 1000;
54 gdk_draw_rectangle (Drawing
->Pixmap
,
55 Drawing
->Drawing_Area_V
->style
->black_gc
,
62 //Drawing_draw_line(Drawing, 10, 10, 50, 10,
63 // Drawing->Drawing_Area_V->style->black_gc);
64 gtk_widget_draw (Drawing
->Drawing_Area_V
, &update_rect
);
66 // Drawing_Refresh( Drawing, 0, 0, 30, 30);
69 void Drawing_Data_Request(Drawing_t
*Drawing
,
75 gdk_draw_rectangle (Pixmap
,
76 Drawing
->Drawing_Area_V
->style
->white_gc
,
79 width
, // do not overlap
82 Drawing_draw_line(Drawing
, Pixmap
, 10, 10, 50, 10,
83 Drawing
->Drawing_Area_V
->style
->black_gc
);
90 /* Create a new backing pixmap of the appropriate size */
92 configure_event( GtkWidget
*widget
, GdkEventConfigure
*event
,
95 Drawing_t
*Drawing
= (Drawing_t
*)user_data
;
97 GdkPixmap
*Pixmap
= gdk_pixmap_new(widget
->window
,
98 widget
->allocation
.width
,
99 widget
->allocation
.height
,
102 if(Drawing
->Pixmap
== NULL
)
104 Drawing
->Pixmap
= gdk_pixmap_new(widget
->window
,
105 widget
->allocation
.width
,
106 widget
->allocation
.height
,
108 Drawing
->width
= widget
->allocation
.width
;
109 Drawing
->height
= widget
->allocation
.height
;
111 /* Initial data request */
112 Drawing_Data_Request(Drawing
, Drawing
->Pixmap
, 0, 0,
113 widget
->allocation
.width
,
114 widget
->allocation
.height
);
117 // /* Draw empty background */
118 // gdk_draw_rectangle (Pixmap,
119 // widget->style->black_gc,
122 // widget->allocation.width,
123 // widget->allocation.height);
125 /* Copy old data to new pixmap */
126 gdk_draw_drawable (Pixmap
,
127 widget
->style
->white_gc
,
133 /* Request data for missing space */
134 Drawing_Data_Request(Drawing
, Pixmap
, Drawing
->width
, 0,
135 widget
->allocation
.width
- Drawing
->width
,
136 widget
->allocation
.height
);
137 Drawing_Data_Request(Drawing
, Pixmap
, 0, Drawing
->height
,
139 widget
->allocation
.height
- Drawing
->height
);
141 // gdk_draw_rectangle (Pixmap,
142 // widget->style->white_gc,
144 // Drawing->width, 0,
145 // widget->allocation.width -
147 // widget->allocation.height);
149 // gdk_draw_rectangle (Pixmap,
150 // widget->style->white_gc,
152 // 0, Drawing->height,
153 // Drawing->width, // do not overlap
154 // widget->allocation.height -
159 g_critical("drawing configure event");
163 gdk_pixmap_unref(Drawing
->Pixmap
);
165 Drawing
->Pixmap
= Pixmap
;
166 Drawing
->width
= widget
->allocation
.width
;
167 Drawing
->height
= widget
->allocation
.height
;
173 /* Redraw the screen from the backing pixmap */
175 expose_event( GtkWidget
*widget
, GdkEventExpose
*event
, gpointer user_data
)
177 Drawing_t
*Drawing
= (Drawing_t
*)user_data
;
178 g_critical("drawing expose event");
180 gdk_draw_pixmap(widget
->window
,
181 widget
->style
->fg_gc
[GTK_WIDGET_STATE (widget
)],
183 event
->area
.x
, event
->area
.y
,
184 event
->area
.x
, event
->area
.y
,
185 event
->area
.width
, event
->area
.height
);
190 Drawing_t
*Drawing_construct(void)
192 Drawing_t
*Drawing
= g_new(Drawing_t
, 1);
194 Drawing
->Drawing_Area_V
= gtk_drawing_area_new ();
196 //gtk_widget_set_size_request(Drawing->Drawing_Area_V->window, 50, 50);
197 g_object_set_data_full(
198 G_OBJECT(Drawing
->Drawing_Area_V
),
201 (GDestroyNotify
)Drawing_destroy
);
203 //gtk_widget_modify_bg( Drawing->Drawing_Area_V,
205 // &CF_Colors[BLACK]);
207 //gdk_window_get_geometry(Drawing->Drawing_Area_V->window,
209 // &(Drawing->width),
210 // &(Drawing->height),
213 //Drawing->Pixmap = gdk_pixmap_new(
214 // Drawing->Drawing_Area_V->window,
219 Drawing
->Pixmap
= NULL
;
221 // Drawing->Pixmap = gdk_pixmap_new(Drawing->Drawing_Area_V->window,
222 // Drawing->Drawing_Area_V->allocation.width,
223 // Drawing->Drawing_Area_V->allocation.height,
227 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
229 G_CALLBACK (configure_event
),
232 g_signal_connect (G_OBJECT(Drawing
->Drawing_Area_V
),
234 G_CALLBACK (expose_event
),
240 void Drawing_destroy(Drawing_t
*Drawing
)
243 // Do not unref here, Drawing_t destroyed by it's widget.
244 //g_object_unref( G_OBJECT(Drawing->Drawing_Area_V));
249 GtkWidget
*Drawing_getWidget(Drawing_t
*Drawing
)
251 return Drawing
->Drawing_Area_V
;
254 /* get_time_from_pixels
256 * Get the time interval from window time and pixels, and pixels requested. This
257 * function uses TimeMul, which should only be used if the float value is lower
258 * that 4, and here it's always lower than 1, so it's ok.
260 void convert_pixels_to_time(
263 LttTime
*window_time_begin
,
264 LttTime
*window_time_end
,
267 LttTime window_time_interval
;
269 TimeSub(window_time_interval
, *window_time_end
, *window_time_begin
);
272 TimeMul(*time
, window_time_interval
,
273 (x
/(float)Drawing
->width
));
274 TimeAdd(*time
, *window_time_begin
, *time
);
280 void convert_time_to_pixels(
281 LttTime window_time_begin
,
282 LttTime window_time_end
,
287 LttTime window_time_interval
;
288 float interval_float
, time_float
;
290 TimeSub(window_time_interval
, window_time_end
, window_time_begin
);
292 TimeSub(time
, time
, window_time_begin
);
294 interval_float
= (window_time_interval
.tv_sec
* NANSECOND_CONST
)
295 + window_time_interval
.tv_nsec
;
296 time_float
= (time
.tv_sec
* NANSECOND_CONST
)
299 *x
= (guint
)(time_float
/interval_float
* Drawing
->width
);
303 void Drawing_Refresh ( Drawing_t
*Drawing
,
305 guint width
, guint height
)
308 Drawing
->Drawing_Area_V
->window
,
309 Drawing
->Drawing_Area_V
->
310 style
->fg_gc
[GTK_WIDGET_STATE (Drawing
->Drawing_Area_V
)],
311 GDK_DRAWABLE(Drawing
->Pixmap
),
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
,