Esempio n. 1
0
 internal protected virtual void TriggerOnMouseMove(Component sender, int x, int y)
 {
     if (OnMouseMove != null)
     {
         OnMouseMove.Invoke(new MouseEventArgs(sender, x, y));
     }
 }
Esempio n. 2
0
        public static void Initialize(ECSWorld world)
        {
            if (initialized)
            {
                return;
            }
            if (world == null)
            {
                throw  new ArgumentNullException(nameof(world), "The ECSWorld provided can not be null.");
            }
            if (!world.IsMainWorld)
            {
                throw new ArgumentException("The ECSWorld of the window needs to be the mainWorld", nameof(world));
            }

            WindowInstance     = Process.GetCurrentProcess().SafeHandle.DangerousGetHandle();
            window             = new Sdl2Window("ECS", 50, 50, 1280, 720, SDL_WindowFlags.Resizable, threadedProcessing: false);
            window.X           = 50;
            window.Y           = 50;
            window.Visible     = true;
            window.MouseWheel += (x) => OnMouseWheel?.Invoke(x);
            window.MouseMove  += (x) => OnMouseMove?.Invoke(x);
            window.MouseDown  += (x) => OnMouseDown?.Invoke(x);
            window.KeyDown    += (x) => OnKeyDown?.Invoke(x);
            window.Closed     += () => OnWindowClose?.Invoke();
            window.Resized    += () => OnWindowResize?.Invoke(window.Width, window.Height);

            world.EarlyUpdate += PumpEvents;

            initialized = true;
            GraphicsContext.Initialize(world);
        }
Esempio n. 3
0
        private void OnMouseDown(InputEventArgs e)
        {
            isMouseDown = true;
            var re = new RecordEvent(); re.Button = e.Button;

            OnMouseMove?.Invoke(this, re);
        }
Esempio n. 4
0
 internal virtual void DoMouseMove()
 {
     if (MouseEnabled)
     {
         OnMouseMove?.Invoke();
     }
 }
Esempio n. 5
0
 private void DetectMouseMove()
 {
     if (_currentX != _oldX || _currentY != _oldY)
     {
         OnMouseMove?.Invoke(this, GetMouseEventArgs());
     }
 }
Esempio n. 6
0
 static public void InvokeOnMouseMove(OpenTK.Input.MouseMoveEventArgs e)
 {
     if (OnMouseMove != null)
     {
         OnMouseMove.Invoke(null, e);
     }
 }
Esempio n. 7
0
        public static void ProcessMouseEvent(SDL_Event ev)
        {
            switch (ev.type)
            {
            case SDL_EventType.SDL_MOUSEBUTTONDOWN:
                SetMouseButtonState(ev.button.button, true);
                if (OnMouseDown != null)
                {
                    var button = TranslatePlatformMouseButton(ev.button.button);
                    OnMouseDown.Invoke(button);
                }
                break;

            case SDL_EventType.SDL_MOUSEBUTTONUP:
                SetMouseButtonState(ev.button.button, false);
                if (OnMouseUp != null)
                {
                    var button = TranslatePlatformMouseButton(ev.button.button);
                    OnMouseUp.Invoke(button);
                }
                break;

            case SDL_EventType.SDL_MOUSEMOTION:
                OnMouseMove?.Invoke();
                break;
            }
        }
Esempio n. 8
0
 private IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam)
 {
     if ((int)wParam == WM_MOUSEMOVE)
     {
         var e  = new InputEventArgs();
         var pt = new POINT();
         GetPhysicalCursorPos(ref pt);
         e.X = pt.x;
         e.Y = pt.y;
         Task.Run(() => OnMouseMove?.Invoke(e));
     }
     else if ((int)wParam == WM_LBUTTONDOWN || (int)wParam == WM_RBUTTONDOWN)
     {
         var e  = new InputEventArgs();
         var pt = new POINT();
         GetPhysicalCursorPos(ref pt);
         e.X = pt.x;
         e.Y = pt.y;
         Task.Run(() => OnMouseDown?.Invoke(e));
     }
     else if ((int)wParam == WM_LBUTTONUP || (int)wParam == WM_RBUTTONUP)
     {
         var e  = new InputEventArgs();
         var pt = new POINT();
         GetPhysicalCursorPos(ref pt);
         e.X = pt.x;
         e.Y = pt.y;
         Task.Run(() => OnMouseUp?.Invoke(e));
     }
     return(CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam));
 }
Esempio n. 9
0
        private void Poll()
        {
            while (true)
            {
                VREvent_t evt  = new VREvent_t();
                var       size = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VREvent_t));

                if (!OpenVR.Overlay.PollNextOverlayEvent(overlayHandle, ref evt, size))
                {
                    Thread.Sleep(PollingRate);
                    continue;
                }
                ;

                switch ((EVREventType)evt.eventType)
                {
                case EVREventType.VREvent_MouseMove:
                    OnMouseMove?.Invoke(this, evt);
                    break;

                case EVREventType.VREvent_MouseButtonDown:
                    OnMouseDown?.Invoke(this, evt);
                    break;

                case EVREventType.VREvent_MouseButtonUp:
                    OnMouseUp?.Invoke(this, evt);
                    break;
                }
            }
        }
        public void PollEvents(Event e)
        {
            Current = e;
            switch (Current.type)
            {
            case EventType.MouseDrag:
                Invoke(OnMouseDrag, Current);
                break;

            case EventType.MouseUp:
                Invoke(OnMouseUp, Current);
                break;

            case EventType.MouseDown:
                Invoke(OnMouseDown, Current);
                break;

            case EventType.Repaint:
                Invoke(OnRepaint, Current);
                break;

            case EventType.ContextClick:
                Invoke(OnContextClick, Current);
                break;

            case EventType.MouseMove:
                OnMouseMove?.Invoke(Current);
                break;

            case EventType.Used:
                OnUsed?.Invoke(Current);
                break;
            }
        }
Esempio n. 11
0
        IntPtr HookProcFunction(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode == 0)
            {
                MSLLHOOKSTRUCT mhs      = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
                var            inwindow = Owner.MouseInWindow(mhs.pt.X, mhs.pt.Y);
                switch ((WM)wParam.ToInt32())
                {
                case WM.MOUSEMOVE:
                    if (inwindow)
                    {
                        OnMouseMove?.Invoke(Owner.ToConsoleCoord(mhs.pt.X, mhs.pt.Y).X, Owner.ToConsoleCoord(mhs.pt.X, mhs.pt.Y).Y, mhs.pt.X, mhs.pt.Y, Owner.GetMouseButtonConsole());
                    }
                    OnGlobalMouseMove?.Invoke(mhs.pt.X, mhs.pt.Y, Owner.GetMouseButtonScreen());
                    break;

                case WM.LBUTTONDOWN:
                    OnMouseDown?.Invoke(Owner.ToConsoleCoord(mhs.pt.X, mhs.pt.Y).X, Owner.ToConsoleCoord(mhs.pt.X, mhs.pt.Y).Y, mhs.pt.X, mhs.pt.Y, inwindow, MButton.Left);
                    break;

                case WM.MBUTTONDOWN:
                    OnMouseDown?.Invoke(Owner.ToConsoleCoord(mhs.pt.X, mhs.pt.Y).X, Owner.ToConsoleCoord(mhs.pt.X, mhs.pt.Y).Y, mhs.pt.X, mhs.pt.Y, inwindow, MButton.Center);
                    break;

                case WM.RBUTTONDOWN:
                    OnMouseDown?.Invoke(Owner.ToConsoleCoord(mhs.pt.X, mhs.pt.Y).X, Owner.ToConsoleCoord(mhs.pt.X, mhs.pt.Y).Y, mhs.pt.X, mhs.pt.Y, inwindow, MButton.Right);
                    break;

                case WM.XBUTTONDOWN:
                    OnMouseDown?.Invoke(Owner.ToConsoleCoord(mhs.pt.X, mhs.pt.Y).X, Owner.ToConsoleCoord(mhs.pt.X, mhs.pt.Y).Y, mhs.pt.X, mhs.pt.Y, inwindow, MButton.XBUTTON1 | MButton.XBUTTON2);
                    break;

                case WM.LBUTTONUP:
                    OnMouseUp?.Invoke(Owner.ToConsoleCoord(mhs.pt.X, mhs.pt.Y).X, Owner.ToConsoleCoord(mhs.pt.X, mhs.pt.Y).Y, mhs.pt.X, mhs.pt.Y, inwindow, MButton.Left);
                    break;

                case WM.MBUTTONUP:
                    OnMouseUp?.Invoke(Owner.ToConsoleCoord(mhs.pt.X, mhs.pt.Y).X, Owner.ToConsoleCoord(mhs.pt.X, mhs.pt.Y).Y, mhs.pt.X, mhs.pt.Y, inwindow, MButton.Center);
                    break;

                case WM.RBUTTONUP:
                    OnMouseUp?.Invoke(Owner.ToConsoleCoord(mhs.pt.X, mhs.pt.Y).X, Owner.ToConsoleCoord(mhs.pt.X, mhs.pt.Y).Y, mhs.pt.X, mhs.pt.Y, inwindow, MButton.Right);
                    break;

                case WM.XBUTTONUP:
                    OnMouseUp?.Invoke(Owner.ToConsoleCoord(mhs.pt.X, mhs.pt.Y).X, Owner.ToConsoleCoord(mhs.pt.X, mhs.pt.Y).Y, mhs.pt.X, mhs.pt.Y, inwindow, MButton.XBUTTON1 | MButton.XBUTTON2);
                    break;

                case WM.MOUSEWHEEL:
                    OnMouseWheel?.Invoke(GetWheelStateByData(mhs.mouseData), mhs.mouseData, mhs.pt.X, mhs.pt.Y, Owner.GetMouseButtonScreen());
                    break;

                default:

                    break;
                }
            }

            return(WinApi.CallNextHookEx(hHook, nCode, wParam, lParam));
        }
Esempio n. 12
0
        /// <summary>
        /// Handles a MouseMovePacket.
        /// </summary>
        /// <param name="packet"></param>
        private void HandleMouseMove(Packet packet)
        {
            var mouseMovePacket = (MouseMovePacket)packet;
            var args            = new MouseMoveEventArgs(mouseMovePacket.P1, mouseMovePacket.P2);

            OnMouseMove?.Invoke(this, args);
        }
Esempio n. 13
0
        private static bool HandleMouseEvent(NativeMouseEvent eventCode, MousePosition pos, int wheelDelta)
        {
            switch (eventCode)
            {
            case NativeMouseEvent.WM_MOUSEMOVE:
                OnMouseMove?.Invoke(pos);
                return(true);

            case NativeMouseEvent.WM_LBUTTONDOWN:
                OnMouseLeftDown?.Invoke(pos);
                return(true);

            case NativeMouseEvent.WM_LBUTTONUP:
                OnMouseLeftUp?.Invoke(pos);
                return(true);

            case NativeMouseEvent.WM_RBUTTONDOWN:
                OnMouseRightDown?.Invoke(pos);
                return(true);

            case NativeMouseEvent.WM_RBUTTONUP:
                OnMouseRightUp?.Invoke(pos);
                return(true);

            case NativeMouseEvent.WM_MOUSEWHEEL:
                OnMouseWheel?.Invoke(pos, wheelDelta);
                return(true);

            default:
                return(false);
            }
        }
Esempio n. 14
0
        private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                switch ((MouseMessage)wParam)
                {
                case MouseMessage.WM_LBUTTONDOWN:
                    OnLeftButtonDown?.Invoke(null, new MouseEventsArgs
                    {
                        Button = MouseButtons.Left,
                        State  = MouseState.MouseDown
                    });
                    break;

                case MouseMessage.WM_LBUTTONUP:
                    OnLeftButtonUp?.Invoke(null, new MouseEventsArgs
                    {
                        Button = MouseButtons.Left,
                        State  = MouseState.MouseUp
                    });
                    break;

                case MouseMessage.WM_LBUTTONDBLCLK:
                    OnLeftDoubleClick?.Invoke(null, new MouseEventsArgs
                    {
                        Button      = MouseButtons.Left,
                        State       = MouseState.MouseUp,
                        DoubleClick = true
                    });
                    break;

                case MouseMessage.WM_RBUTTONDOWN:
                    OnRightButtonDown?.Invoke(null, new MouseEventsArgs
                    {
                        Button = MouseButtons.Right,
                        State  = MouseState.MouseUp
                    });
                    break;

                case MouseMessage.WM_RBUTTONUP:
                    OnRightButtonUp?.Invoke(null, new MouseEventsArgs
                    {
                        Button = MouseButtons.Right,
                        State  = MouseState.MouseUp
                    });
                    break;

                case MouseMessage.WM_MOUSEMOVE:
                    OnMouseMove?.Invoke(null, new MouseEventsArgs
                    {
                        Button = MouseButtons.None,
                        State  = MouseState.MouseMove
                    });
                    break;
                }
            }
            return(NativeMethods.CallNextHookEx(HookId, nCode, wParam, lParam));
        }
Esempio n. 15
0
        private static void InputEventHandler(InputEventArgs e)
        {
            switch (e.Type)
            {
            case InputEventType.KeyUp: OnKeyUp.Invoke(e); break;

            case InputEventType.KeyDown: OnKeyDown.Invoke(e); break;

            case InputEventType.MouseUp: OnMouseUp.Invoke(e); break;

            case InputEventType.MouseDown: OnMouseDown.Invoke(e); break;

            case InputEventType.MouseMove: OnMouseMove.Invoke(e); break;
            }
        }
        internal override void GHook_MouseMove(object sender, MouseEventArgs e)
        {
            if (!Loaded)
            {
                return;
            }

            var mx = e.X - Window.X;
            var my = e.Y - Window.Y;

            //if (ScaleMode == DrawingAreaScaleMode.ScaleAll)
            //{
            //    mx = (int)(mx / Scale.X);
            //    my = (int)(my / Scale.Y);
            //}
            DxWindow.OnMouseMove(DxWindow, DxWindow, e, new SharpDX.Point(mx, my));

            OnMouseMove?.Invoke(sender, e);
        }
Esempio n. 17
0
        private IntPtr _Hook(int code, IntPtr wParam, IntPtr lParam)
        {
            try
            {
                if (code >= 0 && (NativeEnums.MouseMessages)wParam == NativeEnums.MouseMessages.WM_MOUSEMOVE)
                {
                    var ms = (NativeStructs.MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(NativeStructs.MSLLHOOKSTRUCT));

                    _position = new Point(ms.pt.x, ms.pt.y);
                    OnMouseMove?.Invoke(this, _position);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            return(NativeMethods.CallNextHookEx(mHookPtr, code, wParam, lParam));
        }
Esempio n. 18
0
        public void MouseMove(int x, int y)
        {
            if (!active.Enabled)
            {
                return;
            }

            mousePosition.X = x;
            mousePosition.Y = y;

            if (!isMouseDown)
            {
                foreach (Viewport viewport in viewports)
                {
                    if (!viewport.Enabled)
                    {
                        continue;
                    }

                    if (viewport.IsActive(x, y))
                    {
                        viewport.Active = true;
                        active          = viewport;

                        OnMouseMove?.Invoke(this, new ViewportMouseMoveEventArgs(x, y, active));
                    }
                    else
                    {
                        viewport.Active = false;
                    }
                }

                return;
            }

            Drag(new ViewportMouseDragEventArgs(previousMouseDragPosition, new Vector2(x, y)));

            previousMouseDragPosition = new Vector2(x, y);
        }
Esempio n. 19
0
 private IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam)
 {
     try
     {
         if ((int)wParam == WM_MOUSEMOVE)
         {
             var e  = new InputEventArgs();
             var pt = new POINT();
             GetPhysicalCursorPos(ref pt);
             e.X = pt.x;
             e.Y = pt.y;
             Task.Run(() => OnMouseMove?.Invoke(e));
         }
         else if ((int)wParam == WM_LBUTTONDOWN || (int)wParam == WM_RBUTTONDOWN)
         {
             var e  = new InputEventArgs();
             var pt = new POINT();
             GetPhysicalCursorPos(ref pt);
             e.X = pt.x;
             e.Y = pt.y;
             Task.Run(() => OnMouseDown?.Invoke(e));
         }
         else if ((int)wParam == WM_LBUTTONUP || (int)wParam == WM_RBUTTONUP)
         {
             var e  = new InputEventArgs();
             var pt = new POINT();
             GetPhysicalCursorPos(ref pt);
             e.X = pt.x;
             e.Y = pt.y;
             Task.Run(() => OnMouseUp?.Invoke(e));
         }
         return(CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam));
     }
     catch (Exception ex)
     {
         System.Diagnostics.Trace.WriteLine("LowLevelMouseProc: " + ex.Message);
         return(IntPtr.Zero);
     }
 }
Esempio n. 20
0
    // Update is called once per frame
    void Update()
    {
        //We transform the touch position into word space from screen space and store it.
        Vector3   touchPosWorld   = MainCamera.ScreenToWorldPoint(Input.mousePosition);
        Vector2   touchPosWorld2D = new Vector2(touchPosWorld.x, touchPosWorld.y);
        Transform hitTransform    = null;
        //We now raycast with this information. If we have hit something we can process it.
        RaycastHit2D hitInformation = Physics2D.Raycast(touchPosWorld2D, MainCamera.transform.forward);

        if (Physics.Raycast(touchPosWorld, Vector3.forward, out var hitInformation3D))
        {
            hitTransform = hitInformation3D.transform;
        }
        else if (hitInformation.transform)
        {
            hitTransform = hitInformation.transform;
        }

        if (Input.GetMouseButtonDown(0))
        {
            OnMouseDown?.Invoke(touchPosWorld2D, hitTransform);
        }

        if (Input.GetMouseButton(0))
        {
            OnMouseMove?.Invoke(touchPosWorld2D, hitTransform);
        }

        if (Input.GetMouseButtonUp(0))
        {
            OnMouseUp?.Invoke(touchPosWorld2D, hitTransform);
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            LevelManager.LoadLevel(0);
        }
    }
Esempio n. 21
0
 public virtual void MouseMove(Vec2 position)
 {
     foreach (var child in children)
     {
         child.MouseMove(position);
         if (child.Inside(position))
         {
             if (!child.Hovered)
             {
                 child.Hover();
             }
             child.Hovered = true;
         }
         else
         {
             if (child.Hovered)
             {
                 child.Unhover();
             }
             child.Hovered = false;
         }
     }
     OnMouseMove?.Invoke(position);
 }
Esempio n. 22
0
        private void _OnMouseMove(InputEventArgs e)
        {
            if (isMouseDown)
            {
                return;
            }
            if (CurrentProcessId == 0)
            {
                CurrentProcessId = System.Diagnostics.Process.GetCurrentProcess().Id;
            }
            var thread = new Thread(new ThreadStart(() =>
            {
                try
                {
                    lock (_lock)
                    {
                        if (_processing)
                        {
                            return;
                        }
                        _processing = true;
                    }
                    try
                    {
                        if (e.Element == null)
                        {
                            var Element = AutomationHelper.GetFromPoint(e.X, e.Y);
                            if (Element != null)
                            {
                                e.SetElement(Element);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex, "");
                    }
                    lock (_lock)
                    {
                        _processing = false;
                    }
                    if (e.Element == null)
                    {
                        return;
                    }

                    if (e.Element.RawElement.Properties.ProcessId.IsSupported && e.Element.RawElement.Properties.ProcessId.ValueOrDefault == CurrentProcessId)
                    {
                        return;
                    }
                    var re = new RecordEvent
                    {
                        Button    = e.Button,
                        OffsetX   = e.X - e.Element.Rectangle.X,
                        OffsetY   = e.Y - e.Element.Rectangle.Y,
                        Element   = e.Element,
                        UIElement = e.Element,
                        X         = e.X,
                        Y         = e.Y
                    }; OnMouseMove?.Invoke(this, re);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "");
                }
            }));

            thread.IsBackground = true;
            thread.Start();
        }
        internal void DispatchEvent(Map map, HtmlMarkerJsEventArgs eventArgs)
        {
            if (eventArgs.Options != null)
            {
                var popupOptions = Options.Popup;
                Options       = eventArgs.Options;
                Options.Popup = popupOptions;
            }

            switch (eventArgs.Type)
            {
            case "click":
                OnClick?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this));
                break;

            case "contextmenu":
                OnContextMenu?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this));
                break;

            case "dblclick":
                OnDblClick?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this));
                break;

            case "drag":
                OnDrag?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this));
                break;

            case "dragend":
                OnDragEnd?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this));
                break;

            case "dragstart":
                OnDragStart?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this));
                break;

            case "keydown":
                OnKeyDown?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this));
                break;

            case "keypress":
                OnKeyPress?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this));
                break;

            case "keyup":
                OnKeyUp?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this));
                break;

            case "mousedown":
                OnMouseDown?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this));
                break;

            case "mouseenter":
                OnMouseEnter?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this));
                break;

            case "mouseleave":
                OnMouseLeave?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this));
                break;

            case "mousemove":
                OnMouseMove?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this));
                break;

            case "mouseout":
                OnMouseOut?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this));
                break;

            case "mouseover":
                OnMouseOver?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this));
                break;

            case "mouseup":
                OnMouseUp?.Invoke(new HtmlMarkerEventArgs(map, eventArgs.Type, this));
                break;
            }
        }
Esempio n. 24
0
        public static void InvokeEvents()
        {
            if (OnLeftButtonDown != null && IsButtonDown(MouseButton.Left))
            {
                OnLeftButtonDown.Invoke(currentState);
            }
            if (OnLeftButtonPressed != null && IsButtonPressed(MouseButton.Left))
            {
                OnLeftButtonPressed.Invoke(currentState);
            }
            if (OnLeftButtonReleased != null && IsButtonReleased(MouseButton.Left))
            {
                OnLeftButtonReleased.Invoke(currentState);
            }

            if (OnRightButtonDown != null && IsButtonDown(MouseButton.Right))
            {
                OnRightButtonDown.Invoke(currentState);
            }
            if (OnRightButtonPressed != null && IsButtonPressed(MouseButton.Right))
            {
                OnRightButtonPressed.Invoke(currentState);
            }
            if (OnRightButtonReleased != null && IsButtonReleased(MouseButton.Right))
            {
                OnRightButtonReleased.Invoke(currentState);
            }

            if (OnMiddleButtonDown != null && IsButtonDown(MouseButton.Middle))
            {
                OnMiddleButtonDown.Invoke(currentState);
            }
            if (OnMiddleButtonPressed != null && IsButtonPressed(MouseButton.Middle))
            {
                OnMiddleButtonPressed.Invoke(currentState);
            }
            if (OnMiddleButtonReleased != null && IsButtonReleased(MouseButton.Middle))
            {
                OnMiddleButtonReleased.Invoke(currentState);
            }

            if (OnXButton1Down != null && IsButtonDown(MouseButton.XButton1))
            {
                OnXButton1Down.Invoke(currentState);
            }
            if (OnXButton1Pressed != null && IsButtonPressed(MouseButton.XButton1))
            {
                OnXButton1Pressed.Invoke(currentState);
            }
            if (OnXButton1Released != null && IsButtonReleased(MouseButton.XButton1))
            {
                OnXButton1Released.Invoke(currentState);
            }

            if (OnXButton2Down != null && IsButtonDown(MouseButton.XButton2))
            {
                OnXButton2Down.Invoke(currentState);
            }
            if (OnXButton2Pressed != null && IsButtonPressed(MouseButton.XButton2))
            {
                OnXButton2Pressed.Invoke(currentState);
            }
            if (OnXButton2Released != null && IsButtonReleased(MouseButton.XButton2))
            {
                OnXButton2Released.Invoke(currentState);
            }

            if (OnButtonDown != null && IsButtonDown(MouseButton.Any))
            {
                OnButtonDown.Invoke(currentState, GetDownButtons());
            }
            if (OnButtonPressed != null && IsButtonPressed(MouseButton.Any))
            {
                OnButtonPressed.Invoke(currentState, GetPressedButtons());
            }
            if (OnButtonReleased != null && IsButtonReleased(MouseButton.Any))
            {
                OnButtonReleased.Invoke(currentState, GetReleasedButtons());
            }

            if (OnMouseWheelUp != null && IsMouseWheelUp())
            {
                OnMouseWheelUp.Invoke(currentState);
            }
            if (OnMouseWheelDown != null && IsMouseWheelDown())
            {
                OnMouseWheelDown.Invoke(currentState);
            }

            if (OnMouseMove != null && IsMouseMoving())
            {
                OnMouseMove.Invoke(currentState, GetMoveDirection());
            }
        }
Esempio n. 25
0
 // private bool mouseDownWaiting = false;
 private void RaiseOnMouseMove(InputEventArgs e)
 {
     OnMouseMove?.Invoke(e);
 }
Esempio n. 26
0
        private void WindowOnMouseMove(object sender, MouseMoveEventArgs e)
        {
            var mouseEvent = ConvertMouseButtonEventToMouseEvent(e);

            OnMouseMove?.Invoke(this, mouseEvent);
        }
Esempio n. 27
0
        public override void PollEvents()
        {
            while (SDL.PollEvent(out ev) == 1)
            {
                switch (ev.Type)
                {
                case EventType.Quit:
                    OnQuit?.Invoke();
                    break;

                case EventType.KeyDown:
                    OnKeyDown?.Invoke(ev.Key.Keysym.Sym, ev.Key.Keysym.ScanCode);
                    break;

                case EventType.KeyUp:
                    OnKeyUp?.Invoke(ev.Key.Keysym.Sym, ev.Key.Keysym.ScanCode);
                    break;

                case EventType.MouseMotion:
                    OnMouseMove?.Invoke(ev.Motion.X, ev.Motion.Y);
                    break;

                case EventType.MouseButtonDown:
                    OnMouseButtonDown?.Invoke(ev.Button.Button);
                    break;

                case EventType.MouseButtonUp:
                    OnMouseButtonUp?.Invoke(ev.Button.Button);
                    break;

                case EventType.MouseWheel:
                    OnMouseScroll?.Invoke(ev.Wheel.X, ev.Wheel.Y);
                    break;

                case EventType.JoyDeviceAdded:
                    OnJoyDeviceAdd?.Invoke(ev.JDevice.Which);
                    break;

                case EventType.JoyDeviceRemoved:
                    OnJoyDeviceRemove?.Invoke(ev.JDevice.Which);
                    break;

                case EventType.JoyButtonDown:
                    OnJoyButtonDown?.Invoke(ev.JButton.Which, ev.JButton.Button);
                    break;

                case EventType.JoyButtonUp:
                    OnJoyButtonDown?.Invoke(ev.JButton.Which, ev.JButton.Button);
                    break;

                case EventType.JoyAxisMotion:
                    OnJoyAxisMove?.Invoke(ev.JAxis.Which, ev.JAxis.Axis, ev.JAxis.Value / (float)short.MaxValue);
                    break;

                case EventType.WindowEvent:
                    if (ev.Window.WindowID == windowID)
                    {
                        switch (ev.Window.Event)
                        {
                        case WindowEventID.Close:
                            OnWinClose?.Invoke();
                            break;

                        case WindowEventID.Shown:
                            OnWinShown?.Invoke();
                            break;

                        case WindowEventID.Hidden:
                            OnWinHidden?.Invoke();
                            break;

                        case WindowEventID.Exposed:
                            OnWinExposed?.Invoke();
                            break;

                        case WindowEventID.Moved:
                            OnWinMoved?.Invoke();
                            break;

                        case WindowEventID.Resized:
                            OnWinResized?.Invoke();
                            break;

                        case WindowEventID.Minimized:
                            OnWinMinimized?.Invoke();
                            break;

                        case WindowEventID.Maximized:
                            OnWinMaximized?.Invoke();
                            break;

                        case WindowEventID.Restored:
                            OnWinRestored?.Invoke();
                            break;

                        case WindowEventID.Enter:
                            OnWinEnter?.Invoke();
                            break;

                        case WindowEventID.Leave:
                            OnWinLeave?.Invoke();
                            break;

                        case WindowEventID.FocusGained:
                            OnWinFocusGained?.Invoke();
                            break;

                        case WindowEventID.FocusLost:
                            OnWinFocusLost?.Invoke();
                            break;

                        default:
                            OnWinOtherEvent?.Invoke((int)ev.Window.Event);
                            break;
                        }
                    }
                    break;

                default:
                    OnOtherEvent?.Invoke((int)ev.Type);
                    break;
                }
            }
        }
Esempio n. 28
0
 public void DoJSMouseMove(MouseEvent evt)
 {
     ProteusContext.Log("evt=" + evt.ClientPosX + "," + evt.ClientPosY);
     OnMouseMove?.Invoke(evt);
 }
        /// <summary>
        /// Update cursor and keyboard events
        /// </summary>
        private void UpdateCursorAndKeyboardEvents()
        {
            if (!Visible)
            {
                return;
            }

            MouseEvent    mouseState = MouseHandler.GetState();
            KeyboardState kbState    = KeyboardHandler.GetState();
            var           mouseSize  = new Vector2(5);

            var mouseRect = new Rectangle((int)mouseState.X, (int)mouseState.Y, (int)mouseSize.X, (int)mouseSize.Y);

            var thisRect = new Rectangle((int)Position.X, (int)Position.Y, (int)Size.X, (int)Size.Y);

            //First check position
            if (mouseRect.Intersects(thisRect))
            {
                //Second, check buttons

                //Left
                if (LastMouseCheck.LeftButton == ButtonState.Released && mouseState.LeftButton == ButtonState.Pressed)
                {
                    OnMouseDown?.Invoke(this, mouseState.Position, MouseButtons.Left);
                }

                if (LastMouseCheck.LeftButton == ButtonState.Pressed && mouseState.LeftButton == ButtonState.Released)
                {
                    OnMouseUp?.Invoke(this, mouseState.Position, MouseButtons.Left);
                    OnMouseClick?.Invoke(this, mouseState.Position, MouseButtons.Left);
                }

                //Right
                if (LastMouseCheck.RightButton == ButtonState.Released && mouseState.RightButton == ButtonState.Pressed)
                {
                    OnMouseDown?.Invoke(this, mouseState.Position, MouseButtons.Right);
                }

                if (LastMouseCheck.RightButton == ButtonState.Pressed && mouseState.RightButton == ButtonState.Released)
                {
                    OnMouseUp?.Invoke(this, mouseState.Position, MouseButtons.Right);
                    OnMouseClick?.Invoke(this, mouseState.Position, MouseButtons.Right);
                }

                //Middle
                if (LastMouseCheck.MiddleButton == ButtonState.Released && mouseState.MiddleButton == ButtonState.Pressed)
                {
                    OnMouseDown?.Invoke(this, mouseState.Position, MouseButtons.Middle);
                }

                if (LastMouseCheck.MiddleButton == ButtonState.Pressed && mouseState.MiddleButton == ButtonState.Released)
                {
                    OnMouseUp?.Invoke(this, mouseState.Position, MouseButtons.Middle);
                    OnMouseClick?.Invoke(this, mouseState.Position, MouseButtons.Middle);
                }

                //Check move

                if (LastMouseCheck.Position != mouseState.Position)
                {
                    OnMouseMove?.Invoke(this, mouseState.Position, MouseButtons.None);
                }

                //Hook Keyboard

                if (kbState.GetPressedKeys().Count() > 0 && LastKeyboardState.GetPressedKeys().Count() > 0)
                {
                    //check pressed keys
                    List <Keys> pressedKeys = kbState.GetPressedKeys().Except(LastKeyboardState.GetPressedKeys()).ToList();

                    foreach (Keys p in pressedKeys)
                    {
                        OnKeyPress?.Invoke(this, p, kbState);
                    }

                    //check released keys
                    List <Keys> releasedKeys = LastKeyboardState.GetPressedKeys().Except(kbState.GetPressedKeys()).ToList();

                    foreach (Keys r in releasedKeys)
                    {
                        OnKeyUp?.Invoke(this, r, kbState);
                        OnKeyPress?.Invoke(this, r, kbState);
                    }
                }
            }
            else
            {
                // Leave == Release

                //Left
            }

            LastMouseCheck    = mouseState;
            LastKeyboardState = kbState;
        }
        internal void DispatchEvent(Map map, MapJsEventArgs eventArgs)
        {
            switch (eventArgs.Type)
            {
            case "click":
                OnClick?.Invoke(new MapMouseEventArgs(map, eventArgs));
                break;

            case "contextmenu":
                OnContextMenu?.Invoke(new MapMouseEventArgs(map, eventArgs));
                break;

            case "dblclick":
                OnDblClick?.Invoke(new MapMouseEventArgs(map, eventArgs));
                break;

            case "layeradded":
                OnLayerAdded?.Invoke(new MapEventArgs(map, eventArgs.Type));
                break;

            case "layerremoved":
                OnLayerRemoved?.Invoke(new MapEventArgs(map, eventArgs.Type));
                break;

            case "mousedown":
                OnMouseDown?.Invoke(new MapMouseEventArgs(map, eventArgs));
                break;

            case "mouseenter":
                OnMouseEnter?.Invoke(new MapMouseEventArgs(map, eventArgs));
                break;

            case "mouseleave":
                OnMouseLeave?.Invoke(new MapMouseEventArgs(map, eventArgs));
                break;

            case "mousemove":
                OnMouseMove?.Invoke(new MapMouseEventArgs(map, eventArgs));
                break;

            case "mouseout":
                OnMouseOut?.Invoke(new MapMouseEventArgs(map, eventArgs));
                break;

            case "mouseover":
                OnMouseOver?.Invoke(new MapMouseEventArgs(map, eventArgs));
                break;

            case "mouseup":
                OnMouseUp?.Invoke(new MapMouseEventArgs(map, eventArgs));
                break;

            case "touchcancel":
                OnTouchCancel?.Invoke(new MapTouchEventArgs(map, eventArgs));
                break;

            case "touchend":
                OnTouchEnd?.Invoke(new MapTouchEventArgs(map, eventArgs));
                break;

            case "touchmove":
                OnTouchMove?.Invoke(new MapTouchEventArgs(map, eventArgs));
                break;

            case "touchstart":
                OnTouchStart?.Invoke(new MapTouchEventArgs(map, eventArgs));
                break;

            case "wheel":
                OnWheel?.Invoke(new MapEventArgs(map, eventArgs.Type));
                break;
            }
        }