Skip to content

Commit

Permalink
ui: Add script to bake ui elements
Browse files Browse the repository at this point in the history
  • Loading branch information
mborgerson committed Jan 3, 2025
1 parent 42e83d0 commit 8c42c8f
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions data/gen_ui_atlas.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -e

# Rasterize svg objects
SVGS="ports.svg duke.svg xmu.svg"
PNGS=""
for image in $SVGS; do
for obj in $(inkscape --query-all $image | grep -oP "obj_\w+"); do
outfile=${obj}.png
inkscape --export-id-only --export-id=$obj --export-filename=$outfile $image
PNGS="$PNGS $outfile"
done
done

# Build texture atlas
# pip install https://github.com/mborgerson/textureatlas/archive/refs/heads/master.zip
python -m textureatlas -o ui_objs.png -m ui_objs.json -mf=json $PNGS

# Build accessory structs
python <<EOF >ui_objs.h
import json
with open("ui_objs.json", "r", encoding="utf-8") as file:
atlas = json.load(file)
print("const struct { int x, y, w, h; } ui_objs[] = {")
names = []
for name, frames in atlas.items():
for x, y, w, h in frames:
print(" {%4d, %4d, %4d, %4d}, // %s" % (x, y, w, h, name))
names.append(name)
print("};")
print("enum ui_objs_idx {")
for idx, name in enumerate(names):
print(f" ui_{name}_idx = {idx},")
print("};")
EOF

0 comments on commit 8c42c8f

Please sign in to comment.