示例#1
0
    public void CheckMouseButtonEvent()
    {
        MouseButton[] buttons = { MouseButton.Left, MouseButton.Rigth, MouseButton.Middle };

        foreach (MouseButton btn in buttons)
        {
            // Mouse button down
            if (Input.GetMouseButtonDown((int)btn))
            {
                MouseButtonDown.Invoke(new MouseButtonEventData()
                {
                    MouseButton   = btn,
                    MousePosition = Input.mousePosition,
                    ButtonDown    = true
                });
            }

            // Mouse button up
            if (Input.GetMouseButtonUp((int)btn))
            {
                MouseButtonUp.Invoke(new MouseButtonEventData()
                {
                    MouseButton   = btn,
                    MousePosition = Input.mousePosition,
                    ButtonDown    = false
                });
            }
        }
    }
示例#2
0
        /// <summary>
        /// Handles a SharpDX MouseInput event and fires the relevant InputEvents event (Scroll, MouseButtonDown or MouseButtonUp).
        /// </summary>
        private void DeviceOnMouseInput(object sender, MouseInputEventArgs e)
        {
            try
            {
                if (e.WheelDelta != 0)
                {
                    Scroll?.Invoke(sender, e);
                }

                if (e.IsMouseDownEvent())
                {
                    if (!pressedMouseButtons.Contains(e.GetMouseButton()))
                    {
                        pressedMouseButtons.Add(e.GetMouseButton());
                    }
                    MouseButtonDown?.Invoke(sender, e);
                }
                else if (e.IsMouseUpEvent())
                {
                    pressedMouseButtons.Remove(e.GetMouseButton());
                    MouseButtonUp?.Invoke(sender, e);
                }
            }
            catch (Exception exc)
            {
                Global.logger.Error("Exception while handling mouse input. Error: " + exc.ToString());
            }
        }
 private static void Handle_Mouse_Buttons(MouseUpdate data)
 {
     if (data.IsButton)
     {
         MouseButtonDown?.Invoke(null, new MouseButtonEventArgs((int)data.Offset, data.Value));
     }
 }
示例#4
0
 private void OnMouseDown(MouseButtonEventArgs args)
 {
     MouseButtonDown?.Invoke(args);
     if (!_blocked)
     {
         BlockableMouseButtonDown?.Invoke(args);
     }
 }
示例#5
0
 public WindowWrapperInput(Window window)
 {
     _window                     = window;
     window.TextEntered         += (sender, args) => TextEntered?.Invoke(args);
     window.KeyPressed          += (sender, args) => KeyPressed?.Invoke(args);
     window.MouseButtonPressed  += (sender, args) => MouseButtonDown?.Invoke(args);
     window.MouseButtonReleased += (sender, args) => MouseButtonUp?.Invoke(args);
     window.MouseMoved          += (sender, args) => MouseMoved?.Invoke(args);
     window.MouseWheelScrolled  += (sender, args) => MouseWheelScrolled?.Invoke(args);
 }
示例#6
0
 private void EmitButtonChange(bool prev, bool next, MouseButton button, MouseStatus nextStatus)
 {
     if (!prev && next)
     {
         MouseButtonDown?.Invoke(sender, new MouseButtonEvent(LastMouseStatus, nextStatus, button));
     }
     else if (prev && !next)
     {
         var ev = new MouseButtonEvent(LastMouseStatus, nextStatus, button);
         MouseButtonUp?.Invoke(sender, ev);
         MouseClick?.Invoke(sender, ev);
     }
 }
示例#7
0
        internal Window(string title = null, int width = 1920, int height = 1080, bool fullScreen = true)
        {
            if (title == null)
            {
                title = "AshyEngine build " + AssemblyUtils.BuildNumber;
            }

            PrivateWindow = new GameWindow(width,
                                           height,
                                           GraphicsMode.Default,
                                           title,
                                           fullScreen
                                                                  ? GameWindowFlags.Fullscreen
                                                                  : GameWindowFlags.Default);

            _windowCenter = new Point(PrivateWindow.Width / 2, PrivateWindow.Height / 2);
            PressedKeys   = new bool[131];
            KeyDown      += button => PressedKeys[(uint)button] = true;
            KeyUp        += button => PressedKeys[(uint)button] = false;
            Resize       += size => _windowCenter = new Point(size.Width / 2, size.Height / 2);

            PrivateWindow.Mouse.ButtonDown += (sender, args) =>
                                              MouseButtonDown?.Invoke((MouseButton)args.Button, args.Position);

            PrivateWindow.Mouse.ButtonUp += (sender, args) =>
                                            MouseButtonUp?.Invoke((MouseButton)args.Button, args.Position);

            //PrivateWindow.RenderFrame       += (sender, args) =>
            //    RenderFrame?.Invoke         ( (float) args.Time );

            PrivateWindow.Mouse.Move += (sender, args) =>
                                        MouseMove?.Invoke(new Point(args.XDelta, args.YDelta), args.Position);

            PrivateWindow.KeyDown += (sender, args) =>
                                     KeyDown?.Invoke((Key)args.Key);

            PrivateWindow.Resize += (sender, args) =>
                                    Resize?.Invoke(PrivateWindow.ClientSize);

            PrivateWindow.KeyUp += (sender, args) =>
                                   KeyUp?.Invoke((Key)args.Key);

            PrivateWindow.VSync   = VSyncMode.Adaptive;
            PrivateWindow.Visible = true;
        }
示例#8
0
        /// <summary>
        /// Handles a SharpDX MouseInput event and fires the relevant InputEvents event (Scroll, MouseButtonDown or MouseButtonUp).
        /// </summary>
        private void DeviceOnMouseInput(object sender, MouseInputEventArgs e)
        {
            if (e.WheelDelta != 0)
            {
                Scroll?.Invoke(sender, e);
            }

            if (e.IsMouseDownEvent())
            {
                if (!pressedMouseButtons.Contains(e.GetMouseButton()))
                {
                    pressedMouseButtons.Add(e.GetMouseButton());
                }
                MouseButtonDown?.Invoke(sender, e);
            }
            else if (e.IsMouseUpEvent())
            {
                pressedMouseButtons.Remove(e.GetMouseButton());
                MouseButtonUp?.Invoke(sender, e);
            }
        }
示例#9
0
 public void OnPointerDown(PointerEventData eventData)
 {
     OnMouseButtonDownEvent.Invoke(this.gameObject);
 }
示例#10
0
        public override void EnterMessageLoop(bool runInBackground)
        {
            IntPtr e       = System.Runtime.InteropServices.Marshal.AllocHGlobal(24 * sizeof(long));
            bool   running = true;

            while (running)
            {
                while (XPending(_display) != 0)
                {
                    XNextEvent(_display, e);

                    if (XFilterEvent(e, IntPtr.Zero))
                    {
                        continue;
                    }

                    XAnyEvent anyEvent = (XAnyEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XAnyEvent));

                    switch ((Event)anyEvent.type)
                    {
                    case Event.ClientMessage:
                    {
                        running = false;
                        break;
                    }

                    case Event.ConfigureNotify:
                    {
                        XConfigureEvent configureEvent = (XConfigureEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XConfigureEvent));

                        LocationChanged?.Invoke(this, configureEvent.x, configureEvent.y);
                        SizeChanged?.Invoke(this, configureEvent.width, configureEvent.height);
                        break;
                    }

                    case Event.FocusIn:
                    {
                        Activated?.Invoke(this);
                        break;
                    }

                    case Event.FocusOut:
                    {
                        Deactivated?.Invoke(this);
                        break;
                    }

                    case Event.MotionNotify:
                    {
                        XMotionEvent motionEvent = (XMotionEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XMotionEvent));
                        MouseMove?.Invoke(this, motionEvent.x, motionEvent.y);
                        break;
                    }

                    case Event.ButtonPress:
                    {
                        XButtonEvent buttonEvent = (XButtonEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XButtonEvent));

                        switch ((Button)buttonEvent.button)
                        {
                        case Button.Button1:
                        {
                            MouseButtonDown?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Left);
                            break;
                        }

                        case Button.Button2:
                        {
                            MouseButtonDown?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Middle);
                            break;
                        }

                        case Button.Button3:
                        {
                            MouseButtonDown?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Right);
                            break;
                        }

                        case Button.Button4:
                        {
                            MouseWheel?.Invoke(this, buttonEvent.x, buttonEvent.y, 120);
                            break;
                        }

                        case Button.Button5:
                        {
                            MouseWheel?.Invoke(this, buttonEvent.x, buttonEvent.y, -120);
                            break;
                        }
                        }
                        break;
                    }

                    case Event.ButtonRelease:
                    {
                        XButtonEvent buttonEvent = (XButtonEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XButtonEvent));

                        switch ((Button)buttonEvent.button)
                        {
                        case Button.Button1:
                        {
                            MouseButtonUp?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Left);
                            break;
                        }

                        case Button.Button2:
                        {
                            MouseButtonUp?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Middle);
                            break;
                        }

                        case Button.Button3:
                        {
                            MouseButtonUp?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Right);
                            break;
                        }
                        }
                        break;
                    }

                    case Event.KeyPress:
                    {
                        XKeyEvent keyEvent = (XKeyEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XKeyEvent));
                        KeySym    ks       = XLookupKeysym(ref keyEvent, 0);
                        Key       key      = NoesisKey(ks);
                        if (key != Key.None)
                        {
                            KeyDown?.Invoke(this, key);
                        }

                        if (_xic != IntPtr.Zero)
                        {
                            Status status = 0;
                            byte[] buffer = new byte[256];
                            KeySym ret_ks = (KeySym)0;
                            int    size   = Xutf8LookupString(_xic, e, buffer, 255, ref ret_ks, ref status);
                            if (size > 0 && ((int)status == XLookupChars || (int)status == XLookupBoth))
                            {
                                buffer[size] = 0;
                                Decoder decoder   = _utf8.GetDecoder();
                                char[]  text      = new char[256];
                                int     bytesUsed = 0;
                                int     charsUsed = 0;
                                bool    completed = false;
                                decoder.Convert(buffer, 0, size, text, 0, 255, true, out bytesUsed, out charsUsed, out completed);
                                for (int i = 0; i < charsUsed; ++i)
                                {
                                    Char?.Invoke(this, text[i]);
                                }
                            }
                        }
                        break;
                    }

                    case Event.KeyRelease:
                    {
                        XKeyEvent keyEvent = (XKeyEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XKeyEvent));
                        KeySym    ks       = XLookupKeysym(ref keyEvent, 0);
                        Key       key      = NoesisKey(ks);
                        if (key != Key.None)
                        {
                            KeyUp?.Invoke(this, key);
                        }
                        break;
                    }
                    }
                }

                Render?.Invoke(this);
            }
            System.Runtime.InteropServices.Marshal.FreeHGlobal(e);
        }
示例#11
0
 public void OnMouseButtonDown(int x, int y, MouseButton button)
 {
     MouseButtonDown?.Invoke(this, x, y, button);
 }
示例#12
0
 protected virtual void OnMouseDown(MouseEventArgs e)
 {
     MouseButtonDown?.Invoke(this, e);
 }
示例#13
0
 private void OnMouseButtonDown(IMouse mouse, MouseButton button)
 {
     MouseButtonDown?.Invoke(mouse, button);
 }
示例#14
0
        public void Update()
        {
            InputEvent e;

            if (events_.Count > 0)
            {
                while (events_.Count > 0)
                {
                    e = events_.Pop();
                    switch (e.type_)
                    {
                    case InputEventType.KeyboardEvent:

                        KeyboardEvent ke = (KeyboardEvent)e;

                        switch (ke.keyboardtype_)
                        {
                        case KeyboardEventType.KeyDown:
                            if (KeyDown != null)
                            {
                                KeyDown.Invoke(ke);
                            }
                            break;

                        case KeyboardEventType.KeyUp:
                            if (KeyUp != null)
                            {
                                KeyUp.Invoke(ke);
                            }
                            break;
                        }

                        break;

                    case InputEventType.MouseEvent:

                        MouseEvent me = (MouseEvent)e;

                        switch (me.mouseeventtype_)
                        {
                        case MouseEventType.MouseMove:

                            if (MouseMove != null)
                            {
                                MouseMove.Invoke(me);
                            }

                            break;

                        case MouseEventType.MouseDown:
                            if (MouseButtonDown != null)
                            {
                                MouseButtonDown.Invoke(me);
                            }

                            break;

                        case MouseEventType.MouseUp:
                            if (MouseButtonUp != null)
                            {
                                MouseButtonUp.Invoke(me);
                            }
                            break;

                        case MouseEventType.MouseWheel:
                            if (MouseWheel != null)
                            {
                                MouseWheel.Invoke(me);
                            }
                            break;
                        }
                        break;
                    }
                }
            }
        }