コード例 #1
0
        private async Task handleMouseButton(Stopwatch sw, Stopwatch doubleClickSw, bool wasDown, bool isDown, MouseButton button)
        {
            bool fireDown        = !wasDown && isDown && IsMouseIn;
            bool fireDownOutside = !wasDown && isDown && !IsMouseIn && _isFocused;

            _isFocused = fireDown;
            bool fireUp = wasDown && !isDown;

            if (fireDown)
            {
                sw.Restart();
            }
            bool fireClick       = false;
            bool fireDoubleClick = false;

            if (fireUp)
            {
                if (IsMouseIn && sw.ElapsedMilliseconds < 1500 && sw.ElapsedMilliseconds != 0)
                {
                    fireClick = true;
                    if (doubleClickSw.ElapsedMilliseconds == 0)
                    {
                        doubleClickSw.Restart();
                    }
                    else
                    {
                        if (doubleClickSw.ElapsedMilliseconds < 1500)
                        {
                            fireDoubleClick = true;
                        }
                        doubleClickSw.Stop();
                        doubleClickSw.Reset();
                    }
                }
                sw.Stop();
                sw.Reset();
            }

            if (fireDown || fireUp || fireClick || fireDownOutside)
            {
                MouseButtonEventArgs args = new MouseButtonEventArgs(button, _mouseX, _mouseY);
                if (fireDown)
                {
                    await MouseDown.InvokeAsync(_entity, args);
                }
                else if (fireUp)
                {
                    await MouseUp.InvokeAsync(_entity, args);
                }
                else if (fireDownOutside)
                {
                    await LostFocus.InvokeAsync(_entity, args);
                }
                if (fireClick)
                {
                    await MouseClicked.InvokeAsync(_entity, args);
                }
                if (fireDoubleClick)
                {
                    await MouseDoubleClicked.InvokeAsync(_entity, args);
                }
            }
        }