增加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)
@@ -88,16 +90,40 @@ namespace SpineViewer.Utils
} }
public override StandardValuesCollection? GetStandardValues(ITypeDescriptorContext? context) public override StandardValuesCollection? GetStandardValues(ITypeDescriptorContext? context)
{
if (standardValues is null)
{ {
// 查找属性上的 StandardValuesAttribute // 查找属性上的 StandardValuesAttribute
var attribute = context?.PropertyDescriptor?.Attributes.OfType<StandardValuesAttribute>().FirstOrDefault(); var attribute = context?.PropertyDescriptor?.Attributes.OfType<StandardValuesAttribute>().FirstOrDefault();
StandardValuesCollection result;
if (attribute != null) if (attribute != null)
result = new StandardValuesCollection(attribute.StandardValues); standardValues = new StandardValuesCollection(attribute.StandardValues);
else else
result = new StandardValuesCollection(Array.Empty<string>()); standardValues = new StandardValuesCollection(Array.Empty<string>());
return result;
} }
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