Backdrop Path + Cybersteel (#23)

Co-authored-by: Zachary Levy <zachary@sunforge.is>
Reviewed-on: #23
This commit was merged in pull request #23.
This commit is contained in:
2026-05-01 05:43:10 +00:00
parent e36229a3ef
commit 5317b8f142
66 changed files with 5806 additions and 2427 deletions
+26 -33
View File
@@ -1,14 +1,15 @@
package examples
import "../../draw"
import "../../draw/tess"
import "../../vendor/clay"
import "core:math"
import "core:os"
import sdl "vendor:sdl3"
JETBRAINS_MONO_REGULAR_RAW :: #load("fonts/JetBrainsMono-Regular.ttf")
JETBRAINS_MONO_REGULAR: draw.Font_Id = max(draw.Font_Id) // Max so we crash if registration is forgotten
import "../../draw"
import "../../draw/tess"
import "../../vendor/clay"
import cyber "../cybersteel"
PLEX_SANS_REGULAR: draw.Font_Id = max(draw.Font_Id) // Max so we crash if registration is forgotten
hellope_shapes :: proc() {
if !sdl.Init({.VIDEO}) do os.exit(1)
@@ -47,8 +48,7 @@ hellope_shapes :: proc() {
draw.rectangle(
base_layer,
{20, 160, 460, 60},
{255, 0, 0, 255},
gradient = draw.Linear_Gradient{end_color = {0, 0, 255, 255}, angle = 0},
draw.Linear_Gradient{start_color = {255, 0, 0, 255}, end_color = {0, 0, 255, 255}, angle = 0},
)
// ----- Rotation demos -----
@@ -78,18 +78,18 @@ hellope_shapes :: proc() {
)
// Ellipse rotating around its center (tilted ellipse)
draw.ellipse(base_layer, {410, 340}, 50, 30, {255, 200, 50, 255}, rotation = spin_angle)
draw.ellipse(base_layer, {410, 340}, 50, 30, draw.Color{255, 200, 50, 255}, rotation = spin_angle)
// Circle orbiting a point (moon orbiting planet)
// Convention B: center = pivot point (planet), origin = offset from moon center to pivot.
// Moon's visual center at rotation=0: planet_pos - origin = (100, 450) - (0, 40) = (100, 410).
planet_pos := draw.Vec2{100, 450}
draw.circle(base_layer, planet_pos, 8, {200, 200, 200, 255}) // planet (stationary)
draw.circle(base_layer, planet_pos, 8, draw.Color{200, 200, 200, 255}) // planet (stationary)
draw.circle(
base_layer,
planet_pos,
5,
{100, 150, 255, 255},
draw.Color{100, 150, 255, 255},
origin = draw.Vec2{0, 40},
rotation = spin_angle,
) // moon orbiting
@@ -100,7 +100,7 @@ hellope_shapes :: proc() {
draw.Vec2{250, 450},
0,
30,
{100, 100, 220, 255},
draw.Color{100, 100, 220, 255},
start_angle = 0,
end_angle = 270,
rotation = spin_angle,
@@ -126,7 +126,7 @@ hellope_shapes :: proc() {
{460, 450},
6,
30,
{180, 100, 220, 255},
draw.Color{180, 100, 220, 255},
outline_color = draw.WHITE,
outline_width = 2,
rotation = spin_angle,
@@ -147,7 +147,7 @@ hellope_text :: proc() {
gpu := sdl.CreateGPUDevice(draw.PLATFORM_SHADER_FORMAT, true, nil)
if !sdl.ClaimWindowForGPUDevice(gpu, window) do os.exit(1)
if !draw.init(gpu, window) do os.exit(1)
JETBRAINS_MONO_REGULAR = draw.register_font(JETBRAINS_MONO_REGULAR_RAW)
PLEX_SANS_REGULAR = draw.register_font(cyber.SANS_REGULAR_RAW)
FONT_SIZE :: u16(24)
spin_angle: f32 = 0
@@ -168,10 +168,10 @@ hellope_text :: proc() {
base_layer,
"Hellope!",
{300, 80},
JETBRAINS_MONO_REGULAR,
PLEX_SANS_REGULAR,
FONT_SIZE,
color = draw.WHITE,
origin = draw.center_of("Hellope!", JETBRAINS_MONO_REGULAR, FONT_SIZE),
origin = draw.center_of("Hellope!", PLEX_SANS_REGULAR, FONT_SIZE),
id = HELLOPE_ID,
)
@@ -180,35 +180,28 @@ hellope_text :: proc() {
base_layer,
"Hellope World!",
{300, 250},
JETBRAINS_MONO_REGULAR,
PLEX_SANS_REGULAR,
FONT_SIZE,
color = {255, 200, 50, 255},
origin = draw.center_of("Hellope World!", JETBRAINS_MONO_REGULAR, FONT_SIZE),
origin = draw.center_of("Hellope World!", PLEX_SANS_REGULAR, FONT_SIZE),
rotation = spin_angle,
id = ROTATING_SENTENCE_ID,
)
// Uncached text (no id) — created and destroyed each frame, simplest usage
draw.text(
base_layer,
"Top-left anchored",
{20, 450},
JETBRAINS_MONO_REGULAR,
FONT_SIZE,
color = draw.WHITE,
)
draw.text(base_layer, "Top-left anchored", {20, 450}, PLEX_SANS_REGULAR, FONT_SIZE, color = draw.WHITE)
// Measure text for manual layout
size := draw.measure_text("Measured!", JETBRAINS_MONO_REGULAR, FONT_SIZE)
size := draw.measure_text("Measured!", PLEX_SANS_REGULAR, FONT_SIZE)
draw.rectangle(base_layer, {300 - size.x / 2, 380, size.x, size.y}, draw.Color{60, 60, 60, 200})
draw.text(
base_layer,
"Measured!",
{300, 380},
JETBRAINS_MONO_REGULAR,
PLEX_SANS_REGULAR,
FONT_SIZE,
color = draw.WHITE,
origin = draw.top_of("Measured!", JETBRAINS_MONO_REGULAR, FONT_SIZE),
origin = draw.top_of("Measured!", PLEX_SANS_REGULAR, FONT_SIZE),
id = MEASURED_ID,
)
@@ -217,7 +210,7 @@ hellope_text :: proc() {
base_layer,
"Corner spin",
{150, 530},
JETBRAINS_MONO_REGULAR,
PLEX_SANS_REGULAR,
FONT_SIZE,
color = {100, 200, 255, 255},
rotation = spin_angle,
@@ -234,10 +227,10 @@ hellope_clay :: proc() {
gpu := sdl.CreateGPUDevice(draw.PLATFORM_SHADER_FORMAT, true, nil)
if !sdl.ClaimWindowForGPUDevice(gpu, window) do os.exit(1)
if !draw.init(gpu, window) do os.exit(1)
JETBRAINS_MONO_REGULAR = draw.register_font(JETBRAINS_MONO_REGULAR_RAW)
PLEX_SANS_REGULAR = draw.register_font(cyber.SANS_REGULAR_RAW)
text_config := clay.TextElementConfig {
fontId = JETBRAINS_MONO_REGULAR,
fontId = PLEX_SANS_REGULAR,
fontSize = 36,
textColor = {255, 255, 255, 255},
}
@@ -278,10 +271,10 @@ hellope_custom :: proc() {
gpu := sdl.CreateGPUDevice(draw.PLATFORM_SHADER_FORMAT, true, nil)
if !sdl.ClaimWindowForGPUDevice(gpu, window) do os.exit(1)
if !draw.init(gpu, window) do os.exit(1)
JETBRAINS_MONO_REGULAR = draw.register_font(JETBRAINS_MONO_REGULAR_RAW)
PLEX_SANS_REGULAR = draw.register_font(cyber.SANS_REGULAR_RAW)
text_config := clay.TextElementConfig {
fontId = JETBRAINS_MONO_REGULAR,
fontId = PLEX_SANS_REGULAR,
fontSize = 24,
textColor = {255, 255, 255, 255},
}