focus mode

This commit is contained in:
Royce551 2021-09-19 09:22:15 -05:00
parent d8b1317737
commit 61f962d227
3 changed files with 87 additions and 36 deletions

View file

@ -59,7 +59,7 @@ namespace FRESHMusicPlayer
public GUILibrary Library; public GUILibrary Library;
public IMetadataProvider CurrentTrack; public IMetadataProvider CurrentTrack;
public const string WindowName = "FRESHMusicPlayer [Blueprint 11 b.8.29.2021; Not stable!]"; public const string WindowName = "FRESHMusicPlayer [Blueprint 11 b.9.18.2021; Not stable!]";
public PlaytimeTrackingHandler TrackingHandler; public PlaytimeTrackingHandler TrackingHandler;
public bool PauseAfterCurrentTrack = false; public bool PauseAfterCurrentTrack = false;
@ -287,28 +287,28 @@ namespace FRESHMusicPlayer
SelectedAuxiliaryPane = AuxiliaryPane.None; SelectedAuxiliaryPane = AuxiliaryPane.None;
} }
public bool IsControlsBoxVisible { get; private set; } = false; public bool IsControlsBoxVisible { get; private set; } = false;
public void ShowControlsBox() public async void ShowControlsBox()
{ {
var navBarStoryboard = InterfaceUtils.GetThicknessAnimation(
new Thickness(0, -25, 0, 0),
new Thickness(0),
TimeSpan.FromMilliseconds(500),
new PropertyPath(MarginProperty),
new ExponentialEase { EasingMode = EasingMode.EaseIn, Exponent = 3 });
var controlsBoxStoryboard = InterfaceUtils.GetThicknessAnimation(
new Thickness(0, 0, 0, -84),
new Thickness(0),
TimeSpan.FromMilliseconds(500),
new PropertyPath(MarginProperty),
new ExponentialEase { EasingMode = EasingMode.EaseIn, Exponent = 3 });
navBarStoryboard.Begin(MainBar);
await controlsBoxStoryboard.BeginStoryboardAsync(ControlsBoxBorder);
IsControlsBoxVisible = true; IsControlsBoxVisible = true;
var navBarStoryboard = InterfaceUtils.GetThicknessAnimation(
new Thickness(0, -25, 0, 0),
new Thickness(0),
TimeSpan.FromMilliseconds(500),
new PropertyPath(MarginProperty),
new ExponentialEase { EasingMode = EasingMode.EaseIn, Exponent = 3 });
var controlsBoxStoryboard = InterfaceUtils.GetThicknessAnimation(
new Thickness(0, 0, 0, -84),
new Thickness(0),
TimeSpan.FromMilliseconds(500),
new PropertyPath(MarginProperty),
new ExponentialEase { EasingMode = EasingMode.EaseIn, Exponent = 3 });
navBarStoryboard.Begin(MainBar);
controlsBoxStoryboard.Begin(ControlsBoxBorder);
} }
public void HideControlsBox() public async void HideControlsBox()
{ {
IsControlsBoxVisible = false;
var navBarStoryboard = InterfaceUtils.GetThicknessAnimation( var navBarStoryboard = InterfaceUtils.GetThicknessAnimation(
new Thickness(0), new Thickness(0),
new Thickness(0, -25, 0, 0), new Thickness(0, -25, 0, 0),
@ -322,8 +322,8 @@ namespace FRESHMusicPlayer
new PropertyPath(MarginProperty), new PropertyPath(MarginProperty),
new ExponentialEase { EasingMode = EasingMode.EaseIn, Exponent = 3 }); new ExponentialEase { EasingMode = EasingMode.EaseIn, Exponent = 3 });
navBarStoryboard.Begin(MainBar); navBarStoryboard.Begin(MainBar);
controlsBoxStoryboard.Begin(ControlsBoxBorder); await controlsBoxStoryboard.BeginStoryboardAsync(ControlsBoxBorder);
IsControlsBoxVisible = false;
} }
public void ProcessSettings(bool initialize = false) public void ProcessSettings(bool initialize = false)

View file

@ -7,25 +7,21 @@
xmlns:local="clr-namespace:FRESHMusicPlayer.Pages" xmlns:local="clr-namespace:FRESHMusicPlayer.Pages"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" d:DesignHeight="450" d:DesignWidth="800"
Title="FullscreenPage" Unloaded="Page_Unloaded"> Title="FullscreenPage" Unloaded="Page_Unloaded" MouseMove="Page_MouseMove">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
<RowDefinition Height="1*"/> <RowDefinition Height="1*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Rectangle Fill="Transparent" Height="50" Grid.Row="0" Grid.ColumnSpan="3" Panel.ZIndex="2" MouseEnter="Rectangle_MouseEnter"/> <DockPanel x:Name="TopBar" Panel.ZIndex="4" Background="Transparent" LastChildFill="False" Grid.Row="0" Height="30">
<Rectangle Fill="Transparent" Height="50" Grid.Row="2" Grid.ColumnSpan="3" Panel.ZIndex="2" MouseEnter="Rectangle_MouseEnter"/> <Button x:Name="BackButton" DockPanel.Dock="Left" Content="Back" Margin="10,5,0,5" Click="BackButton_Click"/>
<Rectangle Fill="Transparent" Width="50" Grid.Column="0" Grid.RowSpan="3" Panel.ZIndex="2" MouseEnter="Rectangle_MouseEnter"/> <CheckBox x:Name="FocusModeCheckBox" Margin="0,5,10,5" DockPanel.Dock="Right" Content="Focus Mode" Foreground="{StaticResource PrimaryTextColor}" VerticalContentAlignment="Center" Checked="FocusMode_Changed" Unchecked="FocusMode_Changed"/>
<Rectangle Fill="Transparent" Width="50" Grid.Column="2" Grid.RowSpan="3" Panel.ZIndex="2" MouseEnter="Rectangle_MouseEnter"/> </DockPanel>
<Viewbox Stretch="Uniform" Panel.ZIndex="2" Grid.Row="1" Grid.Column="1"> <Rectangle x:Name="TopBarOverlay" Panel.ZIndex="3" Opacity="0.55" Grid.Row="0" Fill="{StaticResource BackgroundColor}"/>
<Viewbox Stretch="Uniform" Panel.ZIndex="2" Grid.Row="1" Margin="25">
<DockPanel LastChildFill="False" Width="700" Height="350"> <DockPanel LastChildFill="False" Width="700" Height="350">
<Image Source="https://royce551.github.io/assets/images/fmp/fullfmplogo.png" DockPanel.Dock="Top" HorizontalAlignment="Left" Width="100" RenderOptions.BitmapScalingMode="HighQuality" Margin="10,0,0,0"/> <Image Source="https://royce551.github.io/assets/images/fmp/fullfmplogo.png" DockPanel.Dock="Top" HorizontalAlignment="Left" Width="100" RenderOptions.BitmapScalingMode="HighQuality" Margin="10,0,0,0"/>

View file

@ -27,13 +27,15 @@ namespace FRESHMusicPlayer.Pages
{ {
this.window = window; this.window = window;
InitializeComponent(); InitializeComponent();
window.HideControlsBox();
window.Player.SongStopped += Player_SongStopped; window.Player.SongStopped += Player_SongStopped;
window.Player.SongChanged += Player_SongChanged; window.Player.SongChanged += Player_SongChanged;
window.ProgressTimer.Tick += ProgressTimer_Tick; window.ProgressTimer.Tick += ProgressTimer_Tick;
Player_SongChanged(null, EventArgs.Empty); Player_SongChanged(null, EventArgs.Empty);
controlDismissTimer.Tick += ControlDismissTimer_Tick;
} }
private void ProgressTimer_Tick(object sender, EventArgs e) private void ProgressTimer_Tick(object sender, EventArgs e)
{ {
var time = window.Player.CurrentTime; var time = window.Player.CurrentTime;
@ -89,8 +91,8 @@ namespace FRESHMusicPlayer.Pages
private void Rectangle_MouseEnter(object sender, MouseEventArgs e) private void Rectangle_MouseEnter(object sender, MouseEventArgs e)
{ {
if (window.IsControlsBoxVisible) window.HideControlsBox(); //if (window.IsControlsBoxVisible) window.HideControlsBox();
else window.ShowControlsBox(); //else window.ShowControlsBox();
} }
private void Page_Unloaded(object sender, RoutedEventArgs e) private void Page_Unloaded(object sender, RoutedEventArgs e)
@ -98,6 +100,59 @@ namespace FRESHMusicPlayer.Pages
window.Player.SongStopped -= Player_SongStopped; window.Player.SongStopped -= Player_SongStopped;
window.Player.SongChanged -= Player_SongChanged; window.Player.SongChanged -= Player_SongChanged;
window.ProgressTimer.Tick -= ProgressTimer_Tick; window.ProgressTimer.Tick -= ProgressTimer_Tick;
controlDismissTimer.Tick -= ControlDismissTimer_Tick;
Mouse.OverrideCursor = null;
}
private readonly WinForms.Timer controlDismissTimer = new WinForms.Timer { Interval = 3000, Enabled = true };
private Point lastMouseMovePosition;
private void Page_MouseMove(object sender, MouseEventArgs e)
{
if (lastMouseMovePosition != null)
{
var position = Mouse.GetPosition(this);
if (Math.Abs(position.X - lastMouseMovePosition.X) > SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(position.Y - lastMouseMovePosition.Y) > SystemParameters.MinimumVerticalDragDistance)
{
if (!controlDismissTimer.Enabled)
{
if (!window.IsControlsBoxVisible) window.ShowControlsBox();
controlDismissTimer.Start();
Mouse.OverrideCursor = null;
TopBar.Visibility = TopBarOverlay.Visibility = Visibility.Visible;
}
}
}
lastMouseMovePosition = Mouse.GetPosition(this);
}
private void ControlDismissTimer_Tick(object sender, EventArgs e)
{
if (!IsMouseOver || FocusModeCheckBox.IsMouseOver || BackButton.IsMouseOver) return; // cursor is probably over controls, don't hide yet
controlDismissTimer.Stop();
window.HideControlsBox();
Mouse.OverrideCursor = Cursors.None;
TopBar.Visibility = TopBarOverlay.Visibility = Visibility.Collapsed;
}
private void BackButton_Click(object sender, RoutedEventArgs e)
{
}
private void FocusMode_Changed(object sender, RoutedEventArgs e)
{
if ((bool)FocusModeCheckBox.IsChecked)
{
CoverArtOverlay.Opacity = 1;
CoverArtOverlay.Fill = (Brush)FindResource("BackgroundColor");
}
else
{
CoverArtOverlay.Opacity = 0.55;
CoverArtOverlay.Fill = (Brush)FindResource("ForegroundColor");
}
} }
} }
} }