fa2c4dbe |
1 | |
76a67e8a |
2 | #include <gtk/gtk.h> |
3 | #include <gdk/gdk.h> |
f0d936c0 |
4 | |
831a876d |
5 | #include <lttv/processTrace.h> |
f66eba62 |
6 | #include <lttv/gtkTraceSet.h> |
7 | #include <lttv/hook.h> |
831a876d |
8 | |
d66666fe |
9 | #include "drawing.h" |
10 | #include "cfv.h" |
11 | #include "cfv-private.h" |
12 | #include "eventhooks.h" |
6d5ed1c3 |
13 | |
14 | #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format) |
15 | #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format) |
16 | |
f0d936c0 |
17 | /***************************************************************************** |
501d5405 |
18 | * drawing functions * |
f0d936c0 |
19 | *****************************************************************************/ |
20 | |
831a876d |
21 | //FIXME Colors will need to be dynamic. Graphic context part not done so far. |
f0d936c0 |
22 | typedef enum |
23 | { |
a56a1ba4 |
24 | RED, |
25 | GREEN, |
26 | BLUE, |
27 | WHITE, |
28 | BLACK |
f0d936c0 |
29 | |
30 | } ControlFlowColors; |
31 | |
32 | /* Vector of unallocated colors */ |
33 | static GdkColor CF_Colors [] = |
34 | { |
a56a1ba4 |
35 | { 0, 0xffff, 0x0000, 0x0000 }, // RED |
36 | { 0, 0x0000, 0xffff, 0x0000 }, // GREEN |
37 | { 0, 0x0000, 0x0000, 0xffff }, // BLUE |
38 | { 0, 0xffff, 0xffff, 0xffff }, // WHITE |
39 | { 0, 0x0000, 0x0000, 0x0000 } // BLACK |
f0d936c0 |
40 | }; |
41 | |
42 | |
831a876d |
43 | /* Function responsible for updating the exposed area. |
44 | * It must call processTrace() to ask for this update. |
432a7065 |
45 | * Note : this function cannot clear the background, because it may |
46 | * erase drawing already present (SAFETY). |
831a876d |
47 | */ |
501d5405 |
48 | void drawing_data_request(Drawing_t *drawing, |
b6db18f8 |
49 | GdkPixmap **pixmap, |
a56a1ba4 |
50 | gint x, gint y, |
51 | gint width, |
52 | gint height) |
847b479d |
53 | { |
d9b7ca88 |
54 | if(width < 0) return ; |
55 | if(height < 0) return ; |
a56a1ba4 |
56 | ControlFlowData *control_flow_data = |
57 | (ControlFlowData*)g_object_get_data( |
58 | G_OBJECT( |
501d5405 |
59 | drawing->drawing_area), |
68997a22 |
60 | "control_flow_data"); |
a56a1ba4 |
61 | |
62 | LttTime start, end; |
ba90bc77 |
63 | LttTime window_end = ltt_time_add(control_flow_data->time_window.time_width, |
64 | control_flow_data->time_window.start_time); |
a56a1ba4 |
65 | |
66 | g_critical("req : window_end : %u, %u", window_end.tv_sec, |
67 | window_end.tv_nsec); |
68 | |
ba90bc77 |
69 | g_critical("req : time width : %u, %u", control_flow_data->time_window.time_width.tv_sec, |
70 | control_flow_data->time_window.time_width.tv_nsec); |
a56a1ba4 |
71 | |
72 | g_critical("x is : %i, x+width is : %i", x, x+width); |
73 | |
501d5405 |
74 | convert_pixels_to_time(drawing->drawing_area->allocation.width, x, |
ba90bc77 |
75 | &control_flow_data->time_window.start_time, |
a56a1ba4 |
76 | &window_end, |
77 | &start); |
78 | |
501d5405 |
79 | convert_pixels_to_time(drawing->drawing_area->allocation.width, x + width, |
ba90bc77 |
80 | &control_flow_data->time_window.start_time, |
a56a1ba4 |
81 | &window_end, |
82 | &end); |
83 | |
84 | LttvTracesetContext * tsc = |
ba90bc77 |
85 | get_traceset_context(control_flow_data->mw); |
a56a1ba4 |
86 | |
432a7065 |
87 | //send_test_process( |
501d5405 |
88 | //guicontrolflow_get_process_list(drawing->control_flow_data), |
89 | //drawing); |
f66eba62 |
90 | //send_test_drawing( |
501d5405 |
91 | //guicontrolflow_get_process_list(drawing->control_flow_data), |
92 | //drawing, *pixmap, x, y, width, height); |
a56a1ba4 |
93 | |
94 | // Let's call processTrace() !! |
95 | EventRequest event_request; // Variable freed at the end of the function. |
68997a22 |
96 | event_request.control_flow_data = control_flow_data; |
a56a1ba4 |
97 | event_request.time_begin = start; |
98 | event_request.time_end = end; |
99 | event_request.x_begin = x; |
100 | event_request.x_end = x+width; |
101 | |
102 | g_critical("req : start : %u, %u", event_request.time_begin.tv_sec, |
103 | event_request.time_begin.tv_nsec); |
104 | |
105 | g_critical("req : end : %u, %u", event_request.time_end.tv_sec, |
106 | event_request.time_end.tv_nsec); |
107 | |
108 | LttvHooks *event = lttv_hooks_new(); |
109 | LttvHooks *after_event = lttv_hooks_new(); |
110 | LttvHooks *after_traceset = lttv_hooks_new(); |
111 | lttv_hooks_add(after_traceset, after_data_request, &event_request); |
112 | lttv_hooks_add(event, draw_event_hook, &event_request); |
113 | //Modified by xiangxiu: state update hooks are added by the main window |
ba90bc77 |
114 | //state_add_event_hooks_api(control_flow_data->mw); |
a56a1ba4 |
115 | lttv_hooks_add(after_event, draw_after_hook, &event_request); |
116 | |
117 | lttv_process_traceset_seek_time(tsc, start); |
118 | // FIXME : would like to place the after_traceset hook after the traceset, |
119 | // but the traceset context state is not valid anymore. |
120 | lttv_traceset_context_add_hooks(tsc, |
121 | // NULL, after_traceset, NULL, NULL, NULL, NULL, |
122 | NULL, NULL, NULL, NULL, NULL, NULL, |
123 | NULL, after_traceset, NULL, event, after_event); |
124 | lttv_process_traceset(tsc, end, G_MAXULONG); |
125 | //after_data_request((void*)&event_request,(void*)tsc); |
126 | lttv_traceset_context_remove_hooks(tsc, |
127 | //NULL, after_traceset, NULL, NULL, NULL, NULL, |
128 | NULL, NULL, NULL, NULL, NULL, NULL, |
129 | NULL, after_traceset, NULL, event, after_event); |
130 | //Modified by xiangxiu: state update hooks are removed by the main window |
ba90bc77 |
131 | //state_remove_event_hooks_api(control_flow_data->mw); |
a56a1ba4 |
132 | |
133 | lttv_hooks_destroy(after_traceset); |
134 | lttv_hooks_destroy(event); |
135 | lttv_hooks_destroy(after_event); |
136 | |
137 | |
847b479d |
138 | } |
a56a1ba4 |
139 | |
847b479d |
140 | /* Callbacks */ |
141 | |
142 | |
143 | /* Create a new backing pixmap of the appropriate size */ |
bd24a9af |
144 | /* As the scaling will always change, it's of no use to copy old |
145 | * pixmap. |
146 | */ |
847b479d |
147 | static gboolean |
148 | configure_event( GtkWidget *widget, GdkEventConfigure *event, |
a56a1ba4 |
149 | gpointer user_data) |
f0d936c0 |
150 | { |
501d5405 |
151 | Drawing_t *drawing = (Drawing_t*)user_data; |
f0d936c0 |
152 | |
86c520a7 |
153 | |
a56a1ba4 |
154 | /* First, get the new time interval of the main window */ |
155 | /* we assume (see documentation) that the main window |
156 | * has updated the time interval before this configure gets |
157 | * executed. |
158 | */ |
501d5405 |
159 | get_time_window(drawing->control_flow_data->mw, |
160 | &drawing->control_flow_data->time_window); |
a56a1ba4 |
161 | |
b6db18f8 |
162 | /* New pixmap, size of the configure event */ |
163 | //GdkPixmap *pixmap = gdk_pixmap_new(widget->window, |
a56a1ba4 |
164 | // widget->allocation.width + SAFETY, |
165 | // widget->allocation.height + SAFETY, |
166 | // -1); |
167 | |
f7afe191 |
168 | g_critical("drawing configure event"); |
a56a1ba4 |
169 | g_critical("New draw size : %i by %i",widget->allocation.width, widget->allocation.height); |
170 | |
171 | |
501d5405 |
172 | if (drawing->pixmap) |
173 | gdk_pixmap_unref(drawing->pixmap); |
a56a1ba4 |
174 | |
b6db18f8 |
175 | /* If no old pixmap present */ |
501d5405 |
176 | //if(drawing->pixmap == NULL) |
847b479d |
177 | { |
501d5405 |
178 | drawing->pixmap = gdk_pixmap_new( |
a56a1ba4 |
179 | widget->window, |
180 | widget->allocation.width + SAFETY, |
181 | widget->allocation.height + SAFETY, |
182 | //ProcessList_get_height |
501d5405 |
183 | // (GuiControlFlow_get_process_list(drawing->control_flow_data)), |
a56a1ba4 |
184 | -1); |
501d5405 |
185 | drawing->width = widget->allocation.width; |
186 | drawing->height = widget->allocation.height; |
a56a1ba4 |
187 | |
188 | |
189 | // Clear the image |
501d5405 |
190 | gdk_draw_rectangle (drawing->pixmap, |
a56a1ba4 |
191 | widget->style->white_gc, |
192 | TRUE, |
193 | 0, 0, |
194 | widget->allocation.width+SAFETY, |
195 | widget->allocation.height+SAFETY); |
196 | |
197 | //g_info("init data request"); |
198 | |
199 | |
200 | /* Initial data request */ |
201 | // Do not need to ask for data of 1 pixel : not synchronized with |
202 | // main window time at this moment. |
501d5405 |
203 | drawing_data_request(drawing, &drawing->pixmap, 0, 0, |
a56a1ba4 |
204 | widget->allocation.width, |
205 | widget->allocation.height); |
206 | |
501d5405 |
207 | drawing->width = widget->allocation.width; |
208 | drawing->height = widget->allocation.height; |
a56a1ba4 |
209 | |
210 | return TRUE; |
bd24a9af |
211 | |
212 | |
847b479d |
213 | |
214 | } |
bd24a9af |
215 | #ifdef NOTUSE |
847b479d |
216 | // /* Draw empty background */ |
b6db18f8 |
217 | // gdk_draw_rectangle (pixmap, |
a56a1ba4 |
218 | // widget->style->black_gc, |
219 | // TRUE, |
220 | // 0, 0, |
221 | // widget->allocation.width, |
222 | // widget->allocation.height); |
223 | |
224 | /* Copy old data to new pixmap */ |
b6db18f8 |
225 | gdk_draw_drawable (pixmap, |
a56a1ba4 |
226 | widget->style->white_gc, |
501d5405 |
227 | drawing->pixmap, |
a56a1ba4 |
228 | 0, 0, |
229 | 0, 0, |
230 | -1, -1); |
231 | |
501d5405 |
232 | if (drawing->pixmap) |
233 | gdk_pixmap_unref(drawing->pixmap); |
80a52ff8 |
234 | |
501d5405 |
235 | drawing->pixmap = pixmap; |
a56a1ba4 |
236 | |
237 | // Clear the bottom part of the image (SAFETY) |
b6db18f8 |
238 | gdk_draw_rectangle (pixmap, |
a56a1ba4 |
239 | widget->style->white_gc, |
240 | TRUE, |
501d5405 |
241 | 0, drawing->height+SAFETY, |
242 | drawing->width+SAFETY, // do not overlap |
243 | (widget->allocation.height) - drawing->height); |
bd24a9af |
244 | |
a56a1ba4 |
245 | // Clear the right part of the image (SAFETY) |
b6db18f8 |
246 | gdk_draw_rectangle (pixmap, |
a56a1ba4 |
247 | widget->style->white_gc, |
248 | TRUE, |
501d5405 |
249 | drawing->width+SAFETY, 0, |
250 | (widget->allocation.width) - drawing->width, // do not overlap |
251 | drawing->height+SAFETY); |
a56a1ba4 |
252 | |
253 | /* Clear the backgound for data request, but not SAFETY */ |
b6db18f8 |
254 | gdk_draw_rectangle (pixmap, |
501d5405 |
255 | drawing->drawing_area->style->white_gc, |
a56a1ba4 |
256 | TRUE, |
501d5405 |
257 | drawing->width + SAFETY, 0, |
258 | widget->allocation.width - drawing->width, // do not overlap |
a56a1ba4 |
259 | widget->allocation.height+SAFETY); |
bd24a9af |
260 | |
432a7065 |
261 | /* Request data for missing space */ |
a56a1ba4 |
262 | g_info("missing data request"); |
501d5405 |
263 | drawing_data_request(drawing, &pixmap, drawing->width, 0, |
264 | widget->allocation.width - drawing->width, |
a56a1ba4 |
265 | widget->allocation.height); |
266 | |
501d5405 |
267 | drawing->width = widget->allocation.width; |
268 | drawing->height = widget->allocation.height; |
847b479d |
269 | |
270 | return TRUE; |
bd24a9af |
271 | #endif //NOTUSE |
847b479d |
272 | } |
273 | |
274 | |
275 | /* Redraw the screen from the backing pixmap */ |
276 | static gboolean |
277 | expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data ) |
278 | { |
501d5405 |
279 | Drawing_t *drawing = (Drawing_t*)user_data; |
a56a1ba4 |
280 | ControlFlowData *control_flow_data = |
281 | (ControlFlowData*)g_object_get_data( |
282 | G_OBJECT(widget), |
68997a22 |
283 | "control_flow_data"); |
8b90e648 |
284 | |
847b479d |
285 | g_critical("drawing expose event"); |
a56a1ba4 |
286 | |
287 | guint x=0; |
ba90bc77 |
288 | LttTime* current_time = |
a56a1ba4 |
289 | guicontrolflow_get_current_time(control_flow_data); |
290 | |
ba90bc77 |
291 | LttTime window_end = ltt_time_add(control_flow_data->time_window.time_width, |
292 | control_flow_data->time_window.start_time); |
a56a1ba4 |
293 | |
294 | convert_time_to_pixels( |
ba90bc77 |
295 | control_flow_data->time_window.start_time, |
a56a1ba4 |
296 | window_end, |
ba90bc77 |
297 | *current_time, |
a56a1ba4 |
298 | widget->allocation.width, |
299 | &x); |
300 | |
847b479d |
301 | gdk_draw_pixmap(widget->window, |
a56a1ba4 |
302 | widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
501d5405 |
303 | drawing->pixmap, |
a56a1ba4 |
304 | event->area.x, event->area.y, |
305 | event->area.x, event->area.y, |
306 | event->area.width, event->area.height); |
307 | |
308 | if(x >= event->area.x && x <= event->area.x+event->area.width) |
309 | { |
501d5405 |
310 | GdkGC *gc = gdk_gc_new(control_flow_data->drawing->pixmap); |
a56a1ba4 |
311 | gdk_gc_copy(gc, widget->style->black_gc); |
312 | |
313 | drawing_draw_line(NULL, widget->window, |
314 | x, event->area.y, |
315 | x, event->area.y+event->area.height, |
316 | gc); |
317 | gdk_gc_unref(gc); |
318 | } |
847b479d |
319 | return FALSE; |
320 | } |
321 | |
8b90e648 |
322 | /* mouse click */ |
323 | static gboolean |
324 | button_press_event( GtkWidget *widget, GdkEventButton *event, gpointer user_data ) |
325 | { |
a56a1ba4 |
326 | ControlFlowData *control_flow_data = |
327 | (ControlFlowData*)g_object_get_data( |
328 | G_OBJECT(widget), |
68997a22 |
329 | "control_flow_data"); |
501d5405 |
330 | Drawing_t *drawing = control_flow_data->drawing; |
8b90e648 |
331 | |
332 | |
a56a1ba4 |
333 | g_critical("click"); |
334 | if(event->button == 1) |
335 | { |
336 | LttTime time; |
8b90e648 |
337 | |
ba90bc77 |
338 | LttTime window_end = ltt_time_add(control_flow_data->time_window.time_width, |
339 | control_flow_data->time_window.start_time); |
8b90e648 |
340 | |
341 | |
a56a1ba4 |
342 | /* left mouse button click */ |
343 | g_critical("x click is : %f", event->x); |
8b90e648 |
344 | |
a56a1ba4 |
345 | convert_pixels_to_time(widget->allocation.width, (guint)event->x, |
ba90bc77 |
346 | &control_flow_data->time_window.start_time, |
a56a1ba4 |
347 | &window_end, |
348 | &time); |
8b90e648 |
349 | |
ba90bc77 |
350 | set_current_time(control_flow_data->mw, &time); |
8b90e648 |
351 | |
a56a1ba4 |
352 | } |
353 | |
354 | return FALSE; |
8b90e648 |
355 | } |
356 | |
357 | |
358 | |
359 | |
68997a22 |
360 | Drawing_t *drawing_construct(ControlFlowData *control_flow_data) |
847b479d |
361 | { |
501d5405 |
362 | Drawing_t *drawing = g_new(Drawing_t, 1); |
a56a1ba4 |
363 | |
501d5405 |
364 | drawing->drawing_area = gtk_drawing_area_new (); |
365 | drawing->control_flow_data = control_flow_data; |
a56a1ba4 |
366 | |
501d5405 |
367 | drawing->pango_layout = |
368 | gtk_widget_create_pango_layout(drawing->drawing_area, NULL); |
a56a1ba4 |
369 | |
501d5405 |
370 | //gtk_widget_set_size_request(drawing->drawing_area->window, 50, 50); |
a56a1ba4 |
371 | g_object_set_data_full( |
501d5405 |
372 | G_OBJECT(drawing->drawing_area), |
373 | "Link_drawing_Data", |
374 | drawing, |
a56a1ba4 |
375 | (GDestroyNotify)drawing_destroy); |
376 | |
501d5405 |
377 | //gtk_widget_modify_bg( drawing->drawing_area, |
a56a1ba4 |
378 | // GTK_STATE_NORMAL, |
379 | // &CF_Colors[BLACK]); |
380 | |
501d5405 |
381 | //gdk_window_get_geometry(drawing->drawing_area->window, |
a56a1ba4 |
382 | // NULL, NULL, |
501d5405 |
383 | // &(drawing->width), |
384 | // &(drawing->height), |
a56a1ba4 |
385 | // -1); |
386 | |
501d5405 |
387 | //drawing->pixmap = gdk_pixmap_new( |
388 | // drawing->drawing_area->window, |
389 | // drawing->width, |
390 | // drawing->height, |
391 | // drawing->depth); |
a56a1ba4 |
392 | |
501d5405 |
393 | drawing->pixmap = NULL; |
a56a1ba4 |
394 | |
501d5405 |
395 | // drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window, |
396 | // drawing->drawing_area->allocation.width, |
397 | // drawing->drawing_area->allocation.height, |
a56a1ba4 |
398 | // -1); |
399 | |
501d5405 |
400 | gtk_widget_add_events(drawing->drawing_area, GDK_BUTTON_PRESS_MASK); |
a56a1ba4 |
401 | |
501d5405 |
402 | g_signal_connect (G_OBJECT(drawing->drawing_area), |
a56a1ba4 |
403 | "configure_event", |
404 | G_CALLBACK (configure_event), |
501d5405 |
405 | (gpointer)drawing); |
a56a1ba4 |
406 | |
501d5405 |
407 | g_signal_connect (G_OBJECT(drawing->drawing_area), |
a56a1ba4 |
408 | "expose_event", |
409 | G_CALLBACK (expose_event), |
501d5405 |
410 | (gpointer)drawing); |
a56a1ba4 |
411 | |
501d5405 |
412 | g_signal_connect (G_OBJECT(drawing->drawing_area), |
a56a1ba4 |
413 | "button-press-event", |
414 | G_CALLBACK (button_press_event), |
501d5405 |
415 | (gpointer)drawing); |
a56a1ba4 |
416 | |
417 | |
501d5405 |
418 | return drawing; |
f0d936c0 |
419 | } |
420 | |
501d5405 |
421 | void drawing_destroy(Drawing_t *drawing) |
f0d936c0 |
422 | { |
423 | |
a56a1ba4 |
424 | // Do not unref here, Drawing_t destroyed by it's widget. |
501d5405 |
425 | //g_object_unref( G_OBJECT(drawing->drawing_area)); |
a56a1ba4 |
426 | |
501d5405 |
427 | g_free(drawing->pango_layout); |
428 | g_free(drawing); |
f0d936c0 |
429 | } |
430 | |
501d5405 |
431 | GtkWidget *drawing_get_widget(Drawing_t *drawing) |
76a67e8a |
432 | { |
501d5405 |
433 | return drawing->drawing_area; |
76a67e8a |
434 | } |
435 | |
f66eba62 |
436 | /* convert_pixels_to_time |
f0d936c0 |
437 | * |
f66eba62 |
438 | * Convert from window pixel and time interval to an absolute time. |
f0d936c0 |
439 | */ |
fa2c4dbe |
440 | void convert_pixels_to_time( |
a56a1ba4 |
441 | gint width, |
442 | guint x, |
443 | LttTime *window_time_begin, |
444 | LttTime *window_time_end, |
445 | LttTime *time) |
f0d936c0 |
446 | { |
a56a1ba4 |
447 | LttTime window_time_interval; |
448 | |
449 | window_time_interval = ltt_time_sub(*window_time_end, |
308711e5 |
450 | *window_time_begin); |
a56a1ba4 |
451 | *time = ltt_time_mul(window_time_interval, (x/(float)width)); |
452 | *time = ltt_time_add(*window_time_begin, *time); |
fa2c4dbe |
453 | } |
454 | |
455 | |
456 | |
457 | void convert_time_to_pixels( |
a56a1ba4 |
458 | LttTime window_time_begin, |
459 | LttTime window_time_end, |
460 | LttTime time, |
461 | int width, |
462 | guint *x) |
fa2c4dbe |
463 | { |
a56a1ba4 |
464 | LttTime window_time_interval; |
465 | float interval_float, time_float; |
466 | |
467 | window_time_interval = ltt_time_sub(window_time_end,window_time_begin); |
468 | |
469 | time = ltt_time_sub(time, window_time_begin); |
470 | |
471 | interval_float = ltt_time_to_double(window_time_interval); |
472 | time_float = ltt_time_to_double(time); |
473 | |
474 | *x = (guint)(time_float/interval_float * width); |
475 | |
f0d936c0 |
476 | } |
477 | |
501d5405 |
478 | void drawing_refresh ( Drawing_t *drawing, |
a56a1ba4 |
479 | guint x, guint y, |
480 | guint width, guint height) |
847b479d |
481 | { |
a56a1ba4 |
482 | g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x, y, width, height); |
483 | GdkRectangle update_rect; |
484 | |
485 | gdk_draw_drawable( |
501d5405 |
486 | drawing->drawing_area->window, |
487 | drawing->drawing_area-> |
488 | style->fg_gc[GTK_WIDGET_STATE (drawing->drawing_area)], |
489 | GDK_DRAWABLE(drawing->pixmap), |
a56a1ba4 |
490 | x, y, |
491 | x, y, |
492 | width, height); |
493 | |
494 | update_rect.x = 0 ; |
495 | update_rect.y = 0 ; |
501d5405 |
496 | update_rect.width = drawing->width; |
497 | update_rect.height = drawing->height ; |
498 | gtk_widget_draw( drawing->drawing_area, &update_rect); |
f7afe191 |
499 | |
847b479d |
500 | } |
501 | |
502 | |
501d5405 |
503 | void drawing_draw_line( Drawing_t *drawing, |
b6db18f8 |
504 | GdkPixmap *pixmap, |
a56a1ba4 |
505 | guint x1, guint y1, |
506 | guint x2, guint y2, |
507 | GdkGC *GC) |
847b479d |
508 | { |
b6db18f8 |
509 | gdk_draw_line (pixmap, |
a56a1ba4 |
510 | GC, |
511 | x1, y1, x2, y2); |
847b479d |
512 | } |
513 | |
514 | |
fa2c4dbe |
515 | |
516 | |
501d5405 |
517 | void drawing_resize(Drawing_t *drawing, guint h, guint w) |
f0d936c0 |
518 | { |
501d5405 |
519 | drawing->height = h ; |
520 | drawing->width = w ; |
a56a1ba4 |
521 | |
501d5405 |
522 | gtk_widget_set_size_request ( drawing->drawing_area, |
523 | drawing->width, |
524 | drawing->height); |
a56a1ba4 |
525 | |
526 | |
f0d936c0 |
527 | } |
847b479d |
528 | |
529 | |
5f16133f |
530 | /* Insert a square corresponding to a new process in the list */ |
501d5405 |
531 | /* Applies to whole drawing->width */ |
532 | void drawing_insert_square(Drawing_t *drawing, |
a56a1ba4 |
533 | guint y, |
534 | guint height) |
5f16133f |
535 | { |
a56a1ba4 |
536 | //GdkRectangle update_rect; |
5f16133f |
537 | |
a56a1ba4 |
538 | /* Allocate a new pixmap with new height */ |
501d5405 |
539 | GdkPixmap *pixmap = gdk_pixmap_new(drawing->drawing_area->window, |
540 | drawing->width + SAFETY, |
541 | drawing->height + height + SAFETY, |
a56a1ba4 |
542 | -1); |
543 | |
544 | /* Copy the high region */ |
b6db18f8 |
545 | gdk_draw_drawable (pixmap, |
501d5405 |
546 | drawing->drawing_area->style->black_gc, |
547 | drawing->pixmap, |
a56a1ba4 |
548 | 0, 0, |
549 | 0, 0, |
501d5405 |
550 | drawing->width + SAFETY, y); |
5f16133f |
551 | |
552 | |
553 | |
5f16133f |
554 | |
a56a1ba4 |
555 | /* add an empty square */ |
b6db18f8 |
556 | gdk_draw_rectangle (pixmap, |
501d5405 |
557 | drawing->drawing_area->style->white_gc, |
a56a1ba4 |
558 | TRUE, |
559 | 0, y, |
501d5405 |
560 | drawing->width + SAFETY, // do not overlap |
a56a1ba4 |
561 | height); |
5f16133f |
562 | |
563 | |
5f16133f |
564 | |
a56a1ba4 |
565 | /* copy the bottom of the region */ |
b6db18f8 |
566 | gdk_draw_drawable (pixmap, |
501d5405 |
567 | drawing->drawing_area->style->black_gc, |
568 | drawing->pixmap, |
a56a1ba4 |
569 | 0, y, |
570 | 0, y + height, |
501d5405 |
571 | drawing->width+SAFETY, drawing->height - y + SAFETY); |
5f16133f |
572 | |
573 | |
574 | |
5f16133f |
575 | |
501d5405 |
576 | if (drawing->pixmap) |
577 | gdk_pixmap_unref(drawing->pixmap); |
5f16133f |
578 | |
501d5405 |
579 | drawing->pixmap = pixmap; |
a56a1ba4 |
580 | |
501d5405 |
581 | drawing->height+=height; |
a56a1ba4 |
582 | |
501d5405 |
583 | /* Rectangle to update, from new drawing dimensions */ |
a56a1ba4 |
584 | //update_rect.x = 0 ; |
585 | //update_rect.y = y ; |
501d5405 |
586 | //update_rect.width = drawing->width; |
587 | //update_rect.height = drawing->height - y ; |
588 | //gtk_widget_draw( drawing->drawing_area, &update_rect); |
5f16133f |
589 | } |
590 | |
591 | |
592 | /* Remove a square corresponding to a removed process in the list */ |
501d5405 |
593 | void drawing_remove_square(Drawing_t *drawing, |
a56a1ba4 |
594 | guint y, |
595 | guint height) |
5f16133f |
596 | { |
a56a1ba4 |
597 | //GdkRectangle update_rect; |
598 | |
599 | /* Allocate a new pixmap with new height */ |
b6db18f8 |
600 | GdkPixmap *pixmap = gdk_pixmap_new( |
501d5405 |
601 | drawing->drawing_area->window, |
602 | drawing->width + SAFETY, |
603 | drawing->height - height + SAFETY, |
a56a1ba4 |
604 | -1); |
605 | |
606 | /* Copy the high region */ |
b6db18f8 |
607 | gdk_draw_drawable (pixmap, |
501d5405 |
608 | drawing->drawing_area->style->black_gc, |
609 | drawing->pixmap, |
a56a1ba4 |
610 | 0, 0, |
611 | 0, 0, |
501d5405 |
612 | drawing->width + SAFETY, y); |
a56a1ba4 |
613 | |
614 | |
615 | |
616 | /* Copy up the bottom of the region */ |
b6db18f8 |
617 | gdk_draw_drawable (pixmap, |
501d5405 |
618 | drawing->drawing_area->style->black_gc, |
619 | drawing->pixmap, |
a56a1ba4 |
620 | 0, y + height, |
621 | 0, y, |
501d5405 |
622 | drawing->width, drawing->height - y - height + SAFETY); |
a56a1ba4 |
623 | |
624 | |
501d5405 |
625 | if (drawing->pixmap) |
626 | gdk_pixmap_unref(drawing->pixmap); |
a56a1ba4 |
627 | |
501d5405 |
628 | drawing->pixmap = pixmap; |
a56a1ba4 |
629 | |
501d5405 |
630 | drawing->height-=height; |
a56a1ba4 |
631 | |
501d5405 |
632 | /* Rectangle to update, from new drawing dimensions */ |
a56a1ba4 |
633 | //update_rect.x = 0 ; |
634 | //update_rect.y = y ; |
501d5405 |
635 | //update_rect.width = drawing->width; |
636 | //update_rect.height = drawing->height - y ; |
637 | //gtk_widget_draw( drawing->drawing_area, &update_rect); |
5f16133f |
638 | } |
189a5d08 |
639 | |
640 | |