[Xfce4-commits] <xfce4-cpugraph-plugin:master> Fix the Led mode drawing code
Florian
noreply at xfce.org
Sat Apr 17 16:16:31 CEST 2010
Updating branch refs/heads/master
to 3a14e29e4bc658ed32b83ef6e1e605902206bdb4 (commit)
from 67776854c6f200ae41561f1d3d4145c11d108edc (commit)
commit 3a14e29e4bc658ed32b83ef6e1e605902206bdb4
Author: Florian <frivoal at gmail.com>
Date: Tue Mar 2 10:05:46 2010 +0900
Fix the Led mode drawing code
The led drawing mode had 2 bugs. In fire mode, it would crash if the cpu
usage reached 100%, and the colors were miscalculated. Reorganize the
code to be clearer, and the bugs go away amlost by themselves.
panel-plugin/mode.c | 28 +++++++++++-----------------
1 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/panel-plugin/mode.c b/panel-plugin/mode.c
index 811f546..3e1c6cf 100644
--- a/panel-plugin/mode.c
+++ b/panel-plugin/mode.c
@@ -76,35 +76,29 @@ void drawGraphModeNormal( CPUGraph *base, GtkWidget *da, int w, int h )
void drawGraphModeLED( CPUGraph *base, GtkWidget *da, int w, int h )
{
- int nrx = (int)((w + 1) / 3.0);
- int nry = (int)((h + 1) / 2.0);
+ int nrx = (w + 1) / 3;
+ int nry = (h + 1) / 2;
int x, y;
+
GdkGC *fg1 = gdk_gc_new( da->window );
GdkGC *fg2 = gdk_gc_new( da->window );
-
gdk_gc_set_rgb_fg_color( fg1, &base->colors[1] );
gdk_gc_set_rgb_fg_color( fg2, &base->colors[2] );
- for( x = nrx ; x >= 0; x-- )
+ for( x = 0; x * 3 < w; x++ )
{
- int tmp = 0;
int idx = nrx-x;
- int limit = (int)(nry - nry * base->m_History[idx]/CPU_SCALE);
-
- for( y = nry; y >= 0; y-- )
+ int limit = nry - nry * base->m_History[idx]/CPU_SCALE;
+ for( y = 0; y * 2 < h; y++ )
{
- if( base->m_ColorMode > 0 )
+ if( base->m_ColorMode != 0 && y < limit )
{
double t = (base->m_ColorMode == 1) ?
- (tmp / nry) :
- (tmp / limit);
- MixAndApplyColors( t, &base->colors[2], &base->colors[3], fg2);
- tmp++;
+ (y / (double)nry) :
+ (y / (double)limit);
+ MixAndApplyColors( t, &base->colors[3], &base->colors[2], fg2);
}
- gdk_draw_rectangle (da->window,
- (y >= limit) ? fg1 : fg2,
- TRUE, x * 3, y * 2, 2, 1);
-
+ gdk_draw_rectangle (da->window, y >= limit ? fg1 : fg2, TRUE, x * 3, y * 2, 2, 1);
}
}
g_object_unref( fg1 );
More information about the Xfce4-commits
mailing list