rewrite EmbeddedAvaloniaResources

This commit is contained in:
GreemDev 2025-11-30 15:58:52 -06:00
parent 9dcb71e120
commit c8c5b9bbfb
4 changed files with 36 additions and 35 deletions

View file

@ -1,31 +0,0 @@
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using Avalonia.Styling;
using Gommon;
using System;
namespace Ryujinx.Ava.Common
{
public static class EmbeddedAvaloniaResources
{
public const string LogoPathFormat = "resm:Ryujinx.Assets.UIImages.Logo_{0}_{1}.png?assembly=Ryujinx";
public static Bitmap LoadBitmap(string uri)
=> new(AssetLoader.Open(new Uri(uri)));
public static Bitmap GetIconByNameAndTheme(string iconName, bool isDarkTheme)
{
string themeName = isDarkTheme ? "Dark" : "Light";
return LoadBitmap(LogoPathFormat.Format(iconName, themeName));
}
public static Bitmap GetIconByNameAndTheme(string iconName, string theme)
{
bool isDarkTheme = theme == "Dark" ||
(theme == "Auto" && RyujinxApp.DetectSystemTheme() == ThemeVariant.Dark);
return GetIconByNameAndTheme(iconName, isDarkTheme);
}
}
}

View file

@ -0,0 +1,32 @@
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using Gommon;
using System;
namespace Ryujinx.Ava.Common
{
// ReSharper disable once InconsistentNaming
// UiImages is ugly, so no
public static class UIImages
{
public const string LogoPathFormat = "resm:Ryujinx.Assets.UIImages.Logo_{0}_{1}.png?assembly=Ryujinx";
public const string IconPathFormat = "resm:Ryujinx.Assets.UIImages.Icon_{0}.png?assembly=Ryujinx";
public static Bitmap LoadBitmap(string uri)
=> new(AssetLoader.Open(new Uri(uri)));
public static Bitmap GetIconByName(string iconName)
=> LoadBitmap(IconPathFormat.Format(iconName));
public static Bitmap GetLogoByNameAndTheme(string iconName, bool isDarkTheme) =>
LoadBitmap(LogoPathFormat.Format(iconName,
isDarkTheme
? "Dark"
: "Light"
)
);
public static Bitmap GetLogoByNameAndVariant(string iconName, string theme)
=> LoadBitmap(LogoPathFormat.Format(iconName, theme));
}
}

View file

@ -109,8 +109,8 @@ namespace Ryujinx.Ava.UI.SetupWizard
bool isDarkTheme = theme == "Dark" ||
(theme == "Auto" && RyujinxApp.DetectSystemTheme() == ThemeVariant.Dark);
DiscordLogo = EmbeddedAvaloniaResources
.GetIconByNameAndTheme("Discord", isDarkTheme)
DiscordLogo = UIImages
.GetLogoByNameAndTheme("Discord", isDarkTheme)
.CreateScaledBitmap(new PixelSize(32, 24));
}

View file

@ -42,9 +42,9 @@ namespace Ryujinx.Ava.UI.ViewModels
bool isDarkTheme = theme == "Dark" ||
(theme == "Auto" && RyujinxApp.DetectSystemTheme() == ThemeVariant.Dark);
DiscordLogo = EmbeddedAvaloniaResources.GetIconByNameAndTheme("Discord", isDarkTheme)
DiscordLogo = UIImages.GetLogoByNameAndTheme("Discord", isDarkTheme)
.CreateScaledBitmap(new PixelSize(32, 24));
GitLabLogo = EmbeddedAvaloniaResources.GetIconByNameAndTheme("GitLab", isDarkTheme)
GitLabLogo = UIImages.GetLogoByNameAndTheme("GitLab", isDarkTheme)
.CreateScaledBitmap(new PixelSize(32, 31));
}