mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-28 11:10:23 +12:00
Added IsValid method to CursorData
This commit is contained in:
parent
898daf4cc5
commit
59aee065f1
|
@ -35,6 +35,8 @@ public class CursorData : IDisposable
|
||||||
public bool IsVisible { get; private set; }
|
public bool IsVisible { get; private set; }
|
||||||
public Point Position { get; private set; }
|
public Point Position { get; private set; }
|
||||||
|
|
||||||
|
public bool IsValid => Handle != IntPtr.Zero && IsVisible;
|
||||||
|
|
||||||
public CursorData()
|
public CursorData()
|
||||||
{
|
{
|
||||||
UpdateCursorData();
|
UpdateCursorData();
|
||||||
|
@ -73,14 +75,14 @@ public void UpdateCursorData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawCursorToImage(Image img)
|
public void DrawCursor(Image img)
|
||||||
{
|
{
|
||||||
DrawCursorToImage(img, Point.Empty);
|
DrawCursor(img, Point.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawCursorToImage(Image img, Point cursorOffset)
|
public void DrawCursor(Image img, Point cursorOffset)
|
||||||
{
|
{
|
||||||
if (Handle != IntPtr.Zero)
|
if (IsValid)
|
||||||
{
|
{
|
||||||
Point drawPosition = new Point(Position.X - cursorOffset.X, Position.Y - cursorOffset.Y);
|
Point drawPosition = new Point(Position.X - cursorOffset.X, Position.Y - cursorOffset.Y);
|
||||||
|
|
||||||
|
@ -92,16 +94,17 @@ public void DrawCursorToImage(Image img, Point cursorOffset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawCursorToHandle(IntPtr hdcDest)
|
public void DrawCursor(IntPtr hdcDest)
|
||||||
{
|
{
|
||||||
DrawCursorToHandle(hdcDest, Point.Empty);
|
DrawCursor(hdcDest, Point.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawCursorToHandle(IntPtr hdcDest, Point cursorOffset)
|
public void DrawCursor(IntPtr hdcDest, Point cursorOffset)
|
||||||
{
|
{
|
||||||
if (Handle != IntPtr.Zero)
|
if (IsValid)
|
||||||
{
|
{
|
||||||
Point drawPosition = new Point(Position.X - cursorOffset.X, Position.Y - cursorOffset.Y);
|
Point drawPosition = new Point(Position.X - cursorOffset.X, Position.Y - cursorOffset.Y);
|
||||||
|
|
||||||
NativeMethods.DrawIconEx(hdcDest, drawPosition.X, drawPosition.Y, Handle, 0, 0, 0, IntPtr.Zero, NativeConstants.DI_NORMAL);
|
NativeMethods.DrawIconEx(hdcDest, drawPosition.X, drawPosition.Y, Handle, 0, 0, 0, IntPtr.Zero, NativeConstants.DI_NORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,7 +135,7 @@ private Image CaptureRectangleNative(IntPtr handle, Rectangle rect, bool capture
|
||||||
{
|
{
|
||||||
using (CursorData cursorData = new CursorData())
|
using (CursorData cursorData = new CursorData())
|
||||||
{
|
{
|
||||||
cursorData.DrawCursorToHandle(hdcDest, cursorOffset);
|
cursorData.DrawCursor(hdcDest, cursorOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
|
@ -47,7 +47,7 @@ public Image CaptureWindowTransparent(IntPtr handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap whiteBackground = null, blackBackground = null, whiteBackground2 = null;
|
Bitmap whiteBackground = null, blackBackground = null, whiteBackground2 = null;
|
||||||
CursorData cursor = null;
|
CursorData cursorData = null;
|
||||||
bool isTransparent = false, isTaskbarHide = false;
|
bool isTransparent = false, isTaskbarHide = false;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -61,7 +61,7 @@ public Image CaptureWindowTransparent(IntPtr handle)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cursor = new CursorData();
|
cursorData = new CursorData();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -119,10 +119,10 @@ public Image CaptureWindowTransparent(IntPtr handle)
|
||||||
transparentImage = whiteBackground2;
|
transparentImage = whiteBackground2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cursor != null && cursor.IsVisible)
|
if (cursorData != null && cursorData.IsValid)
|
||||||
{
|
{
|
||||||
Point cursorOffset = CaptureHelpers.ScreenToClient(rect.Location);
|
Point cursorOffset = CaptureHelpers.ScreenToClient(rect.Location);
|
||||||
cursor.DrawCursorToImage(transparentImage, cursorOffset);
|
cursorData.DrawCursor(transparentImage, cursorOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isTransparent)
|
if (isTransparent)
|
||||||
|
@ -147,7 +147,7 @@ public Image CaptureWindowTransparent(IntPtr handle)
|
||||||
if (whiteBackground != null) whiteBackground.Dispose();
|
if (whiteBackground != null) whiteBackground.Dispose();
|
||||||
if (blackBackground != null) blackBackground.Dispose();
|
if (blackBackground != null) blackBackground.Dispose();
|
||||||
if (isTransparent && whiteBackground2 != null) whiteBackground2.Dispose();
|
if (isTransparent && whiteBackground2 != null) whiteBackground2.Dispose();
|
||||||
if (cursor != null) cursor.Dispose();
|
if (cursorData != null) cursorData.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ protected ImageInfo ExecuteRegionCapture(TaskSettings taskSettings)
|
||||||
|
|
||||||
form.Prepare(img);
|
form.Prepare(img);
|
||||||
|
|
||||||
if (cursorData != null && cursorData.IsVisible)
|
if (cursorData != null && cursorData.IsValid)
|
||||||
{
|
{
|
||||||
form.AddCursor(cursorData.Handle, cursorData.Position);
|
form.AddCursor(cursorData.Handle, cursorData.Position);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue