From 60e59543244e3ae0021358270ec70322273c7f28 Mon Sep 17 00:00:00 2001 From: XangelMusic Date: Sun, 28 Apr 2024 20:18:44 +0800 Subject: [PATCH 1/2] boost(banner): Added Center Position --- .../Framework/Banner/BannerPositionEnum.cs | 3 +- .../Framework/Banner/BannerPositionFactory.cs | 1 + .../Framework/Banner/Position/APosition.cs | 3 +- .../Banner/Position/PositionBottomCenter.cs | 2 +- .../Banner/Position/PositionCenter.cs | 34 +++++++++++++++++++ .../Banner/Position/PositionTopCenter.cs | 2 +- .../Localization/SettingsStrings.Designer.cs | 9 +++++ SoundSwitch/Localization/SettingsStrings.resx | 3 ++ 8 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 SoundSwitch/Framework/Banner/Position/PositionCenter.cs diff --git a/SoundSwitch/Framework/Banner/BannerPositionEnum.cs b/SoundSwitch/Framework/Banner/BannerPositionEnum.cs index c07fcff1fa..a7c09403ba 100644 --- a/SoundSwitch/Framework/Banner/BannerPositionEnum.cs +++ b/SoundSwitch/Framework/Banner/BannerPositionEnum.cs @@ -21,6 +21,7 @@ public enum BannerPositionEnum TopRight = 2, BottomLeft = 3, BottomCenter = 4, - BottomRight = 5 + BottomRight = 5, + Center = 6 } } \ No newline at end of file diff --git a/SoundSwitch/Framework/Banner/BannerPositionFactory.cs b/SoundSwitch/Framework/Banner/BannerPositionFactory.cs index 15267e3283..1a344f82db 100644 --- a/SoundSwitch/Framework/Banner/BannerPositionFactory.cs +++ b/SoundSwitch/Framework/Banner/BannerPositionFactory.cs @@ -25,6 +25,7 @@ public class BannerPositionFactory : AbstractFactory screen.Bounds.X + 50; public int PositionBottom(Screen screen, int height, int offset) => screen.Bounds.Height - height - PositionTop(screen, 0) - offset; public int PositionRight(Screen screen, int width) => screen.Bounds.Width - width - PositionLeft(screen); - public int PositionCenter(Screen screen, int width) => (screen.Bounds.Width - width) / 2; + public int PositionCenterH(Screen screen, int width) => (screen.Bounds.Width - width) / 2; + public int PositionCenterV(Screen screen, int height) => (screen.Bounds.Height - height) / 2; } } \ No newline at end of file diff --git a/SoundSwitch/Framework/Banner/Position/PositionBottomCenter.cs b/SoundSwitch/Framework/Banner/Position/PositionBottomCenter.cs index 9912a31c32..67020e9bbe 100644 --- a/SoundSwitch/Framework/Banner/Position/PositionBottomCenter.cs +++ b/SoundSwitch/Framework/Banner/Position/PositionBottomCenter.cs @@ -26,7 +26,7 @@ internal class PositionBottomCenter : APosition, IPosition public Point GetScreenPosition(Screen screen, int height, int width, int offset) { return new Point( - PositionCenter(screen, width), + PositionCenterH(screen, width), PositionBottom(screen, height, offset) ); } diff --git a/SoundSwitch/Framework/Banner/Position/PositionCenter.cs b/SoundSwitch/Framework/Banner/Position/PositionCenter.cs new file mode 100644 index 0000000000..9917109b9e --- /dev/null +++ b/SoundSwitch/Framework/Banner/Position/PositionCenter.cs @@ -0,0 +1,34 @@ +/******************************************************************** + * Copyright (C) 2015-2017 Antoine Aflalo + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + ********************************************************************/ + +using System.Drawing; +using System.Windows.Forms; +using SoundSwitch.Localization; + +namespace SoundSwitch.Framework.Banner.Position +{ + internal class PositionCenter : APosition, IPosition + { + public BannerPositionEnum TypeEnum => BannerPositionEnum.Center; + public string Label => SettingsStrings.position_option_center; + + public Point GetScreenPosition(Screen screen, int height, int width, int offset) + { + return new Point( + PositionCenterH(screen, width), + PositionCenterV(screen, height) + ); + } + } +} \ No newline at end of file diff --git a/SoundSwitch/Framework/Banner/Position/PositionTopCenter.cs b/SoundSwitch/Framework/Banner/Position/PositionTopCenter.cs index 7a1289cdba..056b4613fd 100644 --- a/SoundSwitch/Framework/Banner/Position/PositionTopCenter.cs +++ b/SoundSwitch/Framework/Banner/Position/PositionTopCenter.cs @@ -26,7 +26,7 @@ internal class PositionTopCenter : APosition, IPosition public Point GetScreenPosition(Screen screen, int height, int width, int offset) { return new Point( - PositionCenter(screen, width), + PositionCenterH(screen, width), PositionTop(screen, offset) ); } diff --git a/SoundSwitch/Localization/SettingsStrings.Designer.cs b/SoundSwitch/Localization/SettingsStrings.Designer.cs index e843e2c53f..242fb7a38a 100644 --- a/SoundSwitch/Localization/SettingsStrings.Designer.cs +++ b/SoundSwitch/Localization/SettingsStrings.Designer.cs @@ -646,6 +646,15 @@ internal static string position_option_bottomRight { } } + /// + /// Looks up a localized string similar to Center. + /// + internal static string position_option_center { + get { + return ResourceManager.GetString("position.option.center", resourceCulture); + } + } + /// /// Looks up a localized string similar to Top Center. /// diff --git a/SoundSwitch/Localization/SettingsStrings.resx b/SoundSwitch/Localization/SettingsStrings.resx index 336c840371..2dade14723 100644 --- a/SoundSwitch/Localization/SettingsStrings.resx +++ b/SoundSwitch/Localization/SettingsStrings.resx @@ -558,4 +558,7 @@ Restore the state of the system when the application is closed. If you need any help or further troubleshooting with SoundSwitch, you can visit the Help Discussion or Community Discord link, or help support us by visiting the Donate link below. + + Center + \ No newline at end of file From dc30bb1459cd4fcc29974f3571fddbef1885fd43 Mon Sep 17 00:00:00 2001 From: XangelMusic <22012301+XangelMusic@users.noreply.github.com> Date: Sun, 28 Apr 2024 20:29:32 +0800 Subject: [PATCH 2/2] Update BannerPositionFactory.cs --- SoundSwitch/Framework/Banner/BannerPositionFactory.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SoundSwitch/Framework/Banner/BannerPositionFactory.cs b/SoundSwitch/Framework/Banner/BannerPositionFactory.cs index 1a344f82db..68b1a71850 100644 --- a/SoundSwitch/Framework/Banner/BannerPositionFactory.cs +++ b/SoundSwitch/Framework/Banner/BannerPositionFactory.cs @@ -25,14 +25,14 @@ public class BannerPositionFactory : AbstractFactory