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