Files
MesenCE/UI/ViewModels/PceConfigViewModel.cs
SourMesen 40335ce735 UI: Update to Avalonia 12, .NET 10 and replace ReactiveUI with MVVM community toolkit (#142)
Also fixes DX11.0 support (for Win7 PCs that aren't fully updated), which stopped working after the recent variable refresh rate changes
2026-07-03 16:04:42 +09:00

65 lines
1.8 KiB
C#

using Avalonia.Controls;
using CommunityToolkit.Mvvm.ComponentModel;
using Mesen.Config;
using Mesen.Controls;
using Mesen.Utilities;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Mesen.ViewModels
{
public partial class PceConfigViewModel : DisposableViewModel
{
[ObservableProperty] public partial PcEngineConfig Config { get; set; }
[ObservableProperty] public partial PcEngineConfig OriginalConfig { get; set; }
[ObservableProperty] public partial PceConfigTab SelectedTab { get; set; } = 0;
public PceInputConfigViewModel Input { get; private set; }
public List<PalettePreset> PalettePresets { get; } = new List<PalettePreset>() {
//The default palette is generated from Kitrinx's palette generator which
//is meant to produce a more accurate palette for the PCE: https://github.com/Kitrinx/TG16_Palette
new() { Name = "Default (by Kitrinx)", Palette = PcEngineConfig.DefaultPalette.ToArray() },
};
public PceConfigViewModel()
{
Config = ConfigManager.Config.PcEngine;
OriginalConfig = Config.Clone();
Input = new PceInputConfigViewModel(Config);
if(Design.IsDesignMode) {
return;
}
UInt32[] linearPalette = new UInt32[512];
for(UInt32 i = 0; i < 0x200; i++) {
UInt32 g = To8Bit(i >> 6);
UInt32 r = To8Bit((i >> 3) & 0x07);
UInt32 b = To8Bit(i & 0x07);
linearPalette[i] = (0xFF000000 | (r << 16) | (g << 8) | b);
}
PalettePresets.Add(new() { Name = "Linear RGB333", Palette = linearPalette });
AddDisposable(Input);
AddDisposable(ReactiveHelper.RegisterRecursiveObserver(Config, (s, e) => { Config.ApplyConfig(); }));
}
UInt32 To8Bit(UInt32 color)
{
return (color << 5) | (color << 2) | (color >> 1);
}
}
public enum PceConfigTab
{
General,
Audio,
Emulation,
Input,
Video
}
}