private ivec2 ComputePlacement(CanvasElement element) { Alignments anchor = element.Anchor; // Using a None anchor allows elements to not be automatically placed (and repositioned) by the canvas. if (anchor == Alignments.None) { return(element.Location); } bool left = (anchor & Alignments.Left) > 0; bool right = (anchor & Alignments.Right) > 0; bool top = (anchor & Alignments.Top) > 0; bool bottom = (anchor & Alignments.Bottom) > 0; ivec2 dimensions = Resolution.WindowDimensions; ivec2 offset = element.Offset; int width = dimensions.x; int height = dimensions.y; int x = left ? offset.x : (right ? width - offset.x : width / 2 + offset.x); int y = top ? offset.y : (bottom ? height - offset.y : height / 2 + offset.y); return(new ivec2(x, y)); }
// This function is only called if an anchor was set (the anchor can be None for free-moving elements that // aren't locked to a particular anchor location). private vec2 ComputePlacement(CanvasElement element) { var anchor = element.Anchor; bool left = (anchor & Anchors.Left) > 0; bool right = (anchor & Anchors.Right) > 0; bool top = (anchor & Anchors.Top) > 0; bool bottom = (anchor & Anchors.Bottom) > 0; var dimensions = Resolution.WindowDimensions; var offset = element.Offset; var width = dimensions.x; var height = dimensions.y; var x = left ? offset.x : (right ? width - offset.x : width / 2 + offset.x); var y = top ? offset.y : (bottom ? height - offset.y : height / 2 + offset.y); return(new vec2(x, y)); }
public void Add(CanvasElement element) { var placement = ComputePlacement(element); if (element.IsCentered) { placement -= element.Bounds.Dimensions / 2; } element.Location = placement; element.Canvas = this; element.Initialize(); elements.Add(element); if (element.UsesRenderTarget) { renderTargetUsers.Add((IRenderTargetUser2D)element); } }
private void PlaceElement(CanvasElement element) { Alignments anchor = element.Anchor; bool left = (anchor & Alignments.Left) > 0; bool right = (anchor & Alignments.Right) > 0; bool top = (anchor & Alignments.Top) > 0; bool bottom = (anchor & Alignments.Bottom) > 0; ivec2 dimensions = Resolution.WindowDimensions; ivec2 offset = element.Offset; int width = dimensions.x; int height = dimensions.y; int x = left ? offset.x : (right ? width - offset.x : width / 2 + offset.x); int y = top ? offset.y : (bottom ? height - offset.y : height / 2 + offset.y); element.Location = new ivec2(x, y); }
public void Remove(CanvasElement element) { var flags = element.flags; Debug.Assert(element != null, "Can't remove a null canvas element."); Debug.Assert((flags & CanvasElementFlags.IsChild) == 0, "Can't remove a child element from the canvas " + "directly (since children are managed by the parent)."); Debug.Assert((flags & CanvasElementFlags.IsRemoved) == 0, "Canvas element was already removed."); Debug.Assert((flags & CanvasElementFlags.IsAdded) > 0, "Element was never added to the canvas."); element.flags &= ~CanvasElementFlags.IsAdded; element.flags |= CanvasElementFlags.IsRemoved; element.Dispose(); elements.Remove(element); if (element is IRenderTargetUser2D user) { renderTargetUsers.Remove(user); } }
public void Remove(CanvasElement element) { elements.Remove(element); }
public void Add(CanvasElement element) { elements.Add(element); PlaceElement(element); }