public void Update(TouchStateBase touchState, MouseStateBase mouseState, IGameTiming gameTime) { if (this.touchAction != null && touchState.Touches.Any(t => this.Rectangle.Intercept(t.Position))) { this.touchAction.Invoke(gameTime); } if (this.hoverAction != null && this.Rectangle.Intercept(mouseState.Position)) { this.hoverAction.Invoke(gameTime); } if (this.clickAction != null) { if (this.mappingGestures.Any(g => (g & touchState.CurrentGesture.GestureType) == g) && this.Rectangle.Intercept(touchState.CurrentGesture.Position)) { this.clickAction.Invoke(gameTime); } if (this.mappingMouseButtons.Any(mouseState.IsButtonDown) && this.Rectangle.Intercept(mouseState.Position)) { this.clickAction.Invoke(gameTime); } } }
protected override InputConfiguration CreateInputConfiguration() { var inputConfiguration = new InputConfiguration(); // Keyboard inputConfiguration.AddDigitalButton("Back").Assign(KeyboardKeys.Escape) //.MapClickTo(gt => this.screenNavigation.Exit()); .MapClickTo(gt => this.Exit()); inputConfiguration.AddDigitalButton("GotoSandbox").Assign(KeyboardKeys.D1) .MapClickTo(gt => this.LaunchSandboxSample()); inputConfiguration.AddDigitalButton("GotoShootEmUp").Assign(KeyboardKeys.D2) .MapClickTo(gt => this.LaunchShootEmUpSample()); inputConfiguration.AddDigitalButton("GotoTiled").Assign(KeyboardKeys.D3) .MapClickTo(gt => this.LaunchTiledSample()); inputConfiguration.AddDigitalButton("GotoTouch").Assign(KeyboardKeys.D4) .MapClickTo(gt => this.LaunchTouchSample()); // Mouse Func<RectangleHit, Samples> hitToSampleFunc = hit => { if (hit != null) { if (hit.RectangleElement == this.sandboxRectangle) return Samples.Sandbox; if (hit.RectangleElement == this.shootEmUpRectangle) return Samples.ShootEmUp; if (hit.RectangleElement == this.tiledRectangle) return Samples.Tiled; if (hit.RectangleElement == this.touchRectangle) return Samples.Touch; } return Samples.None; }; inputConfiguration.CreateMouseTracking(this.Camera).OnUpdate((mt, e) => { this.mouseState = mt; var hit = this.Scene.GetHits(this.mouseState.AbsolutePosition, this.Camera).OfType<RectangleHit>().FirstOrDefault(); this.hoveringSample = hitToSampleFunc(hit); }); inputConfiguration.AddDigitalButton("MouseSelection").Assign(MouseButtons.Left).MapClickTo(elapse => { var hit = this.Scene.GetHits(this.mouseState.AbsolutePosition, this.Camera).OfType<RectangleHit>().FirstOrDefault(); var hitSample = hitToSampleFunc(hit); switch (hitSample) { case Samples.Sandbox: this.LaunchSandboxSample(); break; case Samples.ShootEmUp: this.LaunchShootEmUpSample(); break; case Samples.Tiled: this.LaunchTiledSample(); break; case Samples.Touch: this.LaunchTouchSample(); break; } }); // Touch inputConfiguration.CreateTouchTracking(this.Camera).OnUpdate((ts, gt) => { this.touchState = ts; if (this.touchState.Touches.Any()) { var hit = this.touchState.Touches .SelectMany(t => this.Scene.GetHits(t.Position, this.Camera)) .OfType<RectangleHit>().FirstOrDefault(); this.hoveringSample = hitToSampleFunc(hit); } }); inputConfiguration.AddEvent("TouchSelection").Assign(TouchGestureType.Tap).MapTo(gt => { var hit = this.Scene.GetHits(this.touchState.CurrentGesture.Position, this.Camera) .OfType<RectangleHit>().FirstOrDefault(); var hitSample = hitToSampleFunc(hit); switch (hitSample) { case Samples.Sandbox: this.LaunchSandboxSample(); break; case Samples.ShootEmUp: this.LaunchShootEmUpSample(); break; case Samples.Tiled: this.LaunchTiledSample(); break; case Samples.Touch: this.LaunchTouchSample(); break; } }); return inputConfiguration; }
public void Update(TouchStateBase touchState, IGameTiming gameTime) { var cameraAdjutedMouseState = touchState.AdjustToCamera(this.camera); this.touchAction.Invoke(cameraAdjutedMouseState, gameTime); }
public void Update(TouchStateBase touchState, IGameTiming gameTime) { if (this.touchAction != null && this.mappingGestures.Any(g => (g & touchState.CurrentGesture.GestureType) == g)) this.touchAction.Invoke(gameTime); }
public AdjustedTouchState(TouchStateBase innerTouchState, ICamera camera) { this.innerTouchState = innerTouchState; this.camera = camera; }