Skip to content

Commit

Permalink
Merge pull request #186 from ramon18/dev
Browse files Browse the repository at this point in the history
Some improvements and a feature
  • Loading branch information
Belphemur authored May 25, 2017
2 parents de0a2a1 + 2111002 commit 578724f
Show file tree
Hide file tree
Showing 23 changed files with 684 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*.dSYM/

# Visual Studio
.vs/
bin/
obj/
Debug/
Expand All @@ -55,3 +56,4 @@ packages/
/SoundSwitch.VC.VC.opendb
/SoundSwitch.VC.db
/SoundSwitch.psess

24 changes: 22 additions & 2 deletions Make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,28 @@ IF "%~1" neq "" (
)


REM set msbuildexe="%programfiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe"
set msbuildexe="%programfiles(x86)%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.exe"
set VS2017Ent=%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe
set VS2017Pro=%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe
set VS2017Community=%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.exe
set VS2015=%ProgramFiles(x86)%\MSBuild\14.0\bin\msbuild.exe

if exist "%VS2017Ent%" (
echo Using VS2017Ent
set msbuildexe="%VS2017Ent%"
) else (
if exist "%VS2017Community%" (
echo Using VS2017Community
set msbuildexe="%VS2017Community%"
) else (
if exist "%VS2017Pro%" (
echo Using VS2017Pro
set msbuildexe="%VS2017Pro%"
) else (
echo Fallback to VS2015
set msbuildexe="%VS2015%"
)
)
)

Echo Making SoundSwitch %buildPlatform%
Echo.
Expand Down
48 changes: 48 additions & 0 deletions SoundSwitch/Framework/Banner/BannerData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/********************************************************************
* 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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoundSwitch.Framework.Banner
{
/// <summary>
/// Contains configuration data for the banner form.
/// </summary>
public class BannerData
{
/// <summary>
/// Gets/sets the title of the banner
/// </summary>
public string Title { get; internal set; }

/// <summary>
/// Gets/sets the text of the banner
/// </summary>
public string Text { get; internal set; }

/// <summary>
/// Gets/sets the path for an image, this is optional.
/// </summary>
public string ImagePath { get; internal set; }

/// <summary>
/// Gets/sets the path for a wav sound to be playedc during the notification, this is optional.
/// </summary>
public string SoundFilePath { get; internal set; }
}
}
125 changes: 125 additions & 0 deletions SoundSwitch/Framework/Banner/BannerForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

147 changes: 147 additions & 0 deletions SoundSwitch/Framework/Banner/BannerForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/********************************************************************
* 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.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SoundSwitch.Framework.Banner
{
/// <summary>
/// This class implements the UI form used to show a Banner notification.
/// </summary>
public partial class BannerForm : Form
{
private Timer timerHide;
private bool hiding;
private System.Media.SoundPlayer player;

/// <summary>
/// Constructor for the <see cref="BannerForm"/> class
/// </summary>
public BannerForm()
{
InitializeComponent();

this.Location = new Point(50, 60);
}

protected override bool ShowWithoutActivation => true;

/// <summary>
/// Override the parameters used to create the window handle.
/// Ensure that the window will be top-most and do not activate or take focus.
/// </summary>
protected override CreateParams CreateParams
{
get
{
CreateParams p = base.CreateParams;
p.ExStyle |= 0x08000000; // WS_EX_NOACTIVATE
p.ExStyle |= 0x00000008; // WS_EX_TOPMOST
return p;
}
}

/// <summary>
/// Called internally to configure pass notification parameters
/// </summary>
/// <param name="data">The configuration data to setup the notification UI</param>
internal void SetData(BannerData data)
{
if (this.timerHide == null)
{
this.timerHide = new Timer();
this.timerHide.Interval = 3000;
this.timerHide.Tick += TimerHide_Tick;
}
else
{
this.timerHide.Enabled = false;
}

if (!string.IsNullOrEmpty(data.ImagePath) && System.IO.File.Exists(data.ImagePath))
this.pbxLogo.ImageLocation = data.ImagePath;

DestroySound();

if (!string.IsNullOrEmpty(data.SoundFilePath))
{
this.player = new System.Media.SoundPlayer();
player.SoundLocation = data.SoundFilePath;
player.Play();
}

this.hiding = false;
this.Opacity = .8;
this.lblTop.Text = data.Title;
this.lblTitle.Text = data.Text;
this.timerHide.Enabled = true;

this.Show();
}

/// <summary>
/// Destroy current sound player (if any)
/// </summary>
private void DestroySound()
{
if (this.player != null)
{
this.player.Dispose();
this.player = null;
}
}

/// <summary>
/// Event handler for the "hiding" timer.
/// </summary>
/// <param name="sender">The sender of the event</param>
/// <param name="e">Arguments of the event</param>
private void TimerHide_Tick(object sender, EventArgs e)
{
this.hiding = true;
this.timerHide.Enabled = false;
DestroySound();
FadeOut();
}

/// <summary>
/// Implements an "fadeout" animation while hiding the window.
/// In the end of the animation the form is self disposed.
/// <remarks>The animation is canceled if the method <see cref="SetData"/> is called along the animation.</remarks>
/// </summary>
private async void FadeOut()
{
while (this.Opacity > 0.0)
{
await Task.Delay(50);

if (!this.hiding)
break;
this.Opacity -= 0.05;
}

if (this.hiding)
{
this.Dispose();
}
}
}
}
Loading

0 comments on commit 578724f

Please sign in to comment.