using System;
using System.Collections.Generic;
using System.Numerics;
using Robust.Client.GameObjects;
using Robust.Shared.Graphics;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
namespace Robust.Client.Graphics
{
public abstract class DrawingHandleWorld : DrawingHandleBase
{
protected DrawingHandleWorld(Texture white) : base(white)
{
}
private const int Ppm = EyeManager.PixelsPerMeter;
///
/// Draws an untextured colored rectangle to the world.The coordinate system is right handed.
/// Make sure to set
/// to set the model matrix if needed.
///
/// The four vertices of the quad in object space (or world if the transform is identity.).
/// Color of the rectangle.
/// Is it filled with color, or just the border lines?
public abstract void DrawRect(Box2 rect, Color color, bool filled = true);
///
/// Draws multiple filled, untextured colored rectangles to the world. All rectangles use the current transform.
///
///
/// This is the batched equivalent of repeated filled calls.
///
public abstract void DrawRects(ReadOnlySpan rects);
///
/// Draws multiple filled, untextured colored rectangles without multiplying by the handle modulation color.
///
public abstract void DrawRectsUnmodulated(ReadOnlySpan rects);
///
/// Draws an untextured colored rectangle to the world.The coordinate system is right handed.
/// Make sure to set
/// to set the model matrix if needed.
///
/// The four vertices of the quad in object space (or world if the transform is identity.).
/// The rotation of the rectangle is applied before the transform matrix.
/// Color of the rectangle.
/// Is it filled with color, or just the border lines?
public abstract void DrawRect(in Box2Rotated rect, Color color, bool filled = true);
///
/// Draws a sprite to the world. The coordinate system is right handed.
/// Make sure to set
/// to set the model matrix if needed.
///
/// Texture to draw.
/// The four vertices of the quad in object space (or world if the transform is identity.).
/// A color to multiply the texture by when shading.
/// The four corners of the texture sub region in px.
public abstract void DrawTextureRectRegion(Texture texture, Box2 quad,
Color? modulate = null, UIBox2? subRegion = null);
///
/// Draws a sprite to the world. The coordinate system is right handed.
/// Make sure to set
/// to set the model matrix if needed.
///
/// Texture to draw.
/// The four vertices of the quad in object space (or world if the transform is identity.).
/// The rotation of the rectangle is applied before the transform matrix.
/// A color to multiply the texture by when shading.
/// The four corners of the texture sub region in px.
public abstract void DrawTextureRectRegion(Texture texture, in Box2Rotated quad,
Color? modulate = null, UIBox2? subRegion = null);
///
/// Draws multiple rotated rectangles for the same texture.
///
public abstract void DrawTextureRects(Texture texture, ReadOnlySpan rects);
///
/// Draws multiple rotated rectangles for the same texture without multiplying by the handle modulation color.
///
public abstract void DrawTextureRectsUnmodulated(Texture texture, ReadOnlySpan rects);
///
/// Renders a sprite through the supplied post-shader passes.
///
public abstract void RenderSpritePostShaders(
Entity sprite,
IReadOnlyList postShaders,
Angle eyeRotation,
Angle worldRotation,
Vector2 worldPosition,
Direction? overrideDirection);
private Box2 GetQuad(Texture texture, Vector2 position)
{
return Box2.FromDimensions(position, texture.Size / (float)Ppm);
}
///
/// Draws a full texture sprite to the world. The coordinate system is right handed.
/// Make sure to set
/// to set the model matrix if needed.
///
/// Texture to draw.
/// The coordinates of the quad in object space (or world if the transform is identity.).
/// A color to multiply the texture by when shading.
///
/// The sprite will have it's local dimensions calculated so that it has texels per meter in the world.
///
public override void DrawTexture(Texture texture, Vector2 position, Color? modulate = null)
{
CheckDisposed();
DrawTextureRect(texture, GetQuad(texture, position), modulate);
}
///
/// Draws a full texture sprite to the world. The coordinate system is right handed.
/// Make sure to set
/// to set the model matrix if needed.
///
/// Texture to draw.
/// The coordinates of the quad in object space (or world if the transform is identity.).
/// The angle of the quad in object space.
/// A color to multiply the texture by when shading.
///
/// The sprite will have it's local dimensions calculated so that it has texels per meter in the world.
///
public void DrawTexture(Texture texture, Vector2 position, Angle angle, Color? modulate = null)
{
CheckDisposed();
var quad = GetQuad(texture, position);
DrawTextureRect(texture, new Box2Rotated(quad, angle, quad.Center), modulate);
}
///
/// Draws a full texture sprite to the world. The coordinate system is right handed.
/// Make sure to set
/// to set the model matrix if needed.
///
/// Texture to draw.
/// The four vertices of the quad in object space (or world if the transform is identity.).
/// A color to multiply the texture by when shading.
public void DrawTextureRect(Texture texture, Box2 quad, Color? modulate = null)
{
CheckDisposed();
DrawTextureRectRegion(texture, quad, modulate);
}
///
/// Draws an atlas texture without an additional subregion.
///
public virtual void DrawTextureRect(AtlasTexture texture, Box2 quad, Color? modulate = null)
{
CheckDisposed();
DrawTextureRectRegion(texture, quad, modulate);
}
///
/// Draws a full texture sprite to the world. The coordinate system is right handed.
/// Make sure to set
/// to set the model matrix if needed.
///
/// Texture to draw.
/// The four vertices of the quad in object space (or world if the transform is identity.).
/// The rotation of the rectangle is applied before the transform matrix.
/// A color to multiply the texture by when shading.
public void DrawTextureRect(Texture texture, in Box2Rotated quad, Color? modulate = null)
{
CheckDisposed();
DrawTextureRectRegion(texture, in quad, modulate);
}
}
///
/// A rotated rectangle for batched world texture drawing.
///
public readonly record struct WorldTextureRect(Box2Rotated Quad, Color? Modulate = null);
///
/// An axis-aligned rectangle for batched world rectangle drawing.
///
public readonly record struct WorldRect(Box2 Rect, Color Color);
}