Fixed Issue 86.

This commit is contained in:
Michael Möller 2012-07-12 10:17:18 +00:00
parent 4026c56ba0
commit fc026664d3
5 changed files with 45 additions and 12 deletions

View File

@ -121,7 +121,7 @@ namespace OpenHardwareMonitor.GUI {
this.computer = new Computer(settings);
systemTray = new SystemTray(computer, settings);
systemTray = new SystemTray(computer, settings, unitManager);
systemTray.HideShowCommand += hideShowClick;
systemTray.ExitCommand += exitClick;

View File

@ -581,7 +581,7 @@ namespace OpenHardwareMonitor.GUI {
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);
}

View File

@ -21,6 +21,8 @@ using OpenHardwareMonitor.Utilities;
namespace OpenHardwareMonitor.GUI {
public class SensorNotifyIcon : IDisposable {
private UnitManager unitManager;
private ISensor sensor;
private NotifyIcon notifyIcon;
private Bitmap bitmap;
@ -31,10 +33,12 @@ namespace OpenHardwareMonitor.GUI {
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 @@ namespace OpenHardwareMonitor.GUI {
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 @@ namespace OpenHardwareMonitor.GUI {
darkBrush.Dispose();
pen.Dispose();
graphics.Dispose();
bitmap.Dispose();
bitmap.Dispose();
smallFont.Dispose();
}
private string GetString() {
@ -159,8 +165,12 @@ namespace OpenHardwareMonitor.GUI {
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 @@ namespace OpenHardwareMonitor.GUI {
}
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 @@ namespace OpenHardwareMonitor.GUI {
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));

View File

@ -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 <mmoeller@openhardwaremonitor.org>
Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
*/
@ -20,13 +20,17 @@ namespace OpenHardwareMonitor.GUI {
public class SystemTray : IDisposable {
private IComputer computer;
private PersistentSettings settings;
private UnitManager unitManager;
private List<SensorNotifyIcon> list = new List<SensorNotifyIcon>();
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 @@ namespace OpenHardwareMonitor.GUI {
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);
}

View File

@ -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 <mmoeller@openhardwaremonitor.org>
Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
*/
@ -36,5 +36,9 @@ namespace OpenHardwareMonitor.GUI {
this.settings.SetValue("TemperatureUnit", (int)temperatureUnit);
}
}
public static float? CelsiusToFahrenheit(float? valueInCelsius) {
return valueInCelsius * 1.8f + 32;
}
}
}