Skip to main content

Module overlay

Module overlay 

Source
Expand description

Overlays in image coordinates, edited through one handle kit.

Experimental: may change in any release (docs/stability.md).

The application owns its overlays (shapes, guides, a crop box) and gives them to the viewport each frame; the viewport draws them and turns drags on their handles into Signal::Handles (begin, update, end, or cancel on Escape), which the application applies to its own data (Overlay::apply does it for the standard shapes). A before_handle hook may veto a move or snap it.

The same handle kinds look and behave the same everywhere: a body (move), points and corners, edges, a size, a rotation, a feather, a Bézier control. Their hit target is HIT_RADIUS points whatever their drawn size. A click on a handle, or on an overlay’s outline away from its handles (to add a point there), is a signal too.

Each overlay has a Style: an emphasis (normal, selected, faint) and a dashed line; shapes are points, lines, boxes, circles, ellipses and paths.

Structs§

Handle
A handle: an index within its overlay, a kind, a place (image pixels).
Overlay
An overlay: a shape with an id, its handles, and whether it is a guide (drawn, never edited).
Style
How an overlay is drawn.

Enums§

Emphasis
How an overlay stands out.
HandleKind
What a handle adjusts.
HandleState
How a handle is drawn.
Shape
A shape in image pixels.

Constants§

DRAWN_RADIUS
The radius a handle is drawn with, in points.
EDGE_RADIUS
How close to an outline a click lands on it, in points.
HIT_RADIUS
The radius of a handle’s hit target, in points (24-point targets).
LINE_WIDTH
A shape’s line, its dark outline under it, a handle’s outline, in points before snapping: each is drawn as whole physical pixels at the window’s scale (scale::stroke), so it never blurs at 125 % or 150 %.
OUTLINE_WIDTH
UNDER_WIDTH

Functions§

hit
The handle under pos (points), topmost overlay first.
hit_edge
The outline under pos (points), topmost overlay first, guides left out: the overlay’s index, the segment (between points i and i + 1 of a path or a line, the box’s top, right, bottom and left edges 0 to 3, 0 for a circle or an ellipse) and the nearest point of it in image pixels.
paint_handle
Draws one handle of the kit at pos (points).
paint_handle_styled
Draws one handle of the kit at pos (points), faint when its overlay is.
paint_label
Draws text as a label over an image, through the kit’s viewport-label component: a translucent pill (its fill, radius, padding-x and padding-y) holding the text in its text colour, at its font-size (the Small text style’s when the kit gives none). anchor says which point of the label sits at at (points): LEFT_BOTTOM puts it above and right of at. An overlay’s label (Overlay::label) is drawn this way; so is a HUD’s readout over an image. Returns the rectangle the label covers.
paint_shape
Draws an overlay’s shape (and its label) through a mapping, in its style.