Code refactoring

This commit is contained in:
Jaex 2023-02-15 01:08:29 +03:00
parent 1db78477c1
commit 713b1f4beb
4 changed files with 17 additions and 7 deletions

View file

@ -464,6 +464,18 @@ public static Point GetPosition(ContentAlignment placement, int offset, Size bac
return GetPosition(placement, new Point(offset, offset), backgroundSize, objectSize); return GetPosition(placement, new Point(offset, offset), backgroundSize, objectSize);
} }
public static Point GetPosition(ContentAlignment placement, int offset, Rectangle background, Size objectSize)
{
return GetPosition(placement, new Point(offset, offset), background, objectSize);
}
public static Point GetPosition(ContentAlignment placement, Point offset, Rectangle background, Size objectSize)
{
Point position = GetPosition(placement, offset, background.Size, objectSize);
return new Point(background.X + position.X, background.Y + position.Y);
}
public static Point GetPosition(ContentAlignment placement, Point offset, Size backgroundSize, Size objectSize) public static Point GetPosition(ContentAlignment placement, Point offset, Size backgroundSize, Size objectSize)
{ {
int midX = (int)Math.Round((backgroundSize.Width / 2f) - (objectSize.Width / 2f)); int midX = (int)Math.Round((backgroundSize.Width / 2f) - (objectSize.Width / 2f));

View file

@ -70,7 +70,7 @@ private DropForm(int size, int offset, ContentAlignment alignment, int opacity,
backgroundImage = DrawDropImage(DropSize); backgroundImage = DrawDropImage(DropSize);
Location = Helpers.GetPosition(DropAlignment, DropOffset, Screen.PrimaryScreen.WorkingArea.Size, backgroundImage.Size); Location = Helpers.GetPosition(DropAlignment, DropOffset, Screen.PrimaryScreen.WorkingArea, backgroundImage.Size);
SelectBitmap(backgroundImage, DropOpacity); SelectBitmap(backgroundImage, DropOpacity);
} }

View file

@ -136,10 +136,10 @@ public void LoadConfig(NotificationFormConfig config)
buffer = new Bitmap(Config.Size.Width, Config.Size.Height); buffer = new Bitmap(Config.Size.Width, Config.Size.Height);
gBuffer = Graphics.FromImage(buffer); gBuffer = Graphics.FromImage(buffer);
Point position = Helpers.GetPosition(Config.Placement, Config.Offset, Screen.PrimaryScreen.WorkingArea.Size, Config.Size); Point position = Helpers.GetPosition(Config.Placement, Config.Offset, Screen.PrimaryScreen.WorkingArea, Config.Size);
NativeMethods.SetWindowPos(Handle, (IntPtr)SpecialWindowHandles.HWND_TOPMOST, position.X + Screen.PrimaryScreen.WorkingArea.X, NativeMethods.SetWindowPos(Handle, (IntPtr)SpecialWindowHandles.HWND_TOPMOST, position.X, position.Y, Config.Size.Width, Config.Size.Height,
position.Y + Screen.PrimaryScreen.WorkingArea.Y, Config.Size.Width, Config.Size.Height, SetWindowPosFlags.SWP_NOACTIVATE); SetWindowPosFlags.SWP_NOACTIVATE);
tDuration.Stop(); tDuration.Stop();
tOpacity.Stop(); tOpacity.Stop();

View file

@ -140,9 +140,7 @@ private PinToScreenForm(Image image, PinToScreenOptions options, Point? location
} }
else else
{ {
Rectangle rectActiveScreen = CaptureHelpers.GetActiveScreenWorkingArea(); Location = Helpers.GetPosition(Options.Placement, Options.PlacementOffset, CaptureHelpers.GetActiveScreenWorkingArea(), ImageSize);
Point position = Helpers.GetPosition(Options.Placement, Options.PlacementOffset, rectActiveScreen.Size, ImageSize);
Location = new Point(rectActiveScreen.X + position.X, rectActiveScreen.Y + position.Y);
} }
} }