private void DrawBackgroundInternal(SKCanvas canvas, ArgbColor color, Rect2 rect) { using (SKPaint brush = ToSKPaintBrush(color)) { SKRect srect = SKRect.Create( _scaleToPage(rect.X), _scaleToPage(rect.Y), _scaleToPage(rect.Width), _scaleToPage(rect.Height)); canvas.DrawRect(srect, brush); } }
private Rect2 GetBoundingArea(IEnumerable <PathChunkArea> areas) { var firstArea = areas.ElementAt(0); var boundingRect = new Rect2(firstArea.ChunkOffset, new Vector2(firstArea.HorizontalChunkCount, firstArea.VerticalChunkCount)); foreach (var area in areas) { boundingRect = boundingRect.Merge(new Rect2(area.ChunkOffset, new Vector2(area.HorizontalChunkCount, area.VerticalChunkCount))); } // boundingRect = boundingRect.Grow(1f); return(boundingRect); }
float enlargeFactor = 1.5f; // how much the button enlarges by when hovered public override void _Ready() { origScale = this.RectScale; origIndex = this.GetIndex(); // get this button's rect // used later for hover detection origRect = GetChild <Control>(0).GetRect(); origRect.Size /= 1.35f; // make it a bit smaller so that multiple buttons cant be simultaneously hovered setButtonInfo(); }
public bool Overlaps(IBaseShape shape, Rect2 target, double radius, IDictionary <Type, IBounds> registered) { if (!(shape is ILineShape line)) { throw new ArgumentNullException(nameof(shape)); } var a = new Point2(line.Start.X, line.Start.Y); var b = new Point2(line.End.X, line.End.Y); return(Line2.LineIntersectsWithRect(a, b, target, out double x0clip, out double y0clip, out double x1clip, out double y1clip)); }
public override void _Ready() { camera = GetParent <Camera2D>(); UserCamera = camera; UserGUI = this; dragRectVisual = GetNode <DragSelect>("DragSelect"); dragRect = new Rect2(); this.SetAsToplevel(true); SetProcess(true); }
public override void _Ready() { SetProcessInput(true); dialogText = GetTree().Root.GetNode <RichTextLabel>("MainScene/HUDLayer/DialogBox/DialogText"); Connect(nameof(SendTextToDialog), dialogText, "_ReceiveText"); dialogText.Connect("SignalDialogActive", this, "SetDialog"); player = GetTree().Root.GetNode <KinematicBody2D>("MainScene/Player"); collisionShape = GetNode <CollisionShape2D>("CollisionShape2D"); rectangleShape = (RectangleShape2D)collisionShape.Shape; rect = new Rect2(collisionShape.GlobalPosition.x - rectangleShape.Extents.x, collisionShape.GlobalPosition.y - rectangleShape.Extents.y, rectangleShape.Extents.x * 2, rectangleShape.Extents.y * 2); }
/// <summary> /// /// </summary> /// <param name="g"></param> /// <param name="c"></param> /// <param name="width"></param> /// <param name="height"></param> private void DrawBackground(Graphics g, ArgbColor c, double width, double height) { var brush = new SolidBrush(Color.FromArgb(c.A, c.R, c.G, c.B)); var rect = Rect2.Create(0, 0, width, height); g.FillRectangle( brush, (float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height); brush.Dispose(); }
/// <summary> /// Get the index of the beings within the rectangle rect. /// </summary> public List <int> GetBeingsInside(Rect2 rect) { // Lazy::: TODO var max_x = rect.Position.x < rect.End.x ? rect.End.x : rect.Position.x; var min_x = rect.Position.x > rect.End.x ? rect.End.x : rect.Position.x; var max_y = rect.Position.y < rect.End.y ? rect.End.y : rect.Position.y; var min_y = rect.Position.y > rect.End.y ? rect.End.y : rect.Position.y; Func <Vector2, bool> inside = p => p.x > min_x && p.x < max_x && p.y <max_y && p.y> min_y; return(GetChildren().Where(x => x is GoBeing && inside(((GoBeing)x).Position)).Select(x => ((GoBeing)x).index).ToList()); }
public override bool Overlaps(IBaseShape shape, Rect2 target, double radius, IDictionary <Type, HitTestBase> registered) { if (!(shape is IEllipseShape ellipse)) { throw new ArgumentNullException(nameof(shape)); } return(Rect2.FromPoints( ellipse.TopLeft.X, ellipse.TopLeft.Y, ellipse.BottomRight.X, ellipse.BottomRight.Y).IntersectsWith(target)); }
//For GUI objects that need manual scaling public GUIObject(Vector2 pos, Vector2 size, Texture t, Vector2 scale, Func <bool> shouldShow = null) : base(shouldShow) { automaticRescaling = false; Position = pos; rect = new Rect2(new Vector2(), size); sprite = new Sprite(); if (t != null) { sprite.Texture = t; } sprite.Scale = scale; AddChild(sprite); }
public bool Contains(IBaseShape shape, Point2 target, double radius, IDictionary <Type, IBounds> registered) { if (!(shape is IRectangleShape rectangle)) { throw new ArgumentNullException(nameof(shape)); } return(Rect2.FromPoints( rectangle.TopLeft.X, rectangle.TopLeft.Y, rectangle.BottomRight.X, rectangle.BottomRight.Y).Contains(target)); }
/// <summary> /// /// </summary> /// <param name="gfx"></param> /// <param name="container"></param> private void DrawBackgroundInternal(Graphics gfx, Container container) { Brush brush = ToSolidBrush(container.Background); var rect = Rect2.Create(0, 0, container.Width, container.Height); gfx.FillRectangle( brush, _scaleToPage(rect.X), _scaleToPage(rect.Y), _scaleToPage(rect.Width), _scaleToPage(rect.Height)); brush.Dispose(); }
/// <summary> /// Hit test rectangle if intersects with any of the shape bounds. /// </summary> /// <param name="shapes"></param> /// <param name="rect"></param> /// <param name="selection"></param> /// <param name="selected"></param> /// <param name="threshold"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static bool HitTest(IEnumerable <BaseShape> shapes, Rect2 rect, Vector2[] selection, ISet <BaseShape> selected, double threshold, double dx, double dy) { foreach (var shape in shapes) { var result = HitTest(shape, rect, selection, selected, threshold, dx, dy); if (result == true) { return(true); } } return(false); }
public IBaseShape Overlaps(IBaseShape shape, Rect2 target, double radius, IHitTest hitTest, Modifier modifier) { if (!(shape is CubicBezierShape cubicBezier)) { throw new ArgumentNullException("shape"); } var points = new List <IPointShape>(); cubicBezier.GetPoints(points); return(HitTestHelper.Overlap(points, target) ? shape : null); }
void ScaleControls() { Rect2 screen = this.GetViewportRect(); float width = screen.Size.x; float height = screen.Size.y; float wu = width / 10; // relative height and width units float hu = height / 10; Menu.ScaleControl(background, width, height, 0, 0); Menu.ScaleControl(mainMenuButton, 2 * wu, hu, 0, height - hu); Menu.ScaleControl(titleLabel, 2 * wu, hu, 4 * wu, 0); Menu.ScaleControl(creditsLabel, 8 * wu, 8 * hu, wu, hu); }
public void ScaleControls() { Rect2 screen = this.GetViewportRect(); float width = screen.Size.x; float height = screen.Size.y; float wu = width / 10; // relative height and width units float hu = height / 10; Menu.ScaleControl(healthBox, 2 * wu, hu, 0, height - hu); Menu.ScaleControl(itemBox, 2 * wu, hu, 8 * wu, 9 * hu); Menu.ScaleControl(objectiveBox, 4 * wu, hu, 3 * wu, 0); Menu.ScaleControl(interactionBox, 4 * wu, hu, 3 * wu, 7 * hu); }
public override bool Contains(IBaseShape shape, Point2 target, double radius, IDictionary <Type, HitTestBase> registered) { if (!(shape is IImageShape image)) { throw new ArgumentNullException(nameof(shape)); } return(Rect2.FromPoints( image.TopLeft.X, image.TopLeft.Y, image.BottomRight.X, image.BottomRight.Y).Contains(target)); }
public virtual void Resize(Vector2 newSize) { if (automaticRescaling) { rect = new Rect2(new Vector2(), newSize); sprite.Position = newSize / 2; sprite.Scale = new Vector2(rect.Size.x / sprite.Texture.GetSize().x, rect.Size.y / sprite.Texture.GetSize().y); } else { throw new NotSupportedException(); } }
void ScaleControls() { Rect2 screen = this.GetViewportRect(); float width = screen.Size.x; float height = screen.Size.y; float wu = width / 10; // relative height and width units float hu = height / 10; Menu.ScaleControl(localButton, 2 * wu, 2 * hu, 0, 0); Menu.ScaleControl(onlineButton, 2 * wu, 2 * hu, 0, 2 * hu); Menu.ScaleControl(settingsButton, 2 * wu, 2 * hu, 0, 4 * hu); Menu.ScaleControl(quitButton, 2 * wu, 2 * hu, 0, 8 * hu); }
public bool Overlaps(IBaseShape shape, Rect2 target, double radius, IDictionary <Type, IBounds> registered) { if (!(shape is IImageShape image)) { throw new ArgumentNullException(nameof(shape)); } return(Rect2.FromPoints( image.TopLeft.X, image.TopLeft.Y, image.BottomRight.X, image.BottomRight.Y).IntersectsWith(target)); }
public override void Render(Win2DRenderable renderable, CanvasDrawingSession session, Win2DColor color, bool renderSelection) { var borderBrush = renderable.Resources.ThemeDarkBrush(color); var backgroundBrush = renderable.Node.IsSelected ? renderable.Resources.ThemeLightBrush(color) : renderable.Resources.ThemeNormalBrush(color); var bounds = renderable.RenderBounds.ToRect(); if (borderRadius > 0) { session.FillRoundedRectangle(bounds, borderRadius, borderRadius, backgroundBrush); session.DrawRoundedRectangle(bounds, borderRadius, borderRadius, borderBrush); } else { session.FillRectangle(bounds, backgroundBrush); session.DrawRectangle(bounds, borderBrush); } RenderIcon(renderable, session); RenderText(renderable, session); RenderCheckBox(renderable, session); if (!renderSelection) { return; } if (renderable.Node.IsSelected) { var rect = Rect2.Deflate(renderable.RenderBounds, SelectionMargin).ToRect(); if (borderRadius > 0) { session.DrawRoundedRectangle(rect, borderRadius * 1.4f, borderRadius * 1.4f, borderBrush, 2f, SelectionStrokeStyle); } else { session.DrawRectangle(rect, borderBrush, 2f, SelectionStrokeStyle); } } RenderExpandButton(renderable, session); RenderNotesButton(renderable, session); }
public override void _Draw() { if (world.Grid != null) { Rect2 scale = world.Grid.DrawMinimap(this, new Rect2(0, 0, this.RectSize.x, this.RectSize.y)); for (int i = 0; i < world.Creeps.Count; i++) { Vector3 p3 = world.Creeps[i].Translation; Vector2 p = new Vector2(p3.x, p3.z) * scale.Size + scale.Position; Rect2 r = new Rect2(p.x - 2, p.y - 2, 4, 4); DrawRect(r, MinimapColors.CREEP); } } }
public HashSet <IBaseShape> TryToGetShapes(IEnumerable <IBaseShape> shapes, Rect2 target, double radius) { var selected = new HashSet <IBaseShape>(); foreach (var shape in shapes) { var result = Registered[shape.TargetType].Overlaps(shape, target, radius, Registered); if (result == true) { selected.Add(shape); } } return(selected.Count > 0 ? selected : null); }
public override void _PhysicsProcess(float delta) { Vector2 cameraMovement = Vector2.Zero; bool skipMove = false; // SetZoom(Utils.LerpVec2(GetZoom(), _zoom, delta)); Zoom = _zoom; if (UseKeys) { for (int i = 0; i < moveKeysOn.Length; i++) { if (!moveKeysOn[i]) { continue; } cameraMovement += MOVE_DIRECTIONS[i] * CameraSpeed * delta; } } if (UseEdge) { Rect2 rect = GetViewport().GetVisibleRect(); Vector2 pos = GetLocalMousePosition() + rect.Size / 2; foreach (Vector2 direction in MOVE_DIRECTIONS) { Vector2 bounds = Utils.ClampVec2(direction, 0, 1) * rect.Size; if ((pos - bounds).Abs().Min() < CameraMargin) { // GD.Print(pos, bounds, (pos - bounds).Abs().Min(), direction * CameraSpeed * delta); cameraMovement += direction * CameraSpeed * delta; } } } if (UseDrag && _dragMouseOn) { // this somehow fixes funky camera movement AddToPosition((_previousMousePosition - GetLocalMousePosition()) * GetZoom()); Align(); skipMove = true; } _previousMousePosition = GetLocalMousePosition(); if (skipMove) { return; } AddToPosition(cameraMovement * Zoom); }
public override bool Overlaps(BaseShape shape, Rect2 target, double radius, IDictionary <Type, HitTestBase> registered) { var line = shape as LineShape; if (line == null) { throw new ArgumentNullException(nameof(shape)); } var a = new Point2(line.Start.X, line.Start.Y); var b = new Point2(line.End.X, line.End.Y); return(Line2.LineIntersectsWithRect(a, b, target, out double x0clip, out double y0clip, out double x1clip, out double y1clip)); }
public void ToCorners() { Rect2 rect = new Rect2(10, 20, 50, 30); var corners = rect.ToCorners(); Assert.Equal(new[] { new Vector2(10, 20), new Vector2(60, 20), new Vector2(60, 50), new Vector2(10, 50) }, corners); }
public ISet <IBaseShape> TryToGetShapes(IEnumerable <IBaseShape> shapes, Rect2 target, double radius, double scale, Modifier modifier) { var selected = new HashSet <IBaseShape>(); foreach (var shape in shapes.Reverse()) { var result = shape.Bounds?.Overlaps(shape, target, radius / scale, this, modifier); if (result != null) { selected.Add(shape); } } return(selected.Count > 0 ? selected : null); }
public static bool IsPointOnGUI(this Node parent, Vector2 point) { List <Control> panels = GetAllControls(parent); foreach (Control panel in panels) { Rect2 rect = new Rect2(panel.RectGlobalPosition, panel.RectSize); if (rect.HasPoint(point)) { return(true); } } return(false); }
public ISet <BaseShape> TryToGetShapes(IEnumerable <BaseShape> shapes, Rect2 target, double radius) { var selected = new HashSet <BaseShape>(); foreach (var shape in shapes.Reverse()) { var result = GetHitTest(shape)?.Overlaps(shape, target, radius, this); if (result != null) { selected.Add(shape); } } return(selected.Count > 0 ? selected : null); }
/// <summary>The <c>_intersect</c> method tests whether the room passed as the second parameter /// intersects with any of the rooms in the <c>rooms</c> list.</summary> public bool _intersects(List <Rect2> rooms, Rect2 room) { var isIntersecting = false; foreach (Rect2 roomOther in rooms) { if (room.Intersects(roomOther)) { isIntersecting = true; break; } } return(isIntersecting); }
public bool Equals(Rect2 other) { return X.Equals(other.X) && Y.Equals(other.Y) && Width.Equals(other.Width) && Height.Equals(other.Height); }