OpenTK.Platform.Windows.WinRawMouse.ProcessMouseEvent C# (CSharp) Method

ProcessMouseEvent() public method

public ProcessMouseEvent ( RawInput rin ) : bool
rin RawInput
return bool
        public bool ProcessMouseEvent(RawInput rin)
        {
            RawMouse raw = rin.Data.Mouse;
            ContextHandle handle = new ContextHandle(rin.Header.Device);

            MouseState mouse;
            if (!rawids.ContainsKey(handle))
            {
                RefreshDevices();
            }

            if (mice.Count == 0)
                return false;

            // Note:For some reason, my Microsoft Digital 3000 keyboard reports 0
            // as rin.Header.Device for the "zoom-in/zoom-out" buttons.
            // That's problematic, because no device has a "0" id.
            // As a workaround, we'll add those buttons to the first device (if any).
            int mouse_handle = rawids.ContainsKey(handle) ? rawids[handle] : 0;
            mouse = mice[mouse_handle];

            // Set and release capture of the mouse to fix http://www.opentk.com/node/2133, Patch by Artfunkel
            if ((raw.ButtonFlags & RawInputMouseState.LEFT_BUTTON_DOWN) != 0){
                mouse.EnableBit((int)MouseButton.Left);
                Functions.SetCapture(Window);
            }
            if ((raw.ButtonFlags & RawInputMouseState.LEFT_BUTTON_UP) != 0)
            {
                mouse.DisableBit((int)MouseButton.Left);
                Functions.ReleaseCapture();
            }
            if ((raw.ButtonFlags & RawInputMouseState.RIGHT_BUTTON_DOWN) != 0)
            {
                mouse.EnableBit((int)MouseButton.Right);
                Functions.SetCapture(Window);
            }
            if ((raw.ButtonFlags & RawInputMouseState.RIGHT_BUTTON_UP) != 0)
            {
                mouse.DisableBit((int)MouseButton.Right);
                Functions.ReleaseCapture();
            }
            if ((raw.ButtonFlags & RawInputMouseState.MIDDLE_BUTTON_DOWN) != 0)
            {
                mouse.EnableBit((int)MouseButton.Middle);
                Functions.SetCapture(Window);
            }
            if ((raw.ButtonFlags & RawInputMouseState.MIDDLE_BUTTON_UP) != 0)
            {
                mouse.DisableBit((int)MouseButton.Middle);
                Functions.ReleaseCapture();
            }
            if ((raw.ButtonFlags & RawInputMouseState.BUTTON_4_DOWN) != 0)
            {
                mouse.EnableBit((int)MouseButton.Button1);
                Functions.SetCapture(Window);
            }
            if ((raw.ButtonFlags & RawInputMouseState.BUTTON_4_UP) != 0)
            {
            	mouse.DisableBit((int)MouseButton.Button1);
            	Functions.ReleaseCapture();
            }
            if ((raw.ButtonFlags & RawInputMouseState.BUTTON_5_DOWN) != 0)
            {
                mouse.EnableBit((int)MouseButton.Button2);
                Functions.SetCapture(Window);
            }
            if ((raw.ButtonFlags & RawInputMouseState.BUTTON_5_UP) != 0)
            {
                mouse.DisableBit((int)MouseButton.Button2);
                Functions.ReleaseCapture();
            }

            if ((raw.ButtonFlags & RawInputMouseState.WHEEL) != 0)
                mouse.WheelPrecise += (short)raw.ButtonData / 120.0f;

            if ((raw.Flags & RawMouseFlags.MOUSE_MOVE_ABSOLUTE) != 0)
            {
                mouse.X = raw.LastX;
                mouse.Y = raw.LastY;
            }
            else
            {   // Seems like MOUSE_MOVE_RELATIVE is the default, unless otherwise noted.
                mouse.X += raw.LastX;
                mouse.Y += raw.LastY;
            }

            lock (UpdateLock)
            {
                mice[mouse_handle] = mouse;
                return true;
            }
        }