Commit 65af35e8 authored by Gerard Gascón's avatar Gerard Gascón
Browse files

feat: Resizing properly working without taking delta magnitude into account

parent ce692af8
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -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;
		}
+1 −1
Original line number Diff line number Diff line
@@ -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;
			}
		}
+37 −16
Original line number Diff line number Diff line
@@ -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);

            if (resizeDirection.x < 0) {
                x += (int)resizeFactor;
            int width = 0;
            int height = 0;

            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);
                }
            int height = (int)(width / aspectRatio);
            if (resizeDirection.y < 0) {
                y += (int)resizeFactor;
            } 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);
+6 −6
Original line number Diff line number Diff line
@@ -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));