[gnome-system-monitor/wip/newdesign] Glued in the CPU color pickers with the CPU usage percentage instead of the labels



commit 595c477aa50139eae23a8856ab270ea4f964fcde
Author: Robert Roth <robert roth off gmail com>
Date:   Mon Aug 12 23:55:43 2013 +0300

    Glued in the CPU color pickers with the CPU usage percentage instead of the labels

 data/interface.ui      |    5 +++--
 src/gsm_color_button.c |   16 ++++++++--------
 src/interface.cpp      |   31 +++++++++++++++----------------
 src/load-graph.cpp     |   23 ++++++++++++-----------
 src/load-graph.h       |    4 ++++
 5 files changed, 42 insertions(+), 37 deletions(-)
---
diff --git a/data/interface.ui b/data/interface.ui
index 7926c7b..20996a8 100644
--- a/data/interface.ui
+++ b/data/interface.ui
@@ -207,6 +207,7 @@
                     <child type="label">
                       <object class="GtkBox" id="cpu_label_box">
                         <property name="visible">True</property>
+                        <property name="margin_right">56</property>
                         <property name="can_focus">False</property>
                         <property name="orientation">horizontal</property>
                         <child>
@@ -229,8 +230,8 @@
                           <object class="GtkGrid" id="cpu_table">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
-                            <property name="hexpand">True</property>
                             <property name="row_spacing">6</property>
+                            <property name="column_spacing">6</property>
                             <property name="row_homogeneous">True</property>
                             <property name="column_homogeneous">True</property>
                             <child>
@@ -262,7 +263,7 @@
                             </child>
                           </object>
                           <packing>
-                            <property name="expand">True</property>
+                            <property name="expand">False</property>
                             <property name="fill">True</property>
                             <property name="pack_type">end</property>
                             <property name="position">1</property>
diff --git a/src/gsm_color_button.c b/src/gsm_color_button.c
index 21e0481..e042c9e 100644
--- a/src/gsm_color_button.c
+++ b/src/gsm_color_button.c
@@ -265,23 +265,23 @@ gsm_color_button_draw (GtkWidget *widget, cairo_t * cr)
       pango_font_description_set_size (font_desc, 10 * PANGO_SCALE );
       pango_layout_set_font_description (layout, font_desc);
       pango_font_description_free (font_desc);
-      pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
-      caption = g_strdup_printf ("%.1f%%", priv->fraction * 100);
+      pango_layout_set_alignment (layout, PANGO_ALIGN_RIGHT);
+      caption = g_strdup_printf ("%.1f%%", priv->fraction * 100.0f);
       pango_layout_set_text (layout, caption, -1);
       g_free (caption);
       pango_layout_get_extents (layout, NULL, &extents);
       //printf ("%f from %d\n", 1.0 * extents.height / PANGO_SCALE, width);
       
-      cairo_move_to (cr, (width - 1.0 * extents.width / PANGO_SCALE)/2 +0.5 ,
-                     0);
+      cairo_move_to (cr, (width - 1.3 * extents.width / PANGO_SCALE)/2 + 5.1 ,
+                     (height - 1.3 * extents.height / PANGO_SCALE)/2 + 2);
       
-      cairo_set_line_width (cr, 2.5);
-      cairo_set_source_rgba (cr, 0.3, 0.3, 0.3, 1.0);
+      cairo_set_line_width (cr, 4);
+      cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 1.0);
       pango_cairo_layout_path (cr, layout);
       cairo_stroke (cr);
       
-      cairo_move_to (cr, (width - 1.0 * extents.width / PANGO_SCALE)/2,
-                     0);
+      cairo_move_to (cr, (width - 1.3 * extents.width / PANGO_SCALE)/2 + 4.7,
+                     (height - 1.3 * extents.height / PANGO_SCALE)/2 + 2);
       cairo_set_line_width (cr, 1);
       cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 1.0);
       
diff --git a/src/interface.cpp b/src/interface.cpp
index 67eb03e..b7c6af5 100644
--- a/src/interface.cpp
+++ b/src/interface.cpp
@@ -179,7 +179,7 @@ create_sys_view (GsmApplication *app, GtkBuilder * builder)
 {
     GtkWidget *cpu_graph_box, *mem_graph_box, *net_graph_box;
     GtkWidget *cpu_exp, *mem_exp, *net_exp;
-    GtkWidget *label,*cpu_label;
+    GtkWidget *label;
     GtkWidget *table;
     GtkWidget *color_picker;
     GtkWidget *picker_alignment;
@@ -218,30 +218,29 @@ create_sys_view (GsmApplication *app, GtkBuilder * builder)
             gtk_grid_insert_row(GTK_GRID(cpu_table), (i+1)/cols);
         }
         gtk_grid_attach(GTK_GRID (cpu_table), temp_hbox, i%cols, i/cols, 1, 1);
-        color_picker = gsm_color_button_new (&cpu_graph->colors.at(i), GSMCP_TYPE_CPU);
-        g_signal_connect (G_OBJECT (color_picker), "color-set",
-                          G_CALLBACK (cb_cpu_color_changed), GINT_TO_POINTER (i));
-        gtk_box_pack_start (GTK_BOX (temp_hbox), color_picker, FALSE, TRUE, 0);
-        gtk_widget_set_size_request(GTK_WIDGET(color_picker), 60, -1);
+        
         if(app->config.num_cpus == 1) {
             label_text = g_strdup (_("CPU"));
         } else {
             label_text = g_strdup_printf (_("CPU%d"), i+1);
         }
-        title_text = g_strdup_printf(title_template, label_text);
+        
         label = gtk_label_new (label_text);
-        gsm_color_button_set_title(GSM_COLOR_BUTTON(color_picker), title_text);
-        g_free(title_text);
         gtk_box_pack_start (GTK_BOX (temp_hbox), label, FALSE, FALSE, 6);
         gtk_widget_show (label);
         g_free (label_text);
-
-        cpu_label = gtk_label_new (NULL);
-
-        gtk_misc_set_alignment (GTK_MISC (cpu_label), 0.0, 0.5);
-        gtk_box_pack_start (GTK_BOX (temp_hbox), cpu_label, FALSE, FALSE, 0);
-        gtk_widget_show (cpu_label);
-        load_graph_get_labels(cpu_graph)->cpu[i] = cpu_label;
+        
+        color_picker = load_graph_get_cpu_color_picker (cpu_graph, i);
+        
+        title_text = g_strdup_printf(title_template, label_text);
+        gsm_color_button_set_title(GSM_COLOR_BUTTON(color_picker), title_text);
+        g_free(title_text);
+        
+        g_signal_connect (G_OBJECT (color_picker), "color-set",
+                          G_CALLBACK (cb_cpu_color_changed), GINT_TO_POINTER (i));
+        gtk_box_pack_start (GTK_BOX (temp_hbox), color_picker, FALSE, TRUE, 0);
+        gtk_widget_set_size_request(GTK_WIDGET(color_picker), 80, 20);
+        
 
     }
 
diff --git a/src/load-graph.cpp b/src/load-graph.cpp
index 2ed2004..57c4683 100644
--- a/src/load-graph.cpp
+++ b/src/load-graph.cpp
@@ -327,7 +327,6 @@ get_load (LoadGraph *graph)
     for (i = 0; i < graph->n; i++) {
         float load;
         float total, used;
-        gchar *text;
 
         total = NOW[i][CPU_TOTAL] - LAST[i][CPU_TOTAL];
         used  = NOW[i][CPU_USED]  - LAST[i][CPU_USED];
@@ -341,10 +340,7 @@ get_load (LoadGraph *graph)
             }
         }
 
-        /* Update label */
-        text = g_strdup_printf("%.1f%%", load * 100.0f);
-        gtk_label_set_text(GTK_LABEL(graph->labels.cpu[i]), text);
-        g_free(text);
+        gsm_color_button_set_fraction (GSM_COLOR_BUTTON (load_graph_get_cpu_color_picker (graph, i)), load);
     }
 
     graph->cpu.now ^= 1;
@@ -703,7 +699,8 @@ LoadGraph::LoadGraph(guint type)
       timer_index(0),
       draw(FALSE),
       mem_color_picker(NULL),
-      swap_color_picker(NULL)
+      swap_color_picker(NULL),
+      cpu_color_pickers(NULL)
 {
     LoadGraph * const graph = this;
 
@@ -716,11 +713,6 @@ LoadGraph::LoadGraph(guint type)
             memset(&cpu, 0, sizeof cpu);
             n = GsmApplication::get()->config.num_cpus;
 
-            for(guint i = 0; i < G_N_ELEMENTS(labels.cpu); ++i) {
-                labels.cpu[i] = gtk_label_new(NULL);
-                gtk_label_set_width_chars (GTK_LABEL (labels.cpu[i]), 12);
-            }
-
             break;
 
         case LOAD_GRAPH_MEM:
@@ -768,6 +760,9 @@ LoadGraph::LoadGraph(guint type)
         case LOAD_GRAPH_CPU:
             memcpy(&colors[0], GsmApplication::get()->config.cpu_color,
                    n * sizeof colors[0]);
+            for(guint i = 0; i < G_N_ELEMENTS(labels.cpu); ++i) {
+                cpu_color_pickers = g_list_append (cpu_color_pickers, GTK_WIDGET (gsm_color_button_new 
(&colors[i], GSMCP_TYPE_CPU)));
+            }
             break;
         case LOAD_GRAPH_MEM:
             colors[0] = GsmApplication::get()->config.mem_color;
@@ -881,3 +876,9 @@ load_graph_get_swap_color_picker(LoadGraph *graph)
 {
     return graph->swap_color_picker;
 }
+
+GtkWidget*
+load_graph_get_cpu_color_picker(LoadGraph *graph, guint nr)
+{
+    return GTK_WIDGET (g_list_nth_data (graph->cpu_color_pickers, nr));
+}
diff --git a/src/load-graph.h b/src/load-graph.h
index 7d09f33..8273eb1 100644
--- a/src/load-graph.h
+++ b/src/load-graph.h
@@ -73,6 +73,7 @@ struct LoadGraph
     LoadGraphLabels labels;
     GtkWidget *mem_color_picker;
     GtkWidget *swap_color_picker;
+    GList * cpu_color_pickers;
 
     /* union { */
     struct
@@ -127,4 +128,7 @@ load_graph_get_mem_color_picker(LoadGraph *g) G_GNUC_CONST;
 GtkWidget*
 load_graph_get_swap_color_picker(LoadGraph *g) G_GNUC_CONST;
 
+GtkWidget*
+load_graph_get_cpu_color_picker(LoadGraph *g, guint nr) G_GNUC_CONST;
+
 #endif /* _GSM_LOAD_GRAPH_H_ */


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