feat: Resizing properly working without taking delta magnitude into account

This commit is contained in:
Gerard Gascón 2024-04-16 11:44:37 +02:00
parent ce692af862
commit 65af35e8d5
4 changed files with 49 additions and 28 deletions

View file

@ -12,27 +12,27 @@ namespace SatorImaging.AppWindowUtility {
if (widthPercentage < marginWidthPercentage) {
if (heightPercentage > 1 - marginHeightPercentage)
return new Vector2(-1, 1);
if (heightPercentage < marginHeightPercentage)
return new Vector2(-1, -1);
if (heightPercentage < marginHeightPercentage)
return new Vector2(-1, 1);
return new Vector2(-1, 0);
}
if (widthPercentage > 1 - marginWidthPercentage) {
if (heightPercentage > 1 - marginHeightPercentage)
return new Vector2(1, 1);
if (heightPercentage < marginHeightPercentage)
return new Vector2(1, -1);
if (heightPercentage < marginHeightPercentage)
return new Vector2(1, 1);
return new Vector2(1, 0);
}
if (heightPercentage > 1 - marginHeightPercentage)
return new Vector2(0, 1);
return new Vector2(0, -1);
if (heightPercentage < marginHeightPercentage)
return new Vector2(0, -1);
return new Vector2(0, 1);
return Vector2.zero;
}

View file

@ -41,7 +41,7 @@ namespace SatorImaging.AppWindowUtility {
if (_resizeDirection.x < 0)
_targetPosition.x -= delta.x;
if (_resizeDirection.y < 0)
if (_resizeDirection.y > 0)
_targetPosition.y -= delta.y;
}
}

View file

@ -295,24 +295,45 @@ namespace SatorImaging.AppWindowUtility
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);
int width = 0;
int height = 0;
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);
if (resizeDirection.x > 0) {
if (resizeDirection.y > 0) {
width = (int)(rect.right - rect.left + deltaX);
height = (int)(width / aspectRatio);
}else if (resizeDirection.y < 0) {
width = (int)(rect.right - rect.left + deltaX);
height = (int)(width / aspectRatio);
}else {
width = (int)(rect.right - rect.left + deltaX);
height = (int)(width / aspectRatio);
}
}else if (resizeDirection.x < 0) {
if (resizeDirection.y > 0) {
x += (int)deltaX;
width = rect.right - x;
height = (int)(width / aspectRatio);
}else if (resizeDirection.y < 0) {
x += (int)deltaX;
width = rect.right - x;
height = (int)(width / aspectRatio);
}else {
x += (int)deltaX;
width = rect.right - x;
height = (int)(width / aspectRatio);
}
} else {
if (resizeDirection.y > 0) {
y += (int)deltaY;
height = rect.bottom - y;
width = (int)(height * aspectRatio);
}else if (resizeDirection.y < 0) {
height = (int)(rect.bottom - rect.top + deltaY);
width = (int)(height * aspectRatio);
}
}
WinApi.SetWindowPos(hWnd, IntPtr.Zero, x, y, width, height, WinApi.SetWindowPosFlags.NoFlag);

View file

@ -13,7 +13,7 @@ public class ResizeTest {
[Test]
public void CheckTopLeft() {
Vector2 mousePos = new(0, 1920);
Vector2 mousePos = new(0, 0);
Vector2 screenSize = new(1280, 1920);
Assert.AreEqual(new Vector2(-1, 1), ResizeHelper.GetDirection(mousePos, screenSize));
@ -21,7 +21,7 @@ public class ResizeTest {
[Test]
public void CheckTop() {
Vector2 mousePos = new(500, 1920);
Vector2 mousePos = new(500, 0);
Vector2 screenSize = new(1280, 1920);
Assert.AreEqual(new Vector2(0, 1), ResizeHelper.GetDirection(mousePos, screenSize));
@ -29,7 +29,7 @@ public class ResizeTest {
[Test]
public void CheckTopRight() {
Vector2 mousePos = new(1280, 1920);
Vector2 mousePos = new(1280, 0);
Vector2 screenSize = new(1280, 1920);
Assert.AreEqual(new Vector2(1, 1), ResizeHelper.GetDirection(mousePos, screenSize));
@ -53,7 +53,7 @@ public class ResizeTest {
[Test]
public void CheckBottomLeft() {
Vector2 mousePos = new(0, 0);
Vector2 mousePos = new(0, 1920);
Vector2 screenSize = new(1280, 1920);
Assert.AreEqual(new Vector2(-1, -1), ResizeHelper.GetDirection(mousePos, screenSize));
@ -61,7 +61,7 @@ public class ResizeTest {
[Test]
public void CheckBottom() {
Vector2 mousePos = new(500, 0);
Vector2 mousePos = new(500, 1920);
Vector2 screenSize = new(1280, 1920);
Assert.AreEqual(new Vector2(0, -1), ResizeHelper.GetDirection(mousePos, screenSize));
@ -69,7 +69,7 @@ public class ResizeTest {
[Test]
public void CheckBottomRight() {
Vector2 mousePos = new(1280, 0);
Vector2 mousePos = new(1280, 1920);
Vector2 screenSize = new(1280, 1920);
Assert.AreEqual(new Vector2(1, -1), ResizeHelper.GetDirection(mousePos, screenSize));