feat: basic window resizing

This commit is contained in:
Gerard Gascón 2024-04-16 01:07:26 +02:00
parent 438b16fc6e
commit ce692af862
18 changed files with 324 additions and 74 deletions

View file

@ -273,7 +273,7 @@ namespace SatorImaging.AppWindowUtility
public void ResizeWindowRelative(int relativeWidth, int relativeHeight)
public void ResizeWindow(int width, int height)
{
if (AppWindowUtility.FullScreen) return;
@ -282,12 +282,41 @@ namespace SatorImaging.AppWindowUtility
WinApi.SetWindowPos(hWnd, IntPtr.Zero,
rect.left,
rect.top,
relativeWidth,
relativeHeight,
width,
height,
WinApi.SetWindowPosFlags.NoFlag //ApiWindows.SetWindowPosFlags.IgnoreMove
);
}//
}
public void ResizeWindowRelative(float deltaX, float deltaY, Vector2 resizeDirection, float aspectRatio) {
if (AppWindowUtility.FullScreen) return;
WinApi.RECT rect;
WinApi.GetWindowRect(hWnd, out rect);
float resizeFactor = Mathf.Abs(resizeDirection.x) > Mathf.Abs(resizeDirection.y)
? deltaX
: deltaY;
int x = rect.left;
int y = rect.top;
int width = (int)(rect.right - rect.left + resizeFactor);
//int height = (int)(rect.bottom - rect.top + deltaY);
if (resizeDirection.x < 0) {
x += (int)resizeFactor;
width = rect.right - x;
}
int height = (int)(width / aspectRatio);
if (resizeDirection.y < 0) {
y += (int)resizeFactor;
height = rect.bottom - y;
width = (int)(height * aspectRatio);
}
WinApi.SetWindowPos(hWnd, IntPtr.Zero, x, y, width, height, WinApi.SetWindowPosFlags.NoFlag);
}