Exemplo n.º 1
0
        private void CheckMouseInput()
        {
            int mx = PointToClient(MousePosition).X;
            int my = PointToClient(MousePosition).Y;

            HoverButtons(mx, my);

            if (isMouseDragged)
            {
                MouseDragged?.Invoke();

                UpdateSliders(mx);
            }

            if (isMousePressed)
            {
                MousePressed?.Invoke();
                isMousePressed = false;

                LockSliders(mx, my);
                PressButtons(mx, my);
            }

            if (isMouseReleased)
            {
                MouseReleased?.Invoke();
                isMouseReleased = false;

                UnlockSliders();
                TriggerButtons(mx, my);
            }
        }
Exemplo n.º 2
0
        private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var element = sender as FrameworkElement;

            startingPoint = e.GetPosition(null);
            anchorPoint   = startingPoint;
            element.CaptureMouse();
            isInDrag  = true;
            e.Handled = true;
            MousePressed?.Invoke(this, startingPoint);
        }
Exemplo n.º 3
0
        /*public void dragDropped(DragEvent e)
         * {
         *  MouseEvent me = new MouseEvent(MouseEvent.MOUSE_RELEASED, 0, 0, 0, 0, MouseButton.PRIMARY, 0, true, true, true, true, true, true, true, true, true, true, null);
         *  mouseReleased(me);
         * }*/

        public void mouseReleased(object sender, MouseButtonEventArgs e)
        {
            MousePressed mp = new MousePressed();

            mp.Type = "mouseRealised";
            mp.Key  = e.ChangedButton;
            mp.Name = App.name;
            if (sc.mode != 0)
            {
                mp.Code = App.code % sc.mode;
            }
            Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(mp)));
        }
Exemplo n.º 4
0
        public virtual void SetMousePressed(bool pressed, int mouseX, int mouseY)
        {
            MouseIsPressed = pressed;

            if (MouseIsPressed)
            {
                MousePressed?.Invoke(mouseX, mouseY);
            }
            else
            {
                MouseReleased?.Invoke(mouseX, mouseY);
            }
        }
 bool IActionTextLineMarker.MousePressed(MonoTextEditor editor, MarginMouseEventArgs args)
 {
     MousePressed?.Invoke(this, new TextEventArgsWrapper(args));
     if ((Platform.IsMac && (args.ModifierState & Gdk.ModifierType.Mod2Mask) == Gdk.ModifierType.Mod2Mask) ||
         (!Platform.IsMac && (args.ModifierState & Gdk.ModifierType.ControlMask) == Gdk.ModifierType.ControlMask))
     {
         activateLink?.Invoke(LinkRequest.RequestNewView);
     }
     else
     {
         activateLink?.Invoke(LinkRequest.SameView);
     }
     return(false);
 }
Exemplo n.º 6
0
        private unsafe IntPtr LowLevelMouseAction(int nCode, IntPtr wParam, IntPtr lParam)
        {
            var state = (MouseState)(wParam.ToInt32() - 1); // fix for MouseMove 0x200 mask

            if ((MouseState.All & state) == state)
            {
                var p = Unsafe.Read <LowLevelMouseInputEvent>(lParam.ToPointer());

                var args = new GlobalMouseHookEventArgs(p, state);
                MousePressed?.Invoke(this, args);

                if (args.Handled)
                {
                    return((IntPtr)1);
                }
            }

            return(User32.CallNextHookEx(MouseHookHandle, nCode, wParam, lParam));
        }
Exemplo n.º 7
0
        private IntPtr HookMouseCallbackImplementation(int nCode, IntPtr wParam, IntPtr lParam)
        {
            var mouseBtnCode = (MouseButtonCode)wParam;

            if (nCode >= 0 && (MouseButtonCode.WM_LBUTTONDOWN == mouseBtnCode || MouseButtonCode.WM_RBUTTONDOWN == mouseBtnCode))
            {
                var hookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
                var mouse      = new MousePressed
                {
                    ButtonCode    = mouseBtnCode,
                    CurrentWindow = new Window().CurrentWindowTitle(),
                    X             = hookStruct.pt.x,
                    Y             = hookStruct.pt.y
                };

                mousePressedCallback.Invoke(mouse);
            }

            return(User32.CallNextHookEx(globalMouseHookId, nCode, wParam, lParam));
        }
Exemplo n.º 8
0
        internal bool HandledMousePressed(MouseButtonEventArgs e)
        {
            if (!Visible || !enabled)
            {
                return(false);
            }

            for (var index = children.Count - 1; index >= 0; --index)
            {
                if (children[index].HandledMousePressed(e))
                {
                    HasFocus = false;
                    return(true);
                }
            }

            if (!MouseDirectlyOver)
            {
                HasFocus = false;
                return(false);
            }

            // TODO: Add smarter bring-to-front functionality. Right now, clicking on ANY child will bring it to the front which will cause lists of Controls to be reordered.
            //BringToFront();

            Focus();

            if (!RegisterEventTypes.HasFlag(EventType.MousePress))
            {
                return(false);
            }

            OnMousePressed(e.Button, e.Modifiers);
            MousePressed?.Invoke(this, e);

            return(true);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Check for any change on the mouse and perform the right actions.
        /// </summary>
        private static void CheckForMouseChange()
        {
            MouseButton theMouseButtonDown = GetPressedMouseButton();

            // MouseChanged event: Check if any mouse button was clicked.
            if (AnyMousePressed())
            {
                MouseChanged?.Invoke(null, currentMouseState);
            }

            // MouseDown event: Check if any mouse button was clicked.
            if (theMouseButtonDown != MouseButton.None)
            {
                MousePressed?.Invoke(null, new MouseEventArgs(theMouseButtonDown, currentMouseState.Position, currentMouseState.ScrollWheelValue));
            }

            // MousePositionChanged event: Check if the cursor moved and what mouse button was held while it was.
            Point cursorDelta = GetDeltaMouseMovement();

            if (cursorDelta.X != 0 && cursorDelta.Y != 0)
            {
                MousePositionChanged?.Invoke(null, new MousePositionEventArgs(theMouseButtonDown, currentMouseState.Position, previousMouseState.Position));
            }
        }
Exemplo n.º 10
0
 internal static void OnMousePressed(MouseButton button) => MousePressed?.Invoke(button);
Exemplo n.º 11
0
        public static void InputLoop()
        {
            uint        toRead            = 128;
            var         records           = new INPUT_RECORD[toRead];
            int         prevWidth         = MyConsole.Width;
            int         prevHeight        = MyConsole.Height;
            MouseButton prevMouseState    = MouseButton.None;
            COORD       prevMouseLocation = new COORD();

            while (!MyConsole.Exiting)
            {
                WinApi.ReadConsoleInput(inputHandle, records, toRead, out uint recordLen);

                for (int i = 0; i < recordLen; i++)
                {
                    var record = records[i];

                    switch (record.EventType)
                    {
                    case EventType.Mouse:
                    {
                        var mouseEvent = record.Event.MouseEvent;
                        var button     = mouseEvent.ButtonState;
                        var flags      = mouseEvent.EventFlags;
                        var location   = mouseEvent.MousePosition;

                        bool mousePressed  = prevMouseState == MouseButton.None && button != MouseButton.None;
                        bool mouseReleased = prevMouseState != MouseButton.None && button == MouseButton.None;
                        bool mouseHeld     = prevMouseState != MouseButton.None && button != MouseButton.None;

                        var args = new MouseEventArgs
                        {
                            Button          = button,
                            Location        = location,
                            ControlKeyState = mouseEvent.ControlKeyState
                        };

                        bool sameLocation = location.Equals(prevMouseLocation);

                        if (mousePressed && flags.HasFlag(MouseState.DoubleClick))
                        {
                            MouseDoubleClick?.Invoke(null, args);
                        }
                        else if (mousePressed)
                        {
                            MousePressed?.Invoke(null, args);
                        }
                        else if (mouseReleased)
                        {
                            MouseReleased?.Invoke(null, args);
                        }
                        else if (mouseHeld && flags.HasFlag(MouseState.Moved) && !sameLocation)
                        {
                            MouseDragged?.Invoke(null, args);
                        }
                        else if (flags.HasFlag(MouseState.Moved) && !sameLocation)
                        {
                            MouseMoved?.Invoke(null, args);
                        }

                        prevMouseState    = button;
                        prevMouseLocation = location;
                    }
                    break;

                    case EventType.Key:
                    {
                        var keyEvent = record.Event.KeyEvent;

                        var eventArgs = new KeyEventArgs
                        {
                            Key             = (ConsoleKey)keyEvent.VirtualKeyCode,
                            ControlKeyState = keyEvent.ControlKeyState
                        };

                        bool currState = keyEvent.KeyDown;
                        bool prevState = keyStates[keyEvent.VirtualKeyCode];

                        if (currState && !prevState)
                        {
                            KeyPressed?.Invoke(eventArgs);
                        }
                        else if (prevState && !currState)
                        {
                            KeyReleased?.Invoke(eventArgs);
                        }
                        else if (prevState && currState)
                        {
                            KeyHeld?.Invoke(eventArgs);
                        }

                        keyStates[keyEvent.VirtualKeyCode] = keyEvent.KeyDown;
                    }
                    break;

                    case EventType.Resize:
                    {
                        var clientSize = MyConsole.GetClientSize();
                        var fontSize   = MyConsole.GetFontSize();
                        int w          = clientSize.X / fontSize.X;
                        int h          = clientSize.Y / fontSize.Y;

                        if (prevWidth != w || prevHeight != h)
                        {
                            MyConsole.SetSize(w, h);
                            MyConsole.HideCursor();
                            Drawing.ConsoleRenderer.Resize(w, h);
                            Resized?.Invoke(new ResizedEventArgs
                                {
                                    Width  = w,
                                    Height = h
                                });
                            prevWidth  = w;
                            prevHeight = h;
                        }
                    }
                    break;

                    case EventType.Menu:
                    {
                        var id = record.Event.MenuEvent.dwCommandId;
                        Debug.WriteLine(id);
                    }
                    break;

                    case EventType.Focus:
                    {
                        var focused = record.Event.FocusEvent.bSetFocus;
                    }
                    break;

                    default:
                        Debug.WriteLine("Unhandled event: " + record.EventType);
                        break;
                    }
                }
            }
        }
Exemplo n.º 12
0
 public void NotifyPressed(EventArgs e) => MousePressed?.Invoke(this, e);
Exemplo n.º 13
0
        private void OnMousePressed(object sender, MouseButtonArgs button)
        {
            ButtonsPressed.Add(button.Button);

            MousePressed?.Invoke(sender, button);
        }
Exemplo n.º 14
0
 private static void OnMousePressed(Screen s, MouseButtonEvent e)
 {
     MousePressed?.Invoke(s, e);
 }
Exemplo n.º 15
0
 bool IActionTextLineMarker.MousePressed(MonoTextEditor editor, MarginMouseEventArgs args)
 {
     MousePressed?.Invoke(this, new TextEventArgsWrapper(args));
     return(false);
 }
Exemplo n.º 16
0
 protected virtual void OnMousePressed(DeltaMouseState mouseState)
 {
     MousePressed?.Invoke(this, mouseState);
 }
Exemplo n.º 17
0
        protected override void OnMouseDown(MouseCallbackEventArgs e)
        {
            base.OnMouseDown(e);

            if (e.MouseButton == MouseButton.Right)
            {
                return;
            }

            selected = new List <SelectionGeometry>();

            MouseSelectHandler mouseSelect = new MouseSelectHandler(e.View.ActiveViewport, e.ViewportPoint, e.CtrlKeyDown);

            MousePressed?.Invoke(this, mouseSelect);

            if (selected.Count > 0)
            {
                if (!parent.selectFaces)
                {
                    double min           = System.Double.PositiveInfinity;
                    int    index_closest = 0;
                    for (int i = 0; i < selected.Count; i++)
                    {
                        if (selected[i].parameter < min)
                        {
                            min           = selected[i].parameter;
                            index_closest = i;
                        }
                    }

                    if (!e.CtrlKeyDown)
                    {
                        if (parent.selectThroughObjects == true)
                        {
                            for (int i = 0; i < selected.Count; i++)
                            {
                                selected[i].selected = true;
                                parent.selectionGeometriesStack.Push(selected[i]);
                            }
                        }
                        else
                        {
                            selected[index_closest].selected = true;
                            parent.selectionGeometriesStack.Push(selected[index_closest]);
                        }
                    }
                    else
                    {
                        if (parent.selectThroughObjects == true)
                        {
                            for (int i = 0; i < selected.Count; i++)
                            {
                                selected[i].selected = false;

                                List <SelectionGeometry> selected_list = parent.selectionGeometriesStack.ToList <SelectionGeometry>();
                                selected_list.Remove(selected[i]);
                                parent.selectionGeometriesStack = new Stack <SelectionGeometry>(selected_list);
                            }
                        }
                        else
                        {
                            selected[index_closest].selected = false;

                            List <SelectionGeometry> selected_list = parent.selectionGeometriesStack.ToList <SelectionGeometry>();
                            selected_list.Remove(selected[index_closest]);
                            parent.selectionGeometriesStack = new Stack <SelectionGeometry>(selected_list);
                        }
                    }
                }
                else
                {
                }

                parent.selectionRetrigger = true;
                parent.ExpireSolution(true);
                e.View.Redraw();
            }
        }
Exemplo n.º 18
0
 public override void OnMousePressed(object sender, EventArgs args)
 {
     base.OnMousePressed(sender, args);
     MousePressed?.Invoke(sender, args);
 }