Example #1
0
                /// <summary>
                /// Initializes the components of the button to the values specified by the strings.
                /// </summary>
                /// <param name="ID">The unique id (if any) of this object.</param>
                /// <param name="Children">The XML node list containing the child elements that compose the style of the button (see XML notation docs for further information).</param>
                /// <param name="X">The x positioning of the button relative to the parent as governed by the horizontal alignment as follows:
                /// <list type="table">
                /// <listheader>
                /// <term>Alignment</term>
                /// <term>X Position</term>
                /// </listheader>
                /// <item>
                /// <term>null or empty</term>
                /// <term>x units from parent's left edge</term>
                /// </item>
                /// <item>
                /// <term>Left</term>
                /// <term>x units from parent's left edge</term>
                /// </item>
                /// <item>
                /// <term>Center</term>
                /// <term>x position is ignored</term>
                /// </item>
                /// <item>
                /// <term>Right</term>
                /// <term>x units from parent's right edge</term>
                /// </item>
                /// </list>
                /// </param>
                /// <param name="Y">The y positioning of the button relative to the parent as governed by the vertical alignment as follows:
                /// <list type="table">
                /// <listheader>
                /// <term>Alignment</term>
                /// <term>Y Position</term>
                /// </listheader>
                /// <item>
                /// <term>null or empty</term>
                /// <term>y units from parent's top edge</term>
                /// </item>
                /// <item>
                /// <term>Top</term>
                /// <term>y units from parent's top edge</term>
                /// </item>
                /// <item>
                /// <term>Center</term>
                /// <term>y position is ignored</term>
                /// </item>
                /// <item>
                /// <term>Bottom</term>
                /// <term>y units from parent's bottom edge</term>
                /// </item>
                /// </list>
                /// </param>
                /// <param name="W">The width of the button.</param>
                /// <param name="H">The height of the button.</param>
                /// <param name="HAlign">The horizontal alignemnt of the button within the parent rect as specified by the following values:
                /// <list type="table">
                /// <listheader>
                /// <term>String Value</term>
                /// <term>Alignment.Type</term>
                /// </listheader>
                /// <item>
                /// <term>null or empty</term>
                /// <term>null</term>
                /// </item>
                /// <item>
                /// <term>left</term>
                /// <term>Alignment.Type.Left</term>
                /// </item>
                /// <item>
                /// <term>center</term>
                /// <term>Alignment.Type.Center</term>
                /// </item>
                /// <item>
                /// <term>right</term>
                /// <term>Alignment.Type.Right</term>
                /// </item>
                /// </list>
                /// </param>
                /// <param name="VAlign">The horizontal alignemnt of the button within the parent rect  as specified by the following values:
                /// <list type="table">
                /// <listheader>
                /// <term>String Value</term>
                /// <term>Alignment.Type</term>
                /// </listheader>
                /// <item>
                /// <term>null or empty</term>
                /// <term>null</term>
                /// </item>
                /// <item>
                /// <term>top</term>
                /// <term>Alignment.Type.Top</term>
                /// </item>
                /// <item>
                /// <term>center</term>
                /// <term>Alignment.Type.Center</term>
                /// </item>
                /// <item>
                /// <term>bottom</term>
                /// <term>Alignment.Type.Bottom</term>
                /// </item>
                /// </list>
                /// </param>
                /// <remarks>This constructor is used primarily in conjunction with XML-based layouts</remarks>
                /// <example>
                /// Instantiate a button object with an id of "myButton" (child nodes omitted for clarity) spaced 10% from the left edge of the parent rect, measuring 100x100 virtual units and centered vertically:
                /// <code>
                /// Button button = new Button("myButton", xmlChildren, "10%", null, "100", "100", null, "center");
                /// </code>
                /// </example>
                public Button(StyleSheet Styling, string ID, XmlNodeList Children, string X, string Y, string W, string H, string HAlign, string VAlign, string Enabled, string Visible) : base(ID, X, Y, W, H, HAlign, VAlign, Visible)
                {
                    _guiDispatcher = new GUIEventDispatcher(/*this*/);

                    enabled = Enabled == null || Enabled == "" ? true : bool.Parse(Enabled);

                    foreach (XmlNode element in Children)
                    {
                        string style = Xml.Att(element.Attributes["style"]);

                        switch (element.Name)
                        {
                        // Text styling
                        case "text":

                            string textAlign = Styling.Apply(style, "textAlign", element.Attributes);

                            if (textAlign == "" || textAlign == null)
                            {
                                textAlign = "middleCenter";
                            }

                            text = new Text(element.InnerText,
                                            textAlign,
                                            null,
                                            Styling.Apply(style, "colour", element.Attributes),
                                            Styling.Apply(style, "fontFace", element.Attributes),
                                            Styling.Apply(style, "fontSize", element.Attributes));

                            textDisabled = Colour.Parse(Xml.Att(element.Attributes["disabledColour"]));

                            break;

                        // Background
                        case "background":

                            background = new Image(null,
                                                   Styling.Apply(style, "src", element.Attributes),
                                                   Styling.Apply(style, "colour", element.Attributes),
                                                   Styling.Apply(style, "scale", element.Attributes),
                                                   "0",
                                                   "0",
                                                   "100%",
                                                   "100%",
                                                   null,
                                                   null,
                                                   null);

                            break;

                        default: throw new Exception("Button has unexpected element: " + element.Name);
                        }
                    }

                    if (background == null)
                    {
                        throw new Exception("Button background is required");
                    }
                }
Example #2
0
 /// <summary>
 /// Initializes the components of the button to the specified values.
 /// </summary>
 /// <param name="ID">The unique id (if any) of this object.</param>
 /// <param name="T">The Text object representing the test and styling of the button label.</param>
 /// <param name="B">The image object representing the button background.</param>
 /// <param name="X">The x positioning of the button relative to the parent as governed by the horizontal alignment as follows:
 /// <list type="table">
 /// <listheader>
 /// <term>Alignment</term>
 /// <term>X Position</term>
 /// </listheader>
 /// <item>
 /// <term>null or empty</term>
 /// <term>x units from parent's left edge</term>
 /// </item>
 /// <item>
 /// <term>Left</term>
 /// <term>x units from parent's left edge</term>
 /// </item>
 /// <item>
 /// <term>Center</term>
 /// <term>x position is ignored</term>
 /// </item>
 /// <item>
 /// <term>Right</term>
 /// <term>x units from parent's right edge</term>
 /// </item>
 /// </list>
 /// </param>
 /// <param name="Y">The y positioning of the button relative to the parent as governed by the vertical alignment as follows:
 /// <list type="table">
 /// <listheader>
 /// <term>Alignment</term>
 /// <term>Y Position</term>
 /// </listheader>
 /// <item>
 /// <term>null or empty</term>
 /// <term>y units from parent's top edge</term>
 /// </item>
 /// <item>
 /// <term>Top</term>
 /// <term>y units from parent's top edge</term>
 /// </item>
 /// <item>
 /// <term>Center</term>
 /// <term>y position is ignored</term>
 /// </item>
 /// <item>
 /// <term>Bottom</term>
 /// <term>y units from parent's bottom edge</term>
 /// </item>
 /// </list>
 /// </param>
 /// <param name="W">The width of the button.</param>
 /// <param name="H">The height of the button.</param>
 /// <param name="HAlign">The horizontal alignemnt of the label within the parent rect as specified by the following values:
 /// <list type="table">
 /// <listheader>
 /// <term>String Value</term>
 /// <term>Alignment.Type</term>
 /// </listheader>
 /// <item>
 /// <term>null or empty</term>
 /// <term>null</term>
 /// </item>
 /// <item>
 /// <term>left</term>
 /// <term>Alignment.Type.Left</term>
 /// </item>
 /// <item>
 /// <term>center</term>
 /// <term>Alignment.Type.Center</term>
 /// </item>
 /// <item>
 /// <term>right</term>
 /// <term>Alignment.Type.Right</term>
 /// </item>
 /// </list>
 /// </param>
 /// <param name="VAlign">The horizontal alignemnt of the label within the parent rect  as specified by the following values:
 /// <list type="table">
 /// <listheader>
 /// <term>String Value</term>
 /// <term>Alignment.Type</term>
 /// </listheader>
 /// <item>
 /// <term>null or empty</term>
 /// <term>null</term>
 /// </item>
 /// <item>
 /// <term>top</term>
 /// <term>Alignment.Type.Top</term>
 /// </item>
 /// <item>
 /// <term>center</term>
 /// <term>Alignment.Type.Center</term>
 /// </item>
 /// <item>
 /// <term>bottom</term>
 /// <term>Alignment.Type.Bottom</term>
 /// </item>
 /// </list>
 /// </param>
 /// <example>
 /// Instantiate a button object with an id of "myButton" (child objects omitted for clarity) spaced 10% from the left edge of the parent rect, measuring 100x100 virtual units and centered vertically:
 /// <code>
 /// Button button = new Button("myButton", textLabel, imgBackground, "10%", null, "100", "100", null, "center");
 /// </code>
 /// </example>
 public Button(string ID, Text T, UnityEngine.Color?TextDisabled, Image B, string X, string Y, string W, string H, string HAlign, string VAlign, string Enabled, string Visible) : base(ID, X, Y, W, H, HAlign, VAlign, Visible)
 {
     text           = T == null ? null : new Text(T);
     textDisabled   = TextDisabled;
     _background    = B;
     _guiDispatcher = new GUIEventDispatcher(/*this*/);
     enabled        = Enabled == null || Enabled == "" ? true : bool.Parse(Enabled);
 }
Example #3
0
 public Page(string ID, string Title, string X, string Y, string W, string H, string HAlign, string VAlign, string Visible) : base(ID, X, Y, W, H, HAlign, VAlign, Visible)
 {
     title          = Title;
     widgets        = new List <Presentable>();
     _guiDispatcher = new GUIEventDispatcher(/*this*/);
 }
Example #4
0
 /// <summary>
 /// Initializes the components of the page widget to the values specified by the strings.
 /// </summary>
 /// <param name="ID">The unique id (if any) of this object.</param>
 /// <param name="Title">The title (if any) of this page.</param>
 public Page(string ID, string Title, string Visible) : base(ID, "0", "0", "100%", "100%", null, null, null)
 {
     title          = Title;
     widgets        = new List <Presentable>();
     _guiDispatcher = new GUIEventDispatcher(/*this*/);
 }
Example #5
0
                /// <summary>
                /// Initializes the components of the list to the values specified by the strings.
                /// </summary>
                /// <param name="ID">The unique id (if any) of this object.</param>
                /// <param name="Children">The XML node list containing the child elements that compose the style of the button (see XML notation docs for further information).</param>
                /// <param name="X">The x positioning of the list relative to the parent as governed by the horizontal alignment as follows:
                /// <list type="table">
                /// <listheader>
                /// <term>Alignment</term>
                /// <term>X Position</term>
                /// </listheader>
                /// <item>
                /// <term>null or empty</term>
                /// <term>x units from parent's left edge</term>
                /// </item>
                /// <item>
                /// <term>Left</term>
                /// <term>x units from parent's left edge</term>
                /// </item>
                /// <item>
                /// <term>Center</term>
                /// <term>x position is ignored</term>
                /// </item>
                /// <item>
                /// <term>Right</term>
                /// <term>x units from parent's right edge</term>
                /// </item>
                /// </list>
                /// </param>
                /// <param name="Y">The y positioning of the list relative to the parent as governed by the vertical alignment as follows:
                /// <list type="table">
                /// <listheader>
                /// <term>Alignment</term>
                /// <term>Y Position</term>
                /// </listheader>
                /// <item>
                /// <term>null or empty</term>
                /// <term>y units from parent's top edge</term>
                /// </item>
                /// <item>
                /// <term>Top</term>
                /// <term>y units from parent's top edge</term>
                /// </item>
                /// <item>
                /// <term>Center</term>
                /// <term>y position is ignored</term>
                /// </item>
                /// <item>
                /// <term>Bottom</term>
                /// <term>y units from parent's bottom edge</term>
                /// </item>
                /// </list>
                /// </param>
                /// <param name="W">The width of the list.</param>
                /// <param name="H">The height of the list.</param>
                /// <param name="HAlign">The horizontal alignemnt of the list within the parent rect as specified by the following values:
                /// <list type="table">
                /// <listheader>
                /// <term>String Value</term>
                /// <term>Alignment.Type</term>
                /// </listheader>
                /// <item>
                /// <term>null or empty</term>
                /// <term>null</term>
                /// </item>
                /// <item>
                /// <term>left</term>
                /// <term>Alignment.Type.Left</term>
                /// </item>
                /// <item>
                /// <term>center</term>
                /// <term>Alignment.Type.Center</term>
                /// </item>
                /// <item>
                /// <term>right</term>
                /// <term>Alignment.Type.Right</term>
                /// </item>
                /// </list>
                /// </param>
                /// <param name="VAlign">The horizontal alignemnt of the list within the parent rect  as specified by the following values:
                /// <list type="table">
                /// <listheader>
                /// <term>String Value</term>
                /// <term>Alignment.Type</term>
                /// </listheader>
                /// <item>
                /// <term>null or empty</term>
                /// <term>null</term>
                /// </item>
                /// <item>
                /// <term>top</term>
                /// <term>Alignment.Type.Top</term>
                /// </item>
                /// <item>
                /// <term>center</term>
                /// <term>Alignment.Type.Center</term>
                /// </item>
                /// <item>
                /// <term>bottom</term>
                /// <term>Alignment.Type.Bottom</term>
                /// </item>
                /// </list>
                /// </param>
                /// <remarks>This constructor is used primarily in conjunction with XML-based layouts</remarks>
                /// <example>
                /// Instantiate a list object with a null id (child nodes omitted for clarity) spaced 10% from the left edge of the parent rect, measuring 800x500 virtual units:
                /// <code>
                /// List list = new List(null, xmlChildren, "10%", null, "800", "500", null, null);
                /// </code>
                /// </example>
                public List(StyleSheet Styling, string ID, XmlNodeList Children, string X, string Y, string W, string H, string HAlign, string VAlign, string Visible) : base(ID, X, Y, W, H, HAlign, VAlign, Visible)
                {
                    items = new Dictionary <string, Button>();

                    foreach (XmlNode element in Children)
                    {
                        string style = Xml.Att(element.Attributes["style"]);

                        switch (element.Name)
                        {
                        // Text styling
                        case "text":

                            _text = new Button(null, null, null, null, null, null, null, null, null, null, null, null);

                            text = new Text(null,
                                            "middleLeft",
                                            null,
                                            Styling.Apply(style, "colour", element.Attributes),
                                            Styling.Apply(style, "fontFace", element.Attributes),
                                            Styling.Apply(style, "fontSize", element.Attributes));

                            _text.textDisabled = Colour.Parse(Xml.Att(element.Attributes["disabledColour"]));

                            break;

                        // Icon (bullet) image
                        case "icon":

                            icon = new Image(null,
                                             Styling.Apply(style, "src", element.Attributes),
                                             Styling.Apply(style, "colour", element.Attributes),
                                             Styling.Apply(style, "scale", element.Attributes),
                                             "0",
                                             "0",
                                             "50%",
                                             "50%",
                                             "center",
                                             "center",
                                             null);

                            break;

                        // List item
                        case "li":

                            Button item = new Button(null, text, null, null, null, null, null, null, null, null, Xml.Att(element.Attributes["enabled"]), Xml.Att(element.Attributes["visible"]));
                            item.text.text = element.InnerText;

                            items.Add(Xml.Att(element.Attributes["key"]), item);
                            break;

                        default: throw new Exception(string.Format("Encountered unknown list child: {0}", element.Name));
                        }
                    }

                    if (text == null)
                    {
                        throw new Exception(string.Format("List text member cannot be null (id: {0})", id));
                    }

                    _guiDispatcher = new GUIEventDispatcher(/*this*/);
                }