Fixed Issue 86.
1.1 --- a/GUI/MainForm.cs Wed Jul 11 22:28:39 2012 +0000
1.2 +++ b/GUI/MainForm.cs Thu Jul 12 10:17:18 2012 +0000
1.3 @@ -121,7 +121,7 @@
1.4
1.5 this.computer = new Computer(settings);
1.6
1.7 - systemTray = new SystemTray(computer, settings);
1.8 + systemTray = new SystemTray(computer, settings, unitManager);
1.9 systemTray.HideShowCommand += hideShowClick;
1.10 systemTray.ExitCommand += exitClick;
1.11
2.1 --- a/GUI/SensorGadget.cs Wed Jul 11 22:28:39 2012 +0000
2.2 +++ b/GUI/SensorGadget.cs Thu Jul 12 10:17:18 2012 +0000
2.3 @@ -581,7 +581,7 @@
2.4 if (sensor.SensorType == SensorType.Temperature &&
2.5 unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit) {
2.6 formatted = string.Format("{0:F1} °F",
2.7 - sensor.Value * 1.8 + 32);
2.8 + UnitManager.CelsiusToFahrenheit(sensor.Value));
2.9 } else {
2.10 formatted = string.Format(format, sensor.Value);
2.11 }
3.1 --- a/GUI/SensorNotifyIcon.cs Wed Jul 11 22:28:39 2012 +0000
3.2 +++ b/GUI/SensorNotifyIcon.cs Thu Jul 12 10:17:18 2012 +0000
3.3 @@ -21,6 +21,8 @@
3.4 namespace OpenHardwareMonitor.GUI {
3.5 public class SensorNotifyIcon : IDisposable {
3.6
3.7 + private UnitManager unitManager;
3.8 +
3.9 private ISensor sensor;
3.10 private NotifyIcon notifyIcon;
3.11 private Bitmap bitmap;
3.12 @@ -31,10 +33,12 @@
3.13 private Brush darkBrush;
3.14 private Pen pen;
3.15 private Font font;
3.16 + private Font smallFont;
3.17
3.18 public SensorNotifyIcon(SystemTray sensorSystemTray, ISensor sensor,
3.19 - bool balloonTip, PersistentSettings settings)
3.20 + bool balloonTip, PersistentSettings settings, UnitManager unitManager)
3.21 {
3.22 + this.unitManager = unitManager;
3.23 this.sensor = sensor;
3.24 this.notifyIcon = new NotifyIcon();
3.25
3.26 @@ -50,6 +54,7 @@
3.27
3.28 this.pen = new Pen(Color.FromArgb(96, Color.Black));
3.29 this.font = SystemFonts.MessageBoxFont;
3.30 + this.smallFont = new Font(font.FontFamily, font.Size * 0.8f);
3.31
3.32 ContextMenu contextMenu = new ContextMenu();
3.33 MenuItem hideShowItem = new MenuItem("Hide/Show");
3.34 @@ -145,7 +150,8 @@
3.35 darkBrush.Dispose();
3.36 pen.Dispose();
3.37 graphics.Dispose();
3.38 - bitmap.Dispose();
3.39 + bitmap.Dispose();
3.40 + smallFont.Dispose();
3.41 }
3.42
3.43 private string GetString() {
3.44 @@ -159,8 +165,12 @@
3.45 return string.Format("{0:F1}", 1e-3f * sensor.Value);
3.46 case SensorType.Load:
3.47 return string.Format("{0:F0}", sensor.Value);
3.48 - case SensorType.Temperature:
3.49 - return string.Format("{0:F0}", sensor.Value);
3.50 + case SensorType.Temperature:
3.51 + if (unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit)
3.52 + return string.Format("{0:F0}",
3.53 + UnitManager.CelsiusToFahrenheit(sensor.Value));
3.54 + else
3.55 + return string.Format("{0:F0}", sensor.Value);
3.56 case SensorType.Fan:
3.57 return string.Format("{0:F1}", 1e-3f * sensor.Value);
3.58 case SensorType.Flow:
3.59 @@ -180,10 +190,16 @@
3.60 }
3.61
3.62 private Icon CreateTransparentIcon() {
3.63 + string text = GetString();
3.64 + int count = 0;
3.65 + for (int i = 0; i < text.Length; i++)
3.66 + if ((text[i] >= '0' && text[i] <= '9') || text[i] == '-')
3.67 + count++;
3.68 + bool small = count > 2;
3.69
3.70 graphics.Clear(Color.Black);
3.71 - TextRenderer.DrawText(graphics, GetString(), font,
3.72 - new Point(-2, 0), Color.White, Color.Black);
3.73 + TextRenderer.DrawText(graphics, text, small ? smallFont : font,
3.74 + new Point(-2, small ? 1 : 0), Color.White, Color.Black);
3.75
3.76 BitmapData data = bitmap.LockBits(
3.77 new Rectangle(0, 0, bitmap.Width, bitmap.Height),
3.78 @@ -267,6 +283,15 @@
3.79 case SensorType.Factor: format = "\n{0}: {1:F3} GB"; break;
3.80 }
3.81 string formattedValue = string.Format(format, sensor.Name, sensor.Value);
3.82 +
3.83 + if (sensor.SensorType == SensorType.Temperature &&
3.84 + unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit)
3.85 + {
3.86 + format = "\n{0}: {1:F1} °F";
3.87 + formattedValue = string.Format(format, sensor.Name,
3.88 + UnitManager.CelsiusToFahrenheit(sensor.Value));
3.89 + }
3.90 +
3.91 string hardwareName = sensor.Hardware.Name;
3.92 hardwareName = hardwareName.Substring(0,
3.93 Math.Min(63 - formattedValue.Length, hardwareName.Length));
4.1 --- a/GUI/SystemTray.cs Wed Jul 11 22:28:39 2012 +0000
4.2 +++ b/GUI/SystemTray.cs Thu Jul 12 10:17:18 2012 +0000
4.3 @@ -4,7 +4,7 @@
4.4 License, v. 2.0. If a copy of the MPL was not distributed with this
4.5 file, You can obtain one at http://mozilla.org/MPL/2.0/.
4.6
4.7 - Copyright (C) 2009-2011 Michael Möller <mmoeller@openhardwaremonitor.org>
4.8 + Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
4.9
4.10 */
4.11
4.12 @@ -20,13 +20,17 @@
4.13 public class SystemTray : IDisposable {
4.14 private IComputer computer;
4.15 private PersistentSettings settings;
4.16 + private UnitManager unitManager;
4.17 private List<SensorNotifyIcon> list = new List<SensorNotifyIcon>();
4.18 private bool mainIconEnabled = false;
4.19 private NotifyIcon mainIcon;
4.20
4.21 - public SystemTray(IComputer computer, PersistentSettings settings) {
4.22 + public SystemTray(IComputer computer, PersistentSettings settings,
4.23 + UnitManager unitManager)
4.24 + {
4.25 this.computer = computer;
4.26 this.settings = settings;
4.27 + this.unitManager = unitManager;
4.28 computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
4.29 computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
4.30
4.31 @@ -103,7 +107,7 @@
4.32 if (Contains(sensor)) {
4.33 return;
4.34 } else {
4.35 - list.Add(new SensorNotifyIcon(this, sensor, balloonTip, settings));
4.36 + list.Add(new SensorNotifyIcon(this, sensor, balloonTip, settings, unitManager));
4.37 UpdateMainIconVisibilty();
4.38 settings.SetValue(new Identifier(sensor.Identifier, "tray").ToString(), true);
4.39 }
5.1 --- a/GUI/UnitManager.cs Wed Jul 11 22:28:39 2012 +0000
5.2 +++ b/GUI/UnitManager.cs Thu Jul 12 10:17:18 2012 +0000
5.3 @@ -4,7 +4,7 @@
5.4 License, v. 2.0. If a copy of the MPL was not distributed with this
5.5 file, You can obtain one at http://mozilla.org/MPL/2.0/.
5.6
5.7 - Copyright (C) 2009-2011 Michael Möller <mmoeller@openhardwaremonitor.org>
5.8 + Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
5.9
5.10 */
5.11
5.12 @@ -36,5 +36,9 @@
5.13 this.settings.SetValue("TemperatureUnit", (int)temperatureUnit);
5.14 }
5.15 }
5.16 +
5.17 + public static float? CelsiusToFahrenheit(float? valueInCelsius) {
5.18 + return valueInCelsius * 1.8f + 32;
5.19 + }
5.20 }
5.21 }