73 lines
1.9 KiB
C#
73 lines
1.9 KiB
C#
using Avalonia.Controls;
|
|
using Avalonia.Input;
|
|
using Avalonia.Interactivity;
|
|
using Harmonia.UI.ViewModels;
|
|
|
|
namespace Harmonia.UI.Views;
|
|
|
|
public partial class PlaybackBar : UserControl
|
|
{
|
|
private readonly PlaybackBarViewModel _viewModel;
|
|
|
|
public PlaybackBar()
|
|
{
|
|
InitializeComponent();
|
|
_viewModel = (PlaybackBarViewModel)DataContext!;
|
|
}
|
|
|
|
private void Slider_Loaded(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
|
|
{
|
|
if (sender is not Slider slider)
|
|
return;
|
|
|
|
slider.AddHandler(PointerPressedEvent, OnSliderPointerPressed, RoutingStrategies.Tunnel);
|
|
slider.AddHandler(PointerReleasedEvent, OnSliderPointerReleased, RoutingStrategies.Tunnel);
|
|
}
|
|
|
|
private void OnSliderPointerPressed(object? sender, PointerPressedEventArgs e)
|
|
{
|
|
if (sender is not Slider slider)
|
|
return;
|
|
|
|
PointerPoint currentPoint = e.GetCurrentPoint(slider);
|
|
|
|
if (currentPoint.Properties.IsLeftButtonPressed == false)
|
|
return;
|
|
|
|
_viewModel.IsPositionChangeInProgress = true;
|
|
}
|
|
|
|
private void OnSliderPointerReleased(object? sender, PointerReleasedEventArgs e)
|
|
{
|
|
if (sender is not Slider slider)
|
|
return;
|
|
|
|
_viewModel.CurrentPosition = slider.Value;
|
|
_viewModel.IsPositionChangeInProgress = false;
|
|
}
|
|
|
|
private void PlayButton_Click(object? sender, RoutedEventArgs e)
|
|
{
|
|
_viewModel.Play();
|
|
}
|
|
|
|
private void StopButton_Click(object? sender, RoutedEventArgs e)
|
|
{
|
|
_viewModel.Stop();
|
|
}
|
|
|
|
private void PauseButton_Click(object? sender, RoutedEventArgs e)
|
|
{
|
|
_viewModel.Pause();
|
|
}
|
|
|
|
private void PreviousSongButton_Click(object? sender, RoutedEventArgs e)
|
|
{
|
|
_viewModel.Previous();
|
|
}
|
|
|
|
private void NextSongButton_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
_viewModel.Next();
|
|
}
|
|
} |