Skip to content

Drawing

Drawing :: struct {...}
Line_Cap :: enum {...}
Line_Join :: enum {...}
arc :: proc(d: ^Drawing, center: [2]f32, radius, from, to: f32)
circle_path :: proc(d: ^Drawing, center: [2]f32, radius: f32)
clip :: proc(d: ^Drawing, even_odd := false) -> bool
close_path :: proc(d: ^Drawing)
curve_to :: proc(d: ^Drawing, c1, c2, p: [2]f32)
draw :: proc(d: ^Drawing) -> clay.CustomElementConfig
draw_image :: proc(d: ^Drawing, img: Image, pos, size: [2]f32, tint := Color{255, 255, 255, 255})
draw_text :: proc(d: ^Drawing, s: string, pos: [2]f32, style := TextStyle.Body, color: Color)
drawing :: proc(scale: f32 = 1) -> ^Drawing
fill_path :: proc(d: ^Drawing, color: Color, even_odd := false)
line_to :: proc(d: ^Drawing, p: [2]f32)
move_to :: proc(d: ^Drawing, p: [2]f32)
opacity :: proc(d: ^Drawing, alpha: f32) -> bool
quad_to :: proc(d: ^Drawing, c, p: [2]f32)
rect_path :: proc(d: ^Drawing, pos, size: [2]f32, radius: f32 = 0)
render_image :: proc(d: ^Drawing, width, height: int) -> Image
stroke_path :: proc(d: ^Drawing, color: Color, width: f32, cap := Line_Cap.Round, join := Line_Join.Round, miter_limit: f32 = 4)
transform :: proc(d: ^Drawing, translate := [2]f32{}, rotate: f32 = 0, scale := [2]f32{1, 1}) -> bool
Drawing :: struct {
base: f32, // the scale given to `drawing`
path: Path_Builder, // the current path, in pixels; its `m` is the current transform
cur: [2]f32, // the current point, in drawing coordinates
start: [2]f32, // where the current subpath started
ops: [dynamic]Draw_Op,
saved: [dynamic]Mat, // transforms of the enclosing `transform` blocks
groups: int, // open `clip` and `opacity` blocks
}

A drawing being recorded; build it with the procs in this file, not by hand.

FieldTypeNotes
basef32the scale given to drawing
pathPath_Builderthe current path, in pixels; its m is the current transform
cur[2]f32the current point, in drawing coordinates
start[2]f32where the current subpath started
ops[dynamic]Draw_Op
saved[dynamic]Mattransforms of the enclosing transform blocks
groupsintopen clip and opacity blocks

Source: kiln/draw.odin:41

Line_Cap :: enum {
Butt,
Round,
Square,
}

Values: .Butt, .Round, .Square

Source: kiln/draw.odin:28

Line_Join :: enum {
Miter,
Round,
Bevel,
}

Values: .Miter, .Round, .Bevel

Source: kiln/draw.odin:34

arc :: proc(d: ^Drawing, center: [2]f32, radius, from, to: f32)

A circular arc around center from angle from to to. A line connects the current point with the start of the arc; to < from draws counter-clockwise.

ArgumentTypeDefault
d^Drawingrequired
center[2]f32required
radiusf32required
fromf32required
tof32required

Source: kiln/draw.odin:144

circle_path :: proc(d: ^Drawing, center: [2]f32, radius: f32)

A circle as a closed subpath.

ArgumentTypeDefault
d^Drawingrequired
center[2]f32required
radiusf32required

Source: kiln/draw.odin:176

clip :: proc(d: ^Drawing, even_odd := false) -> bool

Cuts off what is drawn inside at the current path (which it uses up):

kiln.circle_path(d, c, r)
if kiln.clip(d) {kiln.draw_image(d, photo, c - r, 2 * r)}
ArgumentTypeDefault
d^Drawingrequired
even_oddboolfalse
ReturnsType
#0bool

Source: kiln/draw.odin:319

close_path :: proc(d: ^Drawing)

Closes the current subpath with a line back to its start.

ArgumentTypeDefault
d^Drawingrequired

Source: kiln/draw.odin:151

curve_to :: proc(d: ^Drawing, c1, c2, p: [2]f32)

A cubic Bézier curve from the current point to p with the control points c1 and c2.

ArgumentTypeDefault
d^Drawingrequired
c1[2]f32required
c2[2]f32required
p[2]f32required

Source: kiln/draw.odin:136

draw :: proc(d: ^Drawing) -> clay.CustomElementConfig

The custom config that makes an element show a drawing: custom = kiln.draw(d).

ArgumentTypeDefault
d^Drawingrequired
ReturnsType
#0clay.CustomElementConfig

Source: kiln/draw.odin:107

draw_image :: proc(d: ^Drawing, img: Image, pos, size: [2]f32, tint := Color{255, 255, 255, 255})

An image stretched over the rectangle at pos with size, its pixels multiplied by tint.

ArgumentTypeDefault
d^Drawingrequired
imgImagerequired
pos[2]f32required
size[2]f32required
tint[4]f32Color{255, 255, 255, 255}

Source: kiln/draw.odin:236

draw_text :: proc(d: ^Drawing, s: string, pos: [2]f32, style := TextStyle.Body, color: Color)

One line of text in a text style, its top left corner at pos. The letters are filled outlines, so they turn and scale with transform. measure gives the width in pixels.

ArgumentTypeDefault
d^Drawingrequired
sstringrequired
pos[2]f32required
styleTextStyleTextStyle.Body
colorColorrequired

Source: kiln/draw.odin:244

drawing :: proc(scale: f32 = 1) -> ^Drawing

A new drawing for this frame. scale turns drawing coordinates into pixels: 1 draws in pixels, scale_factor() in units.

ArgumentTypeDefault
scalef321
ReturnsType
#0^Drawing

Source: kiln/draw.odin:97

fill_path :: proc(d: ^Drawing, color: Color, even_odd := false)

Fills the inside of the current path (open subpaths are closed) and starts a new path. even_odd makes overlapping parts holes, otherwise everything enclosed is filled.

ArgumentTypeDefault
d^Drawingrequired
colorColorrequired
even_oddboolfalse

Source: kiln/draw.odin:205

line_to :: proc(d: ^Drawing, p: [2]f32)

A straight line from the current point to p.

ArgumentTypeDefault
d^Drawingrequired
p[2]f32required

Source: kiln/draw.odin:122

move_to :: proc(d: ^Drawing, p: [2]f32)

Starts a new subpath at p.

ArgumentTypeDefault
d^Drawingrequired
p[2]f32required

Source: kiln/draw.odin:116

opacity :: proc(d: ^Drawing, alpha: f32) -> bool

Draws what is inside on its own and blends it with alpha (0..1), so overlapping parts do not show through each other.

ArgumentTypeDefault
d^Drawingrequired
alphaf32required
ReturnsType
#0bool

Source: kiln/draw.odin:337

quad_to :: proc(d: ^Drawing, c, p: [2]f32)

A quadratic Bézier curve from the current point to p with the control point c.

ArgumentTypeDefault
d^Drawingrequired
c[2]f32required
p[2]f32required

Source: kiln/draw.odin:129

rect_path :: proc(d: ^Drawing, pos, size: [2]f32, radius: f32 = 0)

A rectangle as a closed subpath, with rounded corners if radius > 0.

ArgumentTypeDefault
d^Drawingrequired
pos[2]f32required
size[2]f32required
radiusf320

Source: kiln/draw.odin:157

render_image :: proc(d: ^Drawing, width, height: int) -> Image

Draws a drawing into a new width x height image (pixels), e.g. a picture that is expensive to draw and changes rarely. Free it with destroy_image.

ArgumentTypeDefault
d^Drawingrequired
widthintrequired
heightintrequired
ReturnsType
#0Image

Source: kiln/draw.odin:361

stroke_path :: proc(
d: ^Drawing,
color: Color,
width: f32,
cap := Line_Cap.Round,
join := Line_Join.Round,
miter_limit: f32 = 4,
)

Draws the outline of the current path width wide and starts a new path. A subpath of a single point gives a dot with round or square caps.

ArgumentTypeDefault
d^Drawingrequired
colorColorrequired
widthf32required
capLine_CapLine_Cap.Round
joinLine_JoinLine_Join.Round
miter_limitf324

Source: kiln/draw.odin:215

transform :: proc(d: ^Drawing, translate := [2]f32{}, rotate: f32 = 0, scale := [2]f32{1, 1}) -> bool

Moves, turns and scales what is drawn inside: the origin moves to translate, then the coordinates turn by rotate and are scaled by scale.

if kiln.transform(d, translate = center, rotate = angle) { ... }
ArgumentTypeDefault
d^Drawingrequired
translate[2]f32[2]f32{}
rotatef320
scale[2]f32[2]f32{1, 1}
ReturnsType
#0bool

Source: kiln/draw.odin:300