2022-07-24 18:38:38 +01:00
|
|
|
using Avalonia.Controls;
|
2022-07-08 19:47:11 +01:00
|
|
|
using Avalonia.Interactivity;
|
2022-07-24 18:38:38 +01:00
|
|
|
using FluentAvalonia.UI.Controls;
|
|
|
|
using FluentAvalonia.UI.Navigation;
|
2022-12-29 14:24:05 +00:00
|
|
|
using Ryujinx.Ava.UI.Controls;
|
|
|
|
using Ryujinx.Ava.UI.Models;
|
|
|
|
using Ryujinx.Ava.UI.ViewModels;
|
2022-07-08 19:47:11 +01:00
|
|
|
using Ryujinx.HLE.FileSystem;
|
2023-01-11 05:20:19 +00:00
|
|
|
using SixLabors.ImageSharp;
|
|
|
|
using SixLabors.ImageSharp.Formats.Png;
|
|
|
|
using SixLabors.ImageSharp.PixelFormats;
|
|
|
|
using SixLabors.ImageSharp.Processing;
|
|
|
|
using System.IO;
|
2022-07-08 19:47:11 +01:00
|
|
|
|
2023-01-11 05:20:19 +00:00
|
|
|
namespace Ryujinx.Ava.UI.Views.User
|
2022-07-08 19:47:11 +01:00
|
|
|
{
|
2023-01-11 05:20:19 +00:00
|
|
|
public partial class UserFirmwareAvatarSelectorView : UserControl
|
2022-07-08 19:47:11 +01:00
|
|
|
{
|
2022-07-24 18:38:38 +01:00
|
|
|
private NavigationDialogHost _parent;
|
|
|
|
private TempProfile _profile;
|
|
|
|
|
2023-01-11 05:20:19 +00:00
|
|
|
public UserFirmwareAvatarSelectorView(ContentManager contentManager)
|
2022-07-08 19:47:11 +01:00
|
|
|
{
|
|
|
|
ContentManager = contentManager;
|
|
|
|
|
|
|
|
DataContext = ViewModel;
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
|
2023-01-11 05:20:19 +00:00
|
|
|
public UserFirmwareAvatarSelectorView()
|
2022-07-08 19:47:11 +01:00
|
|
|
{
|
|
|
|
InitializeComponent();
|
2022-07-24 18:38:38 +01:00
|
|
|
|
|
|
|
AddHandler(Frame.NavigatedToEvent, (s, e) =>
|
|
|
|
{
|
|
|
|
NavigatedTo(e);
|
|
|
|
}, RoutingStrategies.Direct);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void NavigatedTo(NavigationEventArgs arg)
|
|
|
|
{
|
2022-07-08 19:47:11 +01:00
|
|
|
if (Program.PreviewerDetached)
|
|
|
|
{
|
2022-07-24 18:38:38 +01:00
|
|
|
if (arg.NavigationMode == NavigationMode.New)
|
|
|
|
{
|
|
|
|
(_parent, _profile) = ((NavigationDialogHost, TempProfile))arg.Parameter;
|
|
|
|
ContentManager = _parent.ContentManager;
|
|
|
|
if (Program.PreviewerDetached)
|
|
|
|
{
|
2023-01-11 05:20:19 +00:00
|
|
|
ViewModel = new UserFirmwareAvatarSelectorViewModel();
|
2022-07-24 18:38:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DataContext = ViewModel;
|
|
|
|
}
|
2022-07-08 19:47:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-24 18:38:38 +01:00
|
|
|
public ContentManager ContentManager { get; private set; }
|
2022-07-08 19:47:11 +01:00
|
|
|
|
2023-01-11 05:20:19 +00:00
|
|
|
internal UserFirmwareAvatarSelectorViewModel ViewModel { get; set; }
|
2022-07-08 19:47:11 +01:00
|
|
|
|
2023-01-11 05:20:19 +00:00
|
|
|
private void GoBack(object sender, RoutedEventArgs e)
|
2022-07-08 19:47:11 +01:00
|
|
|
{
|
2022-07-24 18:38:38 +01:00
|
|
|
_parent.GoBack();
|
2022-07-08 19:47:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void ChooseButton_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
{
|
2023-01-11 05:20:19 +00:00
|
|
|
if (ViewModel.SelectedImage != null)
|
2022-07-08 19:47:11 +01:00
|
|
|
{
|
2023-01-11 05:20:19 +00:00
|
|
|
MemoryStream streamJpg = new();
|
|
|
|
SixLabors.ImageSharp.Image avatarImage = SixLabors.ImageSharp.Image.Load(ViewModel.SelectedImage, new PngDecoder());
|
|
|
|
|
|
|
|
avatarImage.Mutate(x => x.BackgroundColor(new Rgba32(
|
|
|
|
ViewModel.BackgroundColor.R,
|
|
|
|
ViewModel.BackgroundColor.G,
|
|
|
|
ViewModel.BackgroundColor.B,
|
|
|
|
ViewModel.BackgroundColor.A)));
|
|
|
|
avatarImage.SaveAsJpeg(streamJpg);
|
2022-07-24 18:38:38 +01:00
|
|
|
|
2023-01-11 05:20:19 +00:00
|
|
|
_profile.Image = streamJpg.ToArray();
|
2022-07-08 19:47:11 +01:00
|
|
|
|
2022-07-24 18:38:38 +01:00
|
|
|
_parent.GoBack();
|
2022-07-08 19:47:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|