Skip to content

ui::Matrix

Header: winui/render/PathGeometry.hpp.

An affine transform in row-vector layout: x' = x*m11 + y*m21 + dx, y' = x*m12 + y*m22 + dy. a * b applies a first.

The default-constructed matrix is the identity. Renderer::push_transform() takes one, and PathGeometry::transformed() runs a geometry's points through one.

Example:

// Scale by 2, then move 10 DIPs right: (5,5) lands at (20,10).
const ui::Matrix m = ui::Matrix::scale(2.0f, 2.0f) * ui::Matrix::translation(10.0f, 0.0f);
const ui::Point  p = m.apply(ui::Point{5.0f, 5.0f});
const auto          back = m.inverted(); // nullopt only for a zero scale
renderer.push_transform(m);
// ... draw ...
renderer.pop_transform();

m11

float m11 = 1.0f

x scale (and rotation cosine).

m12

float m12 = 0.0f

How much x feeds y' (rotation / skew).

m21

float m21 = 0.0f

How much y feeds x' (rotation / skew).

m22

float m22 = 1.0f

y scale (and rotation cosine).

dx

float dx = 0.0f

Horizontal translation, in DIPs.

dy

float dy = 0.0f

Vertical translation, in DIPs.

translation

static Matrix translation(float x, float y)

A pure translation by (x, y) DIPs.

scale

static Matrix scale(float sx, float sy)

A scale about the origin, sx horizontally and sy vertically.

rotation

static Matrix rotation(float degrees)

A rotation by degrees clockwise (y down), about the origin.

apply

Point apply(Point p) const

p run through the transform.

is_identity

bool is_identity() const

True for the exact identity (no tolerance), which lets a caller skip a push_transform().

inverted

std::optional<Matrix> inverted() const

The inverse, or nullopt for a singular matrix (a zero scale), which maps every point onto a line and so has no way back. Pointer input hitting a scaled-to-nothing element gets this.

transform_bounds

Rect transform_bounds(const Rect& r) const

The axis-aligned bounds of r once transformed.