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