Port histogram window to 2.x
[lttv.git] / lttv / modules / gui / histogram / histodrawing.c
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2006 Parisa heidari (inspired from CFV by 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 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22
23 #include <gtk/gtk.h>
24 #include <gdk/gdk.h>
25 #include <string.h>
26
27 #include <ltt/trace.h>
28
29 #include <lttv/lttv.h>
30 #include <lttvwindow/lttvwindow.h>
31 #include <lttv/state.h>
32 #include <lttv/hook.h>
33
34 #include "histodrawing.h"
35 #include "histoeventhooks.h"
36 #include "histocfv.h"
37
38 #ifndef g_info
39 #define g_info(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, format)
40 #endif
41 #ifndef g_debug
42 #define g_debug(format...) g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format)
43 #endif
44
45 //FIXME
46 // fixed #define TRACE_NUMBER 0
47 #define EXTRA_ALLOC 1024 // pixels
48 #define padding_width 50
49
50 #if 0 /* colors for two lines representation */
51 GdkColor histo_drawing_colors[NUM_COLORS] =
52 { /* Pixel, R, G, B */
53 { 0, 0, 0, 0 }, /* COL_BLACK */
54 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_WHITE */
55 { 0, 0x0FFF, 0xFFFF, 0xFFFF }, /* COL_WAIT_FORK : pale blue */
56 { 0, 0xFFFF, 0xFFFF, 0x0000 }, /* COL_WAIT_CPU : yellow */
57 { 0, 0xFFFF, 0xA000, 0xFCFF }, /* COL_EXIT : pale magenta */
58 { 0, 0xFFFF, 0x0000, 0xFFFF }, /* COL_ZOMBIE : purple */
59 { 0, 0xFFFF, 0x0000, 0x0000 }, /* COL_WAIT : red */
60 { 0, 0x0000, 0xFFFF, 0x0000 }, /* COL_RUN : green */
61 { 0, 0x8800, 0xFFFF, 0x8A00 }, /* COL_USER_MODE : pale green */
62 { 0, 0x09FF, 0x01FF, 0xFFFF }, /* COL_SYSCALL : blue */
63 { 0, 0xF900, 0x4200, 0xFF00 }, /* COL_TRAP : pale purple */
64 { 0, 0xFFFF, 0x5AFF, 0x01FF }, /* COL_IRQ : orange */
65 { 0, 0xFFFF, 0xFFFF, 0xFFFF } /* COL_MODE_UNKNOWN : white */
66
67 };
68 #endif //0
69
70
71 GdkColor histo_drawing_colors[NUM_COLORS] =
72 { /* Pixel, R, G, B */
73 { 0, 0, 0, 0 }, /* COL_BLACK */
74 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_WHITE */
75 { 0, 0x0000, 0xFF00, 0x0000 }, /* COL_RUN_USER_MODE : green */
76 { 0, 0x0100, 0x9E00, 0xFFFF }, /* COL_RUN_SYSCALL : pale blue */
77 { 0, 0xFF00, 0xFF00, 0x0100 }, /* COL_RUN_TRAP : yellow */
78 { 0, 0xFFFF, 0x5E00, 0x0000 }, /* COL_RUN_IRQ : red */
79 { 0, 0x6600, 0x0000, 0x0000 }, /* COL_WAIT : dark red */
80 { 0, 0x7700, 0x7700, 0x0000 }, /* COL_WAIT_CPU : dark yellow */
81 { 0, 0x6400, 0x0000, 0x5D00 }, /* COL_ZOMBIE : dark purple */
82 { 0, 0x0700, 0x6400, 0x0000 }, /* COL_WAIT_FORK : dark green */
83 { 0, 0x8900, 0x0000, 0x8400 }, /* COL_EXIT : "less dark" magenta */
84 { 0, 0xFFFF, 0xFFFF, 0xFFFF }, /* COL_MODE_UNKNOWN : white */
85 { 0, 0xFFFF, 0xFFFF, 0xFFFF } /* COL_UNNAMED : white */
86
87 };
88
89 /*
90 RUN+USER MODE green
91 RUN+SYSCALL
92 RUN+TRAP
93 RUN+IRQ
94 WAIT+foncé
95 WAIT CPU + WAIT FORK vert foncé ou jaune
96 IRQ rouge
97 TRAP: orange
98 SYSCALL: bleu pâle
99
100 ZOMBIE + WAIT EXIT
101 */
102
103
104 /*****************************************************************************
105 * drawing functions *
106 *****************************************************************************/
107
108 static gboolean
109 histo_expose_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data );
110
111 static gboolean
112 histo_expose_vertical_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data );
113
114 static gboolean
115 histo_motion_notify_ruler(GtkWidget *widget, GdkEventMotion *event, gpointer user_data);
116
117 static gboolean
118 histo_motion_notify_vertical_ruler(GtkWidget *widget, GdkEventMotion *event, gpointer user_data);
119
120 /* Function responsible for updating the exposed area.
121 * It must do an events request to the lttvwindow API to ask for this update.
122 * Note : this function cannot clear the background, because it may
123 * erase drawing already present (SAFETY).
124 */
125 void histo_drawing_data_request(histoDrawing_t *drawing,
126 gint x, gint y,
127 gint width,
128 gint height)
129 {
130
131 }
132
133
134 void histo_drawing_data_request_begin(EventsRequest *events_request, LttvTraceset *traceset)
135 {
136 g_debug("Begin of data request");
137 HistoControlFlowData *cfd = events_request->viewer_data;
138 TimeWindow time_window =
139 lttvwindow_get_time_window(cfd->tab);
140
141 guint width = cfd->drawing->width;
142 guint x=0;
143
144 cfd->drawing->last_start = events_request->start_time;
145
146 histo_convert_time_to_pixels(
147 time_window,
148 events_request->start_time,
149 width,
150 &x);
151
152 }
153
154 void histo_drawing_chunk_begin(EventsRequest *events_request, LttvTraceset *traceset)
155 {
156 g_debug("Begin of chunk");
157 HistoControlFlowData *cfd = events_request->viewer_data;
158
159 if(cfd->chunk_has_begun) return;
160
161 cfd->chunk_has_begun = TRUE;
162 }
163
164
165 void histo_drawing_request_expose(EventsRequest *events_request,
166 LttvTraceset *traceset,
167 LttTime end_time)
168 {
169 HistoControlFlowData *cfd = events_request->viewer_data;
170 histoDrawing_t *drawing = cfd->drawing;
171
172 guint x, x_end, width;
173
174 TimeWindow time_window =
175 lttvwindow_get_time_window(cfd->tab);
176
177 g_debug("histo request expose");
178
179 histo_convert_time_to_pixels(
180 time_window,
181 end_time,
182 drawing->width,
183 &x_end);
184 x = drawing->damage_begin;
185
186 width = x_end - x;
187
188 drawing->damage_begin = x+width;
189
190 // FIXME ?
191 //changed for histogram:
192 gtk_widget_queue_draw_area ( drawing->drawing_area,
193 x, 0,
194 width,
195 drawing->/*drawing_area->allocation.*/height);
196
197 // Update directly when scrolling
198 gdk_window_process_updates(drawing->drawing_area->window,
199 TRUE);
200 }
201
202
203 /* Callbacks */
204
205
206 /* Create a new backing pixmap of the appropriate size */
207 /* As the scaling will always change, it's of no use to copy old
208 * pixmap.
209 *
210 * Change the size if width or height changes.
211 * (different from control flow viewer!)
212 */
213 static gboolean
214 histo_configure_event( GtkWidget *widget, GdkEventConfigure *event,
215 gpointer user_data)
216 {
217 histoDrawing_t *drawing = (histoDrawing_t*)user_data;
218
219 /* First, get the new time interval of the main window */
220 /* we assume (see documentation) that the main window
221 * has updated the time interval before this configure gets
222 * executed.
223 */
224 //lttvwindow_get_time_window(drawing->histo_control_flow_data->mw,
225 // &drawing->histo_control_flow_data->time_window);
226
227 /* New pixmap, size of the configure event */
228 //GdkPixmap *pixmap = gdk_pixmap_new(widget->window,
229 // widget->allocation.width + SAFETY,
230 // widget->allocation.height + SAFETY,
231 // -1);
232 g_debug("drawing configure event");
233 g_debug("New alloc draw size : %i by %i",widget->allocation.width,
234 widget->allocation.height);
235
236 /*modified for histogram, if width is not changed, GArray is valid so
237 just redraw, else recalculate all.(event request again)*/
238
239 //enabled again for histogram:
240 if(drawing->pixmap)
241 gdk_pixmap_unref(drawing->pixmap);
242
243 drawing->pixmap = gdk_pixmap_new(widget->window,
244 widget->allocation.width ,//+ SAFETY + EXTRA_ALLOC,
245 widget->allocation.height + EXTRA_ALLOC,
246 -1);
247
248 //end add
249 drawing->alloc_width = drawing->width + SAFETY + EXTRA_ALLOC;
250 drawing->alloc_height = drawing->height + EXTRA_ALLOC;
251
252 //drawing->height = widget->allocation.height;
253
254
255
256 // Clear the image
257 // gdk_draw_rectangle (drawing->pixmap,
258 // widget->style->black_gc,
259 // TRUE,
260 // 0, 0,
261 // drawing->width+SAFETY,
262 // drawing->height);
263
264 //g_info("init data request");
265
266
267 /* Initial data request */
268 /* no, do initial data request in the expose event */
269 // Do not need to ask for data of 1 pixel : not synchronized with
270 // main window time at this moment.
271 //histo_drawing_data_request(drawing, &drawing->pixmap, 0, 0,
272 // widget->allocation.width,
273 // widget->allocation.height);
274
275 //drawing->width = widget->allocation.width;
276 //drawing->height = widget->allocation.height;
277
278 drawing->damage_begin = 0;
279 drawing->damage_end = widget->allocation.width;
280
281 if((widget->allocation.width != 1 &&
282 widget->allocation.height != 1)
283 /*&& drawing->damage_begin < drawing->damage_end */)
284 {
285
286 gdk_draw_rectangle (drawing->pixmap,
287 drawing->drawing_area->style->black_gc,
288 TRUE,
289 0, 0,
290 drawing->drawing_area->allocation.width, drawing->drawing_area->allocation.height);
291 /* histo_drawing_data_request(drawing,
292 drawing->damage_begin,
293 0,
294 drawing->damage_end - drawing->damage_begin,
295 drawing->height);*/
296 }
297 //modified for histogram
298
299 if(widget->allocation.width == drawing->width)
300 {
301
302 drawing->height = widget->allocation.height;
303 histogram_show( drawing->histo_control_flow_data,0,
304 drawing->histo_control_flow_data->number_of_process->len);
305 }
306 else
307 {
308 drawing->width = widget->allocation.width;
309 drawing->height = widget->allocation.height;
310
311 g_array_set_size (drawing->histo_control_flow_data->number_of_process,
312 widget->allocation.width);
313 histo_request_event( drawing->histo_control_flow_data,drawing->damage_begin
314 ,drawing->damage_end - drawing->damage_begin);
315 }
316 return TRUE;
317 }
318
319
320 /* Redraw the screen from the backing pixmap */
321 static gboolean
322 histo_expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
323 {
324 histoDrawing_t *drawing = (histoDrawing_t*)user_data;
325
326 HistoControlFlowData *histo_control_flow_data =
327 (HistoControlFlowData*)g_object_get_data(
328 G_OBJECT(widget),
329 "histo_control_flow_data");
330 #if 0
331 if(unlikely(drawing->gc == NULL)) {
332 drawing->gc = gdk_gc_new(drawing->drawing_area->window);
333 gdk_gc_copy(drawing->gc, drawing->drawing_area->style->black_gc);
334 }
335 #endif //0
336 TimeWindow time_window =
337 lttvwindow_get_time_window(histo_control_flow_data->tab);
338 LttTime current_time =
339 lttvwindow_get_current_time(histo_control_flow_data->tab);
340
341 guint cursor_x=0;
342
343 LttTime window_end = time_window.end_time;
344
345
346 /* update the screen from the pixmap buffer */
347 //added again for histogram:
348
349 gdk_draw_pixmap(widget->window,
350 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
351 drawing->pixmap,
352 event->area.x, event->area.y,
353 event->area.x, event->area.y,
354 event->area.width, event->area.height);
355 //0
356
357 drawing->height = drawing-> drawing_area ->allocation.height;
358
359 #if 0
360 copy_pixmap_to_screen(histo_control_flow_data->process_list,
361 widget->window,
362 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
363 event->area.x, event->area.y,
364 event->area.width, event->area.height);
365 #endif //0
366
367
368 /* //disabled for histogram
369 copy_pixmap_to_screen(histo_control_flow_data->process_list,
370 widget->window,
371 drawing->gc,
372 event->area.x, event->area.y,
373 event->area.width, event->area.height);*/
374
375 /* Erase the dotted lines left.. */
376 if(widget->allocation.height > drawing->height)
377 {
378 gdk_draw_rectangle (widget->window,
379 drawing->drawing_area->style->black_gc,
380 TRUE,
381 event->area.x, drawing->height,
382 event->area.width, // do not overlap
383 widget->allocation.height - drawing->height);
384 }
385 if(ltt_time_compare(time_window.start_time, current_time) <= 0 &&
386 ltt_time_compare(window_end, current_time) >= 0)
387 {
388 /* Draw the dotted lines */
389 histo_convert_time_to_pixels(
390 time_window,
391 current_time,
392 drawing->width,
393 &cursor_x);
394
395 #if 0
396 if(drawing->dotted_gc == NULL) {
397
398 drawing->dotted_gc = gdk_gc_new(drawing->drawing_area->window);
399 gdk_gc_copy(drawing->dotted_gc, widget->style->white_gc);
400
401 gint8 dash_list[] = { 1, 2 };
402 gdk_gc_set_line_attributes(drawing->dotted_gc,
403 1,
404 GDK_LINE_ON_OFF_DASH,
405 GDK_CAP_BUTT,
406 GDK_JOIN_MITER);
407 gdk_gc_set_dashes(drawing->dotted_gc,
408 0,
409 dash_list,
410 2);
411 }
412 #endif //0
413 gint height_tot = MAX(widget->allocation.height, drawing->height);
414 gdk_draw_line(widget->window,
415 drawing->dotted_gc,
416 cursor_x, 0,
417 cursor_x, height_tot);
418 }
419
420 return FALSE;
421 }
422
423 static gboolean
424 histo_after_expose_event( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
425 {
426 //g_assert(0);
427 g_debug("AFTER EXPOSE");
428
429 return FALSE;
430 }
431
432 /* mouse click */
433 static gboolean
434 histo_button_press_event( GtkWidget *widget, GdkEventButton *event, gpointer user_data )
435 {
436 HistoControlFlowData *histo_control_flow_data =
437 (HistoControlFlowData*)g_object_get_data(
438 G_OBJECT(widget),
439 "histo_control_flow_data");
440 histoDrawing_t *drawing = histo_control_flow_data->drawing;
441 TimeWindow time_window =
442 lttvwindow_get_time_window(histo_control_flow_data->tab);
443
444 g_debug("click");
445 if(event->button == 1)
446 {
447 LttTime time;
448
449 /* left mouse button click */
450 g_debug("x click is : %f", event->x);
451
452 histo_convert_pixels_to_time(drawing->width, (guint)event->x,
453 time_window,
454 &time);
455
456 lttvwindow_report_current_time(histo_control_flow_data->tab, time);
457 ////report event->y for vertical zoom +,-
458 }
459
460 return FALSE;
461 }
462 /*
463 //Viewer's vertical scroll bar is already omitted, not needed for histogram.
464 static gboolean
465 scrollbar_size_allocate(GtkWidget *widget,
466 GtkAllocation *allocation,
467 gpointer user_data)
468 {
469 histoDrawing_t *drawing = (histoDrawing_t*)user_data;
470
471 gtk_widget_set_size_request(drawing->padding, allocation->width, -1);
472 //gtk_widget_queue_resize(drawing->padding);
473 //gtk_widget_queue_resize(drawing->ruler);
474 gtk_container_check_resize(GTK_CONTAINER(drawing->ruler_hbox));
475 return 0;
476 }
477 */
478
479
480 histoDrawing_t *histo_drawing_construct(HistoControlFlowData *histo_control_flow_data)
481 {
482 histoDrawing_t *drawing = g_new(histoDrawing_t, 1);
483
484 drawing->histo_control_flow_data = histo_control_flow_data;
485
486 drawing->vbox = gtk_vbox_new(FALSE, 1);
487
488
489 drawing->ruler_hbox = gtk_hbox_new(FALSE, 1);
490 drawing->ruler = gtk_drawing_area_new ();
491 //gtk_widget_set_size_request(drawing->ruler, -1, 27);
492
493 drawing->padding = gtk_drawing_area_new ();
494 //gtk_widget_set_size_request(drawing->padding, -1, 27);
495
496 gtk_box_pack_start(GTK_BOX(drawing->ruler_hbox), drawing->padding,FALSE, FALSE, 0);
497
498 gtk_box_pack_end(GTK_BOX(drawing->ruler_hbox), drawing->ruler,
499 TRUE, TRUE, 0);
500
501 drawing->drawing_area = gtk_drawing_area_new ();
502
503 drawing->gc = NULL;
504 /*
505 ///at this time not necessary for histogram
506 drawing->hbox = gtk_hbox_new(FALSE, 1);
507
508 drawing->viewport = gtk_viewport_new(NULL, histo_control_flow_data->v_adjust);
509 drawing->scrollbar = gtk_vscrollbar_new(histo_control_flow_data->v_adjust);
510 gtk_box_pack_start(GTK_BOX(drawing->hbox), drawing->viewport,
511 TRUE, TRUE, 0);
512 gtk_box_pack_end(GTK_BOX(drawing->hbox), drawing->scrollbar,
513 FALSE, FALSE, 0);
514 gtk_container_add(GTK_CONTAINER(drawing->viewport),
515 drawing->drawing_area);*/
516
517 //add vertical ruler:
518 drawing->vruler_drawing_hbox = gtk_hbox_new(FALSE, 1);
519 drawing-> vertical_ruler =gtk_drawing_area_new ();
520 gtk_box_pack_start(GTK_BOX(drawing->vruler_drawing_hbox), drawing->vertical_ruler,
521 FALSE, FALSE, 0);
522 gtk_box_pack_end(GTK_BOX(drawing->vruler_drawing_hbox), drawing->drawing_area,
523 TRUE, TRUE, 1);
524 gtk_widget_set_size_request(drawing->vertical_ruler, padding_width, -1);
525
526 gtk_box_pack_start(GTK_BOX(drawing->vbox), drawing->ruler_hbox,
527 FALSE, FALSE, 1);
528 gtk_box_pack_end(GTK_BOX(drawing->vbox), drawing->vruler_drawing_hbox/*drawing_area*/,
529 TRUE, TRUE, 1);
530
531 drawing->pango_layout =
532 gtk_widget_create_pango_layout(drawing->drawing_area, NULL);
533
534 drawing->height = 1;
535 drawing->width = 1;
536 drawing->depth = 0;
537 drawing->alloc_height = 1;
538 drawing->alloc_width = 1;
539
540 drawing->damage_begin = 0;
541 drawing->damage_end = 0;
542 drawing->horizontal_sel = -1;
543
544 //gtk_widget_set_size_request(drawing->drawing_area->window, 50, 50);
545 g_object_set_data_full(
546 G_OBJECT(drawing->drawing_area),
547 "histo_Link_drawing_Data",
548 drawing,
549 (GDestroyNotify)histo_drawing_destroy);
550
551 g_object_set_data(
552 G_OBJECT(drawing->ruler),
553 "histo_drawing",
554 drawing);
555
556 g_object_set_data(
557 G_OBJECT(drawing->vertical_ruler),
558 "histo_drawing",
559 drawing);
560
561 //gtk_widget_modify_bg( drawing->drawing_area,
562 // GTK_STATE_NORMAL,
563 // &CF_Colors[BLACK]);
564
565 //gdk_window_get_geometry(drawing->drawing_area->window,
566 // NULL, NULL,
567 // &(drawing->width),
568 // &(drawing->height),
569 // -1);
570
571 //drawing->pixmap = gdk_pixmap_new(
572 // drawing->drawing_area->window,
573 // drawing->width,
574 // drawing->height,
575 // drawing->depth);
576
577 drawing->pixmap = NULL;
578
579 // drawing->pixmap = gdk_pixmap_new(drawing->drawing_area->window,
580 // drawing->drawing_area->allocation.width,
581 // drawing->drawing_area->allocation.height,
582 // -1);
583
584 g_signal_connect (G_OBJECT(drawing->drawing_area),
585 "configure_event",
586 G_CALLBACK (histo_configure_event),
587 (gpointer)drawing);
588
589 g_signal_connect (G_OBJECT(drawing->ruler),
590 "expose_event",
591 G_CALLBACK(histo_expose_ruler),
592 (gpointer)drawing);
593
594 gtk_widget_add_events(drawing->ruler, GDK_POINTER_MOTION_MASK);
595 gtk_widget_add_events(drawing->vertical_ruler, GDK_POINTER_MOTION_MASK);
596
597 g_signal_connect (G_OBJECT(drawing->ruler),
598 "motion-notify-event",
599 G_CALLBACK(histo_motion_notify_ruler),
600 (gpointer)drawing);
601
602
603 g_signal_connect (G_OBJECT(drawing->vertical_ruler),
604 "expose_event",
605 G_CALLBACK(histo_expose_vertical_ruler),
606 (gpointer)drawing);
607
608 g_signal_connect (G_OBJECT(drawing->vertical_ruler),
609 "motion-notify-event",
610 G_CALLBACK(histo_motion_notify_vertical_ruler),
611 (gpointer)drawing);
612
613 /*//not necessary for historam.
614 g_signal_connect (G_OBJECT(drawing->drawing_area),
615 "size-allocate",
616 G_CALLBACK(scrollbar_size_allocate),
617 (gpointer)drawing); */
618
619
620 gtk_widget_set_size_request(drawing->padding, padding_width, -1);//use it for vertical ruler
621
622 g_signal_connect (G_OBJECT(drawing->drawing_area),
623 "expose_event",
624 G_CALLBACK (histo_expose_event),
625 (gpointer)drawing);
626
627 g_signal_connect_after (G_OBJECT(drawing->drawing_area),
628 "expose_event",
629 G_CALLBACK (histo_after_expose_event),
630 (gpointer)drawing);
631
632 g_signal_connect (G_OBJECT(drawing->drawing_area),
633 "button-press-event",
634 G_CALLBACK (histo_button_press_event),
635 (gpointer)drawing);
636
637 gtk_widget_show(drawing->ruler);
638 gtk_widget_show(drawing->padding);
639 gtk_widget_show(drawing->ruler_hbox);
640 gtk_widget_show(drawing->vertical_ruler);
641 gtk_widget_show(drawing->vruler_drawing_hbox);
642 gtk_widget_show(drawing->drawing_area);
643
644 /// gtk_widget_show(drawing->viewport);
645 /// gtk_widget_show(drawing->scrollbar);
646 /// gtk_widget_show(drawing->hbox);
647
648 /* Allocate the colors */
649 GdkColormap* colormap = gdk_colormap_get_system();
650 gboolean success[NUM_COLORS];
651 gdk_colormap_alloc_colors(colormap, histo_drawing_colors, NUM_COLORS, FALSE,
652 TRUE, success);
653
654 drawing->gc =
655 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data->tab)->window));
656 drawing->dotted_gc =
657 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data->tab)->window));
658
659 gdk_gc_copy(drawing->gc,
660 main_window_get_widget(histo_control_flow_data->tab)->style->black_gc);
661 gdk_gc_copy(drawing->dotted_gc,
662 main_window_get_widget(histo_control_flow_data->tab)->style->white_gc);
663
664 gint8 dash_list[] = { 1, 2 };
665 gdk_gc_set_line_attributes(drawing->dotted_gc,
666 1,
667 GDK_LINE_ON_OFF_DASH,
668 GDK_CAP_BUTT,
669 GDK_JOIN_MITER);
670 gdk_gc_set_dashes(drawing->dotted_gc,
671 0,
672 dash_list,
673 2);
674
675 drawing->ruler_gc_butt =
676 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data->tab)->window));
677 gdk_gc_copy(drawing->ruler_gc_butt,
678 main_window_get_widget(histo_control_flow_data->tab)->style->black_gc);
679 drawing->ruler_gc_round =
680 gdk_gc_new(GDK_DRAWABLE(main_window_get_widget(histo_control_flow_data->tab)->window));
681 gdk_gc_copy(drawing->ruler_gc_round,
682 main_window_get_widget(histo_control_flow_data->tab)->style->black_gc);
683
684
685 gdk_gc_set_line_attributes(drawing->ruler_gc_butt,
686 2,
687 GDK_LINE_SOLID,
688 GDK_CAP_BUTT,
689 GDK_JOIN_MITER);
690
691 gdk_gc_set_line_attributes(drawing->ruler_gc_round,
692 2,
693 GDK_LINE_SOLID,
694 GDK_CAP_ROUND,
695 GDK_JOIN_ROUND);
696 return drawing;
697 }
698
699 void histo_drawing_destroy(histoDrawing_t *drawing)
700 {
701 g_info("histo_drawing_destroy %p", drawing);
702
703 /* Free the colors */
704 GdkColormap* colormap = gdk_colormap_get_system();
705
706 gdk_colormap_free_colors(colormap, histo_drawing_colors, NUM_COLORS);
707
708 // Do not unref here, histoDrawing_t destroyed by it's widget.
709 //g_object_unref( G_OBJECT(drawing->drawing_area));
710 if(drawing->gc != NULL)
711 gdk_gc_unref(drawing->gc);
712
713 g_object_unref(drawing->pango_layout);
714 if(drawing->dotted_gc != NULL) gdk_gc_unref(drawing->dotted_gc);
715 if(drawing->ruler_gc_butt != NULL) gdk_gc_unref(drawing->ruler_gc_butt);
716 if(drawing->ruler_gc_round != NULL) gdk_gc_unref(drawing->ruler_gc_round);
717
718 //added for histogram
719 if(drawing->pixmap)
720 gdk_pixmap_unref(drawing->pixmap);
721 g_free(drawing);
722 g_info("histo_drawing_destroy end");
723 }
724
725 GtkWidget *histo_drawing_get_drawing_area(histoDrawing_t *drawing)
726 {
727 return drawing->drawing_area;
728 }
729
730 GtkWidget *histo_drawing_get_widget(histoDrawing_t *drawing)
731 {
732 return drawing->vbox;
733 }
734
735 void histo_drawing_draw_line( histoDrawing_t *drawing,
736 GdkPixmap *pixmap,
737 guint x1, guint y1,
738 guint x2, guint y2,
739 GdkGC *GC)
740 {
741 gdk_draw_line (pixmap,
742 GC,
743 x1, y1, x2, y2);
744 }
745
746 void histo_drawing_clear(histoDrawing_t *drawing,guint clear_from,guint clear_to)
747 {
748 guint clear_width = clear_to- clear_from;
749 /*
750 //disabled for histogram
751 rectangle_pixmap(cfd->process_list,
752 drawing->drawing_area->style->black_gc,
753 TRUE,
754 0, 0,
755 drawing->alloc_width, // do not overlap
756 -1);*/
757 //instead, this is added for histogram
758
759 histo_rectangle_pixmap (drawing->drawing_area->style->black_gc,
760 TRUE,
761 clear_from/*0*/, 0,
762 clear_width/*drawing->width*/,
763 -1,drawing);
764
765
766
767 /* gdk_draw_rectangle (drawing->pixmap,
768 drawing->drawing_area->style->black_gc,
769 TRUE,
770 0,0,
771 drawing->drawing_area->allocation.width,drawing->drawing_area->allocation.height );
772 */
773
774 /* ask for the buffer to be redrawn */
775 //enabled again for histogram.
776 gtk_widget_queue_draw_area ( drawing->drawing_area,
777 clear_from, 0,
778 clear_width, drawing->height);
779 gdk_window_process_updates(drawing->drawing_area->window,TRUE);
780 //disabled instead for histogram
781 //gtk_widget_queue_draw ( drawing->drawing_area);
782 return;
783 }
784
785 #if 0
786 /* Insert a square corresponding to a new process in the list */
787 /* Applies to whole drawing->width */
788 void drawing_insert_square(histoDrawing_t *drawing,
789 guint y,
790 guint height)
791 {
792 //GdkRectangle update_rect;
793 gboolean reallocate = FALSE;
794 GdkPixmap *new_pixmap;
795
796 /* Allocate a new pixmap with new height */
797 if(drawing->alloc_height < drawing->height + height) {
798
799 new_pixmap = gdk_pixmap_new(drawing->drawing_area->window,
800 drawing->width + SAFETY + EXTRA_ALLOC,
801 drawing->height + height + EXTRA_ALLOC,
802 -1);
803 drawing->alloc_width = drawing->width + SAFETY + EXTRA_ALLOC;
804 drawing->alloc_height = drawing->height + height + EXTRA_ALLOC;
805 reallocate = TRUE;
806
807 /* Copy the high region */
808 gdk_draw_pixmap (new_pixmap,
809 drawing->drawing_area->style->black_gc,
810 drawing->pixmap,
811 0, 0,
812 0, 0,
813 drawing->width + SAFETY, y);
814
815 } else {
816 new_pixmap = drawing->pixmap;
817 }
818
819 //GdkPixmap *pixmap = gdk_pixmap_new(drawing->drawing_area->window,
820 // drawing->width + SAFETY,
821 // drawing->height + height,
822 // -1);
823
824 /* add an empty square */
825 gdk_draw_rectangle (new_pixmap,
826 drawing->drawing_area->style->black_gc,
827 TRUE,
828 0, y,
829 drawing->width + SAFETY, // do not overlap
830 height);
831
832 /* copy the bottom of the region */
833 gdk_draw_pixmap (new_pixmap,
834 drawing->drawing_area->style->black_gc,
835 drawing->pixmap,
836 0, y,
837 0, y + height,
838 drawing->width+SAFETY, drawing->height - y);
839
840
841 if(reallocate && likely(drawing->pixmap)) {
842 gdk_pixmap_unref(drawing->pixmap);
843 drawing->pixmap = new_pixmap;
844 }
845
846 if(unlikely(drawing->height==1)) drawing->height = height;
847 else drawing->height += height;
848
849 gtk_widget_set_size_request(drawing->drawing_area,
850 -1,
851 drawing->height);
852 gtk_widget_queue_resize_no_redraw(drawing->drawing_area);
853
854 /* ask for the buffer to be redrawn */
855 gtk_widget_queue_draw_area ( drawing->drawing_area,
856 0, y,
857 drawing->width, drawing->height-y);
858 }
859
860
861 /* Remove a square corresponding to a removed process in the list */
862 void drawing_remove_square(histoDrawing_t *drawing,
863 guint y,
864 guint height)
865 {
866 GdkPixmap *pixmap;
867
868 if(unlikely((guint)drawing->height == height)) {
869 //pixmap = gdk_pixmap_new(
870 // drawing->drawing_area->window,
871 // drawing->width + SAFETY,
872 // 1,
873 // -1);
874 pixmap = drawing->pixmap;
875 drawing->height=1;
876 } else {
877 /* Allocate a new pixmap with new height */
878 //pixmap = gdk_pixmap_new(
879 // drawing->drawing_area->window,
880 // drawing->width + SAFETY,
881 // drawing->height - height,
882 // -1);
883 /* Keep the same preallocated pixmap */
884 pixmap = drawing->pixmap;
885
886 /* Copy the high region */
887 gdk_draw_pixmap (pixmap,
888 drawing->drawing_area->style->black_gc,
889 drawing->pixmap,
890 0, 0,
891 0, 0,
892 drawing->width + SAFETY, y);
893
894 /* Copy up the bottom of the region */
895 gdk_draw_pixmap (pixmap,
896 drawing->drawing_area->style->black_gc,
897 drawing->pixmap,
898 0, y + height,
899 0, y,
900 drawing->width, drawing->height - y - height);
901
902 drawing->height-=height;
903 }
904
905 //if(likely(drawing->pixmap))
906 // gdk_pixmap_unref(drawing->pixmap);
907
908 //drawing->pixmap = pixmap;
909
910 gtk_widget_set_size_request(drawing->drawing_area,
911 -1,
912 drawing->height);
913 gtk_widget_queue_resize_no_redraw(drawing->drawing_area);
914 /* ask for the buffer to be redrawn */
915 gtk_widget_queue_draw_area ( drawing->drawing_area,
916 0, y,
917 drawing->width, MAX(drawing->height-y, 1));
918 }
919 #endif //0
920
921 void histo_drawing_update_ruler(histoDrawing_t *drawing, TimeWindow *time_window)
922 {
923 gtk_widget_queue_draw(drawing->ruler);
924 }
925
926 /* Redraw the ruler */
927 static gboolean
928 histo_expose_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
929 {
930 histoDrawing_t *drawing = (histoDrawing_t*)user_data;
931 TimeWindow time_window = lttvwindow_get_time_window(drawing->histo_control_flow_data->tab);
932 gchar text[255];
933
934 PangoContext *context;
935 PangoLayout *layout;
936 PangoFontDescription *FontDesc;
937 PangoRectangle ink_rect;
938 gint global_width=0;
939 GdkColor foreground = { 0, 0, 0, 0 };
940 GdkColor background = { 0, 0xffff, 0xffff, 0xffff };
941
942 LttTime window_end = time_window.end_time;
943 LttTime half_width =
944 ltt_time_div(time_window.time_width,2.0);
945 LttTime window_middle =
946 ltt_time_add(half_width,
947 time_window.start_time);
948 g_debug("ruler expose event");
949
950 gdk_draw_rectangle (drawing->ruler->window,
951 drawing->ruler->style->white_gc,
952 TRUE,
953 event->area.x, event->area.y,
954 event->area.width,
955 event->area.height);
956
957 gdk_draw_line (drawing->ruler->window,
958 drawing->ruler_gc_butt,
959 event->area.x, 1,
960 event->area.x + event->area.width, 1);
961
962
963 snprintf(text, 255, "%lus\n%luns",
964 time_window.start_time.tv_sec,
965 time_window.start_time.tv_nsec);
966
967 layout = gtk_widget_create_pango_layout(drawing->drawing_area, NULL);
968
969 context = pango_layout_get_context(layout);
970 FontDesc = pango_context_get_font_description(context);
971
972 pango_font_description_set_size(FontDesc, 6*PANGO_SCALE);
973 pango_layout_context_changed(layout);
974
975 pango_layout_set_text(layout, text, -1);
976 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
977 global_width += ink_rect.width;
978
979 gdk_draw_layout_with_colors(drawing->ruler->window,
980 drawing->ruler_gc_butt,
981 0,
982 6,
983 layout, &foreground, &background);
984
985 gdk_draw_line (drawing->ruler->window,
986 drawing->ruler_gc_round,
987 1, 1,
988 1, 7);
989
990
991 snprintf(text, 255, "%lus\n%luns", window_end.tv_sec,
992 window_end.tv_nsec);
993
994 pango_layout_set_text(layout, text, -1);
995 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
996 global_width += ink_rect.width;
997
998 if(global_width <= drawing->ruler->allocation.width)
999 {
1000 gdk_draw_layout_with_colors(drawing->ruler->window,
1001 drawing->ruler_gc_butt,
1002 drawing->ruler->allocation.width - ink_rect.width,
1003 6,
1004 layout, &foreground, &background);
1005
1006 gdk_draw_line (drawing->ruler->window,
1007 drawing->ruler_gc_butt,
1008 drawing->ruler->allocation.width-1, 1,
1009 drawing->ruler->allocation.width-1, 7);
1010 }
1011
1012
1013 snprintf(text, 255, "%lus\n%luns", window_middle.tv_sec,
1014 window_middle.tv_nsec);
1015
1016 pango_layout_set_text(layout, text, -1);
1017 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
1018 global_width += ink_rect.width;
1019
1020 if(global_width <= drawing->ruler->allocation.width)
1021 {
1022 gdk_draw_layout_with_colors(drawing->ruler->window,
1023 drawing->ruler_gc_butt,
1024 (drawing->ruler->allocation.width - ink_rect.width)/2,
1025 6,
1026 layout, &foreground, &background);
1027
1028 gdk_draw_line (drawing->ruler->window,
1029 drawing->ruler_gc_butt,
1030 drawing->ruler->allocation.width/2, 1,
1031 drawing->ruler->allocation.width/2, 7);
1032 }
1033
1034 g_object_unref(layout);
1035
1036 return FALSE;
1037 }
1038
1039 void histo_drawing_update_vertical_ruler(histoDrawing_t *drawing)//, TimeWindow *time_window)
1040 {
1041 gtk_widget_queue_draw(drawing->vertical_ruler);
1042 }
1043
1044 /* notify mouse on ruler */
1045 static gboolean
1046 histo_motion_notify_ruler(GtkWidget *widget, GdkEventMotion *event, gpointer user_data)
1047 {
1048 //g_debug("motion");
1049 //eventually follow mouse and show time here
1050 return FALSE;
1051 }
1052
1053 static gboolean
1054 histo_motion_notify_vertical_ruler(GtkWidget *widget, GdkEventMotion *event, gpointer user_data)
1055 {
1056 //g_debug("motion");
1057 //eventually follow mouse and show time here
1058 return FALSE;
1059 }
1060
1061
1062
1063 /* Redraw the vertical ruler */
1064 static gboolean
1065 histo_expose_vertical_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data )
1066 {
1067 histoDrawing_t *drawing = (histoDrawing_t*)user_data;
1068 HistoControlFlowData *histo_cfv = drawing->histo_control_flow_data;
1069 gchar text[255];
1070
1071 PangoContext *context;
1072 PangoLayout *layout;
1073 PangoFontDescription *FontDesc;
1074 PangoRectangle ink_rect;
1075 gint global_height=0;
1076 GdkColor foreground = { 0, 0, 0, 0 };
1077 GdkColor background = { 0, 0xffff, 0xffff, 0xffff };
1078 GdkColor red ={ 0, 0xFFFF, 0x1E00, 0x1000 };
1079 //GdkColor magneta ={ 0, 0x8900, 0x0000, 0x8400 };
1080 g_debug("vertical ruler expose event");
1081
1082 gdk_draw_rectangle (drawing->vertical_ruler->window,
1083 drawing->vertical_ruler->style->white_gc,
1084 TRUE,
1085 event->area.x, event->area.y,
1086 event->area.width,
1087 event->area.height);
1088
1089 gdk_draw_line (drawing->vertical_ruler->window,
1090 drawing->ruler_gc_butt,
1091 padding_width-1/*event->area.width-1*/,event->area.y,
1092 padding_width-1/*event->area.width-1*/,event->area.y + event->area.height);
1093
1094 snprintf(text, 255, "%.1f", (float)histo_cfv->max_height);
1095
1096 layout = gtk_widget_create_pango_layout(drawing->drawing_area, NULL);
1097
1098 context = pango_layout_get_context(layout);
1099 FontDesc = pango_context_get_font_description(context);
1100
1101 pango_font_description_set_size(FontDesc, 6*PANGO_SCALE);
1102 pango_layout_context_changed(layout);
1103
1104 pango_layout_set_text(layout, text, -1);
1105 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
1106 global_height += ink_rect.height;
1107
1108 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1109 drawing->ruler_gc_butt,
1110 1,
1111 1,
1112 layout, &foreground, &background);
1113
1114 gdk_draw_line (drawing->vertical_ruler->window,
1115 drawing->ruler_gc_round,
1116 drawing->vertical_ruler-> allocation.width-1, 1,
1117 drawing->vertical_ruler-> allocation.width-7, 1);
1118
1119
1120 snprintf(text, 255, "%d", 0);
1121
1122 pango_layout_set_text(layout, text, -1);
1123 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
1124 global_height += ink_rect.height;
1125
1126 if(global_height <= drawing->vertical_ruler->allocation.height)
1127 {
1128 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1129 drawing->ruler_gc_butt,
1130 1,
1131 drawing->vertical_ruler->allocation.height - ink_rect.height-2,
1132 layout, &foreground, &background);
1133
1134 gdk_draw_line (drawing->vertical_ruler->window,
1135 drawing->ruler_gc_butt,
1136 drawing->vertical_ruler-> allocation.width-1,
1137 drawing->vertical_ruler->allocation.height-1,
1138 drawing->vertical_ruler-> allocation.width-7,
1139 drawing->vertical_ruler->allocation.height-1);
1140 }
1141
1142
1143 snprintf(text, 255, "%.1f",(float) histo_cfv->max_height/2.0);
1144
1145 pango_layout_set_text(layout, text, -1);
1146 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
1147 global_height += ink_rect.height;
1148
1149 if(global_height <= drawing->vertical_ruler->allocation.height)
1150 {
1151 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1152 drawing->ruler_gc_butt,
1153 1,
1154 (drawing->vertical_ruler->allocation.height - ink_rect.height)/2,
1155 layout, &foreground, &background);
1156
1157 gdk_draw_line (drawing->vertical_ruler->window,
1158 drawing->ruler_gc_butt,
1159 drawing->vertical_ruler-> allocation.width-1,
1160 drawing->vertical_ruler-> allocation.height/2,
1161 drawing->vertical_ruler-> allocation.width-7,
1162 drawing->vertical_ruler->allocation.height/2);
1163 }
1164
1165 //show number of events at current time:
1166 LttTime current_time =
1167 lttvwindow_get_current_time(histo_cfv->tab);
1168 TimeWindow time_window =
1169 lttvwindow_get_time_window(histo_cfv->tab);
1170 LttTime time_begin = time_window.start_time;
1171 LttTime time_width = time_window.time_width;
1172 LttTime time_end = ltt_time_add(time_begin, time_width);
1173 if((ltt_time_compare(current_time, time_begin) >= 0)&&
1174 (ltt_time_compare(current_time, time_end) <= 0))
1175 {
1176 guint *events_at_currenttime;
1177 guint max_height=histo_cfv ->max_height;
1178 guint x;
1179 histo_convert_time_to_pixels(
1180 time_window,
1181 current_time,
1182 drawing->width,
1183 &x);
1184 // if(x_test<histo_cfv->number_of_process->len)
1185
1186 {
1187 events_at_currenttime =
1188 &g_array_index(histo_cfv->number_of_process,guint,x);
1189
1190
1191 if((*events_at_currenttime) > max_height)
1192 {
1193 snprintf(text, 255, "OverFlow!");
1194 pango_layout_set_text(layout, text, -1);
1195 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
1196 global_height += ink_rect.height;
1197 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1198 drawing->ruler_gc_butt,
1199 1,
1200 (drawing->vertical_ruler->allocation.height - ink_rect.height)/5,
1201 layout, &red, &background);
1202 }else
1203 // if((*events_at_currenttime) <= max_height)
1204 {
1205 snprintf(text, 255, "%.1f",
1206 (float) *events_at_currenttime);
1207
1208 pango_layout_set_text(layout, text, -1);
1209 pango_layout_get_pixel_extents(layout, &ink_rect, NULL);
1210 global_height += ink_rect.height;
1211
1212 if ((*events_at_currenttime) == 0)
1213 {
1214 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1215 drawing->ruler_gc_butt,
1216 1,
1217 (drawing->vertical_ruler->allocation.height - ink_rect.height)-2,
1218 layout, &red, &background);
1219 }
1220 else if ((*events_at_currenttime) == max_height)
1221 {
1222 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1223 drawing->ruler_gc_butt,
1224 1,
1225 1,
1226 layout, &red, &background);
1227 }
1228 /*else if ((*events_at_currenttime) == max_height/2)
1229 {
1230 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1231 drawing->ruler_gc_butt,
1232 1,
1233 (drawing->vertical_ruler->allocation.height - ink_rect.height)/2,
1234 layout, &red, &background);
1235 }*/
1236 else if ((*events_at_currenttime) > max_height/2)
1237 {
1238 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1239 drawing->ruler_gc_butt,
1240 1,
1241 (drawing->vertical_ruler->allocation.height - ink_rect.height)/4,
1242 layout, &red, &background);
1243 }
1244 else{
1245 gdk_draw_layout_with_colors(drawing->vertical_ruler->window,
1246 drawing->ruler_gc_butt,
1247 1,
1248 ((drawing->vertical_ruler->allocation.height
1249 - ink_rect.height)*3)/4,
1250 layout, &red, &background);
1251 }
1252 }
1253
1254 }
1255 }
1256
1257 g_object_unref(layout);
1258
1259 return FALSE;
1260 }
1261
This page took 0.089828 seconds and 4 git commands to generate.