ce0214a6 |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 Mathieu Desnoyers |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License Version 2 as |
6 | * published by the Free Software Foundation; |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
16 | * MA 02111-1307, USA. |
17 | */ |
fa2c4dbe |
18 | |
76a67e8a |
19 | #include <gtk/gtk.h> |
20 | #include <gdk/gdk.h> |
f0d936c0 |
21 | |
2a2fa4f0 |
22 | #include <lttv/lttv.h> |
d8f124de |
23 | #include <lttv/tracecontext.h> |
5ac76b22 |
24 | #include <lttvwindow/viewer.h> |
b21c82b6 |
25 | #include <lttv/state.h> |
f66eba62 |
26 | #include <lttv/hook.h> |
831a876d |
27 | |
d66666fe |
28 | #include "drawing.h" |
29 | #include "cfv.h" |
30 | #include "cfv-private.h" |
31 | #include "eventhooks.h" |
6d5ed1c3 |
32 | |
33 | #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format) |
34 | #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format) |
35 | |
f0d936c0 |
36 | /***************************************************************************** |
501d5405 |
37 | * drawing functions * |
f0d936c0 |
38 | *****************************************************************************/ |
39 | |
3cb8b205 |
40 | static gboolean |
41 | expose_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data ); |
42 | |
d287af9a |
43 | static gboolean |
44 | motion_notify_ruler(GtkWidget *widget, GdkEventMotion *event, gpointer user_data); |
3cb8b205 |
45 | |
46 | |
831a876d |
47 | //FIXME Colors will need to be dynamic. Graphic context part not done so far. |
f0d936c0 |
48 | typedef enum |
49 | { |
a56a1ba4 |
50 | RED, |
51 | GREEN, |
52 | BLUE, |
53 | WHITE, |
54 | BLACK |
f0d936c0 |
55 | |
56 | } ControlFlowColors; |
57 | |
58 | /* Vector of unallocated colors */ |
59 | static GdkColor CF_Colors [] = |
60 | { |
a56a1ba4 |
61 | { 0, 0xffff, 0x0000, 0x0000 }, // RED |
62 | { 0, 0x0000, 0xffff, 0x0000 }, // GREEN |
63 | { 0, 0x0000, 0x0000, 0xffff }, // BLUE |
64 | { 0, 0xffff, 0xffff, 0xffff }, // WHITE |
65 | { 0, 0x0000, 0x0000, 0x0000 } // BLACK |
f0d936c0 |
66 | }; |
67 | |
68 | |
831a876d |
69 | /* Function responsible for updating the exposed area. |
70 | * It must call processTrace() to ask for this update. |
432a7065 |
71 | * Note : this function cannot clear the background, because it may |
72 | * erase drawing already present (SAFETY). |
831a876d |
73 | */ |
501d5405 |
74 | void drawing_data_request(Drawing_t *drawing, |
b6db18f8 |
75 | GdkPixmap **pixmap, |
a56a1ba4 |
76 | gint x, gint y, |
77 | gint width, |
78 | gint height) |
847b479d |
79 | { |
d9b7ca88 |
80 | if(width < 0) return ; |
81 | if(height < 0) return ; |
224446ce |
82 | |
83 | const TimeWindow *time_window = lttvwindow_get_time_window(drawing->control_flow_data->mw); |
84 | |
a56a1ba4 |
85 | ControlFlowData *control_flow_data = |
86 | (ControlFlowData*)g_object_get_data( |
224446ce |
87 | G_OBJECT(drawing->drawing_area), "control_flow_data"); |
a56a1ba4 |
88 | |
89 | LttTime start, end; |
224446ce |
90 | LttTime window_end = ltt_time_add(time_window->time_width, |
91 | time_window->start_time); |
a56a1ba4 |
92 | |
2a2fa4f0 |
93 | g_debug("req : window_end : %u, %u", window_end.tv_sec, |
224446ce |
94 | window_end.tv_nsec); |
a56a1ba4 |
95 | |
224446ce |
96 | g_debug("req : time width : %u, %u", time_window->time_width.tv_sec, |
97 | time_window->time_width.tv_nsec); |
a56a1ba4 |
98 | |
2a2fa4f0 |
99 | g_debug("x is : %i, x+width is : %i", x, x+width); |
a56a1ba4 |
100 | |
501d5405 |
101 | convert_pixels_to_time(drawing->drawing_area->allocation.width, x, |
224446ce |
102 | time_window->start_time, |
103 | window_end, |
a56a1ba4 |
104 | &start); |
105 | |
501d5405 |
106 | convert_pixels_to_time(drawing->drawing_area->allocation.width, x + width, |
224446ce |
107 | time_window->start_time, |
108 | window_end, |
a56a1ba4 |
109 | &end); |
110 | |
111 | LttvTracesetContext * tsc = |
224446ce |
112 | lttvwindow_get_traceset_context(control_flow_data->mw); |
d52cfc84 |
113 | LttvTracesetState * tss = |
d0cd7f09 |
114 | (LttvTracesetState*)tsc; |
a56a1ba4 |
115 | |
a56a1ba4 |
116 | // Let's call processTrace() !! |
117 | EventRequest event_request; // Variable freed at the end of the function. |
68997a22 |
118 | event_request.control_flow_data = control_flow_data; |
a56a1ba4 |
119 | event_request.time_begin = start; |
120 | event_request.time_end = end; |
121 | event_request.x_begin = x; |
122 | event_request.x_end = x+width; |
123 | |
2a2fa4f0 |
124 | g_debug("req : start : %u, %u", event_request.time_begin.tv_sec, |
a56a1ba4 |
125 | event_request.time_begin.tv_nsec); |
126 | |
2a2fa4f0 |
127 | g_debug("req : end : %u, %u", event_request.time_end.tv_sec, |
a56a1ba4 |
128 | event_request.time_end.tv_nsec); |
129 | |
130 | LttvHooks *event = lttv_hooks_new(); |
131 | LttvHooks *after_event = lttv_hooks_new(); |
132 | LttvHooks *after_traceset = lttv_hooks_new(); |
133 | lttv_hooks_add(after_traceset, after_data_request, &event_request); |
134 | lttv_hooks_add(event, draw_event_hook, &event_request); |
135 | //Modified by xiangxiu: state update hooks are added by the main window |
b21c82b6 |
136 | //lttv_state_add_event_hooks(tsc); |
a56a1ba4 |
137 | lttv_hooks_add(after_event, draw_after_hook, &event_request); |
138 | |
d52cfc84 |
139 | //lttv_process_traceset_seek_time(tsc, start); |
140 | lttv_state_traceset_seek_time_closest(tss, start); |
a56a1ba4 |
141 | // FIXME : would like to place the after_traceset hook after the traceset, |
142 | // but the traceset context state is not valid anymore. |
143 | lttv_traceset_context_add_hooks(tsc, |
d0cd7f09 |
144 | NULL, after_traceset, NULL, NULL, NULL, NULL, |
145 | //NULL, NULL, NULL, NULL, NULL, NULL, |
146 | NULL, NULL, NULL, event, after_event); |
a56a1ba4 |
147 | lttv_process_traceset(tsc, end, G_MAXULONG); |
148 | //after_data_request((void*)&event_request,(void*)tsc); |
149 | lttv_traceset_context_remove_hooks(tsc, |
d0cd7f09 |
150 | NULL, after_traceset, NULL, NULL, NULL, NULL, |
151 | // NULL, NULL, NULL, NULL, NULL, NULL, |
152 | NULL, NULL, NULL, event, after_event); |
a56a1ba4 |
153 | //Modified by xiangxiu: state update hooks are removed by the main window |
b21c82b6 |
154 | //lttv_state_remove_event_hooks(tsc); |
a56a1ba4 |
155 | |
156 | lttv_hooks_destroy(after_traceset); |
157 | lttv_hooks_destroy(event); |
158 | lttv_hooks_destroy(after_event); |
159 | |
160 | |
847b479d |
161 | } |
a56a1ba4 |
162 | |
847b479d |
163 | /* Callbacks */ |
164 | |
165 | |
166 | /* Create a new backing pixmap of the appropriate size */ |
bd24a9af |
167 | /* As the scaling will always change, it's of no use to copy old |
168 | * pixmap. |
169 | */ |
847b479d |
170 | static gboolean |
171 | configure_event( GtkWidget *widget, GdkEventConfigure *event, |
a56a1ba4 |
172 | gpointer user_data) |
f0d936c0 |
173 | { |
501d5405 |
174 | Drawing_t *drawing = (Drawing_t*)user_data; |
f0d936c0 |
175 | |
86c520a7 |
176 | |
a56a1ba4 |
177 | /* First, get the new time interval of the main window */ |
178 | /* we assume (see documentation) that the main window |
179 | * has updated the time interval before this configure gets |
180 | * executed. |
181 | */ |
224446ce |
182 | //lttvwindow_get_time_window(drawing->control_flow_data->mw, |
183 | // &drawing->control_flow_data->time_window); |
a56a1ba4 |
184 | |
b6db18f8 |
185 | /* New pixmap, size of the configure event */ |
186 | //GdkPixmap *pixmap = gdk_pixmap_new(widget->window, |
a56a1ba4 |
187 | // widget->allocation.width + SAFETY, |
188 | // widget->allocation.height + SAFETY, |
189 | // -1); |
190 | |
2a2fa4f0 |
191 | g_debug("drawing configure event"); |
192 | g_debug("New draw size : %i by %i",widget->allocation.width, widget->allocation.height); |
a56a1ba4 |
193 | |
194 | |
501d5405 |
195 | if (drawing->pixmap) |
196 | gdk_pixmap_unref(drawing->pixmap); |
a56a1ba4 |
197 | |
b6db18f8 |
198 | /* If no old pixmap present */ |
501d5405 |
199 | //if(drawing->pixmap == NULL) |
847b479d |
200 | { |
501d5405 |
201 | drawing->pixmap = gdk_pixmap_new( |
a56a1ba4 |
202 | widget->window, |
203 | widget->allocation.width + SAFETY, |
204 | widget->allocation.height + SAFETY, |
205 | //ProcessList_get_height |
501d5405 |
206 | // (GuiControlFlow_get_process_list(drawing->control_flow_data)), |
a56a1ba4 |
207 | -1); |
501d5405 |
208 | drawing->width = widget->allocation.width; |
209 | drawing->height = widget->allocation.height; |
a56a1ba4 |
210 | |
211 | |
212 | // Clear the image |
501d5405 |
213 | gdk_draw_rectangle (drawing->pixmap, |
cfe526b1 |
214 | widget->style->black_gc, |
a56a1ba4 |
215 | TRUE, |
216 | 0, 0, |
217 | widget->allocation.width+SAFETY, |
218 | widget->allocation.height+SAFETY); |
219 | |
220 | //g_info("init data request"); |
221 | |
222 | |
223 | /* Initial data request */ |
224 | // Do not need to ask for data of 1 pixel : not synchronized with |
225 | // main window time at this moment. |
501d5405 |
226 | drawing_data_request(drawing, &drawing->pixmap, 0, 0, |
a56a1ba4 |
227 | widget->allocation.width, |
228 | widget->allocation.height); |
229 | |
501d5405 |
230 | drawing->width = widget->allocation.width; |
231 | drawing->height = widget->allocation.height; |
a56a1ba4 |
232 | |
233 | return TRUE; |
bd24a9af |
234 | |
235 | |
847b479d |
236 | |
237 | } |
bd24a9af |
238 | #ifdef NOTUSE |
847b479d |
239 | // /* Draw empty background */ |
b6db18f8 |
240 | // gdk_draw_rectangle (pixmap, |
a56a1ba4 |
241 | // widget->style->black_gc, |
242 | // TRUE, |
243 | // 0, 0, |
244 | // widget->allocation.width, |
245 | // widget->allocation.height); |
246 | |
247 | /* Copy old data to new pixmap */ |
b6db18f8 |
248 | gdk_draw_drawable (pixmap, |
cfe526b1 |
249 | widget->style->black_gc, |
501d5405 |
250 | drawing->pixmap, |
a56a1ba4 |
251 | 0, 0, |
252 | 0, 0, |
253 | -1, -1); |
254 | |
501d5405 |
255 | if (drawing->pixmap) |
256 | gdk_pixmap_unref(drawing->pixmap); |
80a52ff8 |
257 | |
501d5405 |
258 | drawing->pixmap = pixmap; |
a56a1ba4 |
259 | |
260 | // Clear the bottom part of the image (SAFETY) |
b6db18f8 |
261 | gdk_draw_rectangle (pixmap, |
cfe526b1 |
262 | widget->style->black_gc, |
a56a1ba4 |
263 | TRUE, |
501d5405 |
264 | 0, drawing->height+SAFETY, |
265 | drawing->width+SAFETY, // do not overlap |
266 | (widget->allocation.height) - drawing->height); |
bd24a9af |
267 | |
a56a1ba4 |
268 | // Clear the right part of the image (SAFETY) |
b6db18f8 |
269 | gdk_draw_rectangle (pixmap, |
cfe526b1 |
270 | widget->style->black_gc, |
a56a1ba4 |
271 | TRUE, |
501d5405 |
272 | drawing->width+SAFETY, 0, |
273 | (widget->allocation.width) - drawing->width, // do not overlap |
274 | drawing->height+SAFETY); |
a56a1ba4 |
275 | |
276 | /* Clear the backgound for data request, but not SAFETY */ |
b6db18f8 |
277 | gdk_draw_rectangle (pixmap, |
cfe526b1 |
278 | drawing->drawing_area->style->black_gc, |
a56a1ba4 |
279 | TRUE, |
501d5405 |
280 | drawing->width + SAFETY, 0, |
281 | widget->allocation.width - drawing->width, // do not overlap |
a56a1ba4 |
282 | widget->allocation.height+SAFETY); |
bd24a9af |
283 | |
432a7065 |
284 | /* Request data for missing space */ |
a56a1ba4 |
285 | g_info("missing data request"); |
501d5405 |
286 | drawing_data_request(drawing, &pixmap, drawing->width, 0, |
287 | widget->allocation.width - drawing->width, |
a56a1ba4 |
288 | widget->allocation.height); |
289 | |
501d5405 |
290 | drawing->width = widget->allocation.width; |
291 | drawing->height = widget->allocation.height; |
847b479d |
292 | |
293 | return TRUE; |
bd24a9af |
294 | #endif //NOTUSE |
847b479d |
295 | } |
296 | |
297 | |
298 | /* Redraw the screen from the backing pixmap */ |
299 | static gboolean |
300 | expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data ) |
301 | { |
501d5405 |
302 | Drawing_t *drawing = (Drawing_t*)user_data; |
224446ce |
303 | const TimeWindow *time_window = lttvwindow_get_time_window(drawing->control_flow_data->mw); |
304 | const LttTime* current_time = |
305 | lttvwindow_get_current_time(drawing->control_flow_data->mw); |
306 | |
a56a1ba4 |
307 | ControlFlowData *control_flow_data = |
308 | (ControlFlowData*)g_object_get_data( |
309 | G_OBJECT(widget), |
68997a22 |
310 | "control_flow_data"); |
8b90e648 |
311 | |
2a2fa4f0 |
312 | g_debug("drawing expose event"); |
a56a1ba4 |
313 | |
314 | guint x=0; |
a56a1ba4 |
315 | |
224446ce |
316 | LttTime window_end = ltt_time_add(time_window->time_width, |
317 | time_window->start_time); |
a56a1ba4 |
318 | |
319 | convert_time_to_pixels( |
224446ce |
320 | time_window->start_time, |
a56a1ba4 |
321 | window_end, |
ba90bc77 |
322 | *current_time, |
a56a1ba4 |
323 | widget->allocation.width, |
324 | &x); |
325 | |
847b479d |
326 | gdk_draw_pixmap(widget->window, |
a56a1ba4 |
327 | widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
501d5405 |
328 | drawing->pixmap, |
a56a1ba4 |
329 | event->area.x, event->area.y, |
330 | event->area.x, event->area.y, |
331 | event->area.width, event->area.height); |
332 | |
333 | if(x >= event->area.x && x <= event->area.x+event->area.width) |
334 | { |
853dbdb8 |
335 | gint8 dash_list[] = { 1, 2 }; |
501d5405 |
336 | GdkGC *gc = gdk_gc_new(control_flow_data->drawing->pixmap); |
0e492a24 |
337 | gdk_gc_copy(gc, widget->style->white_gc); |
338 | gdk_gc_set_line_attributes(gc, |
339 | 1, |
340 | GDK_LINE_ON_OFF_DASH, |
341 | GDK_CAP_BUTT, |
342 | GDK_JOIN_MITER); |
853dbdb8 |
343 | gdk_gc_set_dashes(gc, |
344 | 0, |
345 | dash_list, |
346 | 2); |
a56a1ba4 |
347 | drawing_draw_line(NULL, widget->window, |
348 | x, event->area.y, |
349 | x, event->area.y+event->area.height, |
350 | gc); |
351 | gdk_gc_unref(gc); |
352 | } |
847b479d |
353 | return FALSE; |
354 | } |
355 | |
8b90e648 |
356 | /* mouse click */ |
357 | static gboolean |
358 | button_press_event( GtkWidget *widget, GdkEventButton *event, gpointer user_data ) |
359 | { |
a56a1ba4 |
360 | ControlFlowData *control_flow_data = |
361 | (ControlFlowData*)g_object_get_data( |
362 | G_OBJECT(widget), |
68997a22 |
363 | "control_flow_data"); |
501d5405 |
364 | Drawing_t *drawing = control_flow_data->drawing; |
224446ce |
365 | const TimeWindow *time_window = lttvwindow_get_time_window(drawing->control_flow_data->mw); |
8b90e648 |
366 | |
2a2fa4f0 |
367 | g_debug("click"); |
a56a1ba4 |
368 | if(event->button == 1) |
369 | { |
370 | LttTime time; |
8b90e648 |
371 | |
224446ce |
372 | LttTime window_end = ltt_time_add(time_window->time_width, |
373 | time_window->start_time); |
8b90e648 |
374 | |
375 | |
a56a1ba4 |
376 | /* left mouse button click */ |
2a2fa4f0 |
377 | g_debug("x click is : %f", event->x); |
8b90e648 |
378 | |
a56a1ba4 |
379 | convert_pixels_to_time(widget->allocation.width, (guint)event->x, |
224446ce |
380 | time_window->start_time, |
381 | window_end, |
a56a1ba4 |
382 | &time); |
8b90e648 |
383 | |
224446ce |
384 | lttvwindow_report_current_time(control_flow_data->mw, &time); |
8b90e648 |
385 | |
a56a1ba4 |
386 | } |
ebf4f735 |
387 | |
224446ce |
388 | lttvwindow_report_focus(control_flow_data->mw, gtk_widget_get_parent(control_flow_data->scrolled_window)); |
a56a1ba4 |
389 | |
390 | return FALSE; |
8b90e648 |
391 | } |
392 | |
393 | |
394 | |
395 | |
68997a22 |
396 | Drawing_t *drawing_construct(ControlFlowData *control_flow_data) |
847b479d |
397 | { |
501d5405 |
398 | Drawing_t *drawing = g_new(Drawing_t, 1); |
3cb8b205 |
399 | |
501d5405 |
400 | drawing->control_flow_data = control_flow_data; |
a56a1ba4 |
401 | |
3cb8b205 |
402 | drawing->vbox = gtk_vbox_new(FALSE, 1); |
3cb8b205 |
403 | drawing->ruler = gtk_drawing_area_new (); |
404 | gtk_widget_set_size_request(drawing->ruler, -1, 27); |
3cb8b205 |
405 | |
406 | drawing->drawing_area = gtk_drawing_area_new (); |
407 | |
408 | gtk_box_pack_start(GTK_BOX(drawing->vbox), drawing->ruler, |
409 | FALSE, FALSE, 0); |
3cb8b205 |
410 | gtk_box_pack_end(GTK_BOX(drawing->vbox), drawing->drawing_area, |
411 | TRUE, TRUE, 0); |
3cb8b205 |
412 | |
501d5405 |
413 | drawing->pango_layout = |
414 | gtk_widget_create_pango_layout(drawing->drawing_area, NULL); |
a56a1ba4 |
415 | |
501d5405 |
416 | //gtk_widget_set_size_request(drawing->drawing_area->window, 50, 50); |
a56a1ba4 |
417 | g_object_set_data_full( |
501d5405 |
418 | G_OBJECT(drawing->drawing_area), |
419 | "Link_drawing_Data", |
420 | drawing, |
a56a1ba4 |
421 | (GDestroyNotify)drawing_destroy); |
422 | |
3cb8b205 |
423 | g_object_set_data( |
424 | G_OBJECT(drawing->ruler), |
425 | "drawing", |
426 | drawing); |
427 | |
428 | |
501d5405 |
429 | //gtk_widget_modify_bg( drawing->drawing_area, |
a56a1ba4 |
430 | // GTK_STATE_NORMAL, |
431 | // &CF_Colors[BLACK]); |
432 | |
501d5405 |
433 | //gdk_window_get_geometry(drawing->drawing_area->window, |
a56a1ba4 |
434 | // NULL, NULL, |
501d5405 |
435 | // &(drawing->width), |
436 | // &(drawing->height), |
a56a1ba4 |
437 | // -1); |
438 | |
501d5405 |
439 | //drawing->pixmap = gdk_pixmap_new( |
440 | // drawing->drawing_area->window, |
441 | // drawing->width, |
442 | // drawing->height, |
443 | // drawing->depth); |
a56a1ba4 |
444 | |
501d5405 |
445 | drawing->pixmap = NULL; |
a56a1ba4 |
446 | |
501d5405 |
447 | // drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window, |
448 | // drawing->drawing_area->allocation.width, |
449 | // drawing->drawing_area->allocation.height, |
a56a1ba4 |
450 | // -1); |
451 | |
501d5405 |
452 | gtk_widget_add_events(drawing->drawing_area, GDK_BUTTON_PRESS_MASK); |
a56a1ba4 |
453 | |
501d5405 |
454 | g_signal_connect (G_OBJECT(drawing->drawing_area), |
a56a1ba4 |
455 | "configure_event", |
456 | G_CALLBACK (configure_event), |
501d5405 |
457 | (gpointer)drawing); |
3cb8b205 |
458 | |
459 | g_signal_connect (G_OBJECT(drawing->ruler), |
460 | "expose_event", |
461 | G_CALLBACK(expose_ruler), |
462 | (gpointer)drawing); |
463 | |
d287af9a |
464 | gtk_widget_add_events(drawing->ruler, GDK_POINTER_MOTION_MASK); |
465 | |
466 | g_signal_connect (G_OBJECT(drawing->ruler), |
467 | "motion-notify-event", |
468 | G_CALLBACK(motion_notify_ruler), |
469 | (gpointer)drawing); |
470 | |
471 | |
501d5405 |
472 | g_signal_connect (G_OBJECT(drawing->drawing_area), |
a56a1ba4 |
473 | "expose_event", |
474 | G_CALLBACK (expose_event), |
501d5405 |
475 | (gpointer)drawing); |
a56a1ba4 |
476 | |
501d5405 |
477 | g_signal_connect (G_OBJECT(drawing->drawing_area), |
a56a1ba4 |
478 | "button-press-event", |
479 | G_CALLBACK (button_press_event), |
501d5405 |
480 | (gpointer)drawing); |
3cb8b205 |
481 | |
482 | gtk_widget_show(drawing->ruler); |
483 | gtk_widget_show(drawing->drawing_area); |
484 | |
a56a1ba4 |
485 | |
501d5405 |
486 | return drawing; |
f0d936c0 |
487 | } |
488 | |
501d5405 |
489 | void drawing_destroy(Drawing_t *drawing) |
f0d936c0 |
490 | { |
491 | |
a56a1ba4 |
492 | // Do not unref here, Drawing_t destroyed by it's widget. |
501d5405 |
493 | //g_object_unref( G_OBJECT(drawing->drawing_area)); |
a56a1ba4 |
494 | |
501d5405 |
495 | g_free(drawing->pango_layout); |
496 | g_free(drawing); |
f0d936c0 |
497 | } |
498 | |
3cb8b205 |
499 | GtkWidget *drawing_get_drawing_area(Drawing_t *drawing) |
76a67e8a |
500 | { |
501d5405 |
501 | return drawing->drawing_area; |
76a67e8a |
502 | } |
503 | |
3cb8b205 |
504 | GtkWidget *drawing_get_widget(Drawing_t *drawing) |
505 | { |
506 | return drawing->vbox; |
507 | } |
508 | |
f66eba62 |
509 | /* convert_pixels_to_time |
f0d936c0 |
510 | * |
f66eba62 |
511 | * Convert from window pixel and time interval to an absolute time. |
f0d936c0 |
512 | */ |
fa2c4dbe |
513 | void convert_pixels_to_time( |
a56a1ba4 |
514 | gint width, |
515 | guint x, |
224446ce |
516 | LttTime window_time_begin, |
517 | LttTime window_time_end, |
a56a1ba4 |
518 | LttTime *time) |
f0d936c0 |
519 | { |
a56a1ba4 |
520 | LttTime window_time_interval; |
521 | |
224446ce |
522 | window_time_interval = ltt_time_sub(window_time_end, |
523 | window_time_begin); |
a56a1ba4 |
524 | *time = ltt_time_mul(window_time_interval, (x/(float)width)); |
224446ce |
525 | *time = ltt_time_add(window_time_begin, *time); |
fa2c4dbe |
526 | } |
527 | |
528 | |
529 | |
530 | void convert_time_to_pixels( |
a56a1ba4 |
531 | LttTime window_time_begin, |
532 | LttTime window_time_end, |
533 | LttTime time, |
534 | int width, |
535 | guint *x) |
fa2c4dbe |
536 | { |
a56a1ba4 |
537 | LttTime window_time_interval; |
538 | float interval_float, time_float; |
539 | |
540 | window_time_interval = ltt_time_sub(window_time_end,window_time_begin); |
541 | |
542 | time = ltt_time_sub(time, window_time_begin); |
543 | |
544 | interval_float = ltt_time_to_double(window_time_interval); |
545 | time_float = ltt_time_to_double(time); |
546 | |
547 | *x = (guint)(time_float/interval_float * width); |
548 | |
f0d936c0 |
549 | } |
550 | |
501d5405 |
551 | void drawing_refresh ( Drawing_t *drawing, |
a56a1ba4 |
552 | guint x, guint y, |
553 | guint width, guint height) |
847b479d |
554 | { |
a56a1ba4 |
555 | g_info("Drawing.c : drawing_refresh %u, %u, %u, %u", x, y, width, height); |
556 | GdkRectangle update_rect; |
557 | |
558 | gdk_draw_drawable( |
501d5405 |
559 | drawing->drawing_area->window, |
560 | drawing->drawing_area-> |
561 | style->fg_gc[GTK_WIDGET_STATE (drawing->drawing_area)], |
562 | GDK_DRAWABLE(drawing->pixmap), |
a56a1ba4 |
563 | x, y, |
564 | x, y, |
565 | width, height); |
566 | |
567 | update_rect.x = 0 ; |
568 | update_rect.y = 0 ; |
501d5405 |
569 | update_rect.width = drawing->width; |
570 | update_rect.height = drawing->height ; |
571 | gtk_widget_draw( drawing->drawing_area, &update_rect); |
f7afe191 |
572 | |
847b479d |
573 | } |
574 | |
575 | |
501d5405 |
576 | void drawing_draw_line( Drawing_t *drawing, |
b6db18f8 |
577 | GdkPixmap *pixmap, |
a56a1ba4 |
578 | guint x1, guint y1, |
579 | guint x2, guint y2, |
580 | GdkGC *GC) |
847b479d |
581 | { |
b6db18f8 |
582 | gdk_draw_line (pixmap, |
a56a1ba4 |
583 | GC, |
584 | x1, y1, x2, y2); |
847b479d |
585 | } |
586 | |
587 | |
fa2c4dbe |
588 | |
589 | |
501d5405 |
590 | void drawing_resize(Drawing_t *drawing, guint h, guint w) |
f0d936c0 |
591 | { |
501d5405 |
592 | drawing->height = h ; |
593 | drawing->width = w ; |
a56a1ba4 |
594 | |
501d5405 |
595 | gtk_widget_set_size_request ( drawing->drawing_area, |
596 | drawing->width, |
597 | drawing->height); |
a56a1ba4 |
598 | |
599 | |
f0d936c0 |
600 | } |
847b479d |
601 | |
602 | |
5f16133f |
603 | /* Insert a square corresponding to a new process in the list */ |
501d5405 |
604 | /* Applies to whole drawing->width */ |
605 | void drawing_insert_square(Drawing_t *drawing, |
a56a1ba4 |
606 | guint y, |
607 | guint height) |
5f16133f |
608 | { |
a56a1ba4 |
609 | //GdkRectangle update_rect; |
5f16133f |
610 | |
a56a1ba4 |
611 | /* Allocate a new pixmap with new height */ |
501d5405 |
612 | GdkPixmap *pixmap = gdk_pixmap_new(drawing->drawing_area->window, |
613 | drawing->width + SAFETY, |
614 | drawing->height + height + SAFETY, |
a56a1ba4 |
615 | -1); |
616 | |
617 | /* Copy the high region */ |
b6db18f8 |
618 | gdk_draw_drawable (pixmap, |
501d5405 |
619 | drawing->drawing_area->style->black_gc, |
620 | drawing->pixmap, |
a56a1ba4 |
621 | 0, 0, |
622 | 0, 0, |
501d5405 |
623 | drawing->width + SAFETY, y); |
5f16133f |
624 | |
625 | |
626 | |
5f16133f |
627 | |
a56a1ba4 |
628 | /* add an empty square */ |
b6db18f8 |
629 | gdk_draw_rectangle (pixmap, |
cfe526b1 |
630 | drawing->drawing_area->style->black_gc, |
a56a1ba4 |
631 | TRUE, |
632 | 0, y, |
501d5405 |
633 | drawing->width + SAFETY, // do not overlap |
a56a1ba4 |
634 | height); |
5f16133f |
635 | |
636 | |
5f16133f |
637 | |
a56a1ba4 |
638 | /* copy the bottom of the region */ |
b6db18f8 |
639 | gdk_draw_drawable (pixmap, |
501d5405 |
640 | drawing->drawing_area->style->black_gc, |
641 | drawing->pixmap, |
a56a1ba4 |
642 | 0, y, |
643 | 0, y + height, |
501d5405 |
644 | drawing->width+SAFETY, drawing->height - y + SAFETY); |
5f16133f |
645 | |
646 | |
647 | |
5f16133f |
648 | |
501d5405 |
649 | if (drawing->pixmap) |
650 | gdk_pixmap_unref(drawing->pixmap); |
5f16133f |
651 | |
501d5405 |
652 | drawing->pixmap = pixmap; |
a56a1ba4 |
653 | |
501d5405 |
654 | drawing->height+=height; |
a56a1ba4 |
655 | |
501d5405 |
656 | /* Rectangle to update, from new drawing dimensions */ |
a56a1ba4 |
657 | //update_rect.x = 0 ; |
658 | //update_rect.y = y ; |
501d5405 |
659 | //update_rect.width = drawing->width; |
660 | //update_rect.height = drawing->height - y ; |
661 | //gtk_widget_draw( drawing->drawing_area, &update_rect); |
5f16133f |
662 | } |
663 | |
664 | |
665 | /* Remove a square corresponding to a removed process in the list */ |
501d5405 |
666 | void drawing_remove_square(Drawing_t *drawing, |
a56a1ba4 |
667 | guint y, |
668 | guint height) |
5f16133f |
669 | { |
a56a1ba4 |
670 | //GdkRectangle update_rect; |
671 | |
672 | /* Allocate a new pixmap with new height */ |
b6db18f8 |
673 | GdkPixmap *pixmap = gdk_pixmap_new( |
501d5405 |
674 | drawing->drawing_area->window, |
675 | drawing->width + SAFETY, |
676 | drawing->height - height + SAFETY, |
a56a1ba4 |
677 | -1); |
678 | |
679 | /* Copy the high region */ |
b6db18f8 |
680 | gdk_draw_drawable (pixmap, |
501d5405 |
681 | drawing->drawing_area->style->black_gc, |
682 | drawing->pixmap, |
a56a1ba4 |
683 | 0, 0, |
684 | 0, 0, |
501d5405 |
685 | drawing->width + SAFETY, y); |
a56a1ba4 |
686 | |
687 | |
688 | |
689 | /* Copy up the bottom of the region */ |
b6db18f8 |
690 | gdk_draw_drawable (pixmap, |
501d5405 |
691 | drawing->drawing_area->style->black_gc, |
692 | drawing->pixmap, |
a56a1ba4 |
693 | 0, y + height, |
694 | 0, y, |
501d5405 |
695 | drawing->width, drawing->height - y - height + SAFETY); |
a56a1ba4 |
696 | |
697 | |
501d5405 |
698 | if (drawing->pixmap) |
699 | gdk_pixmap_unref(drawing->pixmap); |
a56a1ba4 |
700 | |
501d5405 |
701 | drawing->pixmap = pixmap; |
a56a1ba4 |
702 | |
501d5405 |
703 | drawing->height-=height; |
a56a1ba4 |
704 | |
501d5405 |
705 | /* Rectangle to update, from new drawing dimensions */ |
a56a1ba4 |
706 | //update_rect.x = 0 ; |
707 | //update_rect.y = y ; |
501d5405 |
708 | //update_rect.width = drawing->width; |
709 | //update_rect.height = drawing->height - y ; |
710 | //gtk_widget_draw( drawing->drawing_area, &update_rect); |
5f16133f |
711 | } |
189a5d08 |
712 | |
3cb8b205 |
713 | void drawing_update_ruler(Drawing_t *drawing, TimeWindow *time_window) |
714 | { |
715 | GtkRequisition req; |
716 | GdkRectangle rect; |
717 | |
718 | req.width = drawing->ruler->allocation.width; |
719 | req.height = drawing->ruler->allocation.height; |
720 | |
721 | |
722 | rect.x = 0; |
723 | rect.y = 0; |
724 | rect.width = req.width; |
725 | rect.height = req.height; |
726 | |
727 | gtk_widget_queue_draw(drawing->ruler); |
728 | //gtk_widget_draw( drawing->ruler, &rect); |
729 | } |
730 | |
731 | /* Redraw the ruler */ |
732 | static gboolean |
733 | expose_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data ) |
734 | { |
735 | Drawing_t *drawing = (Drawing_t*)user_data; |
224446ce |
736 | const TimeWindow *time_window = lttvwindow_get_time_window(drawing->control_flow_data->mw); |
3cb8b205 |
737 | gchar text[255]; |
738 | |
739 | PangoContext *context; |
740 | PangoLayout *layout; |
741 | PangoAttribute *attribute; |
742 | PangoFontDescription *FontDesc; |
743 | gint Font_Size; |
744 | PangoRectangle ink_rect; |
745 | guint global_width=0; |
746 | GdkColor foreground = { 0, 0, 0, 0 }; |
747 | GdkColor background = { 0, 0xffff, 0xffff, 0xffff }; |
748 | |
749 | LttTime window_end = |
224446ce |
750 | ltt_time_add(time_window->time_width, |
751 | time_window->start_time); |
3cb8b205 |
752 | LttTime half_width = |
224446ce |
753 | ltt_time_div(time_window->time_width,2.0); |
3cb8b205 |
754 | LttTime window_middle = |
755 | ltt_time_add(half_width, |
224446ce |
756 | time_window->start_time); |
2a2fa4f0 |
757 | g_debug("ruler expose event"); |
3cb8b205 |
758 | |
759 | gdk_draw_rectangle (drawing->ruler->window, |
760 | drawing->ruler->style->white_gc, |
761 | TRUE, |
762 | event->area.x, event->area.y, |
763 | event->area.width, |
764 | event->area.height); |
765 | |
766 | GdkGC *gc = gdk_gc_new(drawing->ruler->window); |
767 | gdk_gc_copy(gc, drawing->ruler->style->black_gc); |
768 | gdk_gc_set_line_attributes(gc, |
769 | 2, |
770 | GDK_LINE_SOLID, |
771 | GDK_CAP_BUTT, |
772 | GDK_JOIN_MITER); |
773 | gdk_draw_line (drawing->ruler->window, |
774 | gc, |
775 | event->area.x, 1, |
776 | event->area.x + event->area.width, 1); |
777 | |
778 | |
779 | snprintf(text, 255, "%lus\n%luns", |
224446ce |
780 | time_window->start_time.tv_sec, |
781 | time_window->start_time.tv_nsec); |
3cb8b205 |
782 | |
783 | layout = gtk_widget_create_pango_layout(drawing->drawing_area, NULL); |
784 | |
785 | context = pango_layout_get_context(layout); |
786 | FontDesc = pango_context_get_font_description(context); |
787 | |
788 | pango_font_description_set_size(FontDesc, 6*PANGO_SCALE); |
789 | pango_layout_context_changed(layout); |
790 | |
791 | pango_layout_set_text(layout, text, -1); |
792 | pango_layout_get_pixel_extents(layout, &ink_rect, NULL); |
793 | global_width += ink_rect.width; |
794 | |
795 | gdk_draw_layout_with_colors(drawing->ruler->window, |
796 | gc, |
797 | 0, |
798 | 6, |
799 | layout, &foreground, &background); |
800 | |
801 | gdk_gc_set_line_attributes(gc, |
802 | 2, |
803 | GDK_LINE_SOLID, |
804 | GDK_CAP_ROUND, |
805 | GDK_JOIN_ROUND); |
806 | |
807 | gdk_draw_line (drawing->ruler->window, |
808 | gc, |
809 | 1, 1, |
810 | 1, 7); |
811 | |
812 | |
813 | snprintf(text, 255, "%lus\n%luns", window_end.tv_sec, |
814 | window_end.tv_nsec); |
815 | |
816 | pango_layout_set_text(layout, text, -1); |
817 | pango_layout_get_pixel_extents(layout, &ink_rect, NULL); |
818 | global_width += ink_rect.width; |
819 | |
820 | if(global_width <= drawing->ruler->allocation.width) |
821 | { |
822 | gdk_draw_layout_with_colors(drawing->ruler->window, |
823 | gc, |
824 | drawing->ruler->allocation.width - ink_rect.width, |
825 | 6, |
826 | layout, &foreground, &background); |
827 | |
828 | gdk_gc_set_line_attributes(gc, |
829 | 2, |
830 | GDK_LINE_SOLID, |
831 | GDK_CAP_ROUND, |
832 | GDK_JOIN_ROUND); |
833 | |
834 | gdk_draw_line (drawing->ruler->window, |
835 | gc, |
836 | drawing->ruler->allocation.width-1, 1, |
837 | drawing->ruler->allocation.width-1, 7); |
838 | } |
839 | |
840 | |
841 | snprintf(text, 255, "%lus\n%luns", window_middle.tv_sec, |
842 | window_middle.tv_nsec); |
843 | |
844 | pango_layout_set_text(layout, text, -1); |
845 | pango_layout_get_pixel_extents(layout, &ink_rect, NULL); |
846 | global_width += ink_rect.width; |
847 | |
848 | if(global_width <= drawing->ruler->allocation.width) |
849 | { |
850 | gdk_draw_layout_with_colors(drawing->ruler->window, |
851 | gc, |
852 | (drawing->ruler->allocation.width - ink_rect.width)/2, |
853 | 6, |
854 | layout, &foreground, &background); |
855 | |
856 | gdk_gc_set_line_attributes(gc, |
857 | 2, |
858 | GDK_LINE_SOLID, |
859 | GDK_CAP_ROUND, |
860 | GDK_JOIN_ROUND); |
861 | |
862 | gdk_draw_line (drawing->ruler->window, |
863 | gc, |
864 | drawing->ruler->allocation.width/2, 1, |
865 | drawing->ruler->allocation.width/2, 7); |
866 | |
867 | |
868 | |
869 | |
870 | } |
871 | |
872 | gdk_gc_unref(gc); |
873 | g_object_unref(layout); |
874 | |
875 | return FALSE; |
876 | } |
877 | |
189a5d08 |
878 | |
d287af9a |
879 | /* notify mouse on ruler */ |
880 | static gboolean |
881 | motion_notify_ruler(GtkWidget *widget, GdkEventMotion *event, gpointer user_data) |
882 | { |
2a2fa4f0 |
883 | //g_debug("motion"); |
d287af9a |
884 | //eventually follow mouse and show time here |
885 | } |