Add scaling for output
This commit is contained in:
parent
db52e10d48
commit
a5afc3f536
@ -17,6 +17,7 @@ public class Blur
|
||||
private readonly List<string> _blurPrograms = new();
|
||||
private readonly Dictionary<IntPtr, uint> _windowHandleSceneItems = new();
|
||||
private readonly ILogger? _logger;
|
||||
private float _scaleWidth = 1, _scaleHeight = 1;
|
||||
|
||||
public Blur(string obsUrl, string obsPassword, string[] enabledObsScenes, string[] blurPrograms, ILogger? logger = null)
|
||||
{
|
||||
@ -113,10 +114,10 @@ public class Blur
|
||||
|
||||
SceneItemTransformInfo info = new()
|
||||
{
|
||||
X = windowInfo.WindowRectangle.X,
|
||||
Y = windowInfo.WindowRectangle.Y,
|
||||
BoundsHeight = windowInfo.WindowRectangle.Height,
|
||||
BoundsWidth = windowInfo.WindowRectangle.Width,
|
||||
X = windowInfo.WindowRectangle.X * _scaleWidth,
|
||||
Y = windowInfo.WindowRectangle.Y * _scaleHeight,
|
||||
BoundsWidth = windowInfo.WindowRectangle.Width * _scaleWidth,
|
||||
BoundsHeight = windowInfo.WindowRectangle.Height * _scaleHeight,
|
||||
BoundsType = SceneItemBoundsType.OBS_BOUNDS_STRETCH,
|
||||
Alignnment = 5
|
||||
};
|
||||
@ -202,6 +203,25 @@ public class Blur
|
||||
}
|
||||
}
|
||||
|
||||
private void SetScaleFactors()
|
||||
{
|
||||
try
|
||||
{
|
||||
JObject response = _websocket.SendRequest("GetVideoSettings");
|
||||
if(!response.TryGetValue("baseWidth", out JToken? baseWidth) || !response.TryGetValue("baseHeight", out JToken? baseHeight))
|
||||
throw new KeyNotFoundException("Response missing key baseWidth or baseHeight");
|
||||
Rectangle desktopRectangle = _windowManager.GetDesktopRectangle();
|
||||
this._scaleWidth = baseWidth.Value<float>() / desktopRectangle.Width;
|
||||
this._scaleHeight = baseHeight.Value<float>() / desktopRectangle.Height;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger?.LogError(e, "Request 'GetVideoSettings'");
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void WindowManagerOnWindowZOrderChanged(IntPtr[] neworder)
|
||||
{
|
||||
|
||||
@ -237,6 +257,8 @@ public class Blur
|
||||
{
|
||||
_currentObsScene = _websocket.GetCurrentProgramScene();
|
||||
_logger?.LogInformation($"Obs Connected. Current Scene '{_currentObsScene}'");
|
||||
SetScaleFactors();
|
||||
_logger?.LogInformation($"Scale-Factors: Width={this._scaleWidth:F} Height={this._scaleHeight:F}");
|
||||
UpdateBlurs();
|
||||
}
|
||||
|
||||
|
@ -77,14 +77,17 @@ public partial class WindowManager : IDisposable
|
||||
if (windowTitle.Length < 1)
|
||||
return true;
|
||||
|
||||
Rectangle rect;
|
||||
GetWindowRect(windowHandle, out rect);
|
||||
GetWindowRect(windowHandle, out Rectangle rect);
|
||||
|
||||
_windows.Add(new WindowInfo(windowHandle, windowTitle, processInfo, placement.ShowCmd, rect));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Rectangle GetDesktopRectangle()
|
||||
{
|
||||
GetWindowRect(GetDesktopWindow(), out Rectangle rect);
|
||||
return rect;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user