Foramatting
This commit is contained in:
142
draw/shapes.odin
142
draw/shapes.odin
@@ -324,13 +324,7 @@ triangle_strip :: proc(
|
||||
// ----- SDF drawing functions ----
|
||||
|
||||
// Draw a rectangle with per-corner rounding radii via SDF.
|
||||
rectangle_corners :: proc(
|
||||
layer: ^Layer,
|
||||
rect: Rectangle,
|
||||
radii: [4]f32,
|
||||
color: Color,
|
||||
soft_px: f32 = 1.0,
|
||||
) {
|
||||
rectangle_corners :: proc(layer: ^Layer, rect: Rectangle, radii: [4]f32, color: Color, soft_px: f32 = 1.0) {
|
||||
max_radius := min(rect.w, rect.h) * 0.5
|
||||
tl := clamp(radii[0], 0, max_radius)
|
||||
tr := clamp(radii[1], 0, max_radius)
|
||||
@@ -387,13 +381,7 @@ rectangle_corners_lines :: proc(
|
||||
}
|
||||
|
||||
// Draw a rectangle with uniform corner rounding via SDF.
|
||||
rectangle_rounded :: proc(
|
||||
layer: ^Layer,
|
||||
rect: Rectangle,
|
||||
roundness: f32,
|
||||
color: Color,
|
||||
soft_px: f32 = 1.0,
|
||||
) {
|
||||
rectangle_rounded :: proc(layer: ^Layer, rect: Rectangle, roundness: f32, color: Color, soft_px: f32 = 1.0) {
|
||||
cr := min(rect.w, rect.h) * clamp(roundness, 0, 1) * 0.5
|
||||
if cr < 1 {
|
||||
rectangle(layer, rect, color)
|
||||
@@ -425,12 +413,19 @@ circle :: proc(layer: ^Layer, center: [2]f32, radius: f32, color: Color, soft_px
|
||||
dpi := GLOB.dpi_scaling
|
||||
|
||||
prim := Primitive {
|
||||
bounds = {center.x - radius - pad, center.y - radius - pad,
|
||||
center.x + radius + pad, center.y + radius + pad},
|
||||
bounds = {
|
||||
center.x - radius - pad,
|
||||
center.y - radius - pad,
|
||||
center.x + radius + pad,
|
||||
center.y + radius + pad,
|
||||
},
|
||||
color = color,
|
||||
kind_flags = pack_kind_flags(.Circle, {}),
|
||||
}
|
||||
prim.params.circle = Circle_Params{radius = radius * dpi, soft_px = soft_px}
|
||||
prim.params.circle = Circle_Params {
|
||||
radius = radius * dpi,
|
||||
soft_px = soft_px,
|
||||
}
|
||||
prepare_sdf_primitive(layer, prim)
|
||||
}
|
||||
|
||||
@@ -447,35 +442,42 @@ circle_lines :: proc(
|
||||
dpi := GLOB.dpi_scaling
|
||||
|
||||
prim := Primitive {
|
||||
bounds = {center.x - radius - pad, center.y - radius - pad,
|
||||
center.x + radius + pad, center.y + radius + pad},
|
||||
bounds = {
|
||||
center.x - radius - pad,
|
||||
center.y - radius - pad,
|
||||
center.x + radius + pad,
|
||||
center.y + radius + pad,
|
||||
},
|
||||
color = color,
|
||||
kind_flags = pack_kind_flags(.Circle, {.Stroke}),
|
||||
}
|
||||
prim.params.circle = Circle_Params{
|
||||
radius = radius * dpi, soft_px = soft_px, stroke_px = thick * dpi,
|
||||
prim.params.circle = Circle_Params {
|
||||
radius = radius * dpi,
|
||||
soft_px = soft_px,
|
||||
stroke_px = thick * dpi,
|
||||
}
|
||||
prepare_sdf_primitive(layer, prim)
|
||||
}
|
||||
|
||||
// Draw a filled ellipse via SDF.
|
||||
ellipse :: proc(
|
||||
layer: ^Layer,
|
||||
center: [2]f32,
|
||||
radius_h, radius_v: f32,
|
||||
color: Color,
|
||||
soft_px: f32 = 1.0,
|
||||
) {
|
||||
ellipse :: proc(layer: ^Layer, center: [2]f32, radius_h, radius_v: f32, color: Color, soft_px: f32 = 1.0) {
|
||||
pad := soft_px / GLOB.dpi_scaling
|
||||
dpi := GLOB.dpi_scaling
|
||||
|
||||
prim := Primitive {
|
||||
bounds = {center.x - radius_h - pad, center.y - radius_v - pad,
|
||||
center.x + radius_h + pad, center.y + radius_v + pad},
|
||||
bounds = {
|
||||
center.x - radius_h - pad,
|
||||
center.y - radius_v - pad,
|
||||
center.x + radius_h + pad,
|
||||
center.y + radius_v + pad,
|
||||
},
|
||||
color = color,
|
||||
kind_flags = pack_kind_flags(.Ellipse, {}),
|
||||
}
|
||||
prim.params.ellipse = Ellipse_Params{radii = {radius_h * dpi, radius_v * dpi}, soft_px = soft_px}
|
||||
prim.params.ellipse = Ellipse_Params {
|
||||
radii = {radius_h * dpi, radius_v * dpi},
|
||||
soft_px = soft_px,
|
||||
}
|
||||
prepare_sdf_primitive(layer, prim)
|
||||
}
|
||||
|
||||
@@ -494,13 +496,19 @@ ellipse_lines :: proc(
|
||||
dpi := GLOB.dpi_scaling
|
||||
|
||||
prim := Primitive {
|
||||
bounds = {center.x - radius_h - pad, center.y - radius_v - pad,
|
||||
center.x + radius_h + pad, center.y + radius_v + pad},
|
||||
bounds = {
|
||||
center.x - radius_h - pad,
|
||||
center.y - radius_v - pad,
|
||||
center.x + radius_h + pad,
|
||||
center.y + radius_v + pad,
|
||||
},
|
||||
color = color,
|
||||
kind_flags = pack_kind_flags(.Ellipse, {.Stroke}),
|
||||
}
|
||||
prim.params.ellipse = Ellipse_Params{
|
||||
radii = {radius_h * dpi, radius_v * dpi}, soft_px = soft_px, stroke_px = thick * dpi,
|
||||
prim.params.ellipse = Ellipse_Params {
|
||||
radii = {radius_h * dpi, radius_v * dpi},
|
||||
soft_px = soft_px,
|
||||
stroke_px = thick * dpi,
|
||||
}
|
||||
prepare_sdf_primitive(layer, prim)
|
||||
}
|
||||
@@ -518,8 +526,12 @@ ring :: proc(
|
||||
dpi := GLOB.dpi_scaling
|
||||
|
||||
prim := Primitive {
|
||||
bounds = {center.x - outer_radius - pad, center.y - outer_radius - pad,
|
||||
center.x + outer_radius + pad, center.y + outer_radius + pad},
|
||||
bounds = {
|
||||
center.x - outer_radius - pad,
|
||||
center.y - outer_radius - pad,
|
||||
center.x + outer_radius + pad,
|
||||
center.y + outer_radius + pad,
|
||||
},
|
||||
color = color,
|
||||
kind_flags = pack_kind_flags(.Ring_Arc, {}),
|
||||
}
|
||||
@@ -544,11 +556,27 @@ ring_lines :: proc(
|
||||
soft_px: f32 = 1.0,
|
||||
) {
|
||||
// Inner arc outline
|
||||
ring(layer, center, max(0, inner_radius - thick * 0.5), inner_radius + thick * 0.5,
|
||||
start_angle, end_angle, color, soft_px)
|
||||
ring(
|
||||
layer,
|
||||
center,
|
||||
max(0, inner_radius - thick * 0.5),
|
||||
inner_radius + thick * 0.5,
|
||||
start_angle,
|
||||
end_angle,
|
||||
color,
|
||||
soft_px,
|
||||
)
|
||||
// Outer arc outline
|
||||
ring(layer, center, max(0, outer_radius - thick * 0.5), outer_radius + thick * 0.5,
|
||||
start_angle, end_angle, color, soft_px)
|
||||
ring(
|
||||
layer,
|
||||
center,
|
||||
max(0, outer_radius - thick * 0.5),
|
||||
outer_radius + thick * 0.5,
|
||||
start_angle,
|
||||
end_angle,
|
||||
color,
|
||||
soft_px,
|
||||
)
|
||||
// Start cap
|
||||
start_rad := math.to_radians(start_angle)
|
||||
end_rad := math.to_radians(end_angle)
|
||||
@@ -562,13 +590,7 @@ ring_lines :: proc(
|
||||
}
|
||||
|
||||
// Draw a line segment via SDF.
|
||||
line :: proc(
|
||||
layer: ^Layer,
|
||||
start, end_pos: [2]f32,
|
||||
color: Color,
|
||||
thick: f32 = 1,
|
||||
soft_px: f32 = 1.0,
|
||||
) {
|
||||
line :: proc(layer: ^Layer, start, end_pos: [2]f32, color: Color, thick: f32 = 1, soft_px: f32 = 1.0) {
|
||||
cap := thick * 0.5 + soft_px / GLOB.dpi_scaling
|
||||
min_x := min(start.x, end_pos.x) - cap
|
||||
max_x := max(start.x, end_pos.x) + cap
|
||||
@@ -595,13 +617,7 @@ line :: proc(
|
||||
}
|
||||
|
||||
// Draw a line strip via decomposed SDF segments.
|
||||
line_strip :: proc(
|
||||
layer: ^Layer,
|
||||
points: [][2]f32,
|
||||
color: Color,
|
||||
thick: f32 = 1,
|
||||
soft_px: f32 = 1.0,
|
||||
) {
|
||||
line_strip :: proc(layer: ^Layer, points: [][2]f32, color: Color, thick: f32 = 1, soft_px: f32 = 1.0) {
|
||||
if len(points) < 2 do return
|
||||
for i in 0 ..< len(points) - 1 {
|
||||
line(layer, points[i], points[i + 1], color, thick, soft_px)
|
||||
@@ -623,8 +639,12 @@ poly :: proc(
|
||||
dpi := GLOB.dpi_scaling
|
||||
|
||||
prim := Primitive {
|
||||
bounds = {center.x - radius - pad, center.y - radius - pad,
|
||||
center.x + radius + pad, center.y + radius + pad},
|
||||
bounds = {
|
||||
center.x - radius - pad,
|
||||
center.y - radius - pad,
|
||||
center.x + radius + pad,
|
||||
center.y + radius + pad,
|
||||
},
|
||||
color = color,
|
||||
kind_flags = pack_kind_flags(.NGon, {}),
|
||||
}
|
||||
@@ -653,8 +673,12 @@ poly_lines :: proc(
|
||||
dpi := GLOB.dpi_scaling
|
||||
|
||||
prim := Primitive {
|
||||
bounds = {center.x - radius - pad, center.y - radius - pad,
|
||||
center.x + radius + pad, center.y + radius + pad},
|
||||
bounds = {
|
||||
center.x - radius - pad,
|
||||
center.y - radius - pad,
|
||||
center.x + radius + pad,
|
||||
center.y + radius + pad,
|
||||
},
|
||||
color = color,
|
||||
kind_flags = pack_kind_flags(.NGon, {.Stroke}),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user