public virtual void Initialise(BaseControl parent) { if (Size == null) { Size = new SpecialVector2(); } if (Position == null) { Position = new SpecialVector2(); } Parent = parent; NamedChildren.Clear(); foreach (var c in Children) { c.Initialise(this); foreach (var namedChild in c.NamedChildren) { NamedChildren.Add(namedChild.Key, namedChild.Value); } if (!string.IsNullOrEmpty(c.Name)) { NamedChildren.Add(c.Name, c); } } }
public SpecialVector2 ParseSpecialVector2(string value, bool throwOnError) { var split = value.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); SpecialVector2 output = new SpecialVector2(0, 0, SpecialVector2Type.Inherit); if (split.Length == 1) { var part = split[0]; if (part.Equals("inherit", StringComparison.InvariantCultureIgnoreCase)) { return(output); } else if (part.EndsWith("%")) { part = part.TrimEnd('%'); output.SpecialType = SpecialVector2Type.Percentage; } else { output.SpecialType = SpecialVector2Type.Absolute; } float val; if (float.TryParse(part, out val)) { output.InputX = output.InputY = val; } else if (throwOnError) { throw new Exception("Failed to parse \'" + value + "\'. Expected a floating point number."); } } else if (split.Length == 2) { var p1 = split[0]; var p2 = split[1]; if (p1.EndsWith("%")) { output.SpecialType = SpecialVector2Type.Percentage; p1 = p1.TrimEnd('%'); p2 = p2.TrimEnd('%'); } else { output.SpecialType = SpecialVector2Type.Absolute; } float p1val, p2val; if (float.TryParse(p1, out p1val) && float.TryParse(p2, out p2val)) { output.InputX = p1val; output.InputY = p2val; } else if (throwOnError) { throw new Exception("Failed to parse \'" + value + "\'. Values must be floating point numbers and either both absolute, or both percentages."); } } else { if (throwOnError) { throw new Exception(value + " is the incorrect format. Expected one/two numbers split by a comma, they can also be percentages. (But not mixed)"); } } if (output.SpecialType == SpecialVector2Type.Percentage) { output.InputX /= 100f; output.InputY /= 100f; } return(output); }