Commit 2b04cce3 authored by Benoît Dejean's avatar Benoît Dejean

Patch by Karl Lattimer, new developer.

Summary of changes
 * Changed the graph to draw using black and white and theme colours
 * Created a simple dash for all graph lines
 * Changed the font and font size and rejiggered the calculation of num_bars
 * Set the text alignment to right 
 * Added 7 vertical lines between the graph edges
 * set the minimum height to 80px, more space can be regained later on by
re-widgeting the colour pickers. 
 * Removed references to the old background/foreground colour definitions and
re-aligned the colour array
 * Added myself to the authors (at the request of Benoit))

svn path=/trunk/; revision=2205
parent 449e9301
......@@ -3,4 +3,5 @@ Erik Johnsson <zaphod@linux.nu> - icon support
Jorgen Scheibengruber
Benoît Dejean <benoit@placenet.org> - maintainer
Paolo Borelli <pborelli@katamail.com>
Baptiste Mille-Mathias - artwork
\ No newline at end of file
Baptiste Mille-Mathias - artwork
Karl Lattimer <karl@qdh.org.uk>
......@@ -136,6 +136,7 @@ cb_about (GtkAction *action, gpointer data)
"Jorgen Scheibengruber",
"Benoît Dejean",
"Paolo Borelli",
"Karl Lattimer",
NULL
};
......
......@@ -290,7 +290,7 @@ create_sys_view (ProcData *procdata)
G_CALLBACK(size_request), &cpu_size);
color_picker = gtk_color_button_new_with_color (
&load_graph_get_colors(cpu_graph)[2+i]);
&load_graph_get_colors(cpu_graph)[i]);
g_signal_connect (G_OBJECT (color_picker), "color_set",
G_CALLBACK (cb_cpu_color_changed), GINT_TO_POINTER (i));
......@@ -347,7 +347,7 @@ create_sys_view (ProcData *procdata)
FALSE, FALSE, 0);
color_picker = gtk_color_button_new_with_color (
&load_graph_get_colors(mem_graph)[2]);
&load_graph_get_colors(mem_graph)[0]);
g_signal_connect (G_OBJECT (color_picker), "color_set",
G_CALLBACK (cb_mem_color_changed), procdata);
gtk_table_attach (GTK_TABLE (table), color_picker, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
......@@ -406,7 +406,7 @@ create_sys_view (ProcData *procdata)
0);
color_picker = gtk_color_button_new_with_color (
&load_graph_get_colors(mem_graph)[3]);
&load_graph_get_colors(mem_graph)[1]);
g_signal_connect (G_OBJECT (color_picker), "color_set",
G_CALLBACK (cb_swap_color_changed), procdata);
gtk_table_attach (GTK_TABLE (table), color_picker, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
......@@ -496,7 +496,7 @@ create_sys_view (ProcData *procdata)
FALSE, FALSE, 0);
color_picker = gtk_color_button_new_with_color (
&load_graph_get_colors(net_graph)[2]);
&load_graph_get_colors(net_graph)[0]);
g_signal_connect (G_OBJECT (color_picker), "color_set",
G_CALLBACK (cb_net_in_color_changed), procdata);
gtk_table_attach (GTK_TABLE (table), color_picker, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
......@@ -540,7 +540,7 @@ create_sys_view (ProcData *procdata)
0);
color_picker = gtk_color_button_new_with_color (
&load_graph_get_colors(net_graph)[3]);
&load_graph_get_colors(net_graph)[1]);
g_signal_connect (G_OBJECT (color_picker), "color_set",
G_CALLBACK (cb_net_out_color_changed), procdata);
gtk_table_attach (GTK_TABLE (table), color_picker, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
......
......@@ -19,6 +19,7 @@
#include <glibtop/swap.h>
#include <glibtop/netload.h>
#include <glibtop/netlist.h>
#include <math.h>
#include <libgnomevfs/gnome-vfs-utils.h>
......@@ -29,7 +30,7 @@
#include "util.h"
#define NUM_POINTS 100
#define GRAPH_MIN_HEIGHT 30
#define GRAPH_MIN_HEIGHT 80
enum {
......@@ -89,33 +90,20 @@ struct _LoadGraph {
void
load_graph_draw (LoadGraph *g)
{
const double fontsize = 12.0;
const double fontsize = 8.0;
const double rmargin = 3.5 * fontsize;
const double indent = 8.0;
double dash[2] = { 1.0, 2.0 };
cairo_t *cr;
int dely;
double delx;
int real_draw_height;
guint i, j;
unsigned num_bars;
cr = cairo_create (g->buffer);
/* clear */
gdk_cairo_set_source_color (cr, &(g->colors [0]));
cairo_paint (cr);
/* draw frame */
cairo_translate (cr, FRAME_WIDTH, FRAME_WIDTH);
gdk_cairo_set_source_color (cr, &(g->colors [1]));
cairo_set_line_width (cr, 1.0);
cairo_select_font_face(cr,
"monospace",
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cr, fontsize);
GtkWidget *notebook;
// keep 100 % num_bars == 0
switch (static_cast<int>(g->draw_height / (fontsize + 3)))
switch (static_cast<int>(g->draw_height / (fontsize + 14)))
{
case 1:
num_bars = 1;
......@@ -134,9 +122,49 @@ load_graph_draw (LoadGraph *g)
dely = g->draw_height / num_bars; /* round to int to avoid AA blur */
real_draw_height = dely * num_bars;
/* GtkStyle gives us the theme background color, this should be in
* load_graph_new but something causes load_graph_new to use the
* default GTK color scheme rather than the current theme color
* we also have to trawl through parent widgets to get to gtknotebook
* *sigh*
*/
notebook = g->main_widget;
while (g_ascii_strncasecmp(gtk_widget_get_name(notebook),
"GtkNotebook", 12)) {
notebook = gtk_widget_get_parent(notebook);
if (notebook == NULL) {
// Fall back to using the main_widget for styles
notebook = g->main_widget;
break;
}
}
GtkStyle *style = gtk_widget_get_style(notebook);
cr = cairo_create (g->buffer);
/* clear */
gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]);
cairo_paint (cr);
/* draw frame */
cairo_translate (cr, FRAME_WIDTH, FRAME_WIDTH);
/* Draw background rectangle */
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
cairo_rectangle (cr, rmargin + indent, 0,
g->draw_width - rmargin - indent, real_draw_height);
cairo_fill(cr);
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_set_line_width (cr, 1.0);
cairo_set_dash(cr, dash, 2, 0);
cairo_set_font_size(cr, fontsize);
for (i = 0; i <= num_bars; ++i) {
char *caption;
double y;
cairo_text_extents_t extents;
if (i == 0)
y = 0.5 + fontsize / 2.0;
......@@ -145,35 +173,47 @@ load_graph_draw (LoadGraph *g)
else
y = i * dely + fontsize / 2.0;
cairo_move_to(cr, 0.0, y);
caption = g_strdup_printf("%3d %%", 100 - i * (100 / num_bars));
cairo_text_extents (cr, caption, &extents);
cairo_move_to(cr, indent - extents.width / 2, y);
cairo_show_text(cr, caption);
g_free(caption);
cairo_move_to (cr, rmargin, i * dely + 0.5);
cairo_line_to (cr, g->draw_width - 0.5, i * dely + 0.5);
}
cairo_stroke (cr);
cairo_move_to (cr, rmargin, 0.5);
cairo_line_to (cr, rmargin, real_draw_height + 0.5);
cairo_set_dash(cr, dash, 2, 1.5);
for (unsigned i = 0; i < 7; i++) {
double x = (i + 1) * (g->draw_width - rmargin + indent) / 8;
cairo_move_to (cr, (ceil(x) + 0.5) + rmargin + indent, 0.5);
cairo_line_to (cr, (ceil(x) + 0.5) + rmargin + indent, real_draw_height + 0.5);
}
cairo_move_to (cr, rmargin + indent + 0.5, 0.5);
cairo_line_to (cr, rmargin + indent + 0.5, real_draw_height + 0.5);
cairo_move_to (cr, g->draw_width - 0.5, 0.5);
cairo_line_to (cr, g->draw_width - 0.5, real_draw_height + 0.5);
cairo_stroke (cr);
cairo_set_dash(cr, NULL, 0, 0);
/* draw the graph */
cairo_set_line_width (cr, 2.0);
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
delx = (g->draw_width - 2.0 - rmargin) / (NUM_POINTS - 1);
delx = (g->draw_width - 2.0 - rmargin - indent) / (NUM_POINTS - 1);
for (j = 0; j < g->n; ++j) {
cairo_move_to (cr,
g->draw_width - 2.0,
(1.0f - g->data[0][j]) * real_draw_height);
gdk_cairo_set_source_color (cr, &(g->colors [j + 2]));
gdk_cairo_set_source_color (cr, &(g->colors [j]));
for (i = 1; i < NUM_POINTS; ++i) {
if (g->data[i][j] == -1.0f)
......@@ -599,22 +639,20 @@ load_graph_new (gint type, ProcData *procdata)
g->speed = procdata->config.graph_update_interval;
g->colors = g_new0 (GdkColor, g->n + 2);
g->colors = g_new0 (GdkColor, g->n);
g->colors[0] = procdata->config.bg_color;
g->colors[1] = procdata->config.frame_color;
switch (type) {
case LOAD_GRAPH_CPU:
memcpy(g->colors + 2, procdata->config.cpu_color,
memcpy(g->colors, procdata->config.cpu_color,
g->n * sizeof g->colors[0]);
break;
case LOAD_GRAPH_MEM:
g->colors[2] = procdata->config.mem_color;
g->colors[3] = procdata->config.swap_color;
g->colors[0] = procdata->config.mem_color;
g->colors[1] = procdata->config.swap_color;
break;
case LOAD_GRAPH_NET:
g->colors[2] = procdata->config.net_in_color;
g->colors[3] = procdata->config.net_out_color;
g->colors[0] = procdata->config.net_in_color;
g->colors[1] = procdata->config.net_out_color;
break;
}
......
......@@ -476,12 +476,10 @@ procdialog_create_preferences_dialog (ProcData *procdata)
GtkWidget *spin_button;
GtkWidget *check_button;
GtkWidget *tab_label;
GtkWidget *color_picker;
GtkWidget *smooth_button;
GtkSizeGroup *size;
gfloat update;
gchar *tmp;
GdkColor color;
if (prefs_dialog)
return;
......@@ -674,42 +672,6 @@ procdialog_create_preferences_dialog (ProcData *procdata)
hbox2 = gtk_hbox_new (FALSE, 12);
gtk_box_pack_start (GTK_BOX (vbox2), hbox2, TRUE, TRUE, 0);
label = gtk_label_new_with_mnemonic (_("_Background color:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
gtk_size_group_add_widget (size, label);
color.red = procdata->config.bg_color.red;
color.green = procdata->config.bg_color.green;
color.blue = procdata->config.bg_color.blue;
color_picker = gtk_color_button_new_with_color (&color);
g_signal_connect (G_OBJECT (color_picker), "color_set",
G_CALLBACK (cb_bg_color_changed), procdata);
gtk_box_pack_start (GTK_BOX (hbox2), color_picker, FALSE, FALSE, 0);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), color_picker);
gtk_widget_show (color_picker);
hbox2 = gtk_hbox_new (FALSE, 12);
gtk_box_pack_start (GTK_BOX (vbox2), hbox2, TRUE, TRUE, 0);
label = gtk_label_new_with_mnemonic (_("_Grid color:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_box_pack_start (GTK_BOX (hbox2), label, FALSE, FALSE, 0);
gtk_size_group_add_widget (size, label);
color.red = procdata->config.frame_color.red;
color.green = procdata->config.frame_color.green;
color.blue = procdata->config.frame_color.blue;
color_picker = gtk_color_button_new_with_color (&color);
g_signal_connect (G_OBJECT (color_picker), "color_set",
G_CALLBACK (cb_frame_color_changed), procdata);
gtk_box_pack_start (GTK_BOX (hbox2), color_picker, FALSE, FALSE, 0);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), color_picker);
gtk_widget_show (color_picker);
/*
* Devices
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment