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