Exemplo n.º 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");
                    }
                }
Exemplo n.º 2
0
                public string Apply(string StyleName, string Property, XmlAttributeCollection Attributes)
                {
                    string widgetValue;

                    if (Attributes != null)
                    {
                        widgetValue = Xml.Att(Attributes[Property]);
                    }
                    else
                    {
                        widgetValue = null;
                    }

                    // Widget widgetValue has precedence over defined styles
                    if (widgetValue != null && widgetValue != "")
                    {
                        return(widgetValue);
                    }
                    // Style is specified, attempt to decode it
                    else if (StyleName != null && StyleName != "")
                    {
                        string[] styleNames = StyleName.Split(' ');

                        // Style precedence is order of definition
                        foreach (string style in styleNames)
                        {
                            if (style != null && style != "")
                            {
                                if (styles.ContainsKey(style) == false)
                                {
                                    throw new Exception("Undefined style: " + style);
                                }

                                string value = styles[style].Get(Property);

                                if (value != null && value != "")
                                {
                                    return(styles[style].Get(Property));
                                }
                            }
                        }
                    }

                    // If a default style exists, use that, otherwise property is null
                    if (styles.ContainsKey("default"))
                    {
                        return(styles["default"].Get(Property));
                    }
                    else
                    {
                        return(null);
                    }
                }
Exemplo n.º 3
0
                protected void AddModal(Layout Parent, XmlNode XMLModal)
                {
                    string modalId = Xml.Att(XMLModal.Attributes["id"]);

                    AddPage(Parent, XMLModal);

                    Page modal = pages[modalId];

                    modal.rect.hAlign = new Alignment(Alignment.Type.Horizontal, Alignment.Direction.Center);
                    modal.rect.dim.x  = new Unit(styleSheet.Apply("__defaultMessageBox__", "width"));
                    modal.rect.dim.y  = new Unit(Xml.Att(XMLModal.Attributes["height"]));
                    modal.rect.pos.y  = new Unit(styleSheet.Apply("__defaultMessageBox__", "y"));
                }
Exemplo n.º 4
0
                /// <summary>
                /// Populates the layout with the elements contained within the supplied XML GUI layout.
                /// </summary>
                /// <param name="XMLGUI">The string containing the XML GUI Layout.</param>
                public Layout(ref string XMLGUI, object Handler) : base(null, null)
                {
                    handler      = Handler;
                    ids          = new Dictionary <string, Thing>();
                    modalOverlay = new Image(null, null, "rgba(0,0,0,224)", null, null, null, "100%", "100%", null, null, null);
                    styleSheet   = new StyleSheet();

                    // Skip comments
                    XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();

                    xmlReaderSettings.IgnoreComments = true;

                    using (XmlReader xmlReader = XmlReader.Create(new StringReader(XMLGUI), xmlReaderSettings))
                    {
                        XmlDocument xmlDoc = new XmlDocument();
                        xmlDoc.Load(xmlReader);
                        XmlNode xmlGui = xmlDoc.DocumentElement.SelectSingleNode("/layout");

                        id = Xml.Att(xmlGui.Attributes["id"]);
                        if (id == null)
                        {
                            throw new Exception("Layout id can't be null or blank");
                        }
                        RegisterId(this);

                        rect.dim.x = new Unit(Xml.Att(xmlGui.Attributes["width"]));
                        rect.dim.y = new Unit(Xml.Att(xmlGui.Attributes["height"]));
                        rect.pos.x = new Unit(null);
                        rect.pos.y = new Unit(null);

                        rect.hAlign = new Alignment(Alignment.Type.Horizontal, Xml.Att(xmlGui.Attributes["alignH"]));
                        rect.vAlign = new Alignment(Alignment.Type.Vertical, Xml.Att(xmlGui.Attributes["alignV"]));

                        if (rect.dim.x.value == null || rect.dim.y.value == null)
                        {
                            throw new Exception("Layout dimensions cannot be null");
                        }
                        if (rect.dim.x.type == Unit.Type.Percentage || rect.dim.y.type == Unit.Type.Percentage || rect.dim.x.type == Unit.Type.Pixel || rect.dim.y.type == Unit.Type.Pixel)
                        {
                            throw new Exception("Layout dimensions cannot be pixel or percentages");
                        }

                        AddChildren(xmlDoc.DocumentElement.ChildNodes, this);
                    }
                }
Exemplo n.º 5
0
                /// <summary>
                /// Adds a page widget to this page collection.
                /// </summary>
                /// <param name="Parent">The parent layout this page collection belongs to.</param>
                /// <param name="XMLPage">The page widget (in XML format) to add to this collection.</param>
                protected void AddPage(Layout Parent, XmlNode XMLPage)
                {
                    // Pages must have an id, otherwise there is no way to refer to them via code
                    if (Xml.Att(XMLPage.Attributes["id"]) == null)
                    {
                        throw new Exception("Encountered unnamed page in PageContainer");
                    }

                    Page p = new Page(Xml.Att(XMLPage.Attributes["id"]), Xml.Att(XMLPage.Attributes["title"]), Xml.Att(XMLPage.Attributes["visible"]));

                    p.guiDispatcher.AttachHandler("onFocus", Parent.handler, Xml.Att(XMLPage.Attributes["onFocus"]));

                    pages.Add(p.id, p);
                    Parent.RegisterId(p);

                    foreach (XmlNode xmlWidget in XMLPage.ChildNodes)
                    {
                        p.AddWidget(xmlWidget, Parent);
                    }
                }
Exemplo n.º 6
0
                public void Parse(XmlNode XMLStyleSheet)
                {
                    foreach (XmlNode xmlStyle in XMLStyleSheet.ChildNodes)
                    {
                        string name = Xml.Att(xmlStyle.Attributes["name"]);

                        // Empty style name is the same as "default"
                        if (name == null || name == "")
                        {
                            name = "__default__";
                        }

                        if (styles.ContainsKey(name) == false)
                        {
                            styles.Add(name, new PropertyCollection());
                        }

                        foreach (XmlAttribute a in xmlStyle.Attributes)
                        {
                            if (a.Name == "name")
                            {
                                continue;
                            }

                            string attName  = a.Name;
                            string attValue = a.InnerText;

                            if (attValue == null || attValue == "")
                            {
                                continue;
                            }

                            styles[name].Set(attName, attValue);
                        }
                    }
                }
Exemplo n.º 7
0
                /// <summary>
                /// Initializes the components of the input field to the values specified by the strings.
                /// </summary>
                /// <param name="ID">The unique id (if any) of this object.</param>
                /// <param name="Type">The type of the input field, as described below:
                /// <list type="table">
                /// <listheader>
                /// <term>Type</term>
                /// <term>Description</term>
                /// </listheader>
                /// <item>
                /// <term>Plain</term>
                /// <term>Standard text input field</term>
                /// </item>
                /// <item>
                /// <term>Password</term>
                /// <term>Input field that masks the inputted characters</term>
                /// </item>
                /// </list>
                /// The string values to determine the field type are as follows
                /// <list type="table">
                /// <listheader>
                /// <term>String Value</term>
                /// <term> InputType</term>
                /// </listheader>
                /// <item>
                /// <term>null or empty</term>
                /// <term>Plain</term>
                /// </item>
                /// <item>
                /// <term>plain</term>
                /// <term>Plain</term>
                /// </item>
                /// <item>
                /// <term>password</term>
                /// <term>Password</term>
                /// </item>
                /// </list>
                /// </param>
                /// <param name="Padding">The amount of padding the text will have from the interior sides of the input field.</param>
                /// <param name="MaxLength">The maximum character length the fiels will hold (0 for unlimited)</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>
                /// Add a password input field with an id of "myPassword", no padding or maximum length (child nodes omitted for clarity) spaced 10% from the left edge of the parent rect, measuring 100x100 virtual units and centered vertically
                /// <code>
                /// Input input = new Input("myPassword", "password", null, null, xmlChildren, "10%", null, "100", "100", null, "center");
                /// </code>
                /// </example>
                public Input(StyleSheet Styling, string ID, string Type, string MaxLength, 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)
                {
                    if (MaxLength != null && MaxLength != "")
                    {
                        maxLength = int.Parse(MaxLength);
                    }
                    else
                    {
                        maxLength = 0;
                    }

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

                        switch (element.Name)
                        {
                        case "text":

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

                            textUnfocus = Colour.Parse(Styling.Apply(style, "unfocusColour", element.Attributes));
                            padding     = new Unit(Styling.Apply(style, "padding", element.Attributes));

                            break;

                        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);

                            backgroundUnfocus = Colour.Parse(Styling.Apply(style, "unfocusColour", element.Attributes));

                            if (backgroundUnfocus != null && (id == null || id == ""))
                            {
                                throw new Exception("Input id is required for focus states");
                            }

                            break;

                        case "icon":

                            icon = new Image(null,
                                             Styling.Apply(style, "src", element.Attributes),
                                             Styling.Apply(style, "colour", element.Attributes),
                                             null,
                                             "0",
                                             "0",
                                             "0px",
                                             "0px",
                                             "right",
                                             null,
                                             null);

                            break;

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

                        if (text == null)
                        {
                            throw new Exception("Input text is required");
                        }
                        if (padding.value == null)
                        {
                            padding = new Unit("2.5%");
                        }
                    }

                    switch (Type)
                    {
                    case "":

                        type = Input.Type.Plain;
                        break;

                    case null:

                        type = Input.Type.Plain;
                        break;

                    case "plain":

                        type = Input.Type.Plain;
                        break;

                    case "password":

                        type = Input.Type.Password;
                        break;

                    default:

                        throw new Exception(string.Format("Unknown input type: {0}", Type));
                    }
                }
Exemplo n.º 8
0
                /// <summary>
                /// Parses the supplied XML node for widgets and adds them to this page.
                /// </summary>
                /// <param name="XMLWidget">The widget (in XML format) to add.</param>
                /// <param name="Parent">The parent layout this page belongs to.</param>
                /// <remarks>This constructor is used primarily in conjunction with XML-based layouts</remarks>
                public void AddWidget(XmlNode XMLWidget, Layout Parent)
                {
                    Presentable w     = null;
                    string      style = Xml.Att(XMLWidget.Attributes["style"]);

                    switch (XMLWidget.Name)
                    {
                    case "img":

                        w = new Image(Xml.Att(XMLWidget.Attributes["id"]),
                                      Parent.styleSheet.Apply(style, "src", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "colour", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "scale", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "x", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "y", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "width", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "height", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "alignH", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "alignV", XMLWidget.Attributes),
                                      Xml.Att(XMLWidget.Attributes["visible"]));
                        break;

                    case "label":

                        w = new Label(Xml.Att(XMLWidget.Attributes["id"]),
                                      XMLWidget.InnerText,
                                      Xml.Att(XMLWidget.Attributes["textAlign"]),
                                      Xml.Att(XMLWidget.Attributes["wordWrap"]),
                                      Parent.styleSheet.Apply(style, "colour", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "fontFace", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "fontSize", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "x", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "y", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "width", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "height", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "alignH", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "alignV", XMLWidget.Attributes),
                                      Xml.Att(XMLWidget.Attributes["visible"]));
                        break;

                    case "input":

                        w = new Input(Parent.styleSheet,
                                      Xml.Att(XMLWidget.Attributes["id"]),
                                      Xml.Att(XMLWidget.Attributes["type"]),
                                      Parent.styleSheet.Apply(style, "maxLength", XMLWidget.Attributes),
                                      XMLWidget.ChildNodes,
                                      Parent.styleSheet.Apply(style, "x", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "y", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "width", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "height", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "alignH", XMLWidget.Attributes),
                                      Parent.styleSheet.Apply(style, "alignV", XMLWidget.Attributes),
                                      Xml.Att(XMLWidget.Attributes["visible"]));

                        break;

                    case "button":

                        Button b = new Button(Parent.styleSheet, Xml.Att(XMLWidget.Attributes["id"]),
                                              XMLWidget.ChildNodes,
                                              Parent.styleSheet.Apply(style, "x", XMLWidget.Attributes),
                                              Parent.styleSheet.Apply(style, "y", XMLWidget.Attributes),
                                              Parent.styleSheet.Apply(style, "width", XMLWidget.Attributes),
                                              Parent.styleSheet.Apply(style, "height", XMLWidget.Attributes),
                                              Parent.styleSheet.Apply(style, "alignH", XMLWidget.Attributes),
                                              Parent.styleSheet.Apply(style, "alignV", XMLWidget.Attributes),
                                              Xml.Att(XMLWidget.Attributes["enabled"]),
                                              Xml.Att(XMLWidget.Attributes["visible"]));

                        b.guiDispatcher.AttachHandler("onClick", Parent.handler, Xml.Att(XMLWidget.Attributes["onClick"]));
                        w = b;
                        break;

                    case "tab":

                        w = new Tab(Parent.styleSheet, Xml.Att(XMLWidget.Attributes["id"]),
                                    Parent.styleSheet.Apply(style, "maxW", XMLWidget.Attributes),
                                    Parent,
                                    XMLWidget.ChildNodes,
                                    Parent.styleSheet.Apply(style, "x", XMLWidget.Attributes),
                                    Parent.styleSheet.Apply(style, "y", XMLWidget.Attributes),
                                    Parent.styleSheet.Apply(style, "width", XMLWidget.Attributes),
                                    Parent.styleSheet.Apply(style, "height", XMLWidget.Attributes),
                                    Parent.styleSheet.Apply(style, "alignH", XMLWidget.Attributes),
                                    Parent.styleSheet.Apply(style, "alignV", XMLWidget.Attributes),
                                    Xml.Att(XMLWidget.Attributes["visible"]));
                        break;

                    case "list":

                        List l = new List(Parent.styleSheet, Xml.Att(XMLWidget.Attributes["id"]),
                                          XMLWidget.ChildNodes,
                                          Parent.styleSheet.Apply(style, "x", XMLWidget.Attributes),
                                          Parent.styleSheet.Apply(style, "y", XMLWidget.Attributes),
                                          Parent.styleSheet.Apply(style, "width", XMLWidget.Attributes),
                                          Parent.styleSheet.Apply(style, "height", XMLWidget.Attributes),
                                          Parent.styleSheet.Apply(style, "alignH", XMLWidget.Attributes),
                                          Parent.styleSheet.Apply(style, "alignV", XMLWidget.Attributes),
                                          Xml.Att(XMLWidget.Attributes["visible"]));

                        l.guiDispatcher.AttachHandler("onClick", Parent.handler, Xml.Att(XMLWidget.Attributes["onClick"]));
                        w = l;

                        break;

                    default:

                        throw new Exception(string.Format("Encountered unknown widget: {0}", XMLWidget.Name));
                    }

                    widgets.Add(w);
                    Parent.RegisterId(w);
                }
Exemplo n.º 9
0
                protected void AddMessageBoxStyle(XmlNode XMLMessageBox)
                {
                    string name = Xml.Att(XMLMessageBox.Attributes["name"]);

                    // Empty style name is the same as "default"
                    if (name == null || name == "")
                    {
                        name = "__defaultMessageBox__";
                    }

                    PropertyCollection msgStyle = new PropertyCollection();

                    string style = Xml.Att(XMLMessageBox.Attributes["style"]);

                    msgStyle.Set("width", styleSheet.Apply(style, "width", XMLMessageBox.Attributes));
                    msgStyle.Set("y", styleSheet.Apply(style, "y", XMLMessageBox.Attributes));
                    msgStyle.Set("alignV", styleSheet.Apply(style, "alignV", XMLMessageBox.Attributes));

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

                        switch (element.Name)
                        {
                        case "title":

                            msgStyle.Set("titleFontSize", styleSheet.Apply(style, "fontSize", element.Attributes));
                            msgStyle.Set("titleFontFace", styleSheet.Apply(style, "fontFace", element.Attributes));
                            msgStyle.Set("titlePaddingTop", styleSheet.Apply(style, "paddingTop", element.Attributes));

                            break;

                        case "body":

                            msgStyle.Set("bodyFontSize", styleSheet.Apply(style, "fontSize", element.Attributes));
                            msgStyle.Set("bodyFontFace", styleSheet.Apply(style, "fontFace", element.Attributes));
                            msgStyle.Set("bodyPaddingTop", styleSheet.Apply(style, "paddingTop", element.Attributes));

                            break;

                        case "background":

                            msgStyle.Set("backgroundColour", styleSheet.Apply(style, "colour", element.Attributes));
                            msgStyle.Set("backgroundSrc", styleSheet.Apply(style, "src", element.Attributes));
                            break;

                        case "button":

                            msgStyle.Set("buttonPaddingTop", styleSheet.Apply(style, "paddingTop", element.Attributes));
                            msgStyle.Set("buttonY", styleSheet.Apply(style, "y", element.Attributes));
                            msgStyle.Set("buttonWidth", styleSheet.Apply(style, "width", element.Attributes));
                            msgStyle.Set("buttonHeight", styleSheet.Apply(style, "height", element.Attributes));

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

                                if (child.Name == "text")
                                {
                                    //msgStyle.Set("buttonTextAlign", styleSheet.Apply(style, "textAlign", child.Attributes));
                                    msgStyle.Set("buttonFontSize", styleSheet.Apply(style, "fontSize", child.Attributes));
                                    msgStyle.Set("buttonFontFace", styleSheet.Apply(style, "fontFace", child.Attributes));
                                }
                                else if (child.Name == "background")
                                {
                                    msgStyle.Set("buttonBackgroundSrc", styleSheet.Apply(style, "src", child.Attributes));
                                    msgStyle.Set("buttonBackgroundColour", styleSheet.Apply(style, "colour", child.Attributes));
                                    //msgStyle.Set("buttonBackgroundScale", styleSheet.Apply(style, "scale", child.Attributes));
                                }
                                else
                                {
                                    throw new Exception("Button has unexpected element: " + element.Name);
                                }
                            }

                            break;

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

                    styleSheet.Add(name, msgStyle);
                }
Exemplo n.º 10
0
                /// <summary>
                /// Initializes the components of the tab widget to the values specified by the strings.
                /// </summary>
                /// <param name="ID">The unique id (if any) of this object.</param>
                /// <param name="MaxTabWidth">The maximum (non-zero) width a page tab can be (can be null for unconstrained width)</param>
                /// <param name="Parent">The parent layout (used for adding and validating page/widget ids)</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 tab container rect 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 tab container rect 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 tab container rect.</param>
                /// <param name="H">The height of the tab container rect.</param>
                /// <param name="HAlign">The horizontal alignemnt of the tab container rect 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 tab container rect 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>
                public Tab(StyleSheet Styling, string ID, string MaxTabWidth, Layout Parent, 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)
                {
                    maxTabWidth = new Unit(MaxTabWidth);

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

                        // Tab header for defining tab sizes, backgrounds etc.
                        if (element.Name == "header")
                        {
                            headerHeight = new Unit(Styling.Apply(style, "height", element.Attributes));
                            maxTabWidth  = new Unit(Styling.Apply(style, "maxW", element.Attributes));

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

                                switch (hChild.Name)
                                {
                                case "background":

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

                                    break;

                                case "active":

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

                                    activeTab = new Button(null,
                                                           null,
                                                           null,
                                                           imgA,
                                                           "0",
                                                           "0",
                                                           "100%",
                                                           "100%",
                                                           null,
                                                           null,
                                                           Xml.Att(element.Attributes["enabled"]),
                                                           null);

                                    activeTab.guiDispatcher.AttachHandler("onClick", this, "tab_Click");

                                    break;

                                case "inactive":

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

                                    inactiveTab = new Button(null,
                                                             null,
                                                             null,
                                                             imgI,
                                                             "0",
                                                             "0",
                                                             "100%",
                                                             "100%",
                                                             null,
                                                             null,
                                                             Xml.Att(element.Attributes["enabled"]),
                                                             null);

                                    inactiveTab.guiDispatcher.AttachHandler("onClick", this, "tab_Click");

                                    break;

                                case "text":

                                    tabText = new Text(null,
                                                       "middleCenter",
                                                       null,
                                                       Styling.Apply(style, "colour", element.Attributes),
                                                       Styling.Apply(style, "fontFace", hChild.Attributes),
                                                       Styling.Apply(style, "fontSize", hChild.Attributes));

                                    break;

                                default: throw new Exception(string.Format("Encountered unknown tab child: {0}", element.Name));
                                }
                            }
                        }
                        else if (element.Name == "body")
                        {
                            bodyHeight = new Unit(Styling.Apply(style, "height", element.Attributes));

                            pages = new PageContainer(Xml.Att(element.Attributes["id"]), Xml.Att(element.Attributes["title"]));

                            pages.AddChildren(element.ChildNodes, Parent);

                            pages.ActivatePage(Xml.Att(element.FirstChild.Attributes["id"]));
                        }
                        else
                        {
                            throw new Exception("Unexpected child node in tab widget: " + element.Name);
                        }
                    }

                    if ((headerHeight == null || headerHeight.value == null) && (bodyHeight == null || bodyHeight.value == null))
                    {
                        throw new Exception("Tab must have either header or body element height specified");
                    }
                    if (activeTab == null)
                    {
                        throw new Exception("Tab must have active tab specified");
                    }
                    if (inactiveTab == null)
                    {
                        throw new Exception("Tab must have inactive tab specified");
                    }
                }
Exemplo n.º 11
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*/);
                }