[gnome-system-monitor/wip/newdesign] Refactored a bit to avoid code duplication



commit 69ae8dfca3560dbb4ac47a30c25d75e9b4483e8b
Author: Robert Roth <robert roth off gmail com>
Date:   Fri Aug 16 14:02:11 2013 +0300

    Refactored a bit to avoid code duplication

 src/gsm_color_button.c |   23 ++++++++---------------
 1 files changed, 8 insertions(+), 15 deletions(-)
---
diff --git a/src/gsm_color_button.c b/src/gsm_color_button.c
index 053cb59..4deb10f 100644
--- a/src/gsm_color_button.c
+++ b/src/gsm_color_button.c
@@ -227,19 +227,19 @@ gsm_color_button_draw (GtkWidget *widget, cairo_t * cr)
   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
+    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);
+  } 
   switch (priv->type)
     {
     case GSMCP_TYPE_RECTANGLE:
 
       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,
                            (width - extents.width) / 2,
                            (height - extents.height) / 2,
@@ -256,13 +256,6 @@ gsm_color_button_draw (GtkWidget *widget, cairo_t * cr)
       radius = pie_size / 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,
                            pie_size + 2 * pie_padding + (width - pie_size - 2 * pie_padding- extents.width) 
/ 2,
                            (height - extents.height) / 2,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]