Skip to content

Commit 420a327

Browse files
authored
Merge pull request #48 from GoingCrazyDude/feature/custom-bootstrappers
Implement RadialGradientBrush
2 parents 02c2795 + 2b2cfb8 commit 420a327

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

Bloxstrap/Resources/CustomBootstrapperSchema.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
"StretchDirection": "StretchDirection",
119119
"Source": "ImageSource",
120120
"IsAnimated": "bool",
121-
"RepeatBehaviour": "string"
121+
"RepeatBehaviour": "string"
122122
}
123123
},
124124
"ScaleTransform": {
@@ -193,6 +193,17 @@
193193
"SpreadMethod": "GradientSpreadMethod"
194194
}
195195
},
196+
"RadialGradientBrush": {
197+
"SuperClass": "Brush",
198+
"IsCreatable": true,
199+
"Attributes": {
200+
"GradientOrigin": "Point",
201+
"Center": "Point",
202+
"ColorInterpolationMode": "ColorInterpolationMode",
203+
"MappingMode": "BrushMappingMode",
204+
"SpreadMethod": "GradientSpreadMethod"
205+
}
206+
},
196207
"GradientStop": {
197208
"IsCreatable": true,
198209
"Attributes": {

Bloxstrap/UI/Elements/Bootstrapper/CustomDialog.Creator.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ private class DummyFrameworkElement : FrameworkElement { }
4545
["SolidColorBrush"] = HandleXmlElement_SolidColorBrush,
4646
["ImageBrush"] = HandleXmlElement_ImageBrush,
4747
["LinearGradientBrush"] = HandleXmlElement_LinearGradientBrush,
48+
["RadialGradientBrush"] = HandleXmlElement_RadialGradientBrush,
4849

4950
["GradientStop"] = HandleXmlElement_GradientStop,
5051

@@ -573,6 +574,7 @@ private static GradientStop HandleXmlElement_GradientStop(CustomDialog dialog, X
573574
private static Brush HandleXmlElement_LinearGradientBrush(CustomDialog dialog, XElement xmlElement)
574575
{
575576
var brush = new LinearGradientBrush();
577+
576578
HandleXml_Brush(brush, xmlElement);
577579

578580
object? startPoint = GetPointFromXElement(xmlElement, "StartPoint");
@@ -593,6 +595,29 @@ private static Brush HandleXmlElement_LinearGradientBrush(CustomDialog dialog, X
593595
return brush;
594596
}
595597

598+
private static Brush HandleXmlElement_RadialGradientBrush(CustomDialog dialog, XElement xmlElement) {
599+
var radialbrush = new RadialGradientBrush();
600+
601+
HandleXml_Brush(radialbrush, xmlElement);
602+
603+
object? startPoint = GetPointFromXElement(xmlElement, "GradientOrigin");
604+
if (startPoint is Point)
605+
radialbrush.GradientOrigin = (Point)startPoint;
606+
607+
object? endPoint = GetPointFromXElement(xmlElement, "Center");
608+
if (endPoint is Point)
609+
radialbrush.Center = (Point)endPoint;
610+
611+
radialbrush.ColorInterpolationMode = ParseXmlAttribute<ColorInterpolationMode>(xmlElement, "ColorInterpolationMode", ColorInterpolationMode.SRgbLinearInterpolation);
612+
radialbrush.MappingMode = ParseXmlAttribute<BrushMappingMode>(xmlElement, "MappingMode", BrushMappingMode.RelativeToBoundingBox);
613+
radialbrush.SpreadMethod = ParseXmlAttribute<GradientSpreadMethod>(xmlElement, "SpreadMethod", GradientSpreadMethod.Pad);
614+
615+
foreach (var child in xmlElement.Elements())
616+
radialbrush.GradientStops.Add(HandleXml<GradientStop>(dialog, child));
617+
618+
return radialbrush;
619+
}
620+
596621
private static void ApplyBrush_UIElement(CustomDialog dialog, FrameworkElement uiElement, string name, DependencyProperty dependencyProperty, XElement xmlElement)
597622
{
598623
// check if attribute exists

0 commit comments

Comments
 (0)