Preserve screen location

This commit is contained in:
Jaex 2022-08-02 18:11:38 +03:00
parent d252c9345e
commit ad35e2389c
5 changed files with 26 additions and 13 deletions

View file

@ -115,7 +115,7 @@ public static float GetCursorSizeMultiplier()
if (cursorSize != null && cursorSize > 1)
{
sizeMultiplier = 1f + (((int)cursorSize - 1) * 0.5f);
sizeMultiplier = 1f + ((cursorSize.Value - 1) * 0.5f);
}
return sizeMultiplier;

View file

@ -44,7 +44,7 @@ public static Bitmap GetRegionImage(RegionCaptureOptions options = null)
}
}
public static bool GetRectangleRegion(out Rectangle rect, RegionCaptureOptions options)
public static bool GetRectangleRegion(out Rectangle rect, RegionCaptureOptions options = null)
{
return GetRectangleRegion(out rect, out _, options);
}

View file

@ -1283,19 +1283,19 @@ public static void PinToScreen()
{
if (form.ShowDialog() == DialogResult.OK)
{
PinToScreen(form.Image);
PinToScreen(form.Image, form.PinToScreenLocation);
}
}
}
public static void PinToScreen(Image image)
public static void PinToScreen(Image image, Point? location = null)
{
if (image != null)
{
PinToScreenOptions options = new PinToScreenOptions();
options.BackgroundColor = ShareXResources.Theme.LightBackgroundColor;
PinToScreenForm form = new PinToScreenForm(image, options);
PinToScreenForm form = new PinToScreenForm(image, options, location);
form.Show();
}
}

View file

@ -122,13 +122,20 @@ private PinToScreenForm(PinToScreenOptions options)
loaded = true;
}
public PinToScreenForm(Image image, PinToScreenOptions options) : this(options)
public PinToScreenForm(Image image, PinToScreenOptions options, Point? location = null) : this(options)
{
Image = image;
AutoSizeForm();
Rectangle rectScreen = CaptureHelpers.GetActiveScreenWorkingArea();
Location = Helpers.GetPosition(Options.Placement, Options.PlacementOffset, rectScreen.Size, ImageSize);
if (location != null)
{
Location = location.Value;
}
else
{
Rectangle rectScreen = CaptureHelpers.GetActiveScreenWorkingArea();
Location = Helpers.GetPosition(Options.Placement, Options.PlacementOffset, rectScreen.Size, ImageSize);
}
}
protected override void Dispose(bool disposing)

View file

@ -35,6 +35,7 @@ namespace ShareX
public partial class PinToScreenStartupForm : Form
{
public Bitmap Image { get; private set; }
public Point? PinToScreenLocation { get; private set; }
public PinToScreenStartupForm()
{
@ -59,12 +60,17 @@ private void btnFromClipboard_Click(object sender, EventArgs e)
private void btnFromScreen_Click(object sender, EventArgs e)
{
Image = RegionCaptureTasks.GetRegionImage();
if (Image != null)
if (RegionCaptureTasks.GetRectangleRegion(out Rectangle rect))
{
DialogResult = DialogResult.OK;
Close();
Image = new Screenshot().CaptureRectangle(rect);
if (Image != null)
{
PinToScreenLocation = rect.Location;
DialogResult = DialogResult.OK;
Close();
}
}
}