11/*
2-
2+
33 This Source Code Form is subject to the terms of the Mozilla Public
44 License, v. 2.0. If a copy of the MPL was not distributed with this
55 file, You can obtain one at http://mozilla.org/MPL/2.0/.
6-
6+
77 Copyright (C) 2009-2012 Michael Möller <mmoeller@openhardwaremonitor.org>
8-
8+
99*/
1010
1111using System ;
@@ -36,7 +36,7 @@ public class SensorNotifyIcon : IDisposable {
3636 private Font smallFont ;
3737
3838 public SensorNotifyIcon ( SystemTray sensorSystemTray , ISensor sensor ,
39- bool balloonTip , PersistentSettings settings , UnitManager unitManager )
39+ bool balloonTip , PersistentSettings settings , UnitManager unitManager )
4040 {
4141 this . unitManager = unitManager ;
4242 this . sensor = sensor ;
@@ -45,17 +45,18 @@ public SensorNotifyIcon(SystemTray sensorSystemTray, ISensor sensor,
4545 //Color defaultColor = Color.Black;
4646 //if (sensor.SensorType == SensorType.Load ||
4747 // sensor.SensorType == SensorType.Control ||
48- // sensor.SensorType == SensorType.Level)
48+ // sensor.SensorType == SensorType.Level)
4949 //{
5050 // defaultColor = Color.FromArgb(0xff, 0x70, 0x8c, 0xf1);
5151 //}
52- Color = settings . GetValue ( new Identifier ( sensor . Identifier ,
53- "traycolor" ) . ToString ( ) , Color . FromArgb ( 0xff , 0x00 , 0xff , 0xff ) ) ;
54-
52+ Color = settings . GetValue ( new Identifier ( sensor . Identifier ,
53+ "traycolor" ) . ToString ( ) , Color . FromArgb ( 0xff , 0x00 , 0xff , 0xff ) ) ;
54+
5555 this . pen = new Pen ( Color . FromArgb ( 96 , Color . Black ) ) ;
5656
5757 ContextMenu contextMenu = new ContextMenu ( ) ;
5858 MenuItem hideShowItem = new MenuItem ( "Hide/Show" ) ;
59+ hideShowItem . DefaultItem = true ;
5960 hideShowItem . Click += delegate ( object obj , EventArgs args ) {
6061 sensorSystemTray . SendHideShowCommand ( ) ;
6162 } ;
@@ -86,7 +87,7 @@ public SensorNotifyIcon(SystemTray sensorSystemTray, ISensor sensor,
8687 this . notifyIcon . ContextMenu = contextMenu ;
8788 this . notifyIcon . DoubleClick += delegate ( object obj , EventArgs args ) {
8889 sensorSystemTray . SendHideShowCommand ( ) ;
89- } ;
90+ } ;
9091
9192 // get the default dpi to create an icon with the correct size
9293 float dpiX , dpiY ;
@@ -95,7 +96,7 @@ public SensorNotifyIcon(SystemTray sensorSystemTray, ISensor sensor,
9596 dpiY = b . VerticalResolution ;
9697 }
9798
98- // adjust the size of the icon to current dpi (default is 16x16 at 96 dpi)
99+ // adjust the size of the icon to current dpi (default is 16x16 at 96 dpi)
99100 int width = ( int ) Math . Round ( 16 * dpiX / 96 ) ;
100101 int height = ( int ) Math . Round ( 16 * dpiY / 96 ) ;
101102
@@ -114,10 +115,10 @@ public SensorNotifyIcon(SystemTray sensorSystemTray, ISensor sensor,
114115
115116 this . font = new Font ( family ,
116117 baseSize * width / 16.0f , GraphicsUnit . Pixel ) ;
117- this . smallFont = new Font ( family ,
118+ this . smallFont = new Font ( family ,
118119 0.75f * baseSize * width / 16.0f , GraphicsUnit . Pixel ) ;
119120
120- this . bitmap = new Bitmap ( width , height , PixelFormat . Format32bppArgb ) ;
121+ this . bitmap = new Bitmap ( width , height , PixelFormat . Format32bppArgb ) ;
121122 this . graphics = Graphics . FromImage ( this . bitmap ) ;
122123
123124 if ( Environment . OSVersion . Version . Major > 5 ) {
@@ -132,7 +133,7 @@ public ISensor Sensor {
132133
133134 public Color Color {
134135 get { return color ; }
135- set {
136+ set {
136137 this . color = value ;
137138 this . darkColor = Color . FromArgb ( 255 ,
138139 this . color . R / 3 ,
@@ -149,19 +150,19 @@ public Color Color {
149150 }
150151 }
151152
152- public void Dispose ( ) {
153+ public void Dispose ( ) {
153154 Icon icon = notifyIcon . Icon ;
154155 notifyIcon . Icon = null ;
155156 if ( icon != null )
156- icon . Dispose ( ) ;
157+ icon . Dispose ( ) ;
157158 notifyIcon . Dispose ( ) ;
158159
159160 if ( brush != null )
160161 brush . Dispose ( ) ;
161162 if ( darkBrush != null )
162163 darkBrush . Dispose ( ) ;
163164 pen . Dispose ( ) ;
164- graphics . Dispose ( ) ;
165+ graphics . Dispose ( ) ;
165166 bitmap . Dispose ( ) ;
166167 font . Dispose ( ) ;
167168 smallFont . Dispose ( ) ;
@@ -176,15 +177,15 @@ private string GetString() {
176177 return string . Format ( "{0:F1}" , sensor . Value ) ;
177178 case SensorType . Clock :
178179 return string . Format ( "{0:F1}" , 1e-3f * sensor . Value ) ;
179- case SensorType . Load :
180+ case SensorType . Load :
180181 return string . Format ( "{0:F0}" , sensor . Value ) ;
181182 case SensorType . Temperature :
182183 if ( unitManager . TemperatureUnit == TemperatureUnit . Fahrenheit )
183- return string . Format ( "{0:F0}" ,
184+ return string . Format ( "{0:F0}" ,
184185 UnitManager . CelsiusToFahrenheit ( sensor . Value ) ) ;
185186 else
186187 return string . Format ( "{0:F0}" , sensor . Value ) ;
187- case SensorType . Fan :
188+ case SensorType . Fan :
188189 return string . Format ( "{0:F1}" , 1e-3f * sensor . Value ) ;
189190 case SensorType . Flow :
190191 return string . Format ( "{0:F1}" , 1e-3f * sensor . Value ) ;
@@ -213,7 +214,7 @@ private Icon CreateTransparentIcon() {
213214
214215 graphics . Clear ( Color . Black ) ;
215216 TextRenderer . DrawText ( graphics , text , small ? smallFont : font ,
216- new Point ( - 4 , small ? 1 : - 2 ) , color , Color . Black ) ;
217+ new Point ( - 4 , small ? 1 : - 2 ) , color , Color . Black ) ;
217218
218219 BitmapData data = bitmap . LockBits (
219220 new Rectangle ( 0 , 0 , bitmap . Width , bitmap . Height ) ,
@@ -238,11 +239,11 @@ private Icon CreateTransparentIcon() {
238239 // bytes[i + 3] = (byte)(0.3 * red + 0.59 * green + 0.11 * blue);
239240 //}
240241
241- return IconFactory . Create ( bytes , bitmap . Width , bitmap . Height ,
242+ return IconFactory . Create ( bytes , bitmap . Width , bitmap . Height ,
242243 PixelFormat . Format32bppArgb ) ;
243244 }
244245
245- private Icon CreatePercentageIcon ( ) {
246+ private Icon CreatePercentageIcon ( ) {
246247 try {
247248 graphics . Clear ( Color . Transparent ) ;
248249 } catch ( ArgumentException ) {
@@ -261,7 +262,7 @@ private Icon CreatePercentageIcon() {
261262 Marshal . Copy ( data . Scan0 , bytes , 0 , bytes . Length ) ;
262263 bitmap . UnlockBits ( data ) ;
263264
264- return IconFactory . Create ( bytes , bitmap . Width , bitmap . Height ,
265+ return IconFactory . Create ( bytes , bitmap . Width , bitmap . Height ,
265266 PixelFormat . Format32bppArgb ) ;
266267 }
267268
@@ -279,7 +280,7 @@ public void Update() {
279280 break ;
280281 }
281282
282- if ( icon != null )
283+ if ( icon != null )
283284 icon . Dispose ( ) ;
284285
285286 string format = "" ;
@@ -299,22 +300,22 @@ public void Update() {
299300 string formattedValue = string . Format ( format , sensor . Name , sensor . Value ) ;
300301
301302 if ( sensor . SensorType == SensorType . Temperature &&
302- unitManager . TemperatureUnit == TemperatureUnit . Fahrenheit )
303+ unitManager . TemperatureUnit == TemperatureUnit . Fahrenheit )
303304 {
304305 format = "\n {0}: {1:F1} °F" ;
305306 formattedValue = string . Format ( format , sensor . Name ,
306307 UnitManager . CelsiusToFahrenheit ( sensor . Value ) ) ;
307308 }
308309
309310 string hardwareName = sensor . Hardware . Name ;
310- hardwareName = hardwareName . Substring ( 0 ,
311+ hardwareName = hardwareName . Substring ( 0 ,
311312 Math . Min ( 63 - formattedValue . Length , hardwareName . Length ) ) ;
312313 string text = hardwareName + formattedValue ;
313314 if ( text . Length > 63 )
314315 text = null ;
315316
316317 notifyIcon . Text = text ;
317- notifyIcon . Visible = true ;
318+ notifyIcon . Visible = true ;
318319 }
319320 }
320321}
0 commit comments