Skip to content

Commit

Permalink
add shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
bluepilledgreat committed Oct 21, 2024
1 parent 5f7ca58 commit 8e2b75c
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 5 deletions.
54 changes: 54 additions & 0 deletions Bloxstrap/Resources/CustomBootstrapperSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,45 @@
"Color": "Color",
"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": {
Expand Down Expand Up @@ -341,6 +380,21 @@
"Reflect",
"Repeat"
]
},
"PenLineCap": {
"Values": [
"Flat",
"Square",
"Round",
"Triangle"
]
},
"PenLineJoin": {
"Values": [
"Miter",
"Bevel",
"Round"
]
}
}
}
69 changes: 64 additions & 5 deletions Bloxstrap/UI/Elements/Bootstrapper/CustomDialog.Creator.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.ComponentModel;
using System.Windows;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Xml.Linq;

using Wpf.Ui.Markup;
Expand Down Expand Up @@ -46,7 +46,11 @@ private class DummyFrameworkElement : FrameworkElement { }
["ScaleTransform"] = HandleXml_ScaleTransform,
["SkewTransform"] = HandleXml_SkewTransform,
["RotateTransform"] = HandleXml_RotateTransform,
["TranslateTransform"] = HandleXml_TranslateTransform
["TranslateTransform"] = HandleXml_TranslateTransform,

["Ellipse"] = HandleXmlElement_Ellipse,
["Line"] = HandleXmlElement_Line,
["Rectangle"] = HandleXmlElement_Rectangle
};


Expand Down Expand Up @@ -432,6 +436,61 @@ private static void ApplyBrush_UIElement(CustomDialog dialog, FrameworkElement u
}
#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
private static void HandleXmlElement_FrameworkElement(CustomDialog dialog, FrameworkElement uiElement, XElement xmlElement)
{
Expand Down Expand Up @@ -767,7 +826,7 @@ private void HandleXmlBase(XElement xml)
#region Public APIs
public void ApplyCustomTheme(string name, string contents)
{
ThemeDir = Path.Combine(Paths.CustomThemes, name);
ThemeDir = System.IO.Path.Combine(Paths.CustomThemes, name);

XElement xml;

Expand All @@ -786,7 +845,7 @@ public void ApplyCustomTheme(string name, string contents)

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));
}
Expand Down

0 comments on commit 8e2b75c

Please sign in to comment.