Skip to content

GraphicsAPI reference

Class Presentation

Namespace: MicroEngine.Graphics
Assembly: MicroEngine.Graphics.dll
Guide: Presentation

How the game’s canvas reaches the window, one independent choice per field: how its scale is rounded (Rounding), what happens to the window’s other shape (Aspect), how it is sampled when it is scaled (Upscale), the sampler textures get when they choose none (DefaultSampler), the size factor of captures (CaptureScale), whether desktop windows open at whole factors (WholeFactorWindows) and whether 2D cameras snap to whole pixels by default (CameraPixelSnap). PixelArt and HighResolution2D are presets: start from one and change any field with with.

C#
public sealed record Presentation : IEquatable<Presentation>

Inheritance

object ← Presentation

Implements

IEquatable<Presentation>

Constructors

Presentation()

C#
public Presentation()

Properties

Aspect

Keep the canvas’s shape (letterbox) or stretch it to the window.

C#
public AspectMode Aspect { get; init; }

Property Value

AspectMode

CameraPixelSnap

Whether 2D cameras created for this presentation round their translation to whole canvas pixels (Camera2D.PixelSnap): crisp pixel art (PixelArt), smooth motion for high-resolution art (HighResolution2D). Each camera can still change it.

C#
public bool CameraPixelSnap { get; init; }

Property Value

bool

CaptureScale

Size factor of the captures a run writes (screenshots, scripted captures): 1 is the canvas’s own size.

C#
public int CaptureScale { get; init; }

Property Value

int

Exceptions

ArgumentOutOfRangeException

The value is less than 1.

DefaultSampler

The sampler of textures, atlases and font pages created without a filter of their own: the game’s explicit default, written down instead of implied by another option.

C#
public SamplerDescription DefaultSampler { get; init; }

Property Value

SamplerDescription

HighResolution2D

High-resolution 2D: the largest size of the canvas’s shape that fits, letterboxed, linear sampling for the canvas and for textures, captures at the canvas’s size, cameras moving smoothly (no snap).

C#
public static Presentation HighResolution2D { get; }

Property Value

Presentation

PixelArt

Pixel art: whole factors unless they waste more than a fifth of the window, letterboxed, nearest sampling for the canvas and for textures, captures three times the canvas, windows opened at whole factors, cameras snapped to whole pixels.

C#
public static Presentation PixelArt { get; }

Property Value

Presentation

Rounding

How the scale is rounded.

C#
public ScaleRounding Rounding { get; init; }

Property Value

ScaleRounding

UiScale

Window pixels per UI unit of the UI view, drawn over the world at the window’s resolution. Null (the default) follows the surface’s pixel density (PixelDensity): 1 on an ordinary screen, 2 on a screen with twice the pixels per logical unit, so the interface keeps its physical size; the headless platform’s density is 1. A value overrides the density: 1 draws one UI unit per window pixel everywhere, 2 makes the UI twice as large. Platforms resolve it with UiScaleFor.

C#
public float? UiScale { get; init; }

Property Value

float?

Exceptions

ArgumentOutOfRangeException

The value is not null and not a positive finite number.

Upscale

How the canvas is sampled when it is drawn to the window at another size.

C#
public SamplerDescription Upscale { get; init; }

Property Value

SamplerDescription

WastefulThreshold

With IntegerUnlessWasteful: the share of the fitting size a whole factor must fill (0.8 by default, so a whole factor is kept when it fills at least 80 % of what would fit).

C#
public float WastefulThreshold { get; init; }

Property Value

float

Exceptions

ArgumentOutOfRangeException

The value is not within 0..1.

WholeFactorWindows

Whether desktop windows open at a whole factor of the canvas when the requested size does not fit the display.

C#
public bool WholeFactorWindows { get; init; }

Property Value

bool

Methods

<Clone>$()

C#
public Presentation <Clone>$()

Returns

Presentation

CanvasSize(RectF, int, int)

The canvas size for area: the configured size, except with Expand, where the side the window has room for grows (at the scale Rounding chooses) until the scaled canvas fills the area. Never smaller than the configured size.

C#
public (int Width, int Height) CanvasSize(RectF area, int canvasWidth, int canvasHeight)

Parameters

area RectF

canvasWidth int

canvasHeight int

Returns

(int Width, int Height)

Exceptions

ArgumentOutOfRangeException

The configured size is not positive.

Equals(object?)

C#
public override bool Equals(object? obj)

Parameters

obj object?

Returns

bool

Equals(Presentation?)

C#
public bool Equals(Presentation? other)

Parameters

other Presentation?

Returns

bool

Fit(RectF, int, int, bool)

Where the canvas lands in area (the window, or its safe area on a phone), in window pixels: the largest scale that fits, rounded by Rounding, centred; with portrait it sits at the top of the area instead (on-screen controls get the space below). With Stretch it covers the whole area.

C#
public RectF Fit(RectF area, int canvasWidth, int canvasHeight, bool portrait = false)

Parameters

area RectF

The area available, in window pixels.

canvasWidth int

The canvas’s width in pixels.

canvasHeight int

The canvas’s height in pixels.

portrait bool

Whether the screen is portrait (taller than wide by more than a tenth).

Returns

RectF

Exceptions

ArgumentOutOfRangeException

The canvas size is not positive.

Fit(Vector2, RectF, int, int)

Where the canvas lands in a window of window pixels whose usable part is safeArea (an empty safe area means the whole window): Fit in the safe area, at its top when the window is portrait (taller than wide by more than a tenth). Every backend places its frame with this method, so they agree.

C#
public RectF Fit(Vector2 window, RectF safeArea, int canvasWidth, int canvasHeight)

Parameters

window Vector2

safeArea RectF

canvasWidth int

canvasHeight int

Returns

RectF

GetHashCode()

C#
public override int GetHashCode()

Returns

int

ToCanvas(Vector2, RectF, int, int)

A window position in canvas pixels, for a canvas drawn at frame.

C#
public static Vector2 ToCanvas(Vector2 window, RectF frame, int canvasWidth, int canvasHeight)

Parameters

window Vector2

frame RectF

canvasWidth int

canvasHeight int

Returns

Vector2

ToString()

C#
public override string ToString()

Returns

string

UiScaleFor(float)

The UI scale on a surface of pixelDensity: UiScale when it is set, else the density (1 when the density is not a positive finite number).

C#
public float UiScaleFor(float pixelDensity)

Parameters

pixelDensity float

Returns

float

Operators

operator ==(Presentation?, Presentation?)

C#
public static bool operator ==(Presentation? left, Presentation? right)

Parameters

left Presentation?

right Presentation?

Returns

bool

operator !=(Presentation?, Presentation?)

C#
public static bool operator !=(Presentation? left, Presentation? right)

Parameters

left Presentation?

right Presentation?

Returns

bool