public bool IsVisible(Rectangle destination) { return destination.Left <= this.X + this.Width && destination.Right >= this.X && destination.Top <= this.Y + this.Height && destination.Bottom >= this.Y; }
private static DrawImageParams CreateDrawImageParams(RectangleInt source, Vector origin, Texture texture = null, Rectangle? destination = null, float rotation = 0.0f, Color? color = null) { var expected = new DrawImageParams { Texture = texture, Source = source, Destination = destination.HasValue ? destination.Value : Rectangle.Empty, Rotation = rotation, Origin = origin, Color = color.HasValue ? color.Value : Color.White, ImageEffect = ImageEffect.None }; return expected; }
public bool Equals(Rectangle other) { const float Tolerance = 0.00001f; return Math.Abs(other.x - this.x) < Tolerance && Math.Abs(other.y - this.y) < Tolerance && Math.Abs(other.width - this.width) < Tolerance && Math.Abs(other.height - this.height) < Tolerance; }
protected override InputConfiguration CreateInputConfiguration() { var inputConfiguration = new InputConfiguration(); inputConfiguration.AddDigitalButton("Back").Assign(KeyboardKeys.Escape) .MapClickTo(gt => this.screenNavigation.NavigateBack()); //inputConfiguration.AddTouchTracking(this.Camera).OnTouch((ts, gt) => this.touchState = ts); inputConfiguration.AddEvent("Tap").Assign(TouchGestureType.Tap).MapTo(gt => this.tapCount++); inputConfiguration.AddEvent("Hold").Assign(TouchGestureType.Hold).MapTo(gt => this.holdCount++); inputConfiguration.AddEvent("DoubleTap").Assign(TouchGestureType.DoubleTap).MapTo(gt => this.doubleTapCount++); inputConfiguration.AddEvent("DragComplete").Assign(TouchGestureType.DragComplete).MapTo(gt => this.dragCompleteCount++); inputConfiguration.AddEvent("Flick").Assign(TouchGestureType.Flick).MapTo(gt => this.flickCount++); inputConfiguration.AddEvent("FreeDrag").Assign(TouchGestureType.FreeDrag).MapTo(gt => this.freeDragCount++); inputConfiguration.AddEvent("HorizontalDrag").Assign(TouchGestureType.HorizontalDrag).MapTo(gt => this.horizontalDragCount++); inputConfiguration.AddEvent("Pinch").Assign(TouchGestureType.Pinch).MapTo(gt => this.pinchCount++); inputConfiguration.AddEvent("PinchComplete").Assign(TouchGestureType.PinchComplete).MapTo(gt => this.pinchCompleteCount++); inputConfiguration.AddEvent("VerticalDrag").Assign(TouchGestureType.VerticalDrag).MapTo(gt => this.verticalDragCount++); var viewport = this.Camera.Viewport; //var size = new Size(viewport.Width, viewport.Height); var s2 = viewport.Size.Scale(0.1f); var backRectangle = new Rectangle(viewport.Width - s2.X * 2, viewport.Height - s2.Y * 2, s2.X, s2.Y); this.visualBackButton = inputConfiguration.AddVisualButton("Back", backRectangle) .Assign(TouchGestureType.Tap) .MapTouchTo(gt => this.isHoveringBackButton = true) .MapClickTo(gt => this.screenNavigation.NavigateBack()); return inputConfiguration; }
public static Vector Clamp(Vector vector, Rectangle clampRectangle) { var x = MathUtil.Clamp(vector.X, clampRectangle.Left, clampRectangle.Right); var y = MathUtil.Clamp(vector.Y, clampRectangle.Top, clampRectangle.Bottom); return new Vector(x, y); }