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