Exemple #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");
                    }
                }
        internal void ApplyRule(StyleSheet registry, int specificity, StyleRule rule, StylePropertyID[] propertyIDs, LoadResourceFunction loadResourceFunc)
        {
            for (int i = 0; i < rule.properties.Length; i++)
            {
                StyleProperty    styleProperty   = rule.properties[i];
                StylePropertyID  stylePropertyID = propertyIDs[i];
                StyleValueHandle handle          = styleProperty.values[0];
                switch (stylePropertyID)
                {
                case StylePropertyID.MarginLeft:
                    registry.Apply(handle, specificity, ref this.marginLeft);
                    break;

                case StylePropertyID.MarginTop:
                    registry.Apply(handle, specificity, ref this.marginTop);
                    break;

                case StylePropertyID.MarginRight:
                    registry.Apply(handle, specificity, ref this.marginRight);
                    break;

                case StylePropertyID.MarginBottom:
                    registry.Apply(handle, specificity, ref this.marginBottom);
                    break;

                case StylePropertyID.PaddingLeft:
                    registry.Apply(handle, specificity, ref this.paddingLeft);
                    break;

                case StylePropertyID.PaddingTop:
                    registry.Apply(handle, specificity, ref this.paddingTop);
                    break;

                case StylePropertyID.PaddingRight:
                    registry.Apply(handle, specificity, ref this.paddingRight);
                    break;

                case StylePropertyID.PaddingBottom:
                    registry.Apply(handle, specificity, ref this.paddingBottom);
                    break;

                case StylePropertyID.BorderLeft:
                    registry.Apply(handle, specificity, ref this.borderLeft);
                    break;

                case StylePropertyID.BorderTop:
                    registry.Apply(handle, specificity, ref this.borderTop);
                    break;

                case StylePropertyID.BorderRight:
                    registry.Apply(handle, specificity, ref this.borderRight);
                    break;

                case StylePropertyID.BorderBottom:
                    registry.Apply(handle, specificity, ref this.borderBottom);
                    break;

                case StylePropertyID.PositionType:
                    registry.Apply(handle, specificity, ref this.positionType);
                    break;

                case StylePropertyID.PositionLeft:
                    registry.Apply(handle, specificity, ref this.positionLeft);
                    break;

                case StylePropertyID.PositionTop:
                    registry.Apply(handle, specificity, ref this.positionTop);
                    break;

                case StylePropertyID.PositionRight:
                    registry.Apply(handle, specificity, ref this.positionRight);
                    break;

                case StylePropertyID.PositionBottom:
                    registry.Apply(handle, specificity, ref this.positionBottom);
                    break;

                case StylePropertyID.Width:
                    registry.Apply(handle, specificity, ref this.width);
                    break;

                case StylePropertyID.Height:
                    registry.Apply(handle, specificity, ref this.height);
                    break;

                case StylePropertyID.MinWidth:
                    registry.Apply(handle, specificity, ref this.minWidth);
                    break;

                case StylePropertyID.MinHeight:
                    registry.Apply(handle, specificity, ref this.minHeight);
                    break;

                case StylePropertyID.MaxWidth:
                    registry.Apply(handle, specificity, ref this.maxWidth);
                    break;

                case StylePropertyID.MaxHeight:
                    registry.Apply(handle, specificity, ref this.maxHeight);
                    break;

                case StylePropertyID.Flex:
                    registry.Apply(handle, specificity, ref this.flex);
                    break;

                case StylePropertyID.BorderWidth:
                    registry.Apply(handle, specificity, ref this.borderWidth);
                    break;

                case StylePropertyID.BorderRadius:
                    registry.Apply(handle, specificity, ref this.borderRadius);
                    break;

                case StylePropertyID.FlexDirection:
                    registry.Apply(handle, specificity, ref this.flexDirection);
                    break;

                case StylePropertyID.FlexWrap:
                    registry.Apply(handle, specificity, ref this.flexWrap);
                    break;

                case StylePropertyID.JustifyContent:
                    registry.Apply(handle, specificity, ref this.justifyContent);
                    break;

                case StylePropertyID.AlignContent:
                    registry.Apply(handle, specificity, ref this.alignContent);
                    break;

                case StylePropertyID.AlignSelf:
                    registry.Apply(handle, specificity, ref this.alignSelf);
                    break;

                case StylePropertyID.AlignItems:
                    registry.Apply(handle, specificity, ref this.alignItems);
                    break;

                case StylePropertyID.TextAlignment:
                    registry.Apply(handle, specificity, ref this.textAlignment);
                    break;

                case StylePropertyID.TextClipping:
                    registry.Apply(handle, specificity, ref this.textClipping);
                    break;

                case StylePropertyID.Font:
                    registry.Apply(handle, specificity, loadResourceFunc, ref this.font);
                    break;

                case StylePropertyID.FontSize:
                    registry.Apply(handle, specificity, ref this.fontSize);
                    break;

                case StylePropertyID.FontStyle:
                    registry.Apply(handle, specificity, ref this.fontStyle);
                    break;

                case StylePropertyID.BackgroundSize:
                    registry.Apply(handle, specificity, ref this.backgroundSize);
                    break;

                case StylePropertyID.WordWrap:
                    registry.Apply(handle, specificity, ref this.wordWrap);
                    break;

                case StylePropertyID.BackgroundImage:
                    registry.Apply(handle, specificity, loadResourceFunc, ref this.backgroundImage);
                    break;

                case StylePropertyID.TextColor:
                    registry.Apply(handle, specificity, ref this.textColor);
                    break;

                case StylePropertyID.BackgroundColor:
                    registry.Apply(handle, specificity, ref this.backgroundColor);
                    break;

                case StylePropertyID.BorderColor:
                    registry.Apply(handle, specificity, ref this.borderColor);
                    break;

                case StylePropertyID.Overflow:
                    registry.Apply(handle, specificity, ref this.overflow);
                    break;

                case StylePropertyID.SliceLeft:
                    registry.Apply(handle, specificity, ref this.sliceLeft);
                    break;

                case StylePropertyID.SliceTop:
                    registry.Apply(handle, specificity, ref this.sliceTop);
                    break;

                case StylePropertyID.SliceRight:
                    registry.Apply(handle, specificity, ref this.sliceRight);
                    break;

                case StylePropertyID.SliceBottom:
                    registry.Apply(handle, specificity, ref this.sliceBottom);
                    break;

                case StylePropertyID.Opacity:
                    registry.Apply(handle, specificity, ref this.opacity);
                    break;

                case StylePropertyID.Custom:
                {
                    if (this.m_CustomProperties == null)
                    {
                        this.m_CustomProperties = new Dictionary <string, CustomProperty>();
                    }
                    CustomProperty value = default(CustomProperty);
                    if (!this.m_CustomProperties.TryGetValue(styleProperty.name, out value) || specificity >= value.specificity)
                    {
                        value.handle      = handle;
                        value.data        = registry;
                        value.specificity = specificity;
                        this.m_CustomProperties[styleProperty.name] = value;
                    }
                    break;
                }

                default:
                    throw new ArgumentException(string.Format("Non exhaustive switch statement (value={0})", stylePropertyID));
                }
            }
        }
Exemple #3
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));
                    }
                }
Exemple #4
0
        internal void ApplyRule(StyleSheet registry, int specificity, StyleRule rule, StylePropertyID[] propertyIDs)
        {
            for (int i = 0; i < rule.properties.Length; i++)
            {
                UnityEngine.StyleSheets.StyleProperty styleProperty = rule.properties[i];
                StylePropertyID propertyID = propertyIDs[i];

                var handles = styleProperty.values;
                switch (propertyID)
                {
                case StylePropertyID.AlignContent:
                    registry.Apply(handles, specificity, ref alignContent, StyleSheetApplicator.ApplyEnum <Align>);
                    break;

                case StylePropertyID.AlignItems:
                    registry.Apply(handles, specificity, ref alignItems, StyleSheetApplicator.ApplyEnum <Align>);
                    break;

                case StylePropertyID.AlignSelf:
                    registry.Apply(handles, specificity, ref alignSelf, StyleSheetApplicator.ApplyEnum <Align>);
                    break;

                case StylePropertyID.BackgroundImage:
                    registry.Apply(handles, specificity, ref backgroundImage, StyleSheetApplicator.ApplyResource);
                    break;

                case StylePropertyID.BorderLeft:
                    registry.Apply(handles, specificity, ref borderLeft, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderTop:
                    registry.Apply(handles, specificity, ref borderTop, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderRight:
                    registry.Apply(handles, specificity, ref borderRight, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderBottom:
                    registry.Apply(handles, specificity, ref borderBottom, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.Flex:
                    registry.Apply(handles, specificity, ref flex, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.FlexBasis:
                    registry.Apply(handles, specificity, ref flexBasis, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.FlexGrow:
                    registry.Apply(handles, specificity, ref flexGrow, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.FlexShrink:
                    registry.Apply(handles, specificity, ref flexShrink, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.Font:
                    registry.Apply(handles, specificity, ref font, StyleSheetApplicator.ApplyResource);
                    break;

                case StylePropertyID.FontSize:
                    registry.Apply(handles, specificity, ref fontSize, StyleSheetApplicator.ApplyInt);
                    break;

                case StylePropertyID.FontStyle:
                    registry.Apply(handles, specificity, ref fontStyle, StyleSheetApplicator.ApplyEnum <FontStyle>);
                    break;

                case StylePropertyID.FlexDirection:
                    registry.Apply(handles, specificity, ref flexDirection, StyleSheetApplicator.ApplyEnum <FlexDirection>);
                    break;

                case StylePropertyID.FlexWrap:
                    registry.Apply(handles, specificity, ref flexWrap, StyleSheetApplicator.ApplyEnum <Wrap>);
                    break;

                case StylePropertyID.Height:
                    registry.Apply(handles, specificity, ref height, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.JustifyContent:
                    registry.Apply(handles, specificity, ref justifyContent, StyleSheetApplicator.ApplyEnum <Justify>);
                    break;

                case StylePropertyID.MarginLeft:
                    registry.Apply(handles, specificity, ref marginLeft, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MarginTop:
                    registry.Apply(handles, specificity, ref marginTop, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MarginRight:
                    registry.Apply(handles, specificity, ref marginRight, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MarginBottom:
                    registry.Apply(handles, specificity, ref marginBottom, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MaxHeight:
                    registry.Apply(handles, specificity, ref maxHeight, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MaxWidth:
                    registry.Apply(handles, specificity, ref maxWidth, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MinHeight:
                    registry.Apply(handles, specificity, ref minHeight, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MinWidth:
                    registry.Apply(handles, specificity, ref minWidth, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.Overflow:
                    registry.Apply(handles, specificity, ref overflow, StyleSheetApplicator.ApplyEnum <Overflow>);
                    break;

                case StylePropertyID.PaddingLeft:
                    registry.Apply(handles, specificity, ref paddingLeft, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.PaddingTop:
                    registry.Apply(handles, specificity, ref paddingTop, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.PaddingRight:
                    registry.Apply(handles, specificity, ref paddingRight, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.PaddingBottom:
                    registry.Apply(handles, specificity, ref paddingBottom, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.PositionType:
                    registry.Apply(handles, specificity, ref positionType, StyleSheetApplicator.ApplyEnum <PositionType>);
                    break;

                case StylePropertyID.PositionTop:
                    registry.Apply(handles, specificity, ref positionTop, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.PositionBottom:
                    registry.Apply(handles, specificity, ref positionBottom, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.PositionLeft:
                    registry.Apply(handles, specificity, ref positionLeft, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.PositionRight:
                    registry.Apply(handles, specificity, ref positionRight, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.TextAlignment:
                    registry.Apply(handles, specificity, ref textAlignment, StyleSheetApplicator.ApplyEnum <TextAnchor>);
                    break;

                case StylePropertyID.TextClipping:
                    registry.Apply(handles, specificity, ref textClipping, StyleSheetApplicator.ApplyEnum <TextClipping>);
                    break;

                case StylePropertyID.TextColor:
                    registry.Apply(handles, specificity, ref textColor, StyleSheetApplicator.ApplyColor);
                    break;

                case StylePropertyID.Width:
                    registry.Apply(handles, specificity, ref width, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.WordWrap:
                    registry.Apply(handles, specificity, ref wordWrap, StyleSheetApplicator.ApplyBool);
                    break;

                case StylePropertyID.BackgroundColor:
                    registry.Apply(handles, specificity, ref backgroundColor, StyleSheetApplicator.ApplyColor);
                    break;

                case StylePropertyID.BackgroundSize:
                    registry.Apply(handles, specificity, ref backgroundSize, StyleSheetApplicator.ApplyInt);
                    break;

                case StylePropertyID.BorderColor:
                    registry.Apply(handles, specificity, ref borderColor, StyleSheetApplicator.ApplyColor);
                    break;

                case StylePropertyID.BorderLeftWidth:
                    registry.Apply(handles, specificity, ref borderLeftWidth, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderTopWidth:
                    registry.Apply(handles, specificity, ref borderTopWidth, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderRightWidth:
                    registry.Apply(handles, specificity, ref borderRightWidth, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderBottomWidth:
                    registry.Apply(handles, specificity, ref borderBottomWidth, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderTopLeftRadius:
                    registry.Apply(handles, specificity, ref borderTopLeftRadius, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderTopRightRadius:
                    registry.Apply(handles, specificity, ref borderTopRightRadius, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderBottomRightRadius:
                    registry.Apply(handles, specificity, ref borderBottomRightRadius, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderBottomLeftRadius:
                    registry.Apply(handles, specificity, ref borderBottomLeftRadius, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.Cursor:
                    registry.Apply(handles, specificity, ref cursor, StyleSheetApplicator.ApplyCursor);
                    break;

                case StylePropertyID.SliceLeft:
                    registry.Apply(handles, specificity, ref sliceLeft, StyleSheetApplicator.ApplyInt);
                    break;

                case StylePropertyID.SliceTop:
                    registry.Apply(handles, specificity, ref sliceTop, StyleSheetApplicator.ApplyInt);
                    break;

                case StylePropertyID.SliceRight:
                    registry.Apply(handles, specificity, ref sliceRight, StyleSheetApplicator.ApplyInt);
                    break;

                case StylePropertyID.SliceBottom:
                    registry.Apply(handles, specificity, ref sliceBottom, StyleSheetApplicator.ApplyInt);
                    break;

                case StylePropertyID.Opacity:
                    registry.Apply(handles, specificity, ref opacity, StyleSheetApplicator.ApplyFloat);
                    break;

                // Shorthand values
                case StylePropertyID.BorderRadius:
                    registry.Apply(handles, specificity, ref borderTopLeftRadius, StyleSheetApplicator.ApplyFloat);
                    registry.Apply(handles, specificity, ref borderTopRightRadius, StyleSheetApplicator.ApplyFloat);
                    registry.Apply(handles, specificity, ref borderBottomLeftRadius, StyleSheetApplicator.ApplyFloat);
                    registry.Apply(handles, specificity, ref borderBottomRightRadius, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.Custom:
                    if (m_CustomProperties == null)
                    {
                        m_CustomProperties = new Dictionary <string, CustomProperty>();
                    }
                    CustomProperty customProp = default(CustomProperty);
                    if (!m_CustomProperties.TryGetValue(styleProperty.name, out customProp) || specificity >= customProp.specificity)
                    {
                        customProp.handles     = handles;
                        customProp.data        = registry;
                        customProp.specificity = specificity;
                        m_CustomProperties[styleProperty.name] = customProp;
                    }
                    break;

                default:
                    throw new ArgumentException(string.Format("Non exhaustive switch statement (value={0})", propertyID));
                }
            }
        }
Exemple #5
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");
                    }
                }
Exemple #6
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*/);
                }