static private string CheckAndAddRef(string Expression, info.lundin.math.ExpressionParser parser, Widget widget) { string expression = Expression; /*replace to values*/ ///add this. values pos expression = expression.Replace("this.X", $"{widget.Left}"); expression = expression.Replace("this.Y", $"{widget.Top}"); expression = expression.Replace("this.l", $"{widget.Left}"); expression = expression.Replace("this.t", $"{widget.Top}"); expression = expression.Replace("this.left", $"{widget.Left}"); expression = expression.Replace("this.top", $"{widget.Top}"); ///add this.size expression = expression.Replace("this.w", $"{widget.Width ?? 0}"); expression = expression.Replace("this.h", $"{widget.Height ?? 0}"); expression = expression.Replace("this.width", $"{widget.Width ?? 0}"); expression = expression.Replace("this.height", $"{widget.Height ?? 0}"); if (widget.Parent != null) { ///add parent values pos expression = expression.Replace("&.X", GerParrentValue(widget, "&.X")); expression = expression.Replace("&.Y", GerParrentValue(widget, "&.Y")); expression = expression.Replace("&.l", GerParrentValue(widget, "&.X")); expression = expression.Replace("&.t", GerParrentValue(widget, "&.Y")); expression = expression.Replace("&.left", GerParrentValue(widget, "&.X")); expression = expression.Replace("&.top", GerParrentValue(widget, "&.Y")); ///add parent values size expression = expression.Replace("&.w", GerParrentValue(widget, "&.w")); expression = expression.Replace("&.h", GerParrentValue(widget, "&.h")); expression = expression.Replace("&.width", GerParrentValue(widget, "&.w")); expression = expression.Replace("&.height", GerParrentValue(widget, "&.h")); } ///add window walues expression = expression.Replace("W.h", $"{MyraEnvironment.Game.Window.ClientBounds.Height}"); expression = expression.Replace("W.height", $"{MyraEnvironment.Game.Window.ClientBounds.Height}"); expression = expression.Replace("W.w", $"{MyraEnvironment.Game.Window.ClientBounds.Width}"); expression = expression.Replace("W.width", $"{MyraEnvironment.Game.Window.ClientBounds.Width}"); /// if (expression.Contains("[")) { Regex regex = new Regex(@"\[.+].\w*"); MatchCollection matches = regex.Matches(expression); foreach (var item in matches) { string Id = item.ToString().Split('[')[1].ToString().Split(']')[0].ToString(); var w = GetByID(Id, _widgets); var valueForReg = GetValue(item.ToString().Substring(item.ToString().IndexOf(']') + 1, 1), w.Bounds); expression = expression.Replace(item as string, $"{valueForReg ?? 0}"); } } return(expression); }
public static void Parse(Widget widget, List <Widget> widgets, int level = 0) { _widgets = widgets; #region Check ///check on depths if (level > DepthOfCalculations) { return; } ///check parent on dynamic layout if (widget.Parent != null && !widget.Parent.Layout2d.Nullable) { Parse(widget.Parent, widgets, ++level); } #endregion ///expresion parser info.lundin.math.ExpressionParser parser = new info.lundin.math.ExpressionParser(); parser.ImplicitMultiplication = false; #region Calculation /// if X exp not null if (widget.Layout2d.PositionXExpression != "NULL") { widget.Left = (int)parser.Parse(CheckAndAddRef(widget.Layout2d.PositionXExpression, parser, widget)); } /// if Y exp not null if (widget.Layout2d.PositionYExpression != "NULL") { widget.Top = (int)parser.Parse(CheckAndAddRef(widget.Layout2d.PositionYExpression, parser, widget)); } /// if H exp not null if (widget.Layout2d.SizeYExpression != "NULL") { widget.Height = (int)parser.Parse(CheckAndAddRef(widget.Layout2d.SizeYExpression, parser, widget)); } /// if W exp not null if (widget.Layout2d.SizeXExpression != "NULL") { widget.Width = (int)parser.Parse(CheckAndAddRef(widget.Layout2d.SizeXExpression, parser, widget)); } #endregion widget.Layout2d.Calculated = true; }