GUI/SensorFrontView.cs
branchMiniDisplay
changeset 438 f590956d3234
parent 433 090259cfd699
child 439 06369ace500d
     1.1 --- a/GUI/SensorFrontView.cs	Mon Feb 02 13:28:41 2015 +0100
     1.2 +++ b/GUI/SensorFrontView.cs	Sat Apr 13 00:43:25 2013 +0200
     1.3 @@ -26,15 +26,13 @@
     1.4          private UnitManager unitManager;
     1.5  
     1.6          private ISensor sensor;
     1.7 -        private Bitmap bitmap;
     1.8 -        private Graphics graphics;
     1.9          private Color color;
    1.10          private Color darkColor;
    1.11 -        private Brush brush;
    1.12 -        private Brush darkBrush;
    1.13 -        private Pen pen;
    1.14          private Font font;
    1.15          private Font smallFont;
    1.16 +        public string iFirstLine;
    1.17 +        public string iSecondLine;
    1.18 +
    1.19  
    1.20          public SensorFrontView(SoundGraphDisplay soundGraphDisplay, ISensor sensor,
    1.21            bool balloonTip, PersistentSettings settings, UnitManager unitManager)
    1.22 @@ -73,14 +71,6 @@
    1.23              this.smallFont = new Font(family,
    1.24                0.75f * baseSize * width / 16.0f, GraphicsUnit.Pixel);
    1.25  
    1.26 -            this.bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
    1.27 -            this.graphics = Graphics.FromImage(this.bitmap);
    1.28 -
    1.29 -            if (Environment.OSVersion.Version.Major > 5)
    1.30 -            {
    1.31 -                this.graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
    1.32 -                this.graphics.SmoothingMode = SmoothingMode.HighQuality;
    1.33 -            }
    1.34          }
    1.35  
    1.36          public ISensor Sensor
    1.37 @@ -98,32 +88,16 @@
    1.38                    this.color.R / 3,
    1.39                    this.color.G / 3,
    1.40                    this.color.B / 3);
    1.41 -                Brush brush = this.brush;
    1.42 -                this.brush = new SolidBrush(this.color);
    1.43 -                if (brush != null)
    1.44 -                    brush.Dispose();
    1.45 -                Brush darkBrush = this.darkBrush;
    1.46 -                this.darkBrush = new SolidBrush(this.darkColor);
    1.47 -                if (darkBrush != null)
    1.48 -                    darkBrush.Dispose();
    1.49              }
    1.50          }
    1.51  
    1.52          public void Dispose()
    1.53          {
    1.54 -
    1.55 -            if (brush != null)
    1.56 -                brush.Dispose();
    1.57 -            if (darkBrush != null)
    1.58 -                darkBrush.Dispose();
    1.59 -            pen.Dispose();
    1.60 -            graphics.Dispose();
    1.61 -            bitmap.Dispose();
    1.62              font.Dispose();
    1.63              smallFont.Dispose();
    1.64          }
    1.65  
    1.66 -        private string GetString()
    1.67 +        public string GetString()
    1.68          {
    1.69              if (!sensor.Value.HasValue)
    1.70                  return "-";
    1.71 @@ -160,73 +134,6 @@
    1.72              return "-";
    1.73          }
    1.74  
    1.75 -        private Icon CreateTransparentIcon()
    1.76 -        {
    1.77 -            string text = GetString();
    1.78 -            int count = 0;
    1.79 -            for (int i = 0; i < text.Length; i++)
    1.80 -                if ((text[i] >= '0' && text[i] <= '9') || text[i] == '-')
    1.81 -                    count++;
    1.82 -            bool small = count > 2;
    1.83 -
    1.84 -            graphics.Clear(Color.Black);
    1.85 -            TextRenderer.DrawText(graphics, text, small ? smallFont : font,
    1.86 -              new Point(-2, small ? 1 : 0), Color.White, Color.Black);
    1.87 -
    1.88 -            BitmapData data = bitmap.LockBits(
    1.89 -              new Rectangle(0, 0, bitmap.Width, bitmap.Height),
    1.90 -              ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
    1.91 -
    1.92 -            IntPtr Scan0 = data.Scan0;
    1.93 -
    1.94 -            int numBytes = bitmap.Width * bitmap.Height * 4;
    1.95 -            byte[] bytes = new byte[numBytes];
    1.96 -            Marshal.Copy(Scan0, bytes, 0, numBytes);
    1.97 -            bitmap.UnlockBits(data);
    1.98 -
    1.99 -            byte red, green, blue;
   1.100 -            for (int i = 0; i < bytes.Length; i += 4)
   1.101 -            {
   1.102 -                blue = bytes[i];
   1.103 -                green = bytes[i + 1];
   1.104 -                red = bytes[i + 2];
   1.105 -
   1.106 -                bytes[i] = color.B;
   1.107 -                bytes[i + 1] = color.G;
   1.108 -                bytes[i + 2] = color.R;
   1.109 -                bytes[i + 3] = (byte)(0.3 * red + 0.59 * green + 0.11 * blue);
   1.110 -            }
   1.111 -
   1.112 -            return IconFactory.Create(bytes, bitmap.Width, bitmap.Height,
   1.113 -              PixelFormat.Format32bppArgb);
   1.114 -        }
   1.115 -
   1.116 -        private Icon CreatePercentageIcon()
   1.117 -        {
   1.118 -            try
   1.119 -            {
   1.120 -                graphics.Clear(Color.Transparent);
   1.121 -            }
   1.122 -            catch (ArgumentException)
   1.123 -            {
   1.124 -                graphics.Clear(Color.Black);
   1.125 -            }
   1.126 -            graphics.FillRectangle(darkBrush, 0.5f, -0.5f, bitmap.Width - 2, bitmap.Height);
   1.127 -            float value = sensor.Value.GetValueOrDefault();
   1.128 -            float y = 0.16f * (100 - value);
   1.129 -            graphics.FillRectangle(brush, 0.5f, -0.5f + y, bitmap.Width - 2, bitmap.Height - y);
   1.130 -            graphics.DrawRectangle(pen, 1, 0, bitmap.Width - 3, bitmap.Height - 1);
   1.131 -
   1.132 -            BitmapData data = bitmap.LockBits(
   1.133 -              new Rectangle(0, 0, bitmap.Width, bitmap.Height),
   1.134 -              ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
   1.135 -            byte[] bytes = new byte[bitmap.Width * bitmap.Height * 4];
   1.136 -            Marshal.Copy(data.Scan0, bytes, 0, bytes.Length);
   1.137 -            bitmap.UnlockBits(data);
   1.138 -
   1.139 -            return IconFactory.Create(bytes, bitmap.Width, bitmap.Height,
   1.140 -              PixelFormat.Format32bppArgb);
   1.141 -        }
   1.142  
   1.143          public void Update()
   1.144          {
   1.145 @@ -248,35 +155,30 @@
   1.146              string format = "";
   1.147              switch (sensor.SensorType)
   1.148              {
   1.149 -                case SensorType.Voltage: format = "\n{0}: {1:F2} V"; break;
   1.150 -                case SensorType.Clock: format = "\n{0}: {1:F0} MHz"; break;
   1.151 -                case SensorType.Load: format = "\n{0}: {1:F1} %"; break;
   1.152 -                case SensorType.Temperature: format = "\n{0}: {1:F1} °C"; break;
   1.153 -                case SensorType.Fan: format = "\n{0}: {1:F0} RPM"; break;
   1.154 -                case SensorType.Flow: format = "\n{0}: {1:F0} L/h"; break;
   1.155 -                case SensorType.Control: format = "\n{0}: {1:F1} %"; break;
   1.156 -                case SensorType.Level: format = "\n{0}: {1:F1} %"; break;
   1.157 -                case SensorType.Power: format = "\n{0}: {1:F0} W"; break;
   1.158 -                case SensorType.Data: format = "\n{0}: {1:F0} GB"; break;
   1.159 -                case SensorType.Factor: format = "\n{0}: {1:F3} GB"; break;
   1.160 +                case SensorType.Voltage: format = "{0}: {1:F2} V"; break;
   1.161 +                case SensorType.Clock: format = "{0}: {1:F0} MHz"; break;
   1.162 +                case SensorType.Load: format = "{0}: {1:F1} %"; break;
   1.163 +                case SensorType.Temperature: format = "{0}: {1:F1} °C"; break;
   1.164 +                case SensorType.Fan: format = "{0}: {1:F0} RPM"; break;
   1.165 +                case SensorType.Flow: format = "{0}: {1:F0} L/h"; break;
   1.166 +                case SensorType.Control: format = "{0}: {1:F1} %"; break;
   1.167 +                case SensorType.Level: format = "{0}: {1:F1} %"; break;
   1.168 +                case SensorType.Power: format = "{0}: {1:F0} W"; break;
   1.169 +                case SensorType.Data: format = "{0}: {1:F0} GB"; break;
   1.170 +                case SensorType.Factor: format = "{0}: {1:F3} GB"; break;
   1.171              }
   1.172              string formattedValue = string.Format(format, sensor.Name, sensor.Value);
   1.173  
   1.174              if (sensor.SensorType == SensorType.Temperature &&
   1.175                unitManager.TemperatureUnit == TemperatureUnit.Fahrenheit)
   1.176              {
   1.177 -                format = "\n{0}: {1:F1} °F";
   1.178 +                format = "{0}: {1:F1} °F";
   1.179                  formattedValue = string.Format(format, sensor.Name,
   1.180                    UnitManager.CelsiusToFahrenheit(sensor.Value));
   1.181              }
   1.182  
   1.183 -            string hardwareName = sensor.Hardware.Name;
   1.184 -            hardwareName = hardwareName.Substring(0,
   1.185 -              Math.Min(63 - formattedValue.Length, hardwareName.Length));
   1.186 -            string text = hardwareName + formattedValue;
   1.187 -            if (text.Length > 63)
   1.188 -                text = null;
   1.189 -
   1.190 +            iFirstLine = sensor.Hardware.Name;
   1.191 +            iSecondLine = formattedValue;
   1.192  
   1.193          }
   1.194      }