# HG changeset patch # User moel.mich # Date 1342088238 0 # Node ID 1dfe9dac1651fdc5dfad9d7fe44e8c8326905958 # Parent 0a386ef7d5bb7b91850477fffaf7a46048cfbe9a Fixed Issue 86. diff -r 0a386ef7d5bb -r 1dfe9dac1651 GUI/MainForm.cs --- a/GUI/MainForm.cs Wed Jul 11 22:28:39 2012 +0000 +++ b/GUI/MainForm.cs Thu Jul 12 10:17:18 2012 +0000 @@ -121,7 +121,7 @@ this.computer = new Computer(settings); - systemTray = new SystemTray(computer, settings); + systemTray = new SystemTray(computer, settings, unitManager); systemTray.HideShowCommand += hideShowClick; systemTray.ExitCommand += exitClick; diff -r 0a386ef7d5bb -r 1dfe9dac1651 GUI/SensorGadget.cs --- a/GUI/SensorGadget.cs Wed Jul 11 22:28:39 2012 +0000 +++ b/GUI/SensorGadget.cs Thu Jul 12 10:17:18 2012 +0000 @@ -581,7 +581,7 @@ if (sensor.SensorType == SensorType.Temperature && unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit) { formatted = string.Format("{0:F1} °F", - sensor.Value * 1.8 + 32); + UnitManager.CelsiusToFahrenheit(sensor.Value)); } else { formatted = string.Format(format, sensor.Value); } diff -r 0a386ef7d5bb -r 1dfe9dac1651 GUI/SensorNotifyIcon.cs --- a/GUI/SensorNotifyIcon.cs Wed Jul 11 22:28:39 2012 +0000 +++ b/GUI/SensorNotifyIcon.cs Thu Jul 12 10:17:18 2012 +0000 @@ -21,6 +21,8 @@ namespace OpenHardwareMonitor.GUI { public class SensorNotifyIcon : IDisposable { + private UnitManager unitManager; + private ISensor sensor; private NotifyIcon notifyIcon; private Bitmap bitmap; @@ -31,10 +33,12 @@ private Brush darkBrush; private Pen pen; private Font font; + private Font smallFont; public SensorNotifyIcon(SystemTray sensorSystemTray, ISensor sensor, - bool balloonTip, PersistentSettings settings) + bool balloonTip, PersistentSettings settings, UnitManager unitManager) { + this.unitManager = unitManager; this.sensor = sensor; this.notifyIcon = new NotifyIcon(); @@ -50,6 +54,7 @@ this.pen = new Pen(Color.FromArgb(96, Color.Black)); this.font = SystemFonts.MessageBoxFont; + this.smallFont = new Font(font.FontFamily, font.Size * 0.8f); ContextMenu contextMenu = new ContextMenu(); MenuItem hideShowItem = new MenuItem("Hide/Show"); @@ -145,7 +150,8 @@ darkBrush.Dispose(); pen.Dispose(); graphics.Dispose(); - bitmap.Dispose(); + bitmap.Dispose(); + smallFont.Dispose(); } private string GetString() { @@ -159,8 +165,12 @@ return string.Format("{0:F1}", 1e-3f * sensor.Value); case SensorType.Load: return string.Format("{0:F0}", sensor.Value); - case SensorType.Temperature: - return string.Format("{0:F0}", sensor.Value); + case SensorType.Temperature: + if (unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit) + return string.Format("{0:F0}", + UnitManager.CelsiusToFahrenheit(sensor.Value)); + else + return string.Format("{0:F0}", sensor.Value); case SensorType.Fan: return string.Format("{0:F1}", 1e-3f * sensor.Value); case SensorType.Flow: @@ -180,10 +190,16 @@ } private Icon CreateTransparentIcon() { + string text = GetString(); + int count = 0; + for (int i = 0; i < text.Length; i++) + if ((text[i] >= '0' && text[i] <= '9') || text[i] == '-') + count++; + bool small = count > 2; graphics.Clear(Color.Black); - TextRenderer.DrawText(graphics, GetString(), font, - new Point(-2, 0), Color.White, Color.Black); + TextRenderer.DrawText(graphics, text, small ? smallFont : font, + new Point(-2, small ? 1 : 0), Color.White, Color.Black); BitmapData data = bitmap.LockBits( new Rectangle(0, 0, bitmap.Width, bitmap.Height), @@ -267,6 +283,15 @@ case SensorType.Factor: format = "\n{0}: {1:F3} GB"; break; } string formattedValue = string.Format(format, sensor.Name, sensor.Value); + + if (sensor.SensorType == SensorType.Temperature && + unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit) + { + format = "\n{0}: {1:F1} °F"; + formattedValue = string.Format(format, sensor.Name, + UnitManager.CelsiusToFahrenheit(sensor.Value)); + } + string hardwareName = sensor.Hardware.Name; hardwareName = hardwareName.Substring(0, Math.Min(63 - formattedValue.Length, hardwareName.Length)); diff -r 0a386ef7d5bb -r 1dfe9dac1651 GUI/SystemTray.cs --- a/GUI/SystemTray.cs Wed Jul 11 22:28:39 2012 +0000 +++ b/GUI/SystemTray.cs Thu Jul 12 10:17:18 2012 +0000 @@ -4,7 +4,7 @@ License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - Copyright (C) 2009-2011 Michael Möller + Copyright (C) 2009-2012 Michael Möller */ @@ -20,13 +20,17 @@ public class SystemTray : IDisposable { private IComputer computer; private PersistentSettings settings; + private UnitManager unitManager; private List list = new List(); private bool mainIconEnabled = false; private NotifyIcon mainIcon; - public SystemTray(IComputer computer, PersistentSettings settings) { + public SystemTray(IComputer computer, PersistentSettings settings, + UnitManager unitManager) + { this.computer = computer; this.settings = settings; + this.unitManager = unitManager; computer.HardwareAdded += new HardwareEventHandler(HardwareAdded); computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved); @@ -103,7 +107,7 @@ if (Contains(sensor)) { return; } else { - list.Add(new SensorNotifyIcon(this, sensor, balloonTip, settings)); + list.Add(new SensorNotifyIcon(this, sensor, balloonTip, settings, unitManager)); UpdateMainIconVisibilty(); settings.SetValue(new Identifier(sensor.Identifier, "tray").ToString(), true); } diff -r 0a386ef7d5bb -r 1dfe9dac1651 GUI/UnitManager.cs --- a/GUI/UnitManager.cs Wed Jul 11 22:28:39 2012 +0000 +++ b/GUI/UnitManager.cs Thu Jul 12 10:17:18 2012 +0000 @@ -4,7 +4,7 @@ License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. - Copyright (C) 2009-2011 Michael Möller + Copyright (C) 2009-2012 Michael Möller */ @@ -36,5 +36,9 @@ this.settings.SetValue("TemperatureUnit", (int)temperatureUnit); } } + + public static float? CelsiusToFahrenheit(float? valueInCelsius) { + return valueInCelsius * 1.8f + 32; + } } }