mirror of
https://github.com/xemu-project/xemu.git
synced 2025-01-30 08:32:08 +00:00
ui: Add script to bake ui elements
This commit is contained in:
parent
42e83d0ccc
commit
8c42c8fae3
35
data/gen_ui_atlas.sh
Executable file
35
data/gen_ui_atlas.sh
Executable file
@ -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
|
Loading…
x
Reference in New Issue
Block a user