mirror of
https://github.com/openhardwaremonitor/openhardwaremonitor
synced 2025-09-02 23:35:29 +00:00
Fixed Issue 86.
This commit is contained in:
@@ -121,7 +121,7 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
|
|
||||||
this.computer = new Computer(settings);
|
this.computer = new Computer(settings);
|
||||||
|
|
||||||
systemTray = new SystemTray(computer, settings);
|
systemTray = new SystemTray(computer, settings, unitManager);
|
||||||
systemTray.HideShowCommand += hideShowClick;
|
systemTray.HideShowCommand += hideShowClick;
|
||||||
systemTray.ExitCommand += exitClick;
|
systemTray.ExitCommand += exitClick;
|
||||||
|
|
||||||
|
@@ -581,7 +581,7 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
if (sensor.SensorType == SensorType.Temperature &&
|
if (sensor.SensorType == SensorType.Temperature &&
|
||||||
unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit) {
|
unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit) {
|
||||||
formatted = string.Format("{0:F1} °F",
|
formatted = string.Format("{0:F1} °F",
|
||||||
sensor.Value * 1.8 + 32);
|
UnitManager.CelsiusToFahrenheit(sensor.Value));
|
||||||
} else {
|
} else {
|
||||||
formatted = string.Format(format, sensor.Value);
|
formatted = string.Format(format, sensor.Value);
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,8 @@ using OpenHardwareMonitor.Utilities;
|
|||||||
namespace OpenHardwareMonitor.GUI {
|
namespace OpenHardwareMonitor.GUI {
|
||||||
public class SensorNotifyIcon : IDisposable {
|
public class SensorNotifyIcon : IDisposable {
|
||||||
|
|
||||||
|
private UnitManager unitManager;
|
||||||
|
|
||||||
private ISensor sensor;
|
private ISensor sensor;
|
||||||
private NotifyIcon notifyIcon;
|
private NotifyIcon notifyIcon;
|
||||||
private Bitmap bitmap;
|
private Bitmap bitmap;
|
||||||
@@ -31,10 +33,12 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
private Brush darkBrush;
|
private Brush darkBrush;
|
||||||
private Pen pen;
|
private Pen pen;
|
||||||
private Font font;
|
private Font font;
|
||||||
|
private Font smallFont;
|
||||||
|
|
||||||
public SensorNotifyIcon(SystemTray sensorSystemTray, ISensor sensor,
|
public SensorNotifyIcon(SystemTray sensorSystemTray, ISensor sensor,
|
||||||
bool balloonTip, PersistentSettings settings)
|
bool balloonTip, PersistentSettings settings, UnitManager unitManager)
|
||||||
{
|
{
|
||||||
|
this.unitManager = unitManager;
|
||||||
this.sensor = sensor;
|
this.sensor = sensor;
|
||||||
this.notifyIcon = new NotifyIcon();
|
this.notifyIcon = new NotifyIcon();
|
||||||
|
|
||||||
@@ -50,6 +54,7 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
|
|
||||||
this.pen = new Pen(Color.FromArgb(96, Color.Black));
|
this.pen = new Pen(Color.FromArgb(96, Color.Black));
|
||||||
this.font = SystemFonts.MessageBoxFont;
|
this.font = SystemFonts.MessageBoxFont;
|
||||||
|
this.smallFont = new Font(font.FontFamily, font.Size * 0.8f);
|
||||||
|
|
||||||
ContextMenu contextMenu = new ContextMenu();
|
ContextMenu contextMenu = new ContextMenu();
|
||||||
MenuItem hideShowItem = new MenuItem("Hide/Show");
|
MenuItem hideShowItem = new MenuItem("Hide/Show");
|
||||||
@@ -145,7 +150,8 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
darkBrush.Dispose();
|
darkBrush.Dispose();
|
||||||
pen.Dispose();
|
pen.Dispose();
|
||||||
graphics.Dispose();
|
graphics.Dispose();
|
||||||
bitmap.Dispose();
|
bitmap.Dispose();
|
||||||
|
smallFont.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetString() {
|
private string GetString() {
|
||||||
@@ -159,8 +165,12 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
return string.Format("{0:F1}", 1e-3f * sensor.Value);
|
return string.Format("{0:F1}", 1e-3f * sensor.Value);
|
||||||
case SensorType.Load:
|
case SensorType.Load:
|
||||||
return string.Format("{0:F0}", sensor.Value);
|
return string.Format("{0:F0}", sensor.Value);
|
||||||
case SensorType.Temperature:
|
case SensorType.Temperature:
|
||||||
return string.Format("{0:F0}", sensor.Value);
|
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:
|
case SensorType.Fan:
|
||||||
return string.Format("{0:F1}", 1e-3f * sensor.Value);
|
return string.Format("{0:F1}", 1e-3f * sensor.Value);
|
||||||
case SensorType.Flow:
|
case SensorType.Flow:
|
||||||
@@ -180,10 +190,16 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Icon CreateTransparentIcon() {
|
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);
|
graphics.Clear(Color.Black);
|
||||||
TextRenderer.DrawText(graphics, GetString(), font,
|
TextRenderer.DrawText(graphics, text, small ? smallFont : font,
|
||||||
new Point(-2, 0), Color.White, Color.Black);
|
new Point(-2, small ? 1 : 0), Color.White, Color.Black);
|
||||||
|
|
||||||
BitmapData data = bitmap.LockBits(
|
BitmapData data = bitmap.LockBits(
|
||||||
new Rectangle(0, 0, bitmap.Width, bitmap.Height),
|
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;
|
case SensorType.Factor: format = "\n{0}: {1:F3} GB"; break;
|
||||||
}
|
}
|
||||||
string formattedValue = string.Format(format, sensor.Name, sensor.Value);
|
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;
|
string hardwareName = sensor.Hardware.Name;
|
||||||
hardwareName = hardwareName.Substring(0,
|
hardwareName = hardwareName.Substring(0,
|
||||||
Math.Min(63 - formattedValue.Length, hardwareName.Length));
|
Math.Min(63 - formattedValue.Length, hardwareName.Length));
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
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/.
|
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 {
|
public class SystemTray : IDisposable {
|
||||||
private IComputer computer;
|
private IComputer computer;
|
||||||
private PersistentSettings settings;
|
private PersistentSettings settings;
|
||||||
|
private UnitManager unitManager;
|
||||||
private List<SensorNotifyIcon> list = new List<SensorNotifyIcon>();
|
private List<SensorNotifyIcon> list = new List<SensorNotifyIcon>();
|
||||||
private bool mainIconEnabled = false;
|
private bool mainIconEnabled = false;
|
||||||
private NotifyIcon mainIcon;
|
private NotifyIcon mainIcon;
|
||||||
|
|
||||||
public SystemTray(IComputer computer, PersistentSettings settings) {
|
public SystemTray(IComputer computer, PersistentSettings settings,
|
||||||
|
UnitManager unitManager)
|
||||||
|
{
|
||||||
this.computer = computer;
|
this.computer = computer;
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
|
this.unitManager = unitManager;
|
||||||
computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
|
computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
|
||||||
computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
|
computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);
|
||||||
|
|
||||||
@@ -103,7 +107,7 @@ namespace OpenHardwareMonitor.GUI {
|
|||||||
if (Contains(sensor)) {
|
if (Contains(sensor)) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
list.Add(new SensorNotifyIcon(this, sensor, balloonTip, settings));
|
list.Add(new SensorNotifyIcon(this, sensor, balloonTip, settings, unitManager));
|
||||||
UpdateMainIconVisibilty();
|
UpdateMainIconVisibilty();
|
||||||
settings.SetValue(new Identifier(sensor.Identifier, "tray").ToString(), true);
|
settings.SetValue(new Identifier(sensor.Identifier, "tray").ToString(), true);
|
||||||
}
|
}
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
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/.
|
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);
|
this.settings.SetValue("TemperatureUnit", (int)temperatureUnit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static float? CelsiusToFahrenheit(float? valueInCelsius) {
|
||||||
|
return valueInCelsius * 1.8f + 32;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user