diff options
Diffstat (limited to 'ViewModels')
| -rw-r--r-- | ViewModels/Image/ImageLoadedViewModel.cs | 26 | ||||
| -rw-r--r-- | ViewModels/Image/ImageViewModel.cs | 10 | ||||
| -rw-r--r-- | ViewModels/Settings/ISettingLimits.cs | 9 | ||||
| -rw-r--r-- | ViewModels/Settings/SettingLimits.cs | 20 | ||||
| -rw-r--r-- | ViewModels/Settings/SettingsViewModel.cs | 52 |
5 files changed, 103 insertions, 14 deletions
diff --git a/ViewModels/Image/ImageLoadedViewModel.cs b/ViewModels/Image/ImageLoadedViewModel.cs index f9e322c..0489ac1 100644 --- a/ViewModels/Image/ImageLoadedViewModel.cs +++ b/ViewModels/Image/ImageLoadedViewModel.cs @@ -1,23 +1,37 @@ -using Avalonia.Media.Imaging; +using Avalar.Models.Interfaces; +using Avalonia.Media.Imaging; +using Avalonia.Threading; using ReactiveUI; +using System; +using System.ComponentModel; namespace Avalar.ViewModels.Image { public class ImageLoadedViewModel : ReactiveObject { - public ImageLoadedViewModel(IBitmap bitmap) + private IImageModel m_ImageModel; + + public ImageLoadedViewModel(IBitmap bitmap, IImageModel imageModel) { Bitmap = bitmap; + m_ImageModel = imageModel ?? throw new ArgumentNullException(nameof(imageModel)); + + m_ImageModel.PropertyChanged += OnImageModelChanged; + } + + private void OnImageModelChanged(object sender, PropertyChangedEventArgs e) + { + Dispatcher.UIThread.InvokeAsync(() => + { + Bitmap = m_ImageModel.LatestResult; + }); } private IBitmap m_Bitmap; public IBitmap Bitmap { get => m_Bitmap; - set - { - this.RaiseAndSetIfChanged(ref m_Bitmap, value); - } + set => this.RaiseAndSetIfChanged(ref m_Bitmap, value); } } } diff --git a/ViewModels/Image/ImageViewModel.cs b/ViewModels/Image/ImageViewModel.cs index 3b41919..4b17343 100644 --- a/ViewModels/Image/ImageViewModel.cs +++ b/ViewModels/Image/ImageViewModel.cs @@ -1,8 +1,6 @@ - -using Avalar.Models.Interfaces; +using Avalar.Models.Interfaces; using Avalar.ViewModels.Image; using Avalar.Views; -using Avalonia.Media.Imaging; using ReactiveUI; using System; using System.Linq; @@ -27,9 +25,7 @@ namespace Avalar.Viewmodels.Image public object ChildViewModel { get => m_ChildViewModel; - set { - this.RaiseAndSetIfChanged(ref m_ChildViewModel, value); - } + set => this.RaiseAndSetIfChanged(ref m_ChildViewModel, value); } public async void OpenFile() @@ -37,7 +33,7 @@ namespace Avalar.Viewmodels.Image var result = await ViewService.ShowOpenImageFileDialog().ConfigureAwait(true); if (result.Length != 1) return; - ChildViewModel = new ImageLoadedViewModel(ImageModel.LoadImage(result.First())); + ChildViewModel = new ImageLoadedViewModel(ImageModel.LoadImage(result.First()), ImageModel); } } } diff --git a/ViewModels/Settings/ISettingLimits.cs b/ViewModels/Settings/ISettingLimits.cs new file mode 100644 index 0000000..a4927f0 --- /dev/null +++ b/ViewModels/Settings/ISettingLimits.cs @@ -0,0 +1,9 @@ +namespace Avalar.ViewModels.Settings +{ + public interface ISettingLimits + { + uint MaxWidth { get; } + + uint MaxHeight { get; } + } +}
\ No newline at end of file diff --git a/ViewModels/Settings/SettingLimits.cs b/ViewModels/Settings/SettingLimits.cs new file mode 100644 index 0000000..8a0f3ea --- /dev/null +++ b/ViewModels/Settings/SettingLimits.cs @@ -0,0 +1,20 @@ +using Avalonia.Media.Imaging; +using System; + +namespace Avalar.ViewModels.Settings +{ + public class SettingLimits : ISettingLimits + { + public SettingLimits(IBitmap bitmap) + { + var _ = bitmap ?? throw new ArgumentNullException(nameof(bitmap)); + + MaxWidth = Convert.ToUInt32(bitmap.Size.Width); + MaxHeight = Convert.ToUInt32(bitmap.Size.Height); + } + + public uint MaxWidth { get; } + + public uint MaxHeight { get; } + } +} diff --git a/ViewModels/Settings/SettingsViewModel.cs b/ViewModels/Settings/SettingsViewModel.cs index 730b662..17c27cc 100644 --- a/ViewModels/Settings/SettingsViewModel.cs +++ b/ViewModels/Settings/SettingsViewModel.cs @@ -1,7 +1,57 @@ +using Avalar.Models.Interfaces; +using ReactiveUI; +using System; +using System.ComponentModel; +using System.Threading.Tasks; + namespace Avalar.ViewModels.Settings { - public class SettingsViewModel + public class SettingsViewModel : ReactiveObject { + private readonly ISettingsModel m_SettingsModel; + public SettingsViewModel(ISettingsModel settingsModel) + { + m_SettingsModel = settingsModel; + + PropertyChanged += OnPropertyChanged; + } + + private async void OnPropertyChanged(object sender, PropertyChangedEventArgs e) + { + if(e.PropertyName == nameof(Width)) + { + await Task.Run(() => m_SettingsModel.SetWidth(Width)).ConfigureAwait(false); + } + if (e.PropertyName == nameof(Height)) + { + await Task.Run(() => m_SettingsModel.SetHeight(Height)).ConfigureAwait(false); + } + if (e.PropertyName == nameof(BrightnessDelta)) + { + await Task.Run(() => m_SettingsModel.SetBrightnessDelta(BrightnessDelta)).ConfigureAwait(false); + } + } + + private uint m_Width; + public uint Width + { + get => m_Width; + set => this.RaiseAndSetIfChanged(ref m_Width, value); + } + + private uint m_Height; + public uint Height + { + get => m_Height; + set => this.RaiseAndSetIfChanged(ref m_Height, value); + } + + private int m_BrightnessDelta; + public int BrightnessDelta + { + get => m_BrightnessDelta; + set => this.RaiseAndSetIfChanged(ref m_BrightnessDelta, value); + } } } |
