Browse Source

Use Dapplo for screens on launching FSG

pull/458/head
Joseph Finney 1 year ago
parent
commit
a62153942c
  1. 1
      Text-Grab/Text-Grab.csproj
  2. 29
      Text-Grab/Utilities/WindowUtilities.cs

1
Text-Grab/Text-Grab.csproj

@ -68,6 +68,7 @@
<ItemGroup>
<PackageReference Include="CliWrap" Version="3.6.6" />
<PackageReference Include="Dapplo.Windows.User32" Version="1.0.28" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
<PackageReference Include="System.Drawing.Common" Version="9.0.0-preview.1.24081.2" />

29
Text-Grab/Utilities/WindowUtilities.cs

@ -1,14 +1,12 @@
using System;
using Dapplo.Windows.User32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Text_Grab.Properties;
using Text_Grab.Views;
// using Screen = System.Windows.Forms.Screen;
using WpfScreenHelper;
using static OSInterop;
namespace Text_Grab.Utilities;
@ -47,15 +45,18 @@ public static class WindowUtilities
couldParseAll = double.TryParse(storedPosition[2], out double parsedWid);
couldParseAll = double.TryParse(storedPosition[3], out double parsedHei);
Rect storedSize = new((int)parsedX, (int)parsedY, (int)parsedWid, (int)parsedHei);
IEnumerable<Screen> allScreens = Screen.AllScreens;
DisplayInfo[] allScreens = DisplayInfo.AllDisplayInfos;
WindowCollection allWindows = Application.Current.Windows;
if (parsedHei < 10 || parsedWid < 10)
return;
foreach (Screen screen in allScreens)
if (screen.WpfBounds.IntersectsWith(storedSize))
foreach (DisplayInfo screen in allScreens)
{
Rect screenRect = screen.Bounds;
if (screenRect.IntersectsWith(storedSize))
isStoredRectWithinScreen = true;
}
if (isStoredRectWithinScreen && couldParseAll)
{
@ -71,7 +72,7 @@ public static class WindowUtilities
public static void LaunchFullScreenGrab(TextBox? destinationTextBox = null)
{
IEnumerable<Screen> allScreens = Screen.AllScreens;
DisplayInfo[] allScreens = DisplayInfo.AllDisplayInfos;
WindowCollection allWindows = Application.Current.Windows;
List<FullscreenGrab> allFullscreenGrab = new();
@ -93,7 +94,7 @@ public static class WindowUtilities
double sideLength = 40;
foreach (Screen screen in allScreens)
foreach (DisplayInfo screen in allScreens)
{
FullscreenGrab fullScreenGrab = allFullscreenGrab[count];
fullScreenGrab.WindowStartupLocation = WindowStartupLocation.Manual;
@ -102,7 +103,8 @@ public static class WindowUtilities
fullScreenGrab.DestinationTextBox = destinationTextBox;
fullScreenGrab.WindowState = WindowState.Normal;
Point screenCenterPoint = screen.GetCenterPoint();
Rect screenRect = screen.Bounds;
Point screenCenterPoint = screenRect.CenterPoint();
fullScreenGrab.Left = screenCenterPoint.X - (sideLength / 2);
fullScreenGrab.Top = screenCenterPoint.Y - (sideLength / 2);
@ -114,10 +116,11 @@ public static class WindowUtilities
}
}
public static Point GetCenterPoint(this Screen screen)
public static Point GetCenterPoint(this DisplayInfo screen)
{
double x = screen.WpfBounds.Left + (screen.WpfBounds.Width / 2);
double y = screen.WpfBounds.Top + (screen.WpfBounds.Height / 2);
Rect screenRect = screen.Bounds;
double x = screenRect.Left + (screenRect.Width / 2);
double y = screenRect.Top + (screenRect.Height / 2);
return new(x, y);
}

Loading…
Cancel
Save