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 List<string> _blurPrograms = new();
|
||||||
private readonly Dictionary<IntPtr, uint> _windowHandleSceneItems = new();
|
private readonly Dictionary<IntPtr, uint> _windowHandleSceneItems = new();
|
||||||
private readonly ILogger? _logger;
|
private readonly ILogger? _logger;
|
||||||
|
private float _scaleWidth = 1, _scaleHeight = 1;
|
||||||
|
|
||||||
public Blur(string obsUrl, string obsPassword, string[] enabledObsScenes, string[] blurPrograms, ILogger? logger = null)
|
public Blur(string obsUrl, string obsPassword, string[] enabledObsScenes, string[] blurPrograms, ILogger? logger = null)
|
||||||
{
|
{
|
||||||
@ -113,10 +114,10 @@ public class Blur
|
|||||||
|
|
||||||
SceneItemTransformInfo info = new()
|
SceneItemTransformInfo info = new()
|
||||||
{
|
{
|
||||||
X = windowInfo.WindowRectangle.X,
|
X = windowInfo.WindowRectangle.X * _scaleWidth,
|
||||||
Y = windowInfo.WindowRectangle.Y,
|
Y = windowInfo.WindowRectangle.Y * _scaleHeight,
|
||||||
BoundsHeight = windowInfo.WindowRectangle.Height,
|
BoundsWidth = windowInfo.WindowRectangle.Width * _scaleWidth,
|
||||||
BoundsWidth = windowInfo.WindowRectangle.Width,
|
BoundsHeight = windowInfo.WindowRectangle.Height * _scaleHeight,
|
||||||
BoundsType = SceneItemBoundsType.OBS_BOUNDS_STRETCH,
|
BoundsType = SceneItemBoundsType.OBS_BOUNDS_STRETCH,
|
||||||
Alignnment = 5
|
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)
|
private void WindowManagerOnWindowZOrderChanged(IntPtr[] neworder)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -237,6 +257,8 @@ public class Blur
|
|||||||
{
|
{
|
||||||
_currentObsScene = _websocket.GetCurrentProgramScene();
|
_currentObsScene = _websocket.GetCurrentProgramScene();
|
||||||
_logger?.LogInformation($"Obs Connected. Current Scene '{_currentObsScene}'");
|
_logger?.LogInformation($"Obs Connected. Current Scene '{_currentObsScene}'");
|
||||||
|
SetScaleFactors();
|
||||||
|
_logger?.LogInformation($"Scale-Factors: Width={this._scaleWidth:F} Height={this._scaleHeight:F}");
|
||||||
UpdateBlurs();
|
UpdateBlurs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,14 +77,17 @@ public partial class WindowManager : IDisposable
|
|||||||
if (windowTitle.Length < 1)
|
if (windowTitle.Length < 1)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Rectangle rect;
|
GetWindowRect(windowHandle, out Rectangle rect);
|
||||||
GetWindowRect(windowHandle, out rect);
|
|
||||||
|
|
||||||
_windows.Add(new WindowInfo(windowHandle, windowTitle, processInfo, placement.ShowCmd, rect));
|
_windows.Add(new WindowInfo(windowHandle, windowTitle, processInfo, placement.ShowCmd, rect));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Rectangle GetDesktopRectangle()
|
||||||
|
{
|
||||||
|
GetWindowRect(GetDesktopWindow(), out Rectangle rect);
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user