/// <summary> /// Draws a colored texture. /// </summary> /// <param name="texture">The texture.</param> /// <param name="color">The color of the texture.</param> /// <param name="destinationRectangle">The rectangle the texture will be displayed in.</param> /// <param name="sourceRectangle">The rectangle defining the part of the texture that will be displayed.</param> /// <param name="opacity">The opacity of the drawn texture.</param> /// <param name="interpolationMode">The interpolation mode used to stretch the texture.</param> /// <exception cref="System.ArgumentOutOfRangeException">The source rectangle lies not inside the textures bounds.</exception> public void DrawTexture(Texture texture, Color4 color, Rectangle destinationRectangle, Rectangle sourceRectangle, float opacity = 1f, InterpolationMode interpolationMode = InterpolationMode.Default) { if (sourceRectangle.Left < 0 || sourceRectangle.Top < 0 || sourceRectangle.Right > texture.Width || sourceRectangle.Bottom > texture.Height) { throw new ArgumentOutOfRangeException(nameof(sourceRectangle)); } SetTexture(texture, color, opacity); SetSamplerState(currentWrapMode, interpolationMode == InterpolationMode.Default ? defaultInterpolationMode : interpolationMode); float textCoordLeft = sourceRectangle.Left / texture.Width; float textCoordRight = sourceRectangle.Right / texture.Width; float textCoordTop = sourceRectangle.Top / texture.Height; float textCoordBottom = sourceRectangle.Bottom / texture.Height; Vertex[] vertices = new[] { new Vertex(destinationRectangle.Left, destinationRectangle.Top, textCoordLeft, textCoordTop), new Vertex(destinationRectangle.Right, destinationRectangle.Top, textCoordRight, textCoordTop), new Vertex(destinationRectangle.Left, destinationRectangle.Bottom, textCoordLeft, textCoordBottom), new Vertex(destinationRectangle.Right, destinationRectangle.Bottom, textCoordRight, textCoordBottom), }; int[] indices = { 0, 1, 2, 1, 2, 3 }; DrawVertices(indices, vertices, 0); }
protected internal override void OnPaint(PaintEventArgs e) { base.OnPaint(e); for (int i = 0; i < Children.Count; i++) { UIElement child = Children[i]; if (child.Visible) { Rectangle bounds = new Rectangle(e.Bounds.X + child.AbsoluteLocation.X, e.Bounds.Y + child.AbsoluteLocation.Y, child.AbsoluteSize.X, child.AbsoluteSize.Y); PaintEventArgs args = new PaintEventArgs(e.Renderer, bounds); child.OnPaint(args); } } }
/// <summary> /// Fills a rectangle with a brush. /// </summary> /// <param name="rectangle">The rectangle to fill.</param> /// <param name="brush">The brush used to fill the rectangle.</param> public void FillRectangle(Rectangle rectangle, Brush brush) { SetBrush(brush); Vertex[] vertices = new[] { new Vertex(rectangle.Left, rectangle.Top), new Vertex(rectangle.Right, rectangle.Top), new Vertex(rectangle.Left, rectangle.Bottom), new Vertex(rectangle.Right, rectangle.Bottom), }; int[] indices = { 0, 1, 2, 1, 2, 3 }; brush.UpdateVertices(vertices); DrawVertices(indices, vertices, 0); }
/// <summary> /// Draws a colored texture. /// </summary> /// <param name="texture">The texture.</param> /// <param name="color">The color of the texture.</param> /// <param name="destinationRectangle">The rectangle the texture will be displayed in.</param> /// <param name="opacity">The opacity of the drawn texture.</param> /// <param name="interpolationMode">The interpolation mode used to stretch the texture.</param> public void DrawTexture(Texture texture, Color4 color, Rectangle destinationRectangle, float opacity = 1f, InterpolationMode interpolationMode = InterpolationMode.Default) { SetTexture(texture, color, opacity); SetSamplerState(currentWrapMode, interpolationMode == InterpolationMode.Default ? defaultInterpolationMode : interpolationMode); Vertex[] vertices = new[] { new Vertex(destinationRectangle.Left, destinationRectangle.Top, 0, 0), new Vertex(destinationRectangle.Right, destinationRectangle.Top, 1, 0), new Vertex(destinationRectangle.Left, destinationRectangle.Bottom, 0, 1), new Vertex(destinationRectangle.Right, destinationRectangle.Bottom, 1, 1), }; int[] indices = { 0, 1, 2, 1, 2, 3 }; DrawVertices(indices, vertices, 0); }
/// <summary> /// Sets the clipping region to the specified rectangle. /// </summary> /// <param name="region">A rectangle defining the new clipping region.</param> /// <param name="reset">Optional. If set to true the old clipping region is discarded, otherweise the new region adds to the old one.</param> /// <remarks>The clipping region is reset automatically before every render cycle.</remarks> public void SetClip(Rectangle region, bool reset = true) { SetBrushBuffer(ClipBrush); if (reset) { ResetClip(); } deviceContext.OutputMerger.SetDepthStencilState(clipDepthStencilState, 1); Vertex[] vertices = new[] { new Vertex(region.Left, region.Top), new Vertex(region.Right, region.Top), new Vertex(region.Left, region.Bottom), new Vertex(region.Right, region.Bottom), }; int[] indices = { 0, 1, 2, 1, 2, 3 }; DrawVertices(indices, vertices, 0); deviceContext.OutputMerger.SetDepthStencilState(clippingDepthStencilState, 1); }
/// <summary> /// Checks if this rectangle intersects with another rectangle. /// </summary> public bool IntersectsWith(Rectangle rect) { return !(this.Left > rect.Right || this.Right < rect.Left || this.Top > rect.Bottom || this.Bottom < rect.Top); }
static Rectangle() { Empty = default(Rectangle); }
public PaintEventArgs(Renderer renderer, Rectangle bounds) { Renderer = renderer; Bounds = bounds; }
/// <summary> /// Draws a colored texture. /// </summary> /// <param name="texture">The texture.</param> /// <param name="color">The color of the texture.</param> /// <param name="destinationRectangle">The rectangle the texture will be displayed in.</param> /// <param name="sourceRectangle">The rectangle defining the part of the texture that will be displayed.</param> /// <param name="opacity">The opacity of the drawn texture.</param> /// <param name="interpolationMode">The interpolation mode used to stretch the texture.</param> /// <exception cref="System.ArgumentOutOfRangeException">The source rectangle lies not inside the textures bounds.</exception> public void DrawTexture(Texture texture, Color4 color, Rectangle destinationRectangle, Rectangle sourceRectangle, float opacity = 1f, InterpolationMode interpolationMode = InterpolationMode.Default) { if (sourceRectangle.Left < 0 || sourceRectangle.Top < 0 || sourceRectangle.Right > texture.Width || sourceRectangle.Bottom > texture.Height) throw new ArgumentOutOfRangeException(nameof(sourceRectangle)); SetTexture(texture, color, opacity); SetSamplerState(currentWrapMode, interpolationMode == InterpolationMode.Default ? defaultInterpolationMode : interpolationMode); float textCoordLeft = sourceRectangle.Left / texture.Width; float textCoordRight = sourceRectangle.Right / texture.Width; float textCoordTop = sourceRectangle.Top / texture.Height; float textCoordBottom = sourceRectangle.Bottom / texture.Height; Vertex[] vertices = new[] { new Vertex(destinationRectangle.Left, destinationRectangle.Top, textCoordLeft, textCoordTop), new Vertex(destinationRectangle.Right, destinationRectangle.Top, textCoordRight, textCoordTop), new Vertex(destinationRectangle.Left, destinationRectangle.Bottom, textCoordLeft, textCoordBottom), new Vertex(destinationRectangle.Right, destinationRectangle.Bottom, textCoordRight, textCoordBottom), }; int[] indices = { 0, 1, 2, 1, 2, 3 }; DrawVertices(indices, vertices, 0); }
/// <summary> /// Sets the clipping region to the specified rectangle. /// </summary> /// <param name="region">A rectangle defining the new clipping region.</param> /// <param name="reset">Optional. If set to true the old clipping region is discarded, otherweise the new region adds to the old one.</param> /// <remarks>The clipping region is reset automatically before every render cycle.</remarks> public void SetClip(Rectangle region, bool reset = true) { SetBrushBuffer(ClipBrush); if (reset) ResetClip(); deviceContext.OutputMerger.SetDepthStencilState(clipDepthStencilState, 1); Vertex[] vertices = new[] { new Vertex(region.Left, region.Top), new Vertex(region.Right, region.Top), new Vertex(region.Left, region.Bottom), new Vertex(region.Right, region.Bottom), }; int[] indices = { 0, 1, 2, 1, 2, 3 }; DrawVertices(indices, vertices, 0); deviceContext.OutputMerger.SetDepthStencilState(clippingDepthStencilState, 1); }
/// <summary> /// Draws formatted text. /// </summary> /// <param name="text">The text.</param> /// <param name="bounds">The bounds the text will be displayed in.</param> /// <param name="font">The font of the text.</param> /// <param name="size">The font size in points.</param> /// <param name="brush">The brush used to draw the text.</param> /// <param name="format">The format of the text.</param> public void DrawText(string text, Rectangle bounds, Font font, float size, TextFormat format, Brush brush) { var layout = new TextLayout(text, bounds.Size, font, size, format); DrawTextLayout(layout, bounds.Location, brush); }
/// <summary> /// Draws a texture. /// </summary> /// <param name="texture">The texture.</param> /// <param name="destinationRectangle">The rectangle the texture will be displayed in.</param> /// <param name="opacity">The opacity of the drawn texture.</param> /// <param name="interpolationMode">The interpolation mode used to stretch the texture.</param> public void DrawTexture(Texture texture, Rectangle destinationRectangle, float opacity = 1f, InterpolationMode interpolationMode = InterpolationMode.Default) { DrawTexture(texture, Color4.White, destinationRectangle, opacity, interpolationMode); }