protected virtual void UpdateMouseState(InputState state) { if (PassThrough) { return; } MouseState mouse = (MouseState)state.Mouse; currentCursorHandler = null; foreach (InputHandler h in inputHandlers) { if (!h.IsActive) { continue; } ICursorInputHandler ch = h as ICursorInputHandler; if (ch == null) { continue; } // Make first handler which is active the current handler. (Handlers are ordered by priority.) if (currentCursorHandler == null && ch.Position != null) { currentCursorHandler = ch; } h.UpdateInput(currentCursorHandler == h); foreach (var b in mouse.ButtonStates) { switch (b.Button) { case MouseButton.Left: b.State |= ch.Left ?? false; break; case MouseButton.Middle: b.State |= ch.Middle ?? false; break; case MouseButton.Right: b.State |= ch.Right ?? false; break; case MouseButton.Button1: b.State |= ch.Back ?? false; break; case MouseButton.Button2: b.State |= ch.Forward ?? false; break; } } mouse.WheelUp |= ch.WheelUp ?? false; mouse.WheelDown |= ch.WheelDown ?? false; } if (currentCursorHandler != null) { //convert InputHandler coordinates to native scren coordinates. Vector2 pos = currentCursorHandler.Position ?? Vector2.Zero; pos.X /= currentCursorHandler.Size.X; pos.Y /= currentCursorHandler.Size.Y; Quad q = ScreenSpaceInputQuad; mouse.Position = q.TopLeft + new Vector2(pos.X * q.Width, pos.Y * q.Height); } else { mouse.Position = Vector2.Zero; } }
protected virtual void UpdateMouseState(InputState state) { if (PassThrough) { return; } MouseState mouse = (MouseState)state.Mouse; currentCursorHandler = null; foreach (InputHandler h in inputHandlers) { if (!h.IsActive) { continue; } ICursorInputHandler ch = h as ICursorInputHandler; if (ch == null) { continue; } // Make first handler which is active the current handler. (Handlers are ordered by priority.) if (currentCursorHandler == null && ch.Position != null) { currentCursorHandler = ch; } h.UpdateInput(currentCursorHandler == h); foreach (var b in mouse.ButtonStates) { switch (b.Button) { case MouseButton.Left: b.State |= ch.Left ?? false; break; case MouseButton.Middle: b.State |= ch.Middle ?? false; break; case MouseButton.Right: b.State |= ch.Right ?? false; break; case MouseButton.Button1: b.State |= ch.Back ?? false; break; case MouseButton.Button2: b.State |= ch.Forward ?? false; break; } } mouse.WheelUp |= ch.WheelDiff.HasValue && ch.WheelDiff.Value > 0; mouse.WheelDown |= ch.WheelDiff.HasValue && ch.WheelDiff.Value < 0; mouse.WheelDiff += ch.WheelDiff ?? 0; } if (currentCursorHandler != null) { //convert inputhandler coordinates to inputmanager coordinates. Vector2 pos = currentCursorHandler.Position ?? Vector2.Zero; pos = Vector2.Multiply(pos, Vector2.Divide(Host.DrawSize, currentCursorHandler.Size)); mouse.Position = pos; } else { mouse.Position = Vector2.Zero; } }