* UIDPIScale: DPI重构

This commit is contained in:
Sunny 2022-03-29 18:26:37 +08:00
parent 6e74517f3f
commit b988632507
8 changed files with 14 additions and 24 deletions

Binary file not shown.

View File

@ -198,7 +198,7 @@ namespace Sunny.UI
{ {
float size = SubFont != null ? SubFont.Size : UIFontColor.SubFontSize; 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?.Dispose();
tmpFont = this.DPIScaleFont(Font, size); tmpFont = this.DPIScaleFont(Font, size);
@ -216,7 +216,7 @@ namespace Sunny.UI
{ {
float size = LegendFont != null ? LegendFont.Size : UIFontColor.SubFontSize; 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?.Dispose();
tmpLegendFont = this.DPIScaleFont(Font, size); tmpLegendFont = this.DPIScaleFont(Font, size);

View File

@ -728,7 +728,7 @@ namespace Sunny.UI
if (ShowToday) 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.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); e.Graphics.FillRoundRectangle(PrimaryColor, new Rectangle(p3.Width - width * 4 + 6, p3.Height - height + 3, 8, height - 10), 3);

View File

@ -1279,7 +1279,7 @@ namespace Sunny.UI
if (ShowToday) 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.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); e.Graphics.FillRoundRectangle(PrimaryColor, new Rectangle((int)(p3.Width - width * 4 + 6), p3.Height - height + 3, 8, height - 10), 3);

View File

@ -90,7 +90,7 @@ namespace Sunny.UI
{ {
this.SetDPIScaleFont(); this.SetDPIScaleFont();
if (!this.DPIScale().Equals(1)) if (!UIDPIScale.DPIScaleIsOne())
{ {
TitleFont = this.DPIScaleFont(TitleFont); TitleFont = this.DPIScaleFont(TitleFont);
} }

View File

@ -83,7 +83,7 @@ namespace Sunny.UI
if (!IsScaled) if (!IsScaled)
{ {
this.SetDPIScaleFont(); this.SetDPIScaleFont();
if (!this.DPIScale().Equals(1)) if (!UIDPIScale.DPIScaleIsOne())
{ {
this.TitleFont = this.DPIScaleFont(this.TitleFont); this.TitleFont = this.DPIScaleFont(this.TitleFont);
} }

View File

@ -32,25 +32,15 @@ namespace Sunny.UI
return GDI.Graphics().DpiX / 96.0f; return GDI.Graphics().DpiX / 96.0f;
} }
public static float DPIScale(this Control control) public static bool DPIScaleIsOne()
{ {
try return DPIScale().EqualsFloat(1);
{
if (control != null)
return control.CreateGraphics().DpiX / 96.0f;
else
return GDI.Graphics().DpiX / 96.0f;
}
catch
{
return 1;
}
} }
public static float DPIScaleFontSize(this Control control, Font font) public static float DPIScaleFontSize(this Control control, Font font)
{ {
if (UIStyles.DPIScale) if (UIStyles.DPIScale)
return font.Size / control.DPIScale(); return font.Size / DPIScale();
else else
return font.Size; return font.Size;
} }
@ -96,9 +86,9 @@ namespace Sunny.UI
if (UIStyles.DPIScale) if (UIStyles.DPIScale)
{ {
if (font.GdiCharSet == 134) 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 else
return new Font(font.FontFamily, fontSize / control.DPIScale()); return new Font(font.FontFamily, fontSize / DPIScale());
} }
else else
{ {
@ -112,7 +102,7 @@ namespace Sunny.UI
public static void SetDPIScaleFont(this Control control) public static void SetDPIScaleFont(this Control control)
{ {
if (!UIStyles.DPIScale) return; if (!UIStyles.DPIScale) return;
if (!DPIScale().EqualsFloat(1)) if (!UIDPIScale.DPIScaleIsOne())
{ {
if (control is IStyleInterface ctrl) if (control is IStyleInterface ctrl)
{ {

View File

@ -415,13 +415,13 @@ namespace Sunny.UI
{ {
foreach (var form in Forms.Values) foreach (var form in Forms.Values)
{ {
if (!form.DPIScale().EqualsFloat(1)) if (!UIDPIScale.DPIScaleIsOne())
form.SetDPIScale(); form.SetDPIScale();
} }
foreach (var page in Pages.Values) foreach (var page in Pages.Values)
{ {
if (!page.DPIScale().EqualsFloat(1)) if (!UIDPIScale.DPIScaleIsOne())
page.SetDPIScale(); page.SetDPIScale();
} }
} }