예제 #1
0
        private void UpdateMouseInfo(MouseInfo mouseInfo, Vector2 baseOffset)
        {
            if (!AcceptMouseOperation)
            {
                return;
            }

            var onMouse = HitTest(mouseInfo.Position - baseOffset);

            if (onMouse)
            {
                if (!lastOnMouse)
                {
                    OnMouseEnter(new MouseEvent(mouseInfo.Position, false, MouseEvent.MouseEventType.None));
                }
                if (lastMousePos != mouseInfo.Position)
                {
                    OnMouseMove(new MouseEvent(mouseInfo.Position, false, MouseEvent.MouseEventType.None));
                }
            }
            else
            {
                if (lastOnMouse)
                {
                    OnMouseLeave(new MouseEvent(mouseInfo.Position, false, MouseEvent.MouseEventType.None));
                }
            }
            lastMousePos = mouseInfo.Position;
            lastOnMouse  = onMouse;

            foreach (MouseEvent mouseEvent in mouseInfo.Events)
            {
                if (HitTest(mouseEvent.Position - baseOffset))
                {
                    switch (mouseEvent.EventType)
                    {
                    case MouseEvent.MouseEventType.Left:
                        if (mouseEvent.Up)
                        {
                            OnMouseLeftUp(mouseEvent);
                            if (mouseLeftDown)
                            {
                                OnMouseLeftClick(mouseEvent);
                            }
                            mouseLeftDown = false;
                        }
                        else
                        {
                            mouseLeftDown = true;
                            OnMouseLeftDown(mouseEvent);
                        }
                        break;

                    case MouseEvent.MouseEventType.Middle:
                        if (mouseEvent.Up)
                        {
                            OnMouseMiddleUp(mouseEvent);
                            if (mouseMiddleDown)
                            {
                                OnMouseMiddleClick(mouseEvent);
                            }
                            mouseMiddleDown = false;
                        }
                        else
                        {
                            mouseMiddleDown = true;
                            OnMouseMiddleDown(mouseEvent);
                        }
                        break;

                    case MouseEvent.MouseEventType.Right:
                        if (mouseEvent.Up)
                        {
                            OnMouseRightUp(mouseEvent);
                            if (mouseRightDown)
                            {
                                OnMouseRightClick(mouseEvent);
                            }
                            mouseRightDown = false;
                        }
                        else
                        {
                            mouseRightDown = true;
                            OnMouseRightDown(mouseEvent);
                        }
                        break;

                    case MouseEvent.MouseEventType.Wheel:
                        OnMouseWheel(mouseEvent);
                        break;
                    }
                }
                else
                {
                    switch (mouseEvent.EventType)
                    {
                    case MouseEvent.MouseEventType.Left:
                        mouseLeftDown &= !mouseEvent.Up;
                        break;

                    case MouseEvent.MouseEventType.Middle:
                        mouseMiddleDown &= !mouseEvent.Up;
                        break;

                    case MouseEvent.MouseEventType.Right:
                        mouseRightDown &= !mouseEvent.Up;
                        break;
                    }
                }
            }

            for (int i = 0; i < ChildrenCount; i++)
            {
                GameComponent child = children[i];
                child.UpdateMouseInfo(mouseInfo, baseOffset + child.Position + child.Offset);
            }
        }