mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-02 13:10:22 +12:00
#5055: Get cursor size from registry and use it while drawing
This commit is contained in:
parent
63922f8025
commit
8984913049
|
@ -33,6 +33,7 @@ public class CursorData
|
||||||
{
|
{
|
||||||
public IntPtr Handle { get; private set; }
|
public IntPtr Handle { get; private set; }
|
||||||
public Point Position { get; private set; }
|
public Point Position { get; private set; }
|
||||||
|
public Size Size { get; private set; }
|
||||||
public bool IsVisible { get; private set; }
|
public bool IsVisible { get; private set; }
|
||||||
|
|
||||||
public CursorData()
|
public CursorData()
|
||||||
|
@ -53,6 +54,7 @@ public void UpdateCursorData()
|
||||||
{
|
{
|
||||||
Handle = cursorInfo.hCursor;
|
Handle = cursorInfo.hCursor;
|
||||||
Position = cursorInfo.ptScreenPos;
|
Position = cursorInfo.ptScreenPos;
|
||||||
|
Size = GetCursorSize();
|
||||||
IsVisible = cursorInfo.flags == NativeConstants.CURSOR_SHOWING;
|
IsVisible = cursorInfo.flags == NativeConstants.CURSOR_SHOWING;
|
||||||
|
|
||||||
if (IsVisible)
|
if (IsVisible)
|
||||||
|
@ -82,6 +84,19 @@ public void UpdateCursorData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Size GetCursorSize()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int cursorBaseSize = RegistryHelpers.GetValueDWord(@"Control Panel\Cursors", "CursorBaseSize");
|
||||||
|
return new Size(cursorBaseSize, cursorBaseSize);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return Size.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void DrawCursor(Image img)
|
public void DrawCursor(Image img)
|
||||||
{
|
{
|
||||||
DrawCursor(img, Point.Empty);
|
DrawCursor(img, Point.Empty);
|
||||||
|
@ -91,13 +106,11 @@ public void DrawCursor(Image img, Point offset)
|
||||||
{
|
{
|
||||||
if (IsVisible)
|
if (IsVisible)
|
||||||
{
|
{
|
||||||
Point drawPosition = new Point(Position.X - offset.X, Position.Y - offset.Y);
|
|
||||||
drawPosition = CaptureHelpers.ScreenToClient(drawPosition);
|
|
||||||
|
|
||||||
using (Graphics g = Graphics.FromImage(img))
|
using (Graphics g = Graphics.FromImage(img))
|
||||||
using (Icon icon = Icon.FromHandle(Handle))
|
|
||||||
{
|
{
|
||||||
g.DrawIcon(icon, drawPosition.X, drawPosition.Y);
|
IntPtr hdcDest = g.GetHdc();
|
||||||
|
|
||||||
|
DrawCursor(hdcDest, offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,7 +127,7 @@ public void DrawCursor(IntPtr hdcDest, Point offset)
|
||||||
Point drawPosition = new Point(Position.X - offset.X, Position.Y - offset.Y);
|
Point drawPosition = new Point(Position.X - offset.X, Position.Y - offset.Y);
|
||||||
drawPosition = CaptureHelpers.ScreenToClient(drawPosition);
|
drawPosition = CaptureHelpers.ScreenToClient(drawPosition);
|
||||||
|
|
||||||
NativeMethods.DrawIconEx(hdcDest, drawPosition.X, drawPosition.Y, Handle, 0, 0, 0, IntPtr.Zero, NativeConstants.DI_NORMAL);
|
NativeMethods.DrawIconEx(hdcDest, drawPosition.X, drawPosition.Y, Handle, Size.Width, Size.Height, 0, IntPtr.Zero, NativeConstants.DI_NORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue