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