diff --git a/SpineViewer/Controls/SpinePreviewPanel.cs b/SpineViewer/Controls/SpinePreviewPanel.cs index 33395d9..281569e 100644 --- a/SpineViewer/Controls/SpinePreviewPanel.cs +++ b/SpineViewer/Controls/SpinePreviewPanel.cs @@ -749,7 +749,7 @@ namespace SpineViewer.Controls public SpinePreviewPanel PreviewPanel { get; } = previewPanel; [RefreshProperties(RefreshProperties.All)] - [TypeConverter(typeof(SizeConverter))] + [TypeConverter(typeof(ResolutionConverter))] [Category("[0] 导出"), DisplayName("分辨率")] public Size Resolution { get => PreviewPanel.Resolution; set => PreviewPanel.Resolution = value; } diff --git a/SpineViewer/Utils/TypeConverter.cs b/SpineViewer/Utils/TypeConverter.cs index c35c85f..3a4a643 100644 --- a/SpineViewer/Utils/TypeConverter.cs +++ b/SpineViewer/Utils/TypeConverter.cs @@ -79,6 +79,8 @@ namespace SpineViewer.Utils } } + private StandardValuesCollection standardValues; + public override bool GetStandardValuesSupported(ITypeDescriptorContext? context) => true; public override bool GetStandardValuesExclusive(ITypeDescriptorContext? context) @@ -89,17 +91,41 @@ namespace SpineViewer.Utils public override StandardValuesCollection? GetStandardValues(ITypeDescriptorContext? context) { - // 查找属性上的 StandardValuesAttribute - var attribute = context?.PropertyDescriptor?.Attributes.OfType().FirstOrDefault(); - StandardValuesCollection result; - if (attribute != null) - result = new StandardValuesCollection(attribute.StandardValues); - else - result = new StandardValuesCollection(Array.Empty()); - return result; + if (standardValues is null) + { + // 查找属性上的 StandardValuesAttribute + var attribute = context?.PropertyDescriptor?.Attributes.OfType().FirstOrDefault(); + if (attribute != null) + standardValues = new StandardValuesCollection(attribute.StandardValues); + else + standardValues = new StandardValuesCollection(Array.Empty()); + } + return standardValues; } } + public class ResolutionConverter : SizeConverter + { + private static readonly StandardValuesCollection standardValues = new(new string[] { + "4096, 4096", + "2048, 2048", + "1024, 1024", + "512, 512", + "3840, 2160", + "2560, 1440", + "1920, 1080", + "1280, 720", + "2160, 3840", + "1440, 2560", + "1080, 1920", + "720, 1280", + }); + + public override bool GetStandardValuesSupported(ITypeDescriptorContext? context) => true; + public override bool GetStandardValuesExclusive(ITypeDescriptorContext? context) => false; + public override StandardValuesCollection? GetStandardValues(ITypeDescriptorContext? context) => standardValues; + } + public class SFMLColorConverter : ExpandableObjectConverter { private class SFMLColorPropertyDescriptor : SimplePropertyDescriptor