Exemplo n.º 1
0
        public override void Draw(IGuiContainer container, Vector2 position)
        {
            Rect coords = new Rect(position.x, position.y, this.ExternalSize.x, this.ExternalSize.y);

            if (this.Style != null)
            {
                if (mDropShadowEnabled)
                {
                    Rect shadowCoords = new Rect(coords);
                    shadowCoords.x += 1.0f;
                    shadowCoords.y += 1.0f;
                    Color     shadowColor = new Color(0.0f, 0.0f, 0.0f, 0.75f);
                    IGuiStyle shadowStyle = new GuiStyle(this.Style, "Shadow");
                    shadowStyle.Normal.TextColor = shadowColor;
                    shadowStyle.Hover.TextColor  = shadowColor;
                    shadowStyle.Active.TextColor = shadowColor;

                    GUI.Label(shadowCoords, mText, shadowStyle.GenerateUnityGuiStyle());
                }
                GUI.Label(coords, mText, this.Style.GenerateUnityGuiStyle());
            }
            else
            {
                GUI.Label(coords, mText);
            }
        }
Exemplo n.º 2
0
        private IGuiStyle BuildStyle(string name, XmlNode node, IGuiStyle basedOn)
        {
            GuiStyle result = null;

            if (basedOn == null)
            {
                result = new GuiStyle(name);
            }
            else
            {
                result = new GuiStyle(basedOn, name);
            }

            // DefaultFor
            if (node.Attributes["defaultFor"] != null)
            {
                string[] defaultTypes = node.Attributes["defaultFor"].InnerText.Split(new char[1] {
                    ' '
                }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string defaultType in defaultTypes)
                {
                    System.Type t = System.Type.GetType("Hangout.Client.Gui." + defaultType, true);
                    result.SetAsDefaultFor(t);
                }
            }

            // Normal, Hover, Disbaled and Active
            foreach (XmlNode styleStateNode in node.SelectNodes("StyleState"))
            {
                string styleStateName = BuildName(styleStateNode);

                switch (styleStateName)
                {
                case "NormalState":
                    if (basedOn == null)
                    {
                        result.Normal = BuildStyleState(styleStateNode, null);
                    }
                    else
                    {
                        result.Normal = BuildStyleState(styleStateNode, basedOn.Normal);
                    }
                    break;

                case "HoverState":
                    if (basedOn == null)
                    {
                        result.Hover = BuildStyleState(styleStateNode, null);
                    }
                    else
                    {
                        result.Hover = BuildStyleState(styleStateNode, basedOn.Normal);
                    }
                    break;

                case "DisabledState":
                    if (basedOn == null)
                    {
                        result.Disabled = BuildStyleState(styleStateNode, null);
                    }
                    else
                    {
                        result.Disabled = BuildStyleState(styleStateNode, basedOn.Normal);
                    }
                    break;

                case "ActiveState":
                    if (basedOn == null)
                    {
                        result.Active = BuildStyleState(styleStateNode, null);
                    }
                    else
                    {
                        result.Active = BuildStyleState(styleStateNode, basedOn.Normal);
                    }
                    break;

                default:
                    throw new GuiConstructionException("Unknown style state found in style (" + name + "): " + styleStateName);
                }
            }

            // InternalMargins, ExternalMargins, NinePartScale
            foreach (XmlNode marginNode in node.SelectNodes("Margin"))
            {
                string    marginName = BuildName(marginNode);
                GuiMargin newMargins = BuildMargin(marginNode);
                switch (marginName)
                {
                case "InternalMargins":
                    result.InternalMargins = newMargins;
                    break;

                case "ExternalMargins":
                    result.ExternalMargins = newMargins;
                    break;

                case "NinePartScale":
                    result.NinePartScale = newMargins;
                    break;

                default:
                    throw new GuiConstructionException("Unknown margin found in style (" + name + "): " + marginName);
                }
            }

            // DefaultFont
            if (node.SelectSingleNode("Font") != null)
            {
                result.DefaultFont = BuildFont(node.SelectSingleNode("Font"), "path");
            }

            // DefaultTextAnchor
            if (node.SelectSingleNode("Anchor") != null)
            {
                result.DefaultTextAnchor = BuildAnchor(node.SelectSingleNode("Anchor"), "value");
            }

            // WordWrap
            try
            {
                XmlNode wordWrapNode = node.SelectSingleNode("WordWrap");
                if (wordWrapNode != null)
                {
                    XmlAttribute valueAttrib = wordWrapNode.Attributes["value"];
                    if (valueAttrib != null)
                    {
                        result.WordWrap = bool.Parse(valueAttrib.InnerText);
                    }
                }
            }
            catch (FormatException e)
            {
                throw new GuiConstructionException("Unable to parse the 'value' attribute on " + name + "'s WordWrap node.", e);
            }

            // ClipText
            try
            {
                XmlNode clipTextNode = node.SelectSingleNode("ClipText");
                if (clipTextNode != null)
                {
                    XmlAttribute valueAttrib = clipTextNode.Attributes["value"];
                    if (valueAttrib != null)
                    {
                        result.ClipText = bool.Parse(valueAttrib.InnerText);
                    }
                }
            }
            catch (FormatException e)
            {
                throw new GuiConstructionException("Unable to parse the 'value' attribute on " + name + "'s ClipText node.", e);
            }

            return(result);
        }