* UIDPIScale: DPI重构
This commit is contained in:
parent
6e74517f3f
commit
b988632507
Binary file not shown.
@ -198,7 +198,7 @@ namespace Sunny.UI
|
||||
{
|
||||
float size = SubFont != null ? SubFont.Size : UIFontColor.SubFontSize;
|
||||
|
||||
if (tmpFont == null || !tmpFont.Size.EqualsFloat(size / this.DPIScale()))
|
||||
if (tmpFont == null || !tmpFont.Size.EqualsFloat(size / UIDPIScale.DPIScale()))
|
||||
{
|
||||
tmpFont?.Dispose();
|
||||
tmpFont = this.DPIScaleFont(Font, size);
|
||||
@ -216,7 +216,7 @@ namespace Sunny.UI
|
||||
{
|
||||
float size = LegendFont != null ? LegendFont.Size : UIFontColor.SubFontSize;
|
||||
|
||||
if (tmpLegendFont == null || !tmpLegendFont.Size.EqualsFloat(size / this.DPIScale()))
|
||||
if (tmpLegendFont == null || !tmpLegendFont.Size.EqualsFloat(size / UIDPIScale.DPIScale()))
|
||||
{
|
||||
tmpLegendFont?.Dispose();
|
||||
tmpLegendFont = this.DPIScaleFont(Font, size);
|
||||
|
@ -728,7 +728,7 @@ namespace Sunny.UI
|
||||
|
||||
if (ShowToday)
|
||||
{
|
||||
using (Font SubFont = new Font("微软雅黑", 10.5f / this.DPIScale()))
|
||||
using (Font SubFont = new Font("微软雅黑", 10.5f / UIDPIScale.DPIScale()))
|
||||
{
|
||||
e.Graphics.FillRectangle(p3.FillColor, p3.Width - width * 4 + 1, p3.Height - height + 1, width * 4 - 2, height - 2);
|
||||
e.Graphics.FillRoundRectangle(PrimaryColor, new Rectangle(p3.Width - width * 4 + 6, p3.Height - height + 3, 8, height - 10), 3);
|
||||
|
@ -1279,7 +1279,7 @@ namespace Sunny.UI
|
||||
|
||||
if (ShowToday)
|
||||
{
|
||||
using (Font SubFont = new Font("微软雅黑", 10.5f / this.DPIScale()))
|
||||
using (Font SubFont = new Font("微软雅黑", 10.5f / UIDPIScale.DPIScale()))
|
||||
{
|
||||
e.Graphics.FillRectangle(p3.FillColor, p3.Width - width * 4 + 1, p3.Height - height + 1, width * 4 - 2, height - 2);
|
||||
e.Graphics.FillRoundRectangle(PrimaryColor, new Rectangle((int)(p3.Width - width * 4 + 6), p3.Height - height + 3, 8, height - 10), 3);
|
||||
|
@ -90,7 +90,7 @@ namespace Sunny.UI
|
||||
{
|
||||
this.SetDPIScaleFont();
|
||||
|
||||
if (!this.DPIScale().Equals(1))
|
||||
if (!UIDPIScale.DPIScaleIsOne())
|
||||
{
|
||||
TitleFont = this.DPIScaleFont(TitleFont);
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ namespace Sunny.UI
|
||||
if (!IsScaled)
|
||||
{
|
||||
this.SetDPIScaleFont();
|
||||
if (!this.DPIScale().Equals(1))
|
||||
if (!UIDPIScale.DPIScaleIsOne())
|
||||
{
|
||||
this.TitleFont = this.DPIScaleFont(this.TitleFont);
|
||||
}
|
||||
|
@ -32,25 +32,15 @@ namespace Sunny.UI
|
||||
return GDI.Graphics().DpiX / 96.0f;
|
||||
}
|
||||
|
||||
public static float DPIScale(this Control control)
|
||||
public static bool DPIScaleIsOne()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (control != null)
|
||||
return control.CreateGraphics().DpiX / 96.0f;
|
||||
else
|
||||
return GDI.Graphics().DpiX / 96.0f;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return DPIScale().EqualsFloat(1);
|
||||
}
|
||||
|
||||
public static float DPIScaleFontSize(this Control control, Font font)
|
||||
{
|
||||
if (UIStyles.DPIScale)
|
||||
return font.Size / control.DPIScale();
|
||||
return font.Size / DPIScale();
|
||||
else
|
||||
return font.Size;
|
||||
}
|
||||
@ -96,9 +86,9 @@ namespace Sunny.UI
|
||||
if (UIStyles.DPIScale)
|
||||
{
|
||||
if (font.GdiCharSet == 134)
|
||||
return new Font(font.FontFamily, fontSize / control.DPIScale(), font.Style, font.Unit, font.GdiCharSet);
|
||||
return new Font(font.FontFamily, fontSize / DPIScale(), font.Style, font.Unit, font.GdiCharSet);
|
||||
else
|
||||
return new Font(font.FontFamily, fontSize / control.DPIScale());
|
||||
return new Font(font.FontFamily, fontSize / DPIScale());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -112,7 +102,7 @@ namespace Sunny.UI
|
||||
public static void SetDPIScaleFont(this Control control)
|
||||
{
|
||||
if (!UIStyles.DPIScale) return;
|
||||
if (!DPIScale().EqualsFloat(1))
|
||||
if (!UIDPIScale.DPIScaleIsOne())
|
||||
{
|
||||
if (control is IStyleInterface ctrl)
|
||||
{
|
||||
|
@ -415,13 +415,13 @@ namespace Sunny.UI
|
||||
{
|
||||
foreach (var form in Forms.Values)
|
||||
{
|
||||
if (!form.DPIScale().EqualsFloat(1))
|
||||
if (!UIDPIScale.DPIScaleIsOne())
|
||||
form.SetDPIScale();
|
||||
}
|
||||
|
||||
foreach (var page in Pages.Values)
|
||||
{
|
||||
if (!page.DPIScale().EqualsFloat(1))
|
||||
if (!UIDPIScale.DPIScaleIsOne())
|
||||
page.SetDPIScale();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user