1.1 --- a/GUI/SensorNotifyIcon.cs Wed Jul 11 22:28:39 2012 +0000
1.2 +++ b/GUI/SensorNotifyIcon.cs Thu Jul 12 10:17:18 2012 +0000
1.3 @@ -21,6 +21,8 @@
1.4 namespace OpenHardwareMonitor.GUI {
1.5 public class SensorNotifyIcon : IDisposable {
1.6
1.7 + private UnitManager unitManager;
1.8 +
1.9 private ISensor sensor;
1.10 private NotifyIcon notifyIcon;
1.11 private Bitmap bitmap;
1.12 @@ -31,10 +33,12 @@
1.13 private Brush darkBrush;
1.14 private Pen pen;
1.15 private Font font;
1.16 + private Font smallFont;
1.17
1.18 public SensorNotifyIcon(SystemTray sensorSystemTray, ISensor sensor,
1.19 - bool balloonTip, PersistentSettings settings)
1.20 + bool balloonTip, PersistentSettings settings, UnitManager unitManager)
1.21 {
1.22 + this.unitManager = unitManager;
1.23 this.sensor = sensor;
1.24 this.notifyIcon = new NotifyIcon();
1.25
1.26 @@ -50,6 +54,7 @@
1.27
1.28 this.pen = new Pen(Color.FromArgb(96, Color.Black));
1.29 this.font = SystemFonts.MessageBoxFont;
1.30 + this.smallFont = new Font(font.FontFamily, font.Size * 0.8f);
1.31
1.32 ContextMenu contextMenu = new ContextMenu();
1.33 MenuItem hideShowItem = new MenuItem("Hide/Show");
1.34 @@ -145,7 +150,8 @@
1.35 darkBrush.Dispose();
1.36 pen.Dispose();
1.37 graphics.Dispose();
1.38 - bitmap.Dispose();
1.39 + bitmap.Dispose();
1.40 + smallFont.Dispose();
1.41 }
1.42
1.43 private string GetString() {
1.44 @@ -159,8 +165,12 @@
1.45 return string.Format("{0:F1}", 1e-3f * sensor.Value);
1.46 case SensorType.Load:
1.47 return string.Format("{0:F0}", sensor.Value);
1.48 - case SensorType.Temperature:
1.49 - return string.Format("{0:F0}", sensor.Value);
1.50 + case SensorType.Temperature:
1.51 + if (unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit)
1.52 + return string.Format("{0:F0}",
1.53 + UnitManager.CelsiusToFahrenheit(sensor.Value));
1.54 + else
1.55 + return string.Format("{0:F0}", sensor.Value);
1.56 case SensorType.Fan:
1.57 return string.Format("{0:F1}", 1e-3f * sensor.Value);
1.58 case SensorType.Flow:
1.59 @@ -180,10 +190,16 @@
1.60 }
1.61
1.62 private Icon CreateTransparentIcon() {
1.63 + string text = GetString();
1.64 + int count = 0;
1.65 + for (int i = 0; i < text.Length; i++)
1.66 + if ((text[i] >= '0' && text[i] <= '9') || text[i] == '-')
1.67 + count++;
1.68 + bool small = count > 2;
1.69
1.70 graphics.Clear(Color.Black);
1.71 - TextRenderer.DrawText(graphics, GetString(), font,
1.72 - new Point(-2, 0), Color.White, Color.Black);
1.73 + TextRenderer.DrawText(graphics, text, small ? smallFont : font,
1.74 + new Point(-2, small ? 1 : 0), Color.White, Color.Black);
1.75
1.76 BitmapData data = bitmap.LockBits(
1.77 new Rectangle(0, 0, bitmap.Width, bitmap.Height),
1.78 @@ -267,6 +283,15 @@
1.79 case SensorType.Factor: format = "\n{0}: {1:F3} GB"; break;
1.80 }
1.81 string formattedValue = string.Format(format, sensor.Name, sensor.Value);
1.82 +
1.83 + if (sensor.SensorType == SensorType.Temperature &&
1.84 + unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit)
1.85 + {
1.86 + format = "\n{0}: {1:F1} °F";
1.87 + formattedValue = string.Format(format, sensor.Name,
1.88 + UnitManager.CelsiusToFahrenheit(sensor.Value));
1.89 + }
1.90 +
1.91 string hardwareName = sensor.Hardware.Name;
1.92 hardwareName = hardwareName.Substring(0,
1.93 Math.Min(63 - formattedValue.Length, hardwareName.Length));