Fix coordinate issues

This commit is contained in:
Jaex 2022-02-24 12:06:13 +03:00
parent 71bb25133c
commit 7efc14112c
3 changed files with 11 additions and 31 deletions

View file

@ -42,7 +42,7 @@ public static Rectangle GetScreenWorkingArea()
return Screen.AllScreens.Select(x => x.WorkingArea).Combine();
}
public static Rectangle GetScreenBounds2()
private static Rectangle GetScreenBounds2()
{
Point topLeft = Point.Empty;
Point bottomRight = Point.Empty;
@ -58,7 +58,7 @@ public static Rectangle GetScreenBounds2()
return new Rectangle(topLeft.X, topLeft.Y, bottomRight.X + Math.Abs(topLeft.X), bottomRight.Y + Math.Abs(topLeft.Y));
}
public static Rectangle GetScreenBounds3()
private static Rectangle GetScreenBounds3()
{
Point topLeft = Point.Empty;
Point bottomRight = Point.Empty;
@ -74,7 +74,7 @@ public static Rectangle GetScreenBounds3()
return new Rectangle(topLeft.X, topLeft.Y, bottomRight.X + Math.Abs(topLeft.X), bottomRight.Y + Math.Abs(topLeft.Y));
}
public static Rectangle GetScreenBounds4()
private static Rectangle GetScreenBounds4()
{
return Screen.AllScreens.Select(x => x.Bounds).Combine();
}
@ -94,21 +94,6 @@ public static Rectangle GetPrimaryScreenBounds()
return Screen.PrimaryScreen.Bounds;
}
public static Rectangle GetScreenBounds0Based()
{
return ScreenToClient(GetScreenBounds());
}
public static Rectangle GetActiveScreenBounds0Based()
{
return ScreenToClient(GetActiveScreenBounds());
}
public static Rectangle GetPrimaryScreenBounds0Based()
{
return ScreenToClient(GetPrimaryScreenBounds());
}
public static Point ScreenToClient(Point p)
{
int screenX = NativeMethods.GetSystemMetrics(SystemMetric.SM_XVIRTUALSCREEN);
@ -143,11 +128,6 @@ public static Point GetCursorPosition()
return Point.Empty;
}
public static Point GetZeroBasedMousePosition()
{
return ScreenToClient(GetCursorPosition());
}
public static void SetCursorPosition(int x, int y)
{
NativeMethods.SetCursorPos(x, y);
@ -188,8 +168,8 @@ public static bool CheckPixelColor(int x, int y, Color color, byte variation)
Color targetColor = GetPixelColor(x, y);
return targetColor.R.IsBetween((byte)(color.R - variation), (byte)(color.R + variation)) &&
targetColor.G.IsBetween((byte)(color.G - variation), (byte)(color.G + variation)) &&
targetColor.B.IsBetween((byte)(color.B - variation), (byte)(color.B + variation));
targetColor.G.IsBetween((byte)(color.G - variation), (byte)(color.G + variation)) &&
targetColor.B.IsBetween((byte)(color.B - variation), (byte)(color.B + variation));
}
public static Rectangle CreateRectangle(int x, int y, int x2, int y2)

View file

@ -1303,17 +1303,17 @@ private void DrawCursorGraphics(Graphics g)
}
Point mousePos = InputManager.ClientMousePosition;
Rectangle currentScreenRect0Based = CaptureHelpers.GetActiveScreenBounds0Based();
Rectangle activeScreenClientRect = RectangleToClient(CaptureHelpers.GetActiveScreenBounds());
int x = mousePos.X + cursorOffsetX;
if (x + totalSize.Width > currentScreenRect0Based.Right)
if (x + totalSize.Width > activeScreenClientRect.Right)
{
x = mousePos.X - cursorOffsetX - totalSize.Width;
}
int y = mousePos.Y + cursorOffsetY;
if (y + totalSize.Height > currentScreenRect0Based.Bottom)
if (y + totalSize.Height > activeScreenClientRect.Bottom)
{
y = mousePos.Y - cursorOffsetY - totalSize.Height;
}
@ -1537,7 +1537,7 @@ public Bitmap GetResultImage()
}
else if (Result == RegionResult.ActiveMonitor)
{
Rectangle activeScreenRect = CaptureHelpers.GetActiveScreenBounds0Based();
Rectangle activeScreenRect = RectangleToClient(CaptureHelpers.GetActiveScreenBounds());
using (Bitmap bmp = ShapeManager.RenderOutputImage(Canvas))
{

View file

@ -175,8 +175,8 @@ public static Bitmap ApplyRegionPathToImage(Bitmap bmp, GraphicsPath gp, out Rec
if (bmp != null && gp != null)
{
Rectangle regionArea = Rectangle.Round(gp.GetBounds());
Rectangle screenRectangle = CaptureHelpers.GetScreenBounds0Based();
resultArea = Rectangle.Intersect(regionArea, screenRectangle);
Rectangle screenRectangle = CaptureHelpers.GetScreenBounds();
resultArea = Rectangle.Intersect(regionArea, new Rectangle(0, 0, screenRectangle.Width, screenRectangle.Height));
if (resultArea.IsValid())
{