Beispiel #1
0
        public void ProccessMouse(MouseEvents mE, float mX, float mY, MouseButtons mButton, int clicks, int delta)
        {
            if (scaleX != 1f || scaleY != 1f)
            {
                mX /= scaleX;
                mY /= scaleY;
            }

            mouseEvent      = mE;
            mouseButton     = mButton;
            mouseWheelDelta = delta;

            mousePositionChanged = mousePositionX != mX || mousePositionY != mY;
            if (mousePositionChanged)
            {
                updateHoveredControl = true;
            }

            mousePositionX = mX;
            mousePositionY = mY;

            switch (mE)
            {
            case MouseEvents.None:
                if (mousePositionChanged == false)
                {
                    return;
                }
                break;

            case MouseEvents.Down:
                mouseButtonLastPressed = mButton;
                break;

            case MouseEvents.Up:
                if (mouseButtonLastPressed == mButton)
                {
                    mouseButtonLastPressed = MouseButtons.None;
                }
                break;
            }


            // Dispose context first.
            for (int i = Contexts.Count - 1; i >= 0; i--) // We want to dispose child context first.
            {
                var contextControl = Contexts[i];
                if (!contextControl.uwfContext)
                {
                    continue;
                }

                if (Contains(contextControl, hoveredControl))
                {
                    continue;
                }
                if (mE != MouseEvents.Down)
                {
                    continue;
                }

                contextControl.Dispose();
            }

            if (hoveredControl == null && mE == MouseEvents.Up)
            {
                dragndrop  = false;
                dragData   = null;
                dragRender = null;
            }

            if (hoveredControl != null)
            {
                _ProcessControl(new PointF(mX, mY), hoveredControl, false);
            }

            if (mE == MouseEvents.Down)
            {
                var downArgs = new MouseEventArgs(mouseButton, clicks, (int)mX, (int)mY, delta);
                MouseHook.RaiseMouseDown(hoveredControl, downArgs);
            }

            if (mE == MouseEvents.Up)
            {
                var upArgs = new MouseEventArgs(mouseButton, clicks, (int)mX, (int)mY, delta);
                MouseHook.RaiseMouseUp(hoveredControl, upArgs);
            }
        }
        public void ProccessMouse(float mouseX, float mouseY)
        {
            if (scaleX != 1f || scaleY != 1f)
            {
                mouseX /= scaleX;
                mouseY /= scaleY;
            }

            mouseEvent  = MouseEvents.None;
            mouseButton = MouseButtons.None;

            mousePositionChanged = mousePositionX != mouseX || mousePositionY != mouseY;
            if (mousePositionChanged)
            {
                updateHoveredControl = true;
            }

            mousePositionX = mouseX;
            mousePositionY = mouseY;

            #region Set events.

            int       eventButton = -1;
            int       eventClicks = 0;
            float     eventDelta  = 0;
            EventType eventType   = EventType.Ignore;

            if (userMouseArgs != null)
            {
                switch (userMouseArgs.Button)
                {
                case MouseButtons.Left: eventButton = 0; break;

                case MouseButtons.Right: eventButton = 1; break;

                case MouseButtons.Middle: eventButton = 2; break;
                }
                eventClicks = userMouseArgs.Clicks;
                eventDelta  = userMouseArgs.Delta;
                switch (userMouseEvent)
                {
                case MouseEvents.Down: eventType = EventType.MouseDown; break;

                case MouseEvents.Up: eventType = EventType.MouseUp; break;

                case MouseEvents.Wheel: eventType = EventType.ScrollWheel; break;
                }
                userMouseArgs = null;
            }
            else
            {
                eventButton = Event.current.button;
                eventClicks = Event.current.clickCount;
                eventDelta  = Event.current.delta.y;
                eventType   = Event.current.type;
            }

            switch (eventType)
            {
            case EventType.MouseDown:
                switch (eventButton)
                {
                case 0:
                    mouseButton = MouseButtons.Left;
                    mouseEvent  = MouseEvents.Down;
                    if (eventClicks > 1)
                    {
                        mouseEvent = MouseEvents.DoubleClick;
                    }
                    break;

                case 1:
                    mouseButton = MouseButtons.Right;
                    mouseEvent  = MouseEvents.Down;
                    break;

                case 2:
                    mouseButton = MouseButtons.Middle;
                    mouseEvent  = MouseEvents.Down;
                    break;
                }
                break;

            case EventType.MouseUp:
                switch (eventButton)
                {
                case 0:
                    mouseButton = MouseButtons.Left;
                    mouseEvent  = MouseEvents.Up;
                    break;

                case 1:
                    mouseButton = MouseButtons.Right;
                    mouseEvent  = MouseEvents.Up;
                    break;

                case 2:
                    mouseButton = MouseButtons.Middle;
                    mouseEvent  = MouseEvents.Up;
                    break;
                }
                break;

            case EventType.ScrollWheel:
                mouseEvent      = MouseEvents.Wheel;
                mouseWheelDelta = eventDelta;
                break;
            }

            #endregion

            //if (_mouseLastClickControl != null && _mouseEvent == MouseEvents.None && _mouseMovePosition != mousePosition)
            //    _ProcessControl(mousePosition, _mouseLastClickControl, true);

            if (mouseEvent == MouseEvents.None && !mousePositionChanged)
            {
                return;
            }

            // Dispose context first.
            for (int i = Contexts.Count - 1; i >= 0; i--) // We want to dispose child context first.
            {
                var contextControl = Contexts[i];
                if (!contextControl.uwfContext)
                {
                    continue;
                }

                if (Contains(contextControl, hoveredControl))
                {
                    continue;
                }
                if (mouseEvent != MouseEvents.Down)
                {
                    continue;
                }

                contextControl.Dispose();
            }

            if (hoveredControl == null && mouseEvent == MouseEvents.Up)
            {
                dragndrop  = false;
                dragData   = null;
                dragRender = null;
            }

            if (hoveredControl != null)
            {
                _ProcessControl(new PointF(mouseX, mouseY), hoveredControl, false);
            }

            if (mouseEvent == MouseEvents.Down)
            {
                var downArgs = new MouseEventArgs(mouseButton, 1, (int)mouseX, (int)mouseY, 0);
                MouseHook.RaiseMouseDown(hoveredControl, downArgs);
            }

            if (mouseEvent == MouseEvents.Up)
            {
                var upArgs = new MouseEventArgs(mouseButton, 1, (int)mouseX, (int)mouseY, 0);
                MouseHook.RaiseMouseUp(hoveredControl, upArgs);
            }
        }
Beispiel #3
0
        public void ProcessMouse(MouseEvents mE, float mX, float mY, MouseButtons mButton, int clicks, int delta)
        {
            if (scaleX != 1f || scaleY != 1f)
            {
                mX /= scaleX;
                mY /= scaleY;
            }

            mouseEvent      = mE;
            mouseButton     = mButton;
            mouseWheelDelta = delta;

            mousePositionChanged = mousePositionX != mX || mousePositionY != mY;
            if (mousePositionChanged)
            {
                updateHoveredControl = true;
            }

            mousePositionX = mX;
            mousePositionY = mY;

            switch (mouseEvent)
            {
            case MouseEvents.None:
                if (!mousePositionChanged)
                {
                    return;
                }
                break;

            case MouseEvents.Down:
                mouseButtonLastPressed = mButton;
                break;

            case MouseEvents.Up:
                if (mouseButtonLastPressed == mButton)
                {
                    mouseButtonLastPressed = MouseButtons.None;
                }
                break;
            }


            // Dispose context first.
            for (int i = Contexts.Count - 1; i >= 0; i--) // We want to dispose child context first.
            {
                var contextControl = Contexts[i];
                if (!contextControl.uwfContext)
                {
                    continue;
                }

                if (Contains(contextControl, hoveredControl))
                {
                    continue;
                }
                if (mouseEvent != MouseEvents.Down)
                {
                    continue;
                }

                contextControl.Dispose();
            }

            var processedControl = mouseDownControl;

            if (processedControl == null || IsDragging)
            {
                processedControl = hoveredControl;
            }

            if (processedControl != null)
            {
                RaiseMouseEvents(new PointF(mX, mY), processedControl);
            }

            if (mouseEvent == MouseEvents.Up)
            {
                // Try raise MouseLeave event if mouse is outside of clicked control.
                if (mouseDownControl != null)
                {
                    var rect = new Rectangle(mouseDownControl.PointToScreen(Point.Empty), mouseDownControl.Size);
                    if (!rect.Contains((int)mousePositionX, (int)mousePositionY))
                    {
                        mouseDownControl.RaiseOnMouseLeave(EventArgs.Empty);
                    }
                }

                mouseDownControl = null;

                if (IsDragging)
                {
                    StopDragDrop();
                }
            }

            if (mouseEvent == MouseEvents.Down)
            {
                var downArgs = new MouseEventArgs(mouseButton, clicks, (int)mX, (int)mY, delta);
                MouseHook.RaiseMouseDown(processedControl, downArgs);
            }

            if (mouseEvent == MouseEvents.Up)
            {
                var upArgs = new MouseEventArgs(mouseButton, clicks, (int)mX, (int)mY, delta);
                MouseHook.RaiseMouseUp(processedControl, upArgs);
            }
        }