Exemple #1
0
        /// <summary>
        /// Select the given button
        /// </summary>
        public void Select(CarToolBarButton selected)
        {
            this.ThrowIfNotReady();

            foreach (CarToolBarButton button in this.buttons)
            {
                button.Selected = (button == selected);
            }
        }
Exemple #2
0
        /// <summary>
        /// Double-Click
        /// </summary>
        private void SawMillMainForm_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            Point            mouse  = this.PointToClient(new Point(MousePosition.X, MousePosition.Y));
            CarToolBarButton button = this.toolBar.HitTest(mouse.X, mouse.Y, this.GetToolbarBounds());

            if (button != null)
            {
                return;
            }

            this.sawMill.DoubleClick();
        }
Exemple #3
0
        /// <summary>
        /// Iterate over the buttons, operating on each button with its bounding rectangle
        /// </summary>
        private void ForEachButton(RectangleF bounds, ButtonRectangleOperation operation)
        {
            this.ThrowIfNotReady();

            int numberOfFixedWidthButtons = 0;
            int sumOfFixedWidthButtons    = 0;

            for (int buttonIndex = 0; buttonIndex < buttons.Count; buttonIndex++)
            {
                int buttonWidth = this.buttons[buttonIndex].Width;
                if (buttonWidth > 0)
                {
                    numberOfFixedWidthButtons++;
                    sumOfFixedWidthButtons += buttonWidth;
                }
            }

            float defaultButtonWidth = (bounds.Width - sumOfFixedWidthButtons) / (this.buttons.Count - numberOfFixedWidthButtons);
            float buttonPosition     = bounds.Left;

            for (int buttonIndex = 0; buttonIndex < buttons.Count; buttonIndex++)
            {
                CarToolBarButton button       = this.buttons[buttonIndex];
                bool             isFixedWidth = button.Width > 0;
                float            buttonWidth  = isFixedWidth ? button.Width : defaultButtonWidth;

                float      left            = buttonPosition;
                float      right           = left + buttonWidth;
                float      top             = bounds.Top;
                float      bottom          = bounds.Bottom;
                RectangleF buttonRectangle = new RectangleF(left, top, right - left, bottom - top);

                if (!operation(button, buttonRectangle))
                {
                    break;
                }

                buttonPosition += buttonWidth;
            }
        }
Exemple #4
0
        /// <summary>
        /// Indicate which button (if any) lies under the given X/Y.
        /// </summary>
        public CarToolBarButton HitTest(int x, int y, RectangleF bounds)
        {
            this.ThrowIfNotReady();

            if (x < bounds.Left)
            {
                return(null);
            }

            if (x > bounds.Right)
            {
                return(null);
            }

            if (y > bounds.Bottom)
            {
                return(null);
            }

            if (y < bounds.Top)
            {
                return(null);
            }

            PointF           point  = new PointF(x, y);
            CarToolBarButton result = null;

            this.ForEachButton(bounds, delegate(CarToolBarButton button, RectangleF buttonRectangle)
            {
                if (buttonRectangle.Contains(point))
                {
                    result = button;
                    return(false);
                }
                return(true);
            });

            return(result);
        }
Exemple #5
0
        /// <summary>
        /// Single Click
        /// </summary>
        void SawMillMainForm_Click(object sender, EventArgs e)
        {
            if (this.IsMinimized())
            {
                return;
            }

            Point            mouse  = this.PointToClient(new Point(MousePosition.X, MousePosition.Y));
            CarToolBarButton button = this.toolBar.HitTest(mouse.X, mouse.Y, this.GetToolbarBounds());

            if (button == null)
            {
                this.sawMill.SingleClick();
                return;
            }

            if (button.Data is SawMillScreen)
            {
                this.toolBar.Select(button);
                if (this.sawMill.CurrentScreen != button.Data)
                {
                    this.sawMill.SetCurrentScreen(button.Data as SawMillScreen);
                    using (Graphics graphics = this.CreateGraphics())
                    {
                        this.Repaint(graphics);
                    }
                }
            }
            else if (button.Data is CarToolBar)
            {
                if (button != this.toolBar.Buttons[0])
                {
                    this.toolBar.Select(button);
                }

                this.toolBar = button.Data as CarToolBar;
                this.DrawToolbar();
                foreach (CarToolBarButton toolBarButton in this.toolBar.Buttons)
                {
                    if (toolBarButton.Selected && toolBarButton.Data is SawMillScreen)
                    {
                        this.sawMill.SetCurrentScreen(toolBarButton.Data as SawMillScreen);
                        break;
                    }
                }
            }
            else if (button.Data is string)
            {
                if ((string)button.Data == exitButtonData)
                {
                    this.toolBar.Select(button);
                    this.DrawToolbar();
                    this.sawMill.BeginClose(this.SawMill_CloseCallback, null);
                }
                else if ((string)button.Data == minimizeButtonData)
                {
                    this.toolBar.Select(button);
                    this.DrawToolbar();

                    if (Settings.Default.BackButton == "SendToBack")
                    {
                        this.SendToBack();
                        this.toolBar.Select(null);
                        this.toolBar = this.mainToolBar;
                    }
                    else
                    {
                        this.WindowState = FormWindowState.Minimized;
                        this.toolBar.Select(null);
                        this.toolBar = this.mainToolBar;
                    }
                }
                this.DrawToolbar();
            }
        }