aboutsummaryrefslogtreecommitdiff
path: root/shell/loadgraph.c
diff options
context:
space:
mode:
Diffstat (limited to 'shell/loadgraph.c')
-rw-r--r--shell/loadgraph.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/shell/loadgraph.c b/shell/loadgraph.c
index ceb91720..0290d1f1 100644
--- a/shell/loadgraph.c
+++ b/shell/loadgraph.c
@@ -6,7 +6,7 @@
* - fixes autoscaling
* - add color
*
- * Copyright (C) 2006 Leandro A. F. Pereira <leandro@hardinfo.org>
+ * Copyright (C) 2006 L. A. F. Pereira <l@tia.mat.br>
*
* The Simple Load Graph is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -43,6 +43,7 @@ struct _LoadGraph {
PangoLayout *layout;
gchar *suffix;
+ gchar *title;
};
static void _draw(LoadGraph * lg);
@@ -56,6 +57,7 @@ LoadGraph *load_graph_new(gint size)
size++;
lg->suffix = g_strdup("");
+ lg->title = g_strdup("");
lg->area = gtk_drawing_area_new();
lg->size = (size * 3) / 2;
lg->data = g_new0(gint, lg->size);
@@ -87,6 +89,18 @@ gchar *load_graph_get_data_suffix(LoadGraph * lg)
return lg->suffix;
}
+void load_graph_set_title(LoadGraph * lg, const gchar * title)
+{
+ g_free(lg->title);
+ lg->title = g_strdup(title);
+}
+
+const gchar *load_graph_get_title(LoadGraph *lg)
+{
+ if (lg != NULL) return lg->title;
+ return NULL;
+}
+
GtkWidget *load_graph_get_framed(LoadGraph * lg)
{
GtkWidget *align, *frame;
@@ -115,6 +129,8 @@ void load_graph_clear(LoadGraph * lg)
lg->max_value = 1;
lg->remax_count = 0;
+ load_graph_set_title(lg, "");
+
_draw(lg);
}
@@ -179,6 +195,18 @@ void load_graph_configure_expose(LoadGraph * lg)
(GCallback) _expose, lg);
}
+static void _draw_title(LoadGraph * lg, const char* title) {
+ gchar *tmp = g_strdup_printf("<span size=\"x-small\">%s</span>", title);
+ pango_layout_set_markup(lg->layout, tmp, -1);
+ int width = 0;
+ int height = 0;
+ pango_layout_get_pixel_size(lg->layout, &width, &height);
+ gint position = (lg->width / 2) - (width / 2);
+ gdk_draw_layout(GDK_DRAWABLE(lg->buf), lg->trace, position, 2,
+ lg->layout);
+ g_free(tmp);
+}
+
static void _draw_label_and_line(LoadGraph * lg, gint position, gint value)
{
gchar *tmp;
@@ -242,6 +270,9 @@ static void _draw(LoadGraph * lg)
_draw_label_and_line(lg, lg->height / 2, lg->max_value / 2);
_draw_label_and_line(lg, 3 * (lg->height / 4), lg->max_value / 4);
+ /* graph title */
+ _draw_title(lg, lg->title);
+
gtk_widget_queue_draw(lg->area);
}