/// <summary> /// Returns a collection of properties for the type of array specified by the value parameter, using the specified context and attributes. /// </summary> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param> /// <param name="value">An <see cref="T:System.Object" /> that specifies the type of array for which to get properties.</param> /// <param name="attributes">An array of type <see cref="T:System.Attribute" /> that is used as a filter.</param> /// <returns> /// A <see cref="T:System.ComponentModel.PropertyDescriptorCollection" /> with the properties that are exposed for this data type, or null if there are no properties. /// </returns> public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { var typeDesc = (ContentTypeDescriptor)context.Instance; PropertyDescriptorCollection result = TypeDescriptor.GetProperties(value, attributes); var properties = new List <ContentPropertyDescriptor>(); // Build the property descriptors for the blending type. foreach (PropertyDescriptor descriptor in result) { var contentProp = new ContentProperty(descriptor, value, typeDesc["TextureSampler"]) { HasDefaultValue = true, RefreshProperties = RefreshProperties.All, IsReadOnly = typeDesc["TextureSampler"].IsReadOnly }; if (string.Equals(descriptor.Name, "TextureFilter", StringComparison.OrdinalIgnoreCase)) { contentProp.DefaultValue = TextureFilter.Point; contentProp.Converter = typeof(TextureFilterTypeConverter).AssemblyQualifiedName; contentProp.DisplayName = APIResources.PROP_SAMPLE_FILTER_NAME; contentProp.Description = APIResources.PROP_SAMPLE_FILTER_DESC; } if (string.Equals(descriptor.Name, "HorizontalWrapping", StringComparison.OrdinalIgnoreCase)) { contentProp.RefreshProperties = RefreshProperties.All; contentProp.DefaultValue = TextureAddressing.Clamp; contentProp.Converter = typeof(TextureAddressingTypeConverter).AssemblyQualifiedName; contentProp.DisplayName = APIResources.PROP_SAMPLE_HORZADDR_NAME; contentProp.Description = APIResources.PROP_SAMPLE_HORZADDR_DESC; } if (string.Equals(descriptor.Name, "VerticalWrapping", StringComparison.OrdinalIgnoreCase)) { contentProp.RefreshProperties = RefreshProperties.All; contentProp.DefaultValue = TextureAddressing.Clamp; contentProp.Converter = typeof(TextureAddressingTypeConverter).AssemblyQualifiedName; contentProp.DisplayName = APIResources.PROP_SAMPLE_VERTADDR_NAME; contentProp.Description = APIResources.PROP_SAMPLE_VERTADDR_DESC; } if (string.Equals(descriptor.Name, "BorderColor", StringComparison.OrdinalIgnoreCase)) { contentProp.DefaultValue = GorgonColor.Transparent; contentProp.Converter = typeof(RGBATypeConverter).AssemblyQualifiedName; contentProp.SetTypeEditor(typeof(RGBAEditor), typeof(UITypeEditor)); contentProp.DisplayName = APIResources.PROP_SAMPLE_BORDER_NAME; contentProp.Description = APIResources.PROP_SAMPLE_BORDER_DESC; } properties.Add(new ContentPropertyDescriptor(contentProp)); } return(new PropertyDescriptorCollection(properties.Cast <PropertyDescriptor>().OrderBy(item => item.DisplayName ?? item.Name).ToArray())); }
/// <summary> /// Returns a collection of properties for the type of array specified by the value parameter, using the specified context and attributes. /// </summary> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param> /// <param name="value">An <see cref="T:System.Object" /> that specifies the type of array for which to get properties.</param> /// <param name="attributes">An array of type <see cref="T:System.Attribute" /> that is used as a filter.</param> /// <returns> /// A <see cref="T:System.ComponentModel.PropertyDescriptorCollection" /> with the properties that are exposed for this data type, or null if there are no properties. /// </returns> public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { var typeDesc = (ContentTypeDescriptor)context.Instance; var content = typeDesc.Content; PropertyDescriptorCollection result = TypeDescriptor.GetProperties(value, attributes); var properties = new List <ContentPropertyDescriptor>(); // Build the property descriptors for the blending type. foreach (PropertyDescriptor descriptor in result) { var contentProp = new ContentProperty(descriptor, value, content.TypeDescriptor["Blending"]) { HasDefaultValue = true, RefreshProperties = RefreshProperties.All, IsReadOnly = typeDesc["Blending"].IsReadOnly }; // Modify the type converters/editors for the appropriate properties. if (string.Equals(descriptor.Name, "WriteMask", StringComparison.OrdinalIgnoreCase)) { contentProp.SetTypeEditor(typeof(WriteMaskTypeEditor)); contentProp.DisplayName = APIResources.PROP_BLEND_WRITEMASK_NAME; contentProp.Description = APIResources.PROP_BLEND_WRITEMASK_DESC; contentProp.DefaultValue = ColorWriteMaskFlags.All; } if (string.Equals(descriptor.Name, "AlphaOperation", StringComparison.OrdinalIgnoreCase)) { contentProp.Converter = typeof(BlendOperationTypeConverter).AssemblyQualifiedName; contentProp.DefaultValue = BlendOperation.Add; contentProp.DisplayName = APIResources.PROP_BLEND_BLEND_OP_ALPHA_NAME; contentProp.Description = APIResources.PROP_BLEND_BLEND_OP_ALPHA_DESC; } if (string.Equals(descriptor.Name, "BlendOperation", StringComparison.OrdinalIgnoreCase)) { contentProp.Converter = typeof(BlendOperationTypeConverter).AssemblyQualifiedName; contentProp.DefaultValue = BlendOperation.Add; contentProp.DisplayName = APIResources.PROP_BLEND_BLEND_OP_COLOR_NAME; contentProp.Description = APIResources.PROP_BLEND_BLEND_OP_COLOR_DESC; } if (string.Equals(descriptor.Name, "SourceAlphaBlend", StringComparison.OrdinalIgnoreCase)) { contentProp.Converter = typeof(AlphaBlendTypeTypeConverter).AssemblyQualifiedName; contentProp.DefaultValue = BlendType.One; contentProp.DisplayName = APIResources.PROP_BLEND_BLEND_TYPE_ALPHA_SRC_NAME; contentProp.Description = APIResources.PROP_BLEND_BLEND_TYPE_ALPHA_SRC_DESC; } if (string.Equals(descriptor.Name, "DestinationAlphaBlend", StringComparison.OrdinalIgnoreCase)) { contentProp.Converter = typeof(AlphaBlendTypeTypeConverter).AssemblyQualifiedName; contentProp.DefaultValue = BlendType.Zero; contentProp.DisplayName = APIResources.PROP_BLEND_BLEND_TYPE_ALPHA_DEST_NAME; contentProp.Description = APIResources.PROP_BLEND_BLEND_TYPE_ALPHA_DEST_DESC; } if (string.Equals(descriptor.Name, "SourceBlend", StringComparison.OrdinalIgnoreCase)) { contentProp.Converter = typeof(BlendTypeTypeConverter).AssemblyQualifiedName; contentProp.DefaultValue = BlendType.SourceAlpha; contentProp.DisplayName = APIResources.PROP_BLEND_BLEND_TYPE_COLOR_SRC_NAME; contentProp.Description = APIResources.PROP_BLEND_BLEND_TYPE_COLOR_SRC_DESC; } if (string.Equals(descriptor.Name, "DestinationBlend", StringComparison.OrdinalIgnoreCase)) { contentProp.Converter = typeof(BlendTypeTypeConverter).AssemblyQualifiedName; contentProp.DefaultValue = BlendType.InverseSourceAlpha; contentProp.DisplayName = APIResources.PROP_BLEND_BLEND_TYPE_COLOR_DEST_NAME; contentProp.Description = APIResources.PROP_BLEND_BLEND_TYPE_COLOR_DEST_DESC; } if (string.Equals(descriptor.Name, "BlendFactor", StringComparison.OrdinalIgnoreCase)) { contentProp.Converter = typeof(RGBATypeConverter).AssemblyQualifiedName; contentProp.SetTypeEditor(typeof(RGBAEditor)); contentProp.DefaultValue = GorgonColor.Transparent; contentProp.DisplayName = APIResources.PROP_BLEND_BLEND_FACTOR_NAME; contentProp.Description = APIResources.PROP_BLEND_BLEND_FACTOR_DESC; } properties.Add(new ContentPropertyDescriptor(contentProp)); } return(new PropertyDescriptorCollection(properties.Cast <PropertyDescriptor>().OrderBy(item => item.DisplayName ?? item.Name).ToArray())); }