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