void UpdateMousePosition() { current = Mouse.GetState(); if (!window.Focused) { return; } if (current != previous) { // Mouse state has changed int xdelta = current.X - previous.X; int ydelta = current.Y - previous.Y; foreach (MouseEventHandler h in mouseEventHandlers) { MouseEventArgs args = new MouseEventArgs(); args.SetX(lastX); args.SetY(lastY); args.SetMovementX(xdelta); args.SetMovementY(ydelta); args.SetEmulated(true); h.OnMouseMove(args); } } previous = current; if (mousePointerLocked) { /* * Windows: OK * Cursor hides properly * Cursor is trapped inside window * Centering works * * Linux: Needs workaround * Cursor hides properly * Cursor is trapped inside window * Centering broken * * Mac OS X: OK * Cursor hides properly (although visible when doing Skype screencast) * Centering works * Opening "mission control" by gesture does not free cursor */ int centerx = window.Bounds.Left + (window.Bounds.Width / 2); int centery = window.Bounds.Top + (window.Bounds.Height / 2); // Setting cursor position this way works on Windows and Mac Mouse.SetPosition(centerx, centery); } }
void Mouse_Move(object sender, MouseMoveEventArgs e) { lastX = e.X; lastY = e.Y; if (TouchTest) { foreach (TouchEventHandler h in touchEventHandlers) { TouchEventArgs args = new TouchEventArgs(); args.SetX(e.X); args.SetY(e.Y); args.SetId(0); h.OnTouchMove(args); } } else { foreach (MouseEventHandler h in mouseEventHandlers) { MouseEventArgs args = new MouseEventArgs(); args.SetX(e.X); args.SetY(e.Y); args.SetMovementX(e.XDelta); args.SetMovementY(e.YDelta); args.SetEmulated(false); h.OnMouseMove(args); } } }