comments on next additions
[lttv.git] / ltt / branches / poly / lttv / modules / guiControlFlow / Drawing.c
CommitLineData
fa2c4dbe 1
f0d936c0 2#include "Drawing.h"
76a67e8a 3#include <gtk/gtk.h>
4#include <gdk/gdk.h>
f0d936c0 5
831a876d 6#include <lttv/processTrace.h>
7
f0d936c0 8/*****************************************************************************
9 * Drawing functions *
10 *****************************************************************************/
11
831a876d 12//FIXME Colors will need to be dynamic. Graphic context part not done so far.
f0d936c0 13typedef enum
14{
15 RED,
16 GREEN,
17 BLUE,
18 WHITE,
19 BLACK
20
21} ControlFlowColors;
22
23/* Vector of unallocated colors */
24static GdkColor CF_Colors [] =
25{
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
31};
32
33
76a67e8a 34struct _Drawing_t {
35 GtkWidget *Drawing_Area_V;
36 GdkPixmap *Pixmap;
f0d936c0 37
76a67e8a 38 gint height, width, depth;
f0d936c0 39
76a67e8a 40};
f0d936c0 41
831a876d 42/* Function responsible for updating the exposed area.
43 * It must call processTrace() to ask for this update.
44 */
847b479d 45void Drawing_Data_Request(Drawing_t *Drawing,
46 GdkPixmap *Pixmap,
47 gint x, gint y,
48 gint width,
49 gint height)
50{
51 gdk_draw_rectangle (Pixmap,
52 Drawing->Drawing_Area_V->style->white_gc,
53 TRUE,
54 x, y,
55 width, // do not overlap
56 height);
57
58 Drawing_draw_line(Drawing, Pixmap, 10, 10, 50, 10,
59 Drawing->Drawing_Area_V->style->black_gc);
60
831a876d 61
847b479d 62}
63
64/* Callbacks */
65
66
67/* Create a new backing pixmap of the appropriate size */
68static gboolean
69configure_event( GtkWidget *widget, GdkEventConfigure *event,
70 gpointer user_data)
f0d936c0 71{
847b479d 72 Drawing_t *Drawing = (Drawing_t*)user_data;
f0d936c0 73
847b479d 74 GdkPixmap *Pixmap = gdk_pixmap_new(widget->window,
75 widget->allocation.width,
76 widget->allocation.height,
77 -1);
78
79 if(Drawing->Pixmap == NULL)
80 {
81 Drawing->Pixmap = gdk_pixmap_new(widget->window,
82 widget->allocation.width,
83 widget->allocation.height,
84 -1);
85 Drawing->width = widget->allocation.width;
86 Drawing->height = widget->allocation.height;
87
88 /* Initial data request */
89 Drawing_Data_Request(Drawing, Drawing->Pixmap, 0, 0,
90 widget->allocation.width,
91 widget->allocation.height);
92
93 }
94// /* Draw empty background */
95// gdk_draw_rectangle (Pixmap,
96// widget->style->black_gc,
97// TRUE,
98// 0, 0,
99// widget->allocation.width,
100// widget->allocation.height);
101
102 /* Copy old data to new pixmap */
103 gdk_draw_drawable (Pixmap,
104 widget->style->white_gc,
105 Drawing->Pixmap,
106 0, 0,
107 0, 0,
108 -1, -1);
109
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,
115 Drawing->width,
116 widget->allocation.height - Drawing->height);
117
118// gdk_draw_rectangle (Pixmap,
119// widget->style->white_gc,
120// TRUE,
121// Drawing->width, 0,
122// widget->allocation.width -
123// Drawing->width,
124// widget->allocation.height);
125
126// gdk_draw_rectangle (Pixmap,
127// widget->style->white_gc,
128// TRUE,
129// 0, Drawing->height,
130// Drawing->width, // do not overlap
131// widget->allocation.height -
132// Drawing->height);
133
134
135
136 g_critical("drawing configure event");
137
138
139 if (Drawing->Pixmap)
140 gdk_pixmap_unref(Drawing->Pixmap);
141
142 Drawing->Pixmap = Pixmap;
143 Drawing->width = widget->allocation.width;
144 Drawing->height = widget->allocation.height;
145
146 return TRUE;
147}
148
149
150/* Redraw the screen from the backing pixmap */
151static gboolean
152expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
153{
154 Drawing_t *Drawing = (Drawing_t*)user_data;
155 g_critical("drawing expose event");
156
157 gdk_draw_pixmap(widget->window,
158 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
159 Drawing->Pixmap,
160 event->area.x, event->area.y,
161 event->area.x, event->area.y,
162 event->area.width, event->area.height);
163
164 return FALSE;
165}
166
167Drawing_t *Drawing_construct(void)
168{
76a67e8a 169 Drawing_t *Drawing = g_new(Drawing_t, 1);
f0d936c0 170
171 Drawing->Drawing_Area_V = gtk_drawing_area_new ();
847b479d 172
173 //gtk_widget_set_size_request(Drawing->Drawing_Area_V->window, 50, 50);
f0d936c0 174 g_object_set_data_full(
175 G_OBJECT(Drawing->Drawing_Area_V),
76a67e8a 176 "Link_Drawing_Data",
f0d936c0 177 Drawing,
fa2c4dbe 178 (GDestroyNotify)Drawing_destroy);
f0d936c0 179
847b479d 180 //gtk_widget_modify_bg( Drawing->Drawing_Area_V,
181 // GTK_STATE_NORMAL,
182 // &CF_Colors[BLACK]);
183
184 //gdk_window_get_geometry(Drawing->Drawing_Area_V->window,
185 // NULL, NULL,
186 // &(Drawing->width),
187 // &(Drawing->height),
188 // -1);
189
190 //Drawing->Pixmap = gdk_pixmap_new(
191 // Drawing->Drawing_Area_V->window,
192 // Drawing->width,
193 // Drawing->height,
194 // Drawing->depth);
195
196 Drawing->Pixmap = NULL;
197
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,
201// -1);
202
203
204 g_signal_connect (G_OBJECT(Drawing->Drawing_Area_V),
205 "configure_event",
206 G_CALLBACK (configure_event),
207 (gpointer)Drawing);
208
209 g_signal_connect (G_OBJECT(Drawing->Drawing_Area_V),
210 "expose_event",
211 G_CALLBACK (expose_event),
212 (gpointer)Drawing);
213
f0d936c0 214 return Drawing;
215}
216
217void Drawing_destroy(Drawing_t *Drawing)
218{
219
76a67e8a 220 // Do not unref here, Drawing_t destroyed by it's widget.
221 //g_object_unref( G_OBJECT(Drawing->Drawing_Area_V));
f0d936c0 222
223 g_free(Drawing);
224}
225
76a67e8a 226GtkWidget *Drawing_getWidget(Drawing_t *Drawing)
227{
228 return Drawing->Drawing_Area_V;
229}
230
f0d936c0 231/* get_time_from_pixels
232 *
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.
236 */
fa2c4dbe 237void convert_pixels_to_time(
238 Drawing_t *Drawing,
239 guint x,
240 LttTime *window_time_begin,
241 LttTime *window_time_end,
76a67e8a 242 LttTime *time)
f0d936c0 243{
fa2c4dbe 244 LttTime window_time_interval;
f0d936c0 245
76a67e8a 246 TimeSub(window_time_interval, *window_time_end, *window_time_begin);
f0d936c0 247
248
fa2c4dbe 249 TimeMul(*time, window_time_interval,
250 (x/(float)Drawing->width));
76a67e8a 251 TimeAdd(*time, *window_time_begin, *time);
f0d936c0 252
fa2c4dbe 253}
254
255
256
257void convert_time_to_pixels(
258 LttTime window_time_begin,
259 LttTime window_time_end,
260 LttTime time,
261 Drawing_t *Drawing,
76a67e8a 262 guint *x)
fa2c4dbe 263{
264 LttTime window_time_interval;
76a67e8a 265 float interval_float, time_float;
fa2c4dbe 266
267 TimeSub(window_time_interval, window_time_end, window_time_begin);
268
76a67e8a 269 TimeSub(time, time, window_time_begin);
fa2c4dbe 270
76a67e8a 271 interval_float = (window_time_interval.tv_sec * NANSECOND_CONST)
272 + window_time_interval.tv_nsec;
273 time_float = (time.tv_sec * NANSECOND_CONST)
274 + time.tv_nsec;
275
276 *x = (guint)(time_float/interval_float * Drawing->width);
f0d936c0 277
278}
279
847b479d 280void Drawing_Refresh ( Drawing_t *Drawing,
281 guint x, guint y,
282 guint width, guint height)
283{
284 gdk_draw_drawable(
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),
289 x, y,
290 x, y,
291 width, height);
292}
293
294
295void Drawing_draw_line( Drawing_t *Drawing,
296 GdkPixmap *Pixmap,
297 guint x1, guint y1,
298 guint x2, guint y2,
299 GdkGC *GC)
300{
301 gdk_draw_line (Pixmap,
302 GC,
303 x1, y1, x2, y2);
304}
305
306
fa2c4dbe 307
308
76a67e8a 309void Drawing_Resize(Drawing_t *Drawing, guint h, guint w)
f0d936c0 310{
f0d936c0 311 Drawing->height = h ;
76a67e8a 312 Drawing->width = w ;
f0d936c0 313
76a67e8a 314 gtk_widget_set_size_request ( Drawing->Drawing_Area_V,
315 Drawing->width,
f0d936c0 316 Drawing->height);
317
318
319}
847b479d 320
321
This page took 0.036994 seconds and 4 git commands to generate.