# Reel windows

> Show the reels through a rounded window, a card per reel or any shape you draw.

Source: https://pixi-reels.schmooky.dev/mechanics/masks/

The viewport clips the reels through a `MaskStrategy`, so buffer cells never
show past the grid. The default is `RectMaskStrategy`, and the strategies
below are options you add on top.

| Board | Strategy |
|---|---|
| Square frame art | `RectMaskStrategy` (default) |
| Rounded frame, reels flush | `RoundedRectMaskStrategy` (`scope: 'set'`) |
| Reels as separate cards, with a cross gap | `RoundedRectMaskStrategy` (`scope: 'reel'`) |
| Rounded frame, one rect per reel, any gap | `RoundedRectMaskStrategy` (`scope: 'outer'`) |
| Hold & Win board, a mask per cell | `cellMask((cell, { corners }) => ...)` |
| Pyramid or MultiWays, rounded, reels flush | `SilhouetteMaskStrategy` |
| Hexes, holes, cut-outs | `PathMaskStrategy` |

`inset(strategy, px)` shrinks any of them by a margin, and
`composeMasks(a, b, ...)` joins several, your own strategies included.

## Writing your own

Implement `build(ctx)` and `update(g, ctx)`, set
`version = MASK_STRATEGY_VERSION`, and pass it to `.maskStrategy(...)`. Try
`PathMaskStrategy` first. A class is only worth it when it keeps state
between draws.

Two things to respect. `ctx.axis` matters because `rects` are in screen
space in every orientation (`axis.toLocal(w, h)` gives `{ cross, main }`).
`ctx.bleed` inflates the cross axis only. Add the optional `draw(g, ctx)`
and your strategy composes like the built-in ones.

## Demos

Each demo passes a mask strategy to `.maskStrategy(...)`. Rounded windows come first, then the helpers that trim or combine a mask, then a mask drawn from your own path.

## Rounded corners

### The whole window

`RoundedRectMaskStrategy` with `scope: 'set'` rounds the corners of the box around all the reels. It works at any cross gap, which is why it is the default scope.

Live demo (mask-rounded-set): https://pixi-reels.schmooky.dev/mechanics/masks/#a-rounded-window

### Each reel as a card

`scope: 'reel'` rounds every reel's box instead, so the reels read as separate cards.

It needs a cross gap above `0`. At gap `0` neighbouring reels share an edge, and rounding both sides of it cuts a notch into every seam. The strategy warns once when it sees touching reels.

Live demo (mask-rounded-reels): https://pixi-reels.schmooky.dev/mechanics/masks/#each-reel-as-its-own-card

### Outer corners only

`scope: 'outer'` keeps one rect per reel, as the default mask does, so buffer cells past a short reel stay hidden. It rounds a corner only where it is also a corner of the box around all the reels: the outer pair on the first reel and on the last. The inner edges stay square, so it works at cross gap `0`, where `scope: 'reel'` notches. `corners: { topLeft: true, ... }` limits any scope to the named screen corners.

On a jagged set the corners of the box may not touch any reel, and then nothing is rounded. Use `SilhouetteMaskStrategy` there.

Live demo (mask-outer-corners): https://pixi-reels.schmooky.dev/mechanics/masks/#one-rect-per-reel-the-windows-corners-only

### Jagged boards

A pyramid has no single rectangle to round. Rounding each reel notches the seams, and rounding the bounding box hides the staircase and shows buffer cells past the short reels. `SilhouetteMaskStrategy` follows the outline of all the reels together and rounds every corner of it. The inward corners, where a short reel meets a taller one, use `concaveRadius`. On a board with no steps it gives a plain rounded rect.

The reels must touch, at cross gap `0`. With a gap the strategy warns and falls back to a rounded rect per reel.

Live demo (mask-silhouette-pyramid): https://pixi-reels.schmooky.dev/mechanics/masks/#rounding-a-jagged-board

### Hold & Win cells

Every Hold & Win cell is its own 1x1 reel set with its own mask. `cellMask` on the Hold & Win builder takes a function that is called once per cell with `{ reel, cell }` (column and row) and `{ cols, rows, corners }`, and returns that cell's strategy. Here every cell gets a plain rect except the four corner cells, which each round their one outer corner, so the gapless board clips as one rounded window made of fifteen masks. `corners` is the cell's corner set already worked out, for the short form `(_, { corners }) => new RoundedRectMaskStrategy({ radius, corners })`.

Live demo (hold-and-win-outer-corners): https://pixi-reels.schmooky.dev/mechanics/masks/#a-mask-per-hold--win-cell-from-its-row-and-column

## Trimming and combining

### Inset and compose

`inset(strategy, px)` shrinks what any strategy draws by `px` on every side, and a negative value grows it. Use it when the art shows a pixel past the frame. `composeMasks(a, b, ...)` joins several strategies into the viewport's one mask. Here a rounded window inset by 4px is joined with a banner strip above the reels.

`composeMasks` can only form a union, because a `Graphics` mask is the union of its filled shapes. To subtract, use `.cut()` inside a `PathMaskStrategy`.

Live demo (mask-inset-compose): https://pixi-reels.schmooky.dev/mechanics/masks/#insetting-and-composing

### A different trim per side

Frame art rarely has four equal lips. `inset(strategy, { top, right, bottom, left })` trims each side by its own amount, for example `inset(new RoundedRectMaskStrategy({ radius: 43 }), { top: 4, bottom: 12 })`. Sides are screen sides in every orientation, and a side you leave out is not trimmed. Here the bottom lip is four times thicker than the top one.

Live demo (mask-inset-sides): https://pixi-reels.schmooky.dev/mechanics/masks/#mask-inset-sides

## Any shape

`PathMaskStrategy` takes a `(graphics, context) => void` callback. The context carries `rects`, `width`, `height`, `axis` and `bleed`. Do not call `g.clear()`, because the strategy already has. The demo fills the board and cuts a hole in the middle, so only the outer ring of symbols shows.

`cut()` subtracts from the last shape filled, so fill first. If you draw the hole before filling, the mask is empty and the board disappears, with no error.

Live demo (mask-path-custom): https://pixi-reels.schmooky.dev/mechanics/masks/#any-shape-without-a-class
