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