sl@403
|
1 |
/*
|
sl@403
|
2 |
|
sl@403
|
3 |
This Source Code Form is subject to the terms of the Mozilla Public
|
sl@403
|
4 |
License, v. 2.0. If a copy of the MPL was not distributed with this
|
sl@403
|
5 |
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
sl@403
|
6 |
|
sl@403
|
7 |
Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
|
sl@403
|
8 |
|
sl@403
|
9 |
*/
|
sl@403
|
10 |
|
sl@403
|
11 |
using System;
|
sl@403
|
12 |
using System.Drawing;
|
sl@403
|
13 |
using System.Drawing.Drawing2D;
|
sl@403
|
14 |
using System.Drawing.Imaging;
|
sl@403
|
15 |
using System.Drawing.Text;
|
sl@403
|
16 |
using System.Runtime.InteropServices;
|
sl@403
|
17 |
using System.Windows.Forms;
|
sl@403
|
18 |
using OpenHardwareMonitor.Hardware;
|
sl@403
|
19 |
using OpenHardwareMonitor.Utilities;
|
sl@403
|
20 |
|
sl@403
|
21 |
namespace OpenHardwareMonitor.GUI
|
sl@403
|
22 |
{
|
sl@403
|
23 |
public class SensorSharpDisplay : IDisposable
|
sl@403
|
24 |
{
|
sl@403
|
25 |
|
sl@403
|
26 |
private UnitManager unitManager;
|
sl@403
|
27 |
|
sl@403
|
28 |
private ISensor sensor;
|
sl@403
|
29 |
private Color color;
|
sl@403
|
30 |
private Color darkColor;
|
sl@403
|
31 |
private Font font;
|
sl@403
|
32 |
private Font smallFont;
|
sl@403
|
33 |
public string iFirstLine;
|
sl@403
|
34 |
public string iSecondLine;
|
sl@403
|
35 |
|
sl@403
|
36 |
|
sl@403
|
37 |
public SensorSharpDisplay(SharpDisplay soundGraphDisplay, ISensor sensor,
|
sl@403
|
38 |
bool balloonTip, PersistentSettings settings, UnitManager unitManager)
|
sl@403
|
39 |
{
|
sl@403
|
40 |
this.unitManager = unitManager;
|
sl@403
|
41 |
this.sensor = sensor;
|
sl@403
|
42 |
|
sl@403
|
43 |
// get the default dpi to create an icon with the correct size
|
sl@403
|
44 |
float dpiX, dpiY;
|
sl@403
|
45 |
using (Bitmap b = new Bitmap(1, 1, PixelFormat.Format32bppArgb))
|
sl@403
|
46 |
{
|
sl@403
|
47 |
dpiX = b.HorizontalResolution;
|
sl@403
|
48 |
dpiY = b.VerticalResolution;
|
sl@403
|
49 |
}
|
sl@403
|
50 |
|
sl@403
|
51 |
// adjust the size of the icon to current dpi (default is 16x16 at 96 dpi)
|
sl@403
|
52 |
int width = (int)Math.Round(16 * dpiX / 96);
|
sl@403
|
53 |
int height = (int)Math.Round(16 * dpiY / 96);
|
sl@403
|
54 |
|
sl@403
|
55 |
// make sure it does never get smaller than 16x16
|
sl@403
|
56 |
width = width < 16 ? 16 : width;
|
sl@403
|
57 |
height = height < 16 ? 16 : height;
|
sl@403
|
58 |
|
sl@403
|
59 |
// adjust the font size to the icon size
|
sl@403
|
60 |
FontFamily family = SystemFonts.MessageBoxFont.FontFamily;
|
sl@403
|
61 |
float baseSize;
|
sl@403
|
62 |
switch (family.Name)
|
sl@403
|
63 |
{
|
sl@403
|
64 |
case "Segoe UI": baseSize = 12; break;
|
sl@403
|
65 |
case "Tahoma": baseSize = 11; break;
|
sl@403
|
66 |
default: baseSize = 12; break;
|
sl@403
|
67 |
}
|
sl@403
|
68 |
|
sl@403
|
69 |
this.font = new Font(family,
|
sl@403
|
70 |
baseSize * width / 16.0f, GraphicsUnit.Pixel);
|
sl@403
|
71 |
this.smallFont = new Font(family,
|
sl@403
|
72 |
0.75f * baseSize * width / 16.0f, GraphicsUnit.Pixel);
|
sl@403
|
73 |
|
sl@403
|
74 |
}
|
sl@403
|
75 |
|
sl@403
|
76 |
public ISensor Sensor
|
sl@403
|
77 |
{
|
sl@403
|
78 |
get { return sensor; }
|
sl@403
|
79 |
}
|
sl@403
|
80 |
|
sl@403
|
81 |
public Color Color
|
sl@403
|
82 |
{
|
sl@403
|
83 |
get { return color; }
|
sl@403
|
84 |
set
|
sl@403
|
85 |
{
|
sl@403
|
86 |
this.color = value;
|
sl@403
|
87 |
this.darkColor = Color.FromArgb(255,
|
sl@403
|
88 |
this.color.R / 3,
|
sl@403
|
89 |
this.color.G / 3,
|
sl@403
|
90 |
this.color.B / 3);
|
sl@403
|
91 |
}
|
sl@403
|
92 |
}
|
sl@403
|
93 |
|
sl@403
|
94 |
public void Dispose()
|
sl@403
|
95 |
{
|
sl@403
|
96 |
font.Dispose();
|
sl@403
|
97 |
smallFont.Dispose();
|
sl@403
|
98 |
}
|
sl@403
|
99 |
|
sl@403
|
100 |
public string GetString()
|
sl@403
|
101 |
{
|
sl@403
|
102 |
if (!sensor.Value.HasValue)
|
sl@403
|
103 |
return "-";
|
sl@403
|
104 |
|
sl@403
|
105 |
switch (sensor.SensorType)
|
sl@403
|
106 |
{
|
sl@403
|
107 |
case SensorType.Voltage:
|
sl@403
|
108 |
return string.Format("{0:F1}", sensor.Value);
|
sl@403
|
109 |
case SensorType.Clock:
|
sl@403
|
110 |
return string.Format("{0:F1}", 1e-3f * sensor.Value);
|
sl@403
|
111 |
case SensorType.Load:
|
sl@403
|
112 |
return string.Format("{0:F0}", sensor.Value);
|
sl@403
|
113 |
case SensorType.Temperature:
|
sl@403
|
114 |
if (unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit)
|
sl@403
|
115 |
return string.Format("{0:F0}",
|
sl@403
|
116 |
UnitManager.CelsiusToFahrenheit(sensor.Value));
|
sl@403
|
117 |
else
|
sl@403
|
118 |
return string.Format("{0:F0}", sensor.Value);
|
sl@403
|
119 |
case SensorType.Fan:
|
sl@403
|
120 |
return string.Format("{0:F1}", 1e-3f * sensor.Value);
|
sl@403
|
121 |
case SensorType.Flow:
|
sl@403
|
122 |
return string.Format("{0:F1}", 1e-3f * sensor.Value);
|
sl@403
|
123 |
case SensorType.Control:
|
sl@403
|
124 |
return string.Format("{0:F0}", sensor.Value);
|
sl@403
|
125 |
case SensorType.Level:
|
sl@403
|
126 |
return string.Format("{0:F0}", sensor.Value);
|
sl@403
|
127 |
case SensorType.Power:
|
sl@403
|
128 |
return string.Format("{0:F0}", sensor.Value);
|
sl@403
|
129 |
case SensorType.Data:
|
sl@403
|
130 |
return string.Format("{0:F0}", sensor.Value);
|
sl@403
|
131 |
case SensorType.Factor:
|
sl@403
|
132 |
return string.Format("{0:F1}", sensor.Value);
|
sl@403
|
133 |
}
|
sl@403
|
134 |
return "-";
|
sl@403
|
135 |
}
|
sl@403
|
136 |
|
sl@403
|
137 |
|
sl@403
|
138 |
public void Update()
|
sl@403
|
139 |
{
|
sl@403
|
140 |
|
sl@403
|
141 |
|
sl@403
|
142 |
switch (sensor.SensorType)
|
sl@403
|
143 |
{
|
sl@403
|
144 |
case SensorType.Load:
|
sl@403
|
145 |
case SensorType.Control:
|
sl@403
|
146 |
case SensorType.Level:
|
sl@403
|
147 |
//notifyIcon.Icon = CreatePercentageIcon();
|
sl@403
|
148 |
break;
|
sl@403
|
149 |
default:
|
sl@403
|
150 |
//notifyIcon.Icon = CreateTransparentIcon();
|
sl@403
|
151 |
break;
|
sl@403
|
152 |
}
|
sl@403
|
153 |
|
sl@403
|
154 |
|
sl@403
|
155 |
string format = "";
|
sl@403
|
156 |
switch (sensor.SensorType)
|
sl@403
|
157 |
{
|
sl@403
|
158 |
case SensorType.Voltage: format = "{0:F2}V"; break;
|
sl@403
|
159 |
case SensorType.Clock: format = "{0:F0}MHz"; break;
|
sl@403
|
160 |
case SensorType.Load: format = "{0:F0}%"; break;
|
sl@403
|
161 |
//iMON VFD escape sequence for Celsius
|
sl@403
|
162 |
case SensorType.Temperature: format = "{0:F0}°C"; break;
|
sl@403
|
163 |
case SensorType.Fan: format = "{0:F0}*"; break; //RPM
|
sl@403
|
164 |
case SensorType.Flow: format = "{0:F0}L/h"; break;
|
sl@403
|
165 |
case SensorType.Control: format = "{0:F0}%"; break;
|
sl@403
|
166 |
case SensorType.Level: format = "{0:F0}%"; break;
|
sl@403
|
167 |
case SensorType.Power: format = "{0:F0}W"; break;
|
sl@403
|
168 |
case SensorType.Data: format = "{0:F0}GB"; break;
|
sl@403
|
169 |
case SensorType.Factor: format = "{0:F3}GB"; break;
|
sl@403
|
170 |
}
|
sl@403
|
171 |
string formattedValue = string.Format(format, sensor.Value);
|
sl@403
|
172 |
|
sl@403
|
173 |
if (sensor.SensorType == SensorType.Temperature &&
|
sl@403
|
174 |
unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit)
|
sl@403
|
175 |
{
|
sl@403
|
176 |
//iMON VFD escape sequence for Fahrenheit
|
sl@403
|
177 |
format = "{0:F0}°F";
|
sl@403
|
178 |
formattedValue = string.Format(format, UnitManager.CelsiusToFahrenheit(sensor.Value));
|
sl@403
|
179 |
}
|
sl@403
|
180 |
|
sl@403
|
181 |
//iFirstLine = sensor.Hardware.Name;
|
sl@403
|
182 |
//iSecondLine = sensor.Name+ ":" + formattedValue;
|
sl@403
|
183 |
|
sl@403
|
184 |
iFirstLine = sensor.Name;
|
sl@403
|
185 |
iSecondLine = formattedValue;
|
sl@403
|
186 |
|
sl@403
|
187 |
|
sl@403
|
188 |
}
|
sl@403
|
189 |
}
|
sl@403
|
190 |
}
|