public InputState(SAMViewportAdapter adapter, KeyboardState ks, MouseState ms, TouchCollection ts, GamePadState gs) { Mouse = ms; Keyboard = ks; TouchPanel = ts; GamePad = gs; if (Mouse.LeftButton == ButtonState.Pressed) { IsDown = true; PointerPosition = adapter.PointToScreen(Mouse.Position); } else if (TouchPanel.Count > 0) { IsDown = true; PointerPosition = adapter.PointToScreen(TouchPanel[0].Position.ToPoint()); } else { IsDown = false; PointerPosition = FPoint.Zero; } currentKeyState = new Dictionary<Keys, bool>(0); }
private InputState(SAMViewportAdapter adapter, KeyboardState ks, MouseState ms, TouchCollection ts, GamePadState gs, InputState prev) { Mouse = ms; Keyboard = ks; TouchPanel = ts; GamePad = gs; if (Mouse.LeftButton == ButtonState.Pressed) { IsDown = true; PointerPosition = adapter.PointToScreen(Mouse.Position); } else if (TouchPanel.Count > 0) { IsDown = true; PointerPosition = adapter.PointToScreen(TouchPanel[0].Position.ToPoint()); } else { IsDown = false; PointerPosition = prev.PointerPosition; } IsJustDown = IsDown && !prev.IsDown; IsJustUp = !IsDown && prev.IsDown; lastKeyState = prev.currentKeyState; currentKeyState = lastKeyState.ToDictionary(p => p.Key, p => ks.IsKeyDown(p.Key)); }
public readonly float LastPinchPower = 0f; // squared private InputState(SAMViewportAdapter gameAdapter, SAMViewportAdapter hudAdapter, KeyboardState ks, MouseState ms, TouchCollection ts, GamePadState gs, InputState prev, float mox, float moy) { Mouse = ms; Keyboard = ks; TouchPanel = ts; GamePad = gs; AllGamePointerPositions = new FPoint[TouchPanel.Count]; float sumX = 0; float sumY = 0; for (int i = 0; i < TouchPanel.Count; i++) { AllGamePointerPositions[i] = gameAdapter.PointToScreen(TouchPanel[i].Position.ToPoint()); sumX += TouchPanel[i].Position.X; sumY += TouchPanel[i].Position.Y; } if (Mouse.LeftButton == ButtonState.Pressed) { isDown = true; GamePointerPosition = gameAdapter.PointToScreen(Mouse.Position); HUDPointerPosition = hudAdapter.PointToScreen(Mouse.Position); } else if (TouchPanel.Count == 1) { isDown = true; GamePointerPosition = AllGamePointerPositions[0]; HUDPointerPosition = hudAdapter.PointToScreen(TouchPanel[0].Position.ToPoint()); } else if (TouchPanel.Count == 0) { isDown = false; GamePointerPosition = prev.GamePointerPosition; HUDPointerPosition = prev.HUDPointerPosition; } else // if (TouchPanel.Count > 1) { isDown = false; // this is correct - down onl when one finger GamePointerPosition = gameAdapter.PointToScreen(sumX / TouchPanel.Count, sumY / TouchPanel.Count); HUDPointerPosition = hudAdapter.PointToScreen(sumX / TouchPanel.Count, sumY / TouchPanel.Count); } GamePointerPositionOnMap = GamePointerPosition.RelativeTo(mox, moy); isJustDown = isDown && !prev.isDown; isJustUp = !isDown && prev.isDown; lastKeyState = prev.currentKeyState; currentKeyState = lastKeyState.ToDictionary(p => p.Key, p => IsKeyDown(p.Key, ks, gs)); LastPinchPower = prev.LastPinchPower; if (TouchPanel.Count == 2) { if (prev.IsGesturePinching) { IsGesturePinching = true; _pinchStartDistance = prev._pinchStartDistance; } var p1 = hudAdapter.PointToScreen(TouchPanel[0].Position.ToPoint()); // hud positions cause HUD will (?) not be resized var p2 = hudAdapter.PointToScreen(TouchPanel[1].Position.ToPoint()); while (Microsoft.Xna.Framework.Input.Touch.TouchPanel.IsGestureAvailable) { var g = Microsoft.Xna.Framework.Input.Touch.TouchPanel.ReadGesture(); if (g.GestureType == GestureType.Pinch) { IsGesturePinching = true; _pinchStartDistance = prev._pinchStartDistance ?? (p1 - p2).LengthSquared(); } else if (g.GestureType == GestureType.PinchComplete && prev._pinchStartDistance != null) { IsGesturePinchComplete = true; LastPinchPower = ((p1 - p2).LengthSquared() - prev._pinchStartDistance.Value) / 5000; } } } }
public FPoint TranslateHUDToGameCoordinates(float x, float y) { return(VAdapterGame.PointToScreen(VAdapterHUD.ScreenToPoint(x, y))); }