Ejemplo n.º 1
0
        /// <summary>
        /// Re-center the toolbar in relation to the window.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CenterizeToolbar()
        {
            // Freeze the layout engine so user does not see an ugly intermediate state
            this.SuspendLayout();

            if (orientation == ToolbarOrientation.HorizontalTop ||
                orientation == ToolbarOrientation.HorizontalBottom)
            {
                int windowHorizMidpt = this.ClientSize.Width / 2;

                // Before updating each control's location, we hide the control
                // since layout engine is frozen, user will still see old version
                toolbarLabel.Hide();
                toolbarLabel.Left = windowHorizMidpt - toolbarLabel.Width / 2;
                toolbarLabel.Show();

                // Align start of toolbar buttons with space in between prev and next arrows
                toolbarButtonsPanel.Hide();
                toolbarButtonsPanel.Left = (windowHorizMidpt - (int)(0.5 * buttonWidth));
                toolbarButtonsIndex      = 0;
                toolbarButtonsPanel.Show();

                navButtonsPanel.Hide();
                navButtonsPanel.Left = windowHorizMidpt - navButtonsPanel.Width / 2;
                navButtonsPanel.Show();
            }
            else if (orientation == ToolbarOrientation.VerticalLeft ||
                     orientation == ToolbarOrientation.VerticalRight)
            {
                int windowVertMidpt  = this.ClientSize.Height / 2;
                int windowHorizMidpt = this.ClientSize.Width / 2;

                // Before updating each control's location we hide the control
                // since layout engine is frozen, user will still see old version
                toolbarLabel.Hide();
                toolbarLabel.Left = windowHorizMidpt - toolbarLabel.Width / 2;
                toolbarLabel.Show();

                // Align start of toolbar buttons with space in between prev and next arrows
                toolbarButtonsPanel.Hide();
                toolbarButtonsPanel.Top = windowVertMidpt - (int)(0.5 * buttonHeight);
                toolbarButtonsIndex     = 0;
                toolbarButtonsPanel.Show();

                navButtonsPanel.Hide();
                navButtonsPanel.Top = windowVertMidpt - navButtonsPanel.Height / 2;
                navButtonsPanel.Show();
            }

            //TODO refactor
            this.ShowMoreArrows();

            // Unfreeze layout engine and show user updated toolbar
            this.ResumeLayout();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add a list of buttons to the toolbar.
        /// </summary>
        /// <param name="buttons"></param>
        private void AddButtonsToToolbar(List <CCButton> buttons)
        {
            // Use a double-buffering like method
            // to reduce screen twitch when changing buttons
            // - create a copy of the toolbar panel to put the new buttons on
            DoubleBufferPanel tempPanel = new DoubleBufferPanel();

            tempPanel.Location     = toolbarButtonsPanel.Location;
            tempPanel.Size         = toolbarButtonsPanel.Size;
            tempPanel.AutoSize     = toolbarButtonsPanel.AutoSize;
            tempPanel.AutoSizeMode = toolbarButtonsPanel.AutoSizeMode;
            tempPanel.BackColor    = toolbarButtonsPanel.BackColor;

            // Add new buttons to the copy panel
            for (int i = 0; i < buttons.Count; i++)
            {
                CCButton currentButton = buttons[i];

                // Make sure button is the current desired size
                currentButton.Width  = buttonWidth;
                currentButton.Height = buttonHeight;

                int x = 0;
                int y = 0;

                switch (this.orientation)
                {
                case ToolbarOrientation.HorizontalTop:
                    x = i * (currentButton.Width + SPACE_BTWN_BTNS);
                    y = 0;
                    break;

                case ToolbarOrientation.HorizontalBottom:
                    goto case ToolbarOrientation.HorizontalTop;

                case ToolbarOrientation.VerticalLeft:
                    x = 0;
                    y = i * (currentButton.Height + SPACE_BTWN_BTNS);
                    break;

                case ToolbarOrientation.VerticalRight:
                    goto case ToolbarOrientation.VerticalLeft;

                default:
                    break;
                }

                currentButton.Location = new Point(x, y);

                tempPanel.Controls.Add(currentButton);
            }

            // Swap the toolbar panel and the copy
            // -- the order of operations is very important
            this.Controls.Add(tempPanel);
            toolbarButtonsPanel.Hide();
            toolbarButtonsPanel.Controls.Clear();
            toolbarButtonsPanel = tempPanel;

            // Reset toolbar panel with starting settings
            // since this is a new set of buttons
            SetToolbarButtonsPanelLocation();
            toolbarButtonsIndex = 0;
            lastSlideDirection  = SlideDirection.Next;
            CenterizeToolbar();
        }