Front View plug-in does not init if no sensor added.
Fixing some format to make strings shorter.
Now trying to start SoundGraphAccess.exe process from same directory.
Packed mode now can display three sensors along with the current time.
3 This Source Code Form is subject to the terms of the Mozilla Public
4 License, v. 2.0. If a copy of the MPL was not distributed with this
5 file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
13 using System.Drawing.Drawing2D;
14 using System.Drawing.Imaging;
15 using System.Drawing.Text;
16 using System.Runtime.InteropServices;
17 using System.Windows.Forms;
18 using OpenHardwareMonitor.Hardware;
19 using OpenHardwareMonitor.Utilities;
21 namespace OpenHardwareMonitor.GUI
23 public class SensorFrontView : IDisposable
26 private UnitManager unitManager;
28 private ISensor sensor;
30 private Color darkColor;
32 private Font smallFont;
33 public string iFirstLine;
34 public string iSecondLine;
37 public SensorFrontView(SoundGraphDisplay soundGraphDisplay, ISensor sensor,
38 bool balloonTip, PersistentSettings settings, UnitManager unitManager)
40 this.unitManager = unitManager;
43 // get the default dpi to create an icon with the correct size
45 using (Bitmap b = new Bitmap(1, 1, PixelFormat.Format32bppArgb))
47 dpiX = b.HorizontalResolution;
48 dpiY = b.VerticalResolution;
51 // adjust the size of the icon to current dpi (default is 16x16 at 96 dpi)
52 int width = (int)Math.Round(16 * dpiX / 96);
53 int height = (int)Math.Round(16 * dpiY / 96);
55 // make sure it does never get smaller than 16x16
56 width = width < 16 ? 16 : width;
57 height = height < 16 ? 16 : height;
59 // adjust the font size to the icon size
60 FontFamily family = SystemFonts.MessageBoxFont.FontFamily;
64 case "Segoe UI": baseSize = 12; break;
65 case "Tahoma": baseSize = 11; break;
66 default: baseSize = 12; break;
69 this.font = new Font(family,
70 baseSize * width / 16.0f, GraphicsUnit.Pixel);
71 this.smallFont = new Font(family,
72 0.75f * baseSize * width / 16.0f, GraphicsUnit.Pixel);
78 get { return sensor; }
87 this.darkColor = Color.FromArgb(255,
100 public string GetString()
102 if (!sensor.Value.HasValue)
105 switch (sensor.SensorType)
107 case SensorType.Voltage:
108 return string.Format("{0:F1}", sensor.Value);
109 case SensorType.Clock:
110 return string.Format("{0:F1}", 1e-3f * sensor.Value);
111 case SensorType.Load:
112 return string.Format("{0:F0}", sensor.Value);
113 case SensorType.Temperature:
114 if (unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit)
115 return string.Format("{0:F0}",
116 UnitManager.CelsiusToFahrenheit(sensor.Value));
118 return string.Format("{0:F0}", sensor.Value);
120 return string.Format("{0:F1}", 1e-3f * sensor.Value);
121 case SensorType.Flow:
122 return string.Format("{0:F1}", 1e-3f * sensor.Value);
123 case SensorType.Control:
124 return string.Format("{0:F0}", sensor.Value);
125 case SensorType.Level:
126 return string.Format("{0:F0}", sensor.Value);
127 case SensorType.Power:
128 return string.Format("{0:F0}", sensor.Value);
129 case SensorType.Data:
130 return string.Format("{0:F0}", sensor.Value);
131 case SensorType.Factor:
132 return string.Format("{0:F1}", sensor.Value);
142 switch (sensor.SensorType)
144 case SensorType.Load:
145 case SensorType.Control:
146 case SensorType.Level:
147 //notifyIcon.Icon = CreatePercentageIcon();
150 //notifyIcon.Icon = CreateTransparentIcon();
156 switch (sensor.SensorType)
158 case SensorType.Voltage: format = "{0:F2}V"; break;
159 case SensorType.Clock: format = "{0:F0}MHz"; break;
160 case SensorType.Load: format = "{0:F0}%"; break;
161 //iMON VFD escape sequence for Celsius
162 case SensorType.Temperature: format = "{0:F0}\x001A"; break;
163 case SensorType.Fan: format = "{0:F0}*"; break; //RPM
164 case SensorType.Flow: format = "{0:F0}L/h"; break;
165 case SensorType.Control: format = "{0:F0}%"; break;
166 case SensorType.Level: format = "{0:F0}%"; break;
167 case SensorType.Power: format = "{0:F0}W"; break;
168 case SensorType.Data: format = "{0:F0}GB"; break;
169 case SensorType.Factor: format = "{0:F3}GB"; break;
171 string formattedValue = string.Format(format, sensor.Value);
173 if (sensor.SensorType == SensorType.Temperature &&
174 unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit)
176 //iMON VFD escape sequence for Fahrenheit
177 format = "{0:F0}\x001B";
178 formattedValue = string.Format(format, UnitManager.CelsiusToFahrenheit(sensor.Value));
181 //iFirstLine = sensor.Hardware.Name;
182 //iSecondLine = sensor.Name+ ":" + formattedValue;
184 iFirstLine = sensor.Name;
185 iSecondLine = formattedValue;