Esempio n. 1
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;
                        }
                    }
                }
            }
Esempio n. 2
0
 /// <summary>
 /// Checks the validity of mouse capture and releases it if necessary.
 /// </summary>
 public void Update()
 {
     if (this.mouseCapture is View.MouseCapture capture)
     {
         if (capture.View.Window != this.window)
         {
             // This view is no longer in the same window -- release the mouse capture
             capture.Dispose();
             this.mouseCapture = null;
         }
     }
 }
Esempio n. 3
0
 public void Dispose()
 {
     this.mouseCapture?.Dispose();
     this.mouseCapture = null;
 }