private void Form1_KeyDown(object sender, KeyEventArgs e) { //Button to refresh the entire layout. if (e.KeyCode == Keys.F5) { //Add the controls we generated to the form. foreach (var controls in userInterface.GetControlRenderList) { Controls.Remove(controls); } userInterface = null; //Create a grid based on the forms widht/height, feed that into the UI generator. UIGrid grid = new UIGrid(Width, Height); userInterface = new UIGenerator(grid); //Load the XML file and generate the controls. UIParser parser = new UIParser(); parser.LoadLayout(userInterface); //Add the controls we generated to the form. foreach (var controls in userInterface.GetControlRenderList) { Controls.Add(controls); } } if (e.KeyCode == Keys.F7) { sx += 0.01f; grid.Scale(sx, sy); userInterface.Refresh(Width, Height); } if (e.KeyCode == Keys.F8) { sx -= 0.01f; grid.Scale(sx, sy); userInterface.Refresh(Width, Height); } if (e.KeyCode == Keys.F9) { sy += 0.01f; grid.Scale(sx, sy); userInterface.Refresh(Width, Height); } if (e.KeyCode == Keys.F10) { sy -= 0.01f; grid.Scale(sx, sy); userInterface.Refresh(Width, Height); } }
public void TestLengthPercentParse() { StyleLength length = UIParser.ToStyleLength("100%"); Assert.AreEqual(length.keyword, StyleKeyword.Undefined); Assert.AreEqual(length.value.unit, LengthUnit.Percent); Assert.AreEqual(length.value.value, 100.0f); }
internal _UnityVisualElement ApplyClassToVisualElement(string className, _UnityVisualElement visualElement) { //Logger.Log("[UI] Attempting to apply class [" + className + "] to [" + visualElement.name + "]"); UssClass ussClass = classes[className]; foreach (string line in ussClass.Lines) { visualElement = UIParser.ParseEntry(line, visualElement); } return(visualElement); }
public UIControl(SetControlPropsNode Node, UIScreen Screen, UIParser.ParserState State) : base(Screen) { Name = Node.Control; if (!State.InSharedPropertiesGroup) { if (Node.Image != "") Image = m_Screen.GetImage(Node.Image, false); } else { if(State.Image != "") Image = m_Screen.GetImage(State.Image, true); if (State.LeftArrowImage != "") m_LeftArrowImage = State.LeftArrowImage; if (State.RightArrowImage != "") m_RightArrowImage = State.RightArrowImage; } if (Node.PositionAssignment != null) Position = new Vector2(Node.PositionAssignment[0], Node.PositionAssignment[1]); if(Node.Size != null) m_Size = new Vector2(Node.Size.Numbers[0], Node.Size.Numbers[1]); if(Node.ThumbSize != null) m_ThumbSize = new Vector2(Node.ThumbSize.Numbers[0], Node.ThumbSize.Numbers[1]); if (Node.ThumbMargins != null) m_ThumbMargins = new Vector2(Node.ThumbMargins.Numbers[0], Node.ThumbMargins.Numbers[1]); if (Node.ThumbImageSize != null) m_ThumbImageSize = new Vector2(Node.ThumbImageSize.Numbers[0], Node.ThumbImageSize.Numbers[1]); if (Node.ThumbImageOffsets != null) m_ThumbImageOffsets = new Vector2(Node.ThumbImageOffsets.Numbers[0], Node.ThumbImageOffsets.Numbers[1]); if (Node.ThumbButtonImage != null) m_ThumbButtonImage = Node.ThumbButtonImage; }
/// <summary> /// On form1 load, setup the custom user interface stuff. /// </summary> private void Form1_Load(object sender, EventArgs e) { Text = "RPN Calculator"; //Create a grid based on the forms widht/height, feed that into the UI generator. grid = new UIGrid(Width, Height); userInterface = new UIGenerator(grid); //Load the XML file and generate the controls. UIParser parser = new UIParser(); parser.LoadLayout(userInterface); //Add the controls we generated to the form. foreach (var controls in userInterface.GetControlRenderList) { Controls.Add(controls); } UIEvents events = new UIEvents(userInterface); KeyPreview = true; }
public static UI Load(string path, Game game, Dictionary <string, string> texts, Dictionary <string, Action <object, EventArgs> > callbacks) { var p = new UIParser(path); return(p.Parse(game, texts, callbacks)); }
public void TestMapCssName() { Assert.AreEqual(UIParser.MapCssName("flex-direction"), "flexDirection"); Assert.AreEqual(UIParser.MapCssName("height"), "height"); Assert.AreEqual(UIParser.MapCssName("-unity-background-image-tint-color"), "unityBackgroundImageTintColor"); }
public static List <LogInfo> Set(EngineState s, CodeCommand cmd) { CodeInfo_Set info = cmd.Info.Cast <CodeInfo_Set>(); Variables.VarKeyType varType = Variables.DetectType(info.VarKey); if (varType == Variables.VarKeyType.None) { // Check Macro if (Regex.Match(info.VarKey, Macro.MacroNameRegex, RegexOptions.Compiled | RegexOptions.CultureInvariant).Success) // Macro Name Validation { string macroCommand = StringEscaper.Preprocess(s, info.VarValue); if (macroCommand.Equals("NIL", StringComparison.OrdinalIgnoreCase)) { macroCommand = null; } LogInfo log = s.Macro.SetMacro(info.VarKey, macroCommand, cmd.Section, info.Permanent, false); return(new List <LogInfo>(1) { log }); } } // [WB082 Behavior] -> Enabled if s.CompatAllowSetModifyInterface == true // If PERMANENT was used but the key exists in interface command, the value will not be written to script.project but in interface. // Need to investigate where the logs are saved in this case. switch (info.Permanent) { case true: { // Check if interface contains VarKey List <LogInfo> logs = new List <LogInfo>(); if (Variables.DetectType(info.VarKey) != Variables.VarKeyType.Variable) { goto case false; } #region Set interface control's value (Compat) if (s.CompatAllowSetModifyInterface) { string varKey = Variables.TrimPercentMark(info.VarKey); string finalValue = StringEscaper.Preprocess(s, info.VarValue); Script sc = cmd.Section.Script; ScriptSection iface = sc.GetInterfaceSection(out _); if (iface == null) { goto case false; } (List <UIControl> uiCtrls, _) = UIParser.ParseStatements(iface.Lines, iface); UIControl uiCtrl = uiCtrls.Find(x => x.Key.Equals(varKey, StringComparison.OrdinalIgnoreCase)); if (uiCtrl == null) { goto case false; } bool valid = uiCtrl.SetValue(finalValue, false, out List <LogInfo> varLogs); logs.AddRange(varLogs); if (valid) { uiCtrl.Update(); // Also update variables logs.AddRange(Variables.SetVariable(s, info.VarKey, info.VarValue, false, false)); return(logs); } } goto case false; #endregion } case false: default: return(Variables.SetVariable(s, info.VarKey, info.VarValue, info.Global, info.Permanent)); } }
/// <summary> /// Walks a generated AST (Abstract Syntax Tree) and creates the elements of this UIScreen. /// </summary> /// <param name="State">A ParserState instance.</param> /// <param name="node">The root node of the AST.</param> private void WalkTree(UIParser.ParserState State, AstNode node) { NodeType NType = (NodeType)Enum.Parse(typeof(NodeType), node.ToString(), true); switch (NType) { case NodeType.DefineImage: //Defines an image and loads a texture for it. DefineImageNode ImgNode = (DefineImageNode)UINode.GetNode(node); UIImage Img = new UIImage(ImgNode, m_Screen); Elements.Add(ImgNode.Name, Img); break; case NodeType.DefineString: //Defines a string with a name. DefineStringNode StrNode = (DefineStringNode)UINode.GetNode(node); Strings.Add(StrNode.Name, StringManager.StrTable(State.CurrentStringTable)[StrNode.StrIndex]); break; case NodeType.AddButton: //Defines a button. AddButtonNode ButtonNode = (AddButtonNode)UINode.GetNode(node); UIButton Btn = new UIButton(ButtonNode, State, m_Screen); Elements.Add(ButtonNode.Name, Btn); break; case NodeType.AddText: AddTextNode TextNode = (AddTextNode)UINode.GetNode(node); UILabel Lbl = new UILabel(TextNode, State, m_Screen); Elements.Add(TextNode.Name, Lbl); break; case NodeType.AddTextEdit: AddTextEditNode TextEditNode = (AddTextEditNode)UINode.GetNode(node); UITextEdit Txt = new UITextEdit(TextEditNode, State, m_Screen); Elements.Add(TextEditNode.Name, Txt); break; case NodeType.AddSlider: AddSliderNode SliderNode = (AddSliderNode)UINode.GetNode(node); UISlider Slider = new UISlider(SliderNode, State, m_Screen); Elements.Add(SliderNode.Name, Slider); break; case NodeType.SetSharedProperties: //Assigns a bunch of shared properties to declarations following the statement. State.InSharedPropertiesGroup = true; SetSharedPropsNode SharedPropsNode = (SetSharedPropsNode)UINode.GetNode(node); if (SharedPropsNode.StringTable != null) State.CurrentStringTable = (int)SharedPropsNode.StringTable; if (SharedPropsNode.ControlPosition != null) { State.Position[0] = SharedPropsNode.ControlPosition.Numbers[0]; State.Position[1] = SharedPropsNode.ControlPosition.Numbers[1]; break; } if (SharedPropsNode.Color != null) { State.Color = new Color(); State.Color.R = (byte)SharedPropsNode.Color.Numbers[0]; State.Color.G = (byte)SharedPropsNode.Color.Numbers[1]; State.Color.B = (byte)SharedPropsNode.Color.Numbers[2]; } if (SharedPropsNode.TextColor != null) { State.TextColor = new Color(); State.TextColor.R = (byte)SharedPropsNode.TextColor.Numbers[0]; State.TextColor.G = (byte)SharedPropsNode.TextColor.Numbers[1]; State.TextColor.B = (byte)SharedPropsNode.TextColor.Numbers[2]; } if (SharedPropsNode.TextColorSelected != null) { State.TextColorSelected = new Color(); State.TextColorSelected.R = (byte)SharedPropsNode.TextColorSelected.Numbers[0]; State.TextColorSelected.G = (byte)SharedPropsNode.TextColorSelected.Numbers[1]; State.TextColorSelected.B = (byte)SharedPropsNode.TextColorSelected.Numbers[2]; } if (SharedPropsNode.TextColorHighlighted != null) { State.TextColorHighlighted = new Color(); State.TextColorHighlighted.R = (byte)SharedPropsNode.TextColorHighlighted.Numbers[0]; State.TextColorHighlighted.G = (byte)SharedPropsNode.TextColorHighlighted.Numbers[1]; State.TextColorHighlighted.B = (byte)SharedPropsNode.TextColorHighlighted.Numbers[2]; } if (SharedPropsNode.TextColorDisabled != null) { State.TextColorDisabled = new Color(); State.TextColorDisabled.R = (byte)SharedPropsNode.TextColorDisabled.Numbers[0]; State.TextColorDisabled.G = (byte)SharedPropsNode.TextColorDisabled.Numbers[1]; State.TextColorDisabled.B = (byte)SharedPropsNode.TextColorDisabled.Numbers[2]; } if (SharedPropsNode.BackColor != null) { State.BackColor = new Color(); State.BackColor.R = (byte)SharedPropsNode.BackColor.Numbers[0]; State.BackColor.G = (byte)SharedPropsNode.BackColor.Numbers[1]; State.BackColor.B = (byte)SharedPropsNode.BackColor.Numbers[2]; } if (SharedPropsNode.CursorColor != null) { State.CursorColor = new Color(); State.CursorColor.R = (byte)SharedPropsNode.CursorColor.Numbers[0]; State.CursorColor.G = (byte)SharedPropsNode.CursorColor.Numbers[1]; State.CursorColor.B = (byte)SharedPropsNode.CursorColor.Numbers[2]; } if (SharedPropsNode.TextButton) State.TextButton = true; if (SharedPropsNode.Opaque != null) State.IsOpaque = (SharedPropsNode.Opaque == 1) ? true : false; if (SharedPropsNode.Transparent != null) State.IsTransparent = (SharedPropsNode.Transparent == 1) ? true : false; if (SharedPropsNode.Alignment != null) State.Alignment = (int)SharedPropsNode.Alignment; if (SharedPropsNode.Image != "") State.Image = SharedPropsNode.Image; if (SharedPropsNode.Tooltip != "") State.Tooltip = SharedPropsNode.Tooltip; if (SharedPropsNode.Text != "") State.Caption = SharedPropsNode.Text; if (SharedPropsNode.Size != null) State.Size = new Vector2(SharedPropsNode.Size.Numbers[0], SharedPropsNode.Size.Numbers[1]); if (SharedPropsNode.Orientation != null) State.Orientation = (int)SharedPropsNode.Orientation; if (SharedPropsNode.Font != null) State.Font = (int)SharedPropsNode.Font; if (SharedPropsNode.Opaque != null) State.Opaque = (int)SharedPropsNode.Opaque; break; case NodeType.SetControlProperties: //Sets a bunch of properties to a specified control. SetControlPropsNode ControlPropsNode = (SetControlPropsNode)UINode.GetNode(node); UIControl Ctrl = new UIControl(ControlPropsNode, m_Screen, State); Controls.Add(ControlPropsNode.Control, Ctrl); if (State.InSharedPropertiesGroup) { UIElement Test = new UIElement(m_Screen, null); //Script implicitly created an object... :\ if (!Elements.TryGetValue(ControlPropsNode.Control, out Test)) { Elements.Add(ControlPropsNode.Control, new UIElement(m_Screen, null)); if (Ctrl.Image != null) Elements[ControlPropsNode.Control].Image = new UIImage(Ctrl.Image); Elements[ControlPropsNode.Control].Position = Ctrl.Position; } } break; case NodeType.End: State.InSharedPropertiesGroup = false; State.Image = ""; //Reset State.TextButton = false; //Reset State.Color = new Color(); State.Caption = ""; //TODO: Reset more? break; } foreach (AstNode child in node.ChildNodes) WalkTree(State, child); }
public VisualElement GetElement(string name) => UIParser.CreateVisualElement(name, _document);