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