add shapes

This commit is contained in:
bluepilledgreat 2024-10-21 21:59:24 +01:00
parent 5f7ca580e4
commit 8e2b75c810
2 changed files with 118 additions and 5 deletions

View File

@ -173,6 +173,45 @@
"Color": "Color", "Color": "Color",
"Offset": "double" "Offset": "double"
} }
},
"Shape": {
"SuperClass": "FrameworkElement",
"IsCreatable": false,
"Attributes": {
"Fill": "Brush",
"Stroke": "Brush",
"Stretch": "Stretch",
"StrokeDashCap": "PenLineCap",
"StrokeDashOffset": "double",
"StrokeEndLineCap": "PenLineCap",
"StrokeLineJoin": "PenLineJoin",
"StrokeMiterLimit": "double",
"StrokeStartLineCap": "PenLineCap",
"StrokeThickness": "double"
}
},
"Ellipse": {
"SuperClass": "Shape",
"IsCreatable": true,
"Attributes": {}
},
"Line": {
"SuperClass": "Shape",
"IsCreatable": true,
"Attributes": {
"X1": "double",
"X2": "double",
"Y1": "double",
"Y2": "double"
}
},
"Rectangle": {
"SuperClass": "Shape",
"IsCreatable": true,
"Attributes": {
"RadiusX": "double",
"RadiusY": "double"
}
} }
}, },
"Types": { "Types": {
@ -341,6 +380,21 @@
"Reflect", "Reflect",
"Repeat" "Repeat"
] ]
},
"PenLineCap": {
"Values": [
"Flat",
"Square",
"Round",
"Triangle"
]
},
"PenLineJoin": {
"Values": [
"Miter",
"Bevel",
"Round"
]
} }
} }
} }

View File

@ -1,9 +1,9 @@
using System.ComponentModel; using System.Windows;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Xml.Linq; using System.Xml.Linq;
using Wpf.Ui.Markup; using Wpf.Ui.Markup;
@ -46,7 +46,11 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
["ScaleTransform"] = HandleXml_ScaleTransform, ["ScaleTransform"] = HandleXml_ScaleTransform,
["SkewTransform"] = HandleXml_SkewTransform, ["SkewTransform"] = HandleXml_SkewTransform,
["RotateTransform"] = HandleXml_RotateTransform, ["RotateTransform"] = HandleXml_RotateTransform,
["TranslateTransform"] = HandleXml_TranslateTransform ["TranslateTransform"] = HandleXml_TranslateTransform,
["Ellipse"] = HandleXmlElement_Ellipse,
["Line"] = HandleXmlElement_Line,
["Rectangle"] = HandleXmlElement_Rectangle
}; };
@ -432,6 +436,61 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
} }
#endregion #endregion
#region Shapes
private static void HandleXmlElement_Shape(CustomDialog dialog, Shape shape, XElement xmlElement)
{
HandleXmlElement_FrameworkElement(dialog, shape, xmlElement);
ApplyBrush_UIElement(dialog, shape, "Fill", Shape.FillProperty, xmlElement);
ApplyBrush_UIElement(dialog, shape, "Stroke", Shape.StrokeProperty, xmlElement);
shape.Stretch = ParseXmlAttribute<Stretch>(xmlElement, "Stretch", Stretch.Fill);
shape.StrokeDashCap = ParseXmlAttribute<PenLineCap>(xmlElement, "StrokeDashCap", PenLineCap.Flat);
shape.StrokeDashOffset = ParseXmlAttribute<double>(xmlElement, "StrokeDashOffset", 0);
shape.StrokeEndLineCap = ParseXmlAttribute<PenLineCap>(xmlElement, "StrokeEndLineCap", PenLineCap.Flat);
shape.StrokeLineJoin = ParseXmlAttribute<PenLineJoin>(xmlElement, "StrokeLineJoin", PenLineJoin.Miter);
shape.StrokeMiterLimit = ParseXmlAttribute<double>(xmlElement, "StrokeMiterLimit", 10);
shape.StrokeStartLineCap = ParseXmlAttribute<PenLineCap>(xmlElement, "StrokeStartLineCap", PenLineCap.Flat);
shape.StrokeThickness = ParseXmlAttribute<double>(xmlElement, "StrokeThickness", 1);
ApplyTransformations_UIElement(dialog, shape, xmlElement);
}
private static Ellipse HandleXmlElement_Ellipse(CustomDialog dialog, XElement xmlElement)
{
var ellipse = new Ellipse();
HandleXmlElement_Shape(dialog, ellipse, xmlElement);
return ellipse;
}
private static Line HandleXmlElement_Line(CustomDialog dialog, XElement xmlElement)
{
var line = new Line();
HandleXmlElement_Shape(dialog, line, xmlElement);
line.X1 = ParseXmlAttribute<double>(xmlElement, "X1", 0);
line.X2 = ParseXmlAttribute<double>(xmlElement, "X2", 0);
line.Y1 = ParseXmlAttribute<double>(xmlElement, "Y1", 0);
line.Y2 = ParseXmlAttribute<double>(xmlElement, "Y2", 0);
return line;
}
private static Rectangle HandleXmlElement_Rectangle(CustomDialog dialog, XElement xmlElement)
{
var rectangle = new Rectangle();
HandleXmlElement_Shape(dialog, rectangle, xmlElement);
rectangle.RadiusX = ParseXmlAttribute<double>(xmlElement, "RadiusX", 0);
rectangle.RadiusY = ParseXmlAttribute<double>(xmlElement, "RadiusY", 0);
return rectangle;
}
#endregion
#region Elements #region Elements
private static void HandleXmlElement_FrameworkElement(CustomDialog dialog, FrameworkElement uiElement, XElement xmlElement) private static void HandleXmlElement_FrameworkElement(CustomDialog dialog, FrameworkElement uiElement, XElement xmlElement)
{ {
@ -767,7 +826,7 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
#region Public APIs #region Public APIs
public void ApplyCustomTheme(string name, string contents) public void ApplyCustomTheme(string name, string contents)
{ {
ThemeDir = Path.Combine(Paths.CustomThemes, name); ThemeDir = System.IO.Path.Combine(Paths.CustomThemes, name);
XElement xml; XElement xml;
@ -786,7 +845,7 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
public void ApplyCustomTheme(string name) public void ApplyCustomTheme(string name)
{ {
string path = Path.Combine(Paths.CustomThemes, name, "Theme.xml"); string path = System.IO.Path.Combine(Paths.CustomThemes, name, "Theme.xml");
ApplyCustomTheme(name, File.ReadAllText(path)); ApplyCustomTheme(name, File.ReadAllText(path));
} }