예제 #1
0
        private HerbiSpeaksButton LoadButtonData(HerbiSpeaksBoard board, int boardIndex,
                                                 XmlNode nodeButton,
                                                 HerbiSpeaksButton containingPictureButton)
        {
            bool fIsPictureButton = false;

            XmlNode node = nodeButton.Attributes.GetNamedItem("IsPictureButton");

            if (node != null)
            {
                fIsPictureButton = Convert.ToBoolean(node.Value);
            }

            HerbiSpeaksButton button = AddNewButton(false, fIsPictureButton);

            if (containingPictureButton != null)
            {
                containingPictureButton.Controls.Add(button);
            }
            else
            {
                this.Controls.Add(button);
            }

            button.BoardName = board.Name;
            button.Visible   = (boardIndex == 0);

            node = nodeButton.Attributes.GetNamedItem("Left");
            if (node != null)
            {
                button.Left = Convert.ToInt32(node.Value);
            }

            node = nodeButton.Attributes.GetNamedItem("Top");
            if (node != null)
            {
                button.Top = Convert.ToInt32(node.Value);
            }

            node = nodeButton.Attributes.GetNamedItem("Width");
            if (node != null)
            {
                button.Width = Convert.ToInt32(node.Value);
            }
            else
            {
                button.Width = _defaultButtonSize.Width;
            }

            SetButtonCenterFromLocation(button);

            node = nodeButton.Attributes.GetNamedItem("Height");
            if (node != null)
            {
                button.Height = Convert.ToInt32(node.Value);
            }
            else
            {
                button.Height = _defaultButtonSize.Height;
            }

            node = nodeButton.Attributes.GetNamedItem("CenterX");
            if (node != null)
            {
                button.CenterX = Convert.ToDouble(node.Value);
            }

            node = nodeButton.Attributes.GetNamedItem("CenterY");
            if (node != null)
            {
                button.CenterY = Convert.ToDouble(node.Value);
            }

            node = nodeButton.Attributes.GetNamedItem("BoardLink");
            if (node != null)
            {
                button.BoardLink = node.Value;
            }

            node = nodeButton.Attributes.GetNamedItem("BoardLinkSpoken");
            if (node != null)
            {
                button.BoardLinkSpoken = Convert.ToBoolean(node.Value);
            }

            SetButtonLocationFromCenter(button);

            bool   fShowText = true;
            string text      = _defaultButtonText;

            node = nodeButton.Attributes.GetNamedItem("ShowText");
            if (node != null)
            {
                fShowText = Convert.ToBoolean(node.Value);
            }

            node = nodeButton.Attributes.GetNamedItem("Text");
            if (node != null)
            {
                text = node.Value;
            }

            button.AccessibleName = text;

            if (fShowText)
            {
                button.Text = text;
            }
            else
            {
                button.Text = "";
            }

            node = nodeButton.Attributes.GetNamedItem("TextColour");
            if (node != null)
            {
                button.ForeColor = Color.FromArgb(Convert.ToInt32(node.Value));
            }
            else
            {
                button.ForeColor = _colButtonText;
            }

            // By default, buttons are not transparent.
            button.BackColor = this.BackColor;
            button.FlatStyle = FlatStyle.Flat;

            button.FlatAppearance.BorderSize  = 0;
            button.FlatAppearance.BorderColor = this.BackColor;

            node = nodeButton.Attributes.GetNamedItem("ButtonTransparent");
            if (node != null)
            {
                button.ButtonTransparent = Convert.ToBoolean(node.Value);
                if (button.ButtonTransparent)
                {
                    button.BackColor = Color.Transparent;
                    button.FlatStyle = FlatStyle.Popup;
                }
            }

            node = nodeButton.Attributes.GetNamedItem("ButtonTransparentOnHover");
            if (node != null)
            {
                button.ButtonTransparentOnHover = Convert.ToBoolean(node.Value);
            }

            string fontName = "";
            int    fontSize = 0;

            node = nodeButton.Attributes.GetNamedItem("FontName");
            if (node != null)
            {
                fontName = node.Value;
            }

            node = nodeButton.Attributes.GetNamedItem("FontSize");
            if (node != null)
            {
                fontSize = Convert.ToInt32(node.Value);
            }

            if (fontName == "")
            {
                fontName = _defaultFont.Name;
            }

            if (fontSize == 0)
            {
                fontSize = (int)_defaultFont.Size;
            }

            // Don't create fonts unnecessarily.
            if ((fontName == _defaultFont.Name) &&
                (fontSize == (int)_defaultFont.Size))
            {
                button.Font = _defaultFont;
            }
            else if ((_previousButtonFont != null) &&
                     (fontName == _previousButtonFont.Name) &&
                     (fontSize == (int)_previousButtonFont.Size))
            {
                button.Font = _previousButtonFont;
            }
            else
            {
                button.Font = new Font(fontName, fontSize);
            }

            _previousButtonFont = button.Font;

            node = nodeButton.Attributes.GetNamedItem("Media");
            if (node != null)
            {
                button.Media = node.Value;
            }

            node = nodeButton.Attributes.GetNamedItem("ButtonTextSpokenBeforeMedia");
            if (node != null)
            {
                button.ButtonTextSpokenBeforeMedia = Convert.ToBoolean(node.Value);
            }
            else
            {
                button.ButtonTextSpokenBeforeMedia = true;
            }

            node = nodeButton.Attributes.GetNamedItem("AutoPlayMedia");
            if (node != null)
            {
                button.AutoPlayMedia = Convert.ToBoolean(node.Value);
            }

            node = nodeButton.Attributes.GetNamedItem("TextPosition");
            if (node != null)
            {
                button.TextPosition = node.Value;
            }
            else
            {
                button.TextPosition = "Middle";
            }

            XmlNode nodePicture = nodeButton.SelectSingleNode("PictureData");

            if (nodePicture != null)
            {
                XmlNode nodeLength = nodePicture.Attributes.GetNamedItem("Length");
                if (nodeLength != null)
                {
                    int pictureDataLength = Convert.ToInt32(nodeLength.Value);
                    if (pictureDataLength > 0)
                    {
                        byte[] bytes = Convert.FromBase64String(nodePicture.InnerXml);

                        MemoryStream  stream     = new MemoryStream(bytes);
                        XmlTextReader textReader = new XmlTextReader(stream);
                        textReader.ReadBase64(bytes, 0, bytes.Length);

                        button.ImageFull = Image.FromStream(stream);
                    }
                }
            }

            XmlNode nodeHoverPicture = nodeButton.SelectSingleNode("HoverPictureData");

            if (nodeHoverPicture != null)
            {
                XmlNode nodeLength = nodeHoverPicture.Attributes.GetNamedItem("Length");
                if (nodeLength != null)
                {
                    int pictureDataLength = Convert.ToInt32(nodeLength.Value);
                    if (pictureDataLength > 0)
                    {
                        byte[] bytes = Convert.FromBase64String(nodeHoverPicture.InnerXml);

                        MemoryStream  stream     = new MemoryStream(bytes);
                        XmlTextReader textReader = new XmlTextReader(stream);
                        textReader.ReadBase64(bytes, 0, bytes.Length);

                        button.ImageHoverFull = Image.FromStream(stream);
                    }
                }
            }

            // Now present the image in the most appropriate manner.
            SetTextPositionOnButton(button);

            return(button);
        }
예제 #2
0
        public void LoadBoard(XmlNode nodeBoard, string filePath, int boardIndex)
        {
            HerbiSpeaksBoard board = new HerbiSpeaksBoard();

            _boards.Add(board);

            string boardName = "Default";

            // First the board-level details.
            XmlNode node = nodeBoard.Attributes.GetNamedItem("Name");

            if (node != null)
            {
                boardName = node.Value;
            }

            // Beware duplicate names when importing boards.
            board.Name = GetUniqueBoardName(boardName);

            board.BackgroundColor = this.BackColor;

            node = nodeBoard.Attributes.GetNamedItem("BackgroundColour");
            if (node != null)
            {
                board.BackgroundColor = Color.FromArgb(Convert.ToInt32(node.Value));

                // Set the default board background color to be the color of the first board.
                if (boardIndex == 0)
                {
                    _colBackground = board.BackgroundColor;

                    this.BackColor = _boards[0].BackgroundColor;
                }
            }

            node = nodeBoard.Attributes.GetNamedItem("TextColour");
            if (node != null)
            {
                _colButtonText = Color.FromArgb(Convert.ToInt32(node.Value));
            }

            ReadDefaultFontDetails(nodeBoard);

            _previousButtonFont = null;

            // Next all the buttons.

            XmlNode nodeButtons = nodeBoard.SelectSingleNode("BoardButtons");

            XmlNodeList nodeButtonList = nodeButtons.SelectNodes("BoardButton");

            for (int i = 0; i < nodeButtonList.Count; ++i)
            {
                XmlNode nodeButton = nodeButtonList[i];
                if (nodeButton != null)
                {
                    HerbiSpeaksButton pictureButton = LoadButtonData(board, boardIndex, nodeButton, null);
                    if (pictureButton.IsPictureButton)
                    {
                        _currentButton = pictureButton;

                        XmlNode containedButtons = nodeButton.SelectSingleNode("PictureButtonContents");

                        XmlNodeList containedButtonsList = containedButtons.SelectNodes("BoardButton");
                        for (int j = 0; j < containedButtonsList.Count; ++j)
                        {
                            XmlNode containedNodeButton = containedButtonsList[j];

                            LoadButtonData(board, boardIndex, containedNodeButton, pictureButton);
                        }
                    }
                }
            }
        }