Beispiel #1
0
        void button_MouseLeave(object sender, EventArgs e)
        {
            HerbiSpeaksButton btn = (HerbiSpeaksButton)sender;

            // Always try to set no border on the button when the mouse is outside it.
            btn.FlatAppearance.BorderSize  = 0;
            btn.FlatAppearance.BorderColor = this.BackColor;

            // Is this button on a picture, and the button is usually transparent?
            if (IsButtonContainedInPicture(btn) && btn.ButtonTransparent)
            {
                // If we made it not transparent when the mouse was over it, set it back
                // to being transparent now. Note that if the button is always transparent,
                // we did change its background when the mouse was over it.
                if (!btn.ButtonTransparentOnHover)
                {
                    btn.FlatStyle = FlatStyle.Popup;
                    btn.BackColor = Color.Transparent;
                }
            }
            else
            {
                // In all other cases, when the mouse moves out of a button, we
                // want it to have no border, and effectively no background colour.

                btn.FlatStyle = FlatStyle.Flat;
                btn.BackColor = this.BackColor;
            }

            this.Cursor = Cursors.Default;

            if (btn.ImageHoverFull != null)
            {
                if (btn.ImageFull != null)
                {
                    if (btn.TextPosition == "Middle")
                    {
                        btn.BackgroundImage       = btn.ImageFull;
                        btn.BackgroundImageLayout = ImageLayout.Stretch;
                        btn.Image = null;
                    }
                    else
                    {
                        btn.Image           = btn.ImageFullThumbnail;
                        btn.BackgroundImage = null;
                    }
                }
                else
                {
                    btn.BackgroundImage = null;
                    btn.Image           = null;
                }
            }
        }
Beispiel #2
0
        void button_MouseEnter(object sender, EventArgs e)
        {
            HerbiSpeaksButton btn = (HerbiSpeaksButton)sender;

            if (btn.IsPictureButton)
            {
                return;
            }

            // Always try to set a big border around the button when the mouse is over it.

            btn.FlatAppearance.BorderColor = btn.ForeColor;
            btn.FlatAppearance.BorderSize  = _borderThickness;

            // Is this button on a picture, and the button is usually transparent?
            if (IsButtonContainedInPicture(btn) && btn.ButtonTransparent)
            {
                // If this button is to remain transparent when the mouse is over it
                // don't change its background when the mouse is over it.
                if (!btn.ButtonTransparentOnHover)
                {
                    btn.FlatStyle = FlatStyle.Flat;
                    btn.BackColor = this.BackColor;
                }
            }

            if (btn.ImageHoverFull != null)
            {
                if (btn.TextPosition == "Middle")
                {
                    btn.BackgroundImage       = btn.ImageHoverFull;
                    btn.BackgroundImageLayout = ImageLayout.Stretch;
                    btn.Image = null;
                }
                else
                {
                    btn.Image           = btn.ImageHoverFullThumbnail;
                    btn.BackgroundImage = null;
                }
            }
        }
Beispiel #3
0
        void button_MouseMove(object sender, MouseEventArgs e)
        {
            HerbiSpeaksButton btn = (HerbiSpeaksButton)sender;

            if (_editModeActive)
            {
                if (!_fDragging)
                {
                    if ((e.Location.X < _dragCornerSize) && (e.Location.Y < _dragCornerSize))
                    {
                        this.Cursor = Cursors.SizeNWSE;
                    }
                    else if ((btn.Width - e.Location.X < _dragCornerSize) && (e.Location.Y < _dragCornerSize))
                    {
                        this.Cursor = Cursors.SizeNESW;
                    }
                    else if ((e.Location.X < _dragCornerSize) && (btn.Height - e.Location.Y < _dragCornerSize))
                    {
                        this.Cursor = Cursors.SizeNESW;
                    }
                    else if ((btn.Width - e.Location.X < _dragCornerSize) && (btn.Height - e.Location.Y < _dragCornerSize))
                    {
                        this.Cursor = Cursors.SizeNWSE;
                    }
                    else
                    {
                        this.Cursor = Cursors.SizeAll;
                    }
                }
                else
                {
                    Point delta = new Point(e.X - _dropOffset.X, e.Y - _dropOffset.Y);

                    bool fAddOffset = true;

                    if (_resizingButtonTopLeft)
                    {
                        _rectDragFeedback.Size = new Size(Math.Max(64, Math.Abs(_originalSize.Width - delta.X)),
                                                          Math.Max(64, Math.Abs(_originalSize.Height - delta.Y)));

                        _rectDragFeedback.Location = new Point(_btnBeingMoved.Location.X + delta.X, _btnBeingMoved.Location.Y + delta.Y);
                    }
                    else if (_resizingButtonTopRight)
                    {
                        _rectDragFeedback.Size = new Size(Math.Max(64, Math.Abs(_originalSize.Width + delta.X)),
                                                          Math.Max(64, Math.Abs(_originalSize.Height - delta.Y)));

                        _rectDragFeedback.Location = new Point(_btnBeingMoved.Location.X, _btnBeingMoved.Location.Y + delta.Y);
                    }
                    else if (_resizingButtonBottomLeft)
                    {
                        _rectDragFeedback.Size = new Size(Math.Max(64, Math.Abs(_originalSize.Width - delta.X)),
                                                          Math.Max(64, Math.Abs(_originalSize.Height + delta.Y)));

                        _rectDragFeedback.Location = new Point(_btnBeingMoved.Location.X + delta.X, _btnBeingMoved.Location.Y);
                    }
                    else if (_resizingButtonBottomRight)
                    {
                        _rectDragFeedback.Size = new Size(Math.Max(64, Math.Abs(_originalSize.Width + delta.X)),
                                                          Math.Max(64, Math.Abs(_originalSize.Height + delta.Y)));

                        _rectDragFeedback.Location = new Point(_btnBeingMoved.Location.X, _btnBeingMoved.Location.Y);
                    }
                    else
                    {
                        fAddOffset = false;

                        _rectDragFeedback.Location = new Point(_originalLocation.X + (e.Location.X - _dropOffset.X),
                                                               _originalLocation.Y + (e.Location.Y - _dropOffset.Y));
                        _rectDragFeedback.Size = _btnBeingMoved.Size;
                    }

                    if (!_rectDragFeedbackPrevious.IsEmpty)
                    {
                        if (fAddOffset)
                        {
                            Button buttonParent = _currentButton.Parent as Button;
                            if (buttonParent != null)
                            {
                                _rectDragFeedback.X += buttonParent.Location.X;
                                _rectDragFeedback.Y += buttonParent.Location.Y;
                            }
                        }

                        _rectDragFeedbackFull = Rectangle.Union(_rectDragFeedbackPrevious, _rectDragFeedback);
                        this.Invalidate(_rectDragFeedbackFull, false);
                    }

                    _rectDragFeedbackPrevious = _rectDragFeedback;
                }
            }
        }
Beispiel #4
0
        void button_MouseUp(object sender, MouseEventArgs e)
        {
            this.Cursor = Cursors.Default;

            HerbiSpeaksButton btn = (HerbiSpeaksButton)sender;

            btn.Capture = false;

            Control ctl = (Control)sender;

            Point originalDragScreenPt = new Point(_originalLocation.X + _dropOffset.X, _originalLocation.Y + _dropOffset.Y);

            Point delta = new Point(e.X - _dropOffset.X, e.Y - _dropOffset.Y);

            if (_fDragging)
            {
                _currentButton = btn;

                _fIsDirty = true;

                if (_resizingButtonTopLeft)
                {
                    btn.Size = new Size(Math.Max(64, Math.Abs(_originalSize.Width - delta.X)),
                                        Math.Max(64, Math.Abs(_originalSize.Height - delta.Y)));

                    btn.Location = new Point(btn.Location.X + delta.X, btn.Location.Y + delta.Y);
                }
                else if (_resizingButtonTopRight)
                {
                    btn.Size = new Size(Math.Max(64, Math.Abs(_originalSize.Width + delta.X)),
                                        Math.Max(64, Math.Abs(_originalSize.Height - delta.Y)));

                    btn.Location = new Point(btn.Location.X, btn.Location.Y + delta.Y);
                }
                else if (_resizingButtonBottomLeft)
                {
                    btn.Size = new Size(Math.Max(64, Math.Abs(_originalSize.Width - delta.X)),
                                        Math.Max(64, Math.Abs(_originalSize.Height + delta.Y)));

                    btn.Location = new Point(btn.Location.X + delta.X, btn.Location.Y);
                }
                else if (_resizingButtonBottomRight)
                {
                    btn.Size = new Size(Math.Max(64, Math.Abs(_originalSize.Width + delta.X)),
                                        Math.Max(64, Math.Abs(_originalSize.Height + delta.Y)));
                }
                else
                {
                    delta = new Point(e.X - _dropOffset.X, e.Y - _dropOffset.Y);

                    btn.Location = new Point(_originalLocation.X + delta.X, _originalLocation.Y + delta.Y);


                    Button buttonParent = _currentButton.Parent as Button;
                    if (buttonParent != null)
                    {
                        btn.Left -= buttonParent.Location.X;
                        btn.Top  -= buttonParent.Location.Y;

                        if (btn.Left < 0)
                        {
                            btn.Left = 0;
                        }

                        if (btn.Top < 0)
                        {
                            btn.Top = 0;
                        }

                        if (btn.Right > buttonParent.Width)
                        {
                            btn.Left = buttonParent.Width - btn.Width;
                        }

                        if (btn.Bottom > buttonParent.Height)
                        {
                            btn.Top = buttonParent.Height - btn.Height;
                        }
                    }
                }

                SetButtonCenterFromLocation(btn);

                _resizingButtonTopLeft     = false;
                _resizingButtonTopRight    = false;
                _resizingButtonBottomLeft  = false;
                _resizingButtonBottomRight = false;

                _fDragging = false;

                ReloadThumbnail(btn);

                _btnBeingMoved = null;

                this.Update();
                this.Refresh();
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                _currentButton = btn;

                PlayMedia("");

                BuildContextMenu(true);
            }
        }
Beispiel #5
0
        private void InvokeButton(HerbiSpeaksButton btn)
        {
            indexSwitchBoardAfterOutput = -1;
            strPlayMediaAfterSpeech     = "";

            // Find a board to jump to in response to this click, if there is a board.
            if (btn.BoardLink != null)
            {
                if (btn.BoardLink == "<random>")
                {
                    if (_boards.Count > 1)
                    {
                        int randomBoardIndex;

                        Random rand = new Random();

                        do
                        {
                            randomBoardIndex = rand.Next(_boards.Count);
                        }while (_currentBoardIndex == randomBoardIndex);

                        this.indexSwitchBoardAfterOutput = randomBoardIndex;
                    }
                }
                else
                {
                    for (int i = 0; i < _boards.Count; ++i)
                    {
                        if (_boards[i].Name == btn.BoardLink)
                        {
                            this.indexSwitchBoardAfterOutput = i;

                            break;
                        }
                    }
                }
            }

            bool startedOutput = false;

            bool fGotMedia = ((btn.Media != null) && (btn.Media != ""));

            // If we're about to play media, check whether the button text should be spoken first.
            if (!fGotMedia || btn.ButtonTextSpokenBeforeMedia)
            {
                // If this button has no target board, or if it does have a target board
                // and text is to be spoken regardless, speak the text aynchronously now.
                if ((btn.BoardLink == null) || (btn.BoardLink == "") || (btn.BoardLinkSpoken))
                {
                    String speakText = btn.Text;

                    if (speakText == "")
                    {
                        speakText = btn.AccessibleName;
                    }

                    if (speakText != "")
                    {
                        startedOutput = true;

                        System.Diagnostics.Debug.WriteLine("SpeakAsync: " + speakText);

                        _outputInProgress = true;

                        // We will switch boards if necessary when the speech has completed.
                        synth.SpeakAsync(speakText);
                    }
                }
            }

            if (!startedOutput)
            {
                startedOutput = PlayMedia(btn.Media);
            }
            else if ((btn.Media != null) && (btn.Media != ""))
            {
                strPlayMediaAfterSpeech = btn.Media;
            }

            // If we need to switch boards and no speech has been started, switch boards now.
            if ((this.indexSwitchBoardAfterOutput != -1) && !startedOutput)
            {
                int targetBoardIndex = this.indexSwitchBoardAfterOutput;

                this.indexSwitchBoardAfterOutput = -1;

                SwitchBoard(targetBoardIndex, true);
            }
        }
Beispiel #6
0
        void button_MouseDown(object sender, MouseEventArgs e)
        {
            this.ContextMenu = null;

            HerbiSpeaksButton btn = sender as HerbiSpeaksButton;

            // In all case below, set _currentButton = btn, except when
            // a left mouse click is done and output is still in progress.

            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                if (_editModeActive)
                {
                    _currentButton = btn;

                    indexSwitchBoardAfterOutput = -1;
                    strPlayMediaAfterSpeech     = "";

                    _dropOffset = e.Location;

                    _resizingButtonTopLeft     = false;
                    _resizingButtonTopRight    = false;
                    _resizingButtonBottomLeft  = false;
                    _resizingButtonBottomRight = false;

                    _originalLocation = btn.Location;
                    _originalSize     = btn.Size;

                    if ((_dropOffset.X < _dragCornerSize) && (_dropOffset.Y < _dragCornerSize))
                    {
                        _resizingButtonTopLeft = true;

                        this.Cursor = Cursors.SizeNWSE;
                    }
                    else if ((btn.Width - _dropOffset.X < _dragCornerSize) && (_dropOffset.Y < _dragCornerSize))
                    {
                        _resizingButtonTopRight = true;

                        this.Cursor = Cursors.SizeNESW;
                    }
                    else if ((_dropOffset.X < _dragCornerSize) && (btn.Height - _dropOffset.Y < _dragCornerSize))
                    {
                        _resizingButtonBottomLeft = true;

                        this.Cursor = Cursors.SizeNESW;
                    }
                    else if ((btn.Width - _dropOffset.X < _dragCornerSize) && (btn.Height - _dropOffset.Y < _dragCornerSize))
                    {
                        _resizingButtonBottomRight = true;

                        this.Cursor = Cursors.SizeNWSE;
                    }
                    else
                    {
                        this.Cursor = Cursors.SizeAll;
                    }

                    _rectDragFeedbackPrevious.Width  = 0;
                    _rectDragFeedbackPrevious.Height = 0;

                    Button buttonParent = _currentButton.Parent as Button;
                    if (buttonParent != null)
                    {
                        _originalLocation.X += buttonParent.Location.X;
                        _originalLocation.Y += buttonParent.Location.Y;
                    }

                    _fDragging     = true;
                    _btnBeingMoved = btn;

                    btn.Capture = true;
                }
                else
                {
                    // If speech is in progress, ignore the left mouse click.
                    if (!_outputInProgress)
                    {
                        _currentButton = btn;

                        if (!btn.IsPictureButton)
                        {
                            InvokeButton(btn);
                        }
                    }
                }
            }
            else
            {
                _currentButton = btn;

                // Always cancel speech on a right click.
                CancelSpeech();
            }
        }
Beispiel #7
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);
        }
Beispiel #8
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);
                        }
                    }
                }
            }
        }
Beispiel #9
0
        private void WriteButtonDetails(XmlTextWriter xwriter, HerbiSpeaksButton btn)
        {
            xwriter.WriteAttributeString("CenterX", btn.CenterX.ToString());
            xwriter.WriteAttributeString("CenterY", btn.CenterY.ToString());

            xwriter.WriteAttributeString("Width", btn.Size.Width.ToString());
            xwriter.WriteAttributeString("Height", btn.Size.Height.ToString());

            xwriter.WriteAttributeString("IsPictureButton", btn.IsPictureButton.ToString());

            xwriter.WriteAttributeString("BoardLink", btn.BoardLink);
            xwriter.WriteAttributeString("BoardLinkSpoken", btn.BoardLinkSpoken.ToString());

            string text = btn.Text;

            if (text == "")
            {
                text = btn.AccessibleName;

                xwriter.WriteAttributeString("ShowText", false.ToString());
            }

            xwriter.WriteAttributeString("Text", text);

            // Always write out the button's font name, font size and text colour, even
            // if any of those things are the same as the app's current default settings.
            xwriter.WriteAttributeString("TextColour", btn.ForeColor.ToArgb().ToString());
            xwriter.WriteAttributeString("FontName", btn.Font.Name);
            xwriter.WriteAttributeString("FontSize", ((int)btn.Font.Size).ToString());
            xwriter.WriteAttributeString("ButtonTransparent", ((bool)btn.ButtonTransparent).ToString());
            xwriter.WriteAttributeString("ButtonTransparentOnHover", ((bool)btn.ButtonTransparentOnHover).ToString());

            if ((btn.Media != null) && (btn.Media != ""))
            {
                xwriter.WriteAttributeString("Media", btn.Media);
            }

            xwriter.WriteAttributeString("ButtonTextSpokenBeforeMedia",
                                         btn.ButtonTextSpokenBeforeMedia.ToString());

            xwriter.WriteAttributeString("AutoPlayMedia",
                                         btn.AutoPlayMedia.ToString());

            xwriter.WriteAttributeString("TextPosition", btn.TextPosition);

            // Always stream out the full image. We don't care here how the image
            // happens to be presented on the button at the moment.
            if (btn.ImageFull != null)
            {
                MemoryStream stream = new MemoryStream();
                btn.ImageFull.Save(stream, ImageFormat.Png);
                byte[] bytes = stream.ToArray();

                xwriter.WriteStartElement("PictureData");
                xwriter.WriteAttributeString("Length", bytes.Length.ToString());
                xwriter.WriteBase64(stream.ToArray(), 0, bytes.Length);
                xwriter.WriteEndElement();
            }

            if (btn.ImageHoverFull != null)
            {
                MemoryStream stream = new MemoryStream();
                btn.ImageHoverFull.Save(stream, ImageFormat.Png);
                byte[] bytes = stream.ToArray();

                xwriter.WriteStartElement("HoverPictureData");
                xwriter.WriteAttributeString("Length", bytes.Length.ToString());
                xwriter.WriteBase64(stream.ToArray(), 0, bytes.Length);
                xwriter.WriteEndElement();
            }
        }
Beispiel #10
0
        private void SaveApp()
        {
            SetEditMode(false);

            string filename = _currentFilename;

            FileStream datafilestream = new FileStream(filename, FileMode.Create, FileAccess.ReadWrite, FileShare.None);

            // Create a new XmlTextWriter.
            XmlTextWriter xwriter = new XmlTextWriter(datafilestream, System.Text.Encoding.UTF8);

            // Write the beginning of the document including the document declaration.
            xwriter.WriteStartDocument();

            xwriter.WriteStartElement("HerbiSpeaks");

            xwriter.WriteStartElement("Boards");

            foreach (HerbiSpeaksBoard board in _boards)
            {
                xwriter.WriteStartElement("Board");

                xwriter.WriteAttributeString("Name", board.Name);
                xwriter.WriteAttributeString("BackgroundColour", board.BackgroundColor.ToArgb().ToString());

                // Today all boards have the same text color etc.
                xwriter.WriteAttributeString("TextColour", this._colButtonText.ToArgb().ToString());

                if (this._defaultFont != null)
                {
                    xwriter.WriteAttributeString("DefaultFontName", this._defaultFont.Name);
                    xwriter.WriteAttributeString("DefaultFontSize", ((int)this._defaultFont.Size).ToString());
                }
                else
                {
                    xwriter.WriteAttributeString("DefaultFontName", this.Font.Name);
                    xwriter.WriteAttributeString("DefaultFontSize", ((int)this.Font.Size).ToString());
                }

                // Now output all buttons for this board.
                xwriter.WriteStartElement("BoardButtons");

                for (int i = 0; i < this.Controls.Count; ++i)
                {
                    HerbiSpeaksButton btn = this.Controls[i] as HerbiSpeaksButton;
                    if (btn != null)
                    {
                        if (btn.BoardName == board.Name)
                        {
                            xwriter.WriteStartElement("BoardButton");

                            WriteButtonDetails(xwriter, btn);

                            // Is this a picture button?
                            if (btn.IsPictureButton)
                            {
                                xwriter.WriteStartElement("PictureButtonContents");

                                for (int idxContainedBtn = 0; idxContainedBtn < btn.Controls.Count; ++idxContainedBtn)
                                {
                                    HerbiSpeaksButton btnContained = btn.Controls[idxContainedBtn] as HerbiSpeaksButton;
                                    if (btn != null)
                                    {
                                        xwriter.WriteStartElement("BoardButton");

                                        WriteButtonDetails(xwriter, btnContained);

                                        xwriter.WriteEndElement();
                                    }
                                }

                                xwriter.WriteEndElement();
                            }

                            // End the "BoardButton" element.
                            xwriter.WriteEndElement();
                        }
                    }
                }

                // End the "BoardButtons" element.
                xwriter.WriteEndElement();

                // End the "Board" element.
                xwriter.WriteEndElement();
            }

            // End the Boards element.
            xwriter.WriteEndElement();

            // End the HerbiSpeaks element.
            xwriter.WriteEndDocument();
            xwriter.Close();

            datafilestream.Close();
        }