[gnome-system-monitor/wip/newdesign] Pie chart ported to rectangle type
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-system-monitor/wip/newdesign] Pie chart ported to rectangle type
- Date: Thu, 15 Aug 2013 14:45:48 +0000 (UTC)
commit 64501011cae813621e871cdbb0a9ab01ac96d9e9
Author: Robert Roth <robert roth off gmail com>
Date: Thu Aug 15 17:45:04 2013 +0300
Pie chart ported to rectangle type
src/gsm_color_button.c | 79 +++++++++++++++++++++--------------------------
src/interface.cpp | 14 ++++----
src/load-graph.cpp | 8 ++++-
3 files changed, 48 insertions(+), 53 deletions(-)
---
diff --git a/src/gsm_color_button.c b/src/gsm_color_button.c
index 31ec8ce..6282aa2 100644
--- a/src/gsm_color_button.c
+++ b/src/gsm_color_button.c
@@ -64,8 +64,8 @@ enum
LAST_SIGNAL
};
-#define GSMCP_MIN_WIDTH 15
-#define GSMCP_MIN_HEIGHT 15
+#define GSMCP_MIN_WIDTH 28
+#define GSMCP_MIN_HEIGHT 28
static void gsm_color_button_class_init (GsmColorButtonClass * klass);
static void gsm_color_button_init (GsmColorButton * color_button);
@@ -216,21 +216,21 @@ gsm_color_button_draw (GtkWidget *widget, cairo_t * cr)
gdk_cairo_set_source_rgba (cr, color);
width = gdk_window_get_width (gtk_widget_get_window (widget));
height = gdk_window_get_height(gtk_widget_get_window (widget));
+ // colored background
+ cairo_paint (cr);
+ cairo_set_line_width (cr, 1);
+ cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
+ cairo_rectangle (cr, 0.5, 0.5, width - 1, height - 1);
+ cairo_stroke (cr);
+ cairo_set_line_width (cr, 1);
+ cairo_set_source_rgba (cr, 1, 1, 1, 0.4);
+ cairo_rectangle (cr, 1.5, 1.5, width - 3, height - 3);
+ cairo_stroke (cr);
switch (priv->type)
{
case GSMCP_TYPE_RECTANGLE:
- // colored background
- cairo_paint (cr);
- cairo_set_line_width (cr, 1);
- cairo_set_source_rgba (cr, 0, 0, 0, 0.5);
- cairo_rectangle (cr, 0.5, 0.5, width - 1, height - 1);
- cairo_stroke (cr);
- cairo_set_line_width (cr, 1);
- cairo_set_source_rgba (cr, 1, 1, 1, 0.4);
- cairo_rectangle (cr, 1.5, 1.5, width - 3, height - 3);
- cairo_stroke (cr);
if (priv->text != NULL) {
// label text with the usage percentage or network rate
@@ -249,64 +249,55 @@ gsm_color_button_draw (GtkWidget *widget, cairo_t * cr)
break;
case GSMCP_TYPE_PIE:
- if (width < 32) // 32px minimum size
- gtk_widget_set_size_request (widget, 32, 32);
- if (width < height)
- radius = width / 2;
- else
- radius = height / 2;
+ if (width < GSMCP_MIN_WIDTH) // 24px minimum size
+ gtk_widget_set_size_request (widget, GSMCP_MIN_WIDTH, -1);
+ radius = MIN (width, height) / 2;
+ if (priv->text != NULL) {
+ // label text with the usage percentage or network rate
+ gchar *markup = g_strdup_printf ("<span font='sans'>%s</span>", priv->text);
+ layout = pango_cairo_create_layout (cr);
+ pango_layout_set_markup (layout, markup, -1);
+ g_free (markup);
+ pango_layout_get_pixel_extents (layout, NULL, &extents);
+ gtk_render_layout (context, cr,
+ MIN (width, height) + (width - MIN (width, height) - extents.width) / 2,
+ (height - extents.height) / 2,
+ layout);
+ }
arc_start = -G_PI_2 + 2 * G_PI * priv->fraction;
arc_end = -G_PI_2;
cairo_set_line_width (cr, 1);
-
- // Draw external stroke and fill
- if (priv->fraction < 0.01) {
- cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, 4.5,
- 0, 2 * G_PI);
- } else if (priv->fraction > 0.99) {
- cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, radius - 2.25,
- 0, 2 * G_PI);
- } else {
- cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 2.25,
- arc_start, arc_end);
- cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, 4.5,
- arc_end, arc_start);
- cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 2.25,
- arc_start, arc_start);
- }
- cairo_fill_preserve (cr);
- cairo_set_source_rgba (cr, 0, 0, 0, 0.7);
- cairo_stroke (cr);
+ cairo_set_operator (cr, CAIRO_OPERATOR_ATOP);
// Draw internal highlight
cairo_set_source_rgba (cr, 1, 1, 1, 0.45);
cairo_set_line_width (cr, 1);
if (priv->fraction < 0.03) {
- cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, 3.25,
+ cairo_arc (cr, (MIN (width, height) / 2) + .5, (MIN (width, height) / 2) + .5, 3.25,
0, 2 * G_PI);
} else if (priv->fraction > 0.99) {
- cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, radius - 3.5,
+ cairo_arc (cr, (MIN (width, height) / 2) + .5, (MIN (width, height) / 2) + .5, radius - 3.5,
0, 2 * G_PI);
} else {
- cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 3.5,
+ cairo_arc_negative (cr, (MIN (width, height) / 2) + .5, (MIN (width, height) / 2) + .5, radius - 3.5,
arc_start + (1 / (radius - 3.75)),
arc_end - (1 / (radius - 3.75)));
- cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, 3.25,
+ cairo_arc_negative (cr, (MIN (width, height) / 2) + .5, (MIN (width, height) / 2) + .5, 3.25,
arc_end - (1 / (radius - 3.75)),
arc_start + (1 / (radius - 3.75)));
- cairo_arc_negative (cr, (width / 2) + .5, (height / 2) + .5, radius - 3.5,
+ cairo_arc_negative (cr, (MIN (width, height) / 2) + .5, (MIN (width, height) / 2) + .5, radius - 3.5,
arc_start + (1 / (radius - 3.75)),
arc_start + (1 / (radius - 3.75)));
}
- cairo_stroke (cr);
+ cairo_fill (cr);
// Draw external shape
cairo_set_line_width (cr, 1);
cairo_set_source_rgba (cr, 0, 0, 0, 0.2);
- cairo_arc (cr, (width / 2) + .5, (height / 2) + .5, radius - 1.25, 0,
+ cairo_arc (cr, (MIN (width, height) / 2) + .5, (MIN (width, height) / 2) + .5, radius - 2.25, 0,
G_PI * 2);
cairo_stroke (cr);
diff --git a/src/interface.cpp b/src/interface.cpp
index f83e0fc..9e91e39 100644
--- a/src/interface.cpp
+++ b/src/interface.cpp
@@ -225,7 +225,7 @@ create_sys_view (GsmApplication *app, GtkBuilder * builder)
G_CALLBACK (cb_cpu_color_changed), GINT_TO_POINTER (i));
gtk_grid_attach(GTK_GRID (cpu_table), color_picker, i%cols, i/cols, 1, 1);
gtk_widget_show (color_picker);
- gtk_widget_set_size_request(GTK_WIDGET(color_picker), 100, 24);
+ gtk_widget_set_size_request(GTK_WIDGET(color_picker), 100, 28);
}
app->cpu_graph = cpu_graph;
@@ -251,8 +251,8 @@ create_sys_view (GsmApplication *app, GtkBuilder * builder)
g_free(title_text);
label = GTK_WIDGET(gtk_builder_get_object(builder, "memory_label"));
-
- gtk_grid_attach_next_to (GTK_GRID (table), color_picker, label, GTK_POS_LEFT, 1, 2);
+ gtk_widget_set_size_request(GTK_WIDGET(color_picker), 100, 28);
+ gtk_grid_attach_next_to (GTK_GRID (table), color_picker, label, GTK_POS_LEFT, 1, 1);
gtk_grid_attach_next_to (GTK_GRID (table), load_graph_get_labels(mem_graph)->memory, label,
GTK_POS_BOTTOM, 1, 1);
color_picker = load_graph_get_swap_color_picker(mem_graph);
@@ -263,8 +263,8 @@ create_sys_view (GsmApplication *app, GtkBuilder * builder)
g_free(title_text);
label = GTK_WIDGET(gtk_builder_get_object(builder, "swap_label"));
-
- gtk_grid_attach_next_to (GTK_GRID (table), color_picker, label, GTK_POS_LEFT, 1, 2);
+ gtk_widget_set_size_request(GTK_WIDGET(color_picker), 100, 28);
+ gtk_grid_attach_next_to (GTK_GRID (table), color_picker, label, GTK_POS_LEFT, 1, 1);
gtk_grid_attach_next_to (GTK_GRID (table), load_graph_get_labels(mem_graph)->swap, label,
GTK_POS_BOTTOM, 1, 1);
app->mem_graph = mem_graph;
@@ -283,7 +283,7 @@ create_sys_view (GsmApplication *app, GtkBuilder * builder)
table = GTK_WIDGET (gtk_builder_get_object (builder, "net_table"));
color_picker = load_graph_get_net_in_color_picker (net_graph);
- gtk_widget_set_size_request(GTK_WIDGET(color_picker), 100, 24);
+ gtk_widget_set_size_request(GTK_WIDGET(color_picker), 100, 28);
g_signal_connect (G_OBJECT (color_picker), "color-set",
G_CALLBACK (cb_net_in_color_changed), app);
title_text = g_strdup_printf(title_template, _("Receiving"));
@@ -294,7 +294,7 @@ create_sys_view (GsmApplication *app, GtkBuilder * builder)
gtk_grid_attach_next_to (GTK_GRID (table), color_picker, label, GTK_POS_RIGHT, 1, 1);
color_picker = load_graph_get_net_out_color_picker (net_graph);
- gtk_widget_set_size_request(GTK_WIDGET(color_picker), 100, 24);
+ gtk_widget_set_size_request(GTK_WIDGET(color_picker), 100, 28);
g_signal_connect (G_OBJECT (color_picker), "color-set",
G_CALLBACK (cb_net_out_color_changed), app);
title_text = g_strdup_printf(title_template, _("Sending"));
diff --git a/src/load-graph.cpp b/src/load-graph.cpp
index 281f4f7..78c40fc 100644
--- a/src/load-graph.cpp
+++ b/src/load-graph.cpp
@@ -368,15 +368,19 @@ namespace
text = g_strdup(_("not available"));
} else {
// xgettext: 540MiB (53 %) of 1.0 GiB
- text = g_strdup_printf(_("%s (%.1f%%) of %s"), used_text, 100.0 * percent, total_text);
+ text = g_strdup_printf(_("%s of %s"), used_text, total_text);
}
gtk_label_set_text(label, text);
g_free(used_text);
g_free(total_text);
g_free(text);
- if (picker)
+ if (picker) {
gsm_color_button_set_fraction(picker, percent);
+ text = total == 0? g_strdup(_("not available")):g_strdup_printf("%.1f%%", 100 * percent);
+ gsm_color_button_set_text(picker, text);
+ g_free (text);
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]