1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/GUI/SensorSharpDisplay.cs Sun Sep 21 21:55:36 2014 +0200
1.3 @@ -0,0 +1,190 @@
1.4 +/*
1.5 +
1.6 + This Source Code Form is subject to the terms of the Mozilla Public
1.7 + License, v. 2.0. If a copy of the MPL was not distributed with this
1.8 + file, You can obtain one at http://mozilla.org/MPL/2.0/.
1.9 +
1.10 + Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
1.11 +
1.12 +*/
1.13 +
1.14 +using System;
1.15 +using System.Drawing;
1.16 +using System.Drawing.Drawing2D;
1.17 +using System.Drawing.Imaging;
1.18 +using System.Drawing.Text;
1.19 +using System.Runtime.InteropServices;
1.20 +using System.Windows.Forms;
1.21 +using OpenHardwareMonitor.Hardware;
1.22 +using OpenHardwareMonitor.Utilities;
1.23 +
1.24 +namespace OpenHardwareMonitor.GUI
1.25 +{
1.26 + public class SensorSharpDisplay : IDisposable
1.27 + {
1.28 +
1.29 + private UnitManager unitManager;
1.30 +
1.31 + private ISensor sensor;
1.32 + private Color color;
1.33 + private Color darkColor;
1.34 + private Font font;
1.35 + private Font smallFont;
1.36 + public string iFirstLine;
1.37 + public string iSecondLine;
1.38 +
1.39 +
1.40 + public SensorSharpDisplay(SharpDisplay soundGraphDisplay, ISensor sensor,
1.41 + bool balloonTip, PersistentSettings settings, UnitManager unitManager)
1.42 + {
1.43 + this.unitManager = unitManager;
1.44 + this.sensor = sensor;
1.45 +
1.46 + // get the default dpi to create an icon with the correct size
1.47 + float dpiX, dpiY;
1.48 + using (Bitmap b = new Bitmap(1, 1, PixelFormat.Format32bppArgb))
1.49 + {
1.50 + dpiX = b.HorizontalResolution;
1.51 + dpiY = b.VerticalResolution;
1.52 + }
1.53 +
1.54 + // adjust the size of the icon to current dpi (default is 16x16 at 96 dpi)
1.55 + int width = (int)Math.Round(16 * dpiX / 96);
1.56 + int height = (int)Math.Round(16 * dpiY / 96);
1.57 +
1.58 + // make sure it does never get smaller than 16x16
1.59 + width = width < 16 ? 16 : width;
1.60 + height = height < 16 ? 16 : height;
1.61 +
1.62 + // adjust the font size to the icon size
1.63 + FontFamily family = SystemFonts.MessageBoxFont.FontFamily;
1.64 + float baseSize;
1.65 + switch (family.Name)
1.66 + {
1.67 + case "Segoe UI": baseSize = 12; break;
1.68 + case "Tahoma": baseSize = 11; break;
1.69 + default: baseSize = 12; break;
1.70 + }
1.71 +
1.72 + this.font = new Font(family,
1.73 + baseSize * width / 16.0f, GraphicsUnit.Pixel);
1.74 + this.smallFont = new Font(family,
1.75 + 0.75f * baseSize * width / 16.0f, GraphicsUnit.Pixel);
1.76 +
1.77 + }
1.78 +
1.79 + public ISensor Sensor
1.80 + {
1.81 + get { return sensor; }
1.82 + }
1.83 +
1.84 + public Color Color
1.85 + {
1.86 + get { return color; }
1.87 + set
1.88 + {
1.89 + this.color = value;
1.90 + this.darkColor = Color.FromArgb(255,
1.91 + this.color.R / 3,
1.92 + this.color.G / 3,
1.93 + this.color.B / 3);
1.94 + }
1.95 + }
1.96 +
1.97 + public void Dispose()
1.98 + {
1.99 + font.Dispose();
1.100 + smallFont.Dispose();
1.101 + }
1.102 +
1.103 + public string GetString()
1.104 + {
1.105 + if (!sensor.Value.HasValue)
1.106 + return "-";
1.107 +
1.108 + switch (sensor.SensorType)
1.109 + {
1.110 + case SensorType.Voltage:
1.111 + return string.Format("{0:F1}", sensor.Value);
1.112 + case SensorType.Clock:
1.113 + return string.Format("{0:F1}", 1e-3f * sensor.Value);
1.114 + case SensorType.Load:
1.115 + return string.Format("{0:F0}", sensor.Value);
1.116 + case SensorType.Temperature:
1.117 + if (unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit)
1.118 + return string.Format("{0:F0}",
1.119 + UnitManager.CelsiusToFahrenheit(sensor.Value));
1.120 + else
1.121 + return string.Format("{0:F0}", sensor.Value);
1.122 + case SensorType.Fan:
1.123 + return string.Format("{0:F1}", 1e-3f * sensor.Value);
1.124 + case SensorType.Flow:
1.125 + return string.Format("{0:F1}", 1e-3f * sensor.Value);
1.126 + case SensorType.Control:
1.127 + return string.Format("{0:F0}", sensor.Value);
1.128 + case SensorType.Level:
1.129 + return string.Format("{0:F0}", sensor.Value);
1.130 + case SensorType.Power:
1.131 + return string.Format("{0:F0}", sensor.Value);
1.132 + case SensorType.Data:
1.133 + return string.Format("{0:F0}", sensor.Value);
1.134 + case SensorType.Factor:
1.135 + return string.Format("{0:F1}", sensor.Value);
1.136 + }
1.137 + return "-";
1.138 + }
1.139 +
1.140 +
1.141 + public void Update()
1.142 + {
1.143 +
1.144 +
1.145 + switch (sensor.SensorType)
1.146 + {
1.147 + case SensorType.Load:
1.148 + case SensorType.Control:
1.149 + case SensorType.Level:
1.150 + //notifyIcon.Icon = CreatePercentageIcon();
1.151 + break;
1.152 + default:
1.153 + //notifyIcon.Icon = CreateTransparentIcon();
1.154 + break;
1.155 + }
1.156 +
1.157 +
1.158 + string format = "";
1.159 + switch (sensor.SensorType)
1.160 + {
1.161 + case SensorType.Voltage: format = "{0:F2}V"; break;
1.162 + case SensorType.Clock: format = "{0:F0}MHz"; break;
1.163 + case SensorType.Load: format = "{0:F0}%"; break;
1.164 + //iMON VFD escape sequence for Celsius
1.165 + case SensorType.Temperature: format = "{0:F0}°C"; break;
1.166 + case SensorType.Fan: format = "{0:F0}*"; break; //RPM
1.167 + case SensorType.Flow: format = "{0:F0}L/h"; break;
1.168 + case SensorType.Control: format = "{0:F0}%"; break;
1.169 + case SensorType.Level: format = "{0:F0}%"; break;
1.170 + case SensorType.Power: format = "{0:F0}W"; break;
1.171 + case SensorType.Data: format = "{0:F0}GB"; break;
1.172 + case SensorType.Factor: format = "{0:F3}GB"; break;
1.173 + }
1.174 + string formattedValue = string.Format(format, sensor.Value);
1.175 +
1.176 + if (sensor.SensorType == SensorType.Temperature &&
1.177 + unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit)
1.178 + {
1.179 + //iMON VFD escape sequence for Fahrenheit
1.180 + format = "{0:F0}°F";
1.181 + formattedValue = string.Format(format, UnitManager.CelsiusToFahrenheit(sensor.Value));
1.182 + }
1.183 +
1.184 + //iFirstLine = sensor.Hardware.Name;
1.185 + //iSecondLine = sensor.Name+ ":" + formattedValue;
1.186 +
1.187 + iFirstLine = sensor.Name;
1.188 + iSecondLine = formattedValue;
1.189 +
1.190 +
1.191 + }
1.192 + }
1.193 +}