GUI/SensorGadget.cs
changeset 316 82bfd8af42a7
parent 300 ee03b05bce9f
child 318 bba78bc5b760
     1.1 --- a/GUI/SensorGadget.cs	Sun Jul 24 22:16:28 2011 +0000
     1.2 +++ b/GUI/SensorGadget.cs	Mon Jul 25 21:09:21 2011 +0000
     1.3 @@ -38,6 +38,7 @@
     1.4  using System;
     1.5  using System.Collections.Generic;
     1.6  using System.Drawing;
     1.7 +using System.Drawing.Imaging;
     1.8  using System.Windows.Forms;
     1.9  using OpenHardwareMonitor.Hardware;
    1.10  
    1.11 @@ -48,11 +49,12 @@
    1.12  
    1.13      private Image back = Utilities.EmbeddedResources.GetImage("gadget.png");
    1.14      private Image barBack = Utilities.EmbeddedResources.GetImage("barback.png");
    1.15 -    private Image barblue = Utilities.EmbeddedResources.GetImage("barblue.png");
    1.16 +    private Image barBlue = Utilities.EmbeddedResources.GetImage("barblue.png");
    1.17      private const int topBorder = 6;
    1.18      private const int bottomBorder = 7;
    1.19      private const int leftBorder = 6;
    1.20      private const int rightBorder = 7;
    1.21 +    private Image background = new Bitmap(1, 1);
    1.22  
    1.23      private readonly float scale;
    1.24      private float fontSize;
    1.25 @@ -238,7 +240,19 @@
    1.26        trimStringFormat = null;
    1.27  
    1.28        alignRightStringFormat.Dispose();
    1.29 -      alignRightStringFormat = null;      
    1.30 +      alignRightStringFormat = null;     
    1.31 + 
    1.32 +      back.Dispose();
    1.33 +      back = null;
    1.34 +
    1.35 +      barBlue.Dispose();
    1.36 +      barBlue = null;
    1.37 +
    1.38 +      barBack.Dispose();
    1.39 +      barBack = null;
    1.40 +
    1.41 +      background.Dispose();
    1.42 +      background = null;
    1.43  
    1.44        base.Dispose();
    1.45      }
    1.46 @@ -385,33 +399,45 @@
    1.47  
    1.48      private void DrawBackground(Graphics g) {
    1.49        int w = Size.Width;
    1.50 -      int h = Size.Height;
    1.51 -      int t = topBorder;
    1.52 -      int b = bottomBorder;
    1.53 -      int l = leftBorder;
    1.54 -      int r = rightBorder;
    1.55 -      GraphicsUnit u = GraphicsUnit.Pixel;
    1.56 +      int h = Size.Height;      
    1.57  
    1.58 -      g.DrawImage(back, new Rectangle(0, 0, l, t),
    1.59 -        new Rectangle(0, 0, l, t), u);
    1.60 -      g.DrawImage(back, new Rectangle(l, 0, w - l - r, t),
    1.61 -        new Rectangle(l, 0, back.Width - l - r, t), u);
    1.62 -      g.DrawImage(back, new Rectangle(w - r, 0, r, t),
    1.63 -        new Rectangle(back.Width - r, 0, r, t), u);
    1.64 +      if (w != background.Width || h != background.Height) {
    1.65  
    1.66 -      g.DrawImage(back, new Rectangle(0, t, l, h - t - b),
    1.67 -        new Rectangle(0, t, l, back.Height - t - b), u);
    1.68 -      g.DrawImage(back, new Rectangle(l, t, w - l - r, h - t - b),
    1.69 -        new Rectangle(l, t, back.Width - l - r, back.Height - t - b), u);
    1.70 -      g.DrawImage(back, new Rectangle(w - r, t, r, h - t - b),
    1.71 -        new Rectangle(back.Width - r, t, r, back.Height - t - b), u);
    1.72 +        background.Dispose();
    1.73 +        background = new Bitmap(w, h, PixelFormat.Format32bppPArgb);
    1.74 +        using (Graphics graphics = Graphics.FromImage(background)) {
    1.75  
    1.76 -      g.DrawImage(back, new Rectangle(0, h - b, l, b),
    1.77 -        new Rectangle(0, back.Height - b, l, b), u);
    1.78 -      g.DrawImage(back, new Rectangle(l, h - b, w - l - r, b),
    1.79 -        new Rectangle(l, back.Height - b, back.Width - l - r, b), u);
    1.80 -      g.DrawImage(back, new Rectangle(w - r, h - b, r, b),
    1.81 -        new Rectangle(back.Width - r, back.Height - b, r, b), u);
    1.82 +          int t = topBorder;
    1.83 +          int b = bottomBorder;
    1.84 +          int l = leftBorder;
    1.85 +          int r = rightBorder;
    1.86 +
    1.87 +          GraphicsUnit u = GraphicsUnit.Pixel;
    1.88 +
    1.89 +          graphics.DrawImage(back, new Rectangle(0, 0, l, t),
    1.90 +            new Rectangle(0, 0, l, t), u);
    1.91 +          graphics.DrawImage(back, new Rectangle(l, 0, w - l - r, t),
    1.92 +            new Rectangle(l, 0, back.Width - l - r, t), u);
    1.93 +          graphics.DrawImage(back, new Rectangle(w - r, 0, r, t),
    1.94 +            new Rectangle(back.Width - r, 0, r, t), u);
    1.95 +
    1.96 +          graphics.DrawImage(back, new Rectangle(0, t, l, h - t - b),
    1.97 +            new Rectangle(0, t, l, back.Height - t - b), u);
    1.98 +          graphics.DrawImage(back, new Rectangle(l, t, w - l - r, h - t - b),
    1.99 +            new Rectangle(l, t, back.Width - l - r, back.Height - t - b), u);
   1.100 +          graphics.DrawImage(back, new Rectangle(w - r, t, r, h - t - b),
   1.101 +            new Rectangle(back.Width - r, t, r, back.Height - t - b), u);
   1.102 +
   1.103 +          graphics.DrawImage(back, new Rectangle(0, h - b, l, b),
   1.104 +            new Rectangle(0, back.Height - b, l, b), u);
   1.105 +          graphics.DrawImage(back, new Rectangle(l, h - b, w - l - r, b),
   1.106 +            new Rectangle(l, back.Height - b, back.Width - l - r, b), u);
   1.107 +          graphics.DrawImage(back, new Rectangle(w - r, h - b, r, b),
   1.108 +            new Rectangle(back.Width - r, back.Height - b, r, b), u);
   1.109 +        }
   1.110 +      }
   1.111 +
   1.112 +      g.DrawImageUnscaled(background, 0, 0);
   1.113      }
   1.114  
   1.115      private void DrawProgress(Graphics g, float x, float y, 
   1.116 @@ -422,9 +448,9 @@
   1.117          new RectangleF(barBack.Width * progress, 0, 
   1.118            (1 - progress) * barBack.Width, barBack.Height), 
   1.119          GraphicsUnit.Pixel);
   1.120 -      g.DrawImage(barblue,
   1.121 +      g.DrawImage(barBlue,
   1.122          new RectangleF(x, y, width * progress, height),
   1.123 -        new RectangleF(0, 0, progress * barblue.Width, barblue.Height),
   1.124 +        new RectangleF(0, 0, progress * barBlue.Width, barBlue.Height),
   1.125          GraphicsUnit.Pixel);
   1.126      }
   1.127