Beispiel #1
0
        static SystemMouseButton()
        {
            buttons = new SystemMouseButton[256];

            for (int i = 0; i < 256; ++i)
            {
                buttons[i] = new SystemMouseButton((byte)i);
            }
        }
Beispiel #2
0
            public void HandleMouseButton(MousePosition position, byte button, bool pressed)
            {
                if (pressed)
                {
                    if (this.pressedButtons.ContainsKey(button))
                    {
                        // Nani the blyat
                        return;
                    }

                    var buttonObject = SystemMouseButton.GetButtonFromPFValue(button);
                    this.pressedButtons.Add(button, buttonObject);

                    // If no buttons were pressed previously, try to acquire the mouse capture on
                    // the view below the mouse pointer.
                    if (this.pressedButtons.Count == 1)
                    {
                        // Find the view below the mouse pointer. This can return `null`.
                        var view = this.window.MouseHitTest(position.Client);

                        // Capture the view. This can also return `null` on failure.
                        this.mouseCapture = view?.AcquireMouseCapture(Instance);
                    }

                    if (this.mouseCapture is View.MouseCapture capture)
                    {
                        // Send the event to the captured view
                        capture.MouseDown(new MouseButtonEventArgs(
                                              TranslatePoint(position), buttonObject));
                    }
                }
                else
                {
                    if (!this.pressedButtons.TryGetValue(button, out var buttonObject))
                    {
                        // Nani the blyat
                        return;
                    }
                    this.pressedButtons.Remove(button);

                    if (this.mouseCapture is View.MouseCapture capture)
                    {
                        // Send the event to the captured view
                        capture.MouseUp(new MouseButtonEventArgs(
                                            TranslatePoint(position), buttonObject));

                        // If it was the last button held down, then release the mouse capture
                        if (this.pressedButtons.Count == 0)
                        {
                            capture.Dispose();
                            this.mouseCapture = null;
                        }
                    }
                }
            }