Skip to content

Commit

Permalink
Version 3.13.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaskohl committed Sep 19, 2021
1 parent 9defef1 commit 12df39b
Show file tree
Hide file tree
Showing 18 changed files with 1,137 additions and 709 deletions.
12 changes: 6 additions & 6 deletions CapsLockIndicatorV3/BetterCheckBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected override void OnPaint(PaintEventArgs e)
}
else
{

var scaling = DPIHelper.GetScalingFactorPercent();
var border = N_Border;
var background = N_Background;
var check = N_Check;
Expand All @@ -89,14 +89,14 @@ protected override void OnPaint(PaintEventArgs e)
check = H_Check;
}

const int boxSize = 13;
const int boxRectInnerMargin = 2;
const int checkPenWidth = 2;
const int textMargin = 3;
int boxSize = (int)(13 * scaling);
int boxRectInnerMargin = (int)(2 * scaling);
int checkPenWidth = (int)(2 * scaling);
int textMargin = (int)(3 * scaling);

var boxY = Height / 2 - boxSize / 2;

var boxRect = new Rectangle(0, boxY, 13, 13);
var boxRect = new Rectangle(0, boxY, boxSize, boxSize);
var boxRectPen = boxRect;
var boxRectInner = boxRect;
--boxRectPen.Width;
Expand Down
23 changes: 19 additions & 4 deletions CapsLockIndicatorV3/BetterTabControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ internal void DrawControl(Graphics g)

internal void DrawTab(Graphics g, TabPage tabPage, int nIndex)
{
var tr = this.GetTabRect(nIndex);
var tr = GetTabRectDPI(nIndex);
Rectangle recBounds = tr;
recBounds.Y -= 2;
recBounds.Height += 2;
Expand Down Expand Up @@ -329,6 +329,21 @@ internal void DrawTab(Graphics g, TabPage tabPage, int nIndex)
}
}

private Rectangle GetTabRectDPI(int nIndex)
{
var rect = GetTabRect(nIndex);
/*
var scale = DPIHelper.GetScalingFactorPercent();
rect = new Rectangle(
(int)(rect.X * scale),
(int)(rect.Y * scale),
(int)(rect.Width * scale),
(int)(rect.Height * scale)
);
*/
return rect;
}

internal void DrawIcons(Graphics g)
{
if (!_darkMode)
Expand Down Expand Up @@ -368,7 +383,7 @@ internal void DrawIcons(Graphics g)
{
if (this.TabCount > 0)
{
Rectangle r3 = this.GetTabRect(0);
Rectangle r3 = GetTabRectDPI(0);
if (r3.Left < TabControlArea.Left)
g.DrawImage(img, r1);
else
Expand All @@ -385,7 +400,7 @@ internal void DrawIcons(Graphics g)
{
if (this.TabCount > 0)
{
Rectangle r3 = this.GetTabRect(this.TabCount - 1);
Rectangle r3 = GetTabRectDPI(this.TabCount - 1);
if (r3.Right > (TabControlArea.Width - r0.Width))
g.DrawImage(img, r2);
else
Expand Down Expand Up @@ -439,7 +454,7 @@ protected override void OnMouseMove(MouseEventArgs e)
var index = -1;
for (var i = 0; i < TabCount; ++i)
{
var rect = GetTabRect(i);
var rect = GetTabRectDPI(i);
if (rect.Contains(pos))
{
index = i;
Expand Down
1 change: 1 addition & 0 deletions CapsLockIndicatorV3/CapsLockIndicatorV3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<Compile Include="DownloadDialog.Designer.cs">
<DependentUpon>DownloadDialog.cs</DependentUpon>
</Compile>
<Compile Include="DPIHelper.cs" />
<Compile Include="DropDownLocale.cs" />
<Compile Include="ExtensionMethods.cs" />
<Compile Include="FirstRunDialog.cs">
Expand Down
43 changes: 43 additions & 0 deletions CapsLockIndicatorV3/DPIHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace CapsLockIndicatorV3
{
internal static class DPIHelper
{
[DllImport("gdi32.dll")]
static extern int GetDeviceCaps(IntPtr hdc, int nIndex);

private enum DeviceCap
{
VERTRES = 10,
LOGPIXELSY = 90,
DESKTOPVERTRES = 117
}

internal static decimal GetScalingFactorPercent()
{
var g = Graphics.FromHwnd(IntPtr.Zero);
try
{
var desktop = g.GetHdc();
var LogicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.VERTRES);
var PhysicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.DESKTOPVERTRES);
var logpixelsy = GetDeviceCaps(desktop, (int)DeviceCap.LOGPIXELSY);
var screenScalingFactor = PhysicalScreenHeight / (decimal)LogicalScreenHeight;
var dpiScalingFactor = logpixelsy / 96.0M;

return dpiScalingFactor;
}
finally
{
g?.ReleaseHdc();
}
}
}
}
8 changes: 4 additions & 4 deletions CapsLockIndicatorV3/IconPackBrowser.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion CapsLockIndicatorV3/IconPackBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private void IconPackBrowser_DarkModeChanged(object sender, EventArgs e)

ControlScheduleSetDarkMode(webBrowser1, dark);

webBrowser1.Navigate("https://cli.jonaskohl.de/icongallery/embedded.php?dark=" + (dark ? "true" : "false"));
webBrowser1.Navigate("https://cli.jonaskohl.de/icongallery/embedded.php?dark=" + (dark ? "true" : "false") + "&scale=" + ((int)(DPIHelper.GetScalingFactorPercent() * 100)).ToString());
}
}
}
4 changes: 2 additions & 2 deletions CapsLockIndicatorV3/IndicatorOverlay.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 12df39b

Please sign in to comment.