增加ResolutionConverter

This commit is contained in:
ww-rm
2025-04-20 12:41:33 +08:00
parent 76c1d96c87
commit bd9c5a176b
2 changed files with 35 additions and 9 deletions

View File

@@ -749,7 +749,7 @@ namespace SpineViewer.Controls
public SpinePreviewPanel PreviewPanel { get; } = previewPanel; public SpinePreviewPanel PreviewPanel { get; } = previewPanel;
[RefreshProperties(RefreshProperties.All)] [RefreshProperties(RefreshProperties.All)]
[TypeConverter(typeof(SizeConverter))] [TypeConverter(typeof(ResolutionConverter))]
[Category("[0] "), DisplayName("")] [Category("[0] "), DisplayName("")]
public Size Resolution { get => PreviewPanel.Resolution; set => PreviewPanel.Resolution = value; } public Size Resolution { get => PreviewPanel.Resolution; set => PreviewPanel.Resolution = value; }

View File

@@ -79,6 +79,8 @@ namespace SpineViewer.Utils
} }
} }
private StandardValuesCollection standardValues;
public override bool GetStandardValuesSupported(ITypeDescriptorContext? context) => true; public override bool GetStandardValuesSupported(ITypeDescriptorContext? context) => true;
public override bool GetStandardValuesExclusive(ITypeDescriptorContext? context) public override bool GetStandardValuesExclusive(ITypeDescriptorContext? context)
@@ -89,17 +91,41 @@ namespace SpineViewer.Utils
public override StandardValuesCollection? GetStandardValues(ITypeDescriptorContext? context) public override StandardValuesCollection? GetStandardValues(ITypeDescriptorContext? context)
{ {
// 查找属性上的 StandardValuesAttribute if (standardValues is null)
var attribute = context?.PropertyDescriptor?.Attributes.OfType<StandardValuesAttribute>().FirstOrDefault(); {
StandardValuesCollection result; // 查找属性上的 StandardValuesAttribute
if (attribute != null) var attribute = context?.PropertyDescriptor?.Attributes.OfType<StandardValuesAttribute>().FirstOrDefault();
result = new StandardValuesCollection(attribute.StandardValues); if (attribute != null)
else standardValues = new StandardValuesCollection(attribute.StandardValues);
result = new StandardValuesCollection(Array.Empty<string>()); else
return result; standardValues = new StandardValuesCollection(Array.Empty<string>());
}
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 public class SFMLColorConverter : ExpandableObjectConverter
{ {
private class SFMLColorPropertyDescriptor : SimplePropertyDescriptor private class SFMLColorPropertyDescriptor : SimplePropertyDescriptor