gfio: improve and remember font selection
authorJens Axboe <axboe@kernel.dk>
Fri, 23 Mar 2012 09:52:25 +0000 (10:52 +0100)
committerJens Axboe <axboe@kernel.dk>
Fri, 23 Mar 2012 09:52:25 +0000 (10:52 +0100)
Redraw/expose doesn't quite work yet, though.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
gfio.c
graph.c
graph.h

diff --git a/gfio.c b/gfio.c
index b91ef064b2281256ddc0141f4d5aec3d51b1108a..6f313ed08490f6c314ce2fab91973191c209e2f7 100644 (file)
--- a/gfio.c
+++ b/gfio.c
@@ -41,7 +41,7 @@ static int gfio_server_running;
 static unsigned int gfio_graph_limit = 100;
 
 GdkColor gfio_color_white;
-const char *gfio_graph_font;
+const char *gfio_graph_font = GRAPH_DEFAULT_FONT;
 
 typedef void (*clickfunction)(GtkWidget *widget, gpointer data);
 
@@ -1047,26 +1047,38 @@ static void view_results(GtkWidget *w, gpointer data)
                gfio_display_end_results(gc);
 }
 
-static void __update_graph_limits(struct gfio_graphs *g)
+static void __update_graph_settings(struct gfio_graphs *g)
 {
        line_graph_set_data_count_limit(g->iops_graph, gfio_graph_limit);
+       graph_set_font(g->iops_graph, gfio_graph_font);
        line_graph_set_data_count_limit(g->bandwidth_graph, gfio_graph_limit);
+       graph_set_font(g->bandwidth_graph, gfio_graph_font);
 }
 
-static void ge_update_lim_fn(gpointer key, gpointer value, gpointer data)
+static void ge_update_settings_fn(gpointer key, gpointer value, gpointer data)
 {
        struct gui_entry *ge = (struct gui_entry *) value;
+       GdkEvent *ev;
 
-       __update_graph_limits(&ge->graphs);
+       __update_graph_settings(&ge->graphs);
+
+       ev = gdk_event_new(GDK_EXPOSE);
+       g_signal_emit_by_name(G_OBJECT(ge->graphs.drawing_area), "expose_event", GTK_WIDGET(ge->graphs.drawing_area), ev, &ge->graphs);
+       gdk_event_free(ev);
 }
 
 static void update_graph_limits(void)
 {
        struct gui *ui = &main_ui;
+       GdkEvent *ev;
+
+       __update_graph_settings(&ui->graphs);
 
-       __update_graph_limits(&ui->graphs);
+       ev = gdk_event_new(GDK_EXPOSE);
+       g_signal_emit_by_name(G_OBJECT(ui->graphs.drawing_area), "expose_event", GTK_WIDGET(ui->graphs.drawing_area), ev, &ui->graphs);
+       gdk_event_free(ev);
 
-       g_hash_table_foreach(ui->ge_hash, ge_update_lim_fn, NULL);
+       g_hash_table_foreach(ui->ge_hash, ge_update_settings_fn, NULL);
 }
 
 static void preferences(GtkWidget *w, gpointer data)
@@ -1093,7 +1105,7 @@ static void preferences(GtkWidget *w, gpointer data)
        entry = gtk_label_new("Font face to use for graph labels");
        gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 5);
 
-       font = gtk_font_button_new();
+       font = gtk_font_button_new_with_font(gfio_graph_font);
        gtk_box_pack_start(GTK_BOX(hbox), font, FALSE, FALSE, 5);
 
        box = gtk_vbox_new(FALSE, 6);
diff --git a/graph.c b/graph.c
index 415c676cd792e2b43c9372c3aaccf448a1a1dcd0..51eb3eff17cb1f5f4d99ee203ea3718f4c482774 100644 (file)
--- a/graph.c
+++ b/graph.c
@@ -123,10 +123,15 @@ struct graph *graph_new(unsigned int xdim, unsigned int ydim, const char *font)
        g->per_label_limit = -1;
        g->font = font;
        if (!g->font)
-               g->font = "Sans";
+               g->font = GRAPH_DEFAULT_FONT;
        return g;
 }
 
+void graph_set_font(struct graph *g, const char *font)
+{
+       g->font = font;
+}
+
 void graph_x_axis_unit_change_notify(struct graph *g, graph_axis_unit_change_callback f)
 {
        g->x_axis_unit_change_callback = f;
@@ -286,7 +291,7 @@ static void draw_aligned_text(struct graph *g, cairo_t *cr, double x, double y,
                        factor = 1.0;
                        break;
        }
-       cairo_select_font_face (cr, g->font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
+       cairo_select_font_face(cr, g->font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
 
        cairo_set_font_size(cr, fontsize);
        cairo_text_extents(cr, text, &extents);
diff --git a/graph.h b/graph.h
index e7d879d683533ebfea5527ce21b9f2b2dfbfb12f..42f781ff9d5f59b4e6b17f891210576d1fd8638f 100644 (file)
--- a/graph.h
+++ b/graph.h
@@ -6,6 +6,8 @@ struct graph_label;
 
 typedef struct graph_label * graph_label_t;
 
+#define GRAPH_DEFAULT_FONT     "Sans 12"
+
 struct graph *graph_new(unsigned int xdim, unsigned int ydim, const char *font);
 /* graph_new() Returns a new graph structure of the given dimensions and font */
 void graph_set_size(struct graph *g, unsigned int xdim, unsigned int ydim);
@@ -21,6 +23,7 @@ void line_graph_set_data_count_limit(struct graph *g, int per_label_limit);
  * be added to a line graph.  Once the limit is reached, the oldest data 
  * is discarded as new data is added
  */
+void graph_set_font(struct graph *g, const char *font);
 void graph_title(struct graph *g, const char *title);
 /* graph_title() sets the main title of the graph to the given string */
 void graph_x_title(struct graph *g, const char *title);