Skip to content

Commit

Permalink
Merge pull request #271 from Founntain/volume-scrollwheel
Browse files Browse the repository at this point in the history
Ability to change volume with scrollwheel
  • Loading branch information
Founntain committed Apr 15, 2024
2 parents f8c9419 + 64a023b commit 6ef30cf
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
11 changes: 5 additions & 6 deletions OsuPlayer/Views/PlayerControlView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
xmlns:cv="using:OsuPlayer.Extensions.ValueConverters"
xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
xmlns:views="clr-namespace:OsuPlayer.Views"
xmlns:lvc="using:LiveChartsCore.SkiaSharpView.Avalonia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="OsuPlayer.Views.PlayerControlView"
FontWeight="{DynamicResource DefaultFontWeight}">
Expand Down Expand Up @@ -44,7 +43,7 @@
</Grid>

<Grid Grid.Row="1" ColumnDefinitions="*, Auto, *">
<ContentControl Grid.ColumnSpan="3" Content="{Binding MainWindowViewModel.AudioVisualizer}"/>
<ContentControl Grid.ColumnSpan="3" Content="{Binding MainWindowViewModel.AudioVisualizer}" />

<Grid Grid.Column="0" ColumnDefinitions="Auto, *">
<Image Grid.Column="0" Stretch="UniformToFill" Source="{Binding CurrentSongImage}" Margin="6"
Expand All @@ -66,21 +65,21 @@
<DockPanel Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="5">
<Panel>
<Button Name="Volume" Width="38" Height="38" CornerRadius="50"
Theme="{StaticResource TransparentButton}">
Theme="{StaticResource TransparentButton}" PointerWheelChanged="Volume_OnPointerWheelChanged">
<avalonia:MaterialIcon Kind="{Binding Volume, Converter={StaticResource VolumeConverter}}"
Height="19" Width="19" />
<Button.Flyout>
<Flyout>
<StackPanel Orientation="Horizontal">
<Button Name="VolumeFly" Width="38" Height="38" CornerRadius="50"
Theme="{StaticResource TransparentButton}" Click="Volume_OnClick">
Theme="{StaticResource TransparentButton}" Click="Volume_OnClick" >
<avalonia:MaterialIcon
Kind="{Binding Volume, Converter={StaticResource VolumeConverter}}"
Height="19" Width="19" />
</Button>
<Slider VerticalAlignment="Center" HorizontalAlignment="Center"
Minimum="0" Maximum="100" Value="{Binding Volume}" Orientation="Horizontal"
Width="100" Margin="6" />
Minimum="0" Maximum="{Binding MaximimumVolume}" Value="{Binding Volume}" Orientation="Horizontal"
Width="100" Margin="6" PointerWheelChanged="Volume_OnPointerWheelChanged"/>
</StackPanel>
</Flyout>
</Button.Flyout>
Expand Down
27 changes: 27 additions & 0 deletions OsuPlayer/Views/PlayerControlView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,31 @@ private void CurrentSongLabel_OnClick(object? sender, RoutedEventArgs e)
_mainWindow.ViewModel.MainView = _mainWindow.ViewModel.PlaylistView;
}
}

private void Volume_OnPointerWheelChanged(object? sender, PointerWheelEventArgs e)
{
if (ViewModel == default) return;

switch (e.Delta.Y)
{
// When we scroll up and exceed the maximum volume, we set it to the max possible volume
case > 0 when ViewModel.Player.Volume.Value + 10 > ViewModel.MaximumVolume:
ViewModel.Player.Volume.Value = ViewModel.MaximumVolume;

return;
// When we scroll up we add 10 (10% as the max volume should always be 100)
case > 0:
ViewModel.Player.Volume.Value += 10;
break;
// When we scroll up and exceed the maximum volume, we set it to 0, otherwise the slider would set it to max volume if we have a negative number
case < 0 when ViewModel.Player.Volume.Value - 10 < 0:
ViewModel.Player.Volume.Value = 0;

return;
// When we scroll up we subtract 10 (10% as the max volume should always be 100)
case < 0:
ViewModel.Player.Volume.Value -= 10;
break;
}
}
}
10 changes: 10 additions & 0 deletions OsuPlayer/Views/PlayerControlViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ public double PlaybackSpeed
}
}

private double _maximumVolume;

public double MaximumVolume
{
get => _maximumVolume;
set => this.RaiseAndSetIfChanged(ref _maximumVolume, value);
}

public double SongTime
{
get
Expand Down Expand Up @@ -163,6 +171,8 @@ public PlayerControlViewModel(IPlayer player, IAudioEngine bassEngine, FluentApp
Player = player;
MainWindowViewModel = mainWindowViewModel;

MaximumVolume = 100;

var config = new Config();

_displayBackgroundImage = !config.Container.DisplayBackgroundImage;
Expand Down

0 comments on commit 6ef30cf

Please sign in to comment.