fa2c4dbe |
1 | |
f0d936c0 |
2 | #include "Drawing.h" |
f7afe191 |
3 | #include "CFV.h" |
76a67e8a |
4 | #include <gtk/gtk.h> |
5 | #include <gdk/gdk.h> |
f0d936c0 |
6 | |
831a876d |
7 | #include <lttv/processTrace.h> |
8 | |
6d5ed1c3 |
9 | |
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) |
12 | |
13 | |
f0d936c0 |
14 | /***************************************************************************** |
15 | * Drawing functions * |
16 | *****************************************************************************/ |
17 | |
831a876d |
18 | //FIXME Colors will need to be dynamic. Graphic context part not done so far. |
f0d936c0 |
19 | typedef enum |
20 | { |
21 | RED, |
22 | GREEN, |
23 | BLUE, |
24 | WHITE, |
25 | BLACK |
26 | |
27 | } ControlFlowColors; |
28 | |
29 | /* Vector of unallocated colors */ |
30 | static GdkColor CF_Colors [] = |
31 | { |
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 |
37 | }; |
38 | |
39 | |
831a876d |
40 | /* Function responsible for updating the exposed area. |
41 | * It must call processTrace() to ask for this update. |
42 | */ |
4c69e0cc |
43 | void drawing_data_request(Drawing_t *Drawing, |
f7afe191 |
44 | GdkPixmap **Pixmap, |
847b479d |
45 | gint x, gint y, |
4c69e0cc |
46 | gint width, |
847b479d |
47 | gint height) |
48 | { |
8d088fb2 |
49 | |
50 | // start from pixel to time(x) |
51 | // end from pixel to time (x + width) |
52 | |
53 | // LttvTracesetContext * tsc = get_traceset_context(event_viewer_data->mw); |
54 | |
d9b7ca88 |
55 | if(width < 0) return ; |
56 | if(height < 0) return ; |
57 | |
f7afe191 |
58 | gdk_draw_rectangle (*Pixmap, |
847b479d |
59 | Drawing->Drawing_Area_V->style->white_gc, |
60 | TRUE, |
61 | x, y, |
62 | width, // do not overlap |
63 | height); |
64 | |
f7afe191 |
65 | send_test_process( |
4c69e0cc |
66 | guicontrolflow_get_process_list(Drawing->Control_Flow_Data), |
f7afe191 |
67 | Drawing); |
68 | send_test_drawing( |
4c69e0cc |
69 | guicontrolflow_get_process_list(Drawing->Control_Flow_Data), |
f7afe191 |
70 | Drawing, *Pixmap, x, y, width, height); |
831a876d |
71 | |
8d088fb2 |
72 | // Let's call processTrace() !! |
73 | |
74 | |
75 | //lttv_process_traceset_seek_time(tsc, start); |
76 | //lttv_traceset_context_add_hooks( |
77 | //lttv_process_traceset |
78 | //lttv_traceset_context_remove_hooks |
847b479d |
79 | } |
80 | |
81 | /* Callbacks */ |
82 | |
83 | |
84 | /* Create a new backing pixmap of the appropriate size */ |
85 | static gboolean |
86 | configure_event( GtkWidget *widget, GdkEventConfigure *event, |
87 | gpointer user_data) |
f0d936c0 |
88 | { |
847b479d |
89 | Drawing_t *Drawing = (Drawing_t*)user_data; |
f0d936c0 |
90 | |
f7afe191 |
91 | /* New Pixmap, size of the configure event */ |
847b479d |
92 | GdkPixmap *Pixmap = gdk_pixmap_new(widget->window, |
93 | widget->allocation.width, |
94 | widget->allocation.height, |
95 | -1); |
96 | |
f7afe191 |
97 | g_critical("drawing configure event"); |
98 | |
99 | /* If no old Pixmap present */ |
847b479d |
100 | if(Drawing->Pixmap == NULL) |
101 | { |
f7afe191 |
102 | Drawing->Pixmap = gdk_pixmap_new( |
103 | widget->window, |
104 | widget->allocation.width, |
105 | widget->allocation.height, |
106 | //ProcessList_get_height |
107 | // (GuiControlFlow_get_Process_List(Drawing->Control_Flow_Data)), |
108 | -1); |
847b479d |
109 | Drawing->width = widget->allocation.width; |
110 | Drawing->height = widget->allocation.height; |
f7afe191 |
111 | g_critical("init data"); |
847b479d |
112 | /* Initial data request */ |
4c69e0cc |
113 | drawing_data_request(Drawing, &Drawing->Pixmap, 0, 0, |
847b479d |
114 | widget->allocation.width, |
115 | widget->allocation.height); |
116 | |
117 | } |
118 | // /* Draw empty background */ |
119 | // gdk_draw_rectangle (Pixmap, |
120 | // widget->style->black_gc, |
121 | // TRUE, |
122 | // 0, 0, |
123 | // widget->allocation.width, |
124 | // widget->allocation.height); |
125 | |
126 | /* Copy old data to new pixmap */ |
127 | gdk_draw_drawable (Pixmap, |
128 | widget->style->white_gc, |
129 | Drawing->Pixmap, |
130 | 0, 0, |
131 | 0, 0, |
132 | -1, -1); |
133 | |
134 | /* Request data for missing space */ |
f7afe191 |
135 | g_critical("missing data"); |
4c69e0cc |
136 | drawing_data_request(Drawing, &Pixmap, Drawing->width, 0, |
847b479d |
137 | widget->allocation.width - Drawing->width, |
138 | widget->allocation.height); |
4c69e0cc |
139 | drawing_data_request(Drawing, &Pixmap, 0, Drawing->height, |
847b479d |
140 | Drawing->width, |
141 | widget->allocation.height - Drawing->height); |
142 | |
143 | // gdk_draw_rectangle (Pixmap, |
144 | // widget->style->white_gc, |
145 | // TRUE, |
146 | // Drawing->width, 0, |
147 | // widget->allocation.width - |
148 | // Drawing->width, |
149 | // widget->allocation.height); |
150 | |
151 | // gdk_draw_rectangle (Pixmap, |
152 | // widget->style->white_gc, |
153 | // TRUE, |
154 | // 0, Drawing->height, |
155 | // Drawing->width, // do not overlap |
156 | // widget->allocation.height - |
157 | // Drawing->height); |
158 | |
847b479d |
159 | |
847b479d |
160 | |
161 | if (Drawing->Pixmap) |
162 | gdk_pixmap_unref(Drawing->Pixmap); |
163 | |
164 | Drawing->Pixmap = Pixmap; |
165 | Drawing->width = widget->allocation.width; |
166 | Drawing->height = widget->allocation.height; |
167 | |
168 | return TRUE; |
169 | } |
170 | |
171 | |
172 | /* Redraw the screen from the backing pixmap */ |
173 | static gboolean |
174 | expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data ) |
175 | { |
176 | Drawing_t *Drawing = (Drawing_t*)user_data; |
177 | g_critical("drawing expose event"); |
178 | |
179 | gdk_draw_pixmap(widget->window, |
180 | widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
181 | Drawing->Pixmap, |
182 | event->area.x, event->area.y, |
183 | event->area.x, event->area.y, |
184 | event->area.width, event->area.height); |
185 | |
186 | return FALSE; |
187 | } |
188 | |
4c69e0cc |
189 | Drawing_t *drawing_construct(ControlFlowData *Control_Flow_Data) |
847b479d |
190 | { |
76a67e8a |
191 | Drawing_t *Drawing = g_new(Drawing_t, 1); |
f0d936c0 |
192 | |
193 | Drawing->Drawing_Area_V = gtk_drawing_area_new (); |
f7afe191 |
194 | Drawing->Control_Flow_Data = Control_Flow_Data; |
195 | |
847b479d |
196 | //gtk_widget_set_size_request(Drawing->Drawing_Area_V->window, 50, 50); |
f0d936c0 |
197 | g_object_set_data_full( |
198 | G_OBJECT(Drawing->Drawing_Area_V), |
76a67e8a |
199 | "Link_Drawing_Data", |
f0d936c0 |
200 | Drawing, |
3cff8cc1 |
201 | (GDestroyNotify)drawing_destroy); |
f0d936c0 |
202 | |
847b479d |
203 | //gtk_widget_modify_bg( Drawing->Drawing_Area_V, |
204 | // GTK_STATE_NORMAL, |
205 | // &CF_Colors[BLACK]); |
206 | |
207 | //gdk_window_get_geometry(Drawing->Drawing_Area_V->window, |
208 | // NULL, NULL, |
209 | // &(Drawing->width), |
210 | // &(Drawing->height), |
211 | // -1); |
212 | |
213 | //Drawing->Pixmap = gdk_pixmap_new( |
214 | // Drawing->Drawing_Area_V->window, |
215 | // Drawing->width, |
216 | // Drawing->height, |
217 | // Drawing->depth); |
218 | |
219 | Drawing->Pixmap = NULL; |
220 | |
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, |
224 | // -1); |
225 | |
847b479d |
226 | g_signal_connect (G_OBJECT(Drawing->Drawing_Area_V), |
227 | "configure_event", |
228 | G_CALLBACK (configure_event), |
229 | (gpointer)Drawing); |
230 | |
231 | g_signal_connect (G_OBJECT(Drawing->Drawing_Area_V), |
232 | "expose_event", |
233 | G_CALLBACK (expose_event), |
234 | (gpointer)Drawing); |
235 | |
f0d936c0 |
236 | return Drawing; |
237 | } |
238 | |
4c69e0cc |
239 | void drawing_destroy(Drawing_t *Drawing) |
f0d936c0 |
240 | { |
241 | |
76a67e8a |
242 | // Do not unref here, Drawing_t destroyed by it's widget. |
243 | //g_object_unref( G_OBJECT(Drawing->Drawing_Area_V)); |
f0d936c0 |
244 | |
245 | g_free(Drawing); |
246 | } |
247 | |
4c69e0cc |
248 | GtkWidget *drawing_get_widget(Drawing_t *Drawing) |
76a67e8a |
249 | { |
250 | return Drawing->Drawing_Area_V; |
251 | } |
252 | |
f0d936c0 |
253 | /* get_time_from_pixels |
254 | * |
308711e5 |
255 | * Get the time interval from window time and pixels, and pixels requested. |
f0d936c0 |
256 | */ |
fa2c4dbe |
257 | void convert_pixels_to_time( |
258 | Drawing_t *Drawing, |
259 | guint x, |
260 | LttTime *window_time_begin, |
261 | LttTime *window_time_end, |
76a67e8a |
262 | LttTime *time) |
f0d936c0 |
263 | { |
fa2c4dbe |
264 | LttTime window_time_interval; |
f0d936c0 |
265 | |
308711e5 |
266 | window_time_interval = ltt_time_sub(*window_time_end, |
267 | *window_time_begin); |
268 | *time = ltt_time_mul(window_time_interval, (x/(float)Drawing->width)); |
269 | *time = ltt_time_add(*window_time_begin, *time); |
fa2c4dbe |
270 | } |
271 | |
272 | |
273 | |
274 | void convert_time_to_pixels( |
275 | LttTime window_time_begin, |
276 | LttTime window_time_end, |
277 | LttTime time, |
278 | Drawing_t *Drawing, |
76a67e8a |
279 | guint *x) |
fa2c4dbe |
280 | { |
281 | LttTime window_time_interval; |
76a67e8a |
282 | float interval_float, time_float; |
fa2c4dbe |
283 | |
308711e5 |
284 | window_time_interval = ltt_time_sub(window_time_end,window_time_begin); |
fa2c4dbe |
285 | |
308711e5 |
286 | time = ltt_time_sub(time, window_time_begin); |
fa2c4dbe |
287 | |
308711e5 |
288 | interval_float = ltt_time_to_double(window_time_interval); |
289 | time_float = ltt_time_to_double(time); |
76a67e8a |
290 | |
291 | *x = (guint)(time_float/interval_float * Drawing->width); |
f0d936c0 |
292 | |
293 | } |
294 | |
4c69e0cc |
295 | void drawing_refresh ( Drawing_t *Drawing, |
847b479d |
296 | guint x, guint y, |
297 | guint width, guint height) |
298 | { |
6d5ed1c3 |
299 | g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x, y, width, height); |
f7afe191 |
300 | GdkRectangle update_rect; |
301 | |
847b479d |
302 | gdk_draw_drawable( |
303 | Drawing->Drawing_Area_V->window, |
304 | Drawing->Drawing_Area_V-> |
305 | style->fg_gc[GTK_WIDGET_STATE (Drawing->Drawing_Area_V)], |
306 | GDK_DRAWABLE(Drawing->Pixmap), |
307 | x, y, |
308 | x, y, |
309 | width, height); |
f7afe191 |
310 | |
311 | update_rect.x = 0 ; |
312 | update_rect.y = 0 ; |
313 | update_rect.width = Drawing->width; |
314 | update_rect.height = Drawing->height ; |
315 | gtk_widget_draw( Drawing->Drawing_Area_V, &update_rect); |
316 | |
847b479d |
317 | } |
318 | |
319 | |
4c69e0cc |
320 | void drawing_draw_line( Drawing_t *Drawing, |
847b479d |
321 | GdkPixmap *Pixmap, |
322 | guint x1, guint y1, |
323 | guint x2, guint y2, |
324 | GdkGC *GC) |
325 | { |
326 | gdk_draw_line (Pixmap, |
327 | GC, |
328 | x1, y1, x2, y2); |
329 | } |
330 | |
331 | |
fa2c4dbe |
332 | |
333 | |
4c69e0cc |
334 | void drawing_resize(Drawing_t *Drawing, guint h, guint w) |
f0d936c0 |
335 | { |
f0d936c0 |
336 | Drawing->height = h ; |
76a67e8a |
337 | Drawing->width = w ; |
f0d936c0 |
338 | |
76a67e8a |
339 | gtk_widget_set_size_request ( Drawing->Drawing_Area_V, |
340 | Drawing->width, |
f0d936c0 |
341 | Drawing->height); |
342 | |
343 | |
344 | } |
847b479d |
345 | |
346 | |
5f16133f |
347 | /* Insert a square corresponding to a new process in the list */ |
348 | /* Applies to whole Drawing->width */ |
4c69e0cc |
349 | void drawing_insert_square(Drawing_t *Drawing, |
5f16133f |
350 | guint y, |
351 | guint height) |
352 | { |
353 | GdkRectangle update_rect; |
354 | |
355 | /* Allocate a new pixmap with new height */ |
356 | GdkPixmap *Pixmap = gdk_pixmap_new(Drawing->Drawing_Area_V->window, |
357 | Drawing->width, |
358 | Drawing->height + height, |
359 | -1); |
360 | |
361 | /* Copy the high region */ |
362 | gdk_draw_drawable (Pixmap, |
363 | Drawing->Drawing_Area_V->style->black_gc, |
364 | Drawing->Pixmap, |
365 | 0, 0, |
366 | 0, 0, |
367 | Drawing->width, y); |
368 | |
369 | |
370 | |
371 | |
372 | /* add an empty square */ |
373 | gdk_draw_rectangle (Pixmap, |
1ab3d149 |
374 | Drawing->Drawing_Area_V->style->black_gc, |
5f16133f |
375 | TRUE, |
376 | 0, y, |
377 | Drawing->width, // do not overlap |
378 | height); |
379 | |
380 | |
381 | |
382 | /* copy the bottom of the region */ |
383 | gdk_draw_drawable (Pixmap, |
384 | Drawing->Drawing_Area_V->style->black_gc, |
385 | Drawing->Pixmap, |
386 | 0, y, |
387 | 0, y + height, |
388 | Drawing->width, Drawing->height - y); |
389 | |
390 | |
391 | |
392 | |
393 | if (Drawing->Pixmap) |
394 | gdk_pixmap_unref(Drawing->Pixmap); |
395 | |
396 | Drawing->Pixmap = Pixmap; |
397 | |
398 | Drawing->height+=height; |
399 | |
400 | /* Rectangle to update, from new Drawing dimensions */ |
401 | update_rect.x = 0 ; |
402 | update_rect.y = y ; |
403 | update_rect.width = Drawing->width; |
404 | update_rect.height = Drawing->height - y ; |
405 | gtk_widget_draw( Drawing->Drawing_Area_V, &update_rect); |
406 | } |
407 | |
408 | |
409 | /* Remove a square corresponding to a removed process in the list */ |
4c69e0cc |
410 | void drawing_remove_square(Drawing_t *Drawing, |
5f16133f |
411 | guint y, |
412 | guint height) |
413 | { |
414 | GdkRectangle update_rect; |
415 | |
416 | /* Allocate a new pixmap with new height */ |
417 | GdkPixmap *Pixmap = gdk_pixmap_new( |
418 | Drawing->Drawing_Area_V->window, |
419 | Drawing->width, |
420 | Drawing->height - height, |
421 | -1); |
422 | |
423 | /* Copy the high region */ |
424 | gdk_draw_drawable (Pixmap, |
425 | Drawing->Drawing_Area_V->style->black_gc, |
426 | Drawing->Pixmap, |
427 | 0, 0, |
428 | 0, 0, |
429 | Drawing->width, y); |
430 | |
431 | |
432 | |
433 | /* Copy up the bottom of the region */ |
434 | gdk_draw_drawable (Pixmap, |
435 | Drawing->Drawing_Area_V->style->black_gc, |
436 | Drawing->Pixmap, |
437 | 0, y + height, |
438 | 0, y, |
439 | Drawing->width, Drawing->height - y - height); |
440 | |
441 | |
442 | if (Drawing->Pixmap) |
443 | gdk_pixmap_unref(Drawing->Pixmap); |
444 | |
445 | Drawing->Pixmap = Pixmap; |
446 | |
447 | Drawing->height-=height; |
448 | |
449 | /* Rectangle to update, from new Drawing dimensions */ |
450 | update_rect.x = 0 ; |
451 | update_rect.y = y ; |
452 | update_rect.width = Drawing->width; |
453 | update_rect.height = Drawing->height - y ; |
454 | gtk_widget_draw( Drawing->Drawing_Area_V, &update_rect); |
455 | } |
189a5d08 |
456 | |
457 | |