private void SetButtonState(MouseButton button, bool pressed)
 {
     if (pressed)
     {
         state.EnableBit((int)button);
     }
     else
     {
         state.DisableBit((int)button);
     }
 }
Ejemplo n.º 2
0
 void WriteBit(MouseButton offset, int enabled)
 {
     if (enabled != 0)
     {
         mouse.EnableBit((int)offset);
     }
     else
     {
         mouse.DisableBit((int)offset);
     }
 }
Ejemplo n.º 3
0
 void update_mouseButtonStates(ref MouseState e, OpenTK.Input.MouseState otk_e)
 {
     for (int i = 0; i < MouseState.MaxButtons; i++) {
         if (otk_e.IsButtonDown ((OpenTK.Input.MouseButton)i))
             e.EnableBit (i);
     }
 }
Ejemplo n.º 4
0
        private void ProcessEvents()
        {
            while (true)
            {
                XEvent e = new XEvent();
                using (new XLock(this.window.Display))
                {
                    if (!Functions.XCheckIfEvent(this.window.Display, ref e, this.Predicate, new IntPtr(XI2Mouse.XIOpCode)))
                    {
                        break;
                    }
                    XGenericEventCookie cookie = e.GenericEventCookie;
                    if (Functions.XGetEventData(this.window.Display, ref cookie) != 0)
                    {
                        XIRawEvent xiRawEvent = (XIRawEvent)Marshal.PtrToStructure(cookie.data, typeof(XIRawEvent));
                        if (!this.rawids.ContainsKey(xiRawEvent.deviceid))
                        {
                            this.mice.Add(new MouseState());
                            this.rawids.Add(xiRawEvent.deviceid, this.mice.Count - 1);
                        }
                        MouseState mouseState = this.mice[this.rawids[xiRawEvent.deviceid]];
                        switch (xiRawEvent.evtype)
                        {
                        case XIEventType.RawButtonPress:
                            switch (xiRawEvent.detail)
                            {
                            case 1:
                                mouseState.EnableBit(0);
                                break;

                            case 2:
                                mouseState.EnableBit(1);
                                break;

                            case 3:
                                mouseState.EnableBit(2);
                                break;

                            case 4:
                                ++mouseState.WheelPrecise;
                                break;

                            case 5:
                                --mouseState.WheelPrecise;
                                break;

                            case 6:
                                mouseState.EnableBit(3);
                                break;

                            case 7:
                                mouseState.EnableBit(4);
                                break;

                            case 8:
                                mouseState.EnableBit(5);
                                break;

                            case 9:
                                mouseState.EnableBit(6);
                                break;

                            case 10:
                                mouseState.EnableBit(7);
                                break;

                            case 11:
                                mouseState.EnableBit(8);
                                break;

                            case 12:
                                mouseState.EnableBit(9);
                                break;

                            case 13:
                                mouseState.EnableBit(10);
                                break;

                            case 14:
                                mouseState.EnableBit(11);
                                break;
                            }

                        case XIEventType.RawButtonRelease:
                            switch (xiRawEvent.detail)
                            {
                            case 1:
                                mouseState.DisableBit(0);
                                break;

                            case 2:
                                mouseState.DisableBit(1);
                                break;

                            case 3:
                                mouseState.DisableBit(2);
                                break;

                            case 6:
                                mouseState.DisableBit(3);
                                break;

                            case 7:
                                mouseState.DisableBit(4);
                                break;

                            case 8:
                                mouseState.DisableBit(5);
                                break;

                            case 9:
                                mouseState.DisableBit(6);
                                break;

                            case 10:
                                mouseState.DisableBit(7);
                                break;

                            case 11:
                                mouseState.DisableBit(8);
                                break;

                            case 12:
                                mouseState.DisableBit(9);
                                break;

                            case 13:
                                mouseState.DisableBit(10);
                                break;

                            case 14:
                                mouseState.DisableBit(11);
                                break;
                            }

                        case XIEventType.RawMotion:
                            double x = 0.0;
                            double y = 0.0;
                            if (XI2Mouse.IsBitSet(xiRawEvent.valuators.mask, 0))
                            {
                                x = BitConverter.Int64BitsToDouble(Marshal.ReadInt64(xiRawEvent.raw_values, 0));
                            }
                            if (XI2Mouse.IsBitSet(xiRawEvent.valuators.mask, 1))
                            {
                                y = BitConverter.Int64BitsToDouble(Marshal.ReadInt64(xiRawEvent.raw_values, 8));
                            }
                            if (!this.CheckMouseWarp(x, y))
                            {
                                mouseState.X += (int)x;
                                mouseState.Y += (int)y;
                                break;
                            }
                            else
                            {
                                break;
                            }
                        }
                        this.mice[this.rawids[xiRawEvent.deviceid]] = mouseState;
                    }
                    Functions.XFreeEventData(this.window.Display, ref cookie);
                }
            }
        }
Ejemplo n.º 5
0
        void ProcessEvents()
        {
            while (true)
            {
                XEvent e = new XEvent();
                XGenericEventCookie cookie;

                using (new XLock(window.Display))
                {
                    if (!Functions.XCheckIfEvent(window.Display, ref e, Predicate, new IntPtr(XIOpCode)))
                    {
                        return;
                    }

                    cookie = e.GenericEventCookie;
                    if (Functions.XGetEventData(window.Display, ref cookie) != 0)
                    {
                        XIRawEvent raw = (XIRawEvent)
                                         Marshal.PtrToStructure(cookie.data, typeof(XIRawEvent));

                        if (!rawids.ContainsKey(raw.deviceid))
                        {
                            mice.Add(new MouseState());
                            rawids.Add(raw.deviceid, mice.Count - 1);
                        }
                        MouseState state = mice[rawids[raw.deviceid]];

                        switch (raw.evtype)
                        {
                        case XIEventType.RawMotion:
                            double x = 0, y = 0;
                            if (IsBitSet(raw.valuators.mask, 0))
                            {
                                x = BitConverter.Int64BitsToDouble(Marshal.ReadInt64(raw.raw_values, 0));
                            }
                            if (IsBitSet(raw.valuators.mask, 1))
                            {
                                y = BitConverter.Int64BitsToDouble(Marshal.ReadInt64(raw.raw_values, 8));
                            }

                            if (!CheckMouseWarp(x, y))
                            {
                                state.X += (int)x;
                                state.Y += (int)y;
                            }
                            break;

                        case XIEventType.RawButtonPress:
                            switch (raw.detail)
                            {
                            case 1: state.EnableBit((int)MouseButton.Left); break;

                            case 2: state.EnableBit((int)MouseButton.Middle); break;

                            case 3: state.EnableBit((int)MouseButton.Right); break;

                            case 4: state.WheelPrecise++; break;

                            case 5: state.WheelPrecise--; break;

                            case 6: state.EnableBit((int)MouseButton.Button1); break;

                            case 7: state.EnableBit((int)MouseButton.Button2); break;

                            case 8: state.EnableBit((int)MouseButton.Button3); break;

                            case 9: state.EnableBit((int)MouseButton.Button4); break;

                            case 10: state.EnableBit((int)MouseButton.Button5); break;

                            case 11: state.EnableBit((int)MouseButton.Button6); break;

                            case 12: state.EnableBit((int)MouseButton.Button7); break;

                            case 13: state.EnableBit((int)MouseButton.Button8); break;

                            case 14: state.EnableBit((int)MouseButton.Button9); break;
                            }
                            break;

                        case XIEventType.RawButtonRelease:
                            switch (raw.detail)
                            {
                            case 1: state.DisableBit((int)MouseButton.Left); break;

                            case 2: state.DisableBit((int)MouseButton.Middle); break;

                            case 3: state.DisableBit((int)MouseButton.Right); break;

                            case 6: state.DisableBit((int)MouseButton.Button1); break;

                            case 7: state.DisableBit((int)MouseButton.Button2); break;

                            case 8: state.DisableBit((int)MouseButton.Button3); break;

                            case 9: state.DisableBit((int)MouseButton.Button4); break;

                            case 10: state.DisableBit((int)MouseButton.Button5); break;

                            case 11: state.DisableBit((int)MouseButton.Button6); break;

                            case 12: state.DisableBit((int)MouseButton.Button7); break;

                            case 13: state.DisableBit((int)MouseButton.Button8); break;

                            case 14: state.DisableBit((int)MouseButton.Button9); break;
                            }
                            break;
                        }
                        mice[rawids[raw.deviceid]] = state;
                    }
                    Functions.XFreeEventData(window.Display, ref cookie);
                }
            }
        }
Ejemplo n.º 6
0
        public bool ProcessMouseEvent(RawInput rin)
        {
            RawMouse      rawMouse = rin.Data.Mouse;
            ContextHandle key      = new ContextHandle(rin.Header.Device);

            if (!this.rawids.ContainsKey(key))
            {
                this.RefreshDevices();
            }
            if (this.mice.Count == 0)
            {
                return(false);
            }
            int        index      = this.rawids.ContainsKey(key) ? this.rawids[key] : 0;
            MouseState mouseState = this.mice[index];

            if ((rawMouse.ButtonFlags & RawInputMouseState.LEFT_BUTTON_DOWN) != (RawInputMouseState)0)
            {
                mouseState.EnableBit(0);
            }
            if ((rawMouse.ButtonFlags & RawInputMouseState.LEFT_BUTTON_UP) != (RawInputMouseState)0)
            {
                mouseState.DisableBit(0);
            }
            if ((rawMouse.ButtonFlags & RawInputMouseState.RIGHT_BUTTON_DOWN) != (RawInputMouseState)0)
            {
                mouseState.EnableBit(2);
            }
            if ((rawMouse.ButtonFlags & RawInputMouseState.RIGHT_BUTTON_UP) != (RawInputMouseState)0)
            {
                mouseState.DisableBit(2);
            }
            if ((rawMouse.ButtonFlags & RawInputMouseState.MIDDLE_BUTTON_DOWN) != (RawInputMouseState)0)
            {
                mouseState.EnableBit(1);
            }
            if ((rawMouse.ButtonFlags & RawInputMouseState.MIDDLE_BUTTON_UP) != (RawInputMouseState)0)
            {
                mouseState.DisableBit(1);
            }
            if ((rawMouse.ButtonFlags & RawInputMouseState.BUTTON_4_DOWN) != (RawInputMouseState)0)
            {
                mouseState.EnableBit(3);
            }
            if ((rawMouse.ButtonFlags & RawInputMouseState.BUTTON_4_UP) != (RawInputMouseState)0)
            {
                mouseState.DisableBit(3);
            }
            if ((rawMouse.ButtonFlags & RawInputMouseState.BUTTON_5_DOWN) != (RawInputMouseState)0)
            {
                mouseState.EnableBit(4);
            }
            if ((rawMouse.ButtonFlags & RawInputMouseState.BUTTON_5_UP) != (RawInputMouseState)0)
            {
                mouseState.DisableBit(4);
            }
            if ((rawMouse.ButtonFlags & RawInputMouseState.WHEEL) != (RawInputMouseState)0)
            {
                mouseState.WheelPrecise += (float)(short)rawMouse.ButtonData / 120f;
            }
            if ((rawMouse.Flags & RawMouseFlags.MOUSE_MOVE_ABSOLUTE) != RawMouseFlags.MOUSE_MOVE_RELATIVE)
            {
                mouseState.X = rawMouse.LastX;
                mouseState.Y = rawMouse.LastY;
            }
            else
            {
                mouseState.X += rawMouse.LastX;
                mouseState.Y += rawMouse.LastY;
            }
            lock (this.UpdateLock)
            {
                this.mice[index] = mouseState;
                return(true);
            }
        }