From: compudj Date: Sat, 31 Jan 2004 06:21:51 +0000 (+0000) Subject: basic time bar X-Git-Tag: v0.12.20~3026 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=3cb8b205f358d14996003565628dfa70ec95a311;p=lttv.git basic time bar git-svn-id: http://ltt.polymtl.ca/svn@463 04897980-b3bd-0310-b5e0-8ef037075253 --- diff --git a/ltt/branches/poly/lttv/modules/gui/controlflow/cfv-private.h b/ltt/branches/poly/lttv/modules/gui/controlflow/cfv-private.h index c383e2d4..291c129f 100644 --- a/ltt/branches/poly/lttv/modules/gui/controlflow/cfv-private.h +++ b/ltt/branches/poly/lttv/modules/gui/controlflow/cfv-private.h @@ -24,11 +24,11 @@ struct _ControlFlowData { GtkWidget *scrolled_window; MainWindow *mw; + GtkWidget *h_paned; + ProcessList *process_list; - Drawing_t *drawing; - GtkWidget *h_paned; - + Drawing_t *drawing; GtkAdjustment *v_adjust ; /* Shown events information */ diff --git a/ltt/branches/poly/lttv/modules/gui/controlflow/cfv.c b/ltt/branches/poly/lttv/modules/gui/controlflow/cfv.c index 3d4f7af4..8f35404e 100644 --- a/ltt/branches/poly/lttv/modules/gui/controlflow/cfv.c +++ b/ltt/branches/poly/lttv/modules/gui/controlflow/cfv.c @@ -46,7 +46,7 @@ extern GSList *g_control_flow_data_list; ControlFlowData * guicontrolflow(void) { - GtkWidget *process_list_widget, *drawing_widget; + GtkWidget *process_list_widget, *drawing_widget, *drawing_area; ControlFlowData* control_flow_data = g_new(ControlFlowData,1) ; @@ -56,6 +56,9 @@ guicontrolflow(void) drawing_widget = drawing_get_widget(control_flow_data->drawing); + drawing_area = + drawing_get_drawing_area(control_flow_data->drawing); + control_flow_data->number_of_process = 0; /* Create the Process list */ @@ -110,7 +113,7 @@ guicontrolflow(void) (GDestroyNotify)guicontrolflow_destructor); g_object_set_data( - G_OBJECT(drawing_widget), + G_OBJECT(drawing_area), "control_flow_data", control_flow_data); diff --git a/ltt/branches/poly/lttv/modules/gui/controlflow/drawing.c b/ltt/branches/poly/lttv/modules/gui/controlflow/drawing.c index f1fe8788..51a63ab0 100644 --- a/ltt/branches/poly/lttv/modules/gui/controlflow/drawing.c +++ b/ltt/branches/poly/lttv/modules/gui/controlflow/drawing.c @@ -35,6 +35,11 @@ * drawing functions * *****************************************************************************/ +static gboolean +expose_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data ); + + + //FIXME Colors will need to be dynamic. Graphic context part not done so far. typedef enum { @@ -386,10 +391,24 @@ button_press_event( GtkWidget *widget, GdkEventButton *event, gpointer user_data Drawing_t *drawing_construct(ControlFlowData *control_flow_data) { Drawing_t *drawing = g_new(Drawing_t, 1); - - drawing->drawing_area = gtk_drawing_area_new (); + drawing->control_flow_data = control_flow_data; + drawing->vbox = gtk_vbox_new(FALSE, 1); + + drawing->ruler = gtk_drawing_area_new (); + gtk_widget_set_size_request(drawing->ruler, -1, 27); + + + drawing->drawing_area = gtk_drawing_area_new (); + + gtk_box_pack_start(GTK_BOX(drawing->vbox), drawing->ruler, + FALSE, FALSE, 0); + //g_object_unref(G_OBJECT(drawing->ruler)); + gtk_box_pack_end(GTK_BOX(drawing->vbox), drawing->drawing_area, + TRUE, TRUE, 0); + //g_object_unref(G_OBJECT(drawing->drawing_area)); + drawing->pango_layout = gtk_widget_create_pango_layout(drawing->drawing_area, NULL); @@ -400,6 +419,12 @@ Drawing_t *drawing_construct(ControlFlowData *control_flow_data) drawing, (GDestroyNotify)drawing_destroy); + g_object_set_data( + G_OBJECT(drawing->ruler), + "drawing", + drawing); + + //gtk_widget_modify_bg( drawing->drawing_area, // GTK_STATE_NORMAL, // &CF_Colors[BLACK]); @@ -429,7 +454,12 @@ Drawing_t *drawing_construct(ControlFlowData *control_flow_data) "configure_event", G_CALLBACK (configure_event), (gpointer)drawing); - + + g_signal_connect (G_OBJECT(drawing->ruler), + "expose_event", + G_CALLBACK(expose_ruler), + (gpointer)drawing); + g_signal_connect (G_OBJECT(drawing->drawing_area), "expose_event", G_CALLBACK (expose_event), @@ -439,7 +469,10 @@ Drawing_t *drawing_construct(ControlFlowData *control_flow_data) "button-press-event", G_CALLBACK (button_press_event), (gpointer)drawing); - + + gtk_widget_show(drawing->ruler); + gtk_widget_show(drawing->drawing_area); + return drawing; } @@ -454,11 +487,16 @@ void drawing_destroy(Drawing_t *drawing) g_free(drawing); } -GtkWidget *drawing_get_widget(Drawing_t *drawing) +GtkWidget *drawing_get_drawing_area(Drawing_t *drawing) { return drawing->drawing_area; } +GtkWidget *drawing_get_widget(Drawing_t *drawing) +{ + return drawing->vbox; +} + /* convert_pixels_to_time * * Convert from window pixel and time interval to an absolute time. @@ -663,4 +701,169 @@ void drawing_remove_square(Drawing_t *drawing, //gtk_widget_draw( drawing->drawing_area, &update_rect); } +void drawing_update_ruler(Drawing_t *drawing, TimeWindow *time_window) +{ + GtkRequisition req; + GdkRectangle rect; + + req.width = drawing->ruler->allocation.width; + req.height = drawing->ruler->allocation.height; + + + rect.x = 0; + rect.y = 0; + rect.width = req.width; + rect.height = req.height; + + gtk_widget_queue_draw(drawing->ruler); + //gtk_widget_draw( drawing->ruler, &rect); +} + +/* Redraw the ruler */ +static gboolean +expose_ruler( GtkWidget *widget, GdkEventExpose *event, gpointer user_data ) +{ + Drawing_t *drawing = (Drawing_t*)user_data; + + gchar text[255]; + + PangoContext *context; + PangoLayout *layout; + PangoAttribute *attribute; + PangoFontDescription *FontDesc; + gint Font_Size; + PangoRectangle ink_rect; + guint global_width=0; + GdkColor foreground = { 0, 0, 0, 0 }; + GdkColor background = { 0, 0xffff, 0xffff, 0xffff }; + + LttTime window_end = + ltt_time_add(drawing->control_flow_data->time_window.time_width, + drawing->control_flow_data->time_window.start_time); + LttTime half_width = + ltt_time_div(drawing->control_flow_data->time_window.time_width,2.0); + LttTime window_middle = + ltt_time_add(half_width, + drawing->control_flow_data->time_window.start_time); + g_critical("ruler expose event"); + + gdk_draw_rectangle (drawing->ruler->window, + drawing->ruler->style->white_gc, + TRUE, + event->area.x, event->area.y, + event->area.width, + event->area.height); + + GdkGC *gc = gdk_gc_new(drawing->ruler->window); + gdk_gc_copy(gc, drawing->ruler->style->black_gc); + gdk_gc_set_line_attributes(gc, + 2, + GDK_LINE_SOLID, + GDK_CAP_BUTT, + GDK_JOIN_MITER); + gdk_draw_line (drawing->ruler->window, + gc, + event->area.x, 1, + event->area.x + event->area.width, 1); + + + snprintf(text, 255, "%lus\n%luns", + drawing->control_flow_data->time_window.start_time.tv_sec, + drawing->control_flow_data->time_window.start_time.tv_nsec); + + layout = gtk_widget_create_pango_layout(drawing->drawing_area, NULL); + + context = pango_layout_get_context(layout); + FontDesc = pango_context_get_font_description(context); + + pango_font_description_set_size(FontDesc, 6*PANGO_SCALE); + pango_layout_context_changed(layout); + + pango_layout_set_text(layout, text, -1); + pango_layout_get_pixel_extents(layout, &ink_rect, NULL); + global_width += ink_rect.width; + + gdk_draw_layout_with_colors(drawing->ruler->window, + gc, + 0, + 6, + layout, &foreground, &background); + + gdk_gc_set_line_attributes(gc, + 2, + GDK_LINE_SOLID, + GDK_CAP_ROUND, + GDK_JOIN_ROUND); + + gdk_draw_line (drawing->ruler->window, + gc, + 1, 1, + 1, 7); + + + snprintf(text, 255, "%lus\n%luns", window_end.tv_sec, + window_end.tv_nsec); + + pango_layout_set_text(layout, text, -1); + pango_layout_get_pixel_extents(layout, &ink_rect, NULL); + global_width += ink_rect.width; + + if(global_width <= drawing->ruler->allocation.width) + { + gdk_draw_layout_with_colors(drawing->ruler->window, + gc, + drawing->ruler->allocation.width - ink_rect.width, + 6, + layout, &foreground, &background); + + gdk_gc_set_line_attributes(gc, + 2, + GDK_LINE_SOLID, + GDK_CAP_ROUND, + GDK_JOIN_ROUND); + + gdk_draw_line (drawing->ruler->window, + gc, + drawing->ruler->allocation.width-1, 1, + drawing->ruler->allocation.width-1, 7); + } + + + snprintf(text, 255, "%lus\n%luns", window_middle.tv_sec, + window_middle.tv_nsec); + + pango_layout_set_text(layout, text, -1); + pango_layout_get_pixel_extents(layout, &ink_rect, NULL); + global_width += ink_rect.width; + + if(global_width <= drawing->ruler->allocation.width) + { + gdk_draw_layout_with_colors(drawing->ruler->window, + gc, + (drawing->ruler->allocation.width - ink_rect.width)/2, + 6, + layout, &foreground, &background); + + gdk_gc_set_line_attributes(gc, + 2, + GDK_LINE_SOLID, + GDK_CAP_ROUND, + GDK_JOIN_ROUND); + + gdk_draw_line (drawing->ruler->window, + gc, + drawing->ruler->allocation.width/2, 1, + drawing->ruler->allocation.width/2, 7); + + + + + } + + gdk_gc_unref(gc); + g_object_unref(layout); + + return FALSE; +} + diff --git a/ltt/branches/poly/lttv/modules/gui/controlflow/drawing.h b/ltt/branches/poly/lttv/modules/gui/controlflow/drawing.h index 8495797b..6576a892 100644 --- a/ltt/branches/poly/lttv/modules/gui/controlflow/drawing.h +++ b/ltt/branches/poly/lttv/modules/gui/controlflow/drawing.h @@ -55,7 +55,9 @@ typedef struct _Drawing_t Drawing_t; struct _Drawing_t { + GtkWidget *vbox; GtkWidget *drawing_area; + GtkWidget *ruler; GdkPixmap *pixmap; ControlFlowData *control_flow_data; @@ -69,7 +71,8 @@ Drawing_t *drawing_construct(ControlFlowData *control_flow_data); void drawing_destroy(Drawing_t *drawing); GtkWidget *drawing_get_widget(Drawing_t *drawing); - +GtkWidget *drawing_get_drawing_area(Drawing_t *drawing); + //void drawing_Refresh ( Drawing_t *drawing, // guint x, guint y, // guint width, guint height); @@ -112,4 +115,6 @@ void convert_time_to_pixels( gint width, guint *x); +void drawing_update_ruler(Drawing_t *drawing, TimeWindow *time_window); + #endif // _DRAWING_H diff --git a/ltt/branches/poly/lttv/modules/gui/controlflow/eventhooks.c b/ltt/branches/poly/lttv/modules/gui/controlflow/eventhooks.c index efc2dea9..ea08a9d7 100644 --- a/ltt/branches/poly/lttv/modules/gui/controlflow/eventhooks.c +++ b/ltt/branches/poly/lttv/modules/gui/controlflow/eventhooks.c @@ -1016,6 +1016,11 @@ gint update_time_window_hook(void *hook_data, void *call_data) guicontrolflow_get_time_window(control_flow_data); TimeWindow *new_time_window = ((TimeWindow*)call_data); + /* Update the ruler */ + drawing_update_ruler(control_flow_data->drawing, + new_time_window); + + /* Two cases : zoom in/out or scrolling */ /* In order to make sure we can reuse the old drawing, the scale must @@ -1197,6 +1202,8 @@ gint update_time_window_hook(void *hook_data, void *call_data) control_flow_data->drawing->height); } + + return 0; } diff --git a/ltt/branches/poly/lttv/modules/gui/controlflow/processlist.c b/ltt/branches/poly/lttv/modules/gui/controlflow/processlist.c index e67cac3f..1d4333f8 100644 --- a/ltt/branches/poly/lttv/modules/gui/controlflow/processlist.c +++ b/ltt/branches/poly/lttv/modules/gui/controlflow/processlist.c @@ -220,7 +220,7 @@ ProcessList *processlist_construct(void) gtk_tree_view_set_headers_visible( - GTK_TREE_VIEW(process_list->process_list_widget), FALSE); + GTK_TREE_VIEW(process_list->process_list_widget), TRUE); /* Create a column, associating the "text" attribute of the * cell_renderer to the first column of the model */