Fixed some dpi scaling bugs that occurred when changing "Control Panel\Appearance and Personalization\Display" to 125% text size or 150% text size.

This commit is contained in:
Michael Möller
2011-01-30 23:45:26 +00:00
parent 4d4c3aae8d
commit be28c71358
5 changed files with 44 additions and 18 deletions
+1 -2
View File
@@ -436,8 +436,7 @@ namespace OpenHardwareMonitor.GUI {
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;
+1
View File
@@ -91,6 +91,7 @@ namespace OpenHardwareMonitor.GUI {
this.Font = SystemFonts.MessageBoxFont;
treeView.Font = SystemFonts.MessageBoxFont;
plotPanel.Font = SystemFonts.MessageBoxFont;
treeView.RowHeight = treeView.Font.Height;
nodeCheckBox.IsVisibleValueNeeded += nodeCheckBox_IsVisibleValueNeeded;
nodeCheckBox.CheckStateChanged += UpdatePlotSelection;
+17 -8
View File
@@ -54,6 +54,7 @@ namespace OpenHardwareMonitor.GUI {
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 @@ namespace OpenHardwareMonitor.GUI {
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 @@ namespace OpenHardwareMonitor.GUI {
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() {
+23 -6
View File
@@ -112,7 +112,22 @@ namespace OpenHardwareMonitor.GUI {
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 @@ namespace OpenHardwareMonitor.GUI {
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 @@ namespace OpenHardwareMonitor.GUI {
} 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 @@ namespace OpenHardwareMonitor.GUI {
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() {
+2 -2
View File
@@ -37,5 +37,5 @@
using System.Reflection;
[assembly: AssemblyVersion("0.2.1.10")]
[assembly: AssemblyInformationalVersion("0.2.1.10 Alpha")]
[assembly: AssemblyVersion("0.2.1.11")]
[assembly: AssemblyInformationalVersion("0.2.1.11 Alpha")]