Example #1
0
        public void OnDragEvent(Event e)
        {
            if (_mouseHandlerActive || e.button > _mousePressed.Length)
            {
                return;
            }

            try {
                bool both = (e.button == 0 ? _mousePressed[1] : _mousePressed[0]) != 0;

                MouseButton mouseButton = MouseButton.None;
                if (both)
                {
                    mouseButton = MouseButton.Both;
                }
                else if (e.button == 0)
                {
                    mouseButton = MouseButton.Left;
                }
                else if (e.button == 1)
                {
                    mouseButton = MouseButton.Right;
                }
                else if (e.button == 2)
                {
                    mouseButton = MouseButton.Middle;
                }


                if (_mouseDragged[e.button] == 0)
                {
                    onBeginDragEvent.InvokeWhile(e, mouseButton, false, () => e.type != EventType.Used);
                }
                else
                {
                    onDragEvent.InvokeWhile(e, mouseButton, true, () => e.type != EventType.Used);
                }

                _mouseDragged[e.button] = OpenTibiaUnity.TicksMillis;
            } catch (System.Exception) {
            } finally {
                _mouseHandlerActive = false;
            }
        }
Example #2
0
        public void OnMouseEvent(Event e)
        {
            if (_mouseHandlerActive || e.button > _mousePressed.Length)
            {
                return;
            }

            try {
                _mouseHandlerActive = true;
                var eventType      = e.type;
                var rawMouseButton = e.button;
                if (eventType == EventType.MouseUp)
                {
                    _mousePressed[e.button] = 0;
                }

                if (_captureMouse && !(e.alt && e.control) && e.button != 2)
                {
                    if (eventType == EventType.MouseDown)
                    {
                        bool leftPressedEarlier  = _mousePressed[0] != 0;
                        bool rightPressedEarlier = _mousePressed[1] != 0;

                        bool both;
                        if (e.button == 0)
                        {
                            both = rightPressedEarlier;
                        }
                        else
                        {
                            both = leftPressedEarlier;
                        }

                        if (both)
                        {
                            _ignoreNextLeft = _ignoreNextRight = false;
                            onMouseDownEvent.Invoke(e, MouseButton.Both, leftPressedEarlier && rightPressedEarlier);
                        }
                        else if (e.button == 0)
                        {
                            onMouseDownEvent.Invoke(e, MouseButton.Left, leftPressedEarlier);
                        }
                        else if (e.button == 1)
                        {
                            onMouseDownEvent.Invoke(e, MouseButton.Right, rightPressedEarlier);
                        }
                    }
                    else if (eventType == EventType.MouseUp)
                    {
                        if (_ignoreNextLeft && e.button == 0)
                        {
                            _ignoreNextLeft = false;
                        }
                        else if (_ignoreNextRight && e.button == 1)
                        {
                            _ignoreNextRight = false;
                        }
                        else
                        {
                            bool both;
                            if (e.button == 0)
                            {
                                both             = _mousePressed[1] != 0;
                                _ignoreNextRight = both && _mouseDragged[1] == 0;
                            }
                            else
                            {
                                both            = _mousePressed[0] != 0;
                                _ignoreNextLeft = both && _mouseDragged[0] == 0;
                            }

                            var mouseButton = MouseButton.Left;
                            if (both)
                            {
                                mouseButton = MouseButton.Both;
                            }
                            else if (e.button == 1)
                            {
                                mouseButton = MouseButton.Right;
                            }

                            if (_mouseDragged[e.button] != 0)
                            {
                                _mouseDragged[e.button] = 0;
                                onEndDragEvent.InvokeWhile(e, mouseButton, false, () => e.type != EventType.Used);
                            }

                            if (e.type != EventType.Used)
                            {
                                onMouseUpEvent.InvokeWhile(e, mouseButton, false, () => e.type != EventType.Used);
                            }
                        }
                    }
                }

                if (eventType == EventType.MouseDown)
                {
                    _mousePressed[e.button] = OpenTibiaUnity.TicksMillis;
                }
            } catch (System.Exception) {
            } finally {
                _mouseHandlerActive = false;
            }
        }