Fixed some dpi scaling bugs that occurred when changing "Control Panel\Appearance and Personalization\Display" to 125% text size or 150% text size.
authormoel.mich
Sun, 30 Jan 2011 23:45:26 +0000
changeset 252e62afa69214f
parent 251 49c38a2958c8
child 253 0044b05a3094
Fixed some dpi scaling bugs that occurred when changing "Control Panel\Appearance and Personalization\Display" to 125% text size or 150% text size.
GUI/MainForm.Designer.cs
GUI/MainForm.cs
GUI/SensorGadget.cs
GUI/SensorNotifyIcon.cs
Properties/AssemblyVersion.cs
     1.1 --- a/GUI/MainForm.Designer.cs	Thu Jan 27 22:29:43 2011 +0000
     1.2 +++ b/GUI/MainForm.Designer.cs	Sun Jan 30 23:45:26 2011 +0000
     1.3 @@ -436,8 +436,7 @@
     1.4        this.treeView.NodeControls.Add(this.nodeTextBoxText);
     1.5        this.treeView.NodeControls.Add(this.nodeTextBoxValue);
     1.6        this.treeView.NodeControls.Add(this.nodeTextBoxMin);
     1.7 -      this.treeView.NodeControls.Add(this.nodeTextBoxMax);
     1.8 -      this.treeView.RowHeight = 18;
     1.9 +      this.treeView.NodeControls.Add(this.nodeTextBoxMax);      
    1.10        this.treeView.SelectedNode = null;
    1.11        this.treeView.Size = new System.Drawing.Size(386, 354);
    1.12        this.treeView.TabIndex = 0;
     2.1 --- a/GUI/MainForm.cs	Thu Jan 27 22:29:43 2011 +0000
     2.2 +++ b/GUI/MainForm.cs	Sun Jan 30 23:45:26 2011 +0000
     2.3 @@ -91,6 +91,7 @@
     2.4        this.Font = SystemFonts.MessageBoxFont;
     2.5        treeView.Font = SystemFonts.MessageBoxFont;
     2.6        plotPanel.Font = SystemFonts.MessageBoxFont;
     2.7 +      treeView.RowHeight = treeView.Font.Height;      
     2.8        
     2.9        nodeCheckBox.IsVisibleValueNeeded += nodeCheckBox_IsVisibleValueNeeded;
    2.10        nodeCheckBox.CheckStateChanged += UpdatePlotSelection;
     3.1 --- a/GUI/SensorGadget.cs	Thu Jan 27 22:29:43 2011 +0000
     3.2 +++ b/GUI/SensorGadget.cs	Sun Jan 30 23:45:26 2011 +0000
     3.3 @@ -54,6 +54,7 @@
     3.4      private const int leftBorder = 6;
     3.5      private const int rightBorder = 7;
     3.6  
     3.7 +    private readonly float scale;
     3.8      private float fontSize;
     3.9      private int iconSize;
    3.10      private int hardwareLineHeight;
    3.11 @@ -108,6 +109,11 @@
    3.12          settings.SetValue("sensorGadget.Location.Y", Location.Y);
    3.13        };
    3.14  
    3.15 +      // get the custom to default dpi ratio
    3.16 +      using (Bitmap b = new Bitmap(1, 1)) {
    3.17 +        scale = b.HorizontalResolution / 96.0f;
    3.18 +      }
    3.19 +
    3.20        SetFontSize(settings.GetValue("sensorGadget.FontSize", 7.5f));
    3.21        Resize(settings.GetValue("sensorGadget.Width", Size.Width));
    3.22        
    3.23 @@ -329,15 +335,18 @@
    3.24        fontSize = size;
    3.25        largeFont = CreateFont(fontSize, FontStyle.Bold);
    3.26        smallFont = CreateFont(fontSize, FontStyle.Regular);
    3.27 -      iconSize = (int)Math.Round(1.5 * fontSize);
    3.28 -      hardwareLineHeight = (int)Math.Round(1.66 * fontSize);
    3.29 -      sensorLineHeight = (int)Math.Round(1.33 * fontSize);      
    3.30 -      leftMargin = leftBorder + (int)Math.Round(0.3 * fontSize);
    3.31 -      rightMargin = rightBorder + (int)Math.Round(0.3 * fontSize);
    3.32 +      
    3.33 +      double scaledFontSize = fontSize * scale;
    3.34 +      iconSize = (int)Math.Round(1.5 * scaledFontSize);
    3.35 +      hardwareLineHeight = (int)Math.Round(1.66 * scaledFontSize);
    3.36 +      sensorLineHeight = (int)Math.Round(1.33 * scaledFontSize);
    3.37 +      leftMargin = leftBorder + (int)Math.Round(0.3 * scaledFontSize);
    3.38 +      rightMargin = rightBorder + (int)Math.Round(0.3 * scaledFontSize);
    3.39        topMargin = topBorder;
    3.40 -      bottomMargin = bottomBorder + (int)Math.Round(0.3 * fontSize);
    3.41 -      progressWidth = (int)Math.Round(5.3 * fontSize);
    3.42 -      Resize((int)Math.Round(17.3 * fontSize));
    3.43 +      bottomMargin = bottomBorder + (int)Math.Round(0.3 * scaledFontSize);
    3.44 +      progressWidth = (int)Math.Round(5.3 * scaledFontSize);
    3.45 +
    3.46 +      Resize((int)Math.Round(17.3 * scaledFontSize));
    3.47      }
    3.48  
    3.49      private void Resize() {
     4.1 --- a/GUI/SensorNotifyIcon.cs	Thu Jan 27 22:29:43 2011 +0000
     4.2 +++ b/GUI/SensorNotifyIcon.cs	Sun Jan 30 23:45:26 2011 +0000
     4.3 @@ -112,7 +112,22 @@
     4.4          sensorSystemTray.SendHideShowCommand();
     4.5        };
     4.6  
     4.7 -      this.bitmap = new Bitmap(16, 16, PixelFormat.Format32bppArgb);
     4.8 +      // get the default dpi to create an icon with the correct size
     4.9 +      float dpiX, dpiY;
    4.10 +      using (Bitmap b = new Bitmap(1, 1, PixelFormat.Format32bppArgb)) {
    4.11 +        dpiX = b.HorizontalResolution;
    4.12 +        dpiY = b.VerticalResolution;
    4.13 +      }
    4.14 +
    4.15 +      // adjust the size of the icon to current dpi (default is 16x16 at 96 dpi) 
    4.16 +      int width = (int)Math.Round(16 * dpiX / 96);
    4.17 +      int height = (int)Math.Round(16 * dpiY / 96);
    4.18 +
    4.19 +      // make sure it does never get smaller than 16x16
    4.20 +      width = width < 16 ? 16: width;
    4.21 +      height = height < 16 ? 16: height;
    4.22 +
    4.23 +      this.bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);      
    4.24        this.graphics = Graphics.FromImage(this.bitmap);
    4.25  
    4.26        if (Environment.OSVersion.Version.Major > 5) {
    4.27 @@ -211,7 +226,8 @@
    4.28          bytes[i + 3] = (byte)(0.3 * red + 0.59 * green + 0.11 * blue);
    4.29        }
    4.30  
    4.31 -      return IconFactory.Create(bytes, 16, 16, PixelFormat.Format32bppArgb);
    4.32 +      return IconFactory.Create(bytes, bitmap.Width, bitmap.Height, 
    4.33 +        PixelFormat.Format32bppArgb);
    4.34      }
    4.35  
    4.36      private Icon CreatePercentageIcon() {      
    4.37 @@ -220,10 +236,10 @@
    4.38        } catch (ArgumentException) {
    4.39          graphics.Clear(Color.Black);
    4.40        }
    4.41 -      graphics.FillRectangle(darkBrush, 0.5f, -0.5f, 14, 16);
    4.42 +      graphics.FillRectangle(darkBrush, 0.5f, -0.5f, bitmap.Width - 2, bitmap.Height);
    4.43        float y = 0.16f * (100 - sensor.Value.Value);
    4.44 -      graphics.FillRectangle(brush, 0.5f, -0.5f + y, 14, 16 - y);
    4.45 -      graphics.DrawRectangle(pen, 1, 0, 13, 15);
    4.46 +      graphics.FillRectangle(brush, 0.5f, -0.5f + y, bitmap.Width - 2, bitmap.Height - y);
    4.47 +      graphics.DrawRectangle(pen, 1, 0, bitmap.Width - 3, bitmap.Height - 1);
    4.48  
    4.49        BitmapData data = bitmap.LockBits(
    4.50          new Rectangle(0, 0, bitmap.Width, bitmap.Height),
    4.51 @@ -232,7 +248,8 @@
    4.52        Marshal.Copy(data.Scan0, bytes, 0, bytes.Length);
    4.53        bitmap.UnlockBits(data);
    4.54  
    4.55 -      return IconFactory.Create(bytes, 16, 16, PixelFormat.Format32bppArgb);
    4.56 +      return IconFactory.Create(bytes, bitmap.Width, bitmap.Height, 
    4.57 +        PixelFormat.Format32bppArgb);
    4.58      }
    4.59  
    4.60      public void Update() {
     5.1 --- a/Properties/AssemblyVersion.cs	Thu Jan 27 22:29:43 2011 +0000
     5.2 +++ b/Properties/AssemblyVersion.cs	Sun Jan 30 23:45:26 2011 +0000
     5.3 @@ -37,5 +37,5 @@
     5.4  
     5.5  using System.Reflection;
     5.6  
     5.7 -[assembly: AssemblyVersion("0.2.1.10")]
     5.8 -[assembly: AssemblyInformationalVersion("0.2.1.10 Alpha")]
     5.9 \ No newline at end of file
    5.10 +[assembly: AssemblyVersion("0.2.1.11")]
    5.11 +[assembly: AssemblyInformationalVersion("0.2.1.11 Alpha")]
    5.12 \ No newline at end of file