Skip to content

Commit

Permalink
refactor: properly use the position to determine the location of the …
Browse files Browse the repository at this point in the history
…banner
  • Loading branch information
Belphemur committed Dec 31, 2023
1 parent b88724e commit 1d6b312
Show file tree
Hide file tree
Showing 13 changed files with 261 additions and 185 deletions.
34 changes: 20 additions & 14 deletions SoundSwitch/Framework/Banner/BannerData.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
/********************************************************************
* 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.
********************************************************************/
* 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.Diagnostics.CodeAnalysis;
using System.Drawing;
using SoundSwitch.Framework.Audio;
using SoundSwitch.Framework.Banner.Position;

namespace SoundSwitch.Framework.Banner
{
Expand Down Expand Up @@ -43,17 +44,22 @@ public class BannerData
/// </summary>
[AllowNull]
public CachedSound SoundFile { get; internal set; }

/// <summary>
/// On what device to play the <see cref="CachedSound"/>
/// </summary>
[AllowNull]
public string CurrentDeviceId { get; internal set; }

/// <summary>
/// Position of the banner
/// </summary>
public IPosition Position { get; internal set; }

/// <summary>
/// Set the priority of the notification
/// If a notification is being shown a higher priority comes, it will replace it, if a lower, nothing will happens.
/// </summary>
public int Priority { get; set; } = -1;
}
}
}
42 changes: 14 additions & 28 deletions SoundSwitch/Framework/Banner/BannerForm.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/********************************************************************
* 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.
********************************************************************/
* 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;
using System.Drawing;
Expand Down Expand Up @@ -111,22 +111,8 @@ internal void SetData(BannerData data)
Region = Region.FromHrgn(RoundedCorner.CreateRoundRectRgn(0, 0, Width, Height , 20, 20));

var screen = GetScreen();
var positionLeft = screen.Bounds.X + 50;
var positionRight = screen.Bounds.Width - Width - positionLeft;
var positionCenterH = (screen.Bounds.Width - Width) / 2;
var positionTop = screen.Bounds.Y + 60;
var positionBottom = screen.Bounds.Height - Height - positionTop;

Location = AppModel.Instance.BannerPosition switch
{
BannerPositionEnum.TopLeft => new Point(positionLeft, positionTop),
BannerPositionEnum.TopCenter => new Point(positionCenterH, positionTop),
BannerPositionEnum.TopRight => new Point(positionRight, positionTop),
BannerPositionEnum.BottomLeft => new Point(positionLeft, positionBottom),
BannerPositionEnum.BottomCenter => new Point(positionCenterH, positionBottom),
BannerPositionEnum.BottomRight => new Point(positionRight, positionBottom),
_ => new Point(0, 0)
};

Location = data.Position.GetScreenPosition(screen, Height, Width);

_timerHide.Enabled = true;

Expand Down
34 changes: 22 additions & 12 deletions SoundSwitch/Framework/Banner/Position/IPosition.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
/********************************************************************
* 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.
********************************************************************/
* 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.Framework.Factory;

namespace SoundSwitch.Framework.Banner.Position
{
public interface IPosition : IEnumImpl<BannerPositionEnum>
{
/// <summary>
/// Get position in the screen for the banner
/// </summary>
/// <param name="screen"></param>
/// <param name="height"></param>
/// <param name="width"></param>
/// <returns></returns>
public Point GetScreenPosition(Screen screen, int height, int width);
}
}
36 changes: 23 additions & 13 deletions SoundSwitch/Framework/Banner/Position/PositionBottomCenter.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/********************************************************************
* 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.
********************************************************************/
* 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
Expand All @@ -20,5 +22,13 @@ internal class PositionBottomCenter : IPosition
{
public BannerPositionEnum TypeEnum => BannerPositionEnum.BottomCenter;
public string Label => SettingsStrings.positionOptionBottomCenter;

public Point GetScreenPosition(Screen screen, int height, int width)
{
var positionCenterH = (screen.Bounds.Width - width) / 2;
var positionTop = screen.Bounds.Y + 60;
var positionBottom = screen.Bounds.Height - height - positionTop;
return new Point(positionCenterH, positionBottom);
}
}
}
}
36 changes: 23 additions & 13 deletions SoundSwitch/Framework/Banner/Position/PositionBottomLeft.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/********************************************************************
* 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.
********************************************************************/
* 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
Expand All @@ -20,5 +22,13 @@ internal class PositionBottomLeft : IPosition
{
public BannerPositionEnum TypeEnum => BannerPositionEnum.BottomLeft;
public string Label => SettingsStrings.positionOptionBottomLeft;

public Point GetScreenPosition(Screen screen, int height, int width)
{
var positionTop = screen.Bounds.Y + 60;
var positionLeft = screen.Bounds.X + 50;
var positionBottom = screen.Bounds.Height - height - positionTop;
return new Point(positionLeft, positionBottom);
}
}
}
}
37 changes: 24 additions & 13 deletions SoundSwitch/Framework/Banner/Position/PositionBottomRight.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/********************************************************************
* 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.
********************************************************************/
* 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
Expand All @@ -20,5 +22,14 @@ internal class PositionBottomRight : IPosition
{
public BannerPositionEnum TypeEnum => BannerPositionEnum.BottomRight;
public string Label => SettingsStrings.positionOptionBottomRight;

public Point GetScreenPosition(Screen screen, int height, int width)
{
var positionLeft = screen.Bounds.X + 50;
var positionRight = screen.Bounds.Width - width - positionLeft;
var positionTop = screen.Bounds.Y + 60;
var positionBottom = screen.Bounds.Height - height - positionTop;
return new Point(positionRight, positionBottom);
}
}
}
}
35 changes: 22 additions & 13 deletions SoundSwitch/Framework/Banner/Position/PositionTopCenter.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/********************************************************************
* 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.
********************************************************************/
* 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
Expand All @@ -20,5 +22,12 @@ internal class PositionTopCenter : IPosition
{
public BannerPositionEnum TypeEnum => BannerPositionEnum.TopCenter;
public string Label => SettingsStrings.positionOptionTopCenter;

public Point GetScreenPosition(Screen screen, int height, int width)
{
var positionCenterH = (screen.Bounds.Width - width) / 2;
var positionTop = screen.Bounds.Y + 60;
return new Point(positionCenterH, positionTop);
}
}
}
}
32 changes: 20 additions & 12 deletions SoundSwitch/Framework/Banner/Position/PositionTopLeft.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/********************************************************************
* 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.
********************************************************************/
* 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
Expand All @@ -20,5 +22,11 @@ internal class PositionTopLeft : IPosition
{
public BannerPositionEnum TypeEnum => BannerPositionEnum.TopLeft;
public string Label => SettingsStrings.positionOptionTopLeft;
public Point GetScreenPosition(Screen screen, int height, int width)
{
var positionLeft = screen.Bounds.X + 50;
var positionTop = screen.Bounds.Y + 60;
return new Point(positionLeft, positionTop);
}
}
}
Loading

0 comments on commit 1d6b312

Please sign in to comment.