123 lines
3.5 KiB
C#
123 lines
3.5 KiB
C#
using System.Drawing;
|
|
using System.Text.Json.Serialization;
|
|
using WebmrAPI.Utils;
|
|
|
|
namespace WebmrAPI.Models
|
|
{
|
|
public class GeometryPoint
|
|
{
|
|
internal Point _point;
|
|
public static GeometryPoint Empty { get => new GeometryPoint(Point.Empty); }
|
|
|
|
public int X { get => _point.X; }
|
|
public int Y { get => _point.Y; }
|
|
|
|
public GeometryPoint(int x, int y)
|
|
{
|
|
_point = new Point(x, y);
|
|
}
|
|
public GeometryPoint(Point point)
|
|
{
|
|
_point = point;
|
|
}
|
|
}
|
|
|
|
public class BaseGeometry
|
|
{
|
|
protected Rectangle _rectangle;
|
|
|
|
public int Width { get => _rectangle.Width; }
|
|
public int Height { get => _rectangle.Height; }
|
|
public static BaseGeometry Empty { get => new BaseGeometry { _rectangle = Rectangle.Empty }; }
|
|
|
|
public static Geometry FromLTRB(int left, int top, int right, int bottom)
|
|
{
|
|
return new Geometry
|
|
{
|
|
_rectangle = Rectangle.FromLTRB(left, top, right, bottom)
|
|
};
|
|
}
|
|
|
|
public bool Contains(GeometryPoint pt)
|
|
{
|
|
return _rectangle.Contains(pt._point);
|
|
}
|
|
}
|
|
|
|
public class Geometry : BaseGeometry
|
|
{
|
|
public int X { get => _rectangle.X; }
|
|
public int Y { get => _rectangle.Y; }
|
|
public new static Geometry Empty { get => new Geometry { _rectangle = Rectangle.Empty }; }
|
|
}
|
|
|
|
public class BaseWindowInfo : ConcurrentObject
|
|
{
|
|
private IntPtr _hwnd;
|
|
private string _title = String.Empty;
|
|
private GeometryPoint _cursor = GeometryPoint.Empty;
|
|
private Geometry _gWindow = Geometry.Empty;
|
|
private BaseGeometry _gContent = BaseGeometry.Empty;
|
|
private bool _isActive;
|
|
|
|
public string Id
|
|
{
|
|
get => LockedGet(ref _hwnd).ToString();
|
|
set
|
|
{
|
|
if (!IntPtr.TryParse(value, out IntPtr hwnd))
|
|
throw new ArgumentException("Invalid window Id format. Must be a valid hwnd (IntPtr) string representation");
|
|
LockedSet(ref _hwnd, hwnd);
|
|
}
|
|
}
|
|
public string Title
|
|
{
|
|
get => LockedGet(ref _title);
|
|
set => LockedSet(ref _title, value);
|
|
}
|
|
public GeometryPoint CursorPosition
|
|
{
|
|
get => LockedGet(ref _cursor);
|
|
set => LockedSet(ref _cursor, value);
|
|
}
|
|
public Geometry WindowGeometry
|
|
{
|
|
get => LockedGet(ref _gWindow);
|
|
set => LockedSet(ref _gWindow, value);
|
|
}
|
|
public BaseGeometry ContentGeometry
|
|
{
|
|
get => LockedGet(ref _gContent);
|
|
set => LockedSet(ref _gContent, value);
|
|
}
|
|
public bool IsActive
|
|
{
|
|
get => LockedGet(ref _isActive);
|
|
set => LockedSet(ref _isActive, value);
|
|
}
|
|
[JsonIgnore]
|
|
public IntPtr Hwnd
|
|
{
|
|
get => LockedGet(ref _hwnd);
|
|
set => LockedSet(ref _hwnd, value);
|
|
}
|
|
public bool HasCursor { get => IsActive && ContentGeometry.Contains(CursorPosition); }
|
|
}
|
|
public class WindowInfo : BaseWindowInfo
|
|
{
|
|
private int _pid;
|
|
private int _threadId;
|
|
|
|
public int PID
|
|
{
|
|
get => LockedGet(ref _pid);
|
|
set => LockedSet(ref _pid, value);
|
|
}
|
|
public int ThreadId
|
|
{
|
|
get => LockedGet(ref _threadId);
|
|
set => LockedSet(ref _threadId, value);
|
|
}
|
|
}
|
|
}
|