Пример #1
0
        protected virtual void UpdateText()
        {
            LabelPart[] parts = new LabelPart[2];
            parts[0] = left;
            parts[1] = right;


            string[] prevText = { left.formatted, right.formatted };

            left.formatted  = defaultText;
            right.formatted = "";

            for (int i = 0; i < 2; ++i)
            {
                if (!string.IsNullOrEmpty(parts[i].text) && Main.PlayControl.IsPlaying())
                {
                    // Evaluate only when there is a track, otherwise keep default text
                    parts[i].formatted = Main.PlayControl.FormatTitle(Main.PlayControl.GetNowPlaying(), parts[i].text);
                }
            }

            for (int i = 0; i < 2; ++i)
            {
                if (prevText[i] != parts[i].formatted)
                {
                    Main.GetInstance().RequestRedraw();
                    break;
                }
            }
        }
Пример #2
0
        protected virtual void AddLabel(XElement node, LabelPart def)
        {
            string    position = GetAttributeValue(node, "position", "left");
            LabelPart label    = ReadLabel(node, def);

            switch (position)
            {
            case "left":
                this.left = label;
                break;

            case "right":
                this.right = label;
                break;
            }
        }
Пример #3
0
        public TextLayer(Rectangle parentRect, XElement node) : base(parentRect, node)
        {
            XElement contents = GetFirstChildByName(node, "contents");

            // read the spacing
            space = GetCastedAttributeValue(contents, "spacing", 20);
            angle = GetCastedAttributeValue(contents, "angle", 0);

            // read the default font
            LabelPart empty = new LabelPart
            {
                isBold   = false,
                isItalic = false,
                fontName = "Arial",
                color    = Color.FromArgb(255, 0, 0, 0),
                fontSize = 9,
            };
            LabelPart def = ReadLabel(contents, empty);

            // read contents
            foreach (XElement n in contents.Elements("label"))
            {
                AddLabel(n, def);
            }

            defaultText = "";
            foreach (XElement n in contents.Elements())
            {
                if (n.Name == "defaultText")
                {
                    defaultText = GetNodeValue(n, false);
                }
            }

            if (Main.GetInstance().CurrentSkin != null)
            {
                Main.GetInstance().CurrentSkin.OnPlaybackNewTrackEvent += OnPlaybackNewTrack;
                Main.GetInstance().CurrentSkin.OnPlaybackTimeEvent += OnPlaybackTime;
                Main.GetInstance().CurrentSkin.OnPlaybackStopEvent += CurrentSkin_OnPlaybackStopEvent;
                Main.GetInstance().CurrentSkin.OnPlaybackPauseEvent += CurrentSkin_OnPlaybackPauseEvent;
            }
        }
Пример #4
0
        protected LabelPart ReadLabel(XElement node, LabelPart def)
        {
            LabelPart res = new LabelPart();

            if (node.Attribute("size") != null)
            {
                res.fontSize = int.Parse(node.Attribute("size").Value);
            }
            else
            {
                res.fontSize = def.fontSize;
            }

            if (node.Attribute("italic") != null)
            {
                res.isItalic = bool.Parse(node.Attribute("italic").Value);
            }
            else
            {
                res.isItalic = def.isItalic;
            }

            if (node.Attribute("bold") != null)
            {
                res.isBold = bool.Parse(node.Attribute("bold").Value);
            }
            else
            {
                res.isBold = def.isBold;
            }

            if (node.Attribute("font") != null)
            {
                res.fontName = node.Attribute("font").Value;
            }
            else
            {
                res.fontName = def.fontName;
            }

            if (node.Attribute("color") != null)
            {
                res.color = ColorFromCode(node.Attribute("color").Value);
            }
            else
            {
                res.color = def.color;
            }

            FontStyle fontStyle = FontStyle.Regular;

            if (res.isItalic)
            {
                fontStyle |= FontStyle.Italic;
            }
            if (res.isBold)
            {
                fontStyle |= FontStyle.Bold;
            }
            res.font = new Font(res.fontName,
                                Main.GetInstance().IsDpiScalable ? res.fontSize : (int)Math.Round((double)res.fontSize * 96 / 72),
                                fontStyle,
                                Main.GetInstance().IsDpiScalable ? GraphicsUnit.Point : GraphicsUnit.Pixel);
            res.text = GetNodeValue(node, false);

            return(res);
        }