mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
add effects
This commit is contained in:
parent
3eb8938abe
commit
49e7724f02
@ -212,6 +212,25 @@
|
||||
"RadiusX": "double",
|
||||
"RadiusY": "double"
|
||||
}
|
||||
},
|
||||
"BlurEffect": {
|
||||
"IsCreatable": true,
|
||||
"Attributes": {
|
||||
"KernelType": "KernelType",
|
||||
"Radius": "double",
|
||||
"RenderingBias": "RenderingBias"
|
||||
}
|
||||
},
|
||||
"DropShadowEffect": {
|
||||
"IsCreatable": true,
|
||||
"Attributes": {
|
||||
"BlurRadius": "double",
|
||||
"Direction": "double",
|
||||
"Opacity": "double",
|
||||
"ShadowDepth": "double",
|
||||
"RenderingBias": "RenderingBias",
|
||||
"Color": "Color"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Types": {
|
||||
@ -395,6 +414,18 @@
|
||||
"Bevel",
|
||||
"Round"
|
||||
]
|
||||
},
|
||||
"KernelType": {
|
||||
"Values": [
|
||||
"Gaussian",
|
||||
"Box"
|
||||
]
|
||||
},
|
||||
"RenderingBias": {
|
||||
"Values": [
|
||||
"Performance",
|
||||
"Quality"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Media.Effects;
|
||||
using System.Windows.Shapes;
|
||||
using System.Xml.Linq;
|
||||
|
||||
@ -48,6 +49,9 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
|
||||
["RotateTransform"] = HandleXml_RotateTransform,
|
||||
["TranslateTransform"] = HandleXml_TranslateTransform,
|
||||
|
||||
["BlurEffect"] = HandleXmlElement_BlurEffect,
|
||||
["DropShadowEffect"] = HandleXmlElement_DropShadowEffect,
|
||||
|
||||
["Ellipse"] = HandleXmlElement_Ellipse,
|
||||
["Line"] = HandleXmlElement_Line,
|
||||
["Rectangle"] = HandleXmlElement_Rectangle
|
||||
@ -300,6 +304,55 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Effects
|
||||
private static BlurEffect HandleXmlElement_BlurEffect(CustomDialog dialog, XElement xmlElement)
|
||||
{
|
||||
var effect = new BlurEffect();
|
||||
|
||||
effect.KernelType = ParseXmlAttribute<KernelType>(xmlElement, "KernelType", KernelType.Gaussian);
|
||||
effect.Radius = ParseXmlAttribute<double>(xmlElement, "Radius", 5);
|
||||
effect.RenderingBias = ParseXmlAttribute<RenderingBias>(xmlElement, "RenderingBias", RenderingBias.Performance);
|
||||
|
||||
return effect;
|
||||
}
|
||||
|
||||
private static DropShadowEffect HandleXmlElement_DropShadowEffect(CustomDialog dialog, XElement xmlElement)
|
||||
{
|
||||
var effect = new DropShadowEffect();
|
||||
|
||||
effect.BlurRadius = ParseXmlAttribute<double>(xmlElement, "BlurRadius", 5);
|
||||
effect.Direction = ParseXmlAttribute<double>(xmlElement, "Direction", 315);
|
||||
effect.Opacity = ParseXmlAttribute<double>(xmlElement, "Opacity", 1);
|
||||
effect.ShadowDepth = ParseXmlAttribute<double>(xmlElement, "ShadowDepth", 5);
|
||||
effect.RenderingBias = ParseXmlAttribute<RenderingBias>(xmlElement, "RenderingBias", RenderingBias.Performance);
|
||||
|
||||
var color = GetColorFromXElement(xmlElement, "Color");
|
||||
if (color is Color)
|
||||
effect.Color = (Color)color;
|
||||
|
||||
return effect;
|
||||
}
|
||||
|
||||
|
||||
private static void ApplyEffects_UIElement(CustomDialog dialog, UIElement uiElement, XElement xmlElement)
|
||||
{
|
||||
var effectElement = xmlElement.Element($"{xmlElement.Name}.Effect");
|
||||
if (effectElement == null)
|
||||
return;
|
||||
|
||||
var children = effectElement.Elements();
|
||||
if (children.Count() > 1)
|
||||
throw new Exception($"{xmlElement.Name}.Effect can only have one child");
|
||||
|
||||
var child = children.FirstOrDefault();
|
||||
if (child == null)
|
||||
return;
|
||||
|
||||
Effect effect = HandleXml<Effect>(dialog, child);
|
||||
uiElement.Effect = effect;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Brushes
|
||||
private static void HandleXml_Brush(Brush brush, XElement xmlElement)
|
||||
{
|
||||
@ -524,6 +577,8 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
|
||||
|
||||
int zIndex = ParseXmlAttributeClamped(xmlElement, "ZIndex", defaultValue: 0, min: 0, max: 1000);
|
||||
Panel.SetZIndex(uiElement, zIndex);
|
||||
|
||||
ApplyEffects_UIElement(dialog, uiElement, xmlElement);
|
||||
}
|
||||
|
||||
private static void HandleXmlElement_Control(CustomDialog dialog, Control uiElement, XElement xmlElement)
|
||||
@ -551,6 +606,10 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
|
||||
xmlElement.SetAttributeValue("IsEnabled", "True");
|
||||
HandleXmlElement_Control(dialog, dialog, xmlElement);
|
||||
|
||||
// transfer effect to element grid
|
||||
dialog.ElementGrid.Effect = dialog.Effect;
|
||||
dialog.Effect = null;
|
||||
|
||||
var theme = ParseXmlAttribute<Theme>(xmlElement, "Theme", Theme.Default);
|
||||
dialog.Resources.MergedDictionaries.Clear();
|
||||
dialog.Resources.MergedDictionaries.Add(new ThemesDictionary() { Theme = theme.GetFinal() == Theme.Dark ? Wpf.Ui.Appearance.ThemeType.Dark : Wpf.Ui.Appearance.ThemeType.Light });
|
||||
@ -580,6 +639,9 @@ namespace Bloxstrap.UI.Elements.Bootstrapper
|
||||
xmlElement.SetAttributeValue("IsEnabled", "True");
|
||||
HandleXmlElement_Control(dialog, dialog.RootTitleBar, xmlElement);
|
||||
|
||||
// get rid of all effects
|
||||
dialog.Effect = null;
|
||||
|
||||
Panel.SetZIndex(dialog.RootTitleBar, 1001); // always show above others
|
||||
|
||||
// properties we dont want modifiable
|
||||
|
Loading…
Reference in New Issue
Block a user