continue, redraw, stop, ok
[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;
221 drawing->damage_end = drawing->width;
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.
237 */
847b479d 238static gboolean
239configure_event( GtkWidget *widget, GdkEventConfigure *event,
a56a1ba4 240 gpointer user_data)
f0d936c0 241{
501d5405 242 Drawing_t *drawing = (Drawing_t*)user_data;
f0d936c0 243
86c520a7 244
a56a1ba4 245 /* First, get the new time interval of the main window */
246 /* we assume (see documentation) that the main window
247 * has updated the time interval before this configure gets
248 * executed.
249 */
224446ce 250 //lttvwindow_get_time_window(drawing->control_flow_data->mw,
251 // &drawing->control_flow_data->time_window);
a56a1ba4 252
b6db18f8 253 /* New pixmap, size of the configure event */
254 //GdkPixmap *pixmap = gdk_pixmap_new(widget->window,
a56a1ba4 255 // widget->allocation.width + SAFETY,
256 // widget->allocation.height + SAFETY,
257 // -1);
258
2a2fa4f0 259 g_debug("drawing configure event");
ca0f8a8e 260 g_debug("New draw size : %i by %i",widget->allocation.width,
261 widget->allocation.height);
a56a1ba4 262
263
501d5405 264 if (drawing->pixmap)
265 gdk_pixmap_unref(drawing->pixmap);
a56a1ba4 266
b6db18f8 267 /* If no old pixmap present */
501d5405 268 //if(drawing->pixmap == NULL)
847b479d 269 {
501d5405 270 drawing->pixmap = gdk_pixmap_new(
a56a1ba4 271 widget->window,
272 widget->allocation.width + SAFETY,
273 widget->allocation.height + SAFETY,
274 //ProcessList_get_height
501d5405 275 // (GuiControlFlow_get_process_list(drawing->control_flow_data)),
a56a1ba4 276 -1);
501d5405 277 drawing->width = widget->allocation.width;
278 drawing->height = widget->allocation.height;
a56a1ba4 279
280
281 // Clear the image
501d5405 282 gdk_draw_rectangle (drawing->pixmap,
cfe526b1 283 widget->style->black_gc,
a56a1ba4 284 TRUE,
285 0, 0,
286 widget->allocation.width+SAFETY,
287 widget->allocation.height+SAFETY);
288
289 //g_info("init data request");
290
291
292 /* Initial data request */
a43d67ba 293 /* no, do initial data request in the expose event */
a56a1ba4 294 // Do not need to ask for data of 1 pixel : not synchronized with
295 // main window time at this moment.
a43d67ba 296 //drawing_data_request(drawing, &drawing->pixmap, 0, 0,
297 // widget->allocation.width,
298 // widget->allocation.height);
a56a1ba4 299
501d5405 300 drawing->width = widget->allocation.width;
301 drawing->height = widget->allocation.height;
a43d67ba 302
ca0f8a8e 303 drawing->damage_begin = 0;
304 drawing->damage_end = widget->allocation.width;
305
306 if(drawing->damage_begin < drawing->damage_end)
307 {
308 drawing_data_request(drawing,
309 &drawing->pixmap,
310 drawing->damage_begin,
311 0,
312 drawing->damage_end,
313 widget->allocation.height);
314 }
315
a56a1ba4 316 return TRUE;
847b479d 317 }
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 */
fa2c4dbe 571void convert_pixels_to_time(
a56a1ba4 572 gint width,
573 guint x,
224446ce 574 LttTime window_time_begin,
575 LttTime window_time_end,
a56a1ba4 576 LttTime *time)
f0d936c0 577{
a56a1ba4 578 LttTime window_time_interval;
579
224446ce 580 window_time_interval = ltt_time_sub(window_time_end,
581 window_time_begin);
a56a1ba4 582 *time = ltt_time_mul(window_time_interval, (x/(float)width));
224446ce 583 *time = ltt_time_add(window_time_begin, *time);
fa2c4dbe 584}
585
586
587
588void convert_time_to_pixels(
a56a1ba4 589 LttTime window_time_begin,
590 LttTime window_time_end,
591 LttTime time,
592 int width,
593 guint *x)
fa2c4dbe 594{
a56a1ba4 595 LttTime window_time_interval;
596 float interval_float, time_float;
597
598 window_time_interval = ltt_time_sub(window_time_end,window_time_begin);
599
600 time = ltt_time_sub(time, window_time_begin);
601
602 interval_float = ltt_time_to_double(window_time_interval);
603 time_float = ltt_time_to_double(time);
604
605 *x = (guint)(time_float/interval_float * width);
606
f0d936c0 607}
608
501d5405 609void drawing_draw_line( Drawing_t *drawing,
b6db18f8 610 GdkPixmap *pixmap,
a56a1ba4 611 guint x1, guint y1,
612 guint x2, guint y2,
613 GdkGC *GC)
847b479d 614{
b6db18f8 615 gdk_draw_line (pixmap,
a56a1ba4 616 GC,
617 x1, y1, x2, y2);
847b479d 618}
619
620
fa2c4dbe 621
622
501d5405 623void drawing_resize(Drawing_t *drawing, guint h, guint w)
f0d936c0 624{
501d5405 625 drawing->height = h ;
626 drawing->width = w ;
a56a1ba4 627
501d5405 628 gtk_widget_set_size_request ( drawing->drawing_area,
629 drawing->width,
630 drawing->height);
a56a1ba4 631
632
f0d936c0 633}
847b479d 634
635
5f16133f 636/* Insert a square corresponding to a new process in the list */
501d5405 637/* Applies to whole drawing->width */
638void drawing_insert_square(Drawing_t *drawing,
a56a1ba4 639 guint y,
640 guint height)
5f16133f 641{
a56a1ba4 642 //GdkRectangle update_rect;
5f16133f 643
a56a1ba4 644 /* Allocate a new pixmap with new height */
501d5405 645 GdkPixmap *pixmap = gdk_pixmap_new(drawing->drawing_area->window,
646 drawing->width + SAFETY,
647 drawing->height + height + SAFETY,
a56a1ba4 648 -1);
649
650 /* Copy the high region */
b6db18f8 651 gdk_draw_drawable (pixmap,
501d5405 652 drawing->drawing_area->style->black_gc,
653 drawing->pixmap,
a56a1ba4 654 0, 0,
655 0, 0,
501d5405 656 drawing->width + SAFETY, y);
5f16133f 657
658
659
5f16133f 660
a56a1ba4 661 /* add an empty square */
b6db18f8 662 gdk_draw_rectangle (pixmap,
cfe526b1 663 drawing->drawing_area->style->black_gc,
a56a1ba4 664 TRUE,
665 0, y,
501d5405 666 drawing->width + SAFETY, // do not overlap
a56a1ba4 667 height);
5f16133f 668
669
5f16133f 670
a56a1ba4 671 /* copy the bottom of the region */
b6db18f8 672 gdk_draw_drawable (pixmap,
501d5405 673 drawing->drawing_area->style->black_gc,
674 drawing->pixmap,
a56a1ba4 675 0, y,
676 0, y + height,
501d5405 677 drawing->width+SAFETY, drawing->height - y + SAFETY);
5f16133f 678
679
680
5f16133f 681
501d5405 682 if (drawing->pixmap)
683 gdk_pixmap_unref(drawing->pixmap);
5f16133f 684
501d5405 685 drawing->pixmap = pixmap;
a56a1ba4 686
501d5405 687 drawing->height+=height;
a56a1ba4 688
501d5405 689 /* Rectangle to update, from new drawing dimensions */
a56a1ba4 690 //update_rect.x = 0 ;
691 //update_rect.y = y ;
501d5405 692 //update_rect.width = drawing->width;
693 //update_rect.height = drawing->height - y ;
694 //gtk_widget_draw( drawing->drawing_area, &update_rect);
5f16133f 695}
696
697
698/* Remove a square corresponding to a removed process in the list */
501d5405 699void drawing_remove_square(Drawing_t *drawing,
a56a1ba4 700 guint y,
701 guint height)
5f16133f 702{
a56a1ba4 703 //GdkRectangle update_rect;
704
705 /* Allocate a new pixmap with new height */
b6db18f8 706 GdkPixmap *pixmap = gdk_pixmap_new(
501d5405 707 drawing->drawing_area->window,
708 drawing->width + SAFETY,
709 drawing->height - height + SAFETY,
a56a1ba4 710 -1);
711
712 /* Copy the high region */
b6db18f8 713 gdk_draw_drawable (pixmap,
501d5405 714 drawing->drawing_area->style->black_gc,
715 drawing->pixmap,
a56a1ba4 716 0, 0,
717 0, 0,
501d5405 718 drawing->width + SAFETY, y);
a56a1ba4 719
720
721
722 /* Copy up the bottom of the region */
b6db18f8 723 gdk_draw_drawable (pixmap,
501d5405 724 drawing->drawing_area->style->black_gc,
725 drawing->pixmap,
a56a1ba4 726 0, y + height,
727 0, y,
501d5405 728 drawing->width, drawing->height - y - height + SAFETY);
a56a1ba4 729
730
501d5405 731 if (drawing->pixmap)
732 gdk_pixmap_unref(drawing->pixmap);
a56a1ba4 733
501d5405 734 drawing->pixmap = pixmap;
a56a1ba4 735
501d5405 736 drawing->height-=height;
a56a1ba4 737
501d5405 738 /* Rectangle to update, from new drawing dimensions */
a56a1ba4 739 //update_rect.x = 0 ;
740 //update_rect.y = y ;
501d5405 741 //update_rect.width = drawing->width;
742 //update_rect.height = drawing->height - y ;
743 //gtk_widget_draw( drawing->drawing_area, &update_rect);
5f16133f 744}
189a5d08 745
3cb8b205 746void drawing_update_ruler(Drawing_t *drawing, TimeWindow *time_window)
747{
748 GtkRequisition req;
749 GdkRectangle rect;
750
751 req.width = drawing->ruler->allocation.width;
752 req.height = drawing->ruler->allocation.height;
753
754
755 rect.x = 0;
756 rect.y = 0;
757 rect.width = req.width;
758 rect.height = req.height;
759
760 gtk_widget_queue_draw(drawing->ruler);
761 //gtk_widget_draw( drawing->ruler, &rect);
762}
763
764/* Redraw the ruler */
765static gboolean
766expose_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
767{
768 Drawing_t *drawing = (Drawing_t*)user_data;
ca0f8a8e 769 TimeWindow time_window = lttvwindow_get_time_window(drawing->control_flow_data->tab);
3cb8b205 770 gchar text[255];
771
772 PangoContext *context;
773 PangoLayout *layout;
774 PangoAttribute *attribute;
775 PangoFontDescription *FontDesc;
776 gint Font_Size;
777 PangoRectangle ink_rect;
778 guint global_width=0;
779 GdkColor foreground = { 0, 0, 0, 0 };
780 GdkColor background = { 0, 0xffff, 0xffff, 0xffff };
781
782 LttTime window_end =
ca0f8a8e 783 ltt_time_add(time_window.time_width,
784 time_window.start_time);
3cb8b205 785 LttTime half_width =
ca0f8a8e 786 ltt_time_div(time_window.time_width,2.0);
3cb8b205 787 LttTime window_middle =
788 ltt_time_add(half_width,
ca0f8a8e 789 time_window.start_time);
2a2fa4f0 790 g_debug("ruler expose event");
3cb8b205 791
792 gdk_draw_rectangle (drawing->ruler->window,
793 drawing->ruler->style->white_gc,
794 TRUE,
795 event->area.x, event->area.y,
796 event->area.width,
797 event->area.height);
798
799 GdkGC *gc = gdk_gc_new(drawing->ruler->window);
800 gdk_gc_copy(gc, drawing->ruler->style->black_gc);
801 gdk_gc_set_line_attributes(gc,
802 2,
803 GDK_LINE_SOLID,
804 GDK_CAP_BUTT,
805 GDK_JOIN_MITER);
806 gdk_draw_line (drawing->ruler->window,
807 gc,
808 event->area.x, 1,
809 event->area.x + event->area.width, 1);
810
811
812 snprintf(text, 255, "%lus\n%luns",
ca0f8a8e 813 time_window.start_time.tv_sec,
814 time_window.start_time.tv_nsec);
3cb8b205 815
816 layout = gtk_widget_create_pango_layout(drawing->drawing_area, NULL);
817
818 context = pango_layout_get_context(layout);
819 FontDesc = pango_context_get_font_description(context);
820
821 pango_font_description_set_size(FontDesc, 6*PANGO_SCALE);
822 pango_layout_context_changed(layout);
823
824 pango_layout_set_text(layout, text, -1);
825 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
826 global_width += ink_rect.width;
827
828 gdk_draw_layout_with_colors(drawing->ruler->window,
829 gc,
830 0,
831 6,
832 layout, &foreground, &background);
833
834 gdk_gc_set_line_attributes(gc,
835 2,
836 GDK_LINE_SOLID,
837 GDK_CAP_ROUND,
838 GDK_JOIN_ROUND);
839
840 gdk_draw_line (drawing->ruler->window,
841 gc,
842 1, 1,
843 1, 7);
844
845
846 snprintf(text, 255, "%lus\n%luns", window_end.tv_sec,
847 window_end.tv_nsec);
848
849 pango_layout_set_text(layout, text, -1);
850 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
851 global_width += ink_rect.width;
852
853 if(global_width <= drawing->ruler->allocation.width)
854 {
855 gdk_draw_layout_with_colors(drawing->ruler->window,
856 gc,
857 drawing->ruler->allocation.width - ink_rect.width,
858 6,
859 layout, &foreground, &background);
860
861 gdk_gc_set_line_attributes(gc,
862 2,
863 GDK_LINE_SOLID,
864 GDK_CAP_ROUND,
865 GDK_JOIN_ROUND);
866
867 gdk_draw_line (drawing->ruler->window,
868 gc,
869 drawing->ruler->allocation.width-1, 1,
870 drawing->ruler->allocation.width-1, 7);
871 }
872
873
874 snprintf(text, 255, "%lus\n%luns", window_middle.tv_sec,
875 window_middle.tv_nsec);
876
877 pango_layout_set_text(layout, text, -1);
878 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
879 global_width += ink_rect.width;
880
881 if(global_width <= drawing->ruler->allocation.width)
882 {
883 gdk_draw_layout_with_colors(drawing->ruler->window,
884 gc,
885 (drawing->ruler->allocation.width - ink_rect.width)/2,
886 6,
887 layout, &foreground, &background);
888
889 gdk_gc_set_line_attributes(gc,
890 2,
891 GDK_LINE_SOLID,
892 GDK_CAP_ROUND,
893 GDK_JOIN_ROUND);
894
895 gdk_draw_line (drawing->ruler->window,
896 gc,
897 drawing->ruler->allocation.width/2, 1,
898 drawing->ruler->allocation.width/2, 7);
899
900
901
902
903 }
904
905 gdk_gc_unref(gc);
906 g_object_unref(layout);
907
908 return FALSE;
909}
910
189a5d08 911
d287af9a 912/* notify mouse on ruler */
913static gboolean
914motion_notify_ruler(GtkWidget *widget, GdkEventMotion *event, gpointer user_data)
915{
2a2fa4f0 916 //g_debug("motion");
d287af9a 917 //eventually follow mouse and show time here
918}
This page took 0.073232 seconds and 4 git commands to generate.