Exemplo n.º 1
0
        private static void UpdateHoveredControl(ControlBase inCanvas)
        {
            ControlBase hovered = inCanvas.GetControlAt(MousePosition.X, MousePosition.Y);

            if (hovered != HoveredControl)
            {
                if (HoveredControl != null)
                {
                    var oldHover = HoveredControl;
                    HoveredControl = null;
                    oldHover.InputMouseLeft();
                }

                HoveredControl = hovered;

                if (HoveredControl != null)
                {
                    HoveredControl.InputMouseEntered();
                }
            }

            if (MouseFocus != null && MouseFocus.GetCanvas() == inCanvas)
            {
                if (HoveredControl != null)
                {
                    var oldHover = HoveredControl;
                    HoveredControl = null;
                    oldHover.Redraw();
                }
                HoveredControl = MouseFocus;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Mouse click handler.
        /// </summary>
        /// <param name="canvas">Canvas.</param>
        /// <param name="mouseButton">Mouse button number.</param>
        /// <param name="down">Specifies if the button is down.</param>
        /// <returns>True if handled.</returns>
        public static bool OnMouseClicked(ControlBase canvas, int mouseButton, bool down)
        {
            // If we click on a control that isn't a menu we want to close
            // all the open menus. Menus are children of the canvas.
            if (down && (null == HoveredControl || !HoveredControl.IsMenuComponent))
            {
                canvas.CloseMenus();
            }

            if (null == HoveredControl)
            {
                return(false);
            }
            if (HoveredControl.GetCanvas() != canvas)
            {
                return(false);
            }
            if (!HoveredControl.IsVisible)
            {
                return(false);
            }
            if (HoveredControl == canvas)
            {
                return(false);
            }

            if (mouseButton > MaxMouseButtons)
            {
                return(false);
            }

            if (mouseButton == 0)
            {
                m_KeyData.LeftMouseDown = down;
            }
            else if (mouseButton == 1)
            {
                m_KeyData.RightMouseDown = down;
            }

            // Double click.
            // Todo: Shouldn't double click if mouse has moved significantly
            bool isDoubleClick = false;

            if (down &&
                m_LastClickPos.X == MousePosition.X &&
                m_LastClickPos.Y == MousePosition.Y &&
                (Platform.GwenPlatform.GetTimeInSeconds() - m_LastClickTime[mouseButton]) < DoubleClickSpeed)
            {
                isDoubleClick = true;
            }

            if (down && !isDoubleClick)
            {
                m_LastClickTime[mouseButton] = Platform.GwenPlatform.GetTimeInSeconds();
                m_LastClickPos = MousePosition;
            }

            if (down)
            {
                FindKeyboardFocus(HoveredControl);
            }

            HoveredControl.UpdateCursor();

            // This tells the child it has been touched, which
            // in turn tells its parents, who tell their parents.
            // This is basically so that Windows can pop themselves
            // to the top when one of their children have been clicked.
            if (down)
            {
                HoveredControl.Touch();
            }

#if GWEN_HOOKSYSTEM
            if (bDown)
            {
                if (Hook::CallHook(&Hook::BaseHook::OnControlClicked, HoveredControl, MousePosition.x,
                                   MousePosition.y))
                {
                    return(true);
                }
            }
#endif

            switch (mouseButton)
            {
            case 0:
            {
                if (DragAndDrop.OnMouseButton(HoveredControl, MousePosition.X, MousePosition.Y, down))
                {
                    return(true);
                }

                if (isDoubleClick)
                {
                    HoveredControl.InputMouseDoubleClickedLeft(MousePosition.X, MousePosition.Y);
                }
                else
                {
                    HoveredControl.InputMouseClickedLeft(MousePosition.X, MousePosition.Y, down);
                }
                return(true);
            }

            case 1:
            {
                if (isDoubleClick)
                {
                    HoveredControl.InputMouseDoubleClickedRight(MousePosition.X, MousePosition.Y);
                }
                else
                {
                    HoveredControl.InputMouseClickedRight(MousePosition.X, MousePosition.Y, down);
                }
                return(true);
            }
            }

            return(false);
        }