public void DrawLoad() { CpuCounter cur = new CpuCounter(); cur.FetchGlobalCounters(); CpuCounter delta = cur.Sub(ref last); last = cur; double num = Math.Round(delta.CpuLoad()); load.Text = ((int)num).ToString(); Color current = (circle.Fill as SolidColorBrush).Color; Color color = new Color(); if (num <= 50) { //interpolate (0,50) between green (0,255,0) and yellow (255,255,0) double red = num / (50d / 255); color = Color.FromArgb(255, (byte)red, 255, 0); } else { //interpolate (50,100) between yellow (255,255,0) and red (255,0,0) double green = (100d - num) / (50d / 255); color = Color.FromArgb(255, 255, (byte)green, 0); } colorAnim.From = current; colorAnim.To = color; colorSb.Begin(); }
public void DrawLoad () { CpuCounter cur = new CpuCounter (); cur.FetchGlobalCounters (); CpuCounter delta = cur.Sub (ref last); last = cur; double num = Math.Round (delta.CpuLoad ()); load.Text = ((int)num).ToString (); Color current = (circle.Fill as SolidColorBrush).Color; Color color = new Color (); if (num <= 50) { //interpolate (0,50) between green (0,255,0) and yellow (255,255,0) double red = num / (50d / 255); color = Color.FromArgb (255, (byte)red, 255, 0); } else { //interpolate (50,100) between yellow (255,255,0) and red (255,0,0) double green = (100d - num) / (50d / 255); color = Color.FromArgb (255, 255, (byte)green, 0); } colorAnim.From = current; colorAnim.To = color; colorSb.Begin (); }
public CpuCounter Sub (ref CpuCounter other) { CpuCounter res = this; res.user -= other.user; res.nice -= other.nice; res.system -= other.system; res.idle -= other.idle; res.iowait -= other.iowait; res.irq -= other.irq; res.softirq -= other.softirq; res.steal -= other.steal; res.total -= other.total; return res; }
public CpuCounter Sub(ref CpuCounter other) { CpuCounter res = this; res.user -= other.user; res.nice -= other.nice; res.system -= other.system; res.idle -= other.idle; res.iowait -= other.iowait; res.irq -= other.irq; res.softirq -= other.softirq; res.steal -= other.steal; res.total -= other.total; return(res); }
public void PageLoaded(object o, EventArgs e) { Moonlight.Gtk.Desklet.SetupToolbox(this); closeButton = FindName("desklet-close") as Polygon; closeButton.MouseEnter += delegate { HighlightButton(closeButton); }; closeButton.MouseLeave += delegate { UnhighlightButton(closeButton); }; circle = FindName("Circle") as Shape; load = FindName("Load") as TextBlock; colorSb = FindName("color_sb") as Storyboard; colorAnim = FindName("color_anim") as ColorAnimation; last = new CpuCounter(); if (circle == null) { Console.WriteLine("no circle =" + (FindName("Circle") != null)); } Storyboard sb = FindName("run") as Storyboard; DoubleAnimation timer = new DoubleAnimation(); sb.Children.Add(timer); timer.Duration = new Duration(TimeSpan.FromMilliseconds(100)); sb.Completed += delegate { DrawLoad(); sb.Begin(); }; sb.Begin(); DrawLoad(); }
public void PageLoaded (object o, EventArgs e) { Moonlight.Gtk.Desklet.SetupToolbox (this); closeButton = FindName ("desklet-close") as Polygon; closeButton.MouseEnter += delegate { HighlightButton (closeButton); }; closeButton.MouseLeave += delegate { UnhighlightButton (closeButton); }; circle = FindName ("Circle") as Shape; load = FindName ("Load") as TextBlock; colorSb = FindName ("color_sb") as Storyboard; colorAnim = FindName ("color_anim") as ColorAnimation; last = new CpuCounter (); if (circle == null) Console.WriteLine ("no circle ="+(FindName ("Circle") != null)); Storyboard sb = FindName ("run") as Storyboard; DoubleAnimation timer = new DoubleAnimation (); sb.Children.Add (timer); timer.Duration = new Duration (TimeSpan.FromMilliseconds (100)); sb.Completed += delegate { DrawLoad (); sb.Begin (); }; sb.Begin (); DrawLoad (); }