# HG changeset patch # User moel.mich # Date 1296431126 0 # Node ID e62afa69214f12213f0c4a74f0afe8cc0096eb50 # Parent 49c38a2958c86984ee88d01e7bf79aa256899627 Fixed some dpi scaling bugs that occurred when changing "Control Panel\Appearance and Personalization\Display" to 125% text size or 150% text size. diff -r 49c38a2958c8 -r e62afa69214f GUI/MainForm.Designer.cs --- a/GUI/MainForm.Designer.cs Thu Jan 27 22:29:43 2011 +0000 +++ b/GUI/MainForm.Designer.cs Sun Jan 30 23:45:26 2011 +0000 @@ -436,8 +436,7 @@ this.treeView.NodeControls.Add(this.nodeTextBoxText); this.treeView.NodeControls.Add(this.nodeTextBoxValue); this.treeView.NodeControls.Add(this.nodeTextBoxMin); - this.treeView.NodeControls.Add(this.nodeTextBoxMax); - this.treeView.RowHeight = 18; + this.treeView.NodeControls.Add(this.nodeTextBoxMax); this.treeView.SelectedNode = null; this.treeView.Size = new System.Drawing.Size(386, 354); this.treeView.TabIndex = 0; diff -r 49c38a2958c8 -r e62afa69214f GUI/MainForm.cs --- a/GUI/MainForm.cs Thu Jan 27 22:29:43 2011 +0000 +++ b/GUI/MainForm.cs Sun Jan 30 23:45:26 2011 +0000 @@ -91,6 +91,7 @@ this.Font = SystemFonts.MessageBoxFont; treeView.Font = SystemFonts.MessageBoxFont; plotPanel.Font = SystemFonts.MessageBoxFont; + treeView.RowHeight = treeView.Font.Height; nodeCheckBox.IsVisibleValueNeeded += nodeCheckBox_IsVisibleValueNeeded; nodeCheckBox.CheckStateChanged += UpdatePlotSelection; diff -r 49c38a2958c8 -r e62afa69214f GUI/SensorGadget.cs --- a/GUI/SensorGadget.cs Thu Jan 27 22:29:43 2011 +0000 +++ b/GUI/SensorGadget.cs Sun Jan 30 23:45:26 2011 +0000 @@ -54,6 +54,7 @@ private const int leftBorder = 6; private const int rightBorder = 7; + private readonly float scale; private float fontSize; private int iconSize; private int hardwareLineHeight; @@ -108,6 +109,11 @@ settings.SetValue("sensorGadget.Location.Y", Location.Y); }; + // get the custom to default dpi ratio + using (Bitmap b = new Bitmap(1, 1)) { + scale = b.HorizontalResolution / 96.0f; + } + SetFontSize(settings.GetValue("sensorGadget.FontSize", 7.5f)); Resize(settings.GetValue("sensorGadget.Width", Size.Width)); @@ -329,15 +335,18 @@ fontSize = size; largeFont = CreateFont(fontSize, FontStyle.Bold); smallFont = CreateFont(fontSize, FontStyle.Regular); - iconSize = (int)Math.Round(1.5 * fontSize); - hardwareLineHeight = (int)Math.Round(1.66 * fontSize); - sensorLineHeight = (int)Math.Round(1.33 * fontSize); - leftMargin = leftBorder + (int)Math.Round(0.3 * fontSize); - rightMargin = rightBorder + (int)Math.Round(0.3 * fontSize); + + double scaledFontSize = fontSize * scale; + iconSize = (int)Math.Round(1.5 * scaledFontSize); + hardwareLineHeight = (int)Math.Round(1.66 * scaledFontSize); + sensorLineHeight = (int)Math.Round(1.33 * scaledFontSize); + leftMargin = leftBorder + (int)Math.Round(0.3 * scaledFontSize); + rightMargin = rightBorder + (int)Math.Round(0.3 * scaledFontSize); topMargin = topBorder; - bottomMargin = bottomBorder + (int)Math.Round(0.3 * fontSize); - progressWidth = (int)Math.Round(5.3 * fontSize); - Resize((int)Math.Round(17.3 * fontSize)); + bottomMargin = bottomBorder + (int)Math.Round(0.3 * scaledFontSize); + progressWidth = (int)Math.Round(5.3 * scaledFontSize); + + Resize((int)Math.Round(17.3 * scaledFontSize)); } private void Resize() { diff -r 49c38a2958c8 -r e62afa69214f GUI/SensorNotifyIcon.cs --- a/GUI/SensorNotifyIcon.cs Thu Jan 27 22:29:43 2011 +0000 +++ b/GUI/SensorNotifyIcon.cs Sun Jan 30 23:45:26 2011 +0000 @@ -112,7 +112,22 @@ sensorSystemTray.SendHideShowCommand(); }; - this.bitmap = new Bitmap(16, 16, PixelFormat.Format32bppArgb); + // get the default dpi to create an icon with the correct size + float dpiX, dpiY; + using (Bitmap b = new Bitmap(1, 1, PixelFormat.Format32bppArgb)) { + dpiX = b.HorizontalResolution; + dpiY = b.VerticalResolution; + } + + // adjust the size of the icon to current dpi (default is 16x16 at 96 dpi) + int width = (int)Math.Round(16 * dpiX / 96); + int height = (int)Math.Round(16 * dpiY / 96); + + // make sure it does never get smaller than 16x16 + width = width < 16 ? 16: width; + height = height < 16 ? 16: height; + + this.bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb); this.graphics = Graphics.FromImage(this.bitmap); if (Environment.OSVersion.Version.Major > 5) { @@ -211,7 +226,8 @@ bytes[i + 3] = (byte)(0.3 * red + 0.59 * green + 0.11 * blue); } - return IconFactory.Create(bytes, 16, 16, PixelFormat.Format32bppArgb); + return IconFactory.Create(bytes, bitmap.Width, bitmap.Height, + PixelFormat.Format32bppArgb); } private Icon CreatePercentageIcon() { @@ -220,10 +236,10 @@ } catch (ArgumentException) { graphics.Clear(Color.Black); } - graphics.FillRectangle(darkBrush, 0.5f, -0.5f, 14, 16); + graphics.FillRectangle(darkBrush, 0.5f, -0.5f, bitmap.Width - 2, bitmap.Height); float y = 0.16f * (100 - sensor.Value.Value); - graphics.FillRectangle(brush, 0.5f, -0.5f + y, 14, 16 - y); - graphics.DrawRectangle(pen, 1, 0, 13, 15); + graphics.FillRectangle(brush, 0.5f, -0.5f + y, bitmap.Width - 2, bitmap.Height - y); + graphics.DrawRectangle(pen, 1, 0, bitmap.Width - 3, bitmap.Height - 1); BitmapData data = bitmap.LockBits( new Rectangle(0, 0, bitmap.Width, bitmap.Height), @@ -232,7 +248,8 @@ Marshal.Copy(data.Scan0, bytes, 0, bytes.Length); bitmap.UnlockBits(data); - return IconFactory.Create(bytes, 16, 16, PixelFormat.Format32bppArgb); + return IconFactory.Create(bytes, bitmap.Width, bitmap.Height, + PixelFormat.Format32bppArgb); } public void Update() { diff -r 49c38a2958c8 -r e62afa69214f Properties/AssemblyVersion.cs --- a/Properties/AssemblyVersion.cs Thu Jan 27 22:29:43 2011 +0000 +++ b/Properties/AssemblyVersion.cs Sun Jan 30 23:45:26 2011 +0000 @@ -37,5 +37,5 @@ using System.Reflection; -[assembly: AssemblyVersion("0.2.1.10")] -[assembly: AssemblyInformationalVersion("0.2.1.10 Alpha")] \ No newline at end of file +[assembly: AssemblyVersion("0.2.1.11")] +[assembly: AssemblyInformationalVersion("0.2.1.11 Alpha")] \ No newline at end of file