Skip to content

@fabwcie/free-drawing / utils/grid

utils/grid ​

Functions ​

drawGrid() ​

drawGrid(ctx, shape, area, scale, style): void

Defined in: packages/free-drawing/src/utils/grid.ts:99

Draw the grid in an area: squares of dashed lines (one stroke per line: browsers draw the dashes of a straight line faster than those of a path of many lines), dots at their crossings, horizontal lines of ruled paper, or triangles of isometric paper (vertical and 30 degrees lines)

Parameters

ctx

Context

Context of the shape drawing the grid

shape

Shape

Shape drawing the grid (stroke or fill of gridShapeStyle)

area

IRect

Area to fill, in drawing coordinates (view)

scale

number

Zoom level

style

GridStyle

Style of the grid

Returns

void


gridRotationSnaps() ​

gridRotationSnaps(style): number[]

Defined in: packages/free-drawing/src/utils/grid.ts:83

Angles a selection snaps to while it is rotated with the grid shown

Parameters

style

GridStyle

Style of the grid

Returns

number[]

Every 30 degrees for the isometric grid, else every 90 degrees


gridShapeStyle() ​

gridShapeStyle(style): ShapeConfig

Defined in: packages/free-drawing/src/utils/grid.ts:28

Style of the shape drawing the grid

Parameters

style

GridStyle

Style of the grid

Returns

ShapeConfig

Attributes of the konva shape: dashed lines of squares, solid ones of paper, filled dots


gridStep() ​

gridStep(scale): number

Defined in: packages/free-drawing/src/utils/grid.ts:41

Space between the lines drawn at a zoom: gridSize, doubled while they would be too near on screen (the lines drawn are lines of the grid: shapes snap to all of them)

Parameters

scale

number

Zoom level

Returns

number

Space between the lines drawn, in drawing units


snapToGrid() ​

snapToGrid(point, style): Vector2d

Defined in: packages/free-drawing/src/utils/grid.ts:56

Point of the grid nearest to a point: crossing of lines (squares, dots), height of a line (lines: x kept), corner of the triangles (isometric)

Parameters

point

Vector2d

Point, in drawing coordinates

style

GridStyle

Style of the grid

Returns

Vector2d

Point snapped to the grid