Skip to content

feat&fix: High Res Scale Adjustment and CurrentCulture #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Core/API/IApiSystem.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace System.Drawing
namespace System.Drawing
{
using System.Globalization;

public interface IApiSystem
{
CultureInfo CurrentCulture { get; }
CultureInfo CurrentCulture { get => CultureInfo.CurrentCulture; }
Point MousePosition { get; }
}
}
8 changes: 5 additions & 3 deletions System/Windows/Forms/Application.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace System.Windows.Forms
namespace System.Windows.Forms
{
using System.Collections.Generic;
using System.Drawing;
Expand Down Expand Up @@ -35,8 +35,10 @@ public class Application

static Application()
{
if (ApiHolder.System != null)
CurrentCulture = ApiHolder.System.CurrentCulture;
//if (ApiHolder.System != null)
// CurrentCulture = ApiHolder.System.CurrentCulture;

CurrentCulture = CultureInfo.CurrentCulture;
}

public Application()
Expand Down
35 changes: 28 additions & 7 deletions Unity/UnityWinForms.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Unity.API
namespace Unity.API
{
using System;
using System.Collections.Generic;
Expand All @@ -8,8 +8,16 @@
using UE = UnityEngine;
using SWF = System.Windows.Forms;

public sealed class UnityWinForms : UE.MonoBehaviour
public sealed class UnityWinForms : UE.MonoBehaviour
{
[UE.Tooltip("Reference Screen Resolution")]
public int referScreenWidth;
public int referScreenHeight;

[UE.Tooltip("Reference Screen Scale Factor")]
public float scaleFactorX = 1.0f;
public float scaleFactorY = 1.0f;

public AppResources Resources;

[UE.Tooltip("Delay between first KeyDown event and following ones")]
Expand All @@ -29,7 +37,7 @@ public sealed class UnityWinForms : UE.MonoBehaviour
private float shiftDownTimer;
private float shiftDownDelayTimer; // Shift pressing is really fast.
private bool paused;

internal static UE.Texture2D DefaultTexture
{
get { return defaultTexture; }
Expand All @@ -54,14 +62,27 @@ internal static void Inspect(object obj)

private void Awake()
{
if(referScreenWidth <=0 || referScreenHeight <= 0)
{
referScreenWidth = UE.Screen.width;
referScreenHeight = UE.Screen.height;
}

if(scaleFactorX > 0f && scaleFactorY > 0f)
{
// 高分辨率适应
Application.ScaleX = (float)UE.Screen.width / (float)referScreenWidth * scaleFactorX;
Application.ScaleY = (float)UE.Screen.height / (float)referScreenHeight * scaleFactorY;
}

defaultTexture = new UE.Texture2D(1, 1);
defaultTexture.SetPixel(0, 0, UE.Color.white);
defaultTexture.Apply();

transparentTexture = new UE.Texture2D(1, 1);
transparentTexture.SetPixel(0, 0, UE.Color.clear);
transparentTexture.Apply();

ApiHolder.Graphics = new UnityGdi();
ApiHolder.Input = new UnityInput();
ApiHolder.System = new UnitySystem();
Expand Down Expand Up @@ -144,10 +165,10 @@ private void Update()
var ueScreenWidth = UE.Screen.width;
var ueScreenHeight = UE.Screen.height;

Screen.width = (int) (ueScreenWidth / Application.ScaleX);
Screen.height = (int) (ueScreenHeight / Application.ScaleY);
Screen.width = (int) (ueScreenWidth / Application.ScaleX);
Screen.height = (int) (ueScreenHeight / Application.ScaleY);

if (controller == null) return;
if (controller == null) return;

if (lastWidth != ueScreenWidth || lastHeight != ueScreenHeight)
{
Expand Down