[Xfce4-commits] <xfce4-cpugraph-plugin:master> Bring back the grid display mode

Florian noreply at xfce.org
Sat Apr 17 16:16:18 CEST 2010


Updating branch refs/heads/master
         to c510e63ae71e5733c9fedf21c263fc4ac485e60b (commit)
       from c9a5adb1a56c852c41695110d596f7557100e1a0 (commit)

commit c510e63ae71e5733c9fedf21c263fc4ac485e60b
Author: Florian <frivoal at gmail.com>
Date:   Mon Feb 22 22:01:47 2010 +0900

    Bring back the grid display mode
    
    The grid display mode had been lost in some of the changes made
    imediately after the release of 0.4.0. Bring it back.

 panel-plugin/cpu.c        |    4 ++++
 panel-plugin/mode.c       |   38 ++++++++++++++++++++++++++++++++++++++
 panel-plugin/mode.h       |    1 +
 panel-plugin/properties.c |    3 ++-
 4 files changed, 45 insertions(+), 1 deletions(-)

diff --git a/panel-plugin/cpu.c b/panel-plugin/cpu.c
index eb81b84..e1e0e4b 100644
--- a/panel-plugin/cpu.c
+++ b/panel-plugin/cpu.c
@@ -265,6 +265,10 @@ void DrawGraph( CPUGraph * base )
 	{
 		drawGraphModeNoHistory( base, fg1, fg2, da, w, h );
 	}
+	else if( base->m_Mode == 3 )
+	{
+		drawGraphGrid(base, fg1, fg2, da, w, h);
+	}
 
 	g_object_unref( fg2 );
 	g_object_unref( fg1 );
diff --git a/panel-plugin/mode.c b/panel-plugin/mode.c
index 884778b..dc34b20 100644
--- a/panel-plugin/mode.c
+++ b/panel-plugin/mode.c
@@ -143,3 +143,41 @@ void drawGraphModeNoHistory( CPUGraph *base, GdkGC *fg1, GdkGC *fg2, GtkWidget *
 				0, y, w, y);
 	}
 }
+
+typedef struct
+{
+	long x;
+	long y;
+} point;
+
+void drawGraphGrid( CPUGraph *base, GdkGC *fg1, GdkGC *fg2, GtkWidget *da, int w, int h )
+{
+	int nrx = w / 6.0;
+	int nry = h / 4.0;
+	int x, y;
+
+	point last, current;
+	last.x = -1;
+
+	/* draw grid */
+	gdk_gc_set_rgb_fg_color( fg1, &base->m_ForeGround1 );
+	for( x = nrx; x >= 0; x-- )
+	{
+		gdk_draw_line( da->window, fg1, x*6, 0, x*6, h );
+	}
+	for( y = nry; y>=0; y-- )
+	{
+		gdk_draw_line( da->window, fg1, 0, y*4, w, y*4 );
+	}
+
+	/* draw data */
+	gdk_gc_set_rgb_fg_color( fg2, &base->m_ForeGround2 );
+	for( x = w; x >= 0; x-- )
+	{
+		current.x = x;
+		current.y = ((h - 1)*(CPU_SCALE - base->m_History[w - x]))/CPU_SCALE;
+		if( last.x == -1 ) last = current;
+		gdk_draw_line( da->window, fg2, current.x, current.y, last.x, last.y );
+		last = current;
+	}
+}
diff --git a/panel-plugin/mode.h b/panel-plugin/mode.h
index 74ce871..7a38b31 100644
--- a/panel-plugin/mode.h
+++ b/panel-plugin/mode.h
@@ -6,5 +6,6 @@
 void drawGraphModeNormal( CPUGraph *base, GdkGC *fg1, GtkWidget *da, int w, int h );
 void drawGraphModeLED( CPUGraph *base, GdkGC *fg1, GdkGC *fg2, GtkWidget *da, int w, int h );
 void drawGraphModeNoHistory( CPUGraph *base, GdkGC *fg1, GdkGC *fg2, GtkWidget *da, int w, int h );
+void drawGraphGrid( CPUGraph *base, GdkGC *fg1, GdkGC *fg2, GtkWidget *da, int w, int h );
 
 #endif
diff --git a/panel-plugin/properties.c b/panel-plugin/properties.c
index 014100f..b3c6cfd 100644
--- a/panel-plugin/properties.c
+++ b/panel-plugin/properties.c
@@ -293,7 +293,8 @@ static void SetupModesOption( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base )
 {
 	const char *items[] = { _("Normal"),
 	                        _("LED"),
-	                        _("No history")
+	                        _("No history"),
+				_("Grid")
 	                      };
 	size_t nb_items = sizeof( items ) / sizeof( char* );
 



More information about the Xfce4-commits mailing list