Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a62f78849 | ||
|
|
865bd70f9c |
+22
-90
@@ -22,6 +22,8 @@ concurrency:
|
||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
jobs:
|
||||
# The x86-64 machines run with hardware virtualization, and also
|
||||
# cross-compile the arm64 programs here, for the arm64 machines below to run.
|
||||
# OpenBSD's base compiler has no arm64 backend, so it uses the ports LLVM.
|
||||
bsd:
|
||||
name: ${{ matrix.os }} ${{ matrix.version }} ${{ matrix.arch }}
|
||||
@@ -52,13 +54,13 @@ jobs:
|
||||
.ccache
|
||||
build
|
||||
build-arm64
|
||||
key: build-v3-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-${{ github.run_id }}
|
||||
restore-keys: build-v3-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-
|
||||
key: build-v2-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-${{ github.run_id }}
|
||||
restore-keys: build-v2-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-
|
||||
|
||||
- name: Build a release from scratch, keeping only ccache
|
||||
if: ${{ inputs.version != '' }}
|
||||
shell: bash
|
||||
run: rm -rf build build-arm64 build-arm64-shared
|
||||
run: rm -rf build build-arm64
|
||||
|
||||
# ninja rebuilds by mtime, and a checkout dates every file now. Date them
|
||||
# before the cached objects instead, and only what changed since the
|
||||
@@ -82,6 +84,7 @@ jobs:
|
||||
echo "no cached build to diff against; every source is new"
|
||||
fi
|
||||
|
||||
# The packages the machine downloads, kept so the next run installs without fetching them.
|
||||
- name: Restore the package cache
|
||||
id: pkgcache
|
||||
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
||||
@@ -189,22 +192,11 @@ jobs:
|
||||
if grep -rq "$sysroot" "dist/$name/lib/cmake" "dist/$name/lib/pkgconfig"; then
|
||||
echo "the package carries the sysroot's path"; exit 1
|
||||
fi
|
||||
cmake -S . -B build-arm64-shared -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_TOOLCHAIN_FILE="$PWD/tools/cross/${{ matrix.os }}-aarch64.cmake" \
|
||||
-DREAKTOR_SYSROOT="$sysroot" -DREAKTOR_SHARED=ON \
|
||||
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
|
||||
-DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON </dev/null
|
||||
cmake --build build-arm64-shared --parallel 4 --target libreaktor </dev/null
|
||||
shared="libreaktor-shared-${version}-${{ matrix.os }}-arm64"
|
||||
cmake --install build-arm64-shared --prefix "dist/$shared" --component libreaktor --strip </dev/null
|
||||
file -L "dist/$shared/lib/libreaktor.so.1" | grep -qi aarch64
|
||||
if grep -rq "$sysroot" "dist/$shared/lib/cmake" "dist/$shared/lib/pkgconfig"; then
|
||||
echo "the shared package carries the sysroot's path"; exit 1
|
||||
fi
|
||||
tar -cf cross-${{ matrix.os }}-arm64.tar \
|
||||
$(sed 's|^|build-arm64/|' tools/ci/tests.txt) \
|
||||
build-arm64/onlaytest build-arm64/keytest build-arm64/a11ytest build-arm64/animtest \
|
||||
build-arm64/localetest build-arm64/laytest build-arm64/texttest build-arm64/csstest \
|
||||
build-arm64/showcase build-arm64/notepad build-arm64/simple build-arm64/bench \
|
||||
build-arm64/licenses build-arm64/CMakeCache.txt "dist/$name" "dist/$shared"
|
||||
build-arm64/licenses build-arm64/CMakeCache.txt "dist/$name"
|
||||
|
||||
# Back to the runner now, so the next run finds this build in the cache
|
||||
# while this one is still testing.
|
||||
@@ -218,7 +210,7 @@ jobs:
|
||||
- name: Drop an unfinished cross build
|
||||
if: ${{ always() && steps.cross.outcome == 'failure' }}
|
||||
shell: bash
|
||||
run: rm -rf build-arm64 build-arm64-shared
|
||||
run: rm -rf build-arm64
|
||||
|
||||
- name: Note which commit the cached build is from
|
||||
if: ${{ always() && steps.build.outcome == 'success' }}
|
||||
@@ -233,7 +225,7 @@ jobs:
|
||||
.ccache
|
||||
build
|
||||
build-arm64
|
||||
key: build-v3-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-${{ github.run_id }}
|
||||
key: build-v2-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-${{ github.run_id }}
|
||||
|
||||
- name: Save the package cache
|
||||
if: ${{ always() && steps.vm.outcome == 'success' }}
|
||||
@@ -254,13 +246,10 @@ jobs:
|
||||
- name: Console tests
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||
run: |
|
||||
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
|
||||
export PATH
|
||||
fail=0
|
||||
for t in $(cat tools/ci/tests.txt); do
|
||||
for t in onlaytest keytest a11ytest animtest localetest laytest texttest csstest; do
|
||||
echo "== $t"
|
||||
a=; [ "$t" = gibustest ] && a=--require-bus
|
||||
if ./build/$t $a </dev/null; then :; else echo "$t: exit status $?"; fail=1; fi
|
||||
if ./build/$t </dev/null; then :; else echo "$t: exit status $?"; fail=1; fi
|
||||
done
|
||||
exit "$fail"
|
||||
|
||||
@@ -328,32 +317,6 @@ jobs:
|
||||
--shot check/lib-packaged.bmp --a11y-dump check/lib-packaged.txt </dev/null
|
||||
for e in bmp txt; do cmp "check/lib-built.$e" "check/lib-packaged.$e"; done
|
||||
|
||||
- name: Pack and check the shared libreaktor packages
|
||||
id: shared
|
||||
if: ${{ !cancelled() && steps.libcheck.outcome == 'success' }}
|
||||
run: |
|
||||
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
|
||||
export PATH
|
||||
case ${{ matrix.os }} in
|
||||
freebsd) remove() { sudo pkg delete -y "$@"; } ;;
|
||||
*) remove() { sudo pkg_delete "$@"; } ;;
|
||||
esac
|
||||
remove libreaktor </dev/null
|
||||
rm -rf build-pkg
|
||||
sh tools/libreaktor-pkg.sh -s -i -o dist-pkg-shared </dev/null
|
||||
cmake -S examples/consumer -B build-pkg-shared -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_PREFIX_PATH=/usr/local/reaktor -DCONSUMER_SHARED=ON </dev/null
|
||||
cmake --build build-pkg-shared </dev/null
|
||||
remove libreaktor-shared </dev/null
|
||||
dbus-run-session -- build-pkg-shared/simple --theme light --video dummy \
|
||||
--shot check/lib-packaged-shared.bmp --a11y-dump check/lib-packaged-shared.txt </dev/null
|
||||
for e in bmp txt; do cmp "check/lib-built.$e" "check/lib-packaged-shared.$e"; done
|
||||
version='${{ inputs.version || 'dev' }}'
|
||||
name="libreaktor-shared-${version}-${{ matrix.os }}-${{ matrix.arch }}"
|
||||
cmake --install build-pkg/build --prefix "dist/$name" --component libreaktor --strip </dev/null
|
||||
tar -C dist -czf "dist/$name.tar.gz" "$name"
|
||||
rm -rf "dist/$name"
|
||||
|
||||
- name: Collect the shots
|
||||
if: ${{ always() && steps.vm.outcome == 'success' }}
|
||||
shell: cpa.sh {0} --sync-files vm-to-runner
|
||||
@@ -377,19 +340,7 @@ jobs:
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-libreaktor-${{ matrix.os }}-${{ matrix.arch }}
|
||||
path: |
|
||||
dist/libreaktor-*.tar.gz
|
||||
!dist/libreaktor-shared-*.tar.gz
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
- name: Upload the shared libreaktor
|
||||
if: ${{ !cancelled() && steps.shared.outcome == 'success' }}
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-libreaktor-shared-${{ matrix.os }}-${{ matrix.arch }}
|
||||
path: |
|
||||
dist/libreaktor-shared-*.tar.gz
|
||||
path: dist/libreaktor-*.tar.gz
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
@@ -402,6 +353,9 @@ jobs:
|
||||
if-no-files-found: warn
|
||||
retention-days: 14
|
||||
|
||||
# The arm64 programs built above, run on an arm64 machine: the tests, the
|
||||
# shots, the package, and a program linked against libreaktor with the
|
||||
# machine's own compiler. Nothing is compiled from the tree here.
|
||||
bsd-arm64:
|
||||
name: ${{ matrix.os }} ${{ matrix.version }} arm64
|
||||
needs: bsd
|
||||
@@ -431,6 +385,7 @@ jobs:
|
||||
with:
|
||||
name: cross-${{ matrix.os }}-arm64
|
||||
|
||||
# Unpacked on the runner, before the machine reads the tree.
|
||||
- name: Unpack the arm64 build
|
||||
shell: bash
|
||||
run: |
|
||||
@@ -439,6 +394,7 @@ jobs:
|
||||
chmod +x build-arm64/*
|
||||
ls -l build-arm64 dist
|
||||
|
||||
# The packages the machine downloads, kept so the next run installs without fetching them.
|
||||
- name: Restore the package cache
|
||||
id: pkgcache
|
||||
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
||||
@@ -505,13 +461,10 @@ jobs:
|
||||
- name: Console tests
|
||||
id: tests
|
||||
run: |
|
||||
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
|
||||
export PATH
|
||||
fail=0
|
||||
for t in $(cat tools/ci/tests.txt); do
|
||||
for t in onlaytest keytest a11ytest animtest localetest laytest texttest csstest; do
|
||||
echo "== $t"
|
||||
a=; [ "$t" = gibustest ] && a=--require-bus
|
||||
if ./build-arm64/$t $a </dev/null; then :; else echo "$t: exit status $?"; fail=1; fi
|
||||
if ./build-arm64/$t </dev/null; then :; else echo "$t: exit status $?"; fail=1; fi
|
||||
done
|
||||
exit "$fail"
|
||||
|
||||
@@ -545,15 +498,6 @@ jobs:
|
||||
version='${{ inputs.version || 'dev' }}'
|
||||
sh tools/ci/check-libreaktor.sh -i -w "dbus-run-session --" build-arm64 "libreaktor-${version}-${{ matrix.os }}-arm64"
|
||||
|
||||
- name: Check the shared libreaktor
|
||||
id: shared
|
||||
if: ${{ !cancelled() && steps.libcheck.outcome == 'success' }}
|
||||
run: |
|
||||
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
|
||||
export PATH
|
||||
version='${{ inputs.version || 'dev' }}'
|
||||
sh tools/ci/check-libreaktor.sh -i -w "dbus-run-session --" build-arm64 "libreaktor-shared-${version}-${{ matrix.os }}-arm64"
|
||||
|
||||
- name: Collect the shots
|
||||
if: ${{ always() && steps.vm.outcome == 'success' }}
|
||||
shell: cpa.sh {0} --sync-files vm-to-runner
|
||||
@@ -575,19 +519,7 @@ jobs:
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-libreaktor-${{ matrix.os }}-arm64
|
||||
path: |
|
||||
dist/libreaktor-*.tar.gz
|
||||
!dist/libreaktor-shared-*.tar.gz
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
- name: Upload the shared libreaktor
|
||||
if: ${{ !cancelled() && steps.shared.outcome == 'success' }}
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-libreaktor-shared-${{ matrix.os }}-arm64
|
||||
path: |
|
||||
dist/libreaktor-shared-*.tar.gz
|
||||
path: dist/libreaktor-*.tar.gz
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
|
||||
+9
-120
@@ -64,7 +64,7 @@ jobs:
|
||||
libx11-dev libxext-dev libxcursor-dev libxi-dev libxfixes-dev \
|
||||
libxrandr-dev libxrender-dev libxtst-dev libxkbcommon-dev \
|
||||
libwayland-dev wayland-protocols libegl-dev libdbus-1-dev \
|
||||
dbus xvfb xauth ccache gdb </dev/null
|
||||
dbus xvfb xauth ccache </dev/null
|
||||
EOF
|
||||
|
||||
# ccache only: the build folder is rebuilt, so a stale cache cannot hide a broken one.
|
||||
@@ -76,6 +76,9 @@ jobs:
|
||||
key: ccache-linux-${{ matrix.arch }}-${{ matrix.image }}-${{ github.run_id }}
|
||||
restore-keys: ccache-linux-${{ matrix.arch }}-${{ matrix.image }}-
|
||||
|
||||
# The emulated architectures are compiled by a native x86-64 Debian with
|
||||
# Debian's cross compilers, in the same checkout; the emulated machine
|
||||
# then only runs what was built.
|
||||
- name: Start the cross builder
|
||||
if: ${{ matrix.emulated }}
|
||||
run: |
|
||||
@@ -128,10 +131,9 @@ jobs:
|
||||
run: |
|
||||
docker exec -i debian sh -u <<'EOF'
|
||||
fail=0
|
||||
for t in $(cat tools/ci/tests.txt); do
|
||||
for t in onlaytest keytest a11ytest animtest localetest laytest texttest csstest; do
|
||||
echo "== $t"
|
||||
a=; [ "$t" = gibustest ] && a=--require-bus
|
||||
if ./build/$t $a </dev/null; then :; else echo "$t: exit status $?"; fail=1; fi
|
||||
if ./build/$t </dev/null; then :; else echo "$t: exit status $?"; fail=1; fi
|
||||
done
|
||||
exit "$fail"
|
||||
EOF
|
||||
@@ -149,70 +151,6 @@ jobs:
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' && matrix.arch == 'x86-64' }}
|
||||
run: docker exec -i debian sh tools/ci/uitest.sh -w "dbus-run-session -- timeout 120" build </dev/null
|
||||
|
||||
- name: What a shared libreaktor would save
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' && matrix.arch == 'x86-64' }}
|
||||
continue-on-error: true
|
||||
run: docker exec -i debian sh tools/ci/pss.sh -x Xvfb -w "dbus-run-session -- timeout 120" build </dev/null
|
||||
|
||||
- name: What a shared libreaktor would save, page by page
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' && matrix.arch == 'x86-64' }}
|
||||
continue-on-error: true
|
||||
run: docker exec -i debian sh tools/ci/pss-pages.sh -x Xvfb -w "dbus-run-session -- timeout 120" </dev/null
|
||||
|
||||
- name: Shared libreaktor
|
||||
id: shared
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||
run: |
|
||||
ctr=debian
|
||||
cross=""
|
||||
if [ "${{ matrix.emulated }}" = true ]; then
|
||||
ctr=builder
|
||||
cross="-DCMAKE_TOOLCHAIN_FILE=/src/tools/cross/linux-cross.cmake -DREAKTOR_CROSS_TRIPLE=${{ matrix.triple }}"
|
||||
fi
|
||||
version='${{ inputs.version || 'dev' }}'
|
||||
name="libreaktor-shared-${version}-linux-${{ matrix.arch }}"
|
||||
docker exec -i -e CROSS="$cross" -e LIBNAME="$name" "$ctr" sh -eu <<'EOF'
|
||||
export CCACHE_DIR=/src/.ccache CCACHE_BASEDIR=/src CCACHE_MAXSIZE=500M
|
||||
cmake -S . -B build-shared -G Ninja -DCMAKE_BUILD_TYPE=Release -DREAKTOR_SHARED=ON \
|
||||
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
|
||||
-DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON $CROSS </dev/null
|
||||
cmake --build build-shared --target all libreaktor </dev/null
|
||||
if [ -n "$CROSS" ]; then
|
||||
cmake --install build-shared --prefix "dist/$LIBNAME" --component libreaktor --strip </dev/null
|
||||
else
|
||||
sh tools/ci/check-exports.sh build-shared </dev/null
|
||||
fi
|
||||
EOF
|
||||
installed=""
|
||||
if [ "${{ matrix.emulated }}" = true ]; then installed=-i; fi
|
||||
docker exec -i debian sh -eu tools/ci/check-libreaktor.sh $installed -w "timeout 600" build-shared "$name" </dev/null
|
||||
|
||||
- name: Upload the shared libreaktor
|
||||
if: ${{ !cancelled() && steps.shared.outcome == 'success' }}
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-libreaktor-shared-linux-${{ matrix.arch }}
|
||||
path: |
|
||||
dist/libreaktor-shared-*.tar.gz
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
- name: ABI table
|
||||
id: abi
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' && !matrix.emulated }}
|
||||
run: |
|
||||
rc=0
|
||||
docker exec -i debian sh tools/ci/check-abi.sh </dev/null || rc=$?
|
||||
if [ "$rc" = 3 ]; then echo "::warning::no ABI table for linux ${{ matrix.arch }} yet; see the abi artifact"; rc=0; fi
|
||||
exit "$rc"
|
||||
|
||||
- name: Upload the ABI table
|
||||
if: ${{ !cancelled() && hashFiles('smoke/abi/*.abi') != '' }}
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: abi-linux-${{ matrix.arch }}
|
||||
path: smoke/abi/
|
||||
|
||||
- name: Package
|
||||
id: package
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||
@@ -262,7 +200,7 @@ jobs:
|
||||
run: |
|
||||
docker exec -i debian sh -eu <<'EOF'
|
||||
dpkg -i dist-pkg/*.deb </dev/null
|
||||
dpkg -s libreaktor | grep -q '^Status: install ok installed'
|
||||
dpkg -s libreaktor-dev | grep -q '^Status: install ok installed'
|
||||
cmake -S examples/consumer -B build-pkg-consumer -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_PREFIX_PATH=/opt/reaktor </dev/null
|
||||
cmake --build build-pkg-consumer </dev/null
|
||||
@@ -271,41 +209,6 @@ jobs:
|
||||
for e in bmp txt; do cmp "check/lib-built.$e" "check/lib-packaged.$e"; done
|
||||
EOF
|
||||
|
||||
- name: Pack the shared libreaktor as .debs
|
||||
id: shareddeb
|
||||
if: ${{ !cancelled() && steps.shared.outcome == 'success' }}
|
||||
run: |
|
||||
if [ "${{ matrix.emulated }}" = true ]; then
|
||||
docker exec -i builder sh -eu tools/libreaktor-pkg.sh -f deb -b build-shared -o dist-pkg-shared -a ${{ matrix.debarch }} </dev/null
|
||||
else
|
||||
docker exec -i debian sh -eu tools/libreaktor-pkg.sh -f deb -b build-shared -o dist-pkg-shared </dev/null
|
||||
fi
|
||||
|
||||
- name: Upload the shared .debs
|
||||
if: ${{ !cancelled() && steps.shareddeb.outcome == 'success' }}
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-deb-shared-linux-${{ matrix.arch }}
|
||||
path: dist-pkg-shared/*.deb
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
- name: Check the shared libreaktor .debs
|
||||
if: ${{ !cancelled() && steps.shareddeb.outcome == 'success' && steps.libcheck.outcome == 'success' && matrix.arch == 'x86-64' }}
|
||||
run: |
|
||||
docker exec -i debian sh -eu <<'EOF'
|
||||
dpkg -r libreaktor </dev/null
|
||||
dpkg -i dist-pkg-shared/*.deb </dev/null
|
||||
cmake -S examples/consumer -B build-pkg-shared -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_PREFIX_PATH=/opt/reaktor -DCONSUMER_SHARED=ON </dev/null
|
||||
cmake --build build-pkg-shared </dev/null
|
||||
dpkg -r libreaktor-shared </dev/null
|
||||
dpkg -s libreaktor1 libreaktor-sdl3-0 | grep -c '^Status: install ok installed' | grep -q 2
|
||||
timeout 600 build-pkg-shared/simple --theme light --video dummy \
|
||||
--shot check/lib-packaged-shared.bmp --a11y-dump check/lib-packaged-shared.txt </dev/null
|
||||
for e in bmp txt; do cmp "check/lib-built.$e" "check/lib-packaged-shared.$e"; done
|
||||
EOF
|
||||
|
||||
- name: Check an app that embeds Reaktor
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' && matrix.arch == 'x86-64' }}
|
||||
run: |
|
||||
@@ -328,9 +231,7 @@ jobs:
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-libreaktor-linux-${{ matrix.arch }}
|
||||
path: |
|
||||
dist/libreaktor-*.tar.gz
|
||||
!dist/libreaktor-shared-*.tar.gz
|
||||
path: dist/libreaktor-*.tar.gz
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
@@ -391,24 +292,12 @@ jobs:
|
||||
libXrandr-devel libXrender-devel libXtst-devel libxkbcommon-devel \
|
||||
wayland-devel wayland-protocols-devel libglvnd-devel dbus-devel </dev/null
|
||||
sh tools/libreaktor-pkg.sh -i -o dist-pkg </dev/null
|
||||
rpm -q libreaktor
|
||||
rpm -q libreaktor-devel
|
||||
cmake -S examples/consumer -B build-pkg-consumer -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_PREFIX_PATH=/opt/reaktor </dev/null
|
||||
cmake --build build-pkg-consumer </dev/null
|
||||
rpm -e libreaktor
|
||||
rm -rf build-pkg
|
||||
sh tools/libreaktor-pkg.sh -s -i -o dist-pkg-shared </dev/null
|
||||
rpm -q libreaktor1 libreaktor-sdl3-0 libreaktor-shared
|
||||
cmake -S examples/consumer -B build-pkg-shared -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_PREFIX_PATH=/opt/reaktor -DCONSUMER_SHARED=ON </dev/null
|
||||
cmake --build build-pkg-shared </dev/null
|
||||
rpm -e libreaktor-shared
|
||||
build-pkg-shared/simple --theme light --video dummy --shot check-shared.bmp </dev/null
|
||||
mv dist-pkg-shared/*.rpm dist-pkg/
|
||||
EOF
|
||||
|
||||
# One folder: two paths would keep dist-pkg/ and dist-pkg-shared/ in the
|
||||
# artifact, and the release expects every package at the top.
|
||||
- name: Upload the .rpm
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
|
||||
+4
-102
@@ -74,7 +74,7 @@ jobs:
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||
run: |
|
||||
fail=0
|
||||
for t in $(cat tools/ci/tests.txt); do
|
||||
for t in onlaytest keytest a11ytest animtest localetest laytest texttest csstest; do
|
||||
echo "== $t"
|
||||
if ./build/$t </dev/null; then :; else echo "$t: exit status $?"; fail=1; fi
|
||||
done
|
||||
@@ -137,13 +137,9 @@ jobs:
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||
run: |
|
||||
version='${{ inputs.version || 'dev' }}'
|
||||
export CCACHE_DIR=$PWD/.ccache CCACHE_BASEDIR=$PWD CCACHE_MAXSIZE=500M
|
||||
name="libreaktor-${version}-macos-${{ matrix.arch }}"
|
||||
cmake -S . -B build-lib -G Ninja -DCMAKE_BUILD_TYPE=Release -DREAKTOR_LTO=OFF \
|
||||
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
|
||||
-DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON </dev/null
|
||||
cmake --build build-lib --target libreaktor </dev/null
|
||||
cmake --install build-lib --prefix "dist/$name" --component libreaktor </dev/null
|
||||
cmake --build build --target libreaktor </dev/null
|
||||
cmake --install build --prefix "dist/$name" --component libreaktor </dev/null
|
||||
cmake -S examples/consumer -B build-consumer -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
"-DCMAKE_PREFIX_PATH=$PWD/dist/$name" </dev/null
|
||||
cmake --build build-consumer </dev/null
|
||||
@@ -158,33 +154,6 @@ jobs:
|
||||
done
|
||||
ditto -c -k --keepParent "dist/$name" "dist/$name.zip"
|
||||
|
||||
- name: Shared libreaktor
|
||||
id: shared
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||
run: |
|
||||
export CCACHE_DIR=$PWD/.ccache CCACHE_BASEDIR=$PWD CCACHE_MAXSIZE=500M
|
||||
version='${{ inputs.version || 'dev' }}'
|
||||
name="libreaktor-shared-${version}-macos-${{ matrix.arch }}"
|
||||
cmake -S . -B build-shared -G Ninja -DCMAKE_BUILD_TYPE=Release -DREAKTOR_SHARED=ON -DREAKTOR_LTO=OFF \
|
||||
-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
|
||||
-DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON </dev/null
|
||||
cmake --build build-shared </dev/null
|
||||
sh tools/ci/check-libreaktor.sh build-shared "$name" </dev/null
|
||||
tar -C dist -xzf "dist/$name.tar.gz"
|
||||
rm "dist/$name.tar.gz"
|
||||
ditto -c -k --keepParent "dist/$name" "dist/$name.zip"
|
||||
rm -rf "dist/$name"
|
||||
|
||||
- name: Upload the shared libreaktor
|
||||
if: ${{ !cancelled() && steps.shared.outcome == 'success' }}
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-libreaktor-shared-macos-${{ matrix.arch }}
|
||||
path: |
|
||||
dist/libreaktor-shared-*.zip
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
- name: Check an app that embeds Reaktor
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||
run: |
|
||||
@@ -206,9 +175,7 @@ jobs:
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-libreaktor-macos-${{ matrix.arch }}
|
||||
path: |
|
||||
dist/libreaktor-*.zip
|
||||
!dist/libreaktor-shared-*.zip
|
||||
path: dist/libreaktor-*.zip
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
@@ -220,68 +187,3 @@ jobs:
|
||||
path: smoke/
|
||||
if-no-files-found: warn
|
||||
retention-days: 14
|
||||
|
||||
universal:
|
||||
name: macos universal
|
||||
needs: macos
|
||||
if: ${{ !cancelled() }}
|
||||
runs-on: macos-15
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
submodules: recursive
|
||||
persist-credentials: false
|
||||
|
||||
- name: Install packages
|
||||
env:
|
||||
HOMEBREW_NO_AUTO_UPDATE: 1
|
||||
run: brew install ninja
|
||||
|
||||
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
name: package-libreaktor-shared-macos-arm64
|
||||
path: dl/arm64
|
||||
|
||||
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
name: package-libreaktor-shared-macos-x86_64
|
||||
path: dl/x86_64
|
||||
|
||||
- name: Join and check the universal libreaktor
|
||||
run: |
|
||||
v='${{ inputs.version || 'dev' }}'
|
||||
for a in arm64 x86_64; do ditto -x -k "dl/$a/libreaktor-shared-$v-macos-$a.zip" "u/$a"; done
|
||||
A="u/arm64/libreaktor-shared-$v-macos-arm64"
|
||||
X="u/x86_64/libreaktor-shared-$v-macos-x86_64"
|
||||
U="dist/libreaktor-shared-$v-macos-universal"
|
||||
mkdir -p dist
|
||||
ditto "$A" "$U"
|
||||
(cd "$A" && find . -type f) | while read -r f; do
|
||||
if file -b "$A/$f" | grep -q -E 'Mach-O|ar archive'; then
|
||||
lipo -create "$A/$f" "$X/$f" -output "$U/$f"
|
||||
else
|
||||
cmp "$A/$f" "$X/$f"
|
||||
fi
|
||||
done
|
||||
codesign --force --sign - "$U/Frameworks/Reaktor.framework"
|
||||
lipo -info "$U/Frameworks/Reaktor.framework/Reaktor"
|
||||
lipo "$U/Frameworks/Reaktor.framework/Reaktor" -verify_arch arm64 x86_64
|
||||
lipo "$U/lib/libreaktor-modules.a" -verify_arch arm64 x86_64
|
||||
cmake -S examples/consumer -B build-consumer -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
||||
"-DCMAKE_PREFIX_PATH=$PWD/$U" -DCONSUMER_SHARED=ON \
|
||||
"-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64" </dev/null
|
||||
cmake --build build-consumer </dev/null
|
||||
lipo build-consumer/simple -verify_arch arm64 x86_64
|
||||
mkdir -p check
|
||||
build-consumer/simple --theme light --video dummy \
|
||||
--shot check/universal.bmp --a11y-dump check/universal.txt </dev/null
|
||||
ditto -c -k --keepParent "$U" "$U.zip"
|
||||
|
||||
- name: Upload the universal libreaktor
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: package-libreaktor-shared-macos-universal
|
||||
path: dist/libreaktor-shared-*-macos-universal.zip
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
|
||||
@@ -124,8 +124,9 @@ jobs:
|
||||
The programs are not signed, and SmartScreen may ask before the first run.
|
||||
- **macOS**: \`reaktor.app\` is the showcase as an app, signed ad hoc and not
|
||||
notarized: open it from its context menu the first time.
|
||||
- **Linux**: glibc 2.36 or newer (2.41 for RISC-V), and X11 or Wayland.
|
||||
- **BSDs**: the release named above, and X11.
|
||||
- **Linux**: glibc 2.36 or newer (2.41 for RISC-V), libdbus-1, and X11 or
|
||||
Wayland.
|
||||
- **BSDs**: the release named above, the dbus package, and X11.
|
||||
- **Web**: the showcase, Notepad and Simple as \`.html\`, \`.js\`, \`.wasm\`
|
||||
and \`.data\`. Serve the folder over HTTP (a \`file://\` page cannot fetch
|
||||
the \`.wasm\`) and open \`showcase.html\`; the same showcase runs at
|
||||
@@ -134,11 +135,10 @@ jobs:
|
||||
### libreaktor
|
||||
|
||||
The library itself, for building your own applications: the same
|
||||
systems and architectures, \`libreaktor-$v-<system>-<arch>\` (a
|
||||
\`.zip\` on Windows and macOS, a \`.tar.gz\` elsewhere), and
|
||||
systems and architectures, \`libreaktor-$v-<system>-<arch>\`, and
|
||||
\`libreaktor-$v-wasm.tar.gz\`. Each holds one static library (\`reaktor.lib\`
|
||||
on Windows, built against the DLL C runtime; \`libreaktor.a\` elsewhere)
|
||||
with SDL, FreeType, plutosvg, Onlay, NukAnim, mojibake, kb_text_shape and toml-c
|
||||
with SDL, libcss, plutosvg, Onlay, NukAnim, mojibake and kb_text_shape
|
||||
inside it, the public headers (\`#include "reaktor/reaktor.h"\`, with
|
||||
Nuklear's, NukAnim's and SDL's), a CMake package and a pkg-config file,
|
||||
and the licenses.
|
||||
@@ -153,40 +153,10 @@ jobs:
|
||||
\`PKG_CONFIG_PATH\` at its \`lib/pkgconfig\`.
|
||||
|
||||
On Linux it also comes as a system package that installs into
|
||||
\`/opt/reaktor\`: \`libreaktor_${v}_<arch>.deb\` for Debian and Ubuntu
|
||||
(amd64, i386, arm64, armhf, riscv64) and \`libreaktor-${v}-1.<arch>.rpm\`
|
||||
\`/opt/reaktor\`: \`libreaktor-dev_${v}_<arch>.deb\` for Debian and Ubuntu
|
||||
(amd64, i386, arm64, armhf, riscv64) and \`libreaktor-devel-${v}-1.<arch>.rpm\`
|
||||
for Fedora and RHEL (x86_64, aarch64).
|
||||
|
||||
#### Shared
|
||||
|
||||
On macOS it also comes as \`Reaktor.framework\`, with SDL inside, in
|
||||
\`libreaktor-shared-$v-macos-<arch>.zip\` (arm64, x86_64, or \`universal\` with
|
||||
both in every binary) beside \`libreaktor-modules.a\` and the static
|
||||
files: link \`reaktor::shared\`. Apps share it from
|
||||
\`/Library/Frameworks\`, which their rpath searches. It is signed ad
|
||||
hoc and not notarized, like everything here, so an app that turns on
|
||||
the hardened runtime cannot load it, and a downloaded copy needs
|
||||
\`xattr -dr com.apple.quarantine Reaktor.framework\` once.
|
||||
|
||||
On Linux and the BSDs the library also comes shared, so
|
||||
several apps can share one copy in memory:
|
||||
\`libreaktor-shared-$v-<system>-<arch>.tar.gz\` holds \`libreaktor.so.1\`,
|
||||
our own SDL as \`libreaktor-sdl3.so.0\`, \`libreaktor-modules.a\` (the
|
||||
modules, which go into each app), everything the static one has, and
|
||||
\`reaktor-shared.pc\`. Link with \`reaktor::shared\` in CMake or
|
||||
\`pkg-config --cflags --libs reaktor-shared\`; the app records where the
|
||||
libraries are. As system packages it splits in three:
|
||||
\`libreaktor-sdl3-0\` and \`libreaktor1\`, all an app needs to run, and
|
||||
\`libreaktor-shared\` to build one:
|
||||
\`libreaktor1_${v}_<arch>.deb\`, \`libreaktor-sdl3-0_${v}_<arch>.deb\` and
|
||||
the \`.rpm\`s beside them. The static library stays the default.
|
||||
|
||||
**Upgrading:** the static package was \`libreaktor-dev\` as a \`.deb\`
|
||||
and \`libreaktor-devel\` as an \`.rpm\`; it is \`libreaktor\` now, as it
|
||||
was already on the BSDs. Remove the old one first, since both install
|
||||
the headers. \`libreaktor-shared\` is the shared one and conflicts with
|
||||
it the same way.
|
||||
|
||||
\`SHA256SUMS\` lists every download's checksum. GitHub's own source
|
||||
archives below leave the submodules out; the \`-source.tar.gz\` above has
|
||||
them.
|
||||
|
||||
@@ -44,6 +44,7 @@ jobs:
|
||||
submodules: recursive
|
||||
persist-credentials: false
|
||||
|
||||
# ccache's own release, pinned and checked; without it the build only runs uncached.
|
||||
- name: Install ccache
|
||||
id: ccache-tool
|
||||
run: |
|
||||
@@ -94,7 +95,7 @@ jobs:
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||
run: |
|
||||
$fail = 0
|
||||
foreach ($t in Get-Content tools/ci/tests.txt) {
|
||||
foreach ($t in 'onlaytest', 'keytest', 'a11ytest', 'animtest', 'localetest', 'laytest', 'texttest', 'csstest') {
|
||||
Write-Host "== $t"
|
||||
& "./${{ matrix.out }}/$t.exe"
|
||||
if ($LASTEXITCODE -ne 0) { Write-Host "${t}: exit status $LASTEXITCODE"; $fail = 1 }
|
||||
@@ -155,12 +156,10 @@ jobs:
|
||||
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||
run: |
|
||||
New-Item -ItemType Directory -Force smoke | Out-Null
|
||||
foreach ($name in 'uitest', 'skiptest', 'damagetest', 'damagetest_text') {
|
||||
$p = Start-Process "./${{ matrix.out }}/$name.exe" -ArgumentList '--log', "smoke/$name.log" -PassThru
|
||||
if (-not $p.WaitForExit(120000)) { $p.Kill(); throw "$name did not finish" }
|
||||
Select-String -Path "smoke/$name.log" -Pattern 'test:' | ForEach-Object { $_.Line }
|
||||
if ($p.ExitCode -ne 0) { throw "$name exited with $($p.ExitCode)" }
|
||||
}
|
||||
$p = Start-Process "./${{ matrix.out }}/uitest.exe" -ArgumentList '--log', 'smoke/uitest.log' -PassThru
|
||||
if (-not $p.WaitForExit(120000)) { $p.Kill(); throw "uitest did not finish" }
|
||||
Select-String -Path smoke/uitest.log -Pattern 'test:' | ForEach-Object { $_.Line }
|
||||
if ($p.ExitCode -ne 0) { throw "uitest exited with $($p.ExitCode)" }
|
||||
|
||||
- name: Package
|
||||
id: package
|
||||
@@ -210,7 +209,7 @@ jobs:
|
||||
if ('${{ steps.ccache-tool.outputs.use }}' -eq 'true') {
|
||||
$launch = '-DCMAKE_C_COMPILER_LAUNCHER=ccache', '-DCMAKE_CXX_COMPILER_LAUNCHER=ccache', '-DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON'
|
||||
}
|
||||
./build.ps1 -Arch ${{ matrix.arch }} -Out build-lib libreaktor -DREAKTOR_LTO=OFF @launch
|
||||
./build.ps1 -Arch ${{ matrix.arch }} -Out build-lib libreaktor @launch
|
||||
|
||||
- name: Save the compiler cache
|
||||
if: ${{ always() && steps.build.outcome == 'success' }}
|
||||
|
||||
@@ -12,9 +12,6 @@ build-arm64/
|
||||
build-lib/
|
||||
build-consumer/
|
||||
build-embedded/
|
||||
build-map/
|
||||
build-proto*/
|
||||
build-shared/
|
||||
.claude/settings.local.json
|
||||
.dart_tool/
|
||||
.gradle/
|
||||
@@ -34,8 +31,5 @@ benchmarks/flutter-bench/.idea/
|
||||
benchmarks/flutter-bench/*.iml
|
||||
build-pkg/
|
||||
build-pkg-consumer/
|
||||
build-pkg-shared/
|
||||
dist-pkg*/
|
||||
dist/
|
||||
smoke/
|
||||
build-static/
|
||||
|
||||
+17
-17
@@ -1,39 +1,39 @@
|
||||
[submodule "external/nuklear"]
|
||||
path = external/nuklear
|
||||
url = https://github.com/Immediate-Mode-UI/Nuklear.git
|
||||
url = ../Nuklear.git
|
||||
[submodule "external/plutosvg"]
|
||||
path = external/plutosvg
|
||||
url = https://github.com/sammycage/plutosvg.git
|
||||
url = ../plutosvg.git
|
||||
[submodule "external/ionicons"]
|
||||
path = external/ionicons
|
||||
url = https://github.com/ionic-team/ionicons.git
|
||||
url = ../ionicons.git
|
||||
[submodule "external/SDL"]
|
||||
path = external/SDL
|
||||
url = https://github.com/libsdl-org/SDL.git
|
||||
url = ../SDL.git
|
||||
[submodule "external/lcui"]
|
||||
path = external/lcui
|
||||
url = ../LCUI.git
|
||||
[submodule "external/onlay"]
|
||||
path = external/onlay
|
||||
url = https://github.com/Alpaq92/Onlay.git
|
||||
url = ../Onlay.git
|
||||
[submodule "external/mojibake"]
|
||||
path = external/mojibake
|
||||
url = https://github.com/zaerl/mojibake.git
|
||||
url = ../mojibake.git
|
||||
[submodule "external/kb"]
|
||||
path = external/kb
|
||||
url = https://github.com/JimmyLefevre/kb.git
|
||||
url = ../kb.git
|
||||
[submodule "external/nukanim"]
|
||||
path = external/nukanim
|
||||
url = https://github.com/Alpaq92/NukAnim.git
|
||||
url = ../NukAnim.git
|
||||
[submodule "external/mglibs"]
|
||||
path = external/mglibs
|
||||
url = ../libs.git
|
||||
[submodule "external/watercss"]
|
||||
path = external/watercss
|
||||
url = https://github.com/kognise/water.css
|
||||
url = ../water.css.git
|
||||
[submodule "external/simplecss"]
|
||||
path = external/simplecss
|
||||
url = https://github.com/kevquirk/simple.css
|
||||
url = ../simple.css.git
|
||||
[submodule "external/freetype"]
|
||||
path = external/freetype
|
||||
url = https://github.com/freetype/freetype
|
||||
[submodule "external/toml-c"]
|
||||
path = external/toml-c
|
||||
url = https://github.com/arp242/toml-c.git
|
||||
[submodule "external/gibus"]
|
||||
path = external/gibus
|
||||
url = https://github.com/Alpaq92/gibus.git
|
||||
url = ../freetype.git
|
||||
|
||||
@@ -4,108 +4,129 @@ C99. Widgets are declared; the look comes from CSS read at runtime.
|
||||
|
||||
## Build and run
|
||||
|
||||
`./build.sh [target]` (`./build.ps1` on Windows, which finds `cmake`; it is
|
||||
not on PATH). Targets: `showcase`, `notepad`, `simple`, `bench`, the tests
|
||||
in `tests/`, and `libreaktor`. `-Arch x86|arm64` builds into `build-<arch>`;
|
||||
ARM64 is checked only by CI.
|
||||
`./build.ps1` on Windows, `./build.sh` elsewhere — `cmake` is not on PATH, the
|
||||
script finds MSVC's. `./build.ps1 <target>` builds one. Targets: `showcase`,
|
||||
`notepad`, `simple`, `bench`, plus the tests in `tests/`. `-Arch x86` (or
|
||||
`arm64`) builds that architecture into `build-<arch>`; ARM64 needs Visual
|
||||
Studio's ARM64 tools, which this machine lacks, so CI is its only check.
|
||||
`tools/package.sh <build> <folder> [.exe]` packs what a release ships; a
|
||||
version tag such as `1.2.3` publishes one through `release.yml`.
|
||||
|
||||
CMake options pass through: `./build.ps1 -DREAKTOR_A11Y=OFF`,
|
||||
`./build.sh -- -DREAKTOR_A11Y=OFF`. The cache keeps them; pass `=ON` to switch
|
||||
back. Check `build/CMakeCache.txt` before measuring: `REAKTOR_SHARED=ON` left
|
||||
in `build/` links every sample shared.
|
||||
|
||||
Shipping: `tools/package.sh` packs a release folder, `tools/libreaktor-pkg.sh`
|
||||
a system package (`libreaktor` static; with `-s`, `libreaktor1`,
|
||||
`libreaktor-sdl3-0` and `libreaktor-shared`). A version tag such as `1.2.3`
|
||||
publishes through `release.yml`.
|
||||
CMake options pass straight through: `./build.ps1 -DREAKTOR_A11Y=OFF`,
|
||||
`./build.sh -- -DREAKTOR_A11Y=OFF`. The cache keeps an option, so a later build
|
||||
without the flag does not reset it — pass `=ON` to switch back.
|
||||
|
||||
## Verify against pixels, not source
|
||||
|
||||
Reasoning about what a dependency will draw has been wrong too often. Take
|
||||
the screenshot and diff the dump:
|
||||
Reasoning from a dependency's source about what it will draw has been wrong
|
||||
often enough to be a rule. Take the screenshot, diff the dump, read the
|
||||
framebuffer.
|
||||
|
||||
```bash
|
||||
./build/showcase --tab 7 --theme dark --shot a.bmp --a11y-dump a.txt
|
||||
```
|
||||
|
||||
The dump has a line per node with role, name, value, state and bounds, so a
|
||||
one-pixel move shows. Lines marked `volatile` (Diagnostics timings) differ
|
||||
every run.
|
||||
`--a11y-dump` writes one line per node with role, name, value, state and
|
||||
**bounds**. Diff two and anything that moved by a pixel says so. It is the
|
||||
regression oracle for every layout or style change.
|
||||
|
||||
## Traps that have cost real time
|
||||
|
||||
- **A rule cannot resize a box the page sized.** `.box = { .h = N }` locks CSS
|
||||
out of that axis; usually why a stylesheet "only changes the color".
|
||||
- **`core/ui/style_map.c` is the only writer of `nk_style`.** Anything set
|
||||
elsewhere is lost on the next theme change.
|
||||
- **A box is placed one frame late and found by its name.** A widget whose
|
||||
label changes every frame needs a stable `.name`.
|
||||
- **Hover redraws only across a hot rectangle.** Motion runs a frame only when
|
||||
it crosses a rectangle `hot_push` registered the frame before.
|
||||
- **A percentage is not a length to `core/css/css.c`.** `width: 100%` is
|
||||
dropped and a lower rule shows through. `[type=range]` reads as
|
||||
`input.type-range`.
|
||||
- **Vertices snap to whole pixels.** Sub-pixel corrections vanish; abutting
|
||||
rects can round apart into a seam.
|
||||
- **SDL's software renderer redraws rectangles its own way**, truncating
|
||||
position and size apart at fractional scales. `nk_sdl_quad` draws them from
|
||||
device pixels first.
|
||||
- **A one-pixel stroke is two pixels.** `nk_stroke_rect` casts to `short` and
|
||||
anti-aliasing splits it. Borders are `reaktor_edge_round`: a ring mask for
|
||||
corners, runs cut from its middle texels.
|
||||
- **Rounded fills are masks.** Fill anti-aliasing is off on the software
|
||||
renderer, so `reaktor_render` swaps each rounded fill for
|
||||
`reaktor_fill_round`, relinking the command list (it ends where a `next`
|
||||
reaches `ctx->memory.allocated`).
|
||||
- **SDL draws when it flushes, not when it is asked.** Its calls only queue,
|
||||
so without a GPU most of a frame is the flush the runtime makes before
|
||||
timing the present; the Diagnostics page and `bench --no-vsync` split them.
|
||||
Vsync sits in the present: a total matching the refresh rate measures it.
|
||||
- **`--shot` never skips a frame.** It and a capture force a whole draw, so a
|
||||
pixel diff cannot see what skipping an unchanged frame, or redrawing only
|
||||
what changed, breaks; `tests/skiptest.c` and `tests/damagetest.c` can.
|
||||
Skipping is the default; `.draw_every_frame` turns it off.
|
||||
- **Text the atlas lacks is not Nuklear's.** Strings with Japanese, Arabic and
|
||||
the like are measured and drawn by `core/text/text.c` through a custom
|
||||
command. mojibake 0.5.0 records `byte_offset` at a character's last byte.
|
||||
- **Only Nuklear's active window gets input.** Others carry a sticky
|
||||
`NK_WINDOW_ROM`. A layer that must not take input uses `reaktor_layer_begin`
|
||||
with `HOLD_ALL`; `reaktor_layer_focus` hands focus back.
|
||||
- **A field's keys are its own.** Edit state lives on the widget's window, so
|
||||
navigation asks `app->editing` before taking arrows, Home, End, Enter or
|
||||
Space. The runtime keeps Home and End, which would scroll the panel.
|
||||
- **A field's value is not its buffer.** `nk_edit_string` leaves bytes past
|
||||
the length; a length not from the field's own last frame reseeds it empty.
|
||||
- **An empty edit has no text pointer.** `nk_str_get_const` is NULL while
|
||||
`nk_str_len_char` is positive.
|
||||
- **Web: a tap focuses the canvas.** Only canceling the touch `pointerdown`
|
||||
stops it.
|
||||
- **Web: SDL delivers events a frame late**, so the page's own typing goes
|
||||
through SDL's queue to keep its order.
|
||||
- **Web: a hidden page runs no frames.** A background tab fires no
|
||||
`requestAnimationFrame`, so the canvas and a11y tree stay empty. Check
|
||||
`document.visibilityState`.
|
||||
- **The shared library exports only `tools/reaktor.map`.** A new public call
|
||||
goes in the map, or `check-exports.sh` fails; a struct an app sees that
|
||||
changes needs a new SOVERSION and `check-abi.sh -u`. OpenBSD installs no
|
||||
unversioned `libreaktor.so`.
|
||||
- **A rule cannot resize a box the page already sized.** Any `.box = { .h = N }`
|
||||
in a page locks CSS out of that axis. This is the usual reason a stylesheet
|
||||
"only changes the color".
|
||||
- **`core/ui/style_map.c` is the only writer of `nk_style`.** Setting a widget
|
||||
style anywhere else works until the next theme change reloads the sheets.
|
||||
- **A box is placed one frame late**, and found again by its **name**. A widget
|
||||
whose label changes every frame needs a stable `.name` or it never gets a
|
||||
rectangle.
|
||||
- **Hover is drawn only across a hot rectangle.** Pointer motion runs a frame
|
||||
only when it crosses a rectangle `hot_push` registered the frame before, so a
|
||||
widget that looks different under the pointer and registers none keeps its
|
||||
old look until some other input.
|
||||
- **libcss has no `em`/`rem`** — its units are px, %, dip, sp, pt. `cssflat.c`
|
||||
converts before the engine sees the text, along with `var()`, `color-mix()`,
|
||||
`@media` and attribute selectors.
|
||||
- **The renderer snaps every vertex to whole pixels.** Sub-pixel corrections
|
||||
are discarded, and rects that abut can round apart into a visible seam.
|
||||
- **SDL redraws a software rectangle its own way.** Its software renderer
|
||||
turns two triangles that make a rectangle into a fill or a copy, and
|
||||
truncates the scaled position and size apart, so at a fractional scale a run
|
||||
a whole number of device pixels wide loses one. `nk_sdl_quad` draws every
|
||||
such rectangle from device pixels before SDL sees it.
|
||||
- **A one-pixel stroke is two pixels here.** `nk_stroke_rect` casts its rect to
|
||||
`short`, so a half-pixel inset never reaches the draw list, and with line
|
||||
anti-aliasing on a stroke of thickness one is always two half-alpha rows.
|
||||
A border is `reaktor_edge_round`, inside the box: a ring mask for its
|
||||
corners, and its runs cut from the mask's middle texels, which hold a
|
||||
straight band so a run is sharp and as thick as its corners at any scale.
|
||||
- **A rounded fill is jagged unless it is a mask.** Fill anti-aliasing is off
|
||||
on the software renderer, the default (`.anti_aliasing` and `--aa` decide;
|
||||
a GPU renderer has it on), so a fill with corners goes through `reaktor_fill_round`,
|
||||
and `reaktor_render` swaps each one Nuklear drew itself for masks, relinking
|
||||
the built command list — whose end is wherever a `next` reaches
|
||||
`ctx->memory.allocated`.
|
||||
- **Measure the present, not the draw.** On a machine with no GPU, most of a
|
||||
frame is `SDL_RenderPresent`. `build/render/present` split is on the
|
||||
Diagnostics page and in `bench --no-vsync`.
|
||||
- **Text the atlas cannot draw is not Nuklear's to draw.** A string with any
|
||||
character the atlas lacks — Japanese, Arabic — is measured by
|
||||
`core/text/text.c` and drawn from the custom command it swaps in for
|
||||
Nuklear's text command, so a change to how Nuklear or the renderer places
|
||||
glyphs does not reach it. Its bidi levels are matched to mojibake's by order:
|
||||
mojibake 0.4.1 records `byte_offset` at a character's last byte.
|
||||
- **Only Nuklear's active window gets input.** Every other window carries a
|
||||
sticky `NK_WINDOW_ROM` until a click or hover activates it inside
|
||||
`nk_begin`. A layer that must not take input is begun
|
||||
`NK_WINDOW_NOT_INTERACTIVE` with `ctx->input` blanked — `reaktor_layer_begin`
|
||||
with `HOLD_ALL` — and focus is handed back with `reaktor_layer_focus`.
|
||||
- **A field's keys are its own, wherever it was declared.** Nuklear keeps
|
||||
edit-active state on the window a widget sits in, so the page's window misses
|
||||
every field inside a group; `app->editing` is what navigation asks before it
|
||||
gives up the arrows, Home, End, Enter and Space. Home and End also scroll the
|
||||
panel out from under the edit, so the runtime keeps those two.
|
||||
- **A field's value is not its buffer, and its length is the caller's.**
|
||||
`nk_edit_string` leaves the bytes past the length alone, so the buffer read as
|
||||
a string is the last, longer value; a length from anywhere but the field's own
|
||||
last frame reseeds it empty every frame.
|
||||
- **An empty edit has no text pointer.** `nk_str_get_const` answers NULL while
|
||||
`nk_str_len_char` still answers bytes, so that pair measures a null pointer
|
||||
with a positive length.
|
||||
- **A tap focuses the canvas by itself.** The canvas is focusable, so a
|
||||
touch's compatibility `mousedown` moves focus to it as its default action,
|
||||
with no script involved. Only canceling the touch `pointerdown` stops it.
|
||||
- **SDL hands the app its events a frame late.** Its web handlers queue them
|
||||
as they happen, but the app sees them only when the next iteration pumps, so
|
||||
anything the page keeps in a queue of its own overtakes them. The page's
|
||||
typing goes onto SDL's queue for that reason.
|
||||
- **A hidden web page runs no frames.** The web build's main loop waits on
|
||||
`requestAnimationFrame`, which never fires in a background tab, a minimized
|
||||
window or a browser pane that is not on screen. `#a11y` is made in `main()`,
|
||||
so the root is there, but the canvas stays blank and the tree empty until
|
||||
the page renders — and a scripted click or screenshot makes it render, so
|
||||
it looks as if the tree waits for input. Check `document.visibilityState`.
|
||||
|
||||
## House rules
|
||||
|
||||
- Dependencies are submodules under `external/`, used as they ship. Never
|
||||
copy a value out of one or generate a header from one. The exception is
|
||||
`REAKTOR_BUILTINS` in CMakeLists.txt: Water.css's palettes and `src/parts/`,
|
||||
the seven Ionicons the widgets draw, the Aileron fonts, the mark and
|
||||
reaktor.css, compiled in byte for byte. SDL is built with
|
||||
`core/sdl/no_dynapi.h`; NOTICE.md says why.
|
||||
- Applications see only `include/reaktor/`; `App` is opaque. What a sample
|
||||
needs becomes a public call. MSVC treats implicit declarations as errors.
|
||||
- American English.
|
||||
- No environment variables: overrides are command-line flags the runtime
|
||||
strips from `argv`.
|
||||
- `docs/DOCUMENTATION.md` is the only manual; `PERFORMANCE.md` holds measured
|
||||
- Dependencies are git submodules under `external/`, read as they ship. Never
|
||||
transcribe a value out of one, and never generate a header from one. The one
|
||||
exception is `REAKTOR_BUILTINS` in CMakeLists.txt: Water.css's two palettes
|
||||
and its `src/parts/`, and the seven Ionicons the widgets draw (three chevrons, three discs, the
|
||||
toast's close cross) are compiled in byte for byte, beside the Aileron
|
||||
fonts, the mark and reaktor.css. Nothing else from a submodule is — not the
|
||||
rest of Ionicons, not Simple.css. SDL is built with `core/sdl/no_dynapi.h`
|
||||
forced in, which turns its dynamic API off; NOTICE.md says why.
|
||||
- Applications see only `include/reaktor/`. The samples include
|
||||
`reaktor/reaktor.h` and `reaktor/main.h`, nothing from `core/`, and
|
||||
`App` is opaque to them; what a sample needs becomes a public call there.
|
||||
MSVC builds apps with implicit declarations as errors, which catches a miss.
|
||||
- American English, in code and prose.
|
||||
- No environment variables. Anything worth overriding is a command-line flag
|
||||
the runtime strips from `argv`.
|
||||
- `docs/DOCUMENTATION.md` is the whole of it; `PERFORMANCE.md` holds measured
|
||||
numbers only, with the machine named.
|
||||
- An optional module is an interface library plus a `_none` twin, switched by
|
||||
`REAKTOR_<NAME>` (default `ON`). Off, pixels and `--a11y-dump` must not
|
||||
change beyond what the module draws. Localization and text shaping are
|
||||
separate modules.
|
||||
- An optional module is an interface library plus a `_none` twin defining the
|
||||
same functions, and an application links one of the two; its
|
||||
`REAKTOR_<NAME>` option, default `ON`, swaps in the twin. Localization and
|
||||
text shaping are two modules, not one. A module that is off must leave pixels
|
||||
and `--a11y-dump` byte-identical except for what the module itself produces.
|
||||
|
||||
+160
-370
@@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(reaktor VERSION 0.11.0 LANGUAGES C CXX)
|
||||
project(reaktor VERSION 0.7.2 LANGUAGES C CXX)
|
||||
|
||||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
set(_reaktor_top ON)
|
||||
@@ -22,116 +22,29 @@ endif()
|
||||
|
||||
set(TP "${CMAKE_CURRENT_SOURCE_DIR}/external")
|
||||
|
||||
option(REAKTOR_SHARED "Also build a shared libreaktor, and link the samples to it" OFF)
|
||||
set(REAKTOR_SHARED_SDL OFF)
|
||||
if(REAKTOR_SHARED)
|
||||
if(NOT UNIX OR EMSCRIPTEN)
|
||||
message(FATAL_ERROR "REAKTOR_SHARED is for Linux, the BSDs and macOS")
|
||||
endif()
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
if(NOT APPLE)
|
||||
set(REAKTOR_SHARED_SDL ON)
|
||||
endif()
|
||||
endif()
|
||||
if(REAKTOR_SHARED_SDL)
|
||||
set(REAKTOR_SDL SDL3::SDL3-shared)
|
||||
else()
|
||||
set(REAKTOR_SDL SDL3::SDL3-static)
|
||||
endif()
|
||||
set(SDL_SHARED ${REAKTOR_SHARED_SDL} CACHE BOOL "" FORCE)
|
||||
set(SDL_SHARED OFF CACHE BOOL "" FORCE)
|
||||
set(SDL_STATIC ON CACHE BOOL "" FORCE)
|
||||
set(SDL_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set(SDL_EXAMPLES OFF CACHE BOOL "" FORCE)
|
||||
set(SDL_TEST_LIBRARY OFF CACHE BOOL "" FORCE)
|
||||
set(SDL_INSTALL OFF CACHE BOOL "" FORCE)
|
||||
foreach(sub AUDIO JOYSTICK HAPTIC HIDAPI SENSOR CAMERA POWER OFFSCREEN)
|
||||
foreach(sub AUDIO JOYSTICK HAPTIC HIDAPI SENSOR CAMERA POWER GPU OFFSCREEN)
|
||||
set(SDL_${sub} OFF CACHE BOOL "" FORCE)
|
||||
endforeach()
|
||||
# Off: the software renderer is the default, and with the GPU API built in,
|
||||
# SDL loads Vulkan and its drivers even for that renderer (PERFORMANCE.md).
|
||||
# An application that runs its own shaders turns it on.
|
||||
option(REAKTOR_SHADERS "An application's own shaders: SDL's GPU API and its renderer, --renderer sdl-gpu" OFF)
|
||||
set(SDL_GPU ${REAKTOR_SHADERS} CACHE BOOL "" FORCE)
|
||||
set(SDL_TRAY ON CACHE BOOL "" FORCE)
|
||||
|
||||
foreach(drv RENDER_D3D RENDER_VULKAN VULKAN)
|
||||
set(SDL_${drv} OFF CACHE BOOL "" FORCE)
|
||||
endforeach()
|
||||
if(REAKTOR_SHADERS AND UNIX AND NOT APPLE AND NOT EMSCRIPTEN)
|
||||
set(SDL_VULKAN ON CACHE BOOL "" FORCE)
|
||||
endif()
|
||||
set(_renderers_all direct3d11 direct3d12 opengl opengles2)
|
||||
if(WIN32)
|
||||
set(_renderers_default direct3d11 direct3d12)
|
||||
set(_renderers_here ${_renderers_all})
|
||||
elseif(UNIX AND NOT APPLE AND NOT EMSCRIPTEN)
|
||||
set(_renderers_default "")
|
||||
set(_renderers_here opengl opengles2)
|
||||
else()
|
||||
set(_renderers_default "")
|
||||
set(_renderers_here "")
|
||||
endif()
|
||||
set(REAKTOR_RENDERERS "" CACHE STRING
|
||||
"Renderers built beside software, as --renderer names them: direct3d11, direct3d12, opengl, opengles2; empty for the platform's default, none for software only")
|
||||
set_property(CACHE REAKTOR_RENDERERS PROPERTY STRINGS "" none ${_renderers_all})
|
||||
|
||||
# A build directory from before the list keeps the renderers its two
|
||||
# switches, REAKTOR_SDL_D3D and REAKTOR_SDL_GL, had chosen.
|
||||
if(NOT REAKTOR_RENDERERS AND (DEFINED REAKTOR_SDL_D3D OR DEFINED REAKTOR_SDL_GL))
|
||||
set(_old "")
|
||||
if(NOT DEFINED REAKTOR_SDL_D3D OR REAKTOR_SDL_D3D)
|
||||
list(APPEND _old direct3d11 direct3d12)
|
||||
endif()
|
||||
if(REAKTOR_SDL_GL)
|
||||
list(APPEND _old opengl opengles2)
|
||||
endif()
|
||||
if(NOT _old)
|
||||
set(_old none)
|
||||
endif()
|
||||
unset(REAKTOR_SDL_D3D CACHE)
|
||||
unset(REAKTOR_SDL_GL CACHE)
|
||||
string(REPLACE ";" "," _old_shown "${_old}")
|
||||
if(_old STREQUAL "none" OR NOT _old STREQUAL "${_renderers_default}")
|
||||
set(REAKTOR_RENDERERS "${_old}" CACHE STRING "" FORCE)
|
||||
message(WARNING "REAKTOR_SDL_D3D and REAKTOR_SDL_GL are now REAKTOR_RENDERERS; this build keeps REAKTOR_RENDERERS=${_old_shown}")
|
||||
else()
|
||||
message(STATUS "REAKTOR_SDL_D3D and REAKTOR_SDL_GL are now REAKTOR_RENDERERS; this build has the default")
|
||||
endif()
|
||||
set(SDL_RENDER_D3D12 ON CACHE BOOL "" FORCE)
|
||||
endif()
|
||||
|
||||
string(REPLACE "," ";" _renderers "${REAKTOR_RENDERERS}")
|
||||
string(REPLACE "," ", " _renderers_shown "${REAKTOR_RENDERERS}")
|
||||
if(_renderers MATCHES "^(ON|OFF|TRUE|FALSE|YES|NO|Y|N|1|0)$")
|
||||
message(FATAL_ERROR "REAKTOR_RENDERERS lists renderers, it is not a switch: direct3d11, direct3d12, opengl, opengles2, or none for software only")
|
||||
elseif(NOT _renderers)
|
||||
set(_renderers ${_renderers_default})
|
||||
elseif(_renderers STREQUAL "none")
|
||||
set(_renderers "")
|
||||
else()
|
||||
foreach(r ${_renderers})
|
||||
if(NOT r IN_LIST _renderers_all)
|
||||
message(FATAL_ERROR "REAKTOR_RENDERERS=${_renderers_shown}: ${r} is not a renderer; the choices are direct3d11, direct3d12, opengl, opengles2, or none")
|
||||
elseif(NOT r IN_LIST _renderers_here)
|
||||
message(STATUS "REAKTOR_RENDERERS: ${r} is not a choice on ${CMAKE_SYSTEM_NAME}, ignored")
|
||||
endif()
|
||||
endforeach()
|
||||
option(REAKTOR_SDL_GL "Build SDL's OpenGL/GLES drivers on Windows, Linux and the BSDs" OFF)
|
||||
if((WIN32 OR (UNIX AND NOT APPLE)) AND NOT EMSCRIPTEN)
|
||||
set(SDL_OPENGL ${REAKTOR_SDL_GL} CACHE BOOL "" FORCE)
|
||||
set(SDL_OPENGLES ${REAKTOR_SDL_GL} CACHE BOOL "" FORCE)
|
||||
endif()
|
||||
foreach(r ${_renderers_here})
|
||||
if(r IN_LIST _renderers)
|
||||
set(_on ON)
|
||||
else()
|
||||
set(_on OFF)
|
||||
endif()
|
||||
if(r STREQUAL direct3d11)
|
||||
set(SDL_RENDER_D3D11 ${_on} CACHE BOOL "" FORCE)
|
||||
elseif(r STREQUAL direct3d12)
|
||||
set(SDL_RENDER_D3D12 ${_on} CACHE BOOL "" FORCE)
|
||||
elseif(r STREQUAL opengl)
|
||||
set(SDL_OPENGL ${_on} CACHE BOOL "" FORCE)
|
||||
elseif(r STREQUAL opengles2)
|
||||
set(SDL_OPENGLES ${_on} CACHE BOOL "" FORCE)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(SDL_X11_XSCRNSAVER OFF CACHE BOOL "" FORCE)
|
||||
# Linux packaging notes; OpenBSD refuses a program whose note segment passes 1 KB.
|
||||
@@ -150,46 +63,7 @@ if(MSVC)
|
||||
elseif(NOT EMSCRIPTEN)
|
||||
add_compile_options(-ffunction-sections -fdata-sections)
|
||||
endif()
|
||||
# Reaktor and SDL optimized as one program: SDL's software rasterizer then no
|
||||
# longer runs faster or slower as the code linked before it changes size. The
|
||||
# objects hold the compiler's own form until the link, so a static library
|
||||
# meant for other compilers is built with it off, as tools/libreaktor-pkg.sh
|
||||
# does. On where it measured faster without new warnings: MSVC and Apple
|
||||
# Clang. GCC warns in dependencies with it, and Clang on Linux gained nothing.
|
||||
if(MSVC OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
|
||||
set(_reaktor_lto_default ON)
|
||||
else()
|
||||
set(_reaktor_lto_default OFF)
|
||||
endif()
|
||||
option(REAKTOR_LTO "Link-time optimization in a Release build" ${_reaktor_lto_default})
|
||||
if(REAKTOR_LTO AND NOT EMSCRIPTEN)
|
||||
include(CheckIPOSupported)
|
||||
check_ipo_supported(RESULT _reaktor_lto OUTPUT _reaktor_lto_why LANGUAGES C CXX)
|
||||
if(_reaktor_lto)
|
||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
|
||||
else()
|
||||
message(STATUS "LTO: not supported by this toolchain")
|
||||
endif()
|
||||
endif()
|
||||
add_subdirectory("${TP}/SDL" EXCLUDE_FROM_ALL)
|
||||
# SDL keeps link-time code out of SDL_mslibc.c for a build without the C
|
||||
# library; with it the file is empty, and the flag only clashes with the
|
||||
# precompiled header.
|
||||
if(MSVC AND _reaktor_lto AND SDL_LIBC AND NOT CMAKE_VERSION VERSION_LESS 3.18)
|
||||
set_property(SOURCE "${TP}/SDL/src/stdlib/SDL_mslibc.c" DIRECTORY "${TP}/SDL"
|
||||
PROPERTY COMPILE_FLAGS "")
|
||||
endif()
|
||||
|
||||
function(reaktor_write_if_changed path content)
|
||||
set(_old "")
|
||||
if(EXISTS "${path}")
|
||||
file(READ "${path}" _old)
|
||||
endif()
|
||||
if(NOT _old STREQUAL content)
|
||||
file(WRITE "${path}" "${content}")
|
||||
endif()
|
||||
endfunction()
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
|
||||
# SDL's dynamic API keeps every SDL function linked and loads whichever SDL
|
||||
# library the SDL3_DYNAMIC_API environment variable names. Reaktor links SDL
|
||||
@@ -206,12 +80,45 @@ else()
|
||||
target_compile_options(SDL3-static PRIVATE
|
||||
-include "${CMAKE_CURRENT_SOURCE_DIR}/core/sdl/no_dynapi.h")
|
||||
endif()
|
||||
if(REAKTOR_SHARED_SDL)
|
||||
target_compile_options(SDL3-shared PRIVATE
|
||||
-include "${CMAKE_CURRENT_SOURCE_DIR}/core/sdl/no_dynapi.h")
|
||||
# Our own SDL under its own name, never the distro's libSDL3.
|
||||
set_target_properties(SDL3-shared PROPERTIES OUTPUT_NAME reaktor-sdl3
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
|
||||
set(LC "${TP}/lcui/lib")
|
||||
set(LCUI_CFG "${CMAKE_BINARY_DIR}/gen/lcui")
|
||||
file(MAKE_DIRECTORY "${LCUI_CFG}")
|
||||
|
||||
set(LCUI_FEATURES YUTIL_STATIC_BUILD LIBCSS_STATIC_BUILD)
|
||||
|
||||
function(lcui_expand IN OUTVAR)
|
||||
file(READ "${IN}" _c)
|
||||
string(REGEX MATCHALL "\\$\\{define [A-Z_]+\\}" _tokens "${_c}")
|
||||
foreach(_t IN LISTS _tokens)
|
||||
string(REGEX REPLACE "\\$\\{define ([A-Z_]+)\\}" "\\1" _name "${_t}")
|
||||
list(FIND LCUI_FEATURES "${_name}" _found)
|
||||
if(_found GREATER -1)
|
||||
set(_r "#define ${_name} 1")
|
||||
else()
|
||||
set(_r "/* ${_name}: not enabled by this build */")
|
||||
endif()
|
||||
string(REPLACE "${_t}" "${_r}" _c "${_c}")
|
||||
endforeach()
|
||||
string(REPLACE "\${VERSION_MAJOR}" "0" _c "${_c}")
|
||||
string(REPLACE "\${VERSION_MINOR}" "0" _c "${_c}")
|
||||
string(REPLACE "\${VERSION_ALTER}" "0" _c "${_c}")
|
||||
string(REPLACE "\${VERSION}" "vendored" _c "${_c}")
|
||||
set(${OUTVAR} "${_c}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
set(LCUI_MERGED "/* Generated by CMakeLists.txt from the .in templates in\n external/lcui. Do not edit; do not commit. */\n")
|
||||
foreach(_in "${LC}/yutil/include/yutil/config.h.in"
|
||||
"${LC}/css/src/config.h.in")
|
||||
lcui_expand("${_in}" _part)
|
||||
string(APPEND LCUI_MERGED "\n${_part}")
|
||||
endforeach()
|
||||
set(_old "")
|
||||
if(EXISTS "${LCUI_CFG}/config.h")
|
||||
file(READ "${LCUI_CFG}/config.h" _old)
|
||||
endif()
|
||||
if(NOT _old STREQUAL LCUI_MERGED)
|
||||
file(WRITE "${LCUI_CFG}/config.h" "${LCUI_MERGED}")
|
||||
endif()
|
||||
|
||||
if(UNIX AND NOT EMSCRIPTEN)
|
||||
@@ -221,6 +128,20 @@ if(UNIX AND NOT EMSCRIPTEN)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
file(GLOB_RECURSE LCUI_SRC
|
||||
"${LC}/yutil/src/*.c"
|
||||
"${LC}/css/src/*.c")
|
||||
|
||||
add_library(lcui STATIC ${LCUI_SRC})
|
||||
target_include_directories(lcui PUBLIC
|
||||
"${LCUI_CFG}"
|
||||
"${LC}/yutil/include"
|
||||
"${LC}/css/include")
|
||||
if(MSVC)
|
||||
target_compile_options(lcui PRIVATE /w)
|
||||
target_compile_definitions(lcui PRIVATE _CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
file(GLOB PLUTOVG_SRC "${TP}/plutosvg/plutovg/source/*.c")
|
||||
add_library(plutovg STATIC ${PLUTOVG_SRC})
|
||||
target_include_directories(plutovg PUBLIC "${TP}/plutosvg/plutovg/include")
|
||||
@@ -249,6 +170,8 @@ target_compile_definitions(onlay PUBLIC LAY_FLOAT=1)
|
||||
if(REAKTOR_TESTS AND NOT EMSCRIPTEN)
|
||||
add_executable(onlaytest ${TP}/onlay/test_onlay.c)
|
||||
target_link_libraries(onlaytest PRIVATE onlay)
|
||||
set_target_properties(onlaytest PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
endif()
|
||||
|
||||
set(REAKTOR_BUILTINS
|
||||
@@ -293,7 +216,13 @@ string(APPEND _gen
|
||||
"\nconst reaktor_builtin reaktor_builtins[] = {\n${_rows}};\n"
|
||||
"const int reaktor_builtin_count = ${_n};\n")
|
||||
set(_builtins "${CMAKE_BINARY_DIR}/gen/reaktor_builtins.c")
|
||||
reaktor_write_if_changed("${_builtins}" "${_gen}")
|
||||
set(_old "")
|
||||
if(EXISTS "${_builtins}")
|
||||
file(READ "${_builtins}" _old)
|
||||
endif()
|
||||
if(NOT _old STREQUAL _gen)
|
||||
file(WRITE "${_builtins}" "${_gen}")
|
||||
endif()
|
||||
message(STATUS "assets: ${_n} compiled in")
|
||||
|
||||
add_library(reaktor_headers INTERFACE)
|
||||
@@ -308,80 +237,77 @@ add_library(reaktor_core STATIC
|
||||
core/render/svg.c
|
||||
"${_builtins}")
|
||||
target_include_directories(reaktor_core PUBLIC core/base core/render)
|
||||
target_link_libraries(reaktor_core PUBLIC plutosvg freetype reaktor_headers ${REAKTOR_SDL})
|
||||
# Nuklear built for size: 139 KB less of the library, at no measurable cost a
|
||||
# frame (PERFORMANCE.md). A debug build keeps its own -O0.
|
||||
set_property(SOURCE core/render/nk_impl.c APPEND PROPERTY COMPILE_OPTIONS
|
||||
"$<$<NOT:$<CONFIG:Debug>>:$<IF:$<C_COMPILER_ID:MSVC>,/Os,-Os>>")
|
||||
target_link_libraries(reaktor_core PUBLIC plutosvg freetype reaktor_headers SDL3::SDL3-static)
|
||||
|
||||
set(APP_ICON assets/icons/reaktor-icon.ico)
|
||||
set(APP_RESOURCES "")
|
||||
|
||||
add_executable(mkicon EXCLUDE_FROM_ALL tools/mkicon.c)
|
||||
target_link_libraries(mkicon PRIVATE reaktor_core)
|
||||
|
||||
if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN AND NOT ANDROID)
|
||||
add_library(reaktor_gibus INTERFACE)
|
||||
target_include_directories(reaktor_gibus INTERFACE "${TP}/gibus/include")
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
endif()
|
||||
set_target_properties(mkicon PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
|
||||
if(REAKTOR_TESTS AND NOT EMSCRIPTEN)
|
||||
add_executable(keytest tests/keytest.c core/ui/keys.c)
|
||||
target_link_libraries(keytest PRIVATE reaktor_headers)
|
||||
target_include_directories(keytest PRIVATE core/ui)
|
||||
target_link_libraries(keytest PRIVATE ${REAKTOR_SDL})
|
||||
target_link_libraries(keytest PRIVATE SDL3::SDL3-static)
|
||||
set_target_properties(keytest PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
endif()
|
||||
|
||||
if(REAKTOR_TESTS AND NOT EMSCRIPTEN)
|
||||
add_executable(a11ytest tests/a11ytest.c core/a11y/a11y.c
|
||||
platform/a11y/a11y_snapshot.c core/base/utf8.c)
|
||||
target_link_libraries(a11ytest PRIVATE reaktor_headers ${REAKTOR_SDL})
|
||||
target_link_libraries(a11ytest PRIVATE reaktor_headers SDL3::SDL3-static)
|
||||
target_include_directories(a11ytest PRIVATE core/a11y core/render
|
||||
platform/a11y core/base)
|
||||
set_target_properties(a11ytest PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
endif()
|
||||
|
||||
if(REAKTOR_TESTS AND NOT EMSCRIPTEN)
|
||||
add_executable(animtest tests/animtest.c core/anim/anim.c)
|
||||
target_include_directories(animtest PRIVATE core/anim core/render
|
||||
"${TP}/nuklear/demo/sdl3_renderer")
|
||||
target_link_libraries(animtest PRIVATE reaktor_core ${REAKTOR_SDL})
|
||||
target_link_libraries(animtest PRIVATE reaktor_core SDL3::SDL3-static)
|
||||
set_target_properties(animtest PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
|
||||
add_executable(localetest tests/localetest.c
|
||||
core/locale/locale.c core/locale/plural.c
|
||||
core/locale/format.c)
|
||||
target_link_libraries(localetest PRIVATE reaktor_headers ${REAKTOR_SDL})
|
||||
target_link_libraries(localetest PRIVATE reaktor_headers SDL3::SDL3-static)
|
||||
target_include_directories(localetest PRIVATE core/locale)
|
||||
target_compile_definitions(localetest PRIVATE REAKTOR_LOCALE_EMBEDDED)
|
||||
set_target_properties(localetest PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
|
||||
add_executable(laytest tests/laytest.c core/ui/layout.c)
|
||||
target_link_libraries(laytest PRIVATE reaktor_headers)
|
||||
target_include_directories(laytest PRIVATE core/ui core/render)
|
||||
target_link_libraries(laytest PRIVATE onlay)
|
||||
set_target_properties(laytest PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
|
||||
add_executable(csstest tests/csstest.c core/css/css.c)
|
||||
add_executable(csstest tests/csstest.c core/css/cssflat.c)
|
||||
target_include_directories(csstest PRIVATE core/css core/base)
|
||||
target_link_libraries(csstest PRIVATE plutovg reaktor_headers)
|
||||
target_link_libraries(csstest PRIVATE plutovg)
|
||||
target_compile_definitions(csstest PRIVATE _CRT_SECURE_NO_WARNINGS
|
||||
CSSTEST_SOURCE="${CMAKE_CURRENT_SOURCE_DIR}/")
|
||||
set_target_properties(csstest PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
|
||||
add_executable(basetest tests/basetest.c core/base/url.c core/base/utf8.c)
|
||||
target_include_directories(basetest PRIVATE core/base)
|
||||
target_link_libraries(basetest PRIVATE ${REAKTOR_SDL})
|
||||
target_link_libraries(basetest PRIVATE SDL3::SDL3-static)
|
||||
set_target_properties(basetest PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
|
||||
add_executable(imagetest tests/imagetest.c)
|
||||
target_link_libraries(imagetest PRIVATE plutovg)
|
||||
|
||||
add_executable(gibustest ${TP}/gibus/tests/gibustest.c ${TP}/gibus/src/gibus_msg.c)
|
||||
target_include_directories(gibustest PRIVATE ${TP}/gibus/include ${TP}/gibus/src)
|
||||
if(TARGET reaktor_gibus)
|
||||
target_sources(gibustest PRIVATE ${TP}/gibus/src/gibus_conn.c)
|
||||
target_link_libraries(gibustest PRIVATE Threads::Threads)
|
||||
target_compile_definitions(gibustest PRIVATE GIBUSTEST_LIVE)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
foreach(_t keytest a11ytest animtest localetest laytest csstest basetest imagetest gibustest)
|
||||
target_compile_options(${_t} PRIVATE /we4013)
|
||||
endforeach()
|
||||
endif()
|
||||
set_target_properties(imagetest PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
endif()
|
||||
|
||||
if(WIN32 AND NOT EMSCRIPTEN)
|
||||
@@ -393,7 +319,14 @@ if(WIN32)
|
||||
file(MAKE_DIRECTORY "${GEN}")
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${APP_ICON}"
|
||||
"${GEN}/reaktor.ico" COPYONLY)
|
||||
reaktor_write_if_changed("${GEN}/reaktor.rc" "1 ICON \"reaktor.ico\"\n")
|
||||
set(_rc "1 ICON \"reaktor.ico\"\n")
|
||||
set(_old "")
|
||||
if(EXISTS "${GEN}/reaktor.rc")
|
||||
file(READ "${GEN}/reaktor.rc" _old)
|
||||
endif()
|
||||
if(NOT _old STREQUAL _rc)
|
||||
file(WRITE "${GEN}/reaktor.rc" "${_rc}")
|
||||
endif()
|
||||
set(APP_RESOURCES "${GEN}/reaktor.rc")
|
||||
elseif(UNIX AND NOT APPLE AND NOT EMSCRIPTEN)
|
||||
file(WRITE "${CMAKE_BINARY_DIR}/reaktor.desktop"
|
||||
@@ -440,15 +373,21 @@ elseif(APPLE)
|
||||
"$<TARGET_OBJECTS:reaktor_a11y_macos>")
|
||||
target_compile_definitions(reaktor_a11y INTERFACE REAKTOR_HAVE_NSACCESSIBILITY)
|
||||
target_link_libraries(reaktor_a11y INTERFACE "-framework Cocoa")
|
||||
elseif(TARGET reaktor_gibus)
|
||||
target_sources(reaktor_a11y INTERFACE
|
||||
"${_a11y}/a11y_snapshot.c" "${_a11y}/a11y_window_none.c" "${_a11y}/a11y_atspi.c")
|
||||
target_compile_definitions(reaktor_a11y INTERFACE REAKTOR_HAVE_ATSPI)
|
||||
target_link_libraries(reaktor_a11y INTERFACE reaktor_gibus)
|
||||
message(STATUS "a11y: AT-SPI")
|
||||
else()
|
||||
target_link_libraries(reaktor_a11y INTERFACE reaktor_a11y_none)
|
||||
message(STATUS "a11y: no AT-SPI bridge on this system")
|
||||
find_package(PkgConfig QUIET)
|
||||
if(PkgConfig_FOUND)
|
||||
pkg_check_modules(REAKTOR_DBUS QUIET IMPORTED_TARGET dbus-1)
|
||||
endif()
|
||||
if(REAKTOR_DBUS_FOUND)
|
||||
target_sources(reaktor_a11y INTERFACE
|
||||
"${_a11y}/a11y_snapshot.c" "${_a11y}/a11y_window_none.c" "${_a11y}/a11y_atspi.c")
|
||||
target_compile_definitions(reaktor_a11y INTERFACE REAKTOR_HAVE_ATSPI)
|
||||
target_link_libraries(reaktor_a11y INTERFACE PkgConfig::REAKTOR_DBUS)
|
||||
message(STATUS "a11y: AT-SPI over libdbus ${REAKTOR_DBUS_VERSION}")
|
||||
else()
|
||||
target_link_libraries(reaktor_a11y INTERFACE reaktor_a11y_none)
|
||||
message(STATUS "a11y: no dbus-1; the AT-SPI bridge is not built")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(REAKTOR_LOCALE "Translations, from the catalogs in assets/locale" ON)
|
||||
@@ -489,7 +428,13 @@ else()
|
||||
"\nconst struct reaktor_locale_catalog reaktor_locale_catalogs[] = {\n${_rows}};\n"
|
||||
"const int reaktor_locale_catalog_count = ${_n};\n")
|
||||
set(_out "${CMAKE_BINARY_DIR}/gen/locale_catalogs.c")
|
||||
reaktor_write_if_changed("${_out}" "${_gen}")
|
||||
set(_old "")
|
||||
if(EXISTS "${_out}")
|
||||
file(READ "${_out}" _old)
|
||||
endif()
|
||||
if(NOT _old STREQUAL _gen)
|
||||
file(WRITE "${_out}" "${_gen}")
|
||||
endif()
|
||||
target_sources(reaktor_locale INTERFACE "${_out}")
|
||||
target_compile_definitions(reaktor_locale INTERFACE REAKTOR_LOCALE_EMBEDDED)
|
||||
message(STATUS "locale: ${_n} catalogs compiled in")
|
||||
@@ -535,11 +480,13 @@ else()
|
||||
target_link_libraries(texttest PRIVATE reaktor_headers)
|
||||
target_include_directories(texttest PRIVATE core/render core/text)
|
||||
target_link_libraries(texttest PRIVATE reaktor_text reaktor_core
|
||||
${REAKTOR_SDL})
|
||||
SDL3::SDL3-static)
|
||||
set_target_properties(texttest PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
option(REAKTOR_SETTINGS "Settings kept between runs, in settings.toml" ON)
|
||||
option(REAKTOR_SETTINGS "Settings kept between runs, in settings.conf" ON)
|
||||
option(REAKTOR_TRAY "A tray icon with a menu" ON)
|
||||
option(REAKTOR_POPUP_WINDOWS "Menus in windows of their own, past the main window's edge" ON)
|
||||
option(REAKTOR_INSPECTOR "The Inspector: tree, box, style, frame and log of a running app" ON)
|
||||
@@ -563,20 +510,12 @@ foreach(_m settings:REAKTOR_SETTINGS:settings tray:REAKTOR_TRAY:tray
|
||||
endif()
|
||||
endforeach()
|
||||
if(REAKTOR_SETTINGS)
|
||||
target_sources(reaktor_settings INTERFACE "${TP}/toml-c/toml.c")
|
||||
target_include_directories(reaktor_settings INTERFACE "${TP}/toml-c")
|
||||
target_include_directories(reaktor_settings INTERFACE "${TP}/mglibs")
|
||||
if(EMSCRIPTEN)
|
||||
target_link_options(reaktor_settings INTERFACE -lidbfs.js
|
||||
"SHELL:--pre-js ${CMAKE_CURRENT_SOURCE_DIR}/tools/web-pre.js")
|
||||
endif()
|
||||
endif()
|
||||
# Linux and the BSDs speak StatusNotifierItem rather than take SDL's tray,
|
||||
# which loads GTK.
|
||||
if(REAKTOR_TRAY AND TARGET reaktor_gibus)
|
||||
target_compile_definitions(reaktor_tray INTERFACE REAKTOR_TRAY_DBUS)
|
||||
target_link_libraries(reaktor_tray INTERFACE reaktor_gibus)
|
||||
message(STATUS "tray: StatusNotifierItem")
|
||||
endif()
|
||||
|
||||
option(REAKTOR_NOTIFY "System notifications: a toast, a D-Bus notification, the browser's" ON)
|
||||
|
||||
@@ -598,12 +537,18 @@ else()
|
||||
target_sources(reaktor_notify INTERFACE "$<TARGET_OBJECTS:reaktor_notify_macos>")
|
||||
target_link_libraries(reaktor_notify INTERFACE
|
||||
"-framework Foundation" "-framework UserNotifications")
|
||||
elseif(TARGET reaktor_gibus)
|
||||
target_compile_definitions(reaktor_notify INTERFACE REAKTOR_HAVE_GIBUS)
|
||||
target_link_libraries(reaktor_notify INTERFACE reaktor_gibus)
|
||||
elseif(NOT EMSCRIPTEN)
|
||||
target_link_libraries(reaktor_notify INTERFACE reaktor_notify_none)
|
||||
message(STATUS "notify: no D-Bus on this system; notifications are not sent")
|
||||
find_package(PkgConfig QUIET)
|
||||
if(PkgConfig_FOUND AND NOT TARGET PkgConfig::REAKTOR_DBUS)
|
||||
pkg_check_modules(REAKTOR_DBUS QUIET IMPORTED_TARGET dbus-1)
|
||||
endif()
|
||||
if(TARGET PkgConfig::REAKTOR_DBUS)
|
||||
target_compile_definitions(reaktor_notify INTERFACE REAKTOR_HAVE_DBUS)
|
||||
target_link_libraries(reaktor_notify INTERFACE PkgConfig::REAKTOR_DBUS)
|
||||
else()
|
||||
target_link_libraries(reaktor_notify INTERFACE reaktor_notify_none)
|
||||
message(STATUS "notify: no dbus-1; notifications are not sent")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -635,8 +580,7 @@ add_library(reaktor_runtime STATIC
|
||||
core/anim/anim.c
|
||||
core/base/metrics.c
|
||||
core/css/style.c
|
||||
core/css/css.c
|
||||
core/render/damage.c
|
||||
core/css/cssflat.c
|
||||
core/render/draw.c
|
||||
core/ui/declare.c
|
||||
core/ui/controls.c
|
||||
@@ -660,16 +604,6 @@ add_library(reaktor_runtime STATIC
|
||||
runtime/window.c)
|
||||
target_compile_definitions(reaktor_runtime PRIVATE
|
||||
REAKTOR_VERSION_STRING="${PROJECT_VERSION}")
|
||||
if(TARGET reaktor_gibus)
|
||||
target_sources(reaktor_runtime PRIVATE
|
||||
${TP}/gibus/src/gibus_msg.c ${TP}/gibus/src/gibus_conn.c)
|
||||
# Its directory alone, and threads PUBLIC: a private link would put
|
||||
# $<LINK_ONLY:...> in what the shared library takes from the runtime's
|
||||
# INTERFACE_LINK_LIBRARIES.
|
||||
target_include_directories(reaktor_runtime PRIVATE ${TP}/gibus/include)
|
||||
target_compile_definitions(reaktor_runtime PRIVATE REAKTOR_HAVE_GIBUS)
|
||||
target_link_libraries(reaktor_runtime PUBLIC Threads::Threads)
|
||||
endif()
|
||||
|
||||
if(EMSCRIPTEN)
|
||||
target_sources(reaktor_runtime PRIVATE platform/web/keyboard_web.c)
|
||||
@@ -694,8 +628,9 @@ target_include_directories(reaktor_runtime PUBLIC
|
||||
|
||||
target_link_libraries(reaktor_runtime PUBLIC
|
||||
reaktor_core
|
||||
${REAKTOR_SDL}
|
||||
onlay)
|
||||
SDL3::SDL3-static
|
||||
onlay
|
||||
lcui)
|
||||
|
||||
if(WIN32 AND NOT EMSCRIPTEN)
|
||||
target_link_libraries(reaktor_runtime PUBLIC dxguid)
|
||||
@@ -703,7 +638,7 @@ endif()
|
||||
|
||||
set(REAKTOR_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "")
|
||||
|
||||
foreach(_lic SDL/LICENSE.txt plutosvg/LICENSE nuklear/LICENSE
|
||||
foreach(_lic SDL/LICENSE.txt lcui/LICENSE.TXT plutosvg/LICENSE nuklear/LICENSE
|
||||
nukanim/LICENSE onlay/LICENSE watercss/LICENSE.md ionicons/LICENSE mojibake/LICENSE
|
||||
kb/LICENSE)
|
||||
string(REGEX REPLACE "/.*" "" _who "${_lic}")
|
||||
@@ -714,86 +649,14 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/external/plutosvg/plutovg/LICENSE"
|
||||
"${CMAKE_BINARY_DIR}/licenses/plutovg.txt" COPYONLY)
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/external/freetype/docs/FTL.TXT"
|
||||
"${CMAKE_BINARY_DIR}/licenses/freetype.txt" COPYONLY)
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/external/toml-c/LICENSE"
|
||||
"${CMAKE_BINARY_DIR}/licenses/toml-c.txt" COPYONLY)
|
||||
if(TARGET reaktor_gibus)
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/external/gibus/LICENSE"
|
||||
"${CMAKE_BINARY_DIR}/licenses/gibus.txt" COPYONLY)
|
||||
endif()
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/external/mglibs/ini.h"
|
||||
"${CMAKE_BINARY_DIR}/licenses/ini.h.txt" COPYONLY)
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/LICENSE"
|
||||
"${CMAKE_BINARY_DIR}/licenses/reaktor.txt" COPYONLY)
|
||||
set(REAKTOR_APP_RESOURCES "${APP_RESOURCES}" CACHE INTERNAL "")
|
||||
|
||||
if(REAKTOR_SHARED)
|
||||
# The runtime, the core and the libraries under them; reaktor.map says
|
||||
# what they export. The modules stay in each app, which exports them back.
|
||||
# On macOS SDL goes in too, and ld64 takes the map as a list of names.
|
||||
set(_so_parts reaktor_runtime reaktor_core plutosvg plutovg freetype onlay)
|
||||
set(_so_files "")
|
||||
foreach(_t IN LISTS _so_parts)
|
||||
target_compile_options(${_t} PRIVATE -fno-semantic-interposition)
|
||||
endforeach()
|
||||
if(APPLE)
|
||||
list(APPEND _so_parts SDL3-static)
|
||||
endif()
|
||||
foreach(_t IN LISTS _so_parts)
|
||||
list(APPEND _so_files "$<TARGET_FILE:${_t}>")
|
||||
endforeach()
|
||||
file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/reaktor_so.c" CONTENT "")
|
||||
add_library(reaktor_shared SHARED "${CMAKE_BINARY_DIR}/reaktor_so.c")
|
||||
set_target_properties(reaktor_shared PROPERTIES
|
||||
VERSION ${PROJECT_VERSION} SOVERSION 1
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
|
||||
LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/tools/reaktor.map")
|
||||
add_dependencies(reaktor_shared ${_so_parts})
|
||||
if(APPLE)
|
||||
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/tools/reaktor.map" _map_lines)
|
||||
set(_exp "")
|
||||
foreach(_l IN LISTS _map_lines)
|
||||
if(_l MATCHES "^ *#" OR _l MATCHES "[{}:]")
|
||||
continue()
|
||||
endif()
|
||||
string(REGEX MATCHALL "[A-Za-z_][A-Za-z0-9_*]*" _names "${_l}")
|
||||
foreach(_n IN LISTS _names)
|
||||
string(APPEND _exp "_${_n}\n")
|
||||
endforeach()
|
||||
endforeach()
|
||||
string(APPEND _exp "_SDL_*\n")
|
||||
file(WRITE "${CMAKE_BINARY_DIR}/reaktor.exp" "${_exp}")
|
||||
set(_force "")
|
||||
foreach(_f IN LISTS _so_files)
|
||||
list(APPEND _force "-Wl,-force_load,${_f}")
|
||||
endforeach()
|
||||
set_target_properties(reaktor_shared PROPERTIES OUTPUT_NAME Reaktor
|
||||
FRAMEWORK TRUE FRAMEWORK_VERSION A
|
||||
MACOSX_FRAMEWORK_IDENTIFIER io.github.alpaq92.reaktor
|
||||
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${PROJECT_VERSION}
|
||||
MACOSX_FRAMEWORK_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||
INSTALL_NAME_DIR "@rpath"
|
||||
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/Frameworks")
|
||||
target_link_libraries(reaktor_shared PRIVATE ${_force}
|
||||
$<TARGET_PROPERTY:reaktor_runtime,INTERFACE_LINK_LIBRARIES>)
|
||||
target_link_options(reaktor_shared PRIVATE
|
||||
"-Wl,-exported_symbols_list,${CMAKE_BINARY_DIR}/reaktor.exp"
|
||||
"-Wl,-undefined,dynamic_lookup")
|
||||
target_link_libraries(reaktor_shared INTERFACE SDL3::Headers)
|
||||
else()
|
||||
set_target_properties(reaktor_shared PROPERTIES OUTPUT_NAME reaktor)
|
||||
target_link_libraries(reaktor_shared PRIVATE
|
||||
-Wl,--whole-archive ${_so_files} -Wl,--no-whole-archive
|
||||
$<TARGET_PROPERTY:reaktor_runtime,INTERFACE_LINK_LIBRARIES>)
|
||||
target_link_options(reaktor_shared PRIVATE
|
||||
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/tools/reaktor.map")
|
||||
target_link_libraries(reaktor_shared INTERFACE ${REAKTOR_SDL})
|
||||
endif()
|
||||
target_include_directories(reaktor_shared INTERFACE
|
||||
$<TARGET_PROPERTY:reaktor_runtime,INTERFACE_INCLUDE_DIRECTORIES>)
|
||||
target_compile_definitions(reaktor_shared INTERFACE
|
||||
$<TARGET_PROPERTY:reaktor_runtime,INTERFACE_COMPILE_DEFINITIONS>)
|
||||
endif()
|
||||
|
||||
function(reaktor_add_app name)
|
||||
cmake_parse_arguments(RA "CONSOLE;STATIC" "" "SOURCES;MODULES;ASSETS" ${ARGN})
|
||||
cmake_parse_arguments(RA "CONSOLE" "" "SOURCES;MODULES;ASSETS" ${ARGN})
|
||||
if(RA_CONSOLE)
|
||||
add_executable(${name} ${RA_SOURCES} ${REAKTOR_APP_RESOURCES})
|
||||
else()
|
||||
@@ -810,18 +673,7 @@ function(reaktor_add_app name)
|
||||
list(APPEND _mods reaktor_${_m}_none)
|
||||
endif()
|
||||
endforeach()
|
||||
# STATIC: a test that reaches past include/reaktor/ links the archives even
|
||||
# in a shared build, so libreaktor.so need not export what it reaches.
|
||||
if(REAKTOR_SHARED AND NOT RA_STATIC)
|
||||
target_link_libraries(${name} PRIVATE ${_mods} reaktor_shared)
|
||||
set_target_properties(${name} PROPERTIES ENABLE_EXPORTS ON)
|
||||
if(APPLE)
|
||||
# Kept through -dead_strip and visible to the framework's lookups.
|
||||
target_link_options(${name} PRIVATE -Wl,-export_dynamic)
|
||||
endif()
|
||||
else()
|
||||
target_link_libraries(${name} PRIVATE reaktor_runtime ${_mods})
|
||||
endif()
|
||||
target_link_libraries(${name} PRIVATE reaktor_runtime ${_mods})
|
||||
if(MSVC)
|
||||
target_compile_options(${name} PRIVATE /we4013)
|
||||
elseif(APPLE)
|
||||
@@ -885,16 +737,14 @@ reaktor_add_app(simple MODULES none SOURCES samples/simple/simple.c)
|
||||
reaktor_add_app(notepad MODULES settings popups print SOURCES samples/notepad/notepad.c)
|
||||
if(NOT EMSCRIPTEN)
|
||||
reaktor_add_app(bench MODULES none SOURCES samples/bench/bench.c)
|
||||
reaktor_add_app(launchtest STATIC MODULES settings popups print SOURCES tests/launchtest.c)
|
||||
reaktor_add_app(launchtest MODULES settings popups print SOURCES tests/launchtest.c)
|
||||
reaktor_add_app(uitest MODULES none SOURCES tests/uitest.c)
|
||||
reaktor_add_app(skiptest MODULES none SOURCES tests/skiptest.c)
|
||||
reaktor_add_app(damagetest STATIC MODULES none SOURCES tests/damagetest.c)
|
||||
reaktor_add_app(damagetest_text STATIC MODULES text SOURCES tests/damagetest.c)
|
||||
set_target_properties(launchtest PROPERTIES EXCLUDE_FROM_ALL ON)
|
||||
endif()
|
||||
|
||||
if(EMSCRIPTEN)
|
||||
target_compile_options(reaktor_runtime PRIVATE -Oz)
|
||||
target_compile_options(lcui PRIVATE -Oz)
|
||||
target_compile_options(plutovg PRIVATE -Oz)
|
||||
target_compile_options(plutosvg PRIVATE -Oz)
|
||||
target_compile_options(freetype PRIVATE -Oz)
|
||||
@@ -1004,7 +854,7 @@ endif()
|
||||
|
||||
if(MSVC)
|
||||
# Nuklear's NK_ALIGNOF takes the offset of a member of an unnamed struct.
|
||||
set_property(SOURCE core/render/nk_impl.c APPEND PROPERTY COMPILE_OPTIONS /wd4116)
|
||||
set_source_files_properties(core/render/nk_impl.c PROPERTIES COMPILE_OPTIONS /wd4116)
|
||||
# nuklear.h combines constants of different enums in its own declarations.
|
||||
target_compile_options(reaktor_headers INTERFACE /wd5287)
|
||||
target_compile_options(showcase PRIVATE /wd4101)
|
||||
@@ -1038,7 +888,7 @@ target_link_libraries(reaktor_modules PRIVATE reaktor_runtime reaktor_a11y reakt
|
||||
reaktor_inspector)
|
||||
set_target_properties(reaktor_modules PROPERTIES EXCLUDE_FROM_ALL ON)
|
||||
|
||||
set(_parts reaktor_runtime reaktor_core reaktor_modules plutosvg plutovg freetype onlay
|
||||
set(_parts reaktor_runtime reaktor_core reaktor_modules plutosvg plutovg freetype lcui onlay
|
||||
SDL3-static)
|
||||
foreach(_t mojibake_lib kb_text_shape)
|
||||
if(TARGET ${_t})
|
||||
@@ -1064,8 +914,7 @@ function(reaktor_outside_links)
|
||||
if(_real)
|
||||
set(_t ${_real})
|
||||
endif()
|
||||
# libreaktor.a carries SDL3-static in the shared SDL's place.
|
||||
if(_t IN_LIST _seen OR _t STREQUAL "SDL3-shared")
|
||||
if(_t IN_LIST _seen)
|
||||
continue()
|
||||
endif()
|
||||
list(APPEND _seen ${_t})
|
||||
@@ -1156,6 +1005,7 @@ function(reaktor_outside_links)
|
||||
endforeach()
|
||||
endwhile()
|
||||
|
||||
# A shared library found on this machine is named, so the package finds it on another.
|
||||
set(_named "")
|
||||
foreach(_l IN LISTS _libs)
|
||||
if(IS_ABSOLUTE "${_l}" AND _l MATCHES "/lib([^/]+)\\.(so|dylib|tbd)(\\.[0-9.]+)?$")
|
||||
@@ -1260,52 +1110,6 @@ add_custom_command(OUTPUT "${_lib}"
|
||||
VERBATIM)
|
||||
add_custom_target(libreaktor DEPENDS "${_lib}")
|
||||
|
||||
if(REAKTOR_SHARED)
|
||||
set(_mod_parts reaktor_modules)
|
||||
foreach(_t mojibake_lib kb_text_shape)
|
||||
if(TARGET ${_t})
|
||||
list(APPEND _mod_parts ${_t})
|
||||
endif()
|
||||
endforeach()
|
||||
set(_mod_lib "${CMAKE_BINARY_DIR}/lib/libreaktor-modules.a")
|
||||
if(APPLE)
|
||||
set(_mod_files "")
|
||||
foreach(_t IN LISTS _mod_parts)
|
||||
list(APPEND _mod_files "$<TARGET_FILE:${_t}>")
|
||||
endforeach()
|
||||
set(_mod_merge "${REAKTOR_LIBTOOL}" -static -o "${_mod_lib}" ${_mod_files})
|
||||
else()
|
||||
set(_mri "CREATE ${_mod_lib}\n")
|
||||
foreach(_t IN LISTS _mod_parts)
|
||||
string(APPEND _mri "ADDLIB $<TARGET_FILE:${_t}>\n")
|
||||
endforeach()
|
||||
string(APPEND _mri "SAVE\nEND\n")
|
||||
file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/reaktor-modules.mri" CONTENT "${_mri}")
|
||||
set(_mod_merge "${CMAKE_COMMAND}" "-DAR=${CMAKE_AR}"
|
||||
"-DMRI=${CMAKE_BINARY_DIR}/reaktor-modules.mri"
|
||||
-P "${CMAKE_CURRENT_SOURCE_DIR}/tools/merge-lib.cmake")
|
||||
endif()
|
||||
add_custom_command(OUTPUT "${_mod_lib}"
|
||||
COMMAND "${CMAKE_COMMAND}" -E make_directory "${CMAKE_BINARY_DIR}/lib"
|
||||
COMMAND "${CMAKE_COMMAND}" -E remove -f "${_mod_lib}"
|
||||
COMMAND ${_mod_merge}
|
||||
DEPENDS ${_mod_parts}
|
||||
COMMENT "Merging libreaktor-modules"
|
||||
VERBATIM)
|
||||
add_custom_target(libreaktor_modules DEPENDS "${_mod_lib}")
|
||||
add_dependencies(libreaktor reaktor_shared libreaktor_modules)
|
||||
if(REAKTOR_SHARED_SDL)
|
||||
add_dependencies(libreaktor SDL3-shared)
|
||||
# Both archives and libraries sit in one lib/: -l would pick the .so.
|
||||
set(REAKTOR_PC_LINK "-l:libreaktor.a")
|
||||
else()
|
||||
# A framework is not found by -l, so libreaktor.a still is.
|
||||
set(REAKTOR_PC_LINK "-lreaktor")
|
||||
endif()
|
||||
else()
|
||||
set(REAKTOR_PC_LINK "-lreaktor")
|
||||
endif()
|
||||
|
||||
option(REAKTOR_INSTALL "Install libreaktor's files" ${_reaktor_top})
|
||||
if(REAKTOR_INSTALL)
|
||||
include(CMakePackageConfigHelpers)
|
||||
@@ -1313,15 +1117,6 @@ if(REAKTOR_INSTALL)
|
||||
write_basic_package_version_file("${CMAKE_BINARY_DIR}/reaktorConfigVersion.cmake"
|
||||
COMPATIBILITY SameMinorVersion)
|
||||
install(FILES "${_lib}" DESTINATION lib COMPONENT libreaktor OPTIONAL)
|
||||
if(REAKTOR_SHARED)
|
||||
if(APPLE)
|
||||
install(TARGETS reaktor_shared FRAMEWORK DESTINATION Frameworks COMPONENT libreaktor)
|
||||
else()
|
||||
install(TARGETS reaktor_shared SDL3-shared
|
||||
LIBRARY DESTINATION lib COMPONENT libreaktor NAMELINK_COMPONENT libreaktor)
|
||||
endif()
|
||||
install(FILES "${_mod_lib}" DESTINATION lib COMPONENT libreaktor OPTIONAL)
|
||||
endif()
|
||||
install(DIRECTORY include/reaktor DESTINATION include COMPONENT libreaktor)
|
||||
install(FILES "${TP}/nuklear/nuklear.h" DESTINATION include COMPONENT libreaktor)
|
||||
install(FILES "${TP}/nukanim/nukanim.h" DESTINATION include COMPONENT libreaktor)
|
||||
@@ -1333,11 +1128,6 @@ if(REAKTOR_INSTALL)
|
||||
configure_file(tools/reaktor.pc.in "${CMAKE_BINARY_DIR}/reaktor.pc" @ONLY)
|
||||
install(FILES "${CMAKE_BINARY_DIR}/reaktor.pc" DESTINATION lib/pkgconfig
|
||||
COMPONENT libreaktor)
|
||||
if(REAKTOR_SHARED_SDL)
|
||||
configure_file(tools/reaktor-shared.pc.in "${CMAKE_BINARY_DIR}/reaktor-shared.pc" @ONLY)
|
||||
install(FILES "${CMAKE_BINARY_DIR}/reaktor-shared.pc" DESTINATION lib/pkgconfig
|
||||
COMPONENT libreaktor)
|
||||
endif()
|
||||
endif()
|
||||
install(DIRECTORY "${CMAKE_BINARY_DIR}/licenses/" DESTINATION share/reaktor/licenses
|
||||
COMPONENT libreaktor)
|
||||
|
||||
+30
-30
@@ -1,28 +1,28 @@
|
||||
# Contributing
|
||||
|
||||
Pull requests are welcome, and so is an issue that says "this looks wrong"
|
||||
with a screenshot.
|
||||
Pull requests are welcome, and so is an issue that just says "this looks
|
||||
wrong" with a screenshot.
|
||||
|
||||
## Getting started
|
||||
|
||||
```bash
|
||||
git submodule update --init --recursive
|
||||
./build.sh # build.ps1 on Windows
|
||||
for t in $(cat tools/ci/tests.txt); do ./build/$t || break; done
|
||||
for t in laytest onlaytest a11ytest animtest keytest localetest texttest
|
||||
do ./build/$t || break; done
|
||||
```
|
||||
|
||||
`tools/ci/tests.txt` lists the console tests CI runs; `sh tools/ci/uitest.sh
|
||||
build` runs the scripted ones. `./build-wasm.sh` builds the web target from the
|
||||
same sources and catches what the native build lets through; run it before
|
||||
sending anything. [docs/DOCUMENTATION.md](docs/DOCUMENTATION.md) is the map:
|
||||
read its [Nuklear traps](docs/DOCUMENTATION.md#nuklear-traps) before touching
|
||||
drawing code.
|
||||
`./build-wasm.sh` builds the web target from the same sources and catches what
|
||||
the native build lets through; run it before sending anything.
|
||||
[docs/DOCUMENTATION.md](docs/DOCUMENTATION.md) is the map — read its
|
||||
[Nuklear traps](docs/DOCUMENTATION.md#nuklear-traps) before touching drawing
|
||||
code.
|
||||
|
||||
## Conventions
|
||||
|
||||
- **C99, portable, no compiler extensions.** A platform subsystem goes in
|
||||
`platform/`; a single platform fact goes behind `_WIN32`, `__APPLE__`,
|
||||
`__linux__` or `__EMSCRIPTEN__` where needed.
|
||||
`__linux__` or `__EMSCRIPTEN__` where it is needed.
|
||||
- **Around 79 columns**, four-space indent, no tabs, American English.
|
||||
- **Few comments.** One line, and only where removing it would invite a bug.
|
||||
- **`reaktor_` prefixes anything crossing a translation unit**; everything
|
||||
@@ -34,45 +34,45 @@ Binding unless you make the case for changing one.
|
||||
|
||||
- **Submodules are read, never edited, never quoted.** No value is copied out
|
||||
of `external/`; the app opens the file at run time. The only vendored source
|
||||
is `core/render/nk_sdl3_renderer.h`, every deviation marked `REAKTOR`. The
|
||||
only bytes compiled in are `REAKTOR_BUILTINS`.
|
||||
is `core/render/nk_sdl3_renderer.h`, with every deviation marked `REAKTOR`.
|
||||
The only bytes compiled in are `REAKTOR_BUILTINS`.
|
||||
- **The stylesheet is the source of style.** A color, radius, border or
|
||||
padding written as a C literal needs a reason beside it, such as a fallback
|
||||
for a sheet that failed to load.
|
||||
padding written as a literal in C needs a reason beside it, such as a
|
||||
fallback for a sheet that failed to load.
|
||||
- **Permissive licenses only, MIT preferred.** Record a dependency in
|
||||
[docs/NOTICE.md](docs/NOTICE.md) in the same change, from the project's own
|
||||
license file. A vendored asset carries its terms in the tree;
|
||||
`assets/fonts/Aileron-Notice.txt` is the shape to copy.
|
||||
- **An optional feature is a module**: an interface library, a `_none` twin
|
||||
defining the same functions, and a `REAKTOR_<NAME>` option, `ON` by default.
|
||||
Off, a build draws the same pixels and writes the same `--a11y-dump`, except
|
||||
for what the module itself produces.
|
||||
Switched off, a build draws the same pixels and writes the same
|
||||
`--a11y-dump`, except for what the module itself produces.
|
||||
- **Nothing is drawn when nothing has changed.** No timers, polling or
|
||||
unconditional repaints; mark what changed.
|
||||
- **Every asset goes through `reaktor_asset_load()`**: a name under the
|
||||
`.reaktor-root` marker, then the compiled-in copies, never the working
|
||||
directory. No network fetches.
|
||||
- **No environment variables.** An override is a command-line flag the
|
||||
runtime strips from `argv`.
|
||||
- **Every asset goes through `reaktor_asset_load()`**, which resolves a name
|
||||
under the `.reaktor-root` marker, then the compiled-in copies, never the
|
||||
working directory. No network fetches.
|
||||
- **No environment variables.** Anything worth overriding is a command-line
|
||||
flag the runtime strips from `argv`.
|
||||
|
||||
## Saying what you verified
|
||||
|
||||
In the pull request:
|
||||
|
||||
- that native and WebAssembly build and the tests pass;
|
||||
- that native and WebAssembly both build and the tests pass;
|
||||
- **the accessibility dump before and after**, if anything moved: run with
|
||||
`--a11y-dump <path>` and diff the two;
|
||||
- a screenshot of a visible change, pinned with `--tab`, `--scroll` and
|
||||
- a screenshot for a visible change, pinned with `--tab`, `--scroll` and
|
||||
`--theme` and written by `--shot`.
|
||||
|
||||
The framebuffer proves a visual fix, not reasoning from the source that drew
|
||||
it wrong. A performance claim needs a number from the Diagnostics page or
|
||||
`bench --no-vsync`, and a claim against another framework needs
|
||||
A visual fix is proven by the framebuffer, not by reasoning from the source
|
||||
that drew it wrong. A performance claim needs a number from the Diagnostics
|
||||
page or `bench --no-vsync`, and a claim against another framework needs
|
||||
`benchmarks/run.ps1`; several plausible optimizations here measured worse.
|
||||
|
||||
## Review
|
||||
|
||||
Automated review is a first pass. It finds a missing bounds check, not that a
|
||||
widget is drawn as it is because the alternative was tried and looked wrong.
|
||||
For a change to layout, styling or frame pacing, say what you tried and how it
|
||||
looked.
|
||||
Automated review is a first pass. It finds a missing bounds check, but not that
|
||||
a widget is drawn as it is because the alternative was tried and looked wrong.
|
||||
For a change to layout, styling or frame pacing, say what you tried and what
|
||||
it looked like.
|
||||
|
||||
@@ -1,527 +0,0 @@
|
||||
# Plan: libreaktor as a shared library
|
||||
|
||||
> **Finished.** Every phase below has shipped; this is the record of how, and
|
||||
> it no longer describes the code. Since it was written the soname became
|
||||
> `libreaktor.so.1` (runtime package `libreaktor1`, ABI tables
|
||||
> `tools/abi/libreaktor.so.1-*.abi`), the packages became `libreaktor`
|
||||
> (static) and `libreaktor-shared` (the split's development package), and
|
||||
> the release archives `libreaktor-*` and `libreaktor-shared-*`. The current
|
||||
> state is in [DOCUMENTATION.md](docs/DOCUMENTATION.md#in-your-own-project),
|
||||
> the measurements in [PERFORMANCE.md](docs/PERFORMANCE.md).
|
||||
|
||||
**Decision (2026-11-02): go.** Three apps together save 14.8%, under the 20%
|
||||
threshold, but four save 20.4% and five 24.2% (Phase 0d), and Reaktor apps
|
||||
are expected to run four or more at a time. Phase 1 starts. Static stays the
|
||||
default.
|
||||
|
||||
## Where things stand
|
||||
|
||||
- **libreaktor is static only.** CMake merges its parts into `libreaktor.a`
|
||||
(`CMakeLists.txt`, the `libreaktor` target), and `tools/libreaktor-pkg.sh`
|
||||
packs it with the headers as a .deb, .rpm, BSD package or .tar.gz.
|
||||
`tools/ci/check-libreaktor.sh` links `examples/consumer` against it.
|
||||
- **No shared-library code exists yet.** No `.so`, no soname, no shared SDL.
|
||||
- **Static stays the default** whatever this plan decides. A shared library is
|
||||
offered beside it, not instead of it.
|
||||
|
||||
## Why consider it at all
|
||||
|
||||
An app is a few MB (stripped Linux showcase: 3.97 MB; 4.3 MB private and
|
||||
11.4 MB resident at run time). On Windows and macOS each app ships alone, so
|
||||
sharing buys little there. The gain is in Linux and BSD packages, where several
|
||||
Reaktor apps could install one copy of the library and share its code pages in
|
||||
memory.
|
||||
|
||||
Two copies of the *same* app already share their code, static or not. A shared
|
||||
library only saves when *different* apps run together, and at most it saves
|
||||
libreaktor's resident code per extra app. Heap, glyph atlases and stylesheets
|
||||
stay private either way. So the saving may be small, and that is why Phase 0
|
||||
measures it before anything is built.
|
||||
|
||||
## Decisions already made (2026-10-24)
|
||||
|
||||
1. **SDL: our own build, shared, under its own name** (option B), for example
|
||||
`libreaktor-sdl3.so`. Built as now: GL out, dynamic API off. Not the
|
||||
distro's SDL, because that:
|
||||
- can load Mesa and LLVM again (the 123.6 MB Linux start in
|
||||
`docs/PERFORMANCE.md`);
|
||||
- sets a minimum SDL version on every distro;
|
||||
- can draw different pixels per distro;
|
||||
- brings `SDL3_DYNAMIC_API` back.
|
||||
2. **Nuklear's struct layouts are part of the ABI.** Apps reach them through
|
||||
the `reaktor/nuklear.h` macros and by reading `ctx->style`, `ctx->input`,
|
||||
`ctx->current` and `ctx->last_widget_state`. Hiding all of that would be a
|
||||
large job for no real gain, since Nuklear is a pinned submodule whose
|
||||
layout changes only when we bump it. Instead, a CI table of `sizeof` and
|
||||
`offsetof` values forces a new soname whenever a layout changes.
|
||||
3. **Style access is settled.** Apps keep `ctx->style`. Three public calls
|
||||
cover the most common reads for clarity: `reaktor_item_spacing`,
|
||||
`reaktor_text_color`, `reaktor_current_font`. Done and merged (`5a8b7f3`).
|
||||
4. **Platforms, in order:** Linux and the BSDs first. Windows was dropped
|
||||
(2026-11-03; see *Later*). macOS (same Team ID, or Homebrew only, since
|
||||
hardened-runtime library validation refuses other developers' dylibs) is
|
||||
in scope at lower priority.
|
||||
|
||||
## Phase 0: measure (go / no-go)
|
||||
|
||||
Goal: know what sharing would save before writing any of it. Needs no new
|
||||
library code.
|
||||
|
||||
1. Build `showcase`, `notepad` and `simple` statically on Linux, as now.
|
||||
2. Run the three together. For each process record, from
|
||||
`/proc/<pid>/smaps_rollup` and `/proc/<pid>/smaps`:
|
||||
- total `Pss`;
|
||||
- `Shared_Clean` and `Private_Clean` of the app's own binary mapping,
|
||||
which is roughly libreaktor's resident code.
|
||||
3. Estimate the shared case: summed PSS minus the libreaktor code that the
|
||||
second and third app would no longer carry.
|
||||
4. Ten launches, medians, as elsewhere in `docs/PERFORMANCE.md`. The numbers
|
||||
go there, with the machine named.
|
||||
5. Put it in a script, `tools/ci/pss.sh`, run in the Debian container that
|
||||
`linux.yml` already uses, so it can be repeated.
|
||||
|
||||
**Go / no-go threshold (agreed 2026-10-30):** go if three different
|
||||
apps running together save at least **20% of their summed PSS**. Disk space
|
||||
does not count toward it; smaller packages would be a separate argument.
|
||||
|
||||
## Phase 0 results (CI, 2026-10-30)
|
||||
|
||||
**What was measured.** `showcase`, `notepad` and `simple` run together, idle,
|
||||
for 10 seconds; ten launches, medians. For each app:
|
||||
|
||||
- **PSS** from `/proc/<pid>/smaps_rollup`: memory it has to itself in full,
|
||||
plus its share of pages it shares with other processes.
|
||||
- **Library pages**: the resident pages of its own binary that hold libreaktor
|
||||
or SDL. Today each app links them statically, so each carries a copy.
|
||||
|
||||
A shared `libreaktor.so` would hold one copy for all three. The saving is the
|
||||
three apps' library pages minus the largest app's, as a share of their summed
|
||||
PSS.
|
||||
|
||||
**Machine.** GitHub `ubuntu-24.04` runner, x86_64, Debian 12 container, GCC
|
||||
Release, Xvfb, no GPU.
|
||||
|
||||
**Two estimates.**
|
||||
|
||||
1. `tools/ci/pss.sh` counts every clean page of each binary as library, so it
|
||||
overcounts by the apps' own code: **21.3%**.
|
||||
|
||||
| | PSS | Clean pages of its binary |
|
||||
| --- | --- | --- |
|
||||
| `showcase` | 9,180 KB | 2,796 KB |
|
||||
| `notepad` | 5,957 KB | 2,208 KB |
|
||||
| `simple` | 5,251 KB | 2,164 KB |
|
||||
|
||||
Summed PSS 20,433 KB; sharing saves 4,366 KB.
|
||||
|
||||
2. `tools/ci/pss-pages.sh` links the three with linker maps and sorts each
|
||||
resident, file-backed page of a binary (from `/proc/<pid>/pagemap`) by the
|
||||
object it came from. Only a page holding nothing but libreaktor or SDL
|
||||
counts: **20.2%**.
|
||||
|
||||
| | PSS | lib | app | mixed | other |
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
| `showcase` | 9,105 KB | 2,386 KB | 170 KB | 32 KB | 144 KB |
|
||||
| `notepad` | 6,028 KB | 2,090 KB | 16 KB | 24 KB | 132 KB |
|
||||
| `simple` | 5,217 KB | 2,018 KB | 0 KB | 28 KB | 128 KB |
|
||||
|
||||
Summed PSS 20,423 KB; sharing saves 4,120 KB.
|
||||
|
||||
**Still an upper bound.** It assumes the smaller apps use no library page the
|
||||
showcase does not, and leaves out what the dynamic linker costs each app at
|
||||
start (relocations, private GOT pages). Both pull the real figure down, most
|
||||
likely under 20%.
|
||||
|
||||
**Reading.** About 4 MB saved across three apps, on the line. Recommendation
|
||||
so far: no-go, pending a run on a real Linux desktop.
|
||||
|
||||
## Phase 0 results (Linux desktop, 2026-11-02)
|
||||
|
||||
**Machine.** Linux Mint 22.3, Cinnamon on X11, Mesa llvmpipe (no GPU), a KVM
|
||||
guest on an AMD Ryzen 5 4600H with 4 cores, kernel 7.0, GCC Release. Same
|
||||
three apps, ten launches, medians.
|
||||
|
||||
1. `pss.sh`: **19.0%**. Summed PSS 24,157 KB; sharing saves 4,602 KB.
|
||||
|
||||
| | PSS | Clean pages of its binary |
|
||||
| --- | --- | --- |
|
||||
| `showcase` | 14,224 KB | 2,898 KB |
|
||||
| `notepad` | 5,386 KB | 2,322 KB |
|
||||
| `simple` | 4,553 KB | 2,262 KB |
|
||||
|
||||
2. `pss-pages.sh`: **17.3%**. Summed PSS 24,200 KB; sharing saves 4,176 KB.
|
||||
|
||||
| | PSS | lib | app | mixed | other |
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
| `showcase` | 14,282 KB | 2,606 KB | 232 KB | 32 KB | 148 KB |
|
||||
| `notepad` | 5,382 KB | 2,124 KB | 80 KB | 24 KB | 136 KB |
|
||||
| `simple` | 4,516 KB | 2,064 KB | 36 KB | 24 KB | 132 KB |
|
||||
|
||||
**Reading.** As expected, the desktop stacks grow the showcase's PSS by about
|
||||
5 MB, while the library pages stay at about 4 MB. Both estimates are upper
|
||||
bounds, and both are under 20%. **No-go**, unless a run on real GPU hardware
|
||||
differs.
|
||||
|
||||
## Phase 0b: a real shared build, measured (2026-11-02)
|
||||
|
||||
The estimates above are upper bounds, so a working prototype was built to
|
||||
measure the real difference. `-DREAKTOR_SHARED_PROTO=ON` (with
|
||||
`-DCMAKE_POSITION_INDEPENDENT_CODE=ON`) links the runtime, the core, SDL,
|
||||
FreeType, plutosvg, plutovg and onlay into `libreaktor-proto.so`; each sample
|
||||
keeps its modules (or their `_none` twins) and exports their symbols back to
|
||||
the library. No soname, no hidden symbols: everything is exported, which is
|
||||
the worst case for relocations and calls.
|
||||
|
||||
Same desktop as above; ten launches, medians, static and shared measured in
|
||||
the same session.
|
||||
|
||||
**Memory** (`pss.sh`, the three apps together, idle):
|
||||
|
||||
| | static | shared | saved |
|
||||
| --- | --- | --- | --- |
|
||||
| `showcase` | 14,261 KB | 13,007 KB | 1,254 KB |
|
||||
| `notepad` | 5,370 KB | 4,239 KB | 1,131 KB |
|
||||
| `simple` | 4,501 KB | 3,453 KB | 1,048 KB |
|
||||
| **summed** | **24,152 KB** | **20,698 KB** | **3,454 KB (14.3%)** |
|
||||
|
||||
The library's pages that each app dirties (GOT, relocated data) are about
|
||||
124 KB per app in `simple`.
|
||||
|
||||
**Disk:** 11.4 MB for the three static binaries, against 6.2 MB shared
|
||||
(`libreaktor-proto.so` 5.0 MB, unstripped, plus 1.16 MB of apps).
|
||||
|
||||
**Start:** the dynamic loader takes 0.1 to 0.2 ms for either build;
|
||||
`showcase` goes from 19,525 to 21,709 relocations. CPU in the first 3
|
||||
seconds: `simple` 40 ms both, `showcase` 220 ms static and 230 ms shared.
|
||||
|
||||
**Frame cost** (`bench --no-vsync`, five runs):
|
||||
|
||||
| | build | render | whole frame |
|
||||
| --- | --- | --- | --- |
|
||||
| static | 0.04 ms | 0.05 ms | 1.46 to 1.63 ms |
|
||||
| shared | 0.05 ms | 0.10 ms | 1.48 to 1.53 ms |
|
||||
| shared, `-fno-semantic-interposition` | 0.04 ms | 0.08 ms | 1.40 to 1.61 ms |
|
||||
| shared, that and `-Wl,-Bsymbolic-functions` | 0.04 ms | 0.06 ms | as static |
|
||||
|
||||
Present (llvmpipe) dominates the frame, so fps does not change.
|
||||
|
||||
**Why the shared build was slower** (`perf`, both builds):
|
||||
|
||||
- **Frame.** The extra render time is in `nk_sdl_render_ex`, Nuklear's
|
||||
SDL drawing loop. With every symbol exported and interposable, GCC stops
|
||||
inlining and specialising small functions inside SDL and Nuklear:
|
||||
`SDL_floorf`, `SDL_roundf`, `SDL_memcmp`, `nk_buffer_memory`, `nk_vec2`
|
||||
become real calls, and the `.constprop`/`.isra` clones go. Calls between
|
||||
files then go through the PLT. `-fno-semantic-interposition` restores the
|
||||
inlining (build back to static); `-Bsymbolic-functions` binds the calls
|
||||
inside the library directly (render back to static). Hidden symbols
|
||||
(Phase 1, item 2) do both, so Phase 1 needs no extra flags.
|
||||
- **Start.** `showcase` uses about 10 ms more CPU in its first 3 s
|
||||
(`perf stat -r 10`: 222 against 232 ms), split about evenly between user
|
||||
and kernel time, with the same page faults (4,170 against 4,199). Lazy
|
||||
binding in the dynamic loader (`_dl_fixup`, `_dl_lookup_symbol_x`) is
|
||||
about 0.3 ms of it; the rest is the slower code above running during start
|
||||
(font rasterising, the first frames) and the kernel mapping one more
|
||||
library. With both flags the difference falls inside run-to-run noise
|
||||
(225 against 234 ms in one pass).
|
||||
|
||||
**Reading.** The real saving is 14.3%, under the 20% threshold and under the
|
||||
17.3% estimate. As built first it cost about 10 ms of start CPU in the showcase
|
||||
and twice Reaktor's render time; with hidden or directly bound symbols both
|
||||
costs go away. The disk saving
|
||||
(46%) is the stronger argument, but it was agreed not to count toward the
|
||||
threshold.
|
||||
|
||||
## Phase 0c: the same, with hidden symbols (2026-11-02)
|
||||
|
||||
`-DREAKTOR_SHARED_PROTO_HIDE=ON` adds a version script that exports only
|
||||
`reaktor_*`, `nk_*`, `nka_*`, `SDL_*` and the five FreeType and plutovg
|
||||
symbols the modules call, and compiles the library's parts with
|
||||
`-fno-semantic-interposition`. Everything else (X11 and Wayland glue,
|
||||
FreeType's and plutovg's insides) binds inside the library. Exports fall from
|
||||
4,653 to 3,365; SDL's own API is 1,961 of them, as it would be as
|
||||
`libreaktor-sdl3.so`. Every sample starts with `LD_BIND_NOW=1`, so nothing
|
||||
it needs is hidden.
|
||||
|
||||
| | static | shared | shared, hidden |
|
||||
| --- | --- | --- | --- |
|
||||
| summed PSS, three apps | 24,152 KB | 20,698 KB | 20,617 KB |
|
||||
| saving against static | | 14.3% | 14.6% |
|
||||
| library pages each app dirties (`simple`) | | 124 KB | 116 KB |
|
||||
| `showcase` relocations | 19,525 | 21,709 | 20,559 |
|
||||
| `bench` build / render | 0.04 / 0.06 ms | 0.05 / 0.10 ms | 0.04 / 0.08 ms |
|
||||
| `showcase` CPU, first 3 s | 216 to 222 ms | 225 to 232 ms | 224 to 230 ms |
|
||||
|
||||
**Reading.** Hiding symbols does not move memory: 81 KB of 20.7 MB. The
|
||||
saving stays at about 14.5%. It does recover build time, and half the render
|
||||
time. The rest of render is the calls into SDL, which go through the PLT
|
||||
because SDL's API stays exported. With SDL as its own library, as decided,
|
||||
that cost stays. Binding SDL inside libreaktor (`-Bsymbolic-functions`,
|
||||
Phase 0b) removes it, but then an app cannot have SDL from anywhere else.
|
||||
|
||||
**Seen and not explained:** in three of six early runs of `pss.sh` on this
|
||||
build, `notepad` had exited by the time it was measured, with nothing in its
|
||||
log. A signal, a closed window, Ctrl+Q and the menu's Quit all end it exactly
|
||||
so: status 0, empty log; a crash would have left a core dump and a kernel
|
||||
line, and there was neither. Since then the runtime logs one `quitting:` line
|
||||
with the reason, and `pss.sh` prints how each app ended. A soak of 15 rounds
|
||||
of ten launches for the hidden build and 15 for the static one, alternating,
|
||||
ran clean (300 launches each of the three apps). Not reproduced; most likely
|
||||
something on the live desktop asked notepad to quit.
|
||||
|
||||
## Phase 0d: more apps at once (2026-11-02)
|
||||
|
||||
The saving grows with each extra app, since each one stops carrying its own
|
||||
copy of the library. `pss.sh -a` takes the list of apps. The fourth and fifth
|
||||
apps are copies of `notepad` and `simple` under new names (`notepad2`,
|
||||
`simple2`): a copy is another file, so statically it shares nothing with the
|
||||
original, as a different app would not. Hidden-symbol shared build against
|
||||
static, same desktop, ten launches, medians.
|
||||
|
||||
| apps together | static | shared | saved | saving |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 3 (`showcase`, `notepad`, `simple`) | 24,200 KB | 20,630 KB | 3,570 KB | 14.8% |
|
||||
| 4 (+ `notepad2`) | 29,802 KB | 23,726 KB | 6,076 KB | **20.4%** |
|
||||
| 5 (+ `simple2`) | 34,437 KB | 26,087 KB | 8,350 KB | **24.2%** |
|
||||
|
||||
Each extra app saves about 2.3 to 2.5 MB: its own library pages, and a
|
||||
little of everyone else's PSS as the shared pages split one more way.
|
||||
|
||||
**Reading.** With four different Reaktor apps running together, sharing
|
||||
crosses the 20% threshold; with five it saves about a quarter. With three it
|
||||
does not. Real different apps carry a little more code of their own than
|
||||
these copies, which pulls the figures down slightly. Whether to go now turns
|
||||
on how many Reaktor apps a user would really run at once.
|
||||
|
||||
## Running Phase 0 on a Linux desktop
|
||||
|
||||
Needs GCC with GNU ld from binutils 2.38 or later (`-Map=DIR/` writes one map
|
||||
per program; not lld or gold), CMake, Ninja, `readelf`, GNU `dd` and `od`, a
|
||||
kernel with `smaps_rollup` (4.14+). No root needed: an unprivileged
|
||||
`pagemap` read still has the present and file-page bits.
|
||||
|
||||
From the checkout, on branch `shared-phase0`:
|
||||
|
||||
```sh
|
||||
git submodule update --init --recursive
|
||||
./build.sh # build/showcase, build/notepad, build/simple
|
||||
sh tools/ci/pss.sh build # estimate 1, on the desktop's own display
|
||||
sh tools/ci/pss-pages.sh # estimate 2; builds build-map with maps first
|
||||
```
|
||||
|
||||
Without `-x` both run on the current `DISPLAY` (or Wayland), which is the
|
||||
point of a desktop run. `-x Xvfb` starts a virtual display instead, as CI does;
|
||||
`-n RUNS` changes the ten launches; `-w WRAP` runs each app under a wrapper.
|
||||
Close any running Reaktor app first: the showcase is single instance, so a
|
||||
running copy would take its launch, and another app's pages would skew PSS.
|
||||
|
||||
Output lands in `smoke/pss/` and `smoke/pss-pages/`: `runs.txt` holds each
|
||||
launch's raw numbers (kB), `saving.txt` the per-launch saving, and each app's
|
||||
`.log` its output. The last lines printed are the medians and the saving
|
||||
against 20%.
|
||||
|
||||
Worth noting with the result: distribution, desktop (X11 or Wayland), GPU or
|
||||
not, and whether the numbers differ from CI's. A desktop run loads the real
|
||||
input-method, accessibility and tray stacks, so PSS grows and the percentage is
|
||||
likely to fall.
|
||||
|
||||
## Phase 1: the shared build (started 2026-11-02)
|
||||
|
||||
**Status.** Items 1 to 4 are in: `-DREAKTOR_SHARED=ON` builds
|
||||
`lib/libreaktor.so.0` (2.0 MB) and `libreaktor-sdl3.so.0` (2.9 MB, SDL 3.4.18
|
||||
with `core/sdl/no_dynapi.h` as for the static build) beside `libreaktor.a`,
|
||||
and links the samples and tests to them. Exports come from a version script,
|
||||
`tools/reaktor.map`, not an export macro: 1,185 symbols, all `reaktor_`, `nk_`,
|
||||
`nka_` and the five FreeType and plutovg calls the modules make. The modules
|
||||
reach some `reaktor_` functions that are not in `include/reaktor/`, so for now
|
||||
the `reaktor_*` glob exports those too; Phase 2's symbol check will draw the
|
||||
line. The measurement prototype (`REAKTOR_SHARED_PROTO`, commit `0948611`) is
|
||||
gone.
|
||||
|
||||
Measured as in Phase 0d: three apps 24,200 KB static against 20,659 KB
|
||||
shared (14.6%), four 29,802 KB against 23,810 KB (20.1%). `bench` build and
|
||||
render 0.05 and 0.08 ms; `showcase` CPU in its first 3 s 232 ms, static 231 ms.
|
||||
All unit tests pass in both builds.
|
||||
|
||||
Item 5 is in too. With `REAKTOR_SHARED`, `cmake --install` adds to the
|
||||
static files `libreaktor.so*`, `libreaktor-sdl3.so*` and
|
||||
`libreaktor-modules.a`, the modules (and mojibake and kb_text_shape) for apps
|
||||
built outside the tree. Such an app links `libreaktor.so`, then the modules
|
||||
archive, which fills in what the library calls, then `libreaktor-sdl3.so`,
|
||||
and exports the modules back with `-Wl,--export-dynamic`. That is what
|
||||
`reaktor-shared.pc` and the CMake target `reaktor::shared` give it; in CMake,
|
||||
`reaktor::reaktor` stays the static one. Since the `.a` and the `.so` share a
|
||||
`lib/`, `reaktor.pc` then names `-l:libreaktor.a`, so it stays static.
|
||||
|
||||
Checked by hand: `examples/consumer` linked statically, linked with
|
||||
`-DCONSUMER_SHARED=ON`, and `simple.c` built with `pkg-config reaktor` and
|
||||
`reaktor-shared` all draw the same pixels and the same accessibility tree as
|
||||
the tree's own `simple`. Phase 2, item 3 puts that into `check-libreaktor.sh`.
|
||||
|
||||
|
||||
1. A `REAKTOR_SHARED` option, default `OFF`, building `libreaktor.so` with a
|
||||
soname (`libreaktor.so.0`) beside the static archive.
|
||||
2. Only the `include/reaktor/` API exported; everything else hidden
|
||||
(`-fvisibility=hidden` and an export macro on the public declarations).
|
||||
3. SDL built as `libreaktor-sdl3.so`, which `libreaktor.so` links.
|
||||
4. Optional modules keep working: an app still links a module or its `_none`
|
||||
twin, so each module's code stays out of the shared core.
|
||||
5. `reaktor.pc` and `reaktorConfig.cmake` learn the shared variant.
|
||||
|
||||
## Phase 2: keeping the ABI honest (in, 2026-11-02)
|
||||
|
||||
**Status.** All three items are in, and CI's x86-64 job runs them in a step
|
||||
of its own (`Shared libreaktor`) on a `-DREAKTOR_SHARED=ON` build:
|
||||
|
||||
- `tools/ci/check-abi.sh` compiles `tools/abi/abi.c` (just `reaktor.h`) with
|
||||
debug types and has gdb print, with `ptype /o`, every `reaktor_` struct,
|
||||
union and enum in `include/reaktor/`, `nk_window` and `nk_input`, every
|
||||
Nuklear type `reaktor/nuklear.h` renames, and the value of every `NK_`
|
||||
constant it renames. Nothing is copied out of Nuklear by hand. The output
|
||||
must match `tools/abi/libreaktor.so.0-ARCH.abi`, ARCH being the compiler's
|
||||
target (`cc -dumpmachine`); otherwise the soname must go up and the table be
|
||||
rewritten with `-u`. Adding one field to `reaktor_shortcut` fails it. Only
|
||||
x86_64 has a table so far (12,266 lines, made here). Every native Linux job
|
||||
(x86-64, x86, arm64) runs the check in a step of its own and uploads what it
|
||||
wrote to `smoke/abi/`; a missing table is a warning, exit status 3, so the
|
||||
x86 and arm64 tables, and the x86_64 one if CI's older gdb lays it out
|
||||
differently, come from CI's artifact.
|
||||
- `tools/ci/check-exports.sh` holds the built library to `tools/reaktor.map`,
|
||||
which lists Reaktor's names instead of `reaktor_*`. Two symbol versions:
|
||||
`LIBREAKTOR_0` holds the 149 public functions the library defines and
|
||||
Nuklear's and nukanim's APIs; `LIBREAKTOR_PRIVATE_0` the 34 non-public calls
|
||||
the modules make and five FreeType and plutovg ones. It fails on a name
|
||||
exported but not listed, listed but not exported, public but in neither the
|
||||
library nor the modules, under `LIBREAKTOR_0` without being public, private
|
||||
and no longer called by the modules, private and called by an app's own
|
||||
code (samples and tests linked to the library), or under the wrong version.
|
||||
`tests/launchtest.c`, which reaches past `include/reaktor/`, links the
|
||||
archives in a shared build (`reaktor_add_app(... STATIC ...)`), so nothing
|
||||
is exported for a test. Exports fell from 1,185 to 1,030.
|
||||
- `check-libreaktor.sh` links `examples/consumer` against `libreaktor.so`
|
||||
too, where the install has it, checks the program needs it, and requires
|
||||
the same pixels and accessibility tree as the built `simple`.
|
||||
|
||||
|
||||
1. The CI `sizeof` / `offsetof` table for the Nuklear structs apps can see,
|
||||
and for Reaktor's own public structs. A change fails CI until the soname
|
||||
is bumped and the table regenerated.
|
||||
2. A check that the exported symbol list matches `include/reaktor/`, so
|
||||
nothing internal leaks out and nothing public is missing.
|
||||
3. `check-libreaktor.sh` gains a shared run: `examples/consumer` linked
|
||||
against the `.so` must draw the same pixels as the static `simple`.
|
||||
|
||||
## Phase 3: packages (in, 2026-11-02)
|
||||
|
||||
**Status.** `tools/libreaktor-pkg.sh -s` builds with `REAKTOR_SHARED` (and
|
||||
`-b` takes a shared build as it is). When the install holds `libreaktor.so`,
|
||||
the package splits in three: `libreaktor-sdl3-0` (`libreaktor-sdl3.so.0*`
|
||||
and SDL's license), `libreaktor0` (`libreaktor.so.0*`, the other licenses,
|
||||
`NOTICE.md`; needs the first) and the development package under its old
|
||||
name (`libreaktor-dev`, `libreaktor-devel`, `libreaktor` on the BSDs) with
|
||||
the headers, both archives, the `.so` links, `reaktor.pc`,
|
||||
`reaktor-shared.pc` and the CMake files; it needs both. Each file is in one
|
||||
package. A static build packs one package, renamed `libreaktor-static` in
|
||||
every format (2026-11-03), so a release can carry both; it and the split's
|
||||
development package install the same headers and conflict with each other
|
||||
in every format. `/opt/reaktor/lib` is
|
||||
not on the loader's path, so `reaktor-shared.pc` and `reaktor::shared` add
|
||||
an rpath to the install's `lib/`.
|
||||
|
||||
Checked here: the three `.deb`s, their dependencies and files, and
|
||||
`examples/consumer -DCONSUMER_SHARED=ON` built against them, unpacked, which
|
||||
draws the same as the built `simple`; a static build still packs one
|
||||
`libreaktor-dev`; `-f tar` writes three tarballs. CI now packs the shared
|
||||
build as `.deb`s on x86-64, installs them, builds the shared consumer,
|
||||
removes `libreaktor-dev` and runs it on the two runtime packages alone; the
|
||||
rpm job does the same with `-s`. The rpm, FreeBSD, OpenBSD and NetBSD
|
||||
branches are written but have not run: rpmbuild and the BSD tools are not on
|
||||
this machine. `bsd.yml` packs the shared build on each BSD and runs the shared
|
||||
consumer on the runtime packages alone, in a step that warns rather than
|
||||
fails until it has passed there.
|
||||
|
||||
|
||||
1. `tools/libreaktor-pkg.sh` packs the shared library and SDL as their own
|
||||
packages (`libreaktor0`, `libreaktor-sdl3-0` or the distro's spelling) and
|
||||
the headers as a `-dev` package.
|
||||
2. The samples get a shared-linked variant to prove a package installs and
|
||||
runs as intended.
|
||||
3. BSD packages follow the same split.
|
||||
|
||||
## In releases (2026-11-03)
|
||||
|
||||
CI builds the shared library next to the static one, and a release carries
|
||||
both. Every Linux job (x86-64, x86, arm64, and armhf and riscv64 cross-built)
|
||||
builds `-DREAKTOR_SHARED=ON`, checks it with `check-libreaktor.sh` (natively,
|
||||
or on the emulated machine after the builder installs it) and uploads
|
||||
`libreaktor-VERSION-linux-ARCH.tar.gz` and the three split `.deb`s;
|
||||
the rpm job adds the split rpms; the x86-64 BSD jobs add
|
||||
`libreaktor-VERSION-OS-x86-64.tar.gz`. The static tarballs beside them, on
|
||||
Linux and the BSDs, are now `libreaktor-static-VERSION-OS-ARCH.tar.gz`,
|
||||
matching the `libreaktor-static` package; Windows, macOS and the web, which
|
||||
have only the static library, are named `libreaktor-static-` too. Installs
|
||||
that ship (`check-libreaktor.sh`, `libreaktor-pkg.sh`, CI's own) pass
|
||||
`--strip`, which strips the two shared libraries and leaves the archives:
|
||||
`libreaktor.so.0` 2.04 to 1.87 MB, `libreaktor-sdl3.so.0` 2.92 to 2.66 MB,
|
||||
exports unchanged. All of them are `package-*`
|
||||
artifacts, so `release.yml` publishes them with the rest, and its notes say
|
||||
how to use them. Not covered: the BSDs' arm64 (cross-built in `bsd-arm64`),
|
||||
Windows, macOS and the web.
|
||||
|
||||
## Later, lower priority
|
||||
|
||||
- ~~**Windows:** an MSIX framework package carrying `reaktor.dll` and SDL, which
|
||||
packaged apps declare as a dependency.~~ Dropped (2026-11-03): each Windows
|
||||
app ships alone, so sharing buys little, and a framework package serves only
|
||||
MSIX-packaged apps while needing a signing certificate, an export macro on
|
||||
every public declaration and the DLL C runtime. Windows stays static.
|
||||
- **macOS:** a framework signed with the app's Team ID, or a Homebrew formula,
|
||||
since apps from other developers cannot load it under the hardened runtime.
|
||||
Homebrew is ruled out (2026-11-03: no access), which leaves only the
|
||||
framework, shared by apps under one Team ID. Kept in scope (2026-11-03).
|
||||
It saves memory only when several of those apps run at once and the
|
||||
framework is installed once, in `/Library/Frameworks`, not inside each
|
||||
`.app`. Still open: an Apple Developer ID to sign and notarize it, and a
|
||||
universal binary or one per architecture. It cannot be built or checked on
|
||||
the Linux machine this plan was worked on; `macos.yml` would be its check.
|
||||
|
||||
**Written, not yet run (2026-11-03).** `-DREAKTOR_SHARED=ON` on macOS builds
|
||||
`Frameworks/Reaktor.framework` (`Versions/A`, install name
|
||||
`@rpath/Reaktor.framework/...`, identifier `io.github.alpaq92.reaktor`)
|
||||
from the same parts plus SDL, linked in with `-force_load`, so there is no
|
||||
`libreaktor-sdl3`: no system SDL stands to be confused with ours. ld64 has
|
||||
no version script, so CMake turns `tools/reaktor.map` into an exported
|
||||
symbol list (190 names, checked here with `cmake -P`); the framework binds
|
||||
its calls into the modules at load (`-undefined dynamic_lookup`) and apps
|
||||
link with `-export_dynamic`, which also keeps those functions through
|
||||
`-dead_strip`. `reaktor::shared` links the framework and
|
||||
`libreaktor-modules.a`, with an rpath to the install and to
|
||||
`/Library/Frameworks`. `macos.yml` builds it on both runners, runs
|
||||
`check-libreaktor.sh` on it and uploads `libreaktor-VERSION-macos-ARCH.zip`.
|
||||
Per architecture, signed ad hoc, as today.
|
||||
|
||||
**Universal too (2026-11-03).** A third job in `macos.yml` takes the two
|
||||
per-architecture zips, joins every Mach-O file and archive in them with
|
||||
`lipo` (the framework, `libreaktor-modules.a`, `libreaktor.a`), requires
|
||||
every other file to be the same in both, signs the framework again ad hoc,
|
||||
builds the shared consumer for `arm64;x86_64` against it, runs it, and
|
||||
uploads `libreaktor-VERSION-macos-universal.zip`. If CMake writes a path
|
||||
that differs between the two runners into the config or `.pc` files, that
|
||||
check fails and the file needs one form for both.
|
||||
|
||||
**No Developer ID (2026-11-03), and none soon.** So the framework stays
|
||||
signed ad hoc and is not notarized, like the rest of the macOS release.
|
||||
Without a Team ID, "apps under one Team ID" means apps that do not turn on
|
||||
the hardened runtime: its library validation is what refuses a framework
|
||||
from another signer, and an ad hoc one has no signer to match. Reaktor's
|
||||
own apps do not turn it on. A framework downloaded from the release carries
|
||||
the quarantine flag, so the person installing it clears that once
|
||||
(`xattr -dr com.apple.quarantine`) before apps can load it.
|
||||
|
||||
## Open questions
|
||||
|
||||
1. ~~Go or no-go.~~ Go (2026-11-02), on four or more apps. The threshold is 20% (agreed 2026-10-30). CI says 20.2% at
|
||||
most, and a Linux desktop says 17.3% (2026-11-02). That points to no-go;
|
||||
a run on a desktop with a real GPU would confirm it. A real shared
|
||||
build (Phase 0b) saves 14.3%, and 14.6% with hidden symbols (Phase 0c),
|
||||
with three apps. Four apps save 20.4%, five 24.2% (Phase 0d).
|
||||
@@ -6,54 +6,57 @@ A Nuklear-powered GUI library for C.
|
||||
<img src="assets/screenshots/screenshot.png" alt="Two Reaktor showcase windows, the light scheme behind and the dark scheme in front: each has the sidebar of pages with its own scheme chosen at the foot, and the front one shows the Login page's card in a rounded panel">
|
||||
</p>
|
||||
|
||||
Tired of C relying on heavy toolkits that want hundreds of megabytes and a
|
||||
dozen dependencies just to put a dialog on screen? And of small alternatives
|
||||
always lacking crucial features? No? But I was, so I wrote Reaktor: complete
|
||||
without being big. A 2.1 MB binary, 7–13 MB of RAM, and no GPU required.
|
||||
Tired of C having no cross-platform GUI — nothing like
|
||||
[Avalonia](https://github.com/avaloniaui/avalonia),
|
||||
[Shaft](https://github.com/ShaftUI/Shaft) or
|
||||
[Freya](https://github.com/marc2332/freya) — and of toolkits that want hundreds
|
||||
of megabytes to put a dialog on screen? No? But I was, so I wrote Reaktor:
|
||||
complete without being big. A 2.4 MB binary, about 10 MB of RAM, and no GPU
|
||||
required.
|
||||
|
||||
**[Try the showcase in your browser](https://alpaq92.github.io/Reaktor/)**, the
|
||||
same program built to WebAssembly, or
|
||||
**[Try the showcase in your browser](https://alpaq92.github.io/Reaktor/)** — the
|
||||
same program, built to WebAssembly — or
|
||||
**[download it](https://github.com/Alpaq92/Reaktor/releases/latest)** for
|
||||
Windows, macOS, Linux, FreeBSD, OpenBSD, NetBSD, or as WebAssembly to serve
|
||||
Windows, macOS, Linux, FreeBSD, OpenBSD or NetBSD, or as WebAssembly to serve
|
||||
yourself.
|
||||
|
||||
> ⚠️ **Reaktor is in active development**; breaking changes may occur.
|
||||
> ⚠️ **Reaktor is in active development**, and breaking changes might occur.
|
||||
|
||||
<p align="center">
|
||||
<a href="docs/PERFORMANCE.md"><img src="docs/benchmark.svg" alt="Two bar charts of drawing 64 rotating boxes at 60 fps in an 800x600 window. Memory: Reaktor 8.8 MB, the same program on D3D12 120.5 MB and on OpenGL 68.7 MB, Flutter 132.7 MB, Electron 155.2 MB, Kotlin Multiplatform 668.7 MB. Steady-state CPU as a percent of one core: Reaktor 6.0%, D3D12 5.2%, OpenGL 5.9%, Flutter 15.3%, Electron 20.7%, Kotlin Multiplatform 29.4%"></a>
|
||||
<a href="docs/PERFORMANCE.md"><img src="docs/benchmark.svg" alt="Two bar charts of drawing 64 rotating boxes at 60 fps in an 800x600 window. Memory: Reaktor 9.5 MB, the same binary on D3D11 59.4 MB, on D3D12 122.3 MB and on OpenGL 70.1 MB, Flutter 90.8 MB, Electron 157.6 MB, Kotlin Multiplatform 667.4 MB. Steady-state CPU as a percent of one core: Reaktor 6.0%, D3D11 10.3%, D3D12 5.0%, OpenGL 5.0%, Flutter 15.6%, Electron 26.1%, Kotlin Multiplatform 33.5%"></a>
|
||||
</p>
|
||||
|
||||
How, and on what, is in [PERFORMANCE.md](docs/PERFORMANCE.md).
|
||||
|
||||
## Features
|
||||
|
||||
- **24 declared widgets**: buttons, fields, checks, radios, sliders, knobs,
|
||||
spinners, combos, color, date and time pickers, sidebar, tabs, a menu bar,
|
||||
tables, trees and a splitter, with tooltips and rows that drag between
|
||||
lists. All of Nuklear is underneath, under Reaktor's names.
|
||||
- **Layers**: menus in windows of their own, in-window dialogs, modal
|
||||
questions, toasts, more native windows, and a tray icon with a menu.
|
||||
- **Services**: system open, save and folder pickers, timers, main-thread
|
||||
posting, persistent settings, undo, system notifications, printing and PDF
|
||||
export.
|
||||
- **24 declared widgets** — buttons, fields, checks, radios, sliders, knobs,
|
||||
spinners, combos, a color picker, date and time pickers, sidebar, tabs, a
|
||||
menu bar, tables, trees and a splitter, with tooltips; rows drag between
|
||||
lists; all of Nuklear underneath, under Reaktor's names.
|
||||
- **Layers** — menus in windows of their own, in-window dialogs, questions,
|
||||
toasts, more windows, and a tray icon with a menu.
|
||||
- **Services** — system open, save and folder pickers, timers, main-thread
|
||||
posting, settings that persist, an undo stack, system notifications, and
|
||||
printing and PDF export.
|
||||
- **Styled by CSS** read at run time: color, type, borders, radii, spacing,
|
||||
`:hover` and `:active`, light and dark. Swap the sheet and the app changes.
|
||||
- **Accessible with no code**: UI Automation, NSAccessibility, AT-SPI and a
|
||||
DOM subtree on the web, and keyboard navigation throughout.
|
||||
- **Localization**: catalogs, plural rules, and numbers, money and dates as
|
||||
- **Accessible with no code** — UI Automation, NSAccessibility, AT-SPI and a
|
||||
DOM subtree on the web, with keyboard navigation throughout.
|
||||
- **Localization** — catalogs, plural rules, and numbers, money and dates as
|
||||
each language writes them.
|
||||
- **Text past Latin-1**: direction, shaping, fallback fonts and Unicode line
|
||||
- **Text past Latin-1** — direction, shaping, fallback fonts and Unicode line
|
||||
breaking, so Japanese wraps properly.
|
||||
- **Animation**: tweens keyed per widget on 31 curves, springs, steps and
|
||||
- **Animation** — tweens keyed per widget on 31 curves, springs, steps and
|
||||
béziers; keyframed clips staggered across a grid; motion paths,
|
||||
oscillators, noise and shakes; colors blended in five spaces; text that
|
||||
arrives a glyph at a time. Idle once everything settles.
|
||||
- **Modular**: accessibility, localization, text shaping, settings, the tray,
|
||||
popup windows, notifications, printing and the Inspector each swap for a
|
||||
stub at build time. Only what they drew goes; every other pixel stays.
|
||||
- **Windows, macOS, Linux, the BSDs and WebAssembly** from one set of sources
|
||||
and one software rasterizer, at any display scale: x86 and ARM everywhere,
|
||||
RISC-V on Linux ([Platforms](docs/DOCUMENTATION.md#platforms)).
|
||||
oscillators, noise and shakes; colors blended in five spaces; and text
|
||||
that arrives a glyph at a time, idle once everything settles.
|
||||
- **Modular** — accessibility, localization, text shaping, settings, the tray,
|
||||
popup windows, notifications and printing each swap for a stub at build
|
||||
time, and only what they drew stops being drawn; every other pixel stays.
|
||||
- **Windows, macOS, Linux, the BSDs and WebAssembly** from one set of sources,
|
||||
on one software rasterizer, at any display scale: x86 and ARM everywhere,
|
||||
and RISC-V on Linux ([Platforms](docs/DOCUMENTATION.md#platforms)).
|
||||
- **Nothing drawn at rest** — 0% of a core while it sits there.
|
||||
|
||||
## Build
|
||||
@@ -69,30 +72,28 @@ cd Reaktor
|
||||
```
|
||||
|
||||
`./build-wasm.sh` (`build-wasm.ps1` on Windows, with
|
||||
[emsdk](https://emscripten.org)) builds the web versions into `build-wasm/`,
|
||||
to be served over HTTP.
|
||||
[emsdk](https://emscripten.org)) builds the web versions into `build-wasm/`, to
|
||||
be served over HTTP.
|
||||
|
||||
For your own application, `add_subdirectory` Reaktor and declare the app with
|
||||
`reaktor_add_app`, or take a `libreaktor` package from the
|
||||
To build your own application, add Reaktor with `add_subdirectory` and declare
|
||||
it with `reaktor_add_app`, or take a `libreaktor` package from the
|
||||
[releases](https://github.com/Alpaq92/Reaktor/releases/latest) and
|
||||
`find_package(reaktor)`: [In your own project](docs/DOCUMENTATION.md#in-your-own-project).
|
||||
|
||||
## Install
|
||||
|
||||
On Linux and the BSDs, one script builds libreaktor as a system package
|
||||
(`.deb`, `.rpm`, FreeBSD, OpenBSD or NetBSD) and installs it:
|
||||
On Linux and the BSDs, one script builds libreaktor as the system's own
|
||||
package (`.deb`, `.rpm`, FreeBSD, OpenBSD or NetBSD) and installs it:
|
||||
|
||||
```bash
|
||||
sh tools/libreaktor-pkg.sh -i
|
||||
```
|
||||
|
||||
It lands in `/opt/reaktor` (`/usr/local/reaktor` on the BSDs); build against
|
||||
it with `-DCMAKE_PREFIX_PATH=/opt/reaktor`, or `pkg-config` with
|
||||
`PKG_CONFIG_PATH=/opt/reaktor/lib/pkgconfig`. The package manager removes it:
|
||||
it is `libreaktor` everywhere. `-s` also builds `libreaktor.so` and packs
|
||||
three packages instead: `libreaktor-sdl3-0` and `libreaktor1` to run an app,
|
||||
`libreaktor-shared` to build one. `libreaktor` and `libreaktor-shared`
|
||||
conflict; install one.
|
||||
It lands in `/opt/reaktor` (`/usr/local/reaktor` on the BSDs); build against it
|
||||
with `-DCMAKE_PREFIX_PATH=/opt/reaktor`, or `pkg-config` with
|
||||
`PKG_CONFIG_PATH=/opt/reaktor/lib/pkgconfig`. Remove it with the system's
|
||||
package manager: `libreaktor-dev` on Debian, `libreaktor-devel` on Fedora,
|
||||
`libreaktor` on the BSDs.
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -111,35 +112,32 @@ REAKTOR_COLUMN(.gap = 10) {
|
||||
}
|
||||
```
|
||||
|
||||
No colors, radii, padding or font sizes: a stylesheet read at startup gives
|
||||
them. Nothing for screen readers either: each widget reports its name, value
|
||||
and position.
|
||||
No colors, radii, padding or font sizes: they come from a stylesheet read at
|
||||
startup. Nothing for screen readers either: each widget reports its own name,
|
||||
value and position.
|
||||
|
||||
## Made of
|
||||
|
||||
[Nuklear](https://github.com/Immediate-Mode-UI/Nuklear) draws the widgets.
|
||||
[SDL3](https://github.com/libsdl-org/SDL) supplies the window, input,
|
||||
software renderer, and the tray on Windows and macOS; on Linux and the BSDs
|
||||
the tray is Reaktor's, over the D-Bus client
|
||||
[gibus](https://github.com/Alpaq92/gibus). Reaktor's own CSS engine reads the
|
||||
stylesheets. [Onlay](https://github.com/Alpaq92/Onlay), a fork of
|
||||
[randrew/layout](https://github.com/randrew/layout), computes the rectangles,
|
||||
and [NukAnim](https://github.com/Alpaq92/NukAnim), a port of ImAnim, moves
|
||||
them.
|
||||
[SDL3](https://github.com/libsdl-org/SDL) supplies the window, input, tray and
|
||||
software renderer. libcss, from [LCUI](https://github.com/lc-soft/LCUI), parses
|
||||
the stylesheets, and [Onlay](https://github.com/Alpaq92/Onlay), a fork of
|
||||
[randrew/layout](https://github.com/randrew/layout), computes the rectangles.
|
||||
[NukAnim](https://github.com/Alpaq92/NukAnim), a port of ImAnim, moves them.
|
||||
Every dependency is a submodule, used as it ships; the full list is in
|
||||
[NOTICE.md](docs/NOTICE.md).
|
||||
|
||||
## Documentation
|
||||
|
||||
- [DOCUMENTATION.md](docs/DOCUMENTATION.md): every widget, layout, layer and
|
||||
style, then how it works inside.
|
||||
- [FAQ.md](docs/FAQ.md): short answers to common questions.
|
||||
- [DEMO.md](docs/DEMO.md): the four programs in this repository.
|
||||
- [PERFORMANCE.md](docs/PERFORMANCE.md): what it costs, measured.
|
||||
- [BENCHMARKS.md](benchmarks/BENCHMARKS.md): the comparison, as runnable
|
||||
- [DOCUMENTATION.md](docs/DOCUMENTATION.md) — the whole of it: every widget,
|
||||
layout and layer, styling, then how it works inside.
|
||||
- [FAQ.md](docs/FAQ.md) — short answers to common questions.
|
||||
- [DEMO.md](docs/DEMO.md) — the four programs in this repository.
|
||||
- [PERFORMANCE.md](docs/PERFORMANCE.md) — what it costs, measured.
|
||||
- [BENCHMARKS.md](benchmarks/BENCHMARKS.md) — the comparison, as runnable
|
||||
projects.
|
||||
- [NOTICE.md](docs/NOTICE.md): dependencies and licenses.
|
||||
- [NOTICE.md](docs/NOTICE.md) — dependencies and licenses.
|
||||
|
||||
## License
|
||||
|
||||
MIT. The dependencies keep their own; see [NOTICE.md](docs/NOTICE.md).
|
||||
MIT. The dependencies keep their own — see [NOTICE.md](docs/NOTICE.md).
|
||||
|
||||
+15
-22
@@ -20,23 +20,18 @@ outside its process. The results are the chart in
|
||||
./benchmarks/run.ps1 -Csv bars.csv
|
||||
```
|
||||
|
||||
`run.ps1` also takes `-Seconds`, `-Fps` and `-Boxes`, and three switches:
|
||||
`-Steady` adds the CPU from 3 s to 8 s of a 9-second run, `-FlatOut` the time
|
||||
a Reaktor frame takes drawn without vsync, and `-PinClock` holds the processor
|
||||
at full speed for the run, through a copy of the power plan it removes after.
|
||||
`run.sh` is the same for macOS, Linux and the BSDs (`--targets`, `--runs`,
|
||||
`--seconds`, `--fps`, `--boxes`, `--csv`). Nothing is built for you: a missing
|
||||
arm is skipped, with the command that builds it.
|
||||
`run.ps1` also takes `-Seconds`, `-Fps` and `-Boxes`; `run.sh` is the same for
|
||||
macOS, Linux and the BSDs (`--targets`, `--runs`, `--seconds`, `--fps`,
|
||||
`--boxes`, `--csv`). Nothing is built for you: a missing arm is skipped, with
|
||||
the command that builds it.
|
||||
|
||||
Reaktor runs four times — `reaktor-software`, its default, and
|
||||
`reaktor-d3d11`, `reaktor-d3d12` and `reaktor-opengl`, the same binary on
|
||||
SDL's GPU drivers (`run.sh` adds `reaktor-metal` on macOS). The others draw on
|
||||
the GPU, so those three are the like-for-like comparison. SDL's OpenGL driver
|
||||
is built only when `REAKTOR_RENDERERS` names it, which the `reaktor-opengl`
|
||||
arm's build does. An arm whose renderer would not start is skipped, not measured
|
||||
under another renderer's name. The chart dates its arms: Reaktor's three are
|
||||
re-measured when the runtime changes in a way that could move them, last on
|
||||
2026-11-09 with Electron; Flutter and Kotlin Multiplatform last on 2026-10-24.
|
||||
is built only with `-DREAKTOR_SDL_GL=ON`, which the `reaktor-opengl` arm's
|
||||
build passes. An arm whose renderer would not start is skipped, not measured
|
||||
under another renderer's name.
|
||||
|
||||
## What every arm draws
|
||||
|
||||
@@ -87,11 +82,9 @@ Each arm uses its framework's own toolchain; none is vendored here.
|
||||
```bash
|
||||
cd benchmarks/electron-bench
|
||||
npm install
|
||||
npx install-electron
|
||||
```
|
||||
|
||||
Node 20.19+ or 22+; older Node fails with `ERR_REQUIRE_ESM`. Since Electron 44
|
||||
`npm install` no longer fetches the binary; `install-electron` does. `--software`
|
||||
Node 20.19+ or 22+; older Node fails with `ERR_REQUIRE_ESM`. `--software`
|
||||
turns hardware acceleration off.
|
||||
|
||||
### Flutter
|
||||
@@ -152,14 +145,14 @@ MSVC 14.44 Release, the C runtime linked in:
|
||||
|
||||
| Program | Bytes |
|
||||
| --- | --- |
|
||||
| `bench.exe` | 2,352,640 |
|
||||
| `simple.exe` | 2,362,880 |
|
||||
| `notepad.exe` | 2,497,536 |
|
||||
| `showcase.exe` | 3,438,592 |
|
||||
| `bench.exe` | 2,752,512 |
|
||||
| `simple.exe` | 2,760,192 |
|
||||
| `notepad.exe` | 2,797,568 |
|
||||
| `showcase.exe` | 3,782,656 |
|
||||
|
||||
The C runtime is about 220 KB of each; a default `./build.ps1` links its DLL
|
||||
instead. The showcase links every module and `notepad` three, and Text is
|
||||
0.6 MB of the difference ([Modules](../docs/PERFORMANCE.md#modules)).
|
||||
The C runtime is about 300 KB of each; a default `./build.ps1` links its DLL
|
||||
instead. Only the showcase links the three optional modules, and Text is
|
||||
0.8 MB of the difference ([Modules](../docs/PERFORMANCE.md#modules)).
|
||||
|
||||
The v0.2.0 downloads, as GitHub Actions built and published them:
|
||||
|
||||
|
||||
+7
-56
@@ -6,10 +6,7 @@ param(
|
||||
[double] $Fps = 60,
|
||||
[int] $Boxes = 64,
|
||||
[int] $Runs = 10,
|
||||
[string] $Csv = "",
|
||||
[switch] $Steady,
|
||||
[switch] $FlatOut,
|
||||
[switch] $PinClock
|
||||
[string] $Csv = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
@@ -41,7 +38,7 @@ function Get-Arm([string]$name) {
|
||||
@{ exe = Join-Path $root "build\bench.exe"
|
||||
args = @("--renderer", "opengl")
|
||||
dir = $root
|
||||
make = "./build.ps1 bench -DREAKTOR_RENDERERS=direct3d11,direct3d12,opengl" }
|
||||
make = "./build.ps1 bench -DREAKTOR_SDL_GL=ON" }
|
||||
}
|
||||
"shaft" {
|
||||
@{ exe = Join-Path $here "shaft-bench\.build\release\ShaftBench.exe"
|
||||
@@ -71,16 +68,12 @@ function Get-Arm([string]$name) {
|
||||
}
|
||||
}
|
||||
|
||||
# Windows reuses process ids, and a process outlives its parent keeping the
|
||||
# parent's id: one started before the app is never its child.
|
||||
function Get-ProcessTree([int]$rootId) {
|
||||
$byParent = @{}
|
||||
$started = @{}
|
||||
foreach ($p in Get-CimInstance Win32_Process -Property ProcessId, ParentProcessId, CreationDate) {
|
||||
foreach ($p in Get-CimInstance Win32_Process -Property ProcessId, ParentProcessId) {
|
||||
$parent = [int]$p.ParentProcessId
|
||||
if (-not $byParent.ContainsKey($parent)) { $byParent[$parent] = @() }
|
||||
$byParent[$parent] += [int]$p.ProcessId
|
||||
$started[[int]$p.ProcessId] = $p.CreationDate
|
||||
}
|
||||
|
||||
$seen = @{}
|
||||
@@ -91,9 +84,7 @@ function Get-ProcessTree([int]$rootId) {
|
||||
if ($seen.ContainsKey($id)) { continue }
|
||||
$seen[$id] = $true
|
||||
if ($byParent.ContainsKey($id)) {
|
||||
foreach ($child in $byParent[$id]) {
|
||||
if ($started[$child] -ge $started[$id]) { $stack.Push($child) }
|
||||
}
|
||||
foreach ($child in $byParent[$id]) { $stack.Push($child) }
|
||||
}
|
||||
}
|
||||
return @($seen.Keys)
|
||||
@@ -108,7 +99,6 @@ function Invoke-Arm($spec, [string[]]$argv) {
|
||||
$null = $proc.Handle
|
||||
|
||||
$cpuMs = @{}
|
||||
$samples = New-Object System.Collections.ArrayList
|
||||
$peakPrivate = 0L
|
||||
$tree = @($proc.Id)
|
||||
$treeAt = -1000
|
||||
@@ -129,9 +119,6 @@ function Invoke-Arm($spec, [string[]]$argv) {
|
||||
} catch { }
|
||||
}
|
||||
if ($private -gt $peakPrivate) { $peakPrivate = $private }
|
||||
$sum = 0.0
|
||||
foreach ($value in $cpuMs.Values) { $sum += $value }
|
||||
$null = $samples.Add(@($clock.ElapsedMilliseconds, $sum))
|
||||
|
||||
Start-Sleep -Milliseconds 100
|
||||
}
|
||||
@@ -150,17 +137,8 @@ function Invoke-Arm($spec, [string[]]$argv) {
|
||||
if ($line -match '^\s*([a-z_0-9]+)\s+(\S+)\s*$') { $keys[$matches[1]] = $matches[2] }
|
||||
}
|
||||
|
||||
# Steady state: from 3 s to 8 s, past startup and before the last frame.
|
||||
$steady = $null
|
||||
$from = $samples | Where-Object { $_[0] -ge 3000 } | Select-Object -First 1
|
||||
$to = $samples | Where-Object { $_[0] -le 8000 } | Select-Object -Last 1
|
||||
if ($wallMs -ge 8500 -and $from -and $to -and $to[0] -gt $from[0]) {
|
||||
$steady = [math]::Round(100.0 * ($to[1] - $from[1]) / ($to[0] - $from[0]), 1)
|
||||
}
|
||||
|
||||
return @{
|
||||
keys = $keys
|
||||
cpu_steady = $steady
|
||||
stderr = $stderr
|
||||
exit = $proc.ExitCode
|
||||
private_mb = [math]::Round($peakPrivate / 1MB, 1)
|
||||
@@ -178,24 +156,9 @@ function Get-Median([double[]]$values) {
|
||||
return ($sorted[$mid - 1] + $sorted[$mid]) / 2
|
||||
}
|
||||
|
||||
if ($Steady) { $Seconds = 9 }
|
||||
$argv = @("--bench-seconds", "$Seconds", "--fps", "$Fps", "--boxes", "$Boxes")
|
||||
$rows = @()
|
||||
|
||||
# A copy of the active plan with the processor held at full speed, so a light
|
||||
# load is not measured at whatever clock the processor idled down to.
|
||||
$restorePlan = $null
|
||||
$pinnedPlan = $null
|
||||
if ($PinClock) {
|
||||
$restorePlan = [regex]::Match((powercfg /getactivescheme), '[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}').Value
|
||||
$pinnedPlan = [regex]::Match((powercfg /duplicatescheme $restorePlan), '[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}').Value
|
||||
powercfg /changename $pinnedPlan "Reaktor benchmark" | Out-Null
|
||||
powercfg /setacvalueindex $pinnedPlan SUB_PROCESSOR PROCTHROTTLEMIN 100 | Out-Null
|
||||
powercfg /setdcvalueindex $pinnedPlan SUB_PROCESSOR PROCTHROTTLEMIN 100 | Out-Null
|
||||
powercfg /setactive $pinnedPlan | Out-Null
|
||||
}
|
||||
try {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "$Boxes boxes, $Seconds s, $Fps fps, $Runs runs, $cores logical processors"
|
||||
Write-Host ""
|
||||
@@ -208,7 +171,7 @@ foreach ($name in $Targets) {
|
||||
continue
|
||||
}
|
||||
|
||||
$private = @(); $cpuCore = @(); $cpuMachine = @(); $cpuSteady = @(); $frames = @(); $perFrame = @()
|
||||
$private = @(); $cpuCore = @(); $cpuMachine = @(); $frames = @(); $perFrame = @()
|
||||
$size = ""
|
||||
|
||||
for ($i = 0; $i -lt $Runs; $i++) {
|
||||
@@ -227,11 +190,7 @@ foreach ($name in $Targets) {
|
||||
$cpuCore += $r.cpu_core
|
||||
$cpuMachine += $r.cpu_machine
|
||||
if ($r.keys.ContainsKey("frames")) { $frames += [double]$r.keys["frames"] }
|
||||
if ($null -ne $r.cpu_steady) { $cpuSteady += $r.cpu_steady }
|
||||
if ($FlatOut -and $name -like "reaktor-*") {
|
||||
$flat = Invoke-Arm $spec @("--bench-seconds", "4", "--boxes", "$Boxes", "--no-vsync")
|
||||
if ($flat.keys.ContainsKey("ms_per_frame")) { $perFrame += [double]$flat.keys["ms_per_frame"] }
|
||||
}
|
||||
if ($r.keys.ContainsKey("ms_per_frame")) { $perFrame += [double]$r.keys["ms_per_frame"] }
|
||||
if ($r.keys.ContainsKey("size")) { $size = $r.keys["size"] }
|
||||
|
||||
$shown = if ($r.keys.ContainsKey("frames")) { $r.keys["frames"] } else { "?" }
|
||||
@@ -246,22 +205,14 @@ foreach ($name in $Targets) {
|
||||
MemoryMB = Get-Median $private
|
||||
CpuCore = Get-Median $cpuCore
|
||||
CpuMachine = Get-Median $cpuMachine
|
||||
CpuSteady = $(if ($cpuSteady.Count) { Get-Median $cpuSteady } else { $null })
|
||||
Frames = Get-Median $frames
|
||||
MsPerFrame = $(if ($perFrame.Count) { Get-Median $perFrame } else { $null })
|
||||
Runs = $private.Count
|
||||
}
|
||||
}
|
||||
|
||||
} finally {
|
||||
if ($pinnedPlan) {
|
||||
powercfg /setactive $restorePlan | Out-Null
|
||||
powercfg /delete $pinnedPlan | Out-Null
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
$rows | Format-Table -AutoSize | Out-String -Width 200 | Write-Host
|
||||
$rows | Format-Table -AutoSize
|
||||
|
||||
foreach ($row in $rows) {
|
||||
if ($row.Size -ne "800x600" -and $row.Size -ne "?") {
|
||||
|
||||
+2
-3
@@ -6,6 +6,7 @@ $root = $PSScriptRoot
|
||||
$outDir = Join-Path $root "build-wasm"
|
||||
|
||||
$emsdk = if ($env:EMSDK) { $env:EMSDK } else { "$env:USERPROFILE\emsdk" }
|
||||
$emcc = Join-Path $emsdk "upstream\emscripten\emcc.py"
|
||||
$toolchain = Join-Path $emsdk "upstream\emscripten\cmake\Modules\Platform\Emscripten.cmake"
|
||||
if (-not (Test-Path $toolchain)) {
|
||||
throw "emsdk not found at $emsdk - clone https://github.com/emscripten-core/emsdk, run 'emsdk install latest' then 'emsdk activate latest', or set EMSDK"
|
||||
@@ -46,7 +47,5 @@ Write-Host "a file:// page cannot fetch the .wasm, so serve it:"
|
||||
Write-Host " python -m http.server -d build-wasm 8000"
|
||||
|
||||
if ($Serve) {
|
||||
$python = Get-ChildItem (Join-Path $emsdk "python") -Filter python.exe -Recurse -Depth 1 |
|
||||
Sort-Object FullName | Select-Object -Last 1
|
||||
& $python.FullName -m http.server -d $outDir 8000
|
||||
& (Join-Path $emsdk "python\3.13.3_64bit\python.exe") -m http.server -d $outDir 8000
|
||||
}
|
||||
|
||||
@@ -14,10 +14,9 @@ while [ $# -gt 0 ]; do
|
||||
target="$1" ;;
|
||||
--debug) buildtype="Debug" ;;
|
||||
--release) buildtype="Release" ;;
|
||||
--help|-h) echo "usage: build.sh [NAME | --target NAME] [--debug] [-- CMAKE_ARGS]"; exit 0 ;;
|
||||
--help|-h) echo "usage: build.sh [--target NAME] [--debug] [-- CMAKE_ARGS]"; exit 0 ;;
|
||||
--) shift; break ;;
|
||||
-*) echo "build.sh: unknown argument: $1 (try --help)" >&2; exit 2 ;;
|
||||
*) target="$1" ;;
|
||||
*) echo "build.sh: unknown argument: $1 (try --help)" >&2; exit 2 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
+40
-24
@@ -55,14 +55,13 @@ intern(reaktor_a11y *a, const char *s, unsigned h)
|
||||
#define same_str(x, y) ((x) == (y) || ((x) && (y) && strcmp((x), (y)) == 0))
|
||||
|
||||
static reaktor_a11y_slot *
|
||||
probe(reaktor_a11y_slot *tab, unsigned gen, unsigned key, int claim)
|
||||
slot_of(reaktor_a11y_slot *tab, unsigned gen, unsigned key)
|
||||
{
|
||||
unsigned i = key & (REAKTOR_A11Y_SLOTS - 1), n;
|
||||
|
||||
for (n = 0; n < REAKTOR_A11Y_SLOTS; n++) {
|
||||
reaktor_a11y_slot *sl = &tab[i];
|
||||
if (sl->gen != gen) {
|
||||
if (!claim) return NULL;
|
||||
sl->gen = gen;
|
||||
sl->key = key;
|
||||
sl->val = 0;
|
||||
@@ -75,11 +74,17 @@ probe(reaktor_a11y_slot *tab, unsigned gen, unsigned key, int claim)
|
||||
}
|
||||
|
||||
static int
|
||||
slot_get(reaktor_a11y_slot *tab, unsigned gen, unsigned key)
|
||||
slot_get(const reaktor_a11y_slot *tab, unsigned gen, unsigned key)
|
||||
{
|
||||
const reaktor_a11y_slot *sl = probe(tab, gen, key, 0);
|
||||
unsigned i = key & (REAKTOR_A11Y_SLOTS - 1), n;
|
||||
|
||||
return sl ? sl->val : 0;
|
||||
for (n = 0; n < REAKTOR_A11Y_SLOTS; n++) {
|
||||
const reaktor_a11y_slot *sl = &tab[i];
|
||||
if (sl->gen != gen) return 0;
|
||||
if (sl->key == key) return sl->val;
|
||||
i = (i + 1) & (REAKTOR_A11Y_SLOTS - 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -88,9 +93,9 @@ same_rect(struct nk_rect x, struct nk_rect y)
|
||||
return x.x == y.x && x.y == y.y && x.w == y.w && x.h == y.h;
|
||||
}
|
||||
|
||||
unsigned
|
||||
reaktor_a11y_add(reaktor_a11y *a, unsigned char role, const char *name,
|
||||
const char *value, unsigned state, struct nk_rect bounds)
|
||||
static unsigned
|
||||
emit(reaktor_a11y *a, unsigned char role, const char *name, const char *value,
|
||||
unsigned state, struct nk_rect bounds)
|
||||
{
|
||||
int f = a->front;
|
||||
reaktor_a11y_node *n;
|
||||
@@ -109,7 +114,7 @@ reaktor_a11y_add(reaktor_a11y *a, unsigned char role, const char *name,
|
||||
base = nh ^ ((unsigned)role * 0x9e3779b9u);
|
||||
base ^= parent + 0x9e3779b9u + (base << 6) + (base >> 2);
|
||||
|
||||
sl = probe(a->bucket, a->bucket_gen, base, 1);
|
||||
sl = slot_of(a->bucket, a->bucket_gen, base);
|
||||
id = sl ? base ^ ((unsigned)sl->val++ * 0x85ebca6bu) : base;
|
||||
if (id == 0) id = 1;
|
||||
|
||||
@@ -117,7 +122,6 @@ reaktor_a11y_add(reaktor_a11y *a, unsigned char role, const char *name,
|
||||
|
||||
if (id == a->focus_id) state |= REAKTOR_A11Y_FOCUSED;
|
||||
|
||||
if ((sl = probe(a->index, a->index_gen, id, 1))) sl->val = a->count[f] + 1;
|
||||
n = &a->node[f][a->count[f]++];
|
||||
n->id = id;
|
||||
n->parent = parent;
|
||||
@@ -135,11 +139,12 @@ reaktor_a11y_add(reaktor_a11y *a, unsigned char role, const char *name,
|
||||
static reaktor_a11y_node *
|
||||
node_of(reaktor_a11y *a, unsigned id)
|
||||
{
|
||||
int i;
|
||||
int f = a->front, i;
|
||||
|
||||
if (!a->building || !id) return NULL;
|
||||
i = slot_get(a->index, a->index_gen, id) - 1;
|
||||
return i >= 0 ? &a->node[a->front][i] : NULL;
|
||||
for (i = a->count[f] - 1; i >= 0; i--)
|
||||
if (a->node[f][i].id == id) return &a->node[f][i];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char *
|
||||
@@ -199,7 +204,6 @@ reaktor_a11y_begin(reaktor_a11y *a, const char *window_name,
|
||||
a->change_count = 0;
|
||||
a->building = 1;
|
||||
a->bucket_gen++;
|
||||
a->index_gen++;
|
||||
if (a->pool_gen == 0) a->pool_gen = 1;
|
||||
|
||||
if (a->pool_used > REAKTOR_A11Y_POOL - REAKTOR_A11Y_POOL / 4 ||
|
||||
@@ -213,11 +217,18 @@ reaktor_a11y_begin(reaktor_a11y *a, const char *window_name,
|
||||
reaktor_a11y_push(a, REAKTOR_A11Y_WINDOW, window_name, NULL, 0, bounds);
|
||||
}
|
||||
|
||||
unsigned
|
||||
reaktor_a11y_add(reaktor_a11y *a, unsigned char role, const char *name,
|
||||
const char *value, unsigned state, struct nk_rect bounds)
|
||||
{
|
||||
return emit(a, role, name, value, state, bounds);
|
||||
}
|
||||
|
||||
unsigned
|
||||
reaktor_a11y_push(reaktor_a11y *a, unsigned char role, const char *name,
|
||||
const char *value, unsigned state, struct nk_rect bounds)
|
||||
{
|
||||
unsigned id = reaktor_a11y_add(a, role, name, value, state, bounds);
|
||||
unsigned id = emit(a, role, name, value, state, bounds);
|
||||
|
||||
if (a->depth < REAKTOR_A11Y_MAX_DEPTH)
|
||||
a->parent[a->depth] = id;
|
||||
@@ -232,11 +243,12 @@ reaktor_a11y_pop(reaktor_a11y *a)
|
||||
}
|
||||
|
||||
static void
|
||||
change(reaktor_a11y *a, unsigned char kind, unsigned id)
|
||||
change(reaktor_a11y *a, unsigned char kind, unsigned id, int index)
|
||||
{
|
||||
if (a->change_count >= REAKTOR_A11Y_MAX_CHANGES) return;
|
||||
a->change[a->change_count].kind = kind;
|
||||
a->change[a->change_count].id = id;
|
||||
a->change[a->change_count].kind = kind;
|
||||
a->change[a->change_count].id = id;
|
||||
a->change[a->change_count].index = index;
|
||||
a->change_count++;
|
||||
}
|
||||
|
||||
@@ -253,6 +265,10 @@ reaktor_a11y_end(reaktor_a11y *a)
|
||||
a->building = 0;
|
||||
a->depth = 0;
|
||||
|
||||
a->index_gen++;
|
||||
for (i = 0; i < ncur; i++)
|
||||
if ((sl = slot_of(a->index, a->index_gen, cur[i].id))) sl->val = i + 1;
|
||||
|
||||
for (i = 1; i < ncur; i++) {
|
||||
struct nk_rect b = cur[i].bounds;
|
||||
unsigned up = cur[i].parent;
|
||||
@@ -275,7 +291,7 @@ reaktor_a11y_end(reaktor_a11y *a)
|
||||
|
||||
a->index_gen++;
|
||||
for (i = 0; i < nold; i++)
|
||||
if ((sl = probe(a->index, a->index_gen, old[i].id, 1))) sl->val = i + 1;
|
||||
if ((sl = slot_of(a->index, a->index_gen, old[i].id))) sl->val = i + 1;
|
||||
if (nold > 0) memset(a->matched, 0, (size_t)nold);
|
||||
|
||||
for (i = 0; i < ncur; i++) {
|
||||
@@ -283,18 +299,18 @@ reaktor_a11y_end(reaktor_a11y *a)
|
||||
if (j < 0) {
|
||||
if (!cur[i].parent ||
|
||||
slot_get(a->index, a->index_gen, cur[i].parent) > 0)
|
||||
change(a, REAKTOR_A11Y_ADDED, cur[i].id);
|
||||
change(a, REAKTOR_A11Y_ADDED, cur[i].id, i);
|
||||
continue;
|
||||
}
|
||||
a->matched[j] = 1;
|
||||
if (!same_str(cur[i].name, old[j].name) ||
|
||||
!same_str(cur[i].value, old[j].value) ||
|
||||
!same_str(cur[i].keys, old[j].keys))
|
||||
change(a, REAKTOR_A11Y_RENAMED, cur[i].id);
|
||||
change(a, REAKTOR_A11Y_RENAMED, cur[i].id, i);
|
||||
if (cur[i].state != old[j].state)
|
||||
change(a, REAKTOR_A11Y_RESTATED, cur[i].id);
|
||||
change(a, REAKTOR_A11Y_RESTATED, cur[i].id, i);
|
||||
else if (!same_rect(cur[i].bounds, old[j].bounds))
|
||||
change(a, REAKTOR_A11Y_MOVED, cur[i].id);
|
||||
change(a, REAKTOR_A11Y_MOVED, cur[i].id, i);
|
||||
}
|
||||
for (i = 0; i < nold; i++) {
|
||||
if (a->matched[i]) continue;
|
||||
@@ -302,7 +318,7 @@ reaktor_a11y_end(reaktor_a11y *a)
|
||||
int up = slot_get(a->index, a->index_gen, old[i].parent) - 1;
|
||||
if (up >= 0 && !a->matched[up]) continue;
|
||||
}
|
||||
change(a, REAKTOR_A11Y_REMOVED, old[i].id);
|
||||
change(a, REAKTOR_A11Y_REMOVED, old[i].id, i);
|
||||
}
|
||||
|
||||
a->front = b;
|
||||
|
||||
@@ -29,6 +29,7 @@ enum {
|
||||
typedef struct reaktor_a11y_change {
|
||||
unsigned char kind;
|
||||
unsigned id;
|
||||
int index;
|
||||
} reaktor_a11y_change;
|
||||
|
||||
#define REAKTOR_A11Y_MAX_NODES 256
|
||||
|
||||
@@ -19,12 +19,3 @@ size_t reaktor_utf8_clean(char *dst, const char *src, size_t cap)
|
||||
dst[n] = 0;
|
||||
return n;
|
||||
}
|
||||
|
||||
char *reaktor_utf8_clean_dup(const char *src)
|
||||
{
|
||||
size_t cap = strlen(src) * 3 + 1;
|
||||
char *dst = (char *)SDL_malloc(cap);
|
||||
|
||||
if (dst) reaktor_utf8_clean(dst, src, cap);
|
||||
return dst;
|
||||
}
|
||||
|
||||
+18
-25
@@ -1,3 +1,4 @@
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -132,30 +133,6 @@ int reaktor_path_absolute(const char *path)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int reaktor_grow(void **p, int *cap, int need, size_t size)
|
||||
{
|
||||
int n = *cap > 0 ? *cap : 64;
|
||||
void *q;
|
||||
|
||||
if (need <= *cap) return 1;
|
||||
while (n < need) n *= 2;
|
||||
if (!(q = SDL_realloc(*p, (size_t)n * size))) return 0;
|
||||
*p = q;
|
||||
*cap = n;
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *reaktor_path_from_cwd(const char *path)
|
||||
{
|
||||
char *cwd, *out = NULL;
|
||||
|
||||
if (reaktor_path_absolute(path)) return SDL_strdup(path);
|
||||
if (!(cwd = SDL_GetCurrentDirectory())) return NULL;
|
||||
if (SDL_asprintf(&out, "%s%s", cwd, path) < 0) out = NULL;
|
||||
SDL_free(cwd);
|
||||
return out;
|
||||
}
|
||||
|
||||
const char *reaktor_path_leaf(const char *path)
|
||||
{
|
||||
const char *p, *leaf = path;
|
||||
@@ -165,6 +142,22 @@ const char *reaktor_path_leaf(const char *path)
|
||||
return leaf;
|
||||
}
|
||||
|
||||
char *reaktor_c_locale_keep(int numeric)
|
||||
{
|
||||
const char *now = setlocale(numeric ? LC_NUMERIC : LC_ALL, NULL);
|
||||
size_t n = now ? strlen(now) + 1 : 0;
|
||||
char *kept = n ? (char *)malloc(n) : NULL;
|
||||
|
||||
if (kept) memcpy(kept, now, n);
|
||||
return kept;
|
||||
}
|
||||
|
||||
void reaktor_c_locale_put(int numeric, char *kept)
|
||||
{
|
||||
setlocale(numeric ? LC_NUMERIC : LC_ALL, kept ? kept : "C");
|
||||
free(kept);
|
||||
}
|
||||
|
||||
#define REGISTERED_MAX 64
|
||||
|
||||
static reaktor_builtin g_registered[REGISTERED_MAX];
|
||||
@@ -289,7 +282,7 @@ void reaktor_process_memory(size_t *rss, size_t *priv)
|
||||
unsigned long resident = 0;
|
||||
|
||||
if (f) {
|
||||
if (fscanf(f, "%*s %lu", &resident) == 1)
|
||||
if (fscanf(f, "%*lu %lu", &resident) == 1)
|
||||
*rss = (size_t)resident * (size_t)sysconf(_SC_PAGESIZE);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
+5
-3
@@ -11,10 +11,11 @@ char *reaktor_read_file(const char *path, size_t *len);
|
||||
FILE *reaktor_fopen(const char *path, const char *mode);
|
||||
|
||||
int reaktor_path_absolute(const char *path);
|
||||
char *reaktor_path_from_cwd(const char *path);
|
||||
int reaktor_grow(void **p, int *cap, int need, size_t size);
|
||||
const char *reaktor_path_leaf(const char *path);
|
||||
|
||||
char *reaktor_c_locale_keep(int numeric);
|
||||
void reaktor_c_locale_put(int numeric, char *kept);
|
||||
|
||||
char *reaktor_asset_load(const char *name, size_t *len);
|
||||
int reaktor_asset_exists(const char *name);
|
||||
int reaktor_asset_register(const char *name, const void *data, size_t size);
|
||||
@@ -33,7 +34,6 @@ void reaktor_process_memory(size_t *rss, size_t *priv);
|
||||
double reaktor_process_cpu_ms(void);
|
||||
void reaktor_free(void *p);
|
||||
size_t reaktor_utf8_clean(char *dst, const char *src, size_t cap);
|
||||
char *reaktor_utf8_clean_dup(const char *src);
|
||||
int reaktor_url_allowed(const char *url, const char *extra);
|
||||
|
||||
void reaktor_release_free_memory(void);
|
||||
@@ -57,4 +57,6 @@ reaktor_fnv_n(unsigned h, const void *p, size_t n)
|
||||
return h;
|
||||
}
|
||||
|
||||
#define REAKTOR_MARK "assets/icons/reaktor-icon.svg"
|
||||
|
||||
#endif
|
||||
|
||||
-1749
File diff suppressed because it is too large
Load Diff
@@ -1,19 +0,0 @@
|
||||
#ifndef REAKTOR_CSS_H
|
||||
#define REAKTOR_CSS_H
|
||||
|
||||
#include "reaktor/style.h"
|
||||
|
||||
typedef struct reaktor_sheet reaktor_sheet;
|
||||
|
||||
reaktor_sheet *reaktor_sheet_load(const char *const *paths, int count, const char *theme);
|
||||
void reaktor_sheet_free(reaktor_sheet *s);
|
||||
void reaktor_sheet_style(reaktor_sheet *s, const char *selector, reaktor_style *out);
|
||||
|
||||
int reaktor_sheet_add(reaktor_sheet *s, const char *path);
|
||||
int reaktor_sheet_color(const reaktor_sheet *s, const char *name, unsigned char rgba[4]);
|
||||
|
||||
void reaktor_css_media(int reduce_motion, int more_contrast);
|
||||
|
||||
void reaktor_css_track(void (*seen)(const char *path));
|
||||
|
||||
#endif
|
||||
+1419
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,23 @@
|
||||
#ifndef REAKTOR_CSSFLAT_H
|
||||
#define REAKTOR_CSSFLAT_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct reaktor_cssvars reaktor_cssvars;
|
||||
|
||||
/* A declaration or selector of token_max bytes or more is dropped; 0 keeps all. */
|
||||
char *reaktor_css_flatten(const char *const *paths, int count, const char *theme,
|
||||
size_t token_max, reaktor_cssvars **out_vars);
|
||||
|
||||
/* What @media (prefers-reduced-motion) and (prefers-contrast) answer. */
|
||||
void reaktor_css_media(int reduce_motion, int more_contrast);
|
||||
|
||||
/* Told each sheet a flatten reads, @imports too, as the sheet names it. */
|
||||
void reaktor_css_track(void (*seen)(const char *path));
|
||||
|
||||
int reaktor_cssvars_color(const reaktor_cssvars *vars, const char *name,
|
||||
unsigned char rgba[4]);
|
||||
|
||||
void reaktor_cssvars_free(reaktor_cssvars *vars);
|
||||
|
||||
#endif
|
||||
+260
-48
@@ -1,6 +1,14 @@
|
||||
#include "style.h"
|
||||
#include "css.h"
|
||||
#include "cssflat.h"
|
||||
|
||||
#include <css.h>
|
||||
#include <css/parser.h>
|
||||
#include <css/library.h>
|
||||
#include <css/selector.h>
|
||||
#include <css/computed.h>
|
||||
#include <css/style_decl.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -13,12 +21,24 @@ typedef struct cache_entry {
|
||||
} cache_entry;
|
||||
|
||||
static struct {
|
||||
reaktor_sheet *sheet;
|
||||
int ready;
|
||||
cache_entry *cache;
|
||||
unsigned cache_cap, cache_n;
|
||||
css_metrics_t metrics;
|
||||
reaktor_cssvars *vars;
|
||||
css_computed_style_t root;
|
||||
int root_ready;
|
||||
unsigned generation;
|
||||
} g;
|
||||
|
||||
static void rgba_of(css_color_value_t c, unsigned char out[4])
|
||||
{
|
||||
out[0] = (unsigned char)((c >> 16) & 0xff);
|
||||
out[1] = (unsigned char)((c >> 8) & 0xff);
|
||||
out[2] = (unsigned char)(c & 0xff);
|
||||
out[3] = (unsigned char)((c >> 24) & 0xff);
|
||||
}
|
||||
|
||||
static void cache_clear(int release)
|
||||
{
|
||||
unsigned i;
|
||||
@@ -35,6 +55,11 @@ static void cache_clear(int release)
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned hash_of(const char *s)
|
||||
{
|
||||
return reaktor_fnv(REAKTOR_FNV, s);
|
||||
}
|
||||
|
||||
static cache_entry *cache_slot(const char *selector, unsigned h)
|
||||
{
|
||||
unsigned i = h & (g.cache_cap - 1);
|
||||
@@ -59,31 +84,100 @@ static void cache_grow(void)
|
||||
free(old);
|
||||
}
|
||||
|
||||
static void base_reset(void)
|
||||
{
|
||||
if (g.root_ready) css_computed_style_destroy(&g.root);
|
||||
memset(&g.root, 0, sizeof(g.root));
|
||||
g.root_ready = 0;
|
||||
}
|
||||
|
||||
static int style_load(const char *const *css_paths, int count,
|
||||
const char *theme)
|
||||
{
|
||||
char *flat;
|
||||
css_parser_t *parser;
|
||||
|
||||
if (!g.ready) {
|
||||
css_init();
|
||||
g.metrics.dpi = 96.0f;
|
||||
g.metrics.density = 1.0f;
|
||||
g.metrics.scaled_density = 1.0f;
|
||||
g.metrics.scale = 1.0f;
|
||||
g.ready = 1;
|
||||
} else {
|
||||
css_destroy_library();
|
||||
css_init_library();
|
||||
}
|
||||
cache_clear(0);
|
||||
g.generation++;
|
||||
base_reset();
|
||||
|
||||
reaktor_cssvars_free(g.vars);
|
||||
g.vars = NULL;
|
||||
/* The parser copies each token into a buffer this size without a bound. */
|
||||
flat = reaktor_css_flatten(css_paths, count, theme, CSS_PARSER_BUFFER_SIZE - 1,
|
||||
&g.vars);
|
||||
if (!flat) return 0;
|
||||
|
||||
parser = css_parser_create("reaktor");
|
||||
if (!parser) { free(flat); return 0; }
|
||||
{
|
||||
const char *cur = flat;
|
||||
size_t len = 1;
|
||||
while (len > 0) {
|
||||
len = css_parser_parse(parser, cur);
|
||||
cur += len;
|
||||
}
|
||||
}
|
||||
css_parser_destroy(parser);
|
||||
free(flat);
|
||||
|
||||
/* One cascade: a second resets the first and leaks its font_family. */
|
||||
base_reset();
|
||||
{
|
||||
static const css_computed_style_t none;
|
||||
css_selector_t *bs = css_selector_create("body");
|
||||
|
||||
if (bs) {
|
||||
css_style_decl_t *bd = css_select_style(bs);
|
||||
|
||||
css_selector_destroy(bs);
|
||||
if (bd) {
|
||||
css_cascade_style(bd, &g.root);
|
||||
css_style_decl_destroy(bd);
|
||||
}
|
||||
}
|
||||
css_compute_absolute_values(&none, &g.root, &g.metrics);
|
||||
}
|
||||
g.root_ready = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* libcss reads numbers with sscanf, which takes the locale's decimal mark. */
|
||||
int reaktor_style_init(const char *const *css_paths, int count,
|
||||
const char *theme)
|
||||
{
|
||||
reaktor_sheet *sheet = reaktor_sheet_load(css_paths, count, theme);
|
||||
char *was = reaktor_c_locale_keep(1);
|
||||
int ok;
|
||||
|
||||
cache_clear(0);
|
||||
g.generation++;
|
||||
reaktor_sheet_free(g.sheet);
|
||||
g.sheet = sheet;
|
||||
return sheet != NULL;
|
||||
}
|
||||
|
||||
int reaktor_style_add(const char *path)
|
||||
{
|
||||
if (!reaktor_sheet_add(g.sheet, path)) return 0;
|
||||
cache_clear(0);
|
||||
g.generation++;
|
||||
return 1;
|
||||
reaktor_c_locale_put(1, NULL);
|
||||
ok = style_load(css_paths, count, theme);
|
||||
reaktor_c_locale_put(1, was);
|
||||
return ok;
|
||||
}
|
||||
|
||||
void reaktor_style_shutdown(void)
|
||||
{
|
||||
if (!g.ready) return;
|
||||
reaktor_cssvars_free(g.vars);
|
||||
g.vars = NULL;
|
||||
if (g.root_ready) {
|
||||
css_computed_style_destroy(&g.root);
|
||||
g.root_ready = 0;
|
||||
}
|
||||
css_destroy();
|
||||
g.ready = 0;
|
||||
cache_clear(1);
|
||||
reaktor_sheet_free(g.sheet);
|
||||
g.sheet = NULL;
|
||||
}
|
||||
|
||||
unsigned reaktor_style_loads(void)
|
||||
@@ -91,6 +185,11 @@ unsigned reaktor_style_loads(void)
|
||||
return g.generation;
|
||||
}
|
||||
|
||||
int reaktor_style_token(const char *name, unsigned char rgba[4])
|
||||
{
|
||||
return reaktor_cssvars_color(g.vars, name, rgba);
|
||||
}
|
||||
|
||||
void reaktor_style_darken(unsigned char rgba[4], float amount)
|
||||
{
|
||||
int i;
|
||||
@@ -101,45 +200,158 @@ void reaktor_style_darken(unsigned char rgba[4], float amount)
|
||||
rgba[i] = (unsigned char)(rgba[i] * (1.0f - amount) + 0.5f);
|
||||
}
|
||||
|
||||
static const reaktor_style *cached(const char *key)
|
||||
static float px_of(css_numeric_value_t v, css_unit_t unit)
|
||||
{
|
||||
unsigned h = reaktor_fnv(REAKTOR_FNV, key);
|
||||
size_t len;
|
||||
cache_entry *e;
|
||||
|
||||
if (g.cache_cap && (e = cache_slot(key, h))->selector) return &e->style;
|
||||
if (2 * (g.cache_n + 1) > g.cache_cap) cache_grow();
|
||||
if (g.cache_n + 1 >= g.cache_cap) return NULL;
|
||||
len = strlen(key) + 1;
|
||||
e = cache_slot(key, h);
|
||||
if (!(e->selector = malloc(len))) return NULL;
|
||||
memcpy(e->selector, key, len);
|
||||
e->hash = h;
|
||||
if (key[0] == '-' && key[1] == '-') {
|
||||
memset(&e->style, 0, sizeof e->style);
|
||||
e->style.matched = reaktor_sheet_color(g.sheet, key, e->style.bg);
|
||||
} else {
|
||||
reaktor_sheet_style(g.sheet, key, &e->style);
|
||||
}
|
||||
g.cache_n++;
|
||||
return &e->style;
|
||||
return unit == CSS_UNIT_PX ? v : 0.0f;
|
||||
}
|
||||
|
||||
int reaktor_style_token(const char *name, unsigned char rgba[4])
|
||||
static void resolve(const char *selector, reaktor_style *out)
|
||||
{
|
||||
const reaktor_style *c;
|
||||
css_selector_t *sel;
|
||||
css_style_decl_t *decl;
|
||||
css_computed_style_t computed;
|
||||
|
||||
if (!name || name[0] != '-' || name[1] != '-') return 0;
|
||||
if (!(c = cached(name))) return reaktor_sheet_color(g.sheet, name, rgba);
|
||||
if (c->matched) memcpy(rgba, c->bg, 4);
|
||||
return c->matched;
|
||||
memset(out, 0, sizeof(*out));
|
||||
out->opacity = 1.0f;
|
||||
if (!g.ready || !selector) return;
|
||||
|
||||
sel = css_selector_create(selector);
|
||||
if (!sel) return;
|
||||
|
||||
decl = css_select_style(sel);
|
||||
css_selector_destroy(sel);
|
||||
if (!decl) return;
|
||||
|
||||
memset(&computed, 0, sizeof(computed));
|
||||
css_cascade_style(decl, &computed);
|
||||
css_compute_absolute_values(&g.root, &computed, &g.metrics);
|
||||
|
||||
rgba_of(computed.background_color, out->bg);
|
||||
rgba_of(computed.color, out->fg);
|
||||
rgba_of(computed.border_top_color, out->border_col);
|
||||
out->border = px_of(computed.border_top_width,
|
||||
computed.unit_bits.border_top_width);
|
||||
out->rounding = px_of(computed.border_top_left_radius,
|
||||
computed.unit_bits.border_top_left_radius);
|
||||
out->pad_x = px_of(computed.padding_left,
|
||||
computed.unit_bits.padding_left);
|
||||
out->pad_y = px_of(computed.padding_top,
|
||||
computed.unit_bits.padding_top);
|
||||
|
||||
out->pad[REAKTOR_SIDE_TOP] = out->pad_y;
|
||||
out->pad[REAKTOR_SIDE_RIGHT] = px_of(computed.padding_right,
|
||||
computed.unit_bits.padding_right);
|
||||
out->pad[REAKTOR_SIDE_BOTTOM] = px_of(computed.padding_bottom,
|
||||
computed.unit_bits.padding_bottom);
|
||||
out->pad[REAKTOR_SIDE_LEFT] = out->pad_x;
|
||||
|
||||
out->border_w[REAKTOR_SIDE_TOP] = out->border;
|
||||
out->border_w[REAKTOR_SIDE_RIGHT] =
|
||||
px_of(computed.border_right_width,
|
||||
computed.unit_bits.border_right_width);
|
||||
out->border_w[REAKTOR_SIDE_BOTTOM] =
|
||||
px_of(computed.border_bottom_width,
|
||||
computed.unit_bits.border_bottom_width);
|
||||
out->border_w[REAKTOR_SIDE_LEFT] =
|
||||
px_of(computed.border_left_width,
|
||||
computed.unit_bits.border_left_width);
|
||||
|
||||
out->radius[REAKTOR_CORNER_TL] = out->rounding;
|
||||
out->radius[REAKTOR_CORNER_TR] =
|
||||
px_of(computed.border_top_right_radius,
|
||||
computed.unit_bits.border_top_right_radius);
|
||||
out->radius[REAKTOR_CORNER_BR] =
|
||||
px_of(computed.border_bottom_right_radius,
|
||||
computed.unit_bits.border_bottom_right_radius);
|
||||
out->radius[REAKTOR_CORNER_BL] =
|
||||
px_of(computed.border_bottom_left_radius,
|
||||
computed.unit_bits.border_bottom_left_radius);
|
||||
|
||||
out->margin[REAKTOR_SIDE_TOP] = px_of(computed.margin_top,
|
||||
computed.unit_bits.margin_top);
|
||||
out->margin[REAKTOR_SIDE_RIGHT] = px_of(computed.margin_right,
|
||||
computed.unit_bits.margin_right);
|
||||
out->margin[REAKTOR_SIDE_BOTTOM] =
|
||||
px_of(computed.margin_bottom, computed.unit_bits.margin_bottom);
|
||||
out->margin[REAKTOR_SIDE_LEFT] = px_of(computed.margin_left,
|
||||
computed.unit_bits.margin_left);
|
||||
|
||||
out->width = px_of(computed.width, computed.unit_bits.width);
|
||||
out->height = px_of(computed.height, computed.unit_bits.height);
|
||||
out->min_width = px_of(computed.min_width,
|
||||
computed.unit_bits.min_width);
|
||||
out->min_height = px_of(computed.min_height,
|
||||
computed.unit_bits.min_height);
|
||||
out->font_px = computed.font_size > 0.0f
|
||||
? (int)(computed.font_size + 0.5f) : 0;
|
||||
out->max_width = px_of(computed.max_width,
|
||||
computed.unit_bits.max_width);
|
||||
out->max_height = px_of(computed.max_height,
|
||||
computed.unit_bits.max_height);
|
||||
|
||||
out->opacity = computed.type_bits.opacity == CSS_OPACITY_SET
|
||||
? computed.opacity : 1.0f;
|
||||
if (out->opacity < 0.0f) out->opacity = 0.0f;
|
||||
if (out->opacity > 1.0f) out->opacity = 1.0f;
|
||||
|
||||
out->line_height = 0.0f;
|
||||
switch (computed.type_bits.line_height) {
|
||||
case CSS_LINE_HEIGHT_NUMBER: {
|
||||
float fs = computed.font_size > 0.0f ? computed.font_size
|
||||
: g.root.font_size;
|
||||
|
||||
out->line_height = computed.line_height * (fs > 0.0f ? fs : 16.0f);
|
||||
break;
|
||||
}
|
||||
case CSS_LINE_HEIGHT_DIMENSION:
|
||||
out->line_height = px_of(computed.line_height,
|
||||
computed.unit_bits.line_height);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (computed.type_bits.font_weight) {
|
||||
case CSS_FONT_WEIGHT_BOLD:
|
||||
case CSS_FONT_WEIGHT_700:
|
||||
case CSS_FONT_WEIGHT_800:
|
||||
case CSS_FONT_WEIGHT_900:
|
||||
out->bold = 1;
|
||||
break;
|
||||
default:
|
||||
out->bold = 0;
|
||||
break;
|
||||
}
|
||||
out->matched = decl->length > 0;
|
||||
|
||||
css_style_decl_destroy(decl);
|
||||
css_computed_style_destroy(&computed);
|
||||
}
|
||||
|
||||
void reaktor_style_get(const char *selector, reaktor_style *out)
|
||||
{
|
||||
const reaktor_style *c;
|
||||
unsigned h;
|
||||
size_t len;
|
||||
cache_entry *e;
|
||||
|
||||
if (!out) return;
|
||||
if (selector && (c = cached(selector)) != NULL) *out = *c;
|
||||
else reaktor_sheet_style(g.sheet, selector, out);
|
||||
h = hash_of(selector);
|
||||
if (g.cache_cap) {
|
||||
e = cache_slot(selector, h);
|
||||
if (e->selector) {
|
||||
*out = e->style;
|
||||
return;
|
||||
}
|
||||
}
|
||||
resolve(selector, out);
|
||||
if (2 * (g.cache_n + 1) > g.cache_cap) cache_grow();
|
||||
if (g.cache_n + 1 >= g.cache_cap) return;
|
||||
len = strlen(selector) + 1;
|
||||
e = cache_slot(selector, h);
|
||||
e->selector = malloc(len);
|
||||
if (!e->selector) return;
|
||||
memcpy(e->selector, selector, len);
|
||||
e->hash = h;
|
||||
e->style = *out;
|
||||
g.cache_n++;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
int reaktor_style_init(const char *const *css_paths, int count,
|
||||
const char *theme);
|
||||
int reaktor_style_add(const char *path);
|
||||
void reaktor_style_shutdown(void);
|
||||
unsigned reaktor_style_loads(void);
|
||||
void reaktor_style_darken(unsigned char rgba[4], float amount);
|
||||
|
||||
+23
-79
@@ -63,9 +63,7 @@ struct img_slot {
|
||||
struct tex_slot s;
|
||||
char src[192];
|
||||
unsigned hash;
|
||||
struct nk_color stroke;
|
||||
float sw;
|
||||
int ion, px, w, h;
|
||||
int px, w, h;
|
||||
float ink_l, ink_r;
|
||||
};
|
||||
|
||||
@@ -103,39 +101,6 @@ struct field_undo {
|
||||
int n, top;
|
||||
};
|
||||
|
||||
#define REAKTOR_DAMAGE_RECTS 4
|
||||
|
||||
enum { REAKTOR_DAMAGE_NONE, REAKTOR_DAMAGE_PARTIAL, REAKTOR_DAMAGE_FULL };
|
||||
|
||||
typedef struct reaktor_damage_item {
|
||||
unsigned hash, at, len;
|
||||
SDL_Rect box;
|
||||
} reaktor_damage_item;
|
||||
|
||||
typedef struct reaktor_damage_list {
|
||||
reaktor_damage_item *item;
|
||||
int n, cap;
|
||||
unsigned char *key;
|
||||
int used, size;
|
||||
int *scaled;
|
||||
int scaled_n, scaled_cap;
|
||||
int ow, oh, laid_w, laid_h;
|
||||
float s;
|
||||
} reaktor_damage_list;
|
||||
|
||||
typedef struct reaktor_damage {
|
||||
reaktor_damage_list list[2];
|
||||
int now, collected, forced;
|
||||
SDL_Texture *k, *check;
|
||||
int kw, kh;
|
||||
struct nk_color clear;
|
||||
int checking;
|
||||
unsigned idle;
|
||||
Uint64 drawn;
|
||||
float peak;
|
||||
unsigned long partial, full, mismatched;
|
||||
} reaktor_damage;
|
||||
|
||||
typedef struct undo_stack {
|
||||
struct reaktor_undo_step *step;
|
||||
unsigned *group, next, open;
|
||||
@@ -167,7 +132,7 @@ struct App {
|
||||
char tip_text[256];
|
||||
|
||||
char render_mode[32];
|
||||
int vsync_on, aa_mode;
|
||||
int vsync_on, aa_mode, redraw_always;
|
||||
|
||||
char frame_rate[16];
|
||||
char drag_rate[16];
|
||||
@@ -218,7 +183,7 @@ struct App {
|
||||
int theme_mode;
|
||||
int theme_pending;
|
||||
struct nk_color page, card_bg, text, accent;
|
||||
struct nk_color icon_col;
|
||||
char icon_hex[10];
|
||||
|
||||
struct hot_region {
|
||||
struct nk_rect r;
|
||||
@@ -232,6 +197,7 @@ struct App {
|
||||
unsigned char hot_last_repaint;
|
||||
|
||||
int dirty;
|
||||
/* The last rounded surface filled this frame, which a field may sit on. */
|
||||
struct nk_rect surface_at;
|
||||
struct nk_color surface;
|
||||
unsigned why;
|
||||
@@ -252,6 +218,7 @@ struct App {
|
||||
Uint64 last_draw_ms;
|
||||
int hover_pending;
|
||||
int renderer_is_sw;
|
||||
int sw_noaa;
|
||||
int drag_moved;
|
||||
int cal_frames, cal_done;
|
||||
double cal_cpu0;
|
||||
@@ -273,7 +240,6 @@ struct App {
|
||||
int popup_open, popups_inline;
|
||||
undo_stack undo;
|
||||
int want_capture;
|
||||
int build_only;
|
||||
SDL_Surface *capture;
|
||||
struct { const char *buf; int from, to, asked; } field_pick;
|
||||
struct { char kind[32], from[64], label[96]; int item, armed, active; struct nk_vec2 at; } drag;
|
||||
@@ -289,8 +255,7 @@ struct App {
|
||||
Uint64 last_frame_ms;
|
||||
float frame_gap_ms;
|
||||
struct nka_context *anim;
|
||||
int style_ms_x100, window_ms_x100, atlas_ms_x100, first_ms_x100;
|
||||
Uint64 started;
|
||||
int style_ms_x100;
|
||||
int sheets;
|
||||
const char *font_face, *font_face_bold;
|
||||
const char *icon_dirs[8];
|
||||
@@ -300,20 +265,16 @@ struct App {
|
||||
int settled_run, settle_tries;
|
||||
unsigned style_loads;
|
||||
int build_ms_x100, render_ms_x100, present_ms_x100;
|
||||
float render_scale;
|
||||
reaktor_damage damage;
|
||||
};
|
||||
|
||||
void img_cache_clear(App *app);
|
||||
void img_cache_free(App *app);
|
||||
struct nk_image ionicon_over(App *app, const char *name, struct nk_color stroke,
|
||||
float sw, int px, float over);
|
||||
struct nk_image ionicon_ink(App *app, const char *name, struct nk_color stroke,
|
||||
float sw, int px, float *left, float *right);
|
||||
struct nk_image icon_over(App *app, const char *src, int px, float over);
|
||||
struct nk_image icon(App *app, const char *src, int px);
|
||||
struct nk_image icon_ink(App *app, const char *src, int px, float *left, float *right);
|
||||
const struct nk_user_font *pick_font(App *app, int px, int bold);
|
||||
const struct nk_user_font *base_font(App *app);
|
||||
void rebuild_font(App *app);
|
||||
void atlas_forget(void);
|
||||
void apply_render_scale(App *app);
|
||||
void reaktor_set_window_icon(SDL_Window *win, const char *name);
|
||||
|
||||
@@ -338,8 +299,7 @@ enum {
|
||||
REAKTOR_WHY_STYLE = 1u << 3
|
||||
};
|
||||
|
||||
void reaktor_tray_event(App *app, const SDL_Event *e);
|
||||
|
||||
/* The Inspector module, or its _none twin. */
|
||||
struct reaktor_inspector_spec;
|
||||
void reaktor_inspector_early(void);
|
||||
void reaktor_inspector_start(App *app, const struct reaktor_inspector_spec *spec, int flag);
|
||||
@@ -377,13 +337,14 @@ extern void (*reaktor_test_hook)(App *app);
|
||||
|
||||
|
||||
void hot_push(App *app, struct nk_rect r, int cursor, int repaint);
|
||||
int hot_hover(const struct nk_context *ctx, struct nk_rect r);
|
||||
#define REAKTOR_BUTTON_GAP 12.0f
|
||||
float css_button_content_w(App *app, struct nk_context *ctx, const char *selector,
|
||||
const struct nk_user_font *f, const char *ionicon,
|
||||
const struct nk_user_font *f, const char *icon_src,
|
||||
const char *label);
|
||||
const char *reaktor_ionicon_src(char out[192], const char *name, const char *hex, float sw);
|
||||
const char *reaktor_button_src(char out[192], const char *ionicon);
|
||||
int css_button_accent(App *app, struct nk_context *ctx, const char *selector,
|
||||
const char *ionicon,
|
||||
const char *icon_src,
|
||||
const char *label);
|
||||
int reaktor_css_button_flat(App *app, struct nk_context *ctx, const char *icon,
|
||||
const char *name, int accent);
|
||||
@@ -410,8 +371,6 @@ typedef struct reaktor_surface {
|
||||
} reaktor_surface;
|
||||
|
||||
reaktor_surface reaktor_rule_surface(const reaktor_style *s, float radius);
|
||||
void reaktor_fill_style(App *app, struct nk_command_buffer *cv, struct nk_rect b,
|
||||
float rounding, const reaktor_style *s);
|
||||
void reaktor_paint_surface(App *app, struct nk_command_buffer *cv, struct nk_rect r,
|
||||
const reaktor_surface *s);
|
||||
struct nk_rect reaktor_rect_trunc(struct nk_rect b);
|
||||
@@ -421,7 +380,6 @@ void reaktor_fade_since(struct nk_context *ctx, const struct nk_command_buffer *
|
||||
|
||||
App *reaktor_main_app(void);
|
||||
bool reaktor_app_wake(const App *app);
|
||||
SDL_Renderer *reaktor_renderer_for(SDL_Window *win, const char *name, int hdr);
|
||||
void reaktor_hint(const char *name, const char *value);
|
||||
int reaktor_key_hook(App *app, const SDL_Event *event);
|
||||
void reaktor_take_event(App *app, SDL_Event *event);
|
||||
@@ -447,19 +405,7 @@ SDL_Cursor *reaktor_cursor(int kind);
|
||||
int reaktor_instance_claim(int argc, char **argv);
|
||||
void reaktor_instance_listen(App *app, void (*opened)(App *app, const char *path));
|
||||
void reaktor_instance_stop(void);
|
||||
void reaktor_mask_rounded_fills(App *app);
|
||||
void reaktor_render(App *app, const SDL_Rect *rects, int n);
|
||||
|
||||
unsigned reaktor_damage_collect(App *app, struct nk_context *ctx);
|
||||
int reaktor_damage_render(App *app);
|
||||
void reaktor_damage_presented(App *app);
|
||||
int reaktor_damage_views(App *app);
|
||||
void reaktor_damage_free(App *app);
|
||||
void reaktor_texture_serial(SDL_Texture *t);
|
||||
void reaktor_damage_add(reaktor_damage_list *l, const void *key, int len,
|
||||
SDL_Rect box, int scaled);
|
||||
int reaktor_damage_diff(const reaktor_damage_list *was, const reaktor_damage_list *now,
|
||||
SDL_Rect *rects, int *n, long long *covered);
|
||||
void reaktor_render(App *app);
|
||||
|
||||
typedef void (*reaktor_page_fn)(App *app, struct nk_context *ctx, int w, int h,
|
||||
void *user);
|
||||
@@ -473,13 +419,12 @@ void reaktor_windows_take(App *app, const SDL_Event *event);
|
||||
int reaktor_windows_retitle(App *app, const char *title);
|
||||
void reaktor_windows_draw(void);
|
||||
void reaktor_windows_restyle(void);
|
||||
int reaktor_windows_holding(void);
|
||||
void reaktor_windows_dirty(void);
|
||||
void reaktor_windows_rescale(void);
|
||||
void reaktor_windows_close_all(void);
|
||||
const char *reaktor_launch_icon(void);
|
||||
int css_button_icon(App *app, struct nk_context *ctx, const char *selector,
|
||||
const char *ionicon, const char *label);
|
||||
const char *icon_src, const char *label);
|
||||
|
||||
struct nk_color readable_on(const unsigned char bg[4], const char *preferred,
|
||||
const char *fallback);
|
||||
@@ -503,6 +448,8 @@ typedef struct reaktor_button_look {
|
||||
void reaktor_button_look_of(const char *selector, reaktor_button_look *k);
|
||||
int reaktor_css_button_look(App *app, struct nk_context *ctx,
|
||||
const reaktor_button_look *k, const char *label);
|
||||
int reaktor_button_label_as(App *app, struct nk_context *ctx,
|
||||
const char *sel, const char *label);
|
||||
int reaktor_button_accent_as(App *app, struct nk_context *ctx, const char *sel,
|
||||
const char *ionicon, const char *label);
|
||||
int reaktor_css_button_custom(App *app, struct nk_context *ctx, const char *sel,
|
||||
@@ -534,19 +481,15 @@ void reaktor_unfit_label(struct nk_context *ctx, int fitted);
|
||||
int reaktor_radio_label(App *app, struct nk_context *ctx, const char *label,
|
||||
int on);
|
||||
|
||||
void reaktor_slider_ramp(App *app, struct nk_context *ctx, unsigned id, float *val,
|
||||
float lo, float hi, float step, const reaktor_style *fill);
|
||||
void reaktor_slider_bar_int(App *app, struct nk_context *ctx, unsigned id,
|
||||
int *val, int lo, int hi, int step,
|
||||
const reaktor_style *fill);
|
||||
int *val, int lo, int hi, int step);
|
||||
void reaktor_knob_dial(App *app, struct nk_context *ctx, float *val,
|
||||
float lo, float hi, enum nk_heading zero);
|
||||
|
||||
int reaktor_property_live(struct nk_context *ctx);
|
||||
void reaktor_property_push(struct nk_context *ctx, struct nk_rect b, int live);
|
||||
void reaktor_property_push(struct nk_context *ctx);
|
||||
void reaktor_property_pop(struct nk_context *ctx);
|
||||
void reaktor_property_chrome(App *app, struct nk_context *ctx, struct nk_rect b,
|
||||
struct nk_rect *steps, int live);
|
||||
struct nk_rect *steps);
|
||||
|
||||
struct nk_rect reaktor_combo_content(struct nk_context *ctx, struct nk_rect h);
|
||||
void reaktor_combo_chrome(App *app, struct nk_context *ctx, struct nk_rect h,
|
||||
@@ -554,7 +497,8 @@ void reaktor_combo_chrome(App *app, struct nk_context *ctx, struct nk_rect h,
|
||||
|
||||
int reaktor_link_label(App *app, struct nk_context *ctx, const char *label,
|
||||
int active);
|
||||
int reaktor_css_button_color(App *app, struct nk_context *ctx, struct nk_color fill);
|
||||
int reaktor_css_button_color(App *app, struct nk_context *ctx, const char *name,
|
||||
struct nk_color fill);
|
||||
|
||||
void field_undo_clear(App *app);
|
||||
|
||||
|
||||
+9
-10
@@ -295,7 +295,7 @@ scan(const char *text, unsigned **set, int *n, int *cap)
|
||||
if (cp <= 0xFF || cp == SDL_INVALID_UNICODE_CODEPOINT) continue;
|
||||
if (*n == *cap) {
|
||||
int grow = *cap ? *cap * 2 : 256;
|
||||
unsigned *more = SDL_realloc(*set, (size_t)grow * sizeof **set);
|
||||
unsigned *more = realloc(*set, (size_t)grow * sizeof **set);
|
||||
|
||||
if (!more) return;
|
||||
*set = more;
|
||||
@@ -305,8 +305,8 @@ scan(const char *text, unsigned **set, int *n, int *cap)
|
||||
}
|
||||
}
|
||||
|
||||
unsigned *
|
||||
reaktor_locale_codepoints(int *count)
|
||||
int
|
||||
reaktor_locale_codepoints(unsigned *out, int cap)
|
||||
{
|
||||
unsigned *set = NULL;
|
||||
int n = 0, room = 0, unique = 0, i, j;
|
||||
@@ -318,12 +318,11 @@ reaktor_locale_codepoints(int *count)
|
||||
}
|
||||
|
||||
if (n) qsort(set, (size_t)n, sizeof *set, by_codepoint);
|
||||
for (i = 0; i < n; i++)
|
||||
if (!unique || set[i] != set[unique - 1]) set[unique++] = set[i];
|
||||
*count = unique;
|
||||
if (!unique) {
|
||||
SDL_free(set);
|
||||
return NULL;
|
||||
for (i = 0; i < n; i++) {
|
||||
if (unique && set[i] == set[i - 1]) continue;
|
||||
if (out && unique < cap) out[unique] = set[i];
|
||||
unique++;
|
||||
}
|
||||
return set;
|
||||
free(set);
|
||||
return unique;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
int reaktor_locale_init(void);
|
||||
int reaktor_locale_find(const char *code);
|
||||
const char *reaktor_locale_system_code(void);
|
||||
unsigned *reaktor_locale_codepoints(int *count);
|
||||
int reaktor_locale_codepoints(unsigned *out, int cap);
|
||||
long reaktor_plural_eval(const char *expr, unsigned long n);
|
||||
|
||||
#ifdef REAKTOR_LOCALE_EMBEDDED
|
||||
|
||||
@@ -40,6 +40,7 @@ reaktor_format_money(char *buf, size_t cap, double amount, const char *currency)
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* English names and numbers: the letters reaktor_format_pattern knows. */
|
||||
const char *
|
||||
reaktor_format_pattern(char *buf, size_t cap, const struct tm *t, const char *pattern)
|
||||
{
|
||||
|
||||
@@ -32,11 +32,12 @@ unsigned *
|
||||
reaktor_locale_glyphs(void)
|
||||
{
|
||||
unsigned *cp, *out;
|
||||
int n = 0, i, at = 0;
|
||||
int n = reaktor_locale_codepoints(NULL, 0), i, at = 0;
|
||||
|
||||
if (!(cp = reaktor_locale_codepoints(&n))) return NULL;
|
||||
if (n <= 0 || !(cp = SDL_malloc((size_t)n * sizeof *cp))) return NULL;
|
||||
out = SDL_malloc(((size_t)n * 2 + 3) * sizeof *out);
|
||||
if (out) {
|
||||
reaktor_locale_codepoints(cp, n);
|
||||
out[at++] = 0x0020;
|
||||
out[at++] = 0x00FF;
|
||||
for (i = 0; i < n; i++) {
|
||||
|
||||
@@ -1,767 +0,0 @@
|
||||
#include "internal.h"
|
||||
|
||||
#define LOOKAHEAD 32
|
||||
#define SERIAL "reaktor.serial"
|
||||
#define IDLE_MS 1000
|
||||
|
||||
typedef struct sink {
|
||||
reaktor_damage_list *l;
|
||||
unsigned h;
|
||||
int ok;
|
||||
const void *tex;
|
||||
Sint64 serial;
|
||||
} sink;
|
||||
|
||||
void
|
||||
reaktor_texture_serial(SDL_Texture *t)
|
||||
{
|
||||
static Sint64 next;
|
||||
|
||||
if (t) SDL_SetNumberProperty(SDL_GetTextureProperties(t), SERIAL, ++next);
|
||||
}
|
||||
|
||||
static Sint64
|
||||
serial_of(sink *k, const void *t)
|
||||
{
|
||||
if (!t) return 0;
|
||||
if (t != k->tex) {
|
||||
k->tex = t;
|
||||
k->serial = SDL_GetNumberProperty(SDL_GetTextureProperties((SDL_Texture *)t),
|
||||
SERIAL, 0);
|
||||
}
|
||||
return k->serial;
|
||||
}
|
||||
|
||||
static void
|
||||
put(sink *k, const void *p, size_t n)
|
||||
{
|
||||
reaktor_damage_list *l = k->l;
|
||||
|
||||
if (!l) {
|
||||
k->h = reaktor_fnv_n(k->h, p, n);
|
||||
return;
|
||||
}
|
||||
if (!k->ok || !reaktor_grow((void **)&l->key, &l->size, l->used + (int)n, 1)) {
|
||||
k->ok = 0;
|
||||
return;
|
||||
}
|
||||
SDL_memcpy(l->key + l->used, p, n);
|
||||
l->used += (int)n;
|
||||
}
|
||||
|
||||
typedef struct span {
|
||||
float x0, y0, x1, y1;
|
||||
int any;
|
||||
} span;
|
||||
|
||||
static void
|
||||
span_at(span *b, float x, float y)
|
||||
{
|
||||
if (!b->any || x < b->x0) b->x0 = x;
|
||||
if (!b->any || y < b->y0) b->y0 = y;
|
||||
if (!b->any || x > b->x1) b->x1 = x;
|
||||
if (!b->any || y > b->y1) b->y1 = y;
|
||||
b->any = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
span_rect(span *b, float x, float y, float w, float h)
|
||||
{
|
||||
span_at(b, x, y);
|
||||
span_at(b, x + w, y + h);
|
||||
}
|
||||
|
||||
static void
|
||||
span_points(span *b, const struct nk_vec2i *p, int n)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n; i++) span_at(b, (float)p[i].x, (float)p[i].y);
|
||||
}
|
||||
|
||||
/* A command by its fields, one at a time: the structs have gaps, and a gap
|
||||
keeps whatever the buffer or a copied struct held before. */
|
||||
#define K(f) put(k, &(f), sizeof(f))
|
||||
|
||||
static void
|
||||
command_read(const struct nk_command *c, struct nk_rect clip, float ink, sink *k,
|
||||
span *b, float *thick)
|
||||
{
|
||||
Sint64 id;
|
||||
|
||||
*thick = 0.0f;
|
||||
K(c->type);
|
||||
switch (c->type) {
|
||||
case NK_COMMAND_SCISSOR: {
|
||||
const struct nk_command_scissor *x = (const void *)c;
|
||||
K(x->x); K(x->y); K(x->w); K(x->h);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_LINE: {
|
||||
const struct nk_command_line *x = (const void *)c;
|
||||
K(x->line_thickness); K(x->begin); K(x->end); K(x->color);
|
||||
span_points(b, &x->begin, 1);
|
||||
span_points(b, &x->end, 1);
|
||||
*thick = x->line_thickness;
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_CURVE: {
|
||||
const struct nk_command_curve *x = (const void *)c;
|
||||
K(x->line_thickness); K(x->begin); K(x->end); K(x->ctrl); K(x->color);
|
||||
span_points(b, &x->begin, 1);
|
||||
span_points(b, &x->end, 1);
|
||||
span_points(b, x->ctrl, 2);
|
||||
*thick = x->line_thickness;
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_RECT: {
|
||||
const struct nk_command_rect *x = (const void *)c;
|
||||
K(x->rounding); K(x->line_thickness); K(x->x); K(x->y); K(x->w); K(x->h); K(x->color);
|
||||
span_rect(b, x->x, x->y, x->w, x->h);
|
||||
*thick = x->line_thickness;
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_RECT_FILLED: {
|
||||
const struct nk_command_rect_filled *x = (const void *)c;
|
||||
K(x->rounding); K(x->x); K(x->y); K(x->w); K(x->h); K(x->color);
|
||||
span_rect(b, x->x, x->y, x->w, x->h);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_RECT_MULTI_COLOR: {
|
||||
const struct nk_command_rect_multi_color *x = (const void *)c;
|
||||
K(x->x); K(x->y); K(x->w); K(x->h); K(x->left); K(x->top); K(x->bottom); K(x->right);
|
||||
span_rect(b, x->x, x->y, x->w, x->h);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_TRIANGLE: {
|
||||
const struct nk_command_triangle *x = (const void *)c;
|
||||
K(x->line_thickness); K(x->a); K(x->b); K(x->c); K(x->color);
|
||||
span_points(b, &x->a, 1);
|
||||
span_points(b, &x->b, 1);
|
||||
span_points(b, &x->c, 1);
|
||||
*thick = x->line_thickness;
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_TRIANGLE_FILLED: {
|
||||
const struct nk_command_triangle_filled *x = (const void *)c;
|
||||
K(x->a); K(x->b); K(x->c); K(x->color);
|
||||
span_points(b, &x->a, 1);
|
||||
span_points(b, &x->b, 1);
|
||||
span_points(b, &x->c, 1);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_CIRCLE: {
|
||||
const struct nk_command_circle *x = (const void *)c;
|
||||
K(x->x); K(x->y); K(x->line_thickness); K(x->w); K(x->h); K(x->color);
|
||||
span_rect(b, x->x, x->y, x->w, x->h);
|
||||
*thick = x->line_thickness;
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_CIRCLE_FILLED: {
|
||||
const struct nk_command_circle_filled *x = (const void *)c;
|
||||
K(x->x); K(x->y); K(x->w); K(x->h); K(x->color);
|
||||
span_rect(b, x->x, x->y, x->w, x->h);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_ARC: {
|
||||
const struct nk_command_arc *x = (const void *)c;
|
||||
K(x->cx); K(x->cy); K(x->r); K(x->line_thickness); K(x->a); K(x->color);
|
||||
span_rect(b, (float)x->cx - x->r, (float)x->cy - x->r, 2.0f * x->r, 2.0f * x->r);
|
||||
*thick = x->line_thickness;
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_ARC_FILLED: {
|
||||
const struct nk_command_arc_filled *x = (const void *)c;
|
||||
K(x->cx); K(x->cy); K(x->r); K(x->a); K(x->color);
|
||||
span_rect(b, (float)x->cx - x->r, (float)x->cy - x->r, 2.0f * x->r, 2.0f * x->r);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_POLYGON:
|
||||
case NK_COMMAND_POLYLINE: {
|
||||
const struct nk_command_polygon *x = (const void *)c;
|
||||
K(x->color); K(x->line_thickness); K(x->point_count);
|
||||
put(k, x->points, (size_t)x->point_count * sizeof x->points[0]);
|
||||
span_points(b, x->points, x->point_count);
|
||||
*thick = x->line_thickness;
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_POLYGON_FILLED: {
|
||||
const struct nk_command_polygon_filled *x = (const void *)c;
|
||||
K(x->color); K(x->point_count);
|
||||
put(k, x->points, (size_t)x->point_count * sizeof x->points[0]);
|
||||
span_points(b, x->points, x->point_count);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_IMAGE: {
|
||||
const struct nk_command_image *x = (const void *)c;
|
||||
K(x->x); K(x->y); K(x->w); K(x->h);
|
||||
id = serial_of(k, x->img.handle.ptr);
|
||||
K(x->img.handle.ptr); K(id); K(x->img.w); K(x->img.h); K(x->img.region); K(x->col);
|
||||
span_rect(b, x->x, x->y, x->w, x->h);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_CUSTOM: {
|
||||
const struct nk_command_custom *x = (const void *)c;
|
||||
K(x->x); K(x->y); K(x->w); K(x->h); K(x->callback_data.ptr); K(x->callback);
|
||||
span_rect(b, clip.x, clip.y, clip.w, clip.h);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_TEXT: {
|
||||
const struct nk_command_text *x = (const void *)c;
|
||||
float g = SDL_max((float)x->h, ink * x->height);
|
||||
|
||||
id = serial_of(k, x->font ? x->font->texture.ptr : NULL);
|
||||
K(x->font); K(id); K(x->background); K(x->foreground);
|
||||
K(x->x); K(x->y); K(x->w); K(x->h); K(x->height); K(x->length);
|
||||
put(k, x->string, (size_t)x->length);
|
||||
span_rect(b, x->x - g, x->y - g, x->w + 2.0f * g, x->h + 2.0f * g);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#undef K
|
||||
|
||||
static int
|
||||
image_scaled(const struct nk_command_image *x, float s)
|
||||
{
|
||||
float sw, sh;
|
||||
|
||||
if (x->img.w || x->img.h) {
|
||||
sw = (float)x->img.region[2];
|
||||
sh = (float)x->img.region[3];
|
||||
} else if (!x->img.handle.ptr ||
|
||||
!SDL_GetTextureSize((SDL_Texture *)x->img.handle.ptr, &sw, &sh)) {
|
||||
return 1;
|
||||
}
|
||||
return sw != (float)x->w * s || sh != (float)x->h * s;
|
||||
}
|
||||
|
||||
static SDL_Rect
|
||||
box_cut(SDL_Rect a, SDL_Rect b)
|
||||
{
|
||||
SDL_Rect r;
|
||||
|
||||
if (!SDL_GetRectIntersection(&a, &b, &r)) SDL_zero(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
static SDL_Rect
|
||||
device_box(float x0, float y0, float x1, float y1, float s, int m)
|
||||
{
|
||||
SDL_Rect d;
|
||||
|
||||
d.x = (int)SDL_floorf(x0 * s) - m;
|
||||
d.y = (int)SDL_floorf(y0 * s) - m;
|
||||
d.w = (int)SDL_ceilf(x1 * s) + m - d.x;
|
||||
d.h = (int)SDL_ceilf(y1 * s) + m - d.y;
|
||||
return d;
|
||||
}
|
||||
|
||||
static int
|
||||
item_close(reaktor_damage_list *l, int at, SDL_Rect box, int scaled)
|
||||
{
|
||||
reaktor_damage_item *it;
|
||||
|
||||
if (!reaktor_grow((void **)&l->item, &l->cap, l->n + 1, sizeof *l->item) ||
|
||||
(scaled && !reaktor_grow((void **)&l->scaled, &l->scaled_cap, l->scaled_n + 1,
|
||||
sizeof *l->scaled)))
|
||||
return 0;
|
||||
if (scaled) l->scaled[l->scaled_n++] = l->n;
|
||||
it = &l->item[l->n++];
|
||||
it->at = (unsigned)at;
|
||||
it->len = (unsigned)(l->used - at);
|
||||
it->hash = reaktor_fnv_n(REAKTOR_FNV, l->key + at, it->len);
|
||||
it->box = box;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_damage_add(reaktor_damage_list *l, const void *key, int len,
|
||||
SDL_Rect box, int scaled)
|
||||
{
|
||||
int at = l->used;
|
||||
|
||||
if (!reaktor_grow((void **)&l->key, &l->size, l->used + len, 1)) return;
|
||||
SDL_memcpy(l->key + at, key, (size_t)len);
|
||||
l->used += len;
|
||||
if (!item_close(l, at, box, scaled)) l->used = at;
|
||||
}
|
||||
|
||||
static int
|
||||
applies(const App *app)
|
||||
{
|
||||
float s = app->render_scale;
|
||||
|
||||
return app->renderer_is_sw && s >= 1.0f && s == SDL_floorf(s);
|
||||
}
|
||||
|
||||
static unsigned
|
||||
stream(struct nk_context *ctx)
|
||||
{
|
||||
const struct nk_command *c;
|
||||
sink k;
|
||||
span b;
|
||||
float thick;
|
||||
|
||||
SDL_zero(k);
|
||||
k.h = REAKTOR_FNV;
|
||||
nk_foreach(c, ctx) {
|
||||
if (c->type == NK_COMMAND_NOP) continue;
|
||||
SDL_zero(b);
|
||||
command_read(c, REAKTOR_NO_CLIP, 0.0f, &k, &b, &thick);
|
||||
}
|
||||
return k.h;
|
||||
}
|
||||
|
||||
unsigned
|
||||
reaktor_damage_collect(App *app, struct nk_context *ctx)
|
||||
{
|
||||
reaktor_damage *d = &app->damage;
|
||||
reaktor_damage_list *l = &d->list[d->now];
|
||||
const struct nk_command *c;
|
||||
struct nk_rect clip = REAKTOR_NO_CLIP;
|
||||
SDL_Rect out, cut;
|
||||
float s = app->render_scale;
|
||||
float ink;
|
||||
unsigned h = REAKTOR_FNV;
|
||||
sink k;
|
||||
int i;
|
||||
|
||||
d->collected = 0;
|
||||
if (!applies(app)) return stream(ctx);
|
||||
ink = SDL_max(reaktor_font_ink_em(), reaktor_text_ink_em());
|
||||
l->n = l->used = l->scaled_n = 0;
|
||||
l->ow = l->oh = 0;
|
||||
SDL_GetRenderOutputSize(app->ren, &l->ow, &l->oh);
|
||||
l->laid_w = app->laid_w;
|
||||
l->laid_h = app->laid_h;
|
||||
l->s = s;
|
||||
out.x = out.y = 0;
|
||||
out.w = l->ow;
|
||||
out.h = l->oh;
|
||||
cut = out;
|
||||
SDL_zero(k);
|
||||
k.l = l;
|
||||
k.ok = 1;
|
||||
nk_foreach(c, ctx) {
|
||||
SDL_Rect box = { 0, 0, 0, 0 };
|
||||
span b;
|
||||
float thick;
|
||||
int at = l->used, scaled = 0;
|
||||
short sc[4];
|
||||
|
||||
if (c->type == NK_COMMAND_SCISSOR) {
|
||||
const struct nk_command_scissor *x = (const void *)c;
|
||||
|
||||
clip = nk_rect(x->x, x->y, x->w, x->h);
|
||||
cut = box_cut(device_box(clip.x, clip.y, clip.x + clip.w, clip.y + clip.h, s, 0),
|
||||
out);
|
||||
continue;
|
||||
}
|
||||
if (c->type == NK_COMMAND_NOP) continue;
|
||||
sc[0] = (short)clip.x;
|
||||
sc[1] = (short)clip.y;
|
||||
sc[2] = (short)clip.w;
|
||||
sc[3] = (short)clip.h;
|
||||
put(&k, sc, sizeof sc);
|
||||
SDL_zero(b);
|
||||
command_read(c, clip, ink, &k, &b, &thick);
|
||||
if (!k.ok) break;
|
||||
if (b.any) {
|
||||
int m = (int)SDL_ceilf((thick * 0.5f + 1.0f) * s) + 2;
|
||||
|
||||
box = box_cut(device_box(b.x0, b.y0, b.x1, b.y1, s, m), cut);
|
||||
if (!SDL_RectEmpty(&box) && c->type == NK_COMMAND_IMAGE)
|
||||
scaled = image_scaled((const struct nk_command_image *)c, s);
|
||||
}
|
||||
if (!(k.ok = item_close(l, at, box, scaled))) break;
|
||||
}
|
||||
if (!k.ok) {
|
||||
l->n = l->used = l->scaled_n = 0;
|
||||
return stream(ctx);
|
||||
}
|
||||
d->collected = 1;
|
||||
for (i = 0; i < l->n; i++) h = reaktor_fnv_n(h, &l->item[i].hash, sizeof l->item[i].hash);
|
||||
return h;
|
||||
}
|
||||
|
||||
static int
|
||||
same(const reaktor_damage_list *a, int i, const reaktor_damage_list *b, int j)
|
||||
{
|
||||
const reaktor_damage_item *x = &a->item[i], *y = &b->item[j];
|
||||
|
||||
return x->hash == y->hash && x->len == y->len &&
|
||||
SDL_memcmp(a->key + x->at, b->key + y->at, x->len) == 0;
|
||||
}
|
||||
|
||||
static long long
|
||||
area(SDL_Rect a)
|
||||
{
|
||||
return SDL_RectEmpty(&a) ? 0 : (long long)a.w * a.h;
|
||||
}
|
||||
|
||||
static SDL_Rect
|
||||
box_join(SDL_Rect a, SDL_Rect b)
|
||||
{
|
||||
SDL_Rect r;
|
||||
|
||||
SDL_GetRectUnion(&a, &b, &r);
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Sharing only an edge counts: SDL_HasRectIntersection would keep apart two
|
||||
rectangles that could be one. */
|
||||
static int
|
||||
touches(SDL_Rect a, SDL_Rect b)
|
||||
{
|
||||
return a.x <= b.x + b.w && b.x <= a.x + a.w && a.y <= b.y + b.h && b.y <= a.y + a.h;
|
||||
}
|
||||
|
||||
static void
|
||||
settle(SDL_Rect *r, int *n)
|
||||
{
|
||||
int i, j, again = 1;
|
||||
|
||||
while (again) {
|
||||
again = 0;
|
||||
for (i = 0; i < *n && !again; i++)
|
||||
for (j = i + 1; j < *n && !again; j++)
|
||||
if (touches(r[i], r[j])) {
|
||||
r[i] = box_join(r[i], r[j]);
|
||||
r[j] = r[--*n];
|
||||
again = 1;
|
||||
}
|
||||
if (!again && *n > REAKTOR_DAMAGE_RECTS) {
|
||||
long long best = -1;
|
||||
int bi = 0, bj = 1;
|
||||
|
||||
for (i = 0; i < *n; i++)
|
||||
for (j = i + 1; j < *n; j++) {
|
||||
long long cost = area(box_join(r[i], r[j])) - area(r[i]) - area(r[j]);
|
||||
|
||||
if (best < 0 || cost < best) {
|
||||
best = cost;
|
||||
bi = i;
|
||||
bj = j;
|
||||
}
|
||||
}
|
||||
r[bi] = box_join(r[bi], r[bj]);
|
||||
r[bj] = r[--*n];
|
||||
again = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
take(SDL_Rect *r, int *n, SDL_Rect b)
|
||||
{
|
||||
if (SDL_RectEmpty(&b)) return;
|
||||
r[(*n)++] = b;
|
||||
settle(r, n);
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_damage_diff(const reaktor_damage_list *was, const reaktor_damage_list *now,
|
||||
SDL_Rect *rects, int *count, long long *covered)
|
||||
{
|
||||
SDL_Rect r[REAKTOR_DAMAGE_RECTS + 1];
|
||||
SDL_Rect o = { 0, 0, 0, 0 };
|
||||
int a = 0, b = 0, ae = was->n, be = now->n, n = 0, i, si, changed;
|
||||
|
||||
*count = 0;
|
||||
*covered = 0;
|
||||
if (was->ow != now->ow || was->oh != now->oh || was->s != now->s ||
|
||||
was->laid_w != now->laid_w || was->laid_h != now->laid_h ||
|
||||
now->ow <= 0 || now->oh <= 0 || now->s < 1.0f)
|
||||
return REAKTOR_DAMAGE_FULL;
|
||||
|
||||
while (a < ae && b < be && same(was, a, now, b)) a++, b++;
|
||||
while (ae > a && be > b && same(was, ae - 1, now, be - 1)) ae--, be--;
|
||||
while (a < ae && b < be) {
|
||||
int d, hit = 0;
|
||||
|
||||
if (same(was, a, now, b)) {
|
||||
a++, b++;
|
||||
continue;
|
||||
}
|
||||
for (d = 1; d <= LOOKAHEAD && !hit; d++) {
|
||||
if (b + d < be && same(was, a, now, b + d)) {
|
||||
for (i = 0; i < d; i++) take(r, &n, now->item[b + i].box);
|
||||
b += d;
|
||||
hit = 1;
|
||||
} else if (a + d < ae && same(was, a + d, now, b)) {
|
||||
for (i = 0; i < d; i++) take(r, &n, was->item[a + i].box);
|
||||
a += d;
|
||||
hit = 1;
|
||||
}
|
||||
}
|
||||
if (!hit) {
|
||||
take(r, &n, was->item[a++].box);
|
||||
take(r, &n, now->item[b++].box);
|
||||
}
|
||||
}
|
||||
while (a < ae) take(r, &n, was->item[a++].box);
|
||||
while (b < be) take(r, &n, now->item[b++].box);
|
||||
if (!n) return REAKTOR_DAMAGE_NONE;
|
||||
|
||||
si = (int)now->s;
|
||||
do {
|
||||
changed = 0;
|
||||
for (i = 0; i < now->scaled_n; i++) {
|
||||
SDL_Rect box = now->item[now->scaled[i]].box;
|
||||
int j;
|
||||
|
||||
for (j = 0; j < n; j++) {
|
||||
SDL_Rect g = box_join(r[j], box);
|
||||
|
||||
if (SDL_HasRectIntersection(&r[j], &box) && !SDL_RectsEqual(&g, &r[j])) {
|
||||
r[j] = g;
|
||||
changed = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
SDL_Rect g;
|
||||
|
||||
g.x = r[i].x / si * si;
|
||||
g.y = r[i].y / si * si;
|
||||
g.w = (r[i].x + r[i].w + si - 1) / si * si - g.x;
|
||||
g.h = (r[i].y + r[i].h + si - 1) / si * si - g.y;
|
||||
if (!SDL_RectsEqual(&g, &r[i])) {
|
||||
r[i] = g;
|
||||
changed = 1;
|
||||
}
|
||||
}
|
||||
if (changed) settle(r, &n);
|
||||
} while (changed);
|
||||
|
||||
o.w = now->ow;
|
||||
o.h = now->oh;
|
||||
for (i = 0; i < n; i++) {
|
||||
*covered += area(box_cut(r[i], o));
|
||||
rects[i] = r[i];
|
||||
}
|
||||
*count = n;
|
||||
if (*covered * 2 > (long long)now->ow * now->oh) return REAKTOR_DAMAGE_FULL;
|
||||
return REAKTOR_DAMAGE_PARTIAL;
|
||||
}
|
||||
|
||||
static SDL_Texture *
|
||||
target(App *app, int w, int h)
|
||||
{
|
||||
const SDL_PixelFormat *f = (const SDL_PixelFormat *)SDL_GetPointerProperty(
|
||||
SDL_GetRendererProperties(app->ren), SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER, NULL);
|
||||
SDL_Texture *t;
|
||||
|
||||
if (!f || *f == SDL_PIXELFORMAT_UNKNOWN) return NULL;
|
||||
t = SDL_CreateTexture(app->ren, *f, SDL_TEXTUREACCESS_TARGET, w, h);
|
||||
if (t) SDL_SetTextureBlendMode(t, SDL_BLENDMODE_NONE);
|
||||
return t;
|
||||
}
|
||||
|
||||
/* SDL keeps a view per target: the frame's scale on K, none on the window. */
|
||||
int
|
||||
reaktor_damage_views(App *app)
|
||||
{
|
||||
float s = app->render_scale;
|
||||
|
||||
if (!app->damage.k) return 0;
|
||||
SDL_SetRenderTarget(app->ren, NULL);
|
||||
SDL_SetRenderScale(app->ren, 1.0f, 1.0f);
|
||||
SDL_SetRenderTarget(app->ren, app->damage.k);
|
||||
SDL_SetRenderScale(app->ren, s, s);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
drop(App *app)
|
||||
{
|
||||
reaktor_damage *d = &app->damage;
|
||||
|
||||
if (!d->k) return;
|
||||
SDL_SetRenderTarget(app->ren, NULL);
|
||||
SDL_DestroyTexture(d->k);
|
||||
if (d->check) SDL_DestroyTexture(d->check);
|
||||
d->k = d->check = NULL;
|
||||
SDL_SetRenderScale(app->ren, app->render_scale, app->render_scale);
|
||||
}
|
||||
|
||||
/* K exists to draw the next frame over; an idle window does not need it. */
|
||||
static void
|
||||
idle_due(App *app, void *user)
|
||||
{
|
||||
reaktor_damage *d = &app->damage;
|
||||
Uint64 idle = SDL_GetTicks() - d->drawn;
|
||||
|
||||
(void)user;
|
||||
d->idle = 0;
|
||||
if (!d->k) return;
|
||||
if (idle < IDLE_MS)
|
||||
d->idle = reaktor_timer(app, (int)(IDLE_MS - idle), 0, idle_due, NULL);
|
||||
else
|
||||
drop(app);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_damage_free(App *app)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (app->damage.idle) reaktor_timer_stop(app->damage.idle);
|
||||
app->damage.idle = 0;
|
||||
if (app->ren) drop(app);
|
||||
for (i = 0; i < 2; i++) {
|
||||
SDL_free(app->damage.list[i].item);
|
||||
SDL_free(app->damage.list[i].key);
|
||||
SDL_free(app->damage.list[i].scaled);
|
||||
}
|
||||
SDL_zero(app->damage);
|
||||
}
|
||||
|
||||
static int
|
||||
pixel_mask(const SDL_Surface *a)
|
||||
{
|
||||
return SDL_BYTESPERPIXEL(a->format) == 4 && !SDL_ISPIXELFORMAT_ALPHA(a->format);
|
||||
}
|
||||
|
||||
static void
|
||||
check(App *app, const SDL_Rect *r, int n)
|
||||
{
|
||||
reaktor_damage *d = &app->damage;
|
||||
SDL_Surface *got = NULL, *want = NULL;
|
||||
Uint32 keep = 0xFFFFFFFFu;
|
||||
int x0 = 0, y0 = 0, x1 = -1, y1 = -1, x, y, i;
|
||||
|
||||
if (!d->check && !(d->check = target(app, d->kw, d->kh))) return;
|
||||
SDL_SetRenderTarget(app->ren, d->check);
|
||||
SDL_SetRenderScale(app->ren, app->render_scale, app->render_scale);
|
||||
reaktor_render(app, NULL, 0);
|
||||
want = SDL_RenderReadPixels(app->ren, NULL);
|
||||
SDL_SetRenderTarget(app->ren, d->k);
|
||||
got = SDL_RenderReadPixels(app->ren, NULL);
|
||||
if (got && want && pixel_mask(got)) {
|
||||
const SDL_PixelFormatDetails *f = SDL_GetPixelFormatDetails(got->format);
|
||||
|
||||
if (f) keep = f->Rmask | f->Gmask | f->Bmask;
|
||||
}
|
||||
for (y = 0; got && want && y < got->h && y < want->h; y++) {
|
||||
const Uint8 *p = (const Uint8 *)got->pixels + y * got->pitch;
|
||||
const Uint8 *q = (const Uint8 *)want->pixels + y * want->pitch;
|
||||
int bpp = SDL_BYTESPERPIXEL(got->format);
|
||||
|
||||
for (x = 0; x < got->w; x++) {
|
||||
int differ;
|
||||
|
||||
if (bpp == 4) {
|
||||
Uint32 u, v;
|
||||
|
||||
SDL_memcpy(&u, p + x * 4, 4);
|
||||
SDL_memcpy(&v, q + x * 4, 4);
|
||||
differ = ((u ^ v) & keep) != 0;
|
||||
} else {
|
||||
differ = SDL_memcmp(p + x * bpp, q + x * bpp, (size_t)bpp) != 0;
|
||||
}
|
||||
if (!differ) continue;
|
||||
if (x1 < 0) {
|
||||
x0 = x1 = x;
|
||||
y0 = y1 = y;
|
||||
}
|
||||
x0 = SDL_min(x0, x);
|
||||
x1 = SDL_max(x1, x);
|
||||
y0 = SDL_min(y0, y);
|
||||
y1 = SDL_max(y1, y);
|
||||
}
|
||||
}
|
||||
if (!got || !want) {
|
||||
SDL_Log("damage: cannot read the frame back (%s)", SDL_GetError());
|
||||
d->mismatched++;
|
||||
} else if (x1 >= 0) {
|
||||
char rs[256];
|
||||
int at = 0;
|
||||
|
||||
rs[0] = 0;
|
||||
for (i = 0; i < n && at < (int)sizeof rs; i++)
|
||||
at += SDL_snprintf(rs + at, sizeof rs - (size_t)at, " %d,%d %dx%d",
|
||||
r[i].x, r[i].y, r[i].w, r[i].h);
|
||||
SDL_Log("damage: frame %u differs from a full redraw in %d,%d %dx%d (device);"
|
||||
" redrawn:%s", app->ctx->seq, x0, y0, x1 - x0 + 1, y1 - y0 + 1,
|
||||
n ? rs : " nothing");
|
||||
d->mismatched++;
|
||||
}
|
||||
SDL_DestroySurface(got);
|
||||
SDL_DestroySurface(want);
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_damage_render(App *app)
|
||||
{
|
||||
reaktor_damage *d = &app->damage;
|
||||
reaktor_damage_list *now = &d->list[d->now], *was = &d->list[!d->now];
|
||||
SDL_Rect box[REAKTOR_DAMAGE_RECTS];
|
||||
SDL_Rect r[REAKTOR_DAMAGE_RECTS];
|
||||
long long covered = 0;
|
||||
int kind = REAKTOR_DAMAGE_FULL, n = 0, fresh = 0, direct = 0, si, i;
|
||||
|
||||
if (!d->collected || !applies(app)) {
|
||||
drop(app);
|
||||
direct = 1;
|
||||
} else if (!d->k || d->kw != now->ow || d->kh != now->oh) {
|
||||
drop(app);
|
||||
if (!(d->k = target(app, now->ow, now->oh))) {
|
||||
SDL_SetRenderTarget(app->ren, NULL);
|
||||
direct = 1;
|
||||
} else {
|
||||
d->kw = now->ow;
|
||||
d->kh = now->oh;
|
||||
fresh = 1;
|
||||
reaktor_damage_views(app);
|
||||
}
|
||||
} else if (SDL_GetRenderTarget(app->ren) != d->k) {
|
||||
SDL_SetRenderTarget(app->ren, d->k);
|
||||
}
|
||||
|
||||
if (!direct && !fresh && !d->forced &&
|
||||
SDL_memcmp(&d->clear, &app->clear, sizeof d->clear) == 0)
|
||||
kind = reaktor_damage_diff(was, now, box, &n, &covered);
|
||||
|
||||
if (kind == REAKTOR_DAMAGE_NONE) return 0;
|
||||
reaktor_mask_rounded_fills(app);
|
||||
if (direct) {
|
||||
reaktor_render(app, NULL, 0);
|
||||
return 1;
|
||||
}
|
||||
if (kind == REAKTOR_DAMAGE_FULL) {
|
||||
reaktor_render(app, NULL, 0);
|
||||
d->full++;
|
||||
} else {
|
||||
float share = (float)covered / ((float)now->ow * (float)now->oh);
|
||||
|
||||
si = (int)app->render_scale;
|
||||
for (i = 0; i < n; i++) {
|
||||
r[i].x = box[i].x / si;
|
||||
r[i].y = box[i].y / si;
|
||||
r[i].w = box[i].w / si;
|
||||
r[i].h = box[i].h / si;
|
||||
}
|
||||
if (share > d->peak) d->peak = share;
|
||||
reaktor_render(app, r, n);
|
||||
if (d->checking) check(app, r, n);
|
||||
d->partial++;
|
||||
}
|
||||
|
||||
SDL_SetRenderTarget(app->ren, NULL);
|
||||
SDL_RenderTexture(app->ren, d->k, NULL, NULL);
|
||||
d->now = !d->now;
|
||||
d->clear = app->clear;
|
||||
d->drawn = SDL_GetTicks();
|
||||
if (!d->idle) d->idle = reaktor_timer(app, IDLE_MS, 0, idle_due, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_damage_presented(App *app)
|
||||
{
|
||||
if (app->damage.k) SDL_SetRenderTarget(app->ren, app->damage.k);
|
||||
}
|
||||
+88
-389
@@ -19,6 +19,7 @@ slot_at(void *slots, size_t size, int i)
|
||||
return (struct tex_slot *)((char *)slots + (size_t)i * size);
|
||||
}
|
||||
|
||||
/* Never evicts a slot this frame's commands use. */
|
||||
static struct tex_slot *
|
||||
slot_take(App *app, void *slots, size_t size, int *count, int max)
|
||||
{
|
||||
@@ -78,30 +79,21 @@ blank_image(App *app)
|
||||
app->blank = SDL_CreateTexture(app->ren, SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_TEXTUREACCESS_STATIC, 1, 1);
|
||||
if (!app->blank) return nk_image_id(0);
|
||||
reaktor_texture_serial(app->blank);
|
||||
SDL_UpdateTexture(app->blank, NULL, &clear, (int)sizeof clear);
|
||||
SDL_SetTextureBlendMode(app->blank, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
return nk_image_ptr(app->blank);
|
||||
}
|
||||
|
||||
#define ION_DIR "external/ionicons/src/svg/"
|
||||
|
||||
struct img_key {
|
||||
const char *src;
|
||||
int ion;
|
||||
struct nk_color stroke;
|
||||
float sw;
|
||||
};
|
||||
|
||||
static const char *
|
||||
icon_source(App *app, const char *rel, char *out, size_t cap)
|
||||
{
|
||||
static const char ion[] = "external/ionicons/src/svg/";
|
||||
const char *base;
|
||||
int i;
|
||||
|
||||
if (SDL_strncmp(rel, ION_DIR, sizeof(ION_DIR) - 1) != 0) return rel;
|
||||
base = rel + sizeof(ION_DIR) - 1;
|
||||
if (SDL_strncmp(rel, ion, sizeof(ion) - 1) != 0) return rel;
|
||||
base = rel + sizeof(ion) - 1;
|
||||
for (i = 0; i < app->icon_dir_count; i++) {
|
||||
SDL_snprintf(out, cap, "%s/%s", app->icon_dirs[i], base);
|
||||
if (reaktor_asset_exists(out)) return out;
|
||||
@@ -123,27 +115,8 @@ raster_surface(const char *path)
|
||||
return surf;
|
||||
}
|
||||
|
||||
static void
|
||||
src_query(char *rel, char *ocol, char *icol, size_t cap, float *sw)
|
||||
{
|
||||
char *opts = strchr(rel, '?');
|
||||
const char *tok;
|
||||
|
||||
if (!opts) return;
|
||||
*opts++ = 0;
|
||||
for (tok = SDL_strtok_r(opts, "&", &opts); tok;
|
||||
tok = SDL_strtok_r(NULL, "&", &opts)) {
|
||||
if (SDL_strncmp(tok, "stroke=", 7) == 0)
|
||||
parse_color(tok + 7, ocol, cap);
|
||||
else if (SDL_strncmp(tok, "fill=", 5) == 0)
|
||||
parse_color(tok + 5, icol, cap);
|
||||
else if (SDL_strncmp(tok, "sw=", 3) == 0)
|
||||
*sw = (float)SDL_atof(tok + 3);
|
||||
}
|
||||
}
|
||||
|
||||
static struct img_slot *
|
||||
img_lookup(App *app, const struct img_key *k, int px)
|
||||
img_lookup(App *app, const char *src, int px)
|
||||
{
|
||||
char rel[192], found[1024], ocol[16] = {0}, icol[16] = {0};
|
||||
float swk = 0.0f;
|
||||
@@ -155,38 +128,38 @@ img_lookup(App *app, const struct img_key *k, int px)
|
||||
unsigned hash;
|
||||
int i, w, h, stride;
|
||||
|
||||
if (!k->src) return NULL;
|
||||
if (px < 8) px = 8;
|
||||
if (px > 512) px = 512;
|
||||
|
||||
hash = reaktor_fnv(REAKTOR_FNV ^ (unsigned)px, k->src);
|
||||
for (i = 0; i < app->img_count; i++) {
|
||||
slot = &app->img[i];
|
||||
if (slot->hash == hash && slot->px == px && slot->ion == k->ion &&
|
||||
!SDL_memcmp(&slot->stroke, &k->stroke, sizeof k->stroke) &&
|
||||
slot->sw == k->sw && strcmp(slot->src, k->src) == 0) {
|
||||
slot->s.seen = app->ctx->seq;
|
||||
return slot->s.tex ? slot : NULL;
|
||||
hash = reaktor_fnv(REAKTOR_FNV ^ (unsigned)px, src);
|
||||
for (i = 0; i < app->img_count; i++)
|
||||
if (app->img[i].hash == hash && app->img[i].px == px &&
|
||||
strcmp(app->img[i].src, src) == 0) {
|
||||
app->img[i].s.seen = app->ctx->seq;
|
||||
return app->img[i].s.tex ? &app->img[i] : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
slot = (struct img_slot *)slot_take(app, app->img, sizeof app->img[0],
|
||||
&app->img_count, app->img_cap);
|
||||
if (!slot) slot = img_grow(app);
|
||||
if (!slot) return NULL;
|
||||
|
||||
if (k->ion) {
|
||||
SDL_snprintf(rel, sizeof(rel), ION_DIR "%s.svg", k->src);
|
||||
reaktor_hex(k->stroke, ocol);
|
||||
if (k->sw >= 0.0f) {
|
||||
char num[32];
|
||||
|
||||
SDL_snprintf(num, sizeof(num), "%.2f", (double)k->sw);
|
||||
swk = (float)SDL_atof(num);
|
||||
SDL_strlcpy(rel, src, sizeof(rel));
|
||||
q = strchr(rel, '?');
|
||||
if (q) {
|
||||
char *opts = (char *)q + 1;
|
||||
char *cut = (char *)q;
|
||||
const char *tok;
|
||||
*cut = 0;
|
||||
for (tok = SDL_strtok_r(opts, "&", &opts); tok;
|
||||
tok = SDL_strtok_r(NULL, "&", &opts)) {
|
||||
if (SDL_strncmp(tok, "stroke=", 7) == 0)
|
||||
parse_color(tok + 7, ocol, sizeof(ocol));
|
||||
else if (SDL_strncmp(tok, "fill=", 5) == 0)
|
||||
parse_color(tok + 5, icol, sizeof(icol));
|
||||
else if (SDL_strncmp(tok, "sw=", 3) == 0)
|
||||
swk = (float)SDL_atof(tok + 3);
|
||||
}
|
||||
} else {
|
||||
SDL_strlcpy(rel, k->src, sizeof(rel));
|
||||
src_query(rel, ocol, icol, sizeof(ocol), &swk);
|
||||
}
|
||||
|
||||
q = SDL_strrchr(rel, '.');
|
||||
@@ -196,10 +169,7 @@ img_lookup(App *app, const struct img_key *k, int px)
|
||||
px, ocol[0] ? ocol : NULL,
|
||||
icol[0] ? icol : NULL, swk);
|
||||
|
||||
SDL_strlcpy(slot->src, k->src, sizeof(slot->src));
|
||||
slot->ion = k->ion;
|
||||
slot->stroke = k->stroke;
|
||||
slot->sw = k->sw;
|
||||
SDL_strlcpy(slot->src, src, sizeof(slot->src));
|
||||
slot->hash = hash;
|
||||
slot->px = px;
|
||||
slot->s.tex = NULL;
|
||||
@@ -249,7 +219,6 @@ img_lookup(App *app, const struct img_key *k, int px)
|
||||
plutovg_surface_destroy(surf);
|
||||
|
||||
if (!tex) return NULL;
|
||||
reaktor_texture_serial(tex);
|
||||
SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetTextureScaleMode(tex, SDL_SCALEMODE_LINEAR);
|
||||
|
||||
@@ -268,38 +237,28 @@ slot_image(App *app, const struct img_slot *slot)
|
||||
}
|
||||
|
||||
static struct img_slot *
|
||||
icon_slot(App *app, const struct img_key *k, int px, float over)
|
||||
icon_slot(App *app, const char *src, int px, float over)
|
||||
{
|
||||
return img_lookup(app, k, (int)(px * reaktor_scale() * over + 0.5f));
|
||||
}
|
||||
|
||||
static struct img_key
|
||||
ion_key(const char *name, struct nk_color stroke, float sw)
|
||||
{
|
||||
struct img_key k;
|
||||
|
||||
k.src = name;
|
||||
k.ion = 1;
|
||||
k.stroke = nk_rgb(stroke.r, stroke.g, stroke.b);
|
||||
k.sw = sw;
|
||||
return k;
|
||||
return img_lookup(app, src, (int)(px * reaktor_scale() * over + 0.5f));
|
||||
}
|
||||
|
||||
struct nk_image
|
||||
ionicon_over(App *app, const char *name, struct nk_color stroke, float sw,
|
||||
int px, float over)
|
||||
icon_over(App *app, const char *src, int px, float over)
|
||||
{
|
||||
struct img_key k = ion_key(name, stroke, sw);
|
||||
|
||||
return slot_image(app, icon_slot(app, &k, px, over));
|
||||
return slot_image(app, icon_slot(app, src, px, over));
|
||||
}
|
||||
|
||||
struct nk_image
|
||||
ionicon_ink(App *app, const char *name, struct nk_color stroke, float sw,
|
||||
int px, float *left, float *right)
|
||||
icon(App *app, const char *src, int px)
|
||||
{
|
||||
struct img_key k = ion_key(name, stroke, sw);
|
||||
struct img_slot *slot = icon_slot(app, &k, px, 2.0f);
|
||||
return icon_over(app, src, px, 2.0f);
|
||||
}
|
||||
|
||||
/* An icon, and where its drawn pixels start and end across its box, 0 to 1. */
|
||||
struct nk_image
|
||||
icon_ink(App *app, const char *src, int px, float *left, float *right)
|
||||
{
|
||||
struct img_slot *slot = icon_slot(app, src, px, 2.0f);
|
||||
|
||||
*left = slot ? slot->ink_l : 0.0f;
|
||||
*right = slot ? slot->ink_r : 1.0f;
|
||||
@@ -309,9 +268,7 @@ ionicon_ink(App *app, const char *name, struct nk_color stroke, float sw,
|
||||
struct nk_image
|
||||
reaktor_image_file(App *app, const char *src, int px)
|
||||
{
|
||||
struct img_key k = { src, 0, { 0, 0, 0, 0 }, 0.0f };
|
||||
|
||||
return slot_image(app, icon_slot(app, &k, px, 2.0f));
|
||||
return icon(app, src, px);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -379,7 +336,6 @@ round_mask(App *app, int r, int t)
|
||||
plutovg_surface_destroy(pv);
|
||||
}
|
||||
if (tex) {
|
||||
reaktor_texture_serial(tex);
|
||||
SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetTextureScaleMode(tex, SDL_SCALEMODE_NEAREST);
|
||||
}
|
||||
@@ -426,8 +382,8 @@ splice_fill(App *app, nk_size at, struct nk_rect clip)
|
||||
return run.last;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_mask_rounded_fills(App *app)
|
||||
static void
|
||||
mask_rounded_fills(App *app)
|
||||
{
|
||||
struct nk_context *ctx = app->ctx;
|
||||
const struct nk_command *c = nk__begin(ctx);
|
||||
@@ -457,51 +413,19 @@ reaktor_mask_rounded_fills(App *app)
|
||||
if (next >= end) break;
|
||||
at = next;
|
||||
}
|
||||
/* What ended the list at the old end must end it at the new one. */
|
||||
if (spliced)
|
||||
((struct nk_command *)((nk_byte *)ctx->memory.memory.ptr + tail))->next =
|
||||
ctx->memory.allocated;
|
||||
}
|
||||
|
||||
/* A software frame that opens by filling the whole window has no use for the
|
||||
clear. A GPU keeps it, as SDL asks; so does a feathered fill, whose edge
|
||||
blends with what is under it. */
|
||||
static int
|
||||
first_fill_covers(App *app)
|
||||
{
|
||||
struct nk_context *ctx = app->ctx;
|
||||
const struct nk_command *c;
|
||||
float sx = 1.0f, sy = 1.0f;
|
||||
int ow = 0, oh = 0, clipped = 0;
|
||||
|
||||
if (!SDL_GetCurrentRenderOutputSize(app->ren, &ow, &oh) ||
|
||||
!SDL_GetRenderScale(app->ren, &sx, &sy))
|
||||
return 0;
|
||||
nk_foreach(c, ctx) {
|
||||
if (c->type == NK_COMMAND_SCISSOR) {
|
||||
const struct nk_command_scissor *s =
|
||||
(const struct nk_command_scissor *)c;
|
||||
|
||||
clipped = s->x > 0 || s->y > 0 || (s->x + s->w) * sx < (float)ow ||
|
||||
(s->y + s->h) * sy < (float)oh;
|
||||
} else if (c->type != NK_COMMAND_NOP) {
|
||||
const struct nk_command_rect_filled *f =
|
||||
(const struct nk_command_rect_filled *)c;
|
||||
|
||||
return !clipped && c->type == NK_COMMAND_RECT_FILLED &&
|
||||
!f->rounding && f->color.a == 255 && f->x <= 0 && f->y <= 0 &&
|
||||
(f->x + f->w) * sx >= (float)ow &&
|
||||
(f->y + f->h) * sy >= (float)oh;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_aa_lines(const App *app)
|
||||
{
|
||||
return app->aa_mode != REAKTOR_AA_OFF;
|
||||
return app->aa_mode != REAKTOR_AA_OFF && !(app->renderer_is_sw && app->sw_noaa);
|
||||
}
|
||||
|
||||
/* Left to a GPU renderer by default; rounded fills are masks either way. */
|
||||
int
|
||||
reaktor_aa_fills(const App *app)
|
||||
{
|
||||
@@ -509,43 +433,16 @@ reaktor_aa_fills(const App *app)
|
||||
(app->aa_mode == REAKTOR_AA_AUTO && !app->renderer_is_sw);
|
||||
}
|
||||
|
||||
static void
|
||||
clear_rects(App *app, const SDL_Rect *rects, int n)
|
||||
void
|
||||
reaktor_render(App *app)
|
||||
{
|
||||
SDL_FRect f[REAKTOR_DAMAGE_RECTS];
|
||||
SDL_BlendMode blend = SDL_BLENDMODE_BLEND;
|
||||
int i;
|
||||
|
||||
n = SDL_min(n, REAKTOR_DAMAGE_RECTS);
|
||||
for (i = 0; i < n; i++) {
|
||||
f[i].x = (float)rects[i].x;
|
||||
f[i].y = (float)rects[i].y;
|
||||
f[i].w = (float)rects[i].w;
|
||||
f[i].h = (float)rects[i].h;
|
||||
}
|
||||
SDL_GetRenderDrawBlendMode(app->ren, &blend);
|
||||
SDL_SetRenderDrawBlendMode(app->ren, SDL_BLENDMODE_NONE);
|
||||
SDL_SetRenderDrawColor(app->ren, app->clear.r, app->clear.g, app->clear.b,
|
||||
app->clear.a);
|
||||
SDL_RenderFillRects(app->ren, f, n);
|
||||
SDL_SetRenderDrawBlendMode(app->ren, blend);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_render(App *app, const SDL_Rect *rects, int n)
|
||||
{
|
||||
if (n > 0) {
|
||||
clear_rects(app, rects, n);
|
||||
} else if (!app->renderer_is_sw || reaktor_aa_fills(app) || !first_fill_covers(app)) {
|
||||
SDL_SetRenderDrawColor(app->ren, app->clear.r, app->clear.g, app->clear.b,
|
||||
app->clear.a);
|
||||
SDL_RenderClear(app->ren);
|
||||
}
|
||||
if (!app->secondary) reaktor_text_prepare(app->ctx, app->ren);
|
||||
nk_sdl_render_area(app->ctx,
|
||||
reaktor_aa_fills(app) ? NK_ANTI_ALIASING_ON : NK_ANTI_ALIASING_OFF,
|
||||
reaktor_aa_lines(app) ? NK_ANTI_ALIASING_ON : NK_ANTI_ALIASING_OFF,
|
||||
rects, n);
|
||||
SDL_RenderClear(app->ren);
|
||||
mask_rounded_fills(app);
|
||||
nk_sdl_render_ex(app->ctx,
|
||||
reaktor_aa_fills(app) ? NK_ANTI_ALIASING_ON : NK_ANTI_ALIASING_OFF,
|
||||
reaktor_aa_lines(app) ? NK_ANTI_ALIASING_ON : NK_ANTI_ALIASING_OFF);
|
||||
}
|
||||
|
||||
nk_size
|
||||
@@ -652,184 +549,36 @@ draw_corners(struct nk_command_buffer *cv, struct nk_image mask, int m,
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct ramp {
|
||||
struct nk_rect b;
|
||||
struct nk_color from, to;
|
||||
int across, flat;
|
||||
} ramp;
|
||||
|
||||
static struct nk_color
|
||||
ramp_at(const ramp *g, float at)
|
||||
{
|
||||
float span = g->across ? g->b.w : g->b.h;
|
||||
float t = (at - (g->across ? g->b.x : g->b.y)) / span;
|
||||
|
||||
if (t < 0.0f) t = 0.0f;
|
||||
if (t > 1.0f) t = 1.0f;
|
||||
return nk_rgba((int)(g->from.r + (g->to.r - g->from.r) * t + 0.5f),
|
||||
(int)(g->from.g + (g->to.g - g->from.g) * t + 0.5f),
|
||||
(int)(g->from.b + (g->to.b - g->from.b) * t + 0.5f),
|
||||
(int)(g->from.a + (g->to.a - g->from.a) * t + 0.5f));
|
||||
}
|
||||
|
||||
static int
|
||||
ramp_levels(const ramp *g)
|
||||
{
|
||||
int d[4] = { g->to.r - g->from.r, g->to.g - g->from.g, g->to.b - g->from.b,
|
||||
g->to.a - g->from.a };
|
||||
int i, most = 0;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
if (SDL_abs(d[i]) > most) most = SDL_abs(d[i]);
|
||||
return most;
|
||||
}
|
||||
|
||||
/* A run in solid bands, one per level the ramp changes by across it: SDL fills
|
||||
a solid rectangle far faster than it shades one from its corners. */
|
||||
static void
|
||||
ramp_rect(struct nk_command_buffer *cv, const ramp *g, struct nk_rect r)
|
||||
{
|
||||
float at = g->across ? r.x : r.y, len = g->across ? r.w : r.h;
|
||||
int n, j;
|
||||
|
||||
if (g->flat) { nk_fill_rect(cv, r, 0.0f, g->from); return; }
|
||||
n = (int)SDL_ceilf((float)ramp_levels(g) * len / (g->across ? g->b.w : g->b.h));
|
||||
if (n > (int)len) n = (int)len;
|
||||
if (n < 1) n = 1;
|
||||
for (j = 0; j < n; j++) {
|
||||
float s0 = at + (float)(int)(len * (float)j / (float)n + 0.5f);
|
||||
float s1 = at + (float)(int)(len * (float)(j + 1) / (float)n + 0.5f);
|
||||
struct nk_color c = ramp_at(g, (s0 + s1) * 0.5f);
|
||||
|
||||
if (s1 <= s0) continue;
|
||||
|
||||
nk_fill_rect(cv, g->across ? nk_rect(s0, r.y, s1 - s0, r.h)
|
||||
: nk_rect(r.x, s0, r.w, s1 - s0), 0.0f, c);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ramp_corners(struct nk_command_buffer *cv, const ramp *g, struct nk_image mask, int m,
|
||||
int r)
|
||||
{
|
||||
float M = (float)m, D = (float)(2 * m + 1), R = (float)r;
|
||||
int i, k;
|
||||
|
||||
if (g->flat) { draw_corners(cv, mask, m, g->b, r, g->from); return; }
|
||||
for (i = 0; i < 4; i++) {
|
||||
float x = (i & 1) ? g->b.x + g->b.w - R : g->b.x;
|
||||
float y = (i & 2) ? g->b.y + g->b.h - R : g->b.y;
|
||||
float u = (i & 1) ? M + 1.0f : 0.0f;
|
||||
float v = (i & 2) ? M + 1.0f : 0.0f;
|
||||
|
||||
for (k = 0; k < m; k++) {
|
||||
float s0 = R * (float)k / M, s1 = R * (float)(k + 1) / M;
|
||||
struct nk_rect at = g->across ? nk_rect(x + s0, y, s1 - s0, R)
|
||||
: nk_rect(x, y + s0, R, s1 - s0);
|
||||
struct nk_rect src = g->across ? nk_rect(u + (float)k, v, 1.0f, M)
|
||||
: nk_rect(u, v + (float)k, M, 1.0f);
|
||||
struct nk_image q = nk_subimage_handle(mask.handle, (nk_ushort)D,
|
||||
(nk_ushort)D, src);
|
||||
|
||||
nk_draw_image(cv, at, &q,
|
||||
ramp_at(g, g->across ? at.x + at.w * 0.5f
|
||||
: at.y + at.h * 0.5f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
fill_shape(App *app, struct nk_command_buffer *cv, float rounding, const ramp *g)
|
||||
{
|
||||
struct nk_rect b = g->b;
|
||||
struct nk_image disc;
|
||||
float R, D;
|
||||
int r, m;
|
||||
|
||||
r = corner_px(b, rounding);
|
||||
if (r < 1) { ramp_rect(cv, g, b); return; }
|
||||
m = mask_px((float)r);
|
||||
disc = round_mask(app, m, 0);
|
||||
if (!disc.handle.ptr) {
|
||||
if (g->flat) nk_fill_rect(cv, b, (float)r, g->from);
|
||||
else ramp_rect(cv, g, b);
|
||||
return;
|
||||
}
|
||||
|
||||
ramp_corners(cv, g, disc, m, r);
|
||||
R = (float)r;
|
||||
D = 2.0f * R;
|
||||
if (!g->flat && g->across) {
|
||||
if (b.w > D)
|
||||
ramp_rect(cv, g, nk_rect(b.x + R, b.y, b.w - D, b.h));
|
||||
if (b.h > D) {
|
||||
ramp_rect(cv, g, nk_rect(b.x, b.y + R, R, b.h - D));
|
||||
ramp_rect(cv, g, nk_rect(b.x + b.w - R, b.y + R, R, b.h - D));
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (b.h > D)
|
||||
ramp_rect(cv, g, nk_rect(b.x, b.y + R, b.w, b.h - D));
|
||||
if (b.w > D) {
|
||||
ramp_rect(cv, g, nk_rect(b.x + R, b.y, b.w - D, R));
|
||||
ramp_rect(cv, g, nk_rect(b.x + R, b.y + b.h - R, b.w - D, R));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_fill_round(App *app, struct nk_command_buffer *cv, struct nk_rect b,
|
||||
float rounding, struct nk_color col)
|
||||
{
|
||||
ramp g;
|
||||
struct nk_image disc;
|
||||
float R, D;
|
||||
int r, m;
|
||||
|
||||
if (b.w <= 0.0f || b.h <= 0.0f || !col.a) return;
|
||||
if (app) {
|
||||
app->surface_at = b;
|
||||
app->surface = col;
|
||||
}
|
||||
g.b = whole_px(b);
|
||||
g.from = g.to = col;
|
||||
g.across = 1;
|
||||
g.flat = 1;
|
||||
if (g.b.w <= 0.0f || g.b.h <= 0.0f) return;
|
||||
fill_shape(app, cv, rounding, &g);
|
||||
}
|
||||
b = whole_px(b);
|
||||
if (b.w <= 0.0f || b.h <= 0.0f) return;
|
||||
r = corner_px(b, rounding);
|
||||
if (r < 1) { nk_fill_rect(cv, b, 0.0f, col); return; }
|
||||
m = mask_px((float)r);
|
||||
disc = round_mask(app, m, 0);
|
||||
if (!disc.handle.ptr) { nk_fill_rect(cv, b, (float)r, col); return; }
|
||||
|
||||
void
|
||||
reaktor_fill_gradient(App *app, struct nk_command_buffer *cv, struct nk_rect b,
|
||||
float rounding, struct nk_color from, struct nk_color to,
|
||||
int axis)
|
||||
{
|
||||
ramp g;
|
||||
|
||||
if (axis == REAKTOR_GRADIENT_NONE || !memcmp(&from, &to, sizeof from)) {
|
||||
reaktor_fill_round(app, cv, b, rounding, from);
|
||||
return;
|
||||
draw_corners(cv, disc, m, b, r, col);
|
||||
R = (float)r;
|
||||
D = 2.0f * R;
|
||||
if (b.h > D)
|
||||
nk_fill_rect(cv, nk_rect(b.x, b.y + R, b.w, b.h - D), 0.0f, col);
|
||||
if (b.w > D) {
|
||||
nk_fill_rect(cv, nk_rect(b.x + R, b.y, b.w - D, R), 0.0f, col);
|
||||
nk_fill_rect(cv, nk_rect(b.x + R, b.y + b.h - R, b.w - D, R), 0.0f, col);
|
||||
}
|
||||
if (b.w <= 0.0f || b.h <= 0.0f || (!from.a && !to.a)) return;
|
||||
g.b = whole_px(b);
|
||||
g.from = from;
|
||||
g.to = to;
|
||||
g.across = axis == REAKTOR_GRADIENT_ACROSS;
|
||||
g.flat = 0;
|
||||
if (g.b.w <= 0.0f || g.b.h <= 0.0f) return;
|
||||
if (app) {
|
||||
app->surface_at = b;
|
||||
app->surface = ramp_at(&g, g.across ? g.b.x + g.b.w * 0.5f
|
||||
: g.b.y + g.b.h * 0.5f);
|
||||
}
|
||||
fill_shape(app, cv, rounding, &g);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_fill_style(App *app, struct nk_command_buffer *cv, struct nk_rect b,
|
||||
float rounding, const reaktor_style *s)
|
||||
{
|
||||
if (s->gradient)
|
||||
reaktor_fill_gradient(app, cv, b, rounding, nk_rgba_bv(s->gradient_from),
|
||||
nk_rgba_bv(s->gradient_to), s->gradient);
|
||||
else
|
||||
reaktor_fill_round(app, cv, b, rounding, nk_rgba_bv(s->bg));
|
||||
}
|
||||
|
||||
|
||||
@@ -863,14 +612,13 @@ nbsp_as_space(struct reaktor_font *f)
|
||||
}
|
||||
|
||||
static void
|
||||
finish_face(struct reaktor_font *f, float height, const char *path, int fresh)
|
||||
finish_face(struct reaktor_font *f, float height, const char *path)
|
||||
{
|
||||
if (!f) return;
|
||||
f->handle.height = height;
|
||||
if (fresh) {
|
||||
center_glyphs_optically(f);
|
||||
nbsp_as_space(f);
|
||||
}
|
||||
center_glyphs_optically(f);
|
||||
nbsp_as_space(f);
|
||||
/* After centering: the Text module reads the baseline. */
|
||||
reaktor_text_attach_font(f, path);
|
||||
}
|
||||
|
||||
@@ -929,34 +677,17 @@ load_face(const char **name, const char *stand_in, size_t *size)
|
||||
return take_face(*name, size);
|
||||
}
|
||||
|
||||
static struct {
|
||||
struct reaktor_fontset set;
|
||||
const char *face, *bold;
|
||||
} g_kept;
|
||||
|
||||
void
|
||||
atlas_forget(void)
|
||||
{
|
||||
reaktor_fontset_free(&g_kept.set);
|
||||
SDL_zero(g_kept);
|
||||
}
|
||||
|
||||
static int
|
||||
keeps(const App *app)
|
||||
{
|
||||
return g_kept.set.pixels && app->font_face == g_kept.face && app->font_face_bold == g_kept.bold;
|
||||
}
|
||||
|
||||
static int
|
||||
bake(App *app, struct reaktor_fontset *set, int *bold)
|
||||
rebuild_font(App *app)
|
||||
{
|
||||
static const nk_rune latin[] = { 0x0020, 0x00FF, 0 };
|
||||
struct reaktor_face_src src[2 * FONT_STEPS];
|
||||
struct reaktor_fontset set;
|
||||
struct reaktor_font *font = NULL;
|
||||
size_t size = 0, bsize = 0;
|
||||
char *ttf, *bttf = NULL;
|
||||
unsigned *ranges;
|
||||
Uint64 t0;
|
||||
int n = 0, ok, i;
|
||||
int n = 0, bold, ok, i;
|
||||
|
||||
ttf = load_face(&app->font_face, FONT_FILE, &size);
|
||||
if (ttf) bttf = load_face(&app->font_face_bold, FONT_BOLD_FILE, &bsize);
|
||||
@@ -970,12 +701,9 @@ bake(App *app, struct reaktor_fontset *set, int *bold)
|
||||
src[n].size = bsize;
|
||||
src[n++].px = (float)reaktor_px(g_font_px[i]);
|
||||
}
|
||||
*bold = bttf != NULL;
|
||||
bold = bttf != NULL;
|
||||
ranges = reaktor_locale_glyphs();
|
||||
t0 = SDL_GetPerformanceCounter();
|
||||
ok = n > 0 && reaktor_fontset_bake(set, src, n, ranges ? ranges : latin);
|
||||
app->atlas_ms_x100 = (int)(100000.0 * (double)(SDL_GetPerformanceCounter() - t0) /
|
||||
(double)SDL_GetPerformanceFrequency());
|
||||
ok = n > 0 && reaktor_fontset_bake(&set, src, n, ranges ? ranges : latin);
|
||||
SDL_free(ranges);
|
||||
reaktor_free(ttf);
|
||||
reaktor_free(bttf);
|
||||
@@ -984,33 +712,14 @@ bake(App *app, struct reaktor_fontset *set, int *bold)
|
||||
if (!app->fonts.count)
|
||||
SDL_snprintf(app->font_status, sizeof(app->font_status),
|
||||
"FALLBACK - could not load %s", app->font_face);
|
||||
return;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
void
|
||||
rebuild_font(App *app)
|
||||
{
|
||||
struct reaktor_fontset set;
|
||||
struct reaktor_font *font = NULL;
|
||||
unsigned char *pixels;
|
||||
nk_handle atlas;
|
||||
int bold, shared, i;
|
||||
|
||||
shared = app->secondary && keeps(app) && reaktor_fontset_copy(&set, &g_kept.set);
|
||||
if (shared) bold = set.count > FONT_STEPS;
|
||||
else if (!bake(app, &set, &bold)) return;
|
||||
|
||||
if (!app->secondary) {
|
||||
reaktor_text_attach_font(NULL, NULL);
|
||||
atlas_forget();
|
||||
}
|
||||
if (!app->secondary) reaktor_text_attach_font(NULL, NULL);
|
||||
reaktor_fontset_free(&app->fonts);
|
||||
app->fonts = set;
|
||||
pixels = shared ? g_kept.set.pixels : set.pixels;
|
||||
atlas = nk_sdl_font_upload(app->ctx, pixels, set.w, set.h);
|
||||
reaktor_texture_serial((SDL_Texture *)atlas.ptr);
|
||||
reaktor_fontset_bind(&app->fonts, atlas);
|
||||
reaktor_fontset_bind(&app->fonts, nk_sdl_font_upload(app->ctx, set.pixels, set.w, set.h));
|
||||
SDL_free(app->fonts.pixels);
|
||||
app->fonts.pixels = NULL;
|
||||
for (i = 0; i < FONT_STEPS; i++) {
|
||||
app->faces[i] = &app->fonts.fonts[i];
|
||||
@@ -1025,17 +734,9 @@ rebuild_font(App *app)
|
||||
|
||||
for (i = 0; i < FONT_STEPS; i++) {
|
||||
finish_face(app->faces[i], (float)g_font_px[i],
|
||||
app->secondary ? NULL : app->font_face, !shared);
|
||||
app->secondary ? NULL : app->font_face);
|
||||
finish_face(app->bolds[i], (float)g_font_px[i],
|
||||
app->secondary ? NULL : app->font_face_bold, !shared);
|
||||
}
|
||||
if (app->secondary && !shared && !g_kept.set.pixels &&
|
||||
reaktor_fontset_copy(&g_kept.set, &app->fonts)) {
|
||||
g_kept.set.pixels = pixels;
|
||||
g_kept.face = app->font_face;
|
||||
g_kept.bold = app->font_face_bold;
|
||||
} else if (!shared) {
|
||||
SDL_free(pixels);
|
||||
app->secondary ? NULL : app->font_face_bold);
|
||||
}
|
||||
|
||||
app->atlas_w = app->atlas_h = app->atlas_bpp = 0;
|
||||
@@ -1055,9 +756,7 @@ void
|
||||
apply_render_scale(App *app)
|
||||
{
|
||||
float s = reaktor_scale();
|
||||
|
||||
app->render_scale = s;
|
||||
if (!reaktor_damage_views(app)) SDL_SetRenderScale(app->ren, s, s);
|
||||
SDL_SetRenderScale(app->ren, s, s);
|
||||
}
|
||||
|
||||
SDL_Surface *
|
||||
|
||||
+20
-51
@@ -6,7 +6,6 @@
|
||||
#include FT_MODULE_H
|
||||
|
||||
#include "font.h"
|
||||
#include "util.h"
|
||||
|
||||
typedef struct baked {
|
||||
int w, h, left, top, at;
|
||||
@@ -107,20 +106,11 @@ reaktor_ft_size(FT_Face face, float px)
|
||||
72, 72);
|
||||
}
|
||||
|
||||
static float g_ink_em;
|
||||
|
||||
float
|
||||
reaktor_font_ink_em(void)
|
||||
{
|
||||
return g_ink_em;
|
||||
}
|
||||
|
||||
const struct reaktor_glyph *
|
||||
reaktor_font_glyph(const struct reaktor_font *f, nk_rune cp)
|
||||
{
|
||||
int lo = 0, hi = f->glyph_count - 1;
|
||||
|
||||
if (cp < 128) return f->ascii[cp] ? &f->glyphs[f->ascii[cp] - 1] : NULL;
|
||||
while (lo <= hi) {
|
||||
int mid = (lo + hi) / 2;
|
||||
|
||||
@@ -247,12 +237,25 @@ pack(baked *b, int n, int *w, int *h)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
grow(void **p, int *cap, int need, size_t size)
|
||||
{
|
||||
int n = *cap > 0 ? *cap : 256;
|
||||
void *q;
|
||||
|
||||
if (need <= *cap) return 1;
|
||||
while (n < need) n *= 2;
|
||||
if (!(q = SDL_realloc(*p, (size_t)n * size))) return 0;
|
||||
*p = q;
|
||||
*cap = n;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_fontset_bake(struct reaktor_fontset *set, const struct reaktor_face_src *src,
|
||||
int n, const nk_rune *ranges)
|
||||
{
|
||||
nk_rune *cp;
|
||||
FT_Face face = NULL;
|
||||
baked *b = NULL;
|
||||
unsigned char *bits = NULL;
|
||||
int ncp = 0, nb = 0, cap_b = 0, cap_bits = 0, used = 0, i, k, ok = 0;
|
||||
@@ -265,12 +268,9 @@ reaktor_fontset_bake(struct reaktor_fontset *set, const struct reaktor_face_src
|
||||
set->count = n;
|
||||
for (i = 0; i < n; i++) {
|
||||
struct reaktor_font *f = &set->fonts[i];
|
||||
FT_Face face = reaktor_ft_open(src[i].ttf, src[i].size);
|
||||
float scale;
|
||||
|
||||
if (!i || src[i].ttf != src[i - 1].ttf) {
|
||||
if (face) FT_Done_Face(face);
|
||||
face = reaktor_ft_open(src[i].ttf, src[i].size);
|
||||
}
|
||||
f->glyphs = set->glyphs + nb;
|
||||
f->height = src[i].px;
|
||||
if (!face) continue;
|
||||
@@ -290,9 +290,11 @@ reaktor_fontset_bake(struct reaktor_fontset *set, const struct reaktor_face_src
|
||||
FT_Get_Advance(face, id, FT_LOAD_NO_SCALE, &adv))
|
||||
continue;
|
||||
bm = &face->glyph->bitmap;
|
||||
if (!reaktor_grow((void **)&b, &cap_b, nb + 1, sizeof *b) ||
|
||||
!reaktor_grow((void **)&bits, &cap_bits, used + (int)(bm->width * bm->rows), 1))
|
||||
if (!grow((void **)&b, &cap_b, nb + 1, sizeof *b) ||
|
||||
!grow((void **)&bits, &cap_bits, used + (int)(bm->width * bm->rows), 1)) {
|
||||
FT_Done_Face(face);
|
||||
goto done;
|
||||
}
|
||||
d = &b[nb];
|
||||
d->w = (int)bm->width;
|
||||
d->h = (int)bm->rows;
|
||||
@@ -311,14 +313,9 @@ reaktor_fontset_bake(struct reaktor_fontset *set, const struct reaktor_face_src
|
||||
g->x1 = (float)(d->left + d->w);
|
||||
g->y0 = (float)-d->top + f->ascent + 0.5f;
|
||||
g->y1 = g->y0 + (float)d->h;
|
||||
{
|
||||
float ink = SDL_max(SDL_max(-g->x0, g->x1), SDL_max(-g->y0, g->y1));
|
||||
|
||||
if (ink / src[i].px > g_ink_em) g_ink_em = ink / src[i].px;
|
||||
}
|
||||
if (cp[k] < 128) f->ascii[cp[k]] = (unsigned char)(f->glyph_count + 1);
|
||||
f->glyph_count++;
|
||||
}
|
||||
FT_Done_Face(face);
|
||||
f->fallback = reaktor_font_glyph(f, '?');
|
||||
if (!f->fallback && f->glyph_count) f->fallback = &f->glyphs[0];
|
||||
}
|
||||
@@ -340,7 +337,6 @@ reaktor_fontset_bake(struct reaktor_fontset *set, const struct reaktor_face_src
|
||||
}
|
||||
ok = 1;
|
||||
done:
|
||||
if (face) FT_Done_Face(face);
|
||||
SDL_free(cp);
|
||||
SDL_free(b);
|
||||
SDL_free(bits);
|
||||
@@ -348,33 +344,6 @@ done:
|
||||
return ok;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_fontset_copy(struct reaktor_fontset *to, const struct reaktor_fontset *from)
|
||||
{
|
||||
int glyphs = 0, i;
|
||||
|
||||
SDL_zerop(to);
|
||||
for (i = 0; i < from->count; i++) glyphs += from->fonts[i].glyph_count;
|
||||
if (!(to->fonts = SDL_malloc((size_t)(from->count ? from->count : 1) * sizeof *to->fonts)) ||
|
||||
!(to->glyphs = SDL_malloc((size_t)(glyphs ? glyphs : 1) * sizeof *to->glyphs))) {
|
||||
reaktor_fontset_free(to);
|
||||
return 0;
|
||||
}
|
||||
SDL_memcpy(to->fonts, from->fonts, (size_t)from->count * sizeof *to->fonts);
|
||||
SDL_memcpy(to->glyphs, from->glyphs, (size_t)glyphs * sizeof *to->glyphs);
|
||||
for (i = 0; i < from->count; i++) {
|
||||
struct reaktor_font *f = &to->fonts[i];
|
||||
const struct reaktor_font *s = &from->fonts[i];
|
||||
|
||||
f->glyphs = to->glyphs + (s->glyphs - from->glyphs);
|
||||
if (s->fallback) f->fallback = to->glyphs + (s->fallback - from->glyphs);
|
||||
}
|
||||
to->count = from->count;
|
||||
to->w = from->w;
|
||||
to->h = from->h;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_fontset_bind(struct reaktor_fontset *set, nk_handle texture)
|
||||
{
|
||||
|
||||
@@ -21,7 +21,6 @@ struct reaktor_font {
|
||||
struct reaktor_glyph *glyphs;
|
||||
int glyph_count;
|
||||
const struct reaktor_glyph *fallback;
|
||||
unsigned char ascii[128];
|
||||
};
|
||||
|
||||
struct reaktor_face_src {
|
||||
@@ -45,11 +44,9 @@ void reaktor_ft_size(FT_Face face, float px);
|
||||
|
||||
int reaktor_fontset_bake(struct reaktor_fontset *set, const struct reaktor_face_src *src,
|
||||
int n, const nk_rune *ranges);
|
||||
int reaktor_fontset_copy(struct reaktor_fontset *to, const struct reaktor_fontset *from);
|
||||
void reaktor_fontset_bind(struct reaktor_fontset *set, nk_handle texture);
|
||||
void reaktor_fontset_free(struct reaktor_fontset *set);
|
||||
|
||||
const struct reaktor_glyph *reaktor_font_glyph(const struct reaktor_font *f, nk_rune cp);
|
||||
float reaktor_font_ink_em(void);
|
||||
|
||||
#endif
|
||||
|
||||
+107
-358
@@ -34,13 +34,15 @@ extern "C"{
|
||||
#endif
|
||||
|
||||
NK_API struct nk_context* nk_sdl_init(SDL_Window *win, SDL_Renderer *renderer, struct nk_allocator allocator);
|
||||
#ifdef NK_INCLUDE_FONT_BAKING
|
||||
NK_API struct nk_font_atlas* nk_sdl_font_stash_begin(struct nk_context* ctx);
|
||||
NK_API void nk_sdl_font_stash_end(struct nk_context* ctx);
|
||||
#endif
|
||||
/* REAKTOR: an atlas Reaktor bakes itself, alpha8. */
|
||||
NK_API nk_handle nk_sdl_font_upload(struct nk_context* ctx, const void *image, int width, int height);
|
||||
NK_API int nk_sdl_handle_event(struct nk_context* ctx, SDL_Event *evt);
|
||||
/* REAKTOR: fill and stroke feathering apart, drawn only inside rects; none
|
||||
is the whole window. The list stays until nk_sdl_frame_done. */
|
||||
NK_API void nk_sdl_render_area(struct nk_context* ctx, enum nk_anti_aliasing shape_AA, enum nk_anti_aliasing line_AA, const SDL_Rect *rects, int n);
|
||||
NK_API void nk_sdl_frame_done(struct nk_context* ctx);
|
||||
/* REAKTOR: fill and stroke feathering apart. */
|
||||
NK_API void nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA, enum nk_anti_aliasing line_AA);
|
||||
NK_API void nk_sdl_update_TextInput(struct nk_context* ctx);
|
||||
NK_API void nk_sdl_shutdown(struct nk_context* ctx);
|
||||
NK_API struct nk_allocator nk_sdl_allocator(void);
|
||||
@@ -88,14 +90,14 @@ struct nk_sdl {
|
||||
SDL_Renderer *renderer;
|
||||
struct nk_sdl_device ogl;
|
||||
struct nk_context ctx;
|
||||
#ifdef NK_INCLUDE_FONT_BAKING
|
||||
struct nk_font_atlas atlas;
|
||||
#endif
|
||||
struct nk_allocator allocator;
|
||||
Uint64 last_render;
|
||||
bool insert_toggle;
|
||||
bool edit_was_active;
|
||||
bool is_sw;
|
||||
/* REAKTOR: each opaque rectangle of the frame, as it will cover. */
|
||||
struct nk_sdl_cover *covers;
|
||||
int covers_cap;
|
||||
};
|
||||
|
||||
NK_INTERN void *
|
||||
@@ -283,45 +285,17 @@ nk_sdl_geometry_sw(SDL_Renderer *ren, SDL_Texture *tex, const void *vertices,
|
||||
if (opaque) SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
|
||||
/* REAKTOR: device pixels [x0, x1) x [y0, y1). */
|
||||
struct nk_sdl_cover {
|
||||
int x0, y0, x1, y1;
|
||||
};
|
||||
|
||||
/* REAKTOR: a rectangle among the triangles, on whole device pixels. */
|
||||
struct nk_sdl_rect {
|
||||
SDL_FRect d, src;
|
||||
struct nk_sdl_cover px;
|
||||
const float *col;
|
||||
int opaque;
|
||||
};
|
||||
|
||||
/* REAKTOR: device pixels as SDL fills them: it truncates a scaled
|
||||
rectangle's position and size apart, toward zero, so a start left of zero
|
||||
is nudged left. */
|
||||
NK_INTERN SDL_FRect
|
||||
nk_sdl_device_rect(const struct nk_sdl_cover *c, float sx, float sy)
|
||||
{
|
||||
SDL_FRect d;
|
||||
float x0 = (float)c->x0, y0 = (float)c->y0;
|
||||
|
||||
d.w = ((float)c->x1 - x0 + 0.25f) / sx;
|
||||
d.h = ((float)c->y1 - y0 + 0.25f) / sy;
|
||||
d.x = (x0 + (x0 < 0.0f ? -0.25f : 0.25f)) / sx;
|
||||
d.y = (y0 + (y0 < 0.0f ? -0.25f : 0.25f)) / sy;
|
||||
return d;
|
||||
}
|
||||
|
||||
/* REAKTOR: what a run of rectangles left set, put back before triangles. */
|
||||
struct nk_sdl_sw {
|
||||
float tint[4];
|
||||
int tinted, unblended;
|
||||
SDL_FRect d, src;
|
||||
const float *col;
|
||||
int opaque;
|
||||
};
|
||||
|
||||
/* REAKTOR: whether the six indices at ix are one rectangle. */
|
||||
NK_INTERN int
|
||||
nk_sdl_quad(const void *vertices, const nk_draw_index *ix, SDL_Texture *tex,
|
||||
float tw, float th, float sx, float sy, struct nk_sdl_rect *q)
|
||||
float sx, float sy, struct nk_sdl_rect *q)
|
||||
{
|
||||
const struct nk_sdl_vertex *v[6];
|
||||
float x0, x1, y0, y1, u[2] = {0, 0}, w[2] = {0, 0};
|
||||
@@ -363,14 +337,18 @@ nk_sdl_quad(const void *vertices, const nk_draw_index *ix, SDL_Texture *tex,
|
||||
return 0;
|
||||
if (tex && !(u[1] > u[0] && w[1] > w[0])) return 0;
|
||||
|
||||
q->px.x0 = (int)SDL_floorf(x0 * sx);
|
||||
q->px.y0 = (int)SDL_floorf(y0 * sy);
|
||||
q->px.x1 = (int)SDL_floorf(x1 * sx);
|
||||
q->px.y1 = (int)SDL_floorf(y1 * sy);
|
||||
d = nk_sdl_device_rect(&q->px, sx, sy);
|
||||
/* SDL truncates toward zero, so a start left of zero is nudged left. */
|
||||
d.x = SDL_floorf(x0 * sx);
|
||||
d.y = SDL_floorf(y0 * sy);
|
||||
d.w = (SDL_floorf(x1 * sx) - d.x + 0.25f) / sx;
|
||||
d.h = (SDL_floorf(y1 * sy) - d.y + 0.25f) / sy;
|
||||
d.x = (d.x + (d.x < 0.0f ? -0.25f : 0.25f)) / sx;
|
||||
d.y = (d.y + (d.y < 0.0f ? -0.25f : 0.25f)) / sy;
|
||||
|
||||
if (tex) {
|
||||
if (!(tw > 0.0f && th > 0.0f)) return 0;
|
||||
float tw, th;
|
||||
|
||||
if (!SDL_GetTextureSize(tex, &tw, &th)) return 0;
|
||||
/* REAKTOR: a sub-image ends on whole texels, but u * size comes back a
|
||||
* hair under one, and SDL's software copy truncates it a texel short. */
|
||||
q->src.x = SDL_roundf(u[0] * tw);
|
||||
@@ -385,236 +363,33 @@ nk_sdl_quad(const void *vertices, const nk_draw_index *ix, SDL_Texture *tex,
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* REAKTOR: cutting pays only for large rectangles, in device pixels; smaller
|
||||
ones neither cut nor are cut. */
|
||||
#define NK_SDL_CUT_MIN 4096
|
||||
#define NK_SDL_PARTS 16
|
||||
|
||||
/* REAKTOR: what of part[0] the n covers at c leave, in place, as at most
|
||||
NK_SDL_PARTS rectangles; returns how many. */
|
||||
NK_INTERN int
|
||||
nk_sdl_uncovered(struct nk_sdl_cover *part, const struct nk_sdl_cover *c, int n)
|
||||
{
|
||||
struct nk_sdl_cover cut[NK_SDL_PARTS];
|
||||
int np = 1, i, j;
|
||||
|
||||
for (i = 0; i < n && np > 0; i++) {
|
||||
const struct nk_sdl_cover *o = &c[i];
|
||||
int nc = 0;
|
||||
|
||||
if (o->x0 >= o->x1 || o->y0 >= o->y1) continue;
|
||||
for (j = 0; j < np; j++) {
|
||||
struct nk_sdl_cover p = part[j];
|
||||
int y0, y1;
|
||||
|
||||
if (o->x0 >= p.x1 || o->x1 <= p.x0 || o->y0 >= p.y1 || o->y1 <= p.y0) {
|
||||
if (nc == NK_SDL_PARTS) return np;
|
||||
cut[nc++] = p;
|
||||
continue;
|
||||
}
|
||||
if (nc + 4 > NK_SDL_PARTS) return np;
|
||||
y0 = SDL_max(p.y0, o->y0);
|
||||
y1 = SDL_min(p.y1, o->y1);
|
||||
if (o->y0 > p.y0) { cut[nc] = p; cut[nc++].y1 = o->y0; }
|
||||
if (o->y1 < p.y1) { cut[nc] = p; cut[nc++].y0 = o->y1; }
|
||||
if (o->x0 > p.x0) {
|
||||
cut[nc].x0 = p.x0; cut[nc].x1 = o->x0;
|
||||
cut[nc].y0 = y0; cut[nc++].y1 = y1;
|
||||
}
|
||||
if (o->x1 < p.x1) {
|
||||
cut[nc].x0 = o->x1; cut[nc].x1 = p.x1;
|
||||
cut[nc].y0 = y0; cut[nc++].y1 = y1;
|
||||
}
|
||||
}
|
||||
SDL_memcpy(part, cut, (size_t)nc * sizeof(*cut));
|
||||
np = nc;
|
||||
}
|
||||
return np;
|
||||
}
|
||||
|
||||
/* REAKTOR: SDL truncates a scaled rectangle's position and size apart. An
|
||||
opaque fill draws only what the n later covers leave: they replace every
|
||||
pixel they paint, whatever was under it. */
|
||||
/* REAKTOR: SDL truncates a scaled rectangle's position and size apart. */
|
||||
NK_INTERN void
|
||||
nk_sdl_quad_draw(SDL_Renderer *ren, SDL_Texture *tex, const struct nk_sdl_rect *q,
|
||||
const struct nk_sdl_cover *later, int n, float sx, float sy,
|
||||
struct nk_sdl_sw *st)
|
||||
nk_sdl_quad_draw(SDL_Renderer *ren, SDL_Texture *tex, const struct nk_sdl_rect *q)
|
||||
{
|
||||
if (tex) {
|
||||
if (!st->tinted || SDL_memcmp(st->tint, q->col, sizeof st->tint) != 0) {
|
||||
SDL_SetTextureColorModFloat(tex, q->col[0], q->col[1], q->col[2]);
|
||||
SDL_SetTextureAlphaModFloat(tex, q->col[3]);
|
||||
SDL_memcpy(st->tint, q->col, sizeof st->tint);
|
||||
st->tinted = 1;
|
||||
}
|
||||
SDL_SetTextureColorModFloat(tex, q->col[0], q->col[1], q->col[2]);
|
||||
SDL_SetTextureAlphaModFloat(tex, q->col[3]);
|
||||
SDL_RenderTexture(ren, tex, &q->src, &q->d);
|
||||
return;
|
||||
}
|
||||
if (q->opaque != st->unblended) {
|
||||
SDL_SetRenderDrawBlendMode(ren, q->opaque ? SDL_BLENDMODE_NONE : SDL_BLENDMODE_BLEND);
|
||||
st->unblended = q->opaque;
|
||||
}
|
||||
SDL_SetRenderDrawColorFloat(ren, q->col[0], q->col[1], q->col[2], q->col[3]);
|
||||
if (q->opaque && n > 0) {
|
||||
struct nk_sdl_cover part[NK_SDL_PARTS];
|
||||
SDL_FRect d[NK_SDL_PARTS];
|
||||
int i, np;
|
||||
|
||||
part[0] = q->px;
|
||||
np = nk_sdl_uncovered(part, later, n);
|
||||
for (i = 0; i < np; i++) d[i] = nk_sdl_device_rect(&part[i], sx, sy);
|
||||
if (np > 0) SDL_RenderFillRects(ren, d, np);
|
||||
return;
|
||||
}
|
||||
SDL_RenderFillRect(ren, &q->d);
|
||||
}
|
||||
|
||||
/* REAKTOR: whether the list holds two large opaque fills, one to cut. */
|
||||
NK_INTERN int
|
||||
nk_sdl_may_cut(struct nk_context *ctx, float sx, float sy)
|
||||
{
|
||||
const struct nk_command *c;
|
||||
int large = 0;
|
||||
|
||||
nk_foreach(c, ctx) {
|
||||
const struct nk_command_rect_filled *f = (const struct nk_command_rect_filled *)c;
|
||||
|
||||
if (c->type == NK_COMMAND_RECT_FILLED && f->color.a == 255 && !f->rounding &&
|
||||
(float)f->w * sx * (float)f->h * sy >= (float)NK_SDL_CUT_MIN &&
|
||||
++large == 2)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* REAKTOR: the device pixels each opaque rectangle surely paints, in list
|
||||
order, for nk_sdl_quad_draw. Clips round inward; SDL rounds them out. */
|
||||
NK_INTERN int
|
||||
nk_sdl_covers(struct nk_sdl *sdl, float sx, float sy)
|
||||
{
|
||||
const struct nk_draw_command *cmd;
|
||||
const nk_draw_index *offset =
|
||||
(const nk_draw_index *)nk_buffer_memory_const(&sdl->ogl.ebuf);
|
||||
const void *vertices = nk_buffer_memory_const(&sdl->ogl.vbuf);
|
||||
int n = 0;
|
||||
|
||||
nk_draw_foreach(cmd, &sdl->ctx, &sdl->ogl.cmds)
|
||||
{
|
||||
SDL_Texture *tex = (SDL_Texture *)cmd->texture.ptr;
|
||||
struct nk_sdl_cover clip;
|
||||
nk_uint k = 0;
|
||||
int cx, cy;
|
||||
|
||||
if (!cmd->elem_count) continue;
|
||||
if (tex != NULL && tex != sdl->ogl.white_tex) {
|
||||
offset += cmd->elem_count;
|
||||
continue;
|
||||
}
|
||||
cx = (int)cmd->clip_rect.x;
|
||||
cy = (int)cmd->clip_rect.y;
|
||||
clip.x0 = (int)SDL_ceilf((float)cx * sx);
|
||||
clip.y0 = (int)SDL_ceilf((float)cy * sy);
|
||||
clip.x1 = (int)SDL_floorf((float)(cx + (int)cmd->clip_rect.w) * sx);
|
||||
clip.y1 = (int)SDL_floorf((float)(cy + (int)cmd->clip_rect.h) * sy);
|
||||
while (k + 6 <= cmd->elem_count) {
|
||||
struct nk_sdl_rect q;
|
||||
struct nk_sdl_cover *c;
|
||||
|
||||
if (!nk_sdl_quad(vertices, offset + k, NULL, 0.0f, 0.0f, sx, sy, &q)) {
|
||||
k += 3;
|
||||
continue;
|
||||
}
|
||||
k += 6;
|
||||
if (!q.opaque) continue;
|
||||
if (n == sdl->covers_cap) {
|
||||
int cap = n ? n * 2 : 64;
|
||||
void *p = SDL_realloc(sdl->covers, (size_t)cap * sizeof(*sdl->covers));
|
||||
|
||||
if (!p) return n;
|
||||
sdl->covers = (struct nk_sdl_cover *)p;
|
||||
sdl->covers_cap = cap;
|
||||
}
|
||||
c = &sdl->covers[n++];
|
||||
SDL_zerop(c);
|
||||
if ((long long)(q.px.x1 - q.px.x0) * (q.px.y1 - q.px.y0) < NK_SDL_CUT_MIN) continue;
|
||||
c->x0 = SDL_max(q.px.x0, clip.x0);
|
||||
c->y0 = SDL_max(q.px.y0, clip.y0);
|
||||
c->x1 = SDL_min(q.px.x1, clip.x1);
|
||||
c->y1 = SDL_min(q.px.y1, clip.y1);
|
||||
}
|
||||
offset += cmd->elem_count;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
NK_INTERN void
|
||||
nk_sdl_sw_restore(SDL_Renderer *ren, SDL_Texture *tex, struct nk_sdl_sw *st)
|
||||
{
|
||||
if (st->tinted) {
|
||||
SDL_SetTextureColorModFloat(tex, 1.0f, 1.0f, 1.0f);
|
||||
SDL_SetTextureAlphaModFloat(tex, 1.0f);
|
||||
return;
|
||||
}
|
||||
if (st->unblended) SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_BLEND);
|
||||
st->tinted = st->unblended = 0;
|
||||
if (q->opaque) SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_NONE);
|
||||
SDL_SetRenderDrawColorFloat(ren, q->col[0], q->col[1], q->col[2], q->col[3]);
|
||||
SDL_RenderFillRect(ren, &q->d);
|
||||
if (q->opaque) SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
|
||||
/* REAKTOR: whether device box [x0, x1) x [y0, y1), grown by a pixel, meets a. */
|
||||
NK_INTERN int
|
||||
nk_sdl_meets(float x0, float y0, float x1, float y1, const SDL_Rect *a,
|
||||
float sx, float sy)
|
||||
{
|
||||
return x1 + 1.0f > (float)a->x * sx && x0 - 1.0f < (float)(a->x + a->w) * sx &&
|
||||
y1 + 1.0f > (float)a->y * sy && y0 - 1.0f < (float)(a->y + a->h) * sy;
|
||||
}
|
||||
|
||||
/* REAKTOR: the device box of a run of triangles. */
|
||||
NK_INTERN void
|
||||
nk_sdl_run_box(const void *vertices, const nk_draw_index *ix, nk_uint count,
|
||||
float sx, float sy, float b[4])
|
||||
{
|
||||
const struct nk_sdl_vertex *v = (const struct nk_sdl_vertex *)vertices;
|
||||
float x0, y0, x1, y1;
|
||||
nk_uint k;
|
||||
|
||||
x0 = x1 = v[ix[0]].position[0];
|
||||
y0 = y1 = v[ix[0]].position[1];
|
||||
for (k = 1; k < count; k++) {
|
||||
const float *p = v[ix[k]].position;
|
||||
|
||||
if (p[0] < x0) x0 = p[0];
|
||||
if (p[0] > x1) x1 = p[0];
|
||||
if (p[1] < y0) y0 = p[1];
|
||||
if (p[1] > y1) y1 = p[1];
|
||||
}
|
||||
b[0] = x0 * sx;
|
||||
b[1] = y0 * sy;
|
||||
b[2] = x1 * sx;
|
||||
b[3] = y1 * sy;
|
||||
}
|
||||
|
||||
/* REAKTOR: clips to rectangle i of n, cut by the command's, if box b (none
|
||||
when NULL) meets it; with no rectangles, to the command's alone. */
|
||||
NK_INTERN int
|
||||
nk_sdl_pass(SDL_Renderer *ren, const SDL_Rect *clip, const SDL_Rect *rects, int n,
|
||||
int i, const float *b, float sx, float sy, SDL_Rect *last)
|
||||
{
|
||||
SDL_Rect r = *clip;
|
||||
|
||||
if (n > 0 && ((b && !nk_sdl_meets(b[0], b[1], b[2], b[3], &rects[i], sx, sy)) ||
|
||||
!SDL_GetRectIntersection(clip, &rects[i], &r)))
|
||||
return 0;
|
||||
if (SDL_memcmp(&r, last, sizeof r) != 0) {
|
||||
SDL_SetRenderClipRect(ren, &r);
|
||||
*last = r;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* REAKTOR: the end of nk_sdl_render, apart. */
|
||||
/* REAKTOR: fill and stroke feathering apart. */
|
||||
NK_API void
|
||||
nk_sdl_frame_done(struct nk_context* ctx)
|
||||
nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
|
||||
enum nk_anti_aliasing line_AA)
|
||||
{
|
||||
/* setup global state */
|
||||
struct nk_sdl* sdl;
|
||||
int is_sw;
|
||||
float sx = 1.0f, sy = 1.0f;
|
||||
NK_ASSERT(ctx);
|
||||
sdl = (struct nk_sdl*)ctx->userdata.ptr;
|
||||
NK_ASSERT(sdl);
|
||||
@@ -625,26 +400,8 @@ nk_sdl_frame_done(struct nk_context* ctx)
|
||||
sdl->last_render = now;
|
||||
}
|
||||
|
||||
nk_clear(&sdl->ctx);
|
||||
}
|
||||
|
||||
/* REAKTOR: the drawing of nk_sdl_render, apart. */
|
||||
NK_API void
|
||||
nk_sdl_render_area(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
|
||||
enum nk_anti_aliasing line_AA, const SDL_Rect *rects, int n)
|
||||
{
|
||||
/* setup global state */
|
||||
struct nk_sdl* sdl;
|
||||
int is_sw, passes;
|
||||
float sx = 1.0f, sy = 1.0f;
|
||||
SDL_Rect last_clip = {0, 0, -1, -1};
|
||||
int covers = 0, seq = 0;
|
||||
NK_ASSERT(ctx);
|
||||
sdl = (struct nk_sdl*)ctx->userdata.ptr;
|
||||
NK_ASSERT(sdl);
|
||||
|
||||
{
|
||||
SDL_Rect saved_clip;
|
||||
SDL_Rect saved_clip, last_clip = {0, 0, -1, -1};
|
||||
SDL_BlendMode saved_blend;
|
||||
float saved_r, saved_g, saved_b, saved_a;
|
||||
bool clipping_enabled;
|
||||
@@ -677,10 +434,6 @@ nk_sdl_render_area(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
|
||||
config.line_AA = line_AA;
|
||||
|
||||
/* convert shapes into vertices */
|
||||
/* REAKTOR: the list may be converted again before nk_sdl_frame_done. */
|
||||
nk_buffer_clear(&sdl->ogl.cmds);
|
||||
nk_buffer_clear(&sdl->ogl.vbuf);
|
||||
nk_buffer_clear(&sdl->ogl.ebuf);
|
||||
nk_convert(&sdl->ctx, &sdl->ogl.cmds, &sdl->ogl.vbuf, &sdl->ogl.ebuf, &config);
|
||||
|
||||
/* REAKTOR: software vertices on the device pixel grid. */
|
||||
@@ -690,17 +443,16 @@ nk_sdl_render_area(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
|
||||
sx = sy = 1.0f;
|
||||
if (is_sw) {
|
||||
nk_byte *v = (nk_byte *)nk_buffer_memory(&sdl->ogl.vbuf);
|
||||
nk_size i, nv = sdl->ogl.vbuf.needed / (nk_size)vs;
|
||||
for (i = 0; i < nv; i++) {
|
||||
nk_size i, n = sdl->ogl.vbuf.needed / (nk_size)vs;
|
||||
for (i = 0; i < n; i++) {
|
||||
float *pos = (float *)(v + i * (nk_size)vs + vp);
|
||||
pos[0] = (SDL_floorf(pos[0] * sx + 0.5f) + 0.5f) / sx;
|
||||
pos[1] = (SDL_floorf(pos[1] * sy + 0.5f) + 0.5f) / sy;
|
||||
}
|
||||
}
|
||||
|
||||
/* REAKTOR: a frame drawn whole cuts its fills; a damaged one is small. */
|
||||
if (is_sw && n == 0 && nk_sdl_may_cut(&sdl->ctx, sx, sy))
|
||||
covers = nk_sdl_covers(sdl, sx, sy);
|
||||
/* iterate over and execute each draw command */
|
||||
offset = (const nk_draw_index*)nk_buffer_memory_const(&sdl->ogl.ebuf);
|
||||
|
||||
clipping_enabled = SDL_RenderClipEnabled(sdl->renderer);
|
||||
SDL_GetRenderClipRect(sdl->renderer, &saved_clip);
|
||||
@@ -713,17 +465,8 @@ nk_sdl_render_area(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
|
||||
&saved_b, &saved_a);
|
||||
SDL_SetRenderDrawBlendMode(sdl->renderer, SDL_BLENDMODE_BLEND);
|
||||
|
||||
/* REAKTOR: one conversion; each run, met by its box, drawn in every
|
||||
* rectangle it reaches. */
|
||||
offset = (const nk_draw_index*)nk_buffer_memory_const(&sdl->ogl.ebuf);
|
||||
passes = n > 0 ? n : 1;
|
||||
|
||||
/* iterate over and execute each draw command */
|
||||
nk_draw_foreach(cmd, &sdl->ctx, &sdl->ogl.cmds)
|
||||
{
|
||||
SDL_Rect clip;
|
||||
int i;
|
||||
|
||||
if (!cmd->elem_count) continue;
|
||||
|
||||
/* REAKTOR: glyph quads on the pixel grid. */
|
||||
@@ -738,20 +481,21 @@ nk_sdl_render_area(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
|
||||
}
|
||||
}
|
||||
|
||||
clip.x = cmd->clip_rect.x;
|
||||
clip.y = cmd->clip_rect.y;
|
||||
clip.w = cmd->clip_rect.w;
|
||||
clip.h = cmd->clip_rect.h;
|
||||
/* REAKTOR: drawn only inside the rectangles. */
|
||||
for (i = 0; i < n && !SDL_HasRectIntersection(&clip, &rects[i]); i++) {}
|
||||
if (n > 0 && i == n) {
|
||||
offset += cmd->elem_count;
|
||||
continue;
|
||||
{
|
||||
SDL_Rect r;
|
||||
r.x = cmd->clip_rect.x;
|
||||
r.y = cmd->clip_rect.y;
|
||||
r.w = cmd->clip_rect.w;
|
||||
r.h = cmd->clip_rect.h;
|
||||
if (SDL_memcmp(&r, &last_clip, sizeof r) != 0) {
|
||||
SDL_SetRenderClipRect(sdl->renderer, &r);
|
||||
last_clip = r;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const void *vertices = nk_buffer_memory_const(&sdl->ogl.vbuf);
|
||||
int nv = (int)(sdl->ogl.vbuf.needed / (nk_size)vs);
|
||||
int n = (int)(sdl->ogl.vbuf.needed / (nk_size)vs);
|
||||
|
||||
/* REAKTOR: shapes untextured. */
|
||||
SDL_Texture *tex = (SDL_Texture *)cmd->texture.ptr;
|
||||
@@ -760,70 +504,34 @@ nk_sdl_render_area(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
|
||||
|
||||
/* REAKTOR: software rectangles from device pixels. */
|
||||
if (is_sw) {
|
||||
struct nk_sdl_sw st;
|
||||
nk_uint k = 0, from = 0;
|
||||
float tw = 0.0f, th = 0.0f, b[4] = {0, 0, 0, 0};
|
||||
|
||||
SDL_zero(st);
|
||||
if (tex && !SDL_GetTextureSize(tex, &tw, &th)) tw = th = 0.0f;
|
||||
while (k + 6 <= cmd->elem_count) {
|
||||
struct nk_sdl_rect q;
|
||||
const struct nk_sdl_cover *later = NULL;
|
||||
int nlater = 0;
|
||||
|
||||
if (!nk_sdl_quad(vertices, offset + k, tex, tw, th, sx, sy, &q)) {
|
||||
if (!nk_sdl_quad(vertices, offset + k, tex, sx, sy, &q)) {
|
||||
k += 3;
|
||||
continue;
|
||||
}
|
||||
/* What came before it in the list is drawn before it. */
|
||||
if (k > from) {
|
||||
nk_sdl_sw_restore(sdl->renderer, tex, &st);
|
||||
if (n > 0)
|
||||
nk_sdl_run_box(vertices, offset + from, k - from, sx, sy, b);
|
||||
for (i = 0; i < passes; i++)
|
||||
if (nk_sdl_pass(sdl->renderer, &clip, rects, n, i, b, sx, sy,
|
||||
&last_clip))
|
||||
nk_sdl_geometry_sw(sdl->renderer, tex, vertices, nv,
|
||||
offset + from, (int)(k - from));
|
||||
}
|
||||
b[0] = q.d.x * sx;
|
||||
b[1] = q.d.y * sy;
|
||||
b[2] = (q.d.x + q.d.w) * sx;
|
||||
b[3] = (q.d.y + q.d.h) * sy;
|
||||
if (!tex && q.opaque && seq++ < covers &&
|
||||
(long long)(q.px.x1 - q.px.x0) * (q.px.y1 - q.px.y0) >= NK_SDL_CUT_MIN) {
|
||||
later = sdl->covers + seq;
|
||||
nlater = covers - seq;
|
||||
}
|
||||
for (i = 0; i < passes; i++)
|
||||
if (nk_sdl_pass(sdl->renderer, &clip, rects, n, i, b, sx, sy,
|
||||
&last_clip))
|
||||
nk_sdl_quad_draw(sdl->renderer, tex, &q, later, nlater,
|
||||
sx, sy, &st);
|
||||
if (k > from)
|
||||
nk_sdl_geometry_sw(sdl->renderer, tex, vertices, n,
|
||||
offset + from, (int)(k - from));
|
||||
nk_sdl_quad_draw(sdl->renderer, tex, &q);
|
||||
k += 6;
|
||||
from = k;
|
||||
}
|
||||
nk_sdl_sw_restore(sdl->renderer, tex, &st);
|
||||
if (cmd->elem_count > from) {
|
||||
if (n > 0)
|
||||
nk_sdl_run_box(vertices, offset + from, cmd->elem_count - from,
|
||||
sx, sy, b);
|
||||
for (i = 0; i < passes; i++)
|
||||
if (nk_sdl_pass(sdl->renderer, &clip, rects, n, i, b, sx, sy,
|
||||
&last_clip))
|
||||
nk_sdl_geometry_sw(sdl->renderer, tex, vertices, nv,
|
||||
offset + from,
|
||||
(int)(cmd->elem_count - from));
|
||||
}
|
||||
if (cmd->elem_count > from)
|
||||
nk_sdl_geometry_sw(sdl->renderer, tex, vertices, n,
|
||||
offset + from,
|
||||
(int)(cmd->elem_count - from));
|
||||
offset += cmd->elem_count;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* REAKTOR: nk_sdl_geometry, not SDL_RenderGeometryRaw. */
|
||||
for (i = 0; i < passes; i++)
|
||||
if (nk_sdl_pass(sdl->renderer, &clip, rects, n, i, NULL, sx, sy, &last_clip))
|
||||
nk_sdl_geometry(sdl->renderer, tex, vertices, nv, offset,
|
||||
(int)cmd->elem_count);
|
||||
nk_sdl_geometry(sdl->renderer, tex, vertices, n, offset,
|
||||
(int)cmd->elem_count);
|
||||
|
||||
offset += cmd->elem_count;
|
||||
}
|
||||
@@ -840,6 +548,11 @@ nk_sdl_render_area(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
|
||||
if (!clipping_enabled) {
|
||||
SDL_SetRenderClipRect(sdl->renderer, NULL);
|
||||
}
|
||||
|
||||
nk_clear(&sdl->ctx);
|
||||
nk_buffer_clear(&sdl->ogl.cmds);
|
||||
nk_buffer_clear(&sdl->ogl.vbuf);
|
||||
nk_buffer_clear(&sdl->ogl.ebuf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -933,6 +646,38 @@ nk_sdl_init(SDL_Window *win, SDL_Renderer *renderer, struct nk_allocator allocat
|
||||
return &sdl->ctx;
|
||||
}
|
||||
|
||||
#ifdef NK_INCLUDE_FONT_BAKING
|
||||
NK_API struct nk_font_atlas*
|
||||
nk_sdl_font_stash_begin(struct nk_context* ctx)
|
||||
{
|
||||
struct nk_sdl* sdl;
|
||||
NK_ASSERT(ctx);
|
||||
sdl = (struct nk_sdl*)ctx->userdata.ptr;
|
||||
NK_ASSERT(sdl);
|
||||
nk_font_atlas_init(&sdl->atlas, &sdl->allocator);
|
||||
nk_font_atlas_begin(&sdl->atlas);
|
||||
return &sdl->atlas;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef NK_INCLUDE_FONT_BAKING
|
||||
NK_API void
|
||||
nk_sdl_font_stash_end(struct nk_context* ctx)
|
||||
{
|
||||
struct nk_sdl* sdl;
|
||||
const void *image; int w, h;
|
||||
NK_ASSERT(ctx);
|
||||
sdl = (struct nk_sdl*)ctx->userdata.ptr;
|
||||
NK_ASSERT(sdl);
|
||||
/* REAKTOR: alpha8. */
|
||||
image = nk_font_atlas_bake(&sdl->atlas, &w, &h, NK_FONT_ATLAS_ALPHA8);
|
||||
NK_ASSERT(image);
|
||||
nk_font_atlas_end(&sdl->atlas, nk_sdl_font_upload(&sdl->ctx, image, w, h), &sdl->ogl.tex_null);
|
||||
if (sdl->atlas.default_font) {
|
||||
nk_style_set_font(&sdl->ctx, &sdl->atlas.default_font->handle);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* REAKTOR */
|
||||
NK_API nk_handle
|
||||
@@ -1117,10 +862,14 @@ void nk_sdl_shutdown(struct nk_context* ctx)
|
||||
sdl = (struct nk_sdl*)ctx->userdata.ptr;
|
||||
NK_ASSERT(sdl);
|
||||
|
||||
#ifdef NK_INCLUDE_FONT_BAKING
|
||||
if (sdl->atlas.font_num > 0)
|
||||
nk_font_atlas_clear(&sdl->atlas);
|
||||
#endif
|
||||
|
||||
nk_buffer_free(&sdl->ogl.cmds);
|
||||
nk_buffer_free(&sdl->ogl.vbuf);
|
||||
nk_buffer_free(&sdl->ogl.ebuf);
|
||||
SDL_free(sdl->covers);
|
||||
|
||||
if (sdl->ogl.font_tex != NULL) {
|
||||
SDL_DestroyTexture(sdl->ogl.font_tex);
|
||||
|
||||
+64
-43
@@ -91,12 +91,11 @@ typedef struct glyph_page {
|
||||
int x, y, row;
|
||||
} glyph_page;
|
||||
|
||||
/* By its shape entry, not the command's string: a command pushed before the
|
||||
draw can move Nuklear's command memory and free the string. */
|
||||
typedef struct text_draw {
|
||||
int face, entry;
|
||||
int face, len;
|
||||
float height;
|
||||
struct nk_color fg;
|
||||
const char *text;
|
||||
} text_draw;
|
||||
|
||||
static text_font g_font[FONTS_MAX];
|
||||
@@ -138,6 +137,18 @@ static int g_draws, g_draw_cap;
|
||||
static unsigned g_seq;
|
||||
static int g_seq_known, g_took;
|
||||
|
||||
static void *
|
||||
grow(void *p, int *cap, int need, size_t size)
|
||||
{
|
||||
int n = *cap > 0 ? *cap : 64;
|
||||
|
||||
if (need <= *cap) return p;
|
||||
while (n < need) n *= 2;
|
||||
p = SDL_realloc(p, (size_t)n * size);
|
||||
if (p) *cap = n;
|
||||
return p;
|
||||
}
|
||||
|
||||
static int
|
||||
font_add(const char *path)
|
||||
{
|
||||
@@ -241,9 +252,11 @@ atlas_draws(const struct reaktor_font *font, const char *s, int len)
|
||||
static int
|
||||
decode(const char *s, int len)
|
||||
{
|
||||
text_char *p;
|
||||
int n = 0, at = 0;
|
||||
|
||||
if (!reaktor_grow((void **)&g_ch, &g_ch_cap, len, sizeof *g_ch)) return 0;
|
||||
if (!(p = grow(g_ch, &g_ch_cap, len, sizeof *g_ch))) return 0;
|
||||
g_ch = p;
|
||||
while (at < len) {
|
||||
kbts_decode d = kbts_DecodeUtf8(s + at, (kbts_un)(len - at));
|
||||
|
||||
@@ -258,15 +271,14 @@ static void
|
||||
levels(const char *s, int len, int n)
|
||||
{
|
||||
mjb_bidi_paragraph p;
|
||||
mjb_text text = mjb_text_utf8(s, (size_t)len);
|
||||
int i, k = 0;
|
||||
|
||||
for (i = 0; i < n && g_ch[i].cp < 0x0590; i++) {}
|
||||
if (i == n ||
|
||||
mjb_bidi_resolve(&text, MJB_DIRECTION_AUTO, &p)
|
||||
mjb_bidi_resolve(s, (size_t)len, MJB_ENC_UTF_8, MJB_DIRECTION_AUTO, &p)
|
||||
!= MJB_STATUS_OK)
|
||||
return;
|
||||
/* mojibake 0.5.0 puts byte_offset at a character's last byte. */
|
||||
/* mojibake 0.4.1 puts byte_offset at a character's last byte. */
|
||||
for (i = 0; i < n; i++) {
|
||||
if (k < (int)p.count && (int)p.chars[k].codepoint == g_ch[i].cp)
|
||||
g_ch[i].level = p.chars[k++].level;
|
||||
@@ -342,13 +354,15 @@ choose_fonts(int base, int n)
|
||||
static int
|
||||
split(int n)
|
||||
{
|
||||
text_run *p;
|
||||
int i, r = 0;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
if (r == 0 || g_ch[i].level != g_ch[i - 1].level ||
|
||||
g_ch[i].script != g_ch[i - 1].script ||
|
||||
g_ch[i].font != g_ch[i - 1].font) {
|
||||
if (reaktor_grow((void **)&g_run, &g_run_cap, r + 1, sizeof *g_run)) {
|
||||
if ((p = grow(g_run, &g_run_cap, r + 1, sizeof *g_run)) != NULL) {
|
||||
g_run = p;
|
||||
g_run[r].from = i;
|
||||
g_run[r].font = g_ch[i].font;
|
||||
g_run[r].level = g_ch[i].level;
|
||||
@@ -449,6 +463,7 @@ shape_run(const text_run *r, float pen)
|
||||
kbts_glyph_iterator it;
|
||||
kbts_glyph *g;
|
||||
shaped *out;
|
||||
void *p;
|
||||
int i;
|
||||
|
||||
if (!c) return pen;
|
||||
@@ -458,13 +473,15 @@ shape_run(const text_run *r, float pen)
|
||||
if (kbts_ShapeDirect(c->scratch, &g_storage,
|
||||
(r->level & 1) ? KBTS_DIRECTION_RTL : KBTS_DIRECTION_LTR,
|
||||
&it) != KBTS_SHAPE_ERROR_NONE) {
|
||||
/* A scratchpad keeps its error. */
|
||||
kbts_DestroyShapeScratchpad(c->scratch);
|
||||
c->scratch = NULL;
|
||||
return pen;
|
||||
}
|
||||
while (kbts_GlyphIteratorNext(&it, &g)) {
|
||||
if (!reaktor_grow((void **)&g_glyph, &g_glyph_cap, g_glyphs + 1, sizeof *g_glyph))
|
||||
if (!(p = grow(g_glyph, &g_glyph_cap, g_glyphs + 1, sizeof *g_glyph)))
|
||||
break;
|
||||
g_glyph = p;
|
||||
out = &g_glyph[g_glyphs++];
|
||||
out->x = pen + (float)g->OffsetX * f->unit;
|
||||
out->y = (float)g->OffsetY * f->unit;
|
||||
@@ -480,6 +497,7 @@ shape(int file, const char *s, int len)
|
||||
{
|
||||
shape_entry *e;
|
||||
Uint32 hash = reaktor_fnv_n(REAKTOR_FNV ^ (Uint32)file, s, (size_t)(len > 0 ? len : 0));
|
||||
void *p;
|
||||
float pen = 0.0f;
|
||||
int i, n, runs, first;
|
||||
|
||||
@@ -497,10 +515,13 @@ shape(int file, const char *s, int len)
|
||||
segment(n);
|
||||
choose_fonts(file, n);
|
||||
runs = split(n);
|
||||
if (!reaktor_grow((void **)&g_order, &g_order_cap, runs, sizeof *g_order)) return -1;
|
||||
if (!(p = grow(g_order, &g_order_cap, runs, sizeof *g_order))) return -1;
|
||||
g_order = p;
|
||||
order(runs);
|
||||
if (!reaktor_grow((void **)&g_entry, &g_entry_cap, g_entries + 1, sizeof *g_entry)) return -1;
|
||||
if (!reaktor_grow((void **)&g_bytes, &g_byte_cap, g_byte_n + len, 1)) return -1;
|
||||
if (!(p = grow(g_entry, &g_entry_cap, g_entries + 1, sizeof *g_entry))) return -1;
|
||||
g_entry = p;
|
||||
if (!(p = grow(g_bytes, &g_byte_cap, g_byte_n + len, 1))) return -1;
|
||||
g_bytes = p;
|
||||
|
||||
first = g_glyphs;
|
||||
for (i = 0; i < runs; i++) pen = shape_run(&g_run[g_order[i]], pen);
|
||||
@@ -521,6 +542,8 @@ shape(int file, const char *s, int len)
|
||||
return g_entries++;
|
||||
}
|
||||
|
||||
/* Keeps what the frame just measured, so a full cache does not reshape
|
||||
everything on screen at once. */
|
||||
static void
|
||||
shapes_compact(void)
|
||||
{
|
||||
@@ -600,9 +623,11 @@ static int
|
||||
upload(int page, int x, int y, const FT_Bitmap *bm)
|
||||
{
|
||||
SDL_Rect r;
|
||||
void *p;
|
||||
int w = (int)bm->width, h = (int)bm->rows, bw = w + 2, bh = h + 2, i;
|
||||
|
||||
if (!reaktor_grow((void **)&g_bitmap, &g_bitmap_cap, bw * bh, 1)) return 0;
|
||||
if (!(p = grow(g_bitmap, &g_bitmap_cap, bw * bh, 1))) return 0;
|
||||
g_bitmap = p;
|
||||
SDL_memset(g_bitmap, 0, (size_t)(bw * bh));
|
||||
for (i = 0; i < h; i++)
|
||||
SDL_memcpy(g_bitmap + (i + 1) * bw + 1, bm->buffer + i * bm->pitch, (size_t)w);
|
||||
@@ -612,7 +637,8 @@ upload(int page, int x, int y, const FT_Bitmap *bm)
|
||||
r.h = bh;
|
||||
if (!g_page[page].argb)
|
||||
return SDL_UpdateTexture(g_page[page].tex, &r, g_bitmap, bw);
|
||||
if (!reaktor_grow((void **)&g_pixels, &g_pixel_cap, bw * bh, sizeof *g_pixels)) return 0;
|
||||
if (!(p = grow(g_pixels, &g_pixel_cap, bw * bh, sizeof *g_pixels))) return 0;
|
||||
g_pixels = p;
|
||||
for (i = 0; i < bw * bh; i++)
|
||||
g_pixels[i] = (Uint32)g_bitmap[i] << 24 | 0x00FFFFFF;
|
||||
return SDL_UpdateTexture(g_page[page].tex, &r, g_pixels, bw * 4);
|
||||
@@ -769,7 +795,7 @@ draw(void *canvas, short x, short y, unsigned short w, unsigned short h,
|
||||
return;
|
||||
d = &g_draw[data.id];
|
||||
f = &g_face[d->face];
|
||||
if ((e = d->entry) < 0) return;
|
||||
if ((e = shape(f->file, d->text, d->len)) < 0) return;
|
||||
px = f->font->height * d->height / f->font->handle.height;
|
||||
k = d->height / px;
|
||||
top = f->font->baseline * px / f->font->height;
|
||||
@@ -800,6 +826,7 @@ reaktor_text_prepare(struct nk_context *ctx, struct SDL_Renderer *renderer)
|
||||
const struct nk_command *cmd;
|
||||
|
||||
g_renderer = renderer;
|
||||
/* The same frame again: its text commands are already custom ones. */
|
||||
if (g_faces == 0 || (g_seq_known && ctx->seq == g_seq)) return;
|
||||
g_seq = ctx->seq;
|
||||
g_seq_known = 1;
|
||||
@@ -815,6 +842,7 @@ reaktor_text_prepare(struct nk_context *ctx, struct SDL_Renderer *renderer)
|
||||
struct nk_command_custom *c = (struct nk_command_custom *)cmd;
|
||||
const struct reaktor_font *font;
|
||||
text_draw d;
|
||||
void *p;
|
||||
short x, y;
|
||||
unsigned short w, h;
|
||||
int face;
|
||||
@@ -825,11 +853,13 @@ reaktor_text_prepare(struct nk_context *ctx, struct SDL_Renderer *renderer)
|
||||
if (face < 0 || atlas_draws(font, t->string, t->length) ||
|
||||
!font_open(g_face[face].file))
|
||||
continue;
|
||||
if (!reaktor_grow((void **)&g_draw, &g_draw_cap, g_draws + 1, sizeof *g_draw)) break;
|
||||
if (!(p = grow(g_draw, &g_draw_cap, g_draws + 1, sizeof *g_draw))) break;
|
||||
g_draw = p;
|
||||
d.face = face;
|
||||
d.entry = shape(g_face[face].file, t->string, t->length);
|
||||
d.len = t->length;
|
||||
d.height = t->height;
|
||||
d.fg = t->foreground;
|
||||
d.text = t->string;
|
||||
x = t->x;
|
||||
y = t->y;
|
||||
w = t->w;
|
||||
@@ -845,37 +875,28 @@ reaktor_text_prepare(struct nk_context *ctx, struct SDL_Renderer *renderer)
|
||||
}
|
||||
}
|
||||
|
||||
float
|
||||
reaktor_text_ink_em(void)
|
||||
{
|
||||
float most = 0.0f;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < g_fonts; i++) {
|
||||
const text_font *f = &g_font[i];
|
||||
FT_Pos m;
|
||||
|
||||
if (f->state <= 0) continue;
|
||||
m = SDL_max(SDL_max(-f->face->bbox.xMin, f->face->bbox.xMax),
|
||||
SDL_max(-f->face->bbox.yMin, f->face->bbox.yMax));
|
||||
if ((float)m * f->unit > most) most = (float)m * f->unit;
|
||||
}
|
||||
return most;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_text_break(const char *s, int len, int limit)
|
||||
{
|
||||
mjb_text text = mjb_text_utf8(s, (size_t)len);
|
||||
mjb_line_break_state st;
|
||||
mjb_break_type t;
|
||||
int best = 0;
|
||||
mjb_next_line_state st;
|
||||
mjb_break_type t;
|
||||
int best = 0;
|
||||
|
||||
if (len <= 0 || limit <= 0) return 0;
|
||||
SDL_zero(st);
|
||||
while ((t = mjb_line_break_next(&text, &st)) != MJB_BT_NOT_SET) {
|
||||
if ((int)st.position > limit) break;
|
||||
if (t == MJB_BT_ALLOWED || t == MJB_BT_MANDATORY) best = (int)st.position;
|
||||
st.index = 0;
|
||||
while ((t = mjb_next_line_break(s, (size_t)len, MJB_ENC_UTF_8, &st))
|
||||
!= MJB_BT_NOT_SET) {
|
||||
/* The boundary is before the character ending at st.index. */
|
||||
int at = (int)st.index;
|
||||
|
||||
if (at > len) {
|
||||
at = len;
|
||||
} else {
|
||||
at--;
|
||||
while (at > 0 && ((unsigned char)s[at] & 0xC0) == 0x80) at--;
|
||||
}
|
||||
if (at > limit) break;
|
||||
if (t == MJB_BT_ALLOWED || t == MJB_BT_MANDATORY) best = at;
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,5 @@ struct SDL_Renderer;
|
||||
void reaktor_text_add_fallback(const char *path);
|
||||
void reaktor_text_attach_font(struct reaktor_font *font, const char *path);
|
||||
void reaktor_text_prepare(struct nk_context *ctx, struct SDL_Renderer *renderer);
|
||||
float reaktor_text_ink_em(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,12 +14,6 @@ reaktor_text_prepare(struct nk_context *ctx, struct SDL_Renderer *renderer)
|
||||
(void)ctx; (void)renderer;
|
||||
}
|
||||
|
||||
float
|
||||
reaktor_text_ink_em(void)
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_text_break(const char *s, int len, int limit)
|
||||
{
|
||||
|
||||
+21
-19
@@ -10,15 +10,16 @@ fit_button(reaktor_box *box, const reaktor_button_spec *s)
|
||||
const struct nk_style_button *nb = &g_frame_ctx->style.button;
|
||||
const char *sel = decl_rule_or(s->style, "button");
|
||||
float least = box->w, w;
|
||||
char src[192];
|
||||
|
||||
box->w = box->h = 0.0f;
|
||||
box->flags &= ~(REAKTOR_LAY_FILL);
|
||||
box->flags &= ~(REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y);
|
||||
decl_box_from_style(box, NULL, s->style, "button", nb->padding.x, nb->padding.y);
|
||||
if (s->icon && !s->label)
|
||||
w = box->h;
|
||||
else
|
||||
w = css_button_content_w(g_frame_app, g_frame_ctx, sel, decl_style_font(sel),
|
||||
s->icon, s->label);
|
||||
reaktor_button_src(src, s->icon), s->label);
|
||||
box->w = SDL_ceilf(SDL_max(w, least));
|
||||
}
|
||||
|
||||
@@ -285,6 +286,7 @@ reaktor_label(const reaktor_label_spec *s)
|
||||
: NK_TEXT_LEFT;
|
||||
struct nk_color c = reaktor_token(s->color, g_frame_ctx->style.text.color);
|
||||
|
||||
/* A sheet can repaint the page without redefining the token. */
|
||||
if (s->color)
|
||||
c = reaktor_visible(c, reaktor_page_color(g_frame_app),
|
||||
g_frame_ctx->style.text.color);
|
||||
@@ -332,6 +334,7 @@ reaktor_field_select(App *app, const char *buf, int from, int to)
|
||||
reaktor_wake(app);
|
||||
}
|
||||
|
||||
/* Room for what is typed or pasted this frame: Nuklear never writes past cap. */
|
||||
static char *
|
||||
field_room(const reaktor_field_spec *s, int *cap)
|
||||
{
|
||||
@@ -488,7 +491,9 @@ reaktor_swatch(const reaktor_swatch_spec *s)
|
||||
if (!decl_place(REAKTOR_A11Y_BUTTON, s->name, hex, 0u, NULL, &box, &id))
|
||||
return 0;
|
||||
|
||||
hit = reaktor_css_button_color(g_frame_app, g_frame_ctx, s->fill);
|
||||
reaktor_note_mute(g_frame_app, 1);
|
||||
hit = reaktor_css_button_color(g_frame_app, g_frame_ctx, s->name, s->fill);
|
||||
reaktor_note_mute(g_frame_app, 0);
|
||||
|
||||
if (reaktor_focus_activated(g_frame_app, id)) hit = 1;
|
||||
if (hit && s->on_press.fn) s->on_press.fn(s->on_press.user);
|
||||
@@ -633,11 +638,10 @@ reaktor_select(const reaktor_select_spec *s)
|
||||
void
|
||||
reaktor_slider(const reaktor_slider_spec *s)
|
||||
{
|
||||
reaktor_box box;
|
||||
reaktor_style fill;
|
||||
char text[32];
|
||||
unsigned id = 0;
|
||||
float now;
|
||||
reaktor_box box;
|
||||
char text[32];
|
||||
unsigned id = 0;
|
||||
float now;
|
||||
|
||||
if (!g_frame_app || !s || (!s->value && !s->ivalue)) return;
|
||||
now = s->value ? *s->value : (float)*s->ivalue;
|
||||
@@ -654,14 +658,14 @@ reaktor_slider(const reaktor_slider_spec *s)
|
||||
if (!decl_place(REAKTOR_A11Y_SLIDER, s->name, text, 0u, NULL, &box, &id))
|
||||
return;
|
||||
|
||||
reaktor_style_get(s->style ? s->style : "input.type-range", &fill);
|
||||
reaktor_note_range(g_frame_app, id, now, s->lo, s->hi, s->step);
|
||||
|
||||
reaktor_note_mute(g_frame_app, 1);
|
||||
if (s->value)
|
||||
reaktor_slider_ramp(g_frame_app, g_frame_ctx, id, s->value, s->lo, s->hi, s->step,
|
||||
&fill);
|
||||
reaktor_slider_bar(g_frame_app, g_frame_ctx, id, s->value, s->lo, s->hi, s->step);
|
||||
else
|
||||
reaktor_slider_bar_int(g_frame_app, g_frame_ctx, id, s->ivalue, (int)s->lo,
|
||||
(int)s->hi, (int)s->step, &fill);
|
||||
(int)s->hi, (int)s->step);
|
||||
reaktor_note_mute(g_frame_app, 0);
|
||||
}
|
||||
|
||||
@@ -719,7 +723,6 @@ reaktor_property(const reaktor_property_spec *s)
|
||||
char text[32];
|
||||
unsigned id = 0;
|
||||
double now;
|
||||
int live;
|
||||
|
||||
if (!g_frame_app || !s || (!s->ivalue && !s->fvalue && !s->dvalue)) return;
|
||||
now = s->ivalue ? (double)*s->ivalue
|
||||
@@ -740,9 +743,8 @@ reaktor_property(const reaktor_property_spec *s)
|
||||
|
||||
r = nk_widget_bounds(g_frame_ctx);
|
||||
|
||||
live = reaktor_property_live(g_frame_ctx);
|
||||
reaktor_note_mute(g_frame_app, 1);
|
||||
reaktor_property_push(g_frame_ctx, reaktor_rect_trunc(r), live);
|
||||
reaktor_property_push(g_frame_ctx);
|
||||
if (s->ivalue)
|
||||
nk_property_int(g_frame_ctx, s->label, (int)s->lo, s->ivalue, (int)s->hi,
|
||||
(int)s->step, s->grain);
|
||||
@@ -753,7 +755,7 @@ reaktor_property(const reaktor_property_spec *s)
|
||||
nk_property_double(g_frame_ctx, s->label, s->lo, s->dvalue, s->hi,
|
||||
s->step, s->grain);
|
||||
reaktor_property_pop(g_frame_ctx);
|
||||
reaktor_property_chrome(g_frame_app, g_frame_ctx, r, NULL, live);
|
||||
reaktor_property_chrome(g_frame_app, g_frame_ctx, r, NULL);
|
||||
reaktor_note_mute(g_frame_app, 0);
|
||||
}
|
||||
|
||||
@@ -785,12 +787,12 @@ reaktor_spinner(const reaktor_spinner_spec *s)
|
||||
f = ctx->style.font;
|
||||
cv = nk_window_get_canvas(ctx);
|
||||
nk_widget(&r, ctx);
|
||||
bg = hot_hover(ctx, r) ? st->hover : st->normal;
|
||||
bg = nk_input_is_mouse_hovering_rect(&ctx->input, r) ? st->hover : st->normal;
|
||||
if (bg.type == NK_STYLE_ITEM_COLOR)
|
||||
reaktor_fill_round(g_frame_app, cv, r, st->rounding, bg.data.color);
|
||||
if (st->border > 0.0f)
|
||||
reaktor_edge_round(g_frame_app, cv, r, st->rounding, st->border, st->border_color);
|
||||
reaktor_property_chrome(g_frame_app, ctx, r, step, 1);
|
||||
reaktor_property_chrome(g_frame_app, ctx, r, step);
|
||||
y = (float)(int)(r.y + (r.h - f->height) * 0.5f);
|
||||
if (s->label)
|
||||
nk_draw_text(cv, nk_rect(step[0].x + step[0].w + 8.0f, y, r.w * 0.5f, f->height),
|
||||
@@ -852,7 +854,7 @@ reaktor_combo_open(const reaktor_combo_spec *s)
|
||||
|
||||
if (open) nk_push_scissor(nk_window_get_canvas(g_frame_ctx), clip);
|
||||
if (s->disc) {
|
||||
struct nk_rect im;
|
||||
struct nk_rect im = reaktor_combo_content(g_frame_ctx, h);
|
||||
|
||||
im.w = im.h = h.h - 2.0f * g_frame_ctx->style.combo.content_padding.y;
|
||||
im.x = h.x + g_frame_ctx->style.combo.content_padding.x;
|
||||
|
||||
+32
-25
@@ -22,6 +22,9 @@ static struct nk_rect g_boxrect[REAKTOR_LAY_DEPTH + 1];
|
||||
static unsigned char g_boxok[REAKTOR_LAY_DEPTH + 1];
|
||||
static unsigned g_boxid[REAKTOR_LAY_DEPTH + 1];
|
||||
|
||||
/* Marks, for tests: kept apart from the tree, and allocated only once a widget
|
||||
sets one, so an application that sets none pays nothing. The main window's
|
||||
last frame is what a test reads. One mark may sit on many widgets. */
|
||||
#define MARK_LEN 64
|
||||
|
||||
typedef struct decl_mark {
|
||||
@@ -61,6 +64,7 @@ reaktor_mark_at(int i, unsigned *id)
|
||||
return g_marks[i].mark;
|
||||
}
|
||||
|
||||
/* Whether a node carries a mark; with id 0, whether anything does. */
|
||||
int
|
||||
reaktor_mark_has(unsigned id, const char *mark)
|
||||
{
|
||||
@@ -93,6 +97,7 @@ reaktor_frame_end(void)
|
||||
if (g_space) { nk_layout_space_end(g_frame_ctx); g_space = 0; }
|
||||
reaktor_layout_end(&g_frame_app->lay);
|
||||
|
||||
/* This frame's rectangles were laid out with the sizes of an older sheet. */
|
||||
if (g_frame_app->style_loads != reaktor_style_loads()) {
|
||||
g_frame_app->style_loads = reaktor_style_loads();
|
||||
g_frame_unsettled++;
|
||||
@@ -277,21 +282,17 @@ decl_place(unsigned char role, const char *name, const char *value, unsigned sta
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct nk_user_font *
|
||||
style_font(const reaktor_style *st)
|
||||
{
|
||||
return st->matched && st->font_px > 0 ? pick_font(g_frame_app, st->font_px, st->bold)
|
||||
: g_frame_ctx->style.font;
|
||||
}
|
||||
|
||||
const struct nk_user_font *
|
||||
decl_style_font(const char *selector)
|
||||
{
|
||||
reaktor_style st;
|
||||
|
||||
if (!selector) return g_frame_ctx->style.font;
|
||||
reaktor_style_get(selector, &st);
|
||||
return style_font(&st);
|
||||
if (selector) {
|
||||
reaktor_style_get(selector, &st);
|
||||
if (st.matched && st.font_px > 0)
|
||||
return pick_font(g_frame_app, st.font_px, st.bold);
|
||||
}
|
||||
return g_frame_ctx->style.font;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -341,22 +342,23 @@ void
|
||||
decl_box_from_style(reaktor_box *box, const char *text, const char *selector,
|
||||
const char *element, float pad_x, float pad_y)
|
||||
{
|
||||
const char *sel = element ? element : selector;
|
||||
const struct nk_user_font *f;
|
||||
reaktor_style st;
|
||||
float extra_w, extra_h;
|
||||
|
||||
memset(&st, 0, sizeof(st));
|
||||
if (element) reaktor_style_get(element, &st);
|
||||
f = style_font(&st);
|
||||
if (selector) {
|
||||
reaktor_style narrow;
|
||||
|
||||
reaktor_style_get(selector, &narrow);
|
||||
if (narrow.matched) {
|
||||
f = style_font(&narrow);
|
||||
sel = selector;
|
||||
overlay(&st, &narrow);
|
||||
}
|
||||
}
|
||||
f = decl_style_font(sel);
|
||||
|
||||
if (st.matched) {
|
||||
extra_w = st.pad[REAKTOR_SIDE_LEFT] + st.pad[REAKTOR_SIDE_RIGHT]
|
||||
@@ -425,27 +427,32 @@ reaktor_soak(void)
|
||||
(void)decl_place(REAKTOR_A11Y_NONE, NULL, NULL, 0u, NULL, &box, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
tip_at(App *app, struct nk_context *ctx, struct nk_rect r, const char *text, int cursor)
|
||||
void
|
||||
decl_tip_at(const char *tip, struct nk_rect r, int cursor)
|
||||
{
|
||||
if (!text || !ctx || !ctx->current) return;
|
||||
reaktor_hot_follow(app, r, cursor);
|
||||
if (hot_hover(ctx, r)) {
|
||||
SDL_strlcpy(app->tip_text, text, sizeof app->tip_text);
|
||||
app->tip = app->tip_text;
|
||||
const struct nk_input *in = &g_frame_ctx->input;
|
||||
|
||||
if (!tip) return;
|
||||
reaktor_hot_follow(g_frame_app, r, cursor);
|
||||
if (nk_input_is_mouse_hovering_rect(in, r) &&
|
||||
nk_input_is_mouse_hovering_rect(in, g_frame_ctx->current->layout->clip)) {
|
||||
SDL_strlcpy(g_frame_app->tip_text, tip, sizeof g_frame_app->tip_text);
|
||||
g_frame_app->tip = g_frame_app->tip_text;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_tip(App *app, struct nk_rect r, const char *text)
|
||||
{
|
||||
tip_at(app, app ? app->ctx : NULL, r, text, 0);
|
||||
}
|
||||
struct nk_context *ctx = app ? app->ctx : NULL;
|
||||
|
||||
void
|
||||
decl_tip_at(const char *tip, struct nk_rect r, int cursor)
|
||||
{
|
||||
tip_at(g_frame_app, g_frame_ctx, r, tip, cursor);
|
||||
if (!text || !ctx || !ctx->current) return;
|
||||
reaktor_hot_follow(app, r, 0);
|
||||
if (nk_input_is_mouse_hovering_rect(&ctx->input, r) &&
|
||||
nk_input_is_mouse_hovering_rect(&ctx->input, ctx->current->layout->clip)) {
|
||||
SDL_strlcpy(app->tip_text, text, sizeof app->tip_text);
|
||||
app->tip = app->tip_text;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+4
-12
@@ -121,6 +121,7 @@ shut(App *app, int i, int tell)
|
||||
hand_back(app, &o);
|
||||
SDL_free(o.title);
|
||||
if (tell && o.spec.closed) o.spec.closed(app, o.spec.user);
|
||||
/* The page is already drawn; the close shows next frame. */
|
||||
reaktor_wake(app);
|
||||
}
|
||||
|
||||
@@ -149,6 +150,7 @@ reaktor_floaters_draw(App *app, struct nk_context *ctx, int win_w, int win_h)
|
||||
char name[40];
|
||||
int shown, k, was = top;
|
||||
|
||||
/* A body drawn before this one may have opened a modal. */
|
||||
for (top = -1, k = 0; k < g_floater_n; k++)
|
||||
if (g_floater[k].spec.modal && !g_floater[k].closing) top = k;
|
||||
if (i > 0 && top != was) app->trap_lo = app->trap_hi = -1;
|
||||
@@ -192,14 +194,6 @@ typedef struct question {
|
||||
float text_h;
|
||||
} question;
|
||||
|
||||
static float
|
||||
ask_button_w(App *app, struct nk_context *ctx, const char *label)
|
||||
{
|
||||
float w = reaktor_button_width(app, ctx, NULL, label);
|
||||
|
||||
return w > 96.0f ? w : 96.0f;
|
||||
}
|
||||
|
||||
static void
|
||||
ask_body(App *app, struct nk_context *ctx, int w, int h, void *user)
|
||||
{
|
||||
@@ -216,8 +210,7 @@ ask_body(App *app, struct nk_context *ctx, int w, int h, void *user)
|
||||
nk_spacer(ctx);
|
||||
nk_layout_row_template_begin(ctx, 36.0f);
|
||||
nk_layout_row_template_push_dynamic(ctx);
|
||||
for (i = 0; i < q->q.count; i++)
|
||||
nk_layout_row_template_push_static(ctx, ask_button_w(app, ctx, q->q.buttons[i]));
|
||||
for (i = 0; i < q->q.count; i++) nk_layout_row_template_push_static(ctx, 96.0f);
|
||||
nk_layout_row_template_end(ctx);
|
||||
nk_spacer(ctx);
|
||||
for (i = 0; i < q->q.count; i++)
|
||||
@@ -266,8 +259,7 @@ reaktor_ask(App *app, const reaktor_question *spec)
|
||||
q->q.text = SDL_memcpy(at, spec->text, SDL_strlen(spec->text) + 1);
|
||||
|
||||
f = reaktor_style_font(app, ".popup-title", 16, 1);
|
||||
w = 120.0f;
|
||||
for (i = 0; i < spec->count; i++) w += ask_button_w(app, app->ctx, spec->buttons[i]) + 8.0f;
|
||||
w = 104.0f * (float)spec->count + 120.0f;
|
||||
if (w < 328.0f) w = 328.0f;
|
||||
q->text_h = 22.0f * (float)(1 + (int)(f->width(f->userdata, f->height, q->q.text,
|
||||
(int)SDL_strlen(q->q.text)) / w));
|
||||
|
||||
+43
-32
@@ -52,35 +52,14 @@ focus_reveal(App *app, const reaktor_a11y_node *t, int n, int pick)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
node_index(const reaktor_a11y_node *t, int n, unsigned id)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
if (t[i].id == id) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
focus_to(App *app, const reaktor_a11y_node *t, int n, int i)
|
||||
{
|
||||
app->focus_id = t[i].id;
|
||||
reaktor_a11y_set_focus(&app->a11y, app->focus_id);
|
||||
app->focus_rect = t[i].bounds;
|
||||
app->focus_seen = 1;
|
||||
app->focus_visible = 1;
|
||||
app->dirty = 1;
|
||||
focus_reveal(app, t, n, i);
|
||||
}
|
||||
|
||||
static void
|
||||
focus_move(App *app, int step)
|
||||
{
|
||||
int n, i, cur, pick = -1, lo, hi;
|
||||
int n, i, cur = -1, pick = -1, lo, hi;
|
||||
const reaktor_a11y_node *t = reaktor_a11y_tree(&app->a11y, &n);
|
||||
|
||||
cur = node_index(t, n, app->focus_id);
|
||||
for (i = 0; i < n; i++)
|
||||
if (t[i].id == app->focus_id) { cur = i; break; }
|
||||
lo = 0;
|
||||
hi = n - 1;
|
||||
if (app->popup_hi >= 0 && app->popup_hi < n) {
|
||||
@@ -109,7 +88,14 @@ focus_move(App *app, int step)
|
||||
}
|
||||
}
|
||||
if (pick < 0) return;
|
||||
focus_to(app, t, n, pick);
|
||||
|
||||
app->focus_id = t[pick].id;
|
||||
reaktor_a11y_set_focus(&app->a11y, app->focus_id);
|
||||
app->focus_rect = t[pick].bounds;
|
||||
app->focus_seen = 1;
|
||||
app->focus_visible = 1;
|
||||
app->dirty = 1;
|
||||
focus_reveal(app, t, n, pick);
|
||||
if (t[pick].role == REAKTOR_A11Y_TEXTBOX) reaktor_key_click_ask(app);
|
||||
}
|
||||
|
||||
@@ -127,20 +113,29 @@ focus_resolve(App *app)
|
||||
const reaktor_a11y_node *t = reaktor_a11y_tree(&app->a11y, &n);
|
||||
|
||||
if (!app->focus_id) return;
|
||||
if ((i = node_index(t, n, app->focus_id)) >= 0 && focusable(&t[i])) return;
|
||||
for (i = 0; i < n; i++)
|
||||
if (t[i].id == app->focus_id) {
|
||||
if (focusable(&t[i])) return;
|
||||
break;
|
||||
}
|
||||
app->focus_id = 0;
|
||||
reaktor_a11y_set_focus(&app->a11y, 0);
|
||||
}
|
||||
|
||||
/* 1 when every arrow steps the focused widget, 2 when only Left and Right do. */
|
||||
static int
|
||||
focus_steps(App *app)
|
||||
{
|
||||
int n, i;
|
||||
const reaktor_a11y_node *t = reaktor_a11y_tree(&app->a11y, &n);
|
||||
|
||||
if (!app->focus_id || (i = node_index(t, n, app->focus_id)) < 0) return 0;
|
||||
return t[i].role == REAKTOR_A11Y_SLIDER || t[i].role == REAKTOR_A11Y_SPINBUTTON ? 1
|
||||
: t[i].role == REAKTOR_A11Y_TREEITEM ? 2 : 0;
|
||||
if (!app->focus_id) return 0;
|
||||
for (i = 0; i < n; i++)
|
||||
if (t[i].id == app->focus_id)
|
||||
return t[i].role == REAKTOR_A11Y_SLIDER ||
|
||||
t[i].role == REAKTOR_A11Y_SPINBUTTON ? 1
|
||||
: t[i].role == REAKTOR_A11Y_TREEITEM ? 2 : 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -162,6 +157,7 @@ focus_key(App *app, const SDL_Event *event)
|
||||
return 1;
|
||||
}
|
||||
if (editing) {
|
||||
/* The caret's, and the panel would scroll the field out of sight. */
|
||||
switch (event->key.key) {
|
||||
case SDLK_HOME:
|
||||
nk_input_key(app->ctx, NK_KEY_TEXT_START, nk_true);
|
||||
@@ -235,7 +231,17 @@ reader_focus(void *user, unsigned id)
|
||||
int n, i;
|
||||
const reaktor_a11y_node *t = reaktor_a11y_tree(&app->a11y, &n);
|
||||
|
||||
if ((i = node_index(t, n, id)) >= 0) focus_to(app, t, n, i);
|
||||
for (i = 0; i < n; i++)
|
||||
if (t[i].id == id) {
|
||||
app->focus_id = id;
|
||||
reaktor_a11y_set_focus(&app->a11y, id);
|
||||
app->focus_rect = t[i].bounds;
|
||||
app->focus_seen = 1;
|
||||
app->focus_visible = 1;
|
||||
app->dirty = 1;
|
||||
focus_reveal(app, t, n, i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -329,9 +335,13 @@ focus_ring(App *app, struct nk_context *ctx, struct nk_command_buffer *cv)
|
||||
int n, i, in_page = 0;
|
||||
const reaktor_a11y_node *t = reaktor_a11y_tree(&app->a11y, &n);
|
||||
|
||||
if (app->focus_layer == FOCUS_PAGE && (i = node_index(t, n, app->focus_id)) >= 0)
|
||||
in_page = node_under(t, n, i, app->page_node);
|
||||
for (i = 0; i < n && app->focus_layer == FOCUS_PAGE; i++)
|
||||
if (t[i].id == app->focus_id) {
|
||||
in_page = node_under(t, n, i, app->page_node);
|
||||
break;
|
||||
}
|
||||
if (in_page) nk_push_scissor(cv, app->body_rect);
|
||||
/* Truncated as nk_widget truncates the chrome it surrounds. */
|
||||
r = reaktor_rect_trunc(r);
|
||||
reaktor_edge_round(app, cv,
|
||||
nk_rect(r.x - 3.0f, r.y - 3.0f, r.w + 6.0f, r.h + 6.0f),
|
||||
@@ -339,6 +349,7 @@ focus_ring(App *app, struct nk_context *ctx, struct nk_command_buffer *cv)
|
||||
if (in_page) nk_push_scissor(cv, save);
|
||||
}
|
||||
|
||||
/* Popups draw after every window; the ring goes in the overlay, drawn last. */
|
||||
void
|
||||
reaktor_overlay(App *app, struct nk_context *ctx, int ring)
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@ rect_of(float x, float y, float w, float h)
|
||||
return r;
|
||||
}
|
||||
|
||||
/* The direction a box was declared with, read back from onlay's own item. */
|
||||
static unsigned char
|
||||
dir_of(const reaktor_layout *l, lay_id it)
|
||||
{
|
||||
|
||||
+6
-1
@@ -15,6 +15,7 @@ typedef struct pick_col {
|
||||
float w;
|
||||
} pick_col;
|
||||
|
||||
/* One picker is open at a time; its wheels hold the value until it is set. */
|
||||
static struct {
|
||||
const void *owner;
|
||||
pick_col col[PICK_COLS];
|
||||
@@ -73,6 +74,7 @@ pick_days(void)
|
||||
}
|
||||
}
|
||||
|
||||
/* The segments, in the order the language writes a short date. */
|
||||
static int
|
||||
date_order(int *kinds)
|
||||
{
|
||||
@@ -115,7 +117,7 @@ pick_draw_wheels(App *app, struct nk_context *ctx, struct nk_rect body, float ro
|
||||
unsigned id;
|
||||
|
||||
reaktor_hot(app, col, REAKTOR_CURSOR_POINTER, 1);
|
||||
if (!g_pick.fresh && hot_hover(ctx, col) &&
|
||||
if (!g_pick.fresh && nk_input_is_mouse_hovering_rect(&ctx->input, col) &&
|
||||
ctx->input.mouse.scroll_delta.y != 0.0f) {
|
||||
c->at = pick_wrap(c, c->at - (ctx->input.mouse.scroll_delta.y > 0.0f ? 1 : -1));
|
||||
g_pick.key = k;
|
||||
@@ -174,6 +176,7 @@ pick_key(App *app)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 1 when set, -1 when dismissed, 0 while open. */
|
||||
static int
|
||||
pick_flyout(App *app, struct nk_context *ctx, float row)
|
||||
{
|
||||
@@ -236,6 +239,7 @@ pick_flyout(App *app, struct nk_context *ctx, float row)
|
||||
return done;
|
||||
}
|
||||
|
||||
/* The field is an input like any other: the value as the language writes it, or a hint. */
|
||||
static int
|
||||
pick_field(const void *owner, const char *name, const reaktor_box *spec_box,
|
||||
pick_col *cols, int n, const char *hint, const char *value)
|
||||
@@ -252,6 +256,7 @@ pick_field(const void *owner, const char *name, const reaktor_box *spec_box,
|
||||
unsigned id;
|
||||
int k, v, done = 0;
|
||||
|
||||
/* The padding a text field resolves, so the hint sits where a field's does. */
|
||||
sf = push_edit_style(ctx, &in, NULL);
|
||||
reaktor_style_frame_pop(ctx, sf);
|
||||
decl_box_from_style(&box, NULL, "input.type-text", "input", 0.0f, 7.0f);
|
||||
|
||||
+66
-96
@@ -39,16 +39,6 @@ hot_push(App *app, struct nk_rect r, int cursor, int repaint)
|
||||
hot_push_ex(app, r, cursor, repaint, 0, 0);
|
||||
}
|
||||
|
||||
int
|
||||
hot_hover(const struct nk_context *ctx, struct nk_rect r)
|
||||
{
|
||||
const struct nk_window *w = ctx->current;
|
||||
|
||||
if (w && w->widgets_disabled) return 0;
|
||||
return nk_input_is_mouse_hovering_rect(&ctx->input, r) &&
|
||||
(!w || !w->layout || nk_input_is_mouse_hovering_rect(&ctx->input, w->layout->clip));
|
||||
}
|
||||
|
||||
static struct {
|
||||
int armed;
|
||||
struct nk_rect b;
|
||||
@@ -58,7 +48,6 @@ static struct {
|
||||
float *border, border_was;
|
||||
int edges;
|
||||
struct nk_color edge_hover, edge_active;
|
||||
struct { struct nk_color from, to; int axis; } ramp[3];
|
||||
} g_chrome;
|
||||
|
||||
static void
|
||||
@@ -87,7 +76,6 @@ reaktor_chrome_disarm(void)
|
||||
{
|
||||
g_chrome.armed = 0;
|
||||
g_chrome.edges = 0;
|
||||
g_chrome.ramp[0].axis = g_chrome.ramp[1].axis = g_chrome.ramp[2].axis = 0;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -109,25 +97,19 @@ button_chrome_begin(struct nk_command_buffer *out, nk_handle user)
|
||||
struct nk_style_button *st = &app->ctx->style.button;
|
||||
nk_flags state = app->ctx->last_widget_state;
|
||||
struct nk_color col, edge = st->border_color;
|
||||
float k = st->color_factor_background;
|
||||
int at = (state & NK_WIDGET_STATE_HOVER) ? 1 : (state & NK_WIDGET_STATE_ACTIVED) ? 2 : 0;
|
||||
|
||||
if (!g_chrome.armed ||
|
||||
!chrome_take(at == 1 ? &st->hover : at == 2 ? &st->active : &st->normal, &col))
|
||||
!chrome_take((state & NK_WIDGET_STATE_HOVER) ? &st->hover
|
||||
: (state & NK_WIDGET_STATE_ACTIVED) ? &st->active
|
||||
: &st->normal, &col))
|
||||
return;
|
||||
if (g_chrome.edges)
|
||||
edge = at == 1 ? g_chrome.edge_hover : at == 2 ? g_chrome.edge_active : edge;
|
||||
if (g_chrome.ramp[at].axis) {
|
||||
reaktor_fill_gradient(app, out, g_chrome.b, st->rounding,
|
||||
nk_rgb_factor(g_chrome.ramp[at].from, k),
|
||||
nk_rgb_factor(g_chrome.ramp[at].to, k),
|
||||
g_chrome.ramp[at].axis);
|
||||
reaktor_edge_round(app, out, g_chrome.b, st->rounding, st->border,
|
||||
nk_rgb_factor(edge, k));
|
||||
} else {
|
||||
reaktor_paint_surface(app, out, g_chrome.b, &(reaktor_surface){
|
||||
nk_rgb_factor(col, k), nk_rgb_factor(edge, k), st->border, st->rounding });
|
||||
}
|
||||
edge = (state & NK_WIDGET_STATE_HOVER) ? g_chrome.edge_hover
|
||||
: (state & NK_WIDGET_STATE_ACTIVED) ? g_chrome.edge_active : edge;
|
||||
reaktor_paint_surface(app, out, g_chrome.b, &(reaktor_surface){
|
||||
nk_rgb_factor(col, st->color_factor_background),
|
||||
nk_rgb_factor(edge, st->color_factor_background),
|
||||
st->border, st->rounding });
|
||||
g_chrome.border = &st->border;
|
||||
g_chrome.border_was = st->border;
|
||||
st->border = 0.0f;
|
||||
@@ -199,28 +181,6 @@ push_button_look(App *app, struct nk_context *ctx, const reaktor_button_look *k)
|
||||
g_chrome.edges = 1;
|
||||
g_chrome.edge_hover = nk_rgba_bv(hov->matched ? hov->border_col : s.border_col);
|
||||
g_chrome.edge_active = nk_rgba_bv(act->matched ? act->border_col : s.border_col);
|
||||
{
|
||||
const reaktor_style *by[3];
|
||||
int i;
|
||||
|
||||
by[0] = &s;
|
||||
by[1] = hov->matched ? hov : &s;
|
||||
by[2] = act->matched ? act : by[1];
|
||||
for (i = 0; i < 3; i++) {
|
||||
unsigned char from[4], to[4];
|
||||
|
||||
g_chrome.ramp[i].axis = by[i]->gradient;
|
||||
if (!by[i]->gradient) continue;
|
||||
memcpy(from, by[i]->gradient_from, 4);
|
||||
memcpy(to, by[i]->gradient_to, 4);
|
||||
if (i == 2 && !act->matched) {
|
||||
reaktor_style_darken(from, 0.10f);
|
||||
reaktor_style_darken(to, 0.10f);
|
||||
}
|
||||
g_chrome.ramp[i].from = nk_rgba_bv(from);
|
||||
g_chrome.ramp[i].to = nk_rgba_bv(to);
|
||||
}
|
||||
}
|
||||
|
||||
nk_style_push_float(ctx, &ctx->style.button.rounding, s.rounding);
|
||||
nk_style_push_float(ctx, &ctx->style.button.border, s.border);
|
||||
@@ -310,29 +270,18 @@ reaktor_css_button_look(App *app, struct nk_context *ctx,
|
||||
return clicked;
|
||||
}
|
||||
|
||||
static float
|
||||
linear(unsigned char c)
|
||||
{
|
||||
static float table[256];
|
||||
static int filled;
|
||||
|
||||
if (!filled) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
float v = i / 255.0f;
|
||||
table[i] = v <= 0.04045f ? v / 12.92f
|
||||
: powf((v + 0.055f) / 1.055f, 2.4f);
|
||||
}
|
||||
filled = 1;
|
||||
}
|
||||
return table[c];
|
||||
}
|
||||
|
||||
static float
|
||||
luminance(const unsigned char c[4])
|
||||
{
|
||||
return 0.2126f * linear(c[0]) + 0.7152f * linear(c[1]) + 0.0722f * linear(c[2]);
|
||||
float ch[3];
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
float v = c[i] / 255.0f;
|
||||
ch[i] = v <= 0.04045f ? v / 12.92f
|
||||
: powf((v + 0.055f) / 1.055f, 2.4f);
|
||||
}
|
||||
return 0.2126f * ch[0] + 0.7152f * ch[1] + 0.0722f * ch[2];
|
||||
}
|
||||
|
||||
static float
|
||||
@@ -374,6 +323,7 @@ reaktor_visible(struct nk_color want, struct nk_color behind,
|
||||
return contrast_ratio(a, b) < 1.12f ? fallback : want;
|
||||
}
|
||||
|
||||
/* What the sheet's rule puts between a button's edge and its label. */
|
||||
static float
|
||||
button_inset(struct nk_context *ctx, const reaktor_style *st, int glyph)
|
||||
{
|
||||
@@ -381,16 +331,20 @@ button_inset(struct nk_context *ctx, const reaktor_style *st, int glyph)
|
||||
float pad = st->matched ? st->pad_x : nb->padding.x;
|
||||
float edge = st->matched ? st->border : nb->border + nb->rounding;
|
||||
|
||||
/* An icon tightens the sides, as GTK's image-text buttons are. */
|
||||
return (glyph ? pad * 0.5f : pad) + edge;
|
||||
}
|
||||
|
||||
/* A button's icon: "button .icon" in the sheet sizes it and spaces it from
|
||||
the label; unstyled, it follows the font. ink_l and ink_r are where its
|
||||
drawn pixels start and end, since an Ionicon sits anywhere in its square. */
|
||||
typedef struct button_glyph {
|
||||
struct nk_image im;
|
||||
float px, gap, ink_l, ink_r;
|
||||
} button_glyph;
|
||||
|
||||
static void
|
||||
glyph_of(App *app, struct nk_context *ctx, const char *selector, const char *ionicon,
|
||||
glyph_of(App *app, struct nk_context *ctx, const char *selector, const char *icon_src,
|
||||
button_glyph *g)
|
||||
{
|
||||
reaktor_style st;
|
||||
@@ -402,10 +356,10 @@ glyph_of(App *app, struct nk_context *ctx, const char *selector, const char *ion
|
||||
: SDL_roundf(ctx->style.font->height * 1.125f);
|
||||
g->gap = st.matched && st.margin[REAKTOR_SIDE_RIGHT] > 0.0f
|
||||
? st.margin[REAKTOR_SIDE_RIGHT] : REAKTOR_BUTTON_GAP;
|
||||
g->im = ionicon_ink(app, ionicon, nk_rgb(255, 255, 255), -1.0f, (int)g->px,
|
||||
&g->ink_l, &g->ink_r);
|
||||
g->im = icon_ink(app, icon_src, (int)g->px, &g->ink_l, &g->ink_r);
|
||||
}
|
||||
|
||||
/* The icon and label side by side, and the button that holds them. */
|
||||
static float
|
||||
group_w(const struct nk_user_font *f, const button_glyph *g, const char *label)
|
||||
{
|
||||
@@ -426,12 +380,12 @@ content_w(struct nk_context *ctx, const char *selector, float group, int glyph)
|
||||
|
||||
float
|
||||
css_button_content_w(App *app, struct nk_context *ctx, const char *selector,
|
||||
const struct nk_user_font *f, const char *ionicon, const char *label)
|
||||
const struct nk_user_font *f, const char *icon_src, const char *label)
|
||||
{
|
||||
button_glyph g;
|
||||
|
||||
if (ionicon) glyph_of(app, ctx, selector, ionicon, &g);
|
||||
return content_w(ctx, selector, group_w(f, ionicon ? &g : NULL, label), ionicon != NULL);
|
||||
if (icon_src) glyph_of(app, ctx, selector, icon_src, &g);
|
||||
return content_w(ctx, selector, group_w(f, icon_src ? &g : NULL, label), icon_src != NULL);
|
||||
}
|
||||
|
||||
static struct nk_color
|
||||
@@ -446,6 +400,9 @@ state_ink(struct nk_context *ctx)
|
||||
return nk_rgb_factor(ink, bs->color_factor_text);
|
||||
}
|
||||
|
||||
/* The glyph and label centred as one, as GTK and Qt set them: the label is
|
||||
set flush right of a padding that leaves the pair in the middle. 0 when
|
||||
the button is too narrow for both, and the label stands alone. */
|
||||
static int
|
||||
group_push(struct nk_context *ctx, const char *selector, struct nk_rect b,
|
||||
const button_glyph *g, const char *label, struct nk_rect *at)
|
||||
@@ -464,16 +421,18 @@ group_push(struct nk_context *ctx, const char *selector, struct nk_rect b,
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Presses the button, with its icon beside the label when there is room,
|
||||
in the label's color for the button's state. */
|
||||
static int
|
||||
group_press(App *app, struct nk_context *ctx, const char *selector, const char *ionicon,
|
||||
group_press(App *app, struct nk_context *ctx, const char *selector, const char *icon_src,
|
||||
const char *label)
|
||||
{
|
||||
button_glyph g;
|
||||
struct nk_rect at;
|
||||
int drawn = 0, clicked;
|
||||
|
||||
if (ionicon) {
|
||||
glyph_of(app, ctx, selector, ionicon, &g);
|
||||
if (icon_src) {
|
||||
glyph_of(app, ctx, selector, icon_src, &g);
|
||||
drawn = group_push(ctx, selector, nk_widget_bounds(ctx), &g, label, &at);
|
||||
}
|
||||
reaktor_button_arm(ctx);
|
||||
@@ -489,7 +448,7 @@ group_press(App *app, struct nk_context *ctx, const char *selector, const char *
|
||||
|
||||
int
|
||||
css_button_accent(App *app, struct nk_context *ctx, const char *selector,
|
||||
const char *ionicon, const char *label)
|
||||
const char *icon_src, const char *label)
|
||||
{
|
||||
reaktor_style_frame f, a = { 0, 0, 0, 0, 0 };
|
||||
unsigned char c[4], hov[4];
|
||||
@@ -520,7 +479,7 @@ css_button_accent(App *app, struct nk_context *ctx, const char *selector,
|
||||
a.colors = 4;
|
||||
g_chrome.edge_hover = g_chrome.edge_active = app->accent;
|
||||
|
||||
clicked = group_press(app, ctx, selector, ionicon, label);
|
||||
clicked = group_press(app, ctx, selector, icon_src, label);
|
||||
reaktor_style_frame_pop(ctx, a);
|
||||
reaktor_style_frame_pop(ctx, f);
|
||||
return clicked;
|
||||
@@ -528,30 +487,22 @@ css_button_accent(App *app, struct nk_context *ctx, const char *selector,
|
||||
|
||||
int
|
||||
css_button_icon(App *app, struct nk_context *ctx, const char *selector,
|
||||
const char *ionicon, const char *label)
|
||||
const char *icon_src, const char *label)
|
||||
{
|
||||
reaktor_button_look k;
|
||||
reaktor_style_frame f;
|
||||
int clicked;
|
||||
|
||||
hot_push(app, nk_widget_bounds(ctx), REAKTOR_CURSOR_POINTER, 1);
|
||||
reaktor_note_here(app, ctx, REAKTOR_A11Y_BUTTON, label, 0);
|
||||
f = push_button_style(app, ctx, selector);
|
||||
clicked = group_press(app, ctx, selector, ionicon, label);
|
||||
reaktor_button_look_of(selector, &k);
|
||||
f = push_button_look(app, ctx, &k);
|
||||
clicked = group_press(app, ctx, selector, icon_src, label);
|
||||
reaktor_style_frame_pop(ctx, f);
|
||||
return clicked;
|
||||
}
|
||||
|
||||
static int
|
||||
press_blank(struct nk_context *ctx)
|
||||
{
|
||||
int clicked;
|
||||
|
||||
reaktor_button_arm(ctx);
|
||||
clicked = nk_button_text(ctx, "", 0);
|
||||
reaktor_chrome_disarm();
|
||||
return clicked;
|
||||
}
|
||||
|
||||
/* The sheet's button with nothing in it; the caller paints the inside. */
|
||||
int
|
||||
reaktor_css_button_custom(App *app, struct nk_context *ctx, const char *sel,
|
||||
const char *name, reaktor_button_paint paint, void *user)
|
||||
@@ -568,7 +519,9 @@ reaktor_css_button_custom(App *app, struct nk_context *ctx, const char *sel,
|
||||
reaktor_button_look_of(sel, &k);
|
||||
in_x = button_inset(ctx, &k.s, 0);
|
||||
f = push_button_look(app, ctx, &k);
|
||||
clicked = press_blank(ctx);
|
||||
reaktor_button_arm(ctx);
|
||||
clicked = nk_button_text(ctx, "", 0);
|
||||
reaktor_chrome_disarm();
|
||||
if (paint) {
|
||||
float in_y = k.s.matched ? k.s.pad_y : ctx->style.button.padding.y;
|
||||
struct nk_rect c = nk_rect(b.x + in_x, b.y + in_y, b.w - 2.0f * in_x, b.h - 2.0f * in_y);
|
||||
@@ -581,6 +534,17 @@ reaktor_css_button_custom(App *app, struct nk_context *ctx, const char *sel,
|
||||
return clicked;
|
||||
}
|
||||
|
||||
static int
|
||||
press_blank(struct nk_context *ctx)
|
||||
{
|
||||
int clicked;
|
||||
|
||||
reaktor_button_arm(ctx);
|
||||
clicked = nk_button_text(ctx, "", 0);
|
||||
reaktor_chrome_disarm();
|
||||
return clicked;
|
||||
}
|
||||
|
||||
static void
|
||||
image_centered(struct nk_context *ctx, struct nk_rect b, struct nk_image im, float px)
|
||||
{
|
||||
@@ -590,6 +554,7 @@ image_centered(struct nk_context *ctx, struct nk_rect b, struct nk_image im, flo
|
||||
&im, nk_rgb(255, 255, 255));
|
||||
}
|
||||
|
||||
/* An icon alone: no fill or edge until the pointer is over it, then the sheet's hover. */
|
||||
int
|
||||
reaktor_css_button_flat(App *app, struct nk_context *ctx, const char *icon,
|
||||
const char *name, int accent)
|
||||
@@ -708,6 +673,7 @@ reaktor_edit_edge(App *app, struct nk_context *ctx, struct nk_rect b,
|
||||
struct nk_color fill = nk_rgba_bv(s->bg);
|
||||
|
||||
if (!s->matched) return;
|
||||
/* A sheet may fill a field like the card it sits on; it then takes the page's. */
|
||||
if (on.w > b.w && b.x >= on.x && b.y >= on.y &&
|
||||
b.x + b.w <= on.x + on.w && b.y + b.h <= on.y + on.h &&
|
||||
SDL_abs(fill.r - app->surface.r) + SDL_abs(fill.g - app->surface.g) +
|
||||
@@ -739,7 +705,7 @@ draw_hint(struct nk_context *ctx, struct nk_rect bounds, const char *hint,
|
||||
void
|
||||
note_field_rect(App *app, struct nk_context *ctx, struct nk_rect bounds)
|
||||
{
|
||||
if (hot_hover(ctx, bounds)) {
|
||||
if (nk_input_is_mouse_hovering_rect(&ctx->input, bounds)) {
|
||||
app->field_rect = bounds;
|
||||
app->field_rect_valid = 1;
|
||||
}
|
||||
@@ -748,6 +714,7 @@ note_field_rect(App *app, struct nk_context *ctx, struct nk_rect bounds)
|
||||
void
|
||||
note_edit_active(App *app, struct nk_context *ctx, nk_flags state)
|
||||
{
|
||||
/* A held field keeps its caret, not the keys. */
|
||||
if (!(state & NK_EDIT_ACTIVE) || app->layer_held) return;
|
||||
if (app->stop_editing) nk_edit_unfocus(ctx);
|
||||
else app->editing = 1;
|
||||
@@ -762,6 +729,7 @@ note_ime_caret(App *app, struct nk_context *ctx, struct nk_rect bounds,
|
||||
|
||||
if (!(state & NK_EDIT_ACTIVE) || app->layer_held) return;
|
||||
|
||||
/* An empty edit has no text, whatever it says its length is. */
|
||||
if (font && font->width && nk_str_get_const(&edit->string)) {
|
||||
const char *txt = nk_str_get_const(&edit->string);
|
||||
nk_rune unicode;
|
||||
@@ -881,6 +849,7 @@ apply_widget_style(App *app)
|
||||
st->button.userdata = nk_handle_ptr(app);
|
||||
st->button.draw_begin = button_chrome_begin;
|
||||
st->button.draw_end = chrome_end;
|
||||
/* A disabled button is faded, not darkened: see reaktor_button. */
|
||||
st->button.disabled_factor = 1.0f;
|
||||
|
||||
reaktor_style_get("input.type-text", &inp);
|
||||
@@ -1044,6 +1013,7 @@ apply_widget_style(App *app)
|
||||
st->chart.selected_color = focus;
|
||||
st->chart.border = 1.0f;
|
||||
|
||||
/* No track: a scrollbar sits on lists and panels as well as the page. */
|
||||
st->scrollh.normal = i_none;
|
||||
st->scrollh.hover = i_none;
|
||||
st->scrollh.active = i_none;
|
||||
|
||||
+3
-1
@@ -63,6 +63,7 @@ reaktor_toast(App *app, const reaktor_toast_spec *spec)
|
||||
t->icon = copy(spec->icon);
|
||||
t->action = copy(spec->action);
|
||||
ms = spec->timeout_ms;
|
||||
/* Nothing would ever close it. */
|
||||
if (ms <= 0 && spec->no_close && !spec->action) ms = 5000;
|
||||
if (ms > 0) {
|
||||
t->until = SDL_GetTicks() + (Uint64)ms;
|
||||
@@ -148,6 +149,7 @@ reaktor_toasts_draw(App *app, struct nk_context *ctx, int win_w, int win_h,
|
||||
nk_style_item_color(none));
|
||||
nk_style_push_font(ctx, font);
|
||||
|
||||
/* Creating the toasts window takes Nuklear's focus. */
|
||||
keep = nk_window_find(ctx, "reaktor-toasts") ? NULL : ctx->active;
|
||||
hold = blocked ? HOLD_ALL : g_toast_fresh ? HOLD_FRESH : HOLD_NONE;
|
||||
g_toast_fresh = 0;
|
||||
@@ -194,7 +196,7 @@ reaktor_toasts_draw(App *app, struct nk_context *ctx, int win_w, int win_h,
|
||||
}
|
||||
}
|
||||
if (t->action &&
|
||||
css_button(app, ctx, ".toast-button", t->action))
|
||||
reaktor_button_label_as(app, ctx, ".toast-button", t->action))
|
||||
act = first + i;
|
||||
if (!t->spec.no_close &&
|
||||
reaktor_css_button_image(
|
||||
|
||||
+21
-10
@@ -128,6 +128,7 @@ reaktor_tabs(const reaktor_tabs_spec *s)
|
||||
return nav_list(s, 1);
|
||||
}
|
||||
|
||||
/* A tree is a list whose first column is indented, with a chevron on each branch. */
|
||||
typedef struct tree_rows {
|
||||
const reaktor_tree_spec *s;
|
||||
int *node, *depth, *row;
|
||||
@@ -191,14 +192,16 @@ list_follow(const reaktor_list_spec *s, int focused, struct nk_rect area, float
|
||||
return changed;
|
||||
}
|
||||
|
||||
/* Row r's first column in a tree; 1 when the selection should move to t->jump. */
|
||||
static int
|
||||
tree_first(tree_rows *t, int r, const char *label, unsigned id, struct nk_color fg, float pad)
|
||||
tree_first(tree_rows *t, int r, unsigned id, struct nk_color fg, float pad)
|
||||
{
|
||||
struct nk_context *ctx = g_frame_ctx;
|
||||
const struct nk_user_font *f = ctx->style.font;
|
||||
const reaktor_tree_spec *s = t->s;
|
||||
int node = t->node[r], branch = tree_branch(t, node), step, up;
|
||||
struct nk_rect b, chev;
|
||||
const char *label = s->label(node, s->user);
|
||||
const char *icon = s->icon ? s->icon(node, s->user) : NULL;
|
||||
float x;
|
||||
|
||||
@@ -245,6 +248,7 @@ tree_first(tree_rows *t, int r, const char *label, unsigned id, struct nk_color
|
||||
|
||||
static int list_draw(const reaktor_list_spec *s, tree_rows *t);
|
||||
|
||||
/* Rows with .drag start a drag; a list of the same kind shows where it lands. */
|
||||
static float
|
||||
list_drag(const reaktor_list_spec *s, struct nk_rect area, float row_h, int *changed)
|
||||
{
|
||||
@@ -373,6 +377,9 @@ list_draw(const reaktor_list_spec *s, tree_rows *t)
|
||||
even = reaktor_token("--table-bg-alt", odd);
|
||||
head_bg = thead.matched && thead.bg[3] ? reaktor_col(thead.bg)
|
||||
: reaktor_token("--table", g_frame_app->accent);
|
||||
head_bg = reaktor_visible(reaktor_visible(head_bg, reaktor_page_color(g_frame_app),
|
||||
g_frame_app->accent),
|
||||
odd, g_frame_app->accent);
|
||||
|
||||
box = s->box;
|
||||
if (!box.name) box.name = s->name;
|
||||
@@ -404,7 +411,7 @@ list_draw(const reaktor_list_spec *s, tree_rows *t)
|
||||
}
|
||||
}
|
||||
|
||||
body.flags = REAKTOR_LAY_FILL;
|
||||
body.flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y;
|
||||
if (decl_place(REAKTOR_A11Y_NONE, NULL, NULL, 0u, NULL, &body, NULL)) {
|
||||
struct nk_rect area = nk_widget_bounds(g_frame_ctx);
|
||||
int focused = -1;
|
||||
@@ -426,7 +433,6 @@ list_draw(const reaktor_list_spec *s, tree_rows *t)
|
||||
struct nk_color fg = g_frame_ctx->style.text.color;
|
||||
int on = s->selected && *s->selected == r;
|
||||
struct nk_rect row;
|
||||
const char *first = s->cell(r, 0, s->user);
|
||||
unsigned id;
|
||||
|
||||
nk_layout_row(g_frame_ctx, NK_DYNAMIC, row_h, cols, ratio);
|
||||
@@ -436,7 +442,7 @@ list_draw(const reaktor_list_spec *s, tree_rows *t)
|
||||
if (s->selected) reaktor_hot(g_frame_app, row, REAKTOR_CURSOR_DEFAULT, 1);
|
||||
id = reaktor_note(g_frame_app,
|
||||
t ? REAKTOR_A11Y_TREEITEM : REAKTOR_A11Y_LISTITEM,
|
||||
first, NULL,
|
||||
s->cell(r, 0, s->user), NULL,
|
||||
(on ? REAKTOR_A11Y_SELECTED : 0u) |
|
||||
(t && tree_branch(t, t->node[r]) && t->s->open[t->node[r]]
|
||||
? REAKTOR_A11Y_EXPANDED : 0u), row);
|
||||
@@ -444,15 +450,16 @@ list_draw(const reaktor_list_spec *s, tree_rows *t)
|
||||
if (s->selected && on) {
|
||||
nk_fill_rect(cv, row, 0.0f, g_frame_app->accent);
|
||||
fg = reaktor_on(g_frame_app->accent);
|
||||
} else if (s->selected && hot_hover(g_frame_ctx, row)) {
|
||||
} else if (s->selected &&
|
||||
nk_input_is_mouse_hovering_rect(&g_frame_ctx->input, row)) {
|
||||
nk_fill_rect(cv, row, 0.0f,
|
||||
reaktor_token("--background-hover", nk_rgba(128, 128, 128, 60)));
|
||||
}
|
||||
for (c = 0; c < cols; c++) {
|
||||
const char *cell = c ? s->cell(r, c, s->user) : first;
|
||||
const char *cell = s->cell(r, c, s->user);
|
||||
|
||||
if (t && c == 0) {
|
||||
if (tree_first(t, r, cell, id, fg, pad) && s->selected) {
|
||||
if (tree_first(t, r, id, fg, pad) && s->selected) {
|
||||
int k = t->row[t->jump];
|
||||
|
||||
if (k >= 0 && *s->selected != k) {
|
||||
@@ -546,6 +553,7 @@ reaktor_splitter(const reaktor_splitter_spec *s)
|
||||
#define MENU_COLS (MENU_DEPTH + 1)
|
||||
#define MENU_ITEMS 32
|
||||
|
||||
/* The windows that draw a column run after the frame that declared it: they draw a copy. */
|
||||
typedef struct menu_col {
|
||||
const reaktor_menu_entry *items, *src;
|
||||
reaktor_menu_entry copy[MENU_ITEMS];
|
||||
@@ -555,6 +563,7 @@ typedef struct menu_col {
|
||||
float lead;
|
||||
} menu_col;
|
||||
|
||||
/* One menu bar is open at a time; its columns are read by the windows that draw them. */
|
||||
static struct {
|
||||
int open, depth, kcol, kbd, keyed, focused;
|
||||
int path[MENU_DEPTH], hi[MENU_COLS], win[MENU_COLS];
|
||||
@@ -720,6 +729,7 @@ menu_draw_entry(const reaktor_menu_entry *e, struct nk_rect b, float lead, int l
|
||||
"chevron-forward-outline", fg);
|
||||
}
|
||||
|
||||
/* Draws column k with its top left at `at`, in whichever window holds it. */
|
||||
static void
|
||||
menu_draw_col(int k, struct nk_vec2 at)
|
||||
{
|
||||
@@ -763,7 +773,8 @@ menu_draw_col(int k, struct nk_vec2 at)
|
||||
if (e->keys) reaktor_note_keys(app, id, e->keys);
|
||||
if (!e->disabled) {
|
||||
reaktor_hot_top(app, slot, 1, 1);
|
||||
if (hot_hover(ctx, slot) && nk_input_is_mouse_moved(&ctx->input) &&
|
||||
if (nk_input_is_mouse_hovering_rect(&ctx->input, slot) &&
|
||||
nk_input_is_mouse_moved(&ctx->input) &&
|
||||
(g_menu.hi[k] != i || g_menu.kcol != k || g_menu.depth != k + !!e->items)) {
|
||||
g_menu.hi[k] = i;
|
||||
g_menu.kcol = k;
|
||||
@@ -773,7 +784,7 @@ menu_draw_col(int k, struct nk_vec2 at)
|
||||
}
|
||||
}
|
||||
if (nk_input_is_mouse_released(&ctx->input, NK_BUTTON_LEFT) &&
|
||||
hot_hover(ctx, slot) && !e->disabled && !e->items) {
|
||||
nk_input_is_mouse_hovering_rect(&ctx->input, slot) && !e->disabled && !e->items) {
|
||||
g_menu.picked_k = k;
|
||||
g_menu.picked_i = i;
|
||||
menu_changed();
|
||||
@@ -977,7 +988,7 @@ reaktor_menubar(const reaktor_menubar_spec *s)
|
||||
reaktor_hot(app, r, REAKTOR_CURSOR_POINTER, 1);
|
||||
if (g_menu.open == m) { st.normal = st.active; st.text_normal = st.text_active; }
|
||||
nk_button_text_styled(ctx, &st, label, (int)strlen(label));
|
||||
if (hot_hover(ctx, r)) {
|
||||
if (nk_input_is_mouse_hovering_rect(&ctx->input, r)) {
|
||||
on_title = 1;
|
||||
if (g_menu.open >= 0 && g_menu.open != m && nk_input_is_mouse_moved(&ctx->input))
|
||||
menu_open_at(m, 0);
|
||||
|
||||
+88
-71
@@ -23,26 +23,19 @@ reaktor_font(App *app, int px, int bold)
|
||||
return pick_font(app, px, bold);
|
||||
}
|
||||
|
||||
struct nk_vec2
|
||||
reaktor_item_spacing(struct nk_context *ctx)
|
||||
{
|
||||
return ctx->style.window.spacing;
|
||||
}
|
||||
|
||||
struct nk_color
|
||||
reaktor_text_color(struct nk_context *ctx)
|
||||
{
|
||||
return ctx->style.text.color;
|
||||
}
|
||||
|
||||
const struct nk_user_font *
|
||||
reaktor_current_font(struct nk_context *ctx)
|
||||
{
|
||||
return ctx->style.font;
|
||||
}
|
||||
|
||||
#define ICON_HAIRLINE_BELOW 20
|
||||
|
||||
const char *
|
||||
reaktor_ionicon_src(char out[192], const char *name, const char *hex, float sw)
|
||||
{
|
||||
if (sw < 0.0f)
|
||||
SDL_snprintf(out, 192, "external/ionicons/src/svg/%s.svg?stroke=%s", name, hex);
|
||||
else
|
||||
SDL_snprintf(out, 192, "external/ionicons/src/svg/%s.svg?stroke=%s&sw=%.2f",
|
||||
name, hex, (double)sw);
|
||||
return out;
|
||||
}
|
||||
|
||||
static void
|
||||
push_clear(struct nk_context *ctx, struct nk_style_item *const *items, int n,
|
||||
struct nk_style_item clear)
|
||||
@@ -59,23 +52,31 @@ pop_items(struct nk_context *ctx, int n)
|
||||
struct nk_image
|
||||
reaktor_ionicon(App *app, const char *name, int px)
|
||||
{
|
||||
return ionicon_over(app, name, app->icon_col,
|
||||
px < ICON_HAIRLINE_BELOW ? GLYPH_STROKE : -1.0f, px, 2.0f);
|
||||
char src[192];
|
||||
|
||||
return icon(app, reaktor_ionicon_src(src, name, app->icon_hex,
|
||||
px < ICON_HAIRLINE_BELOW ? GLYPH_STROKE : -1.0f), px);
|
||||
}
|
||||
|
||||
struct nk_image
|
||||
reaktor_ionicon_exact(App *app, const char *name, int px,
|
||||
struct nk_color stroke, float sw)
|
||||
{
|
||||
char hex[8], src[192];
|
||||
|
||||
if (sw <= 0.0f) sw = px < ICON_HAIRLINE_BELOW ? GLYPH_STROKE : 1.0f;
|
||||
return ionicon_over(app, name, stroke, sw, px, 1.0f);
|
||||
reaktor_hex(stroke, hex);
|
||||
return icon_over(app, reaktor_ionicon_src(src, name, hex, sw), px, 1.0f);
|
||||
}
|
||||
|
||||
struct nk_image
|
||||
reaktor_ionicon_col(App *app, const char *name, int px, struct nk_color stroke)
|
||||
{
|
||||
return ionicon_over(app, name, stroke,
|
||||
px < ICON_HAIRLINE_BELOW ? GLYPH_STROKE : 1.0f, px, 2.0f);
|
||||
char hex[8], src[192];
|
||||
|
||||
reaktor_hex(stroke, hex);
|
||||
return icon(app, reaktor_ionicon_src(src, name, hex,
|
||||
px < ICON_HAIRLINE_BELOW ? GLYPH_STROKE : 1.0f), px);
|
||||
}
|
||||
|
||||
struct nk_color
|
||||
@@ -205,19 +206,12 @@ shaded(struct nk_color c, float amount)
|
||||
void
|
||||
reaktor_slider_bar(App *app, struct nk_context *ctx, unsigned id, float *val,
|
||||
float lo, float hi, float step)
|
||||
{
|
||||
reaktor_slider_ramp(app, ctx, id, val, lo, hi, step, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_slider_ramp(App *app, struct nk_context *ctx, unsigned id, float *val,
|
||||
float lo, float hi, float step, const reaktor_style *fill)
|
||||
{
|
||||
const struct nk_style_slider *st = &ctx->style.slider;
|
||||
struct nk_style_item clear = nk_style_item_color(nk_rgba(0, 0, 0, 0));
|
||||
struct nk_command_buffer *cv = nk_window_get_canvas(ctx);
|
||||
struct nk_rect b = reaktor_rect_trunc(nk_widget_bounds(ctx));
|
||||
int hot = hot_hover(ctx, b);
|
||||
int hot = nk_input_is_mouse_hovering_rect(&ctx->input, b);
|
||||
const struct nk_style_item *ci = hot ? &st->cursor_hover
|
||||
: &st->cursor_normal;
|
||||
struct nk_color track = hot ? st->bar_hover : st->bar_normal;
|
||||
@@ -269,10 +263,7 @@ reaktor_slider_ramp(App *app, struct nk_context *ctx, unsigned id, float *val,
|
||||
st->cursor_size.x, st->cursor_size.y);
|
||||
|
||||
reaktor_fill_round(app, cv, bar, cap, track);
|
||||
if (fl.w >= 1.0f) {
|
||||
if (fill && fill->gradient) reaktor_fill_style(app, cv, fl, cap, fill);
|
||||
else reaktor_fill_round(app, cv, fl, cap, filled);
|
||||
}
|
||||
if (fl.w >= 1.0f) reaktor_fill_round(app, cv, fl, cap, filled);
|
||||
reaktor_glyph_at(app, ctx, kn, REAKTOR_DISC_ROUND, knob,
|
||||
(int)(st->cursor_size.x < st->cursor_size.y ? st->cursor_size.x
|
||||
: st->cursor_size.y),
|
||||
@@ -281,11 +272,11 @@ reaktor_slider_ramp(App *app, struct nk_context *ctx, unsigned id, float *val,
|
||||
|
||||
void
|
||||
reaktor_slider_bar_int(App *app, struct nk_context *ctx, unsigned id, int *val,
|
||||
int lo, int hi, int step, const reaktor_style *fill)
|
||||
int lo, int hi, int step)
|
||||
{
|
||||
float f = (float)*val;
|
||||
|
||||
reaktor_slider_ramp(app, ctx, id, &f, (float)lo, (float)hi, (float)step, fill);
|
||||
reaktor_slider_bar(app, ctx, id, &f, (float)lo, (float)hi, (float)step);
|
||||
*val = (int)(f + (f < 0.0f ? -0.5f : 0.5f));
|
||||
}
|
||||
|
||||
@@ -301,7 +292,7 @@ reaktor_progress_bar(App *app, struct nk_context *ctx, nk_size *cur, nk_size max
|
||||
st->padding.y + st->border);
|
||||
struct nk_rect fill = nk_rect(b.x + pad.x, b.y + pad.y,
|
||||
b.w - 2.0f * pad.x, b.h - 2.0f * pad.y);
|
||||
int hot = hot_hover(ctx, b);
|
||||
int hot = nk_input_is_mouse_hovering_rect(&ctx->input, b);
|
||||
struct nk_style_item track_it = hot ? st->hover : st->normal;
|
||||
struct nk_style_item fill_it = hot ? st->cursor_hover : st->cursor_normal;
|
||||
float track_r = st->rounding, r;
|
||||
@@ -400,11 +391,11 @@ reaktor_chevron_at(App *app, struct nk_context *ctx, struct nk_rect slot,
|
||||
}
|
||||
|
||||
static void
|
||||
stepper_wash(App *app, struct nk_context *ctx, struct nk_rect sq, int live)
|
||||
stepper_wash(App *app, struct nk_context *ctx, struct nk_rect sq)
|
||||
{
|
||||
struct nk_color wash;
|
||||
|
||||
if (!live || !hot_hover(ctx, sq)) return;
|
||||
if (!nk_input_is_mouse_hovering_rect(&ctx->input, sq)) return;
|
||||
wash = reaktor_token("--background-hover", ctx->style.property.hover.type
|
||||
== NK_STYLE_ITEM_COLOR
|
||||
? ctx->style.property.hover.data.color
|
||||
@@ -412,6 +403,7 @@ stepper_wash(App *app, struct nk_context *ctx, struct nk_rect sq, int live)
|
||||
reaktor_fill_round(app, nk_window_get_canvas(ctx), sq, sq.w * 0.5f, wash);
|
||||
}
|
||||
|
||||
/* How far below a centered line's middle its capitals' middle lies. */
|
||||
static float
|
||||
reaktor_cap_offset(const struct nk_user_font *f)
|
||||
{
|
||||
@@ -424,7 +416,7 @@ reaktor_cap_offset(const struct nk_user_font *f)
|
||||
|
||||
void
|
||||
reaktor_property_chrome(App *app, struct nk_context *ctx, struct nk_rect b,
|
||||
struct nk_rect *steps, int live)
|
||||
struct nk_rect *steps)
|
||||
{
|
||||
const struct nk_style_property *st = &ctx->style.property;
|
||||
float h = ctx->style.font->height;
|
||||
@@ -436,44 +428,31 @@ reaktor_property_chrome(App *app, struct nk_context *ctx, struct nk_rect b,
|
||||
reaktor_cap_offset(ctx->style.font) + 0.5f);
|
||||
r.x = b.x + b.w - (h + st->padding.x);
|
||||
r.y = l.y;
|
||||
hot_push(app, b, 0, 1);
|
||||
hot_push(app, l, 0, 1);
|
||||
hot_push(app, r, 0, 1);
|
||||
stepper_wash(app, ctx, l, live);
|
||||
stepper_wash(app, ctx, r, live);
|
||||
stepper_wash(app, ctx, l);
|
||||
stepper_wash(app, ctx, r);
|
||||
reaktor_chevron_at(app, ctx, l, "chevron-back-outline", st->dec_button.text_normal);
|
||||
reaktor_chevron_at(app, ctx, r, "chevron-forward-outline", st->inc_button.text_normal);
|
||||
if (steps) { steps[0] = l; steps[1] = r; }
|
||||
}
|
||||
|
||||
/* Nuklear's property takes no input in a read-only window. */
|
||||
int
|
||||
reaktor_property_live(struct nk_context *ctx)
|
||||
{
|
||||
return !(ctx->current->layout->flags & NK_WINDOW_ROM);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_property_push(struct nk_context *ctx, struct nk_rect b, int live)
|
||||
reaktor_property_push(struct nk_context *ctx)
|
||||
{
|
||||
struct nk_style_property *st = &ctx->style.property;
|
||||
struct nk_style_item clear = nk_style_item_color(nk_rgba(0, 0, 0, 0));
|
||||
int lit = live && hot_hover(ctx, b);
|
||||
|
||||
push_clear(ctx, (struct nk_style_item *[]){
|
||||
&st->dec_button.hover,
|
||||
&st->dec_button.active,
|
||||
&st->inc_button.hover,
|
||||
&st->inc_button.active }, 4, clear);
|
||||
nk_style_push_style_item(ctx, &st->normal, lit ? st->hover : st->normal);
|
||||
nk_style_push_color(ctx, &st->label_normal, lit ? st->label_hover : st->label_normal);
|
||||
&ctx->style.property.dec_button.hover,
|
||||
&ctx->style.property.dec_button.active,
|
||||
&ctx->style.property.inc_button.hover,
|
||||
&ctx->style.property.inc_button.active }, 4, clear);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_property_pop(struct nk_context *ctx)
|
||||
{
|
||||
nk_style_pop_color(ctx);
|
||||
pop_items(ctx, 5);
|
||||
pop_items(ctx, 4);
|
||||
}
|
||||
|
||||
#define COMBO_MARGIN 12.0f
|
||||
@@ -517,18 +496,36 @@ reaktor_button_label(App *app, struct nk_context *ctx, const char *label)
|
||||
return css_button(app, ctx, "button", label);
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_button_label_as(App *app, struct nk_context *ctx, const char *sel,
|
||||
const char *label)
|
||||
{
|
||||
return css_button(app, ctx, sel, label);
|
||||
}
|
||||
|
||||
/* A button's icon is drawn white and tinted with its label's color. */
|
||||
const char *
|
||||
reaktor_button_src(char out[192], const char *ionicon)
|
||||
{
|
||||
return ionicon ? reaktor_ionicon_src(out, ionicon, "#ffffff", -1.0f) : NULL;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_button_accent_as(App *app, struct nk_context *ctx, const char *sel,
|
||||
const char *ionicon, const char *label)
|
||||
{
|
||||
return css_button_accent(app, ctx, sel, ionicon, label);
|
||||
char src[192];
|
||||
|
||||
return css_button_accent(app, ctx, sel, reaktor_button_src(src, ionicon), label);
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_button_icon_as(App *app, struct nk_context *ctx, const char *sel,
|
||||
const char *ionicon, const char *label)
|
||||
{
|
||||
return css_button_icon(app, ctx, sel, ionicon, label);
|
||||
char src[192];
|
||||
|
||||
return css_button_icon(app, ctx, sel, reaktor_button_src(src, ionicon), label);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -548,8 +545,10 @@ float
|
||||
reaktor_button_width(App *app, struct nk_context *ctx, const char *ionicon,
|
||||
const char *label)
|
||||
{
|
||||
char src[192];
|
||||
|
||||
return SDL_ceilf(css_button_content_w(app, ctx, "button", ctx->style.font,
|
||||
ionicon, label));
|
||||
reaktor_button_src(src, ionicon), label));
|
||||
}
|
||||
|
||||
int
|
||||
@@ -580,12 +579,17 @@ reaktor_unfit_label(struct nk_context *ctx, int fitted)
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_css_button_color(App *app, struct nk_context *ctx, struct nk_color fill)
|
||||
reaktor_css_button_color(App *app, struct nk_context *ctx, const char *name,
|
||||
struct nk_color fill)
|
||||
{
|
||||
struct nk_rect b = nk_widget_bounds(ctx);
|
||||
unsigned char hov[4];
|
||||
char hex[10];
|
||||
int clicked;
|
||||
|
||||
hot_push(app, nk_widget_bounds(ctx), REAKTOR_CURSOR_POINTER, 1);
|
||||
hot_push(app, b, REAKTOR_CURSOR_POINTER, 1);
|
||||
reaktor_hex(fill, hex);
|
||||
reaktor_note(app, REAKTOR_A11Y_BUTTON, name, hex, 0, b);
|
||||
|
||||
hov[0] = fill.r; hov[1] = fill.g; hov[2] = fill.b; hov[3] = fill.a;
|
||||
reaktor_style_darken(hov, 0.12f);
|
||||
@@ -712,6 +716,7 @@ field_edit(App *app, struct nk_context *ctx, nk_flags flags, char *buf,
|
||||
undo_drop(u, 0);
|
||||
held = undo_keep(u, buf, *len);
|
||||
}
|
||||
/* After the click that focused the field, which would move the caret. */
|
||||
if (win->edit.active && win->edit.seq == win->edit.name &&
|
||||
app->field_pick.buf == buf && app->field_pick.asked &&
|
||||
app->key_click == KEY_CLICK_NONE) {
|
||||
@@ -782,6 +787,7 @@ reaktor_field_text_as(App *app, struct nk_context *ctx, const char *sel,
|
||||
if (pad_x > 0.0f) ctx->style.edit.padding.x = pad_x;
|
||||
if (pad_y > 0.0f) ctx->style.edit.padding.y = pad_y;
|
||||
hint_pad = ctx->style.edit.padding;
|
||||
/* One byte short, so the value is always there to be read as a string. */
|
||||
state = field_edit(app, ctx, flags, buf, len, cap > 0 ? cap - 1 : 0,
|
||||
filter);
|
||||
if (cap > 0) buf[*len] = '\0';
|
||||
@@ -795,6 +801,7 @@ reaktor_field_text_as(App *app, struct nk_context *ctx, const char *sel,
|
||||
if (hint && *len == 0) {
|
||||
struct nk_rect at = bounds;
|
||||
|
||||
/* Where the first line would be: a box's sits at the top. */
|
||||
if (flags & NK_EDIT_MULTILINE) {
|
||||
s.pad_x = hint_pad.x;
|
||||
at.h = 2.0f * hint_pad.y + ctx->style.font->height;
|
||||
@@ -1007,7 +1014,14 @@ unsigned
|
||||
reaktor_note_here(App *app, struct nk_context *ctx, unsigned char role,
|
||||
const char *name, unsigned state)
|
||||
{
|
||||
return reaktor_note(app, role, name, NULL, state, nk_widget_bounds(ctx));
|
||||
struct nk_rect b;
|
||||
unsigned id;
|
||||
|
||||
if (g_note_mute) return 0;
|
||||
b = nk_widget_bounds(ctx);
|
||||
id = reaktor_a11y_add(&app->a11y, role, name, NULL, state, b);
|
||||
focus_saw(app, id, b);
|
||||
return id;
|
||||
}
|
||||
|
||||
const struct nk_user_font *
|
||||
@@ -1023,6 +1037,7 @@ reaktor_style_font(App *app, const char *selector, int px, int bold)
|
||||
return reaktor_font(app, px, bold);
|
||||
}
|
||||
|
||||
/* A borderless popup of the current window at r, in screen coordinates. */
|
||||
int
|
||||
reaktor_flyout_begin(struct nk_context *ctx, const char *name, struct nk_rect r)
|
||||
{
|
||||
@@ -1071,6 +1086,7 @@ reaktor_menu_style_push(struct nk_context *ctx)
|
||||
reaktor_popup_rounding());
|
||||
nk_style_push_vec2(ctx, &ctx->style.window.spacing,
|
||||
nk_vec2(4.0f, REAKTOR_MENU_GAP));
|
||||
/* Alpha 0 drops a dynamic popup's own fills; reaktor_menu_edge paints them. */
|
||||
nk_style_push_color(ctx, &ctx->style.window.background, none);
|
||||
nk_style_push_color(ctx, &ctx->style.window.menu_border_color, none);
|
||||
nk_style_push_color(ctx, &ctx->style.window.contextual_border_color,
|
||||
@@ -1120,6 +1136,7 @@ reaktor_popup_open(const struct nk_window *w)
|
||||
return w && w->popup.win && w->popup.active;
|
||||
}
|
||||
|
||||
/* Nuklear keeps ROM until its own popups end. */
|
||||
static void
|
||||
lift_rom(struct nk_window *w)
|
||||
{
|
||||
@@ -1152,6 +1169,7 @@ hold_end(App *app, struct nk_context *ctx)
|
||||
app->layer_held = app->input_held = 0;
|
||||
}
|
||||
|
||||
/* The page is BACKGROUND: activated in place, never raised. */
|
||||
void
|
||||
reaktor_layer_focus(struct nk_context *ctx, struct nk_window *to)
|
||||
{
|
||||
@@ -1171,6 +1189,7 @@ reaktor_layer_begin(App *app, struct nk_context *ctx, const char *name,
|
||||
hold_input(app, ctx, name, hold, held);
|
||||
app->layer = layer;
|
||||
app->layer_trap = trap;
|
||||
/* ROM alone: a click activates the window, and activation lifts it. */
|
||||
return nk_begin(ctx, name, r,
|
||||
flags | (hold == HOLD_ALL ? (nk_flags)NK_WINDOW_NOT_INTERACTIVE : 0));
|
||||
}
|
||||
@@ -1182,6 +1201,7 @@ reaktor_layer_end(App *app, struct nk_context *ctx, int shown)
|
||||
app->focus_layer == app->layer && app->focus_win == ctx->current) {
|
||||
struct nk_command_buffer *cv = nk_window_get_canvas(ctx);
|
||||
|
||||
/* The ring stands outside its widget, past the content region. */
|
||||
nk_push_scissor(cv, nk_window_get_bounds(ctx));
|
||||
focus_ring(app, ctx, cv);
|
||||
}
|
||||
@@ -1296,9 +1316,6 @@ reaktor_diagnostics(App *app, reaktor_diag *out)
|
||||
out->sheets = app->sheets;
|
||||
out->scale = reaktor_scale();
|
||||
out->style_ms = app->style_ms_x100 / 100.0f;
|
||||
out->window_ms = app->window_ms_x100 / 100.0f;
|
||||
out->atlas_ms = app->atlas_ms_x100 / 100.0f;
|
||||
out->first_frame_ms = app->first_ms_x100 / 100.0f;
|
||||
out->frame_gap_ms = app->frame_gap_ms;
|
||||
out->cpu_ms_per_frame = app->cpu_ms_per_frame;
|
||||
out->hover_gap_ms = (int)g_hover_gap_ms;
|
||||
|
||||
+37
-37
@@ -1,15 +1,15 @@
|
||||
# The four programs
|
||||
|
||||
All four share `runtime/` and `core/`; they differ in `samples/` and in the
|
||||
modules they link. The showcase takes every module, notepad settings, popup
|
||||
menus and printing; bench and simple take none, so they show what the runtime
|
||||
costs alone. Without the accessibility module, a screen reader finds nothing
|
||||
in notepad, bench or simple.
|
||||
All four share `runtime/` and `core/`; what differs is `samples/`, and which
|
||||
modules each links. The showcase takes every module. Notepad takes settings, popup
|
||||
menus and printing; bench and simple take none, so they show what the runtime costs by
|
||||
itself. Without the accessibility module, a screen reader finds nothing in
|
||||
notepad, bench or simple.
|
||||
|
||||
| | Lines | For |
|
||||
| --- | --- | --- |
|
||||
| `showcase` | ~4,600 | Every widget and layer, both schemes, three languages, and how far the CSS reaches |
|
||||
| `notepad` | ~410 | A text editor that opens, edits, searches and saves a file of any size |
|
||||
| `showcase` | ~3,300 | Every widget and layer, both schemes, three languages, and how far the CSS reaches |
|
||||
| `notepad` | ~330 | A text editor that opens, edits, searches and saves a file of any size |
|
||||
| `bench` | ~150 | The workload the published figures measure, here and in four other frameworks |
|
||||
| `simple` | ~40 | One button that closes the window |
|
||||
|
||||
@@ -23,28 +23,28 @@ in notepad, bench or simple.
|
||||
## Showcase
|
||||
|
||||
It opens with a two-second splash: the mark, the name, Reaktor's and SDL's
|
||||
versions and what it is built on, fading in one after another. The web build
|
||||
shows its loading screen instead.
|
||||
versions and what it is built on, each fading in after the one before. The
|
||||
web build shows its loading screen instead.
|
||||
|
||||
<p align="center">
|
||||
<img src="../assets/screenshots/showcase.png" alt="The Reaktor showcase under the system's titlebar in the dark scheme: the sidebar of pages with System chosen at its foot, and the Login page's card in a rounded panel">
|
||||
</p>
|
||||
|
||||
Ten pages in a sidebar (Login, Buttons, Inputs, Display, Layout, Popups,
|
||||
Animation, Styling, Translations, Diagnostics), the color scheme and the
|
||||
Ten pages in a sidebar — Login, Buttons, Inputs, Display, Layout, Popups,
|
||||
Animation, Styling, Translations, Diagnostics — with the color scheme and the
|
||||
titlebar switch at its foot, and an icon in the tray. It is the reference for
|
||||
what the library draws, where its claims are tested rather than asserted:
|
||||
what the library draws, and where its claims are tested rather than asserted:
|
||||
|
||||
- **Styling** lays Simple.css over Water.css with a checkbox, and prints what
|
||||
each rule resolved to beside the widgets it painted.
|
||||
- **Styling** lays Simple.css over Water.css at the flick of a checkbox, and
|
||||
prints what each rule resolved to beside the widgets it painted.
|
||||
- **Translations** sets the opening of *The Ugly Duckling* in English, Polish
|
||||
and Japanese from the catalogs, beside a date, a number, one amount in three
|
||||
currencies and a count of ducklings, each written the way that language
|
||||
writes it. The Japanese is drawn by the Text module.
|
||||
- **Popups** opens floaters, toasts, windows of their own, menus and the tray,
|
||||
and can have the showcase ask before it closes.
|
||||
- **Diagnostics** shows the renderer, and live, where each frame's
|
||||
milliseconds and each megabyte went.
|
||||
- **Diagnostics** shows the renderer, and where each frame's milliseconds and
|
||||
each megabyte went, live.
|
||||
- **Animation** sends five blocks to one stop, one of them instantly, draws
|
||||
all 31 easing curves through the function the widgets animate with, and
|
||||
plays the rest of NukAnim: a clip staggered across a grid under its debug
|
||||
@@ -58,10 +58,10 @@ what the library draws, where its claims are tested rather than asserted:
|
||||
</p>
|
||||
|
||||
A real editor in one file: a menu bar, a multiline field with line numbers
|
||||
that grows to fit any file, a find bar, printing and PDF export, a status
|
||||
line, the platform's open and save dialogs, and eight shortcuts. A page of
|
||||
widgets never has to answer what happens to a modified document, or where a
|
||||
menu's last item lands when its popup is a pixel short; this does.
|
||||
that grows to fit any file, a find bar, printing and PDF export, a status line, the platform's own open
|
||||
and save dialogs, and eight shortcuts. A page of widgets
|
||||
never has to answer what happens to a modified document, or where a menu's last
|
||||
item lands when its popup is a pixel short; this does.
|
||||
|
||||
## Bench
|
||||
|
||||
@@ -70,29 +70,29 @@ menu's last item lands when its popup is a pixel short; this does.
|
||||
</p>
|
||||
|
||||
Sixty-four rotating boxes, at the display's rate or flat out with
|
||||
`--no-vsync`, for `--bench-seconds`, then what the run cost, on stdout. Six
|
||||
seconds flat out on the Windows machine
|
||||
`--no-vsync`, for `--bench-seconds`, then what the run cost on stdout. Six
|
||||
seconds flat out, on the Windows machine that
|
||||
[PERFORMANCE.md](PERFORMANCE.md#where-the-numbers-came-from) names:
|
||||
|
||||
```
|
||||
size 800x600
|
||||
frames 8095
|
||||
fps 1349.2
|
||||
ms_build 0.00
|
||||
ms_render 0.43
|
||||
ms_present 0.28
|
||||
ms_per_frame 0.72
|
||||
cpu_at_60fps 4.3
|
||||
cpu_percent 97.1
|
||||
private_mb 6.0
|
||||
frames 4290
|
||||
fps 715.0
|
||||
ms_build 0.03
|
||||
ms_render 0.07
|
||||
ms_present 1.27
|
||||
ms_per_frame 1.37
|
||||
cpu_at_60fps 8.2
|
||||
cpu_percent 97.4
|
||||
private_mb 7.1
|
||||
```
|
||||
|
||||
With `--no-vsync`, read `cpu_at_60fps`, not `cpu_percent`. On vsync,
|
||||
`SDL_RenderPresent` waits for the next vblank, and whether the wait is charged
|
||||
depends on whether SDL blocks or spins: the same 386 frames have read from
|
||||
0.3% to 99.6% of a core. `size` is the drawing area, printed because four
|
||||
`SDL_RenderPresent` waits for the next vblank, and whether that wait is charged
|
||||
depends on whether SDL blocks or spins: the same 386 frames have read anywhere
|
||||
from 0.3% to 99.6% of a core. `size` is the drawing area, printed because four
|
||||
other frameworks in `benchmarks/` draw the same picture. `--boxes` changes the
|
||||
workload; `--fps` holds it to a rate.
|
||||
workload, and `--fps` holds it to a rate.
|
||||
|
||||
It is deliberately what the library is worst at. Everything else in
|
||||
PERFORMANCE.md counts frames, because nothing is drawn while nothing changes;
|
||||
@@ -106,7 +106,7 @@ bars in the chart there come from this program, one per renderer.
|
||||
</p>
|
||||
|
||||
One centered button that closes the window, in about forty lines: the
|
||||
smallest application, and the one to start from.
|
||||
smallest thing that is still an application, and the one to start from.
|
||||
|
||||
## Running one the same way twice
|
||||
|
||||
@@ -116,5 +116,5 @@ smallest application, and the one to start from.
|
||||
|
||||
`--shot` writes the window once it settles and quits; `--a11y-dump` writes
|
||||
every node's role, name, value, state and rectangle. Diff two dumps and
|
||||
anything that moved by a pixel shows. The other flags are in
|
||||
anything that moved by a pixel says so. The rest of the flags are in
|
||||
[DOCUMENTATION.md](DOCUMENTATION.md#command-line-flags).
|
||||
|
||||
+450
-617
File diff suppressed because it is too large
Load Diff
+64
-62
@@ -53,45 +53,48 @@
|
||||
|
||||
### What is Reaktor, and how is it different from Nuklear?
|
||||
|
||||
A toolkit for desktop and web apps in C. Nuklear, which it is built on, gives
|
||||
you widgets and leaves the rest to you. Reaktor fills it in:
|
||||
Reaktor is a toolkit for building desktop and web apps in C. Nuklear, which it
|
||||
is built on, gives you widgets and leaves everything else to
|
||||
you. Reaktor fills in the rest:
|
||||
|
||||
- **The whole stack.** Nuklear only draws; the window, input, fonts and
|
||||
rendering are yours to wire up. Reaktor brings them, on SDL.
|
||||
- **The whole stack, ready to use.** Nuklear only draws; the window, input,
|
||||
fonts and rendering are yours to wire up. Reaktor brings them, built on
|
||||
SDL, so there is nothing to connect yourself.
|
||||
- **A finished app, not a drawing kit.** One call opens a window and runs
|
||||
it; you describe what is on screen and Reaktor lays it out.
|
||||
it; you describe what's on screen and Reaktor lays it out.
|
||||
- **A look you change without recompiling.** Colors, fonts, spacing and
|
||||
rounded corners come from ordinary CSS files, light and dark.
|
||||
- **Everyone can use it.** Screen readers read it, and every control works
|
||||
from the keyboard.
|
||||
rounded corners come from ordinary CSS files, with light and dark themes.
|
||||
- **Everyone can use it.** Screen readers can read it, and every control
|
||||
works from the keyboard.
|
||||
- **Any language.** Translations, number and date formats, and scripts such
|
||||
as Japanese and Arabic.
|
||||
- **What real apps need.** Menus, file pickers, dialogs, notifications,
|
||||
undo, printing, saved settings, extra windows and a tray icon.
|
||||
- **One codebase.** Windows, macOS, Linux, the BSDs and the browser.
|
||||
- **One codebase everywhere.** Windows, macOS, Linux, the BSDs and the
|
||||
browser.
|
||||
|
||||
Nuklear is still underneath when you need it directly. See
|
||||
[An application](DOCUMENTATION.md#an-application).
|
||||
Nuklear is still there underneath when you need something it offers
|
||||
directly. See [An application](DOCUMENTATION.md#an-application).
|
||||
|
||||
### Why C99 and an immediate-mode core instead of a retained toolkit like GTK or Qt?
|
||||
|
||||
To stay small: a 2.1 MB binary, 7–16 MB of RAM, no GPU, nothing to install
|
||||
beside it. A frame is drawn only when something changes, so the app idles at
|
||||
0% of a core. See [The frame loop](DOCUMENTATION.md#the-frame-loop)
|
||||
To stay small: a 2.4 MB binary, about 10 MB of RAM, no GPU, and nothing to
|
||||
install beside it. A frame is drawn only when something changes, so the app
|
||||
idles at 0% of a core. See [The frame loop](DOCUMENTATION.md#the-frame-loop)
|
||||
and [PERFORMANCE.md](PERFORMANCE.md).
|
||||
|
||||
### Which platforms and architectures are supported?
|
||||
|
||||
Windows, macOS, Linux, FreeBSD, OpenBSD, NetBSD and WebAssembly, on x86 and
|
||||
ARM, plus ARMv7 and RISC-V on Linux. Every pull request builds them all; a
|
||||
job that runs under emulation (the BSDs' ARM64, Linux's ARMv7 and RISC-V) may
|
||||
fail without failing the run. See
|
||||
ARM, plus ARMv7 and RISC-V on Linux. Every pull request builds them all; the
|
||||
BSDs' ARM64 runs under emulation and may fail without failing the run. See
|
||||
[Platforms](DOCUMENTATION.md#platforms).
|
||||
|
||||
### What license is it under?
|
||||
|
||||
MIT. Each dependency keeps its own permissive license; a release ships them in
|
||||
`licenses/` with [NOTICE.md](NOTICE.md), and your app should carry them too.
|
||||
MIT. Each dependency keeps its own license, all permissive; a release ships
|
||||
them in `licenses/` with [NOTICE.md](NOTICE.md), and your app should carry
|
||||
them too.
|
||||
|
||||
---
|
||||
|
||||
@@ -105,11 +108,11 @@ axis. Leave the axis unset and the rule applies. See
|
||||
|
||||
### Why can't I use `em` or `rem`, and how far do `var()` and `color-mix()` go?
|
||||
|
||||
You can: `em` is the body's font size and `rem` the root's. The engine also
|
||||
resolves `var()`, `color-mix(in srgb, …)` and `calc()` over pixels, and keeps
|
||||
the `prefers-color-scheme` branch for the active scheme. Percentages are not
|
||||
lengths, and operator selectors such as `[href^="http"]` are dropped. See
|
||||
[Styling](DOCUMENTATION.md#styling).
|
||||
You can: the engine underneath, libcss, has neither, so `cssflat.c` turns
|
||||
them into pixels before it reads the sheet. It also resolves `var()`, works
|
||||
out `color-mix(in srgb, …)` and `calc()` over pixels, and keeps the
|
||||
`prefers-color-scheme` branch for the active scheme. Operator selectors such
|
||||
as `[href^="http"]` are dropped. See [Styling](DOCUMENTATION.md#styling).
|
||||
|
||||
### How do I ship my own stylesheet or theme?
|
||||
|
||||
@@ -125,9 +128,9 @@ and `--css` adds one on top. `.no_reaktor_css` drops reaktor.css. See
|
||||
### Why does a widget have no rectangle, or the declared tree not settle?
|
||||
|
||||
A box is placed one frame late and found again by its name. A widget whose
|
||||
label changes every frame needs a stable `.name`; a node declared only on some
|
||||
frames renumbers everything after it. A loose label after a row belongs inside
|
||||
a named `REAKTOR_COLUMN`. See [Layout](DOCUMENTATION.md#layout).
|
||||
label changes every frame needs a stable `.name`, and a node declared only on
|
||||
some frames renumbers everything after it. A loose label after a row belongs
|
||||
inside a named `REAKTOR_COLUMN`. See [Layout](DOCUMENTATION.md#layout).
|
||||
|
||||
### Can I still call Nuklear directly?
|
||||
|
||||
@@ -138,9 +141,9 @@ a panel, but a group or popup is its own panel. See
|
||||
|
||||
### How do I write a widget of my own?
|
||||
|
||||
Lay it out by hand in a group from the pieces in `ui.h`: colors from the
|
||||
Lay it out by hand in a group, from the pieces in `ui.h`: colors from the
|
||||
sheet, rounded fills and borders, a hot rectangle so hover redraws, and a
|
||||
`reaktor_note` so screen readers and keyboard focus find it. See
|
||||
`reaktor_note` so screen readers and keyboard focus see it. See
|
||||
[Beyond the specs](DOCUMENTATION.md#beyond-the-specs).
|
||||
|
||||
---
|
||||
@@ -149,15 +152,15 @@ sheet, rounded fills and borders, a hot rectangle so hover redraws, and a
|
||||
|
||||
### Where are settings stored, and when are they saved?
|
||||
|
||||
In `settings.toml`, in SDL's preference folder for the app. `.save_settings`
|
||||
picks when: never (the default), on quit, on every change, or `.save_ms`
|
||||
after a change. `reaktor_settings_save` writes now; `reaktor_settings_clear`
|
||||
empties them and deletes the file. See
|
||||
In `settings.conf`, an INI file in SDL's preference folder for the app.
|
||||
`.save_settings` picks when: never (the default), on quit, on every change,
|
||||
or `.save_ms` after a change. `reaktor_settings_save` writes now and
|
||||
`reaktor_settings_clear` empties them and deletes the file. See
|
||||
[Services](DOCUMENTATION.md#services).
|
||||
|
||||
### How do settings work on the web?
|
||||
|
||||
The same `settings.toml` lives in the browser's IndexedDB, loaded before
|
||||
The same `settings.conf` lives in the browser's IndexedDB, loaded before
|
||||
`main` and synced after each write; saving on quit means saving on change
|
||||
there. Clearing site data or closing a private window loses it.
|
||||
|
||||
@@ -177,8 +180,8 @@ followed by a frame. See [Services](DOCUMENTATION.md#services).
|
||||
|
||||
### How do I add undo, notifications or printing?
|
||||
|
||||
Push a step with undo and redo callbacks after each change; Ctrl+Z and Ctrl+Y
|
||||
take it back and forth, merging typing into one step if asked.
|
||||
Push a step with an undo and a redo callback after each change, and Ctrl+Z
|
||||
and Ctrl+Y take it back and forth, merging typing into one step if asked.
|
||||
`reaktor_notify` shows a message outside the window. `reaktor_print` and
|
||||
`reaktor_print_pdf` lay pages out as the window does and print them or write
|
||||
a PDF. See [Services](DOCUMENTATION.md#services).
|
||||
@@ -189,7 +192,7 @@ a PDF. See [Services](DOCUMENTATION.md#services).
|
||||
|
||||
### How do I build without CMake on PATH, or for x86 or ARM64?
|
||||
|
||||
`./build.ps1` on Windows finds Visual Studio's CMake; `./build.sh` elsewhere.
|
||||
`./build.ps1` on Windows finds MSVC's CMake; `./build.sh` elsewhere.
|
||||
`./build.ps1 -Arch x86` or `-Arch arm64` builds that architecture into
|
||||
`build-<arch>`; ARM64 needs Visual Studio's ARM64 tools. See
|
||||
[Platforms](DOCUMENTATION.md#platforms).
|
||||
@@ -197,28 +200,28 @@ a PDF. See [Services](DOCUMENTATION.md#services).
|
||||
### How do I turn off accessibility, localization or text shaping?
|
||||
|
||||
`-DREAKTOR_A11Y=OFF`, `-DREAKTOR_LOCALE=OFF` or `-DREAKTOR_TEXT=OFF`. Each
|
||||
swaps in a stub; pixels and `--a11y-dump` stay identical apart from what the
|
||||
module drew. CMake keeps the option until you pass `=ON`. See
|
||||
swaps in a stub, and pixels and `--a11y-dump` stay identical apart from what
|
||||
the module drew. CMake keeps the option until you pass `=ON`. See
|
||||
[Build options](DOCUMENTATION.md#build-options).
|
||||
|
||||
### How do I install libreaktor and link against it?
|
||||
|
||||
Take the release's archive, `.deb` or `.rpm`, or run
|
||||
`sh tools/libreaktor-pkg.sh -i`. Then `find_package(reaktor 0.11 REQUIRED)`
|
||||
Take the release's archive or the `.deb` or `.rpm`, or run
|
||||
`sh tools/libreaktor-pkg.sh -i`. Then `find_package(reaktor 0.7 REQUIRED)`
|
||||
and link `reaktor::reaktor`, or use `pkg-config --cflags --libs reaktor`. To
|
||||
build it into your tree, `add_subdirectory` the checkout and call
|
||||
build it into your tree instead, `add_subdirectory` the checkout and call
|
||||
`reaktor_add_app`. See [In your own project](DOCUMENTATION.md#in-your-own-project).
|
||||
|
||||
### How do I build and host the WebAssembly version?
|
||||
|
||||
`./build-wasm.sh` (or `.ps1`) with emsdk writes the pages into `build-wasm/`.
|
||||
Serve that folder over HTTP; opened as a file, a page will not load.
|
||||
`./build-wasm.sh` (or `.ps1`) with emsdk writes the pages into `build-wasm/`;
|
||||
serve that folder over HTTP, since opening the file directly will not load.
|
||||
See [The web build](DOCUMENTATION.md#the-web-build).
|
||||
|
||||
### Why is the web page blank in a background tab?
|
||||
|
||||
The loop waits on `requestAnimationFrame`, which a hidden tab, a minimized
|
||||
window or an off-screen pane never fires. It draws once visible.
|
||||
window or an off-screen pane never fires. It draws once it is visible.
|
||||
|
||||
---
|
||||
|
||||
@@ -230,37 +233,36 @@ window or an off-screen pane never fires. It draws once visible.
|
||||
./build/showcase --tab 7 --theme dark --shot a.bmp --a11y-dump a.txt
|
||||
```
|
||||
|
||||
Any app takes `--shot` and `--a11y-dump`. The dump lists every node with its
|
||||
bounds, so two dumps diff to the pixel. Neither reads settings.
|
||||
Any app takes `--shot` and `--a11y-dump`; the dump lists every node with its
|
||||
bounds, so two dumps diff to the pixel. Settings are not read under either.
|
||||
See [Command-line flags](DOCUMENTATION.md#command-line-flags).
|
||||
|
||||
### Should my app use a GPU renderer?
|
||||
|
||||
Usually not. `software`, the default, needs no GPU, uses about a tenth of the
|
||||
memory and starts fastest. A GPU renderer pays off in long, continuous
|
||||
animation. `--renderer gpu` takes Metal on macOS; on Windows OpenGL where the
|
||||
build has it, else Direct3D 12, else 11, so `directx` on a default build; on
|
||||
Linux and the BSDs OpenGL, else OpenGL ES 2, neither built unless
|
||||
`REAKTOR_RENDERERS` names it. Expect six to thirteen times the memory. See
|
||||
memory and starts fastest. A GPU
|
||||
renderer pays off in long, continuous animation: `--renderer directx` takes
|
||||
Direct3D 12 on Windows where it starts, else 11, and `opengl` needs a build
|
||||
with `-DREAKTOR_SDL_GL=ON`. Expect six to thirteen times the memory. See
|
||||
[The renderer](DOCUMENTATION.md#the-renderer).
|
||||
|
||||
### Why is the frame time high on a machine with no GPU?
|
||||
|
||||
Most of it is usually rasterizing: SDL queues what it is asked to draw and
|
||||
fills the pixels when the queue is flushed. Most of the rest is copying the
|
||||
frame to the window. The Diagnostics page and `bench --no-vsync` split build,
|
||||
Most of it is usually `SDL_RenderPresent`, copying the frame to the screen,
|
||||
not drawing it. The Diagnostics page and `bench --no-vsync` split build,
|
||||
render and present. See [The renderer](DOCUMENTATION.md#the-renderer).
|
||||
|
||||
### Why does Japanese or Arabic text draw differently from Latin?
|
||||
|
||||
The Text module draws a string with a character the atlas lacks: it orders,
|
||||
shapes and takes glyphs from fallback fonts. The rest is Nuklear's. Arabic,
|
||||
Hebrew or an Indic script needs a font that has it, passed with
|
||||
`--font-fallback` or `.font_fallbacks`. See [Text](DOCUMENTATION.md#text).
|
||||
A string with a character the font atlas lacks is drawn by the Text module,
|
||||
which orders, shapes and takes glyphs from fallback fonts; the rest is
|
||||
Nuklear's. Arabic, Hebrew or an Indic script needs a font that has it, passed
|
||||
with `--font-fallback` or `.font_fallbacks`. See [Text](DOCUMENTATION.md#text).
|
||||
|
||||
### How do I report a bug?
|
||||
|
||||
Open an issue at [github.com/Alpaq92/Reaktor/issues](https://github.com/Alpaq92/Reaktor/issues)
|
||||
with the Reaktor version (`reaktor_version()`), system and architecture, the
|
||||
steps that show it, and what you expected. For anything drawn wrong, attach a
|
||||
`--shot` and an `--a11y-dump`; for a crash, what `--console debug` printed.
|
||||
with the Reaktor version (`reaktor_version()`), the system and architecture,
|
||||
the steps that show it, and what you expected. For anything drawn wrong,
|
||||
attach a `--shot` and an `--a11y-dump` of it; for a crash, what the
|
||||
`--console debug` log printed.
|
||||
|
||||
+62
-56
@@ -2,14 +2,15 @@
|
||||
|
||||
Reaktor is MIT ([LICENSE](../LICENSE)). Everything it is built on is a git
|
||||
submodule under `external/`, used as it ships; each license below was read
|
||||
from the project's own license file at the pinned revision, which
|
||||
`git submodule status` prints.
|
||||
from the project's own license file at the pinned revision.
|
||||
`git submodule status` prints the pins.
|
||||
|
||||
| Component | Used for | License |
|
||||
| --- | --- | --- |
|
||||
| [SDL](https://github.com/libsdl-org/SDL) | Window, input, renderer, system theme, file dialog, tray | zlib |
|
||||
| [Nuklear](https://github.com/Immediate-Mode-UI/Nuklear) | Widgets and the SDL3 backend | MIT **or** public domain |
|
||||
| [NukAnim](https://github.com/Alpaq92/NukAnim) | Every animation, and `nukanim.h` for applications — a port of [ImAnim](https://github.com/soufianekhiat/ImAnim) with [ImAnimate](https://github.com/RaidcoreGG/ImAnimate)'s `animate` | MIT |
|
||||
| [LCUI](https://github.com/lc-soft/LCUI) | `libcss` (parse, match, cascade) and `yutil` | MIT |
|
||||
| [Onlay](https://github.com/Alpaq92/Onlay) | The rectangles — a fork of [randrew/layout](https://github.com/randrew/layout) | MIT |
|
||||
| [Water.css](https://github.com/kognise/water.css) | The stylesheet the look comes from, compiled in | MIT |
|
||||
| [Simple.css](https://github.com/kevquirk/simple.css) | Alternative style used in the demo app | MIT |
|
||||
@@ -19,58 +20,63 @@ from the project's own license file at the pinned revision, which
|
||||
| [plutovg](https://github.com/sammycage/plutovg) | plutosvg's canvas (nested submodule) | MIT |
|
||||
| [mojibake](https://github.com/zaerl/mojibake) | Bidirectional text (UAX #9) and line breaking (UAX #14), for the Text module | MIT |
|
||||
| [kb_text_shape](https://github.com/JimmyLefevre/kb) | OpenType shaping, script segmentation and font coverage, for the Text module | zlib |
|
||||
| [toml-c](https://github.com/arp242/toml-c) | Reading `settings.toml`; a fork of [tomlc99](https://github.com/cktan/tomlc99), whose copyright notice it keeps | MIT |
|
||||
| [gibus](https://github.com/Alpaq92/gibus) | D-Bus on Linux and the BSDs, for the AT-SPI bridge, the tray, notifications and the desktop portal's settings — a port of [minidbus](https://codefloe.com/Honken/minidbus), whose copyright notice it keeps | MIT |
|
||||
| [ini.h](https://github.com/mattiasgustavsson/libs) | Reading and writing `settings.conf` | MIT **or** public domain |
|
||||
|
||||
SDL is built static (and, in a `REAKTOR_SHARED` build on Linux and the BSDs,
|
||||
shared too, as `libreaktor-sdl3.so`) without audio, joystick, haptic, HID,
|
||||
sensor, camera, power, offscreen, the render backends Reaktor never selects,
|
||||
or its dynamic API (see below); its GPU API is built only with
|
||||
`REAKTOR_SHADERS`. Its tray is built, and opened on Windows and macOS. On
|
||||
Linux and the BSDs Reaktor's own tray speaks StatusNotifierItem and dbusmenu
|
||||
over gibus, so SDL's, which would load AppIndicator and GTK 3, never opens
|
||||
there and nothing links them. mojibake is built without its collation, IDNA,
|
||||
security and character-name tables. NukAnim is one header, compiled in
|
||||
Only LCUI's `libcss` and `yutil` are built, not the toolkit. SDL is built
|
||||
static, without audio, joystick, haptic, HID, sensor, camera, power, GPU,
|
||||
offscreen, the render backends Reaktor never selects, or its dynamic API (see
|
||||
below). Its tray is built: on
|
||||
Linux and the BSDs it loads AppIndicator and GTK 3 when a tray opens, and
|
||||
nothing links them. mojibake is built without its collation, IDNA, security
|
||||
and character-name tables. NukAnim is one header, compiled in
|
||||
`core/anim/anim.c`; its own Nuklear submodule, which only its tests use, comes
|
||||
with a recursive checkout and is not built. kb_text_shape is one header,
|
||||
compiled in `core/text/kb.c`; it shapes, and FreeType draws. FreeType is built
|
||||
with only its TrueType, CFF, auto-hinter and anti-aliasing modules, and
|
||||
with a recursive checkout and is not built. kb_text_shape is one header, compiled in
|
||||
`core/text/kb.c`; it shapes, and FreeType draws. FreeType is built with only
|
||||
its TrueType, CFF, auto-hinter and anti-aliasing modules, and
|
||||
`core/render/ft/reaktor_ftoption.h` turns off what Reaktor never reads, its
|
||||
environment override among them.
|
||||
|
||||
Nothing links libdbus. SDL still opens `libdbus-1.so.3` where the system has
|
||||
it, for input methods, portals and the screensaver, and does without it
|
||||
elsewhere.
|
||||
|
||||
The stylesheets are read by Reaktor's own engine, `core/css/css.c`; no CSS
|
||||
library is linked or copied.
|
||||
|
||||
Portions of this software are copyright © 2026 The FreeType Project
|
||||
(https://freetype.org). All rights reserved.
|
||||
|
||||
## The one dependency that is not a submodule
|
||||
|
||||
`libdbus`, on Linux and the BSDs, when present: the AT-SPI bridge speaks
|
||||
D-Bus. CMake asks pkg-config for `dbus-1`; without it the bridge is not built,
|
||||
as on a desktop with no accessibility bus.
|
||||
|
||||
| Component | License |
|
||||
| --- | --- |
|
||||
| [libdbus](https://gitlab.freedesktop.org/dbus/dbus) | **AFL-2.1** or GPL-2.0-or-later — taken under AFL-2.1 |
|
||||
|
||||
AFL-2.1 is permissive, with an attribution requirement this table meets and a
|
||||
patent-termination clause. It is not GPL-compatible, which matters to GPL
|
||||
downstreams, not to an MIT project. The alternative was ATK: LGPL, and being
|
||||
retired in favor of speaking AT-SPI directly.
|
||||
|
||||
## The one vendored source file
|
||||
|
||||
`core/render/nk_sdl3_renderer.h` is Nuklear's SDL3 backend, copied from
|
||||
`external/nuklear/demo/sdl3_renderer/` under Nuklear's license. Every
|
||||
deviation is marked `REAKTOR`: an 8-bit indexed atlas, a 1×1 white texture
|
||||
for untextured geometry, pixel snapping, fills and strokes feathered apart,
|
||||
the atlas palette shared with the Text module, rectangles drawn from device
|
||||
pixels by `nk_sdl_quad` on the software renderer, an upload for the atlas
|
||||
Reaktor bakes itself, `tex_null` repointed after every bake, a key-up dropped
|
||||
for a key Nuklear does not hold, text input of any length fed one rune at a
|
||||
time, and textures clamped rather than tested for wrapping.
|
||||
`external/nuklear/demo/sdl3_renderer/` under Nuklear's license. Every deviation
|
||||
is marked `REAKTOR`: an 8-bit indexed atlas, a 1×1 white texture for
|
||||
untextured geometry, pixel snapping, fills and strokes feathered apart, the
|
||||
atlas palette shared with the Text module, rectangles drawn from device pixels
|
||||
by `nk_sdl_quad` on the software renderer, an upload for the atlas Reaktor
|
||||
bakes itself, `tex_null` repointed after every bake, a key-up dropped for a key Nuklear does not hold, text input of any
|
||||
length fed one rune at a time, and textures clamped rather than tested for
|
||||
wrapping.
|
||||
|
||||
It cannot stay an include: the changes sit inside its functions, and
|
||||
submodules are not edited. So when Nuklear's backend changes, it is
|
||||
re-vendored and the hunks re-applied.
|
||||
It cannot stay an include because the changes sit inside its functions, and
|
||||
submodules are not edited. The cost: when
|
||||
Nuklear's backend changes, it is re-vendored and the hunks re-applied.
|
||||
|
||||
## The one change to how a submodule builds
|
||||
|
||||
SDL's dynamic API keeps every SDL function in the program and, at startup,
|
||||
loads whichever SDL library the `SDL3_DYNAMIC_API` environment variable names,
|
||||
so a statically linked game can take a newer SDL. Reaktor's programs are
|
||||
rebuilt against one instead, and read no environment. Without it `simple` is
|
||||
20% smaller and `showcase` 12%.
|
||||
loads whichever SDL library the `SDL3_DYNAMIC_API` environment variable names.
|
||||
It exists so a statically linked game can take a newer SDL; Reaktor's
|
||||
programs are rebuilt against one instead, and read no environment. Without it
|
||||
`simple` is 20% smaller and `showcase` 12%.
|
||||
|
||||
SDL refuses a command-line switch for it, so `core/sdl/no_dynapi.h` is forced
|
||||
into SDL's sources and defines `SDL_dynapi_h_`, the guard of SDL's own
|
||||
@@ -88,11 +94,11 @@ UI face, Karla, came from inside Nuklear with no license near it.
|
||||
| **M PLUS 1p** | Japanese, for what Aileron lacks | OFL 1.1 | `assets/fonts/MPLUS1p-Notice.txt` |
|
||||
|
||||
Aileron is by Sora Sagano of DOT COLON. Its download has no license file, so
|
||||
the terms were traced: the font's `name` table says `copyright: No Rights
|
||||
the terms were traced: the font's own `name` table says `copyright: No Rights
|
||||
Reserved.`, and dotcolon.net/font/aileron links CC0 beside it.
|
||||
`Aileron-Notice.txt` records both, says this project assembled it, and
|
||||
reproduces the CC0 legal code. It is an OTF with CFF outlines, which FreeType
|
||||
reads.
|
||||
reproduces the CC0 legal code. It is an OTF with CFF outlines, which
|
||||
FreeType reads.
|
||||
|
||||
M PLUS 1p is by The M+ Project Authors. `MPLUS1p-Regular.ttf` is the file as
|
||||
Google Fonts ships it; `MPLUS1p-Notice.txt` names its commit and SHA-256 and
|
||||
@@ -114,7 +120,7 @@ translator who died before 1956:
|
||||
|
||||
All three are public domain in the United States, in Japan, and wherever
|
||||
protection ends seventy years after the translator's death. Mexico's hundred
|
||||
years and Colombia's eighty still cover the Japanese one; no Japanese
|
||||
years and Colombia's eighty still cover the Japanese one, and no Japanese
|
||||
translation with checkable dates clears them. Each catalog repeats its
|
||||
attribution, and the page prints it under the story.
|
||||
|
||||
@@ -126,29 +132,29 @@ domain as a U.S. Government work.
|
||||
|
||||
## Benchmarks
|
||||
|
||||
Nothing in `benchmarks/` is listed above. Its four projects (Flutter,
|
||||
Electron, Compose Multiplatform and Shaft) hold source and build files only;
|
||||
Nothing in `benchmarks/` is listed above. Its four projects — Flutter,
|
||||
Electron, Compose Multiplatform and Shaft — hold source and build files only;
|
||||
each toolchain fetches its own framework, and none is part of a Reaktor build.
|
||||
|
||||
## What is redistributed
|
||||
|
||||
A native build links SDL, plutosvg, plutovg and FreeType statically, plus
|
||||
mojibake and kb_text_shape with the Text module, and compiles in Nuklear,
|
||||
NukAnim, Onlay and toml-c, and gibus on Linux and the BSDs, so it carries the
|
||||
zlib, MIT and FreeType License terms above. Each license is copied unchanged
|
||||
into `licenses/` beside the programs: ship that folder, and this file, with a
|
||||
binary.
|
||||
A native build links SDL, libcss, yutil, plutosvg, plutovg and FreeType
|
||||
statically, plus mojibake and kb_text_shape with the Text module, and compiles
|
||||
in Nuklear, NukAnim, Onlay and ini.h, so it carries the zlib, MIT and FreeType
|
||||
License terms above. Each license
|
||||
is copied unchanged into `licenses/` beside the programs (ini.h's sits at the
|
||||
end of the header, so the header itself is `licenses/ini.h.txt`): ship that folder,
|
||||
and this file, with a binary.
|
||||
|
||||
The binary also carries the default assets in `REAKTOR_BUILTINS`, byte for
|
||||
byte: Water.css's `variables-light.css`, `variables-dark.css` and the nine
|
||||
files in `src/parts/` (MIT); the seven Ionicons `chevron-down-outline`,
|
||||
`chevron-back-outline`, `chevron-forward-outline`, `ellipse`,
|
||||
`ellipse-outline`, `radio-button-off` and `close-outline` (MIT); Aileron
|
||||
Regular and Bold (CC0); and the mark and `assets/css/reaktor.css` (MIT).
|
||||
Their licenses are in `licenses/` too.
|
||||
files in `src/parts/` (MIT); the seven Ionicons `chevron-down-outline`, `chevron-back-outline`,
|
||||
`chevron-forward-outline`, `ellipse`, `ellipse-outline`, `radio-button-off`
|
||||
and `close-outline` (MIT); Aileron Regular and Bold (CC0); and the mark and
|
||||
`assets/css/reaktor.css` (MIT). Their licenses are in `licenses/` too.
|
||||
|
||||
The rest of Ionicons, Simple.css, the Japanese font and the catalogs are not
|
||||
embedded (the catalogs are with `-DREAKTOR_LOCALE_EMBED=ON`); a build that
|
||||
uses them ships them beside the binary under the `.reaktor-root` marker,
|
||||
uses them ships them beside the binary, under the `.reaktor-root` marker,
|
||||
which `tools/package.sh` writes for releases. The WebAssembly build packs the
|
||||
ones it uses into its `.data` bundle.
|
||||
|
||||
+160
-291
@@ -11,334 +11,203 @@ queue and builds a frame only when the picture would differ. So **CPU is a
|
||||
count of frames, not a load**, and **memory is a floor, not a curve**: once the
|
||||
atlas and icons are baked, nothing grows.
|
||||
|
||||
Unless a figure says otherwise, it was measured on 2026-11-10 on master for
|
||||
0.11.0, on the Windows machine in
|
||||
[Where the numbers came from](#where-the-numbers-came-from). There,
|
||||
`showcase.exe` is 3,385,344 bytes, `notepad.exe` 2,376,192, `simple.exe`
|
||||
2,233,344 and `bench.exe` 2,217,984, linked with
|
||||
[link-time optimization](#size). The showcase links all nine optional
|
||||
modules, `notepad` three (settings, popup windows, printing) and the other two
|
||||
none; each carries the default look compiled in: Aileron, the mark, the sheets
|
||||
and seven icons, 73,123 bytes.
|
||||
On Windows today, `showcase.exe` is 3,671,040 bytes, `notepad.exe` 2,610,176,
|
||||
`simple.exe` 2,476,544 and `bench.exe` 2,466,304. The showcase links all three
|
||||
optional modules and the others none; each carries the default look —
|
||||
Aileron, the mark, the sheets and seven icons, 67,829 bytes — compiled in. The
|
||||
four-platform figures below come from an older build that shipped one
|
||||
executable, at 1.00× scale in a 960×680 window; the runtime they measure is
|
||||
the one all four programs share.
|
||||
|
||||
## Against the others
|
||||
|
||||

|
||||
Memory: Reaktor 9.5 MB, the same binary on D3D11 59.4 MB, on D3D12 122.3 MB
|
||||
and on OpenGL 70.1 MB, Flutter 90.8 MB, Electron 157.6 MB, Kotlin
|
||||
Multiplatform 667.4 MB. Steady-state CPU as a percent of one core: Reaktor
|
||||
6.0%, D3D11 10.3%, D3D12 5.0%, OpenGL 5.0%, Flutter 15.6%, Electron 26.1%,
|
||||
Kotlin Multiplatform 33.5%](benchmark.svg)
|
||||
|
||||
The workload is [ShaftUI/Shaft](https://github.com/ShaftUI/Shaft)'s: 64 boxes
|
||||
rotating at 60 fps in an 800×600 window. Each arm is its own app, built with
|
||||
its framework's toolchain; one script launches it and samples its whole
|
||||
process tree from outside. [`benchmarks/`](../benchmarks/BENCHMARKS.md) has
|
||||
the projects and the runner. Reaktor appears once per `--renderer`. Shaft is
|
||||
not plotted: it does not link on Windows.
|
||||
rotating at 60 fps in an 800×600 window, every arm on the same machine: a
|
||||
Lenovo laptop with a 6-core Ryzen 5 4600H, a GeForce RTX 2060 and a 1920×1080
|
||||
120 Hz display, on Windows 11 Pro. Each arm is its own app, built with its
|
||||
framework's toolchain; one script launches it and samples its whole process
|
||||
tree from outside. [`benchmarks/`](../benchmarks/BENCHMARKS.md) has the
|
||||
projects and the runner. Reaktor appears once per `--renderer`. Shaft is not
|
||||
plotted: it does not link on Windows.
|
||||
|
||||
| Arm | Memory | CPU, with startup | CPU, steady state | Measured |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| **Reaktor**, `software` | 8.8 MB | 7.0% | 6.0% | 2026-11-11 |
|
||||
| **Reaktor**, `direct3d11` | 57.6 MB | 14.4% | 11.7% | 2026-11-11 |
|
||||
| **Reaktor**, `direct3d12` | 120.5 MB | 10.6% | 5.2% | 2026-11-11 |
|
||||
| **Reaktor**, `opengl` | 68.7 MB | 11.1% | 5.9% | 2026-11-11 |
|
||||
| Electron 44.3.0 | 155.2 MB | 36.1% | 20.7% | 2026-11-09 |
|
||||
| Flutter 3.47.8 | 132.7 MB | 38.8% | 15.3% | 2026-10-24 |
|
||||
| Kotlin Multiplatform | 668.7 MB | 51.5% | 29.4% | 2026-10-24 |
|
||||
| Arm | Memory | CPU, with startup | CPU, steady state |
|
||||
| --- | --- | --- | --- |
|
||||
| **Reaktor**, `software` | 9.5 MB | 8.6% | 6.0% |
|
||||
| **Reaktor**, `direct3d11` | 59.4 MB | 14.1% | 10.3% |
|
||||
| **Reaktor**, `direct3d12` | 122.3 MB | 11.8% | 5.0% |
|
||||
| **Reaktor**, `opengl` | 70.1 MB | 11.6% | 5.0% |
|
||||
| Flutter | 90.8 MB | 19.3% | 15.6% |
|
||||
| Electron | 157.6 MB | 40.8% | 26.1% |
|
||||
| Kotlin Multiplatform | 667.4 MB | 59.6% | 33.5% |
|
||||
|
||||
- **About a fifteenth of Flutter's memory and less than half its CPU**, with
|
||||
startup or without, and about a seventy-fifth of Kotlin Multiplatform's
|
||||
memory.
|
||||
- **About a tenth of Flutter's memory and less than half its CPU**, with
|
||||
startup or without, and a seventieth of Kotlin Multiplatform's memory.
|
||||
- **Every Reaktor renderer takes less CPU than every other framework.** On a
|
||||
GPU renderer its memory is mostly the graphics driver's: 58–121 MB, below
|
||||
Flutter's 133.
|
||||
- **Once running, `direct3d12` takes 0.8 points less than `software` and
|
||||
`opengl` about the same; with startup, they take 3.6–4.1 more.**
|
||||
`direct3d11` takes the most of the four either way.
|
||||
- **`software`'s memory lands on one of two levels.** Its runs read
|
||||
8.1–8.3 MB or 9.1–9.2 MB, 16 of the 40 the lower, so the median falls
|
||||
between. Master before #139 does the same: twelve passes of the two taken
|
||||
in turn gave each a median of 9.1 MB. The passes of 2026-11-10 read 9.1,
|
||||
those of 2026-11-09 8.4.
|
||||
- **About 2.2 MB of every arm is the antivirus.** Bitdefender puts two
|
||||
components into every process on this machine. Walked with VirtualQueryEx
|
||||
and a heap ledger on `bench` on 2026-11-04, they come to two private heaps
|
||||
of 776 KB each, 74 code pages patched with hooks (303 KB), 56 more copied
|
||||
unchanged (229 KB), 53 KB of trampolines and about 180 KB of pages beside.
|
||||
Subtract that to compare with a machine without it. Of the rest, 1.9 MB is
|
||||
the window's framebuffer, 1.75 MB system DLL data made private, and 1.1 MB
|
||||
Reaktor's, SDL's, Nuklear's and FreeType's own allocations, the glyph atlas
|
||||
(537 KB) the largest.
|
||||
GPU renderer its memory is mostly the graphics driver's: 59–122 MB, around
|
||||
Flutter's 91.
|
||||
- **Startup counts.** A run that draws for only 0.2 s takes 0.16 s of CPU on
|
||||
`software` and 0.41–0.52 s on a GPU renderer. Once running, `direct3d12` and
|
||||
`opengl` take a point less than `software`.
|
||||
- **A GPU renderer's CPU depends on what else uses the GPU.** With another
|
||||
program keeping it busy, `direct3d11` and `opengl` missed 60 fps and took
|
||||
16–28% of a core (2026-10-24). These runs had the GeForce RTX 2060 idle.
|
||||
16–28% of a core. These runs had the GeForce RTX 2060 idle.
|
||||
|
||||
`software` used to read 67.3% here, because every rectangle reached SDL as
|
||||
two blended triangles. Drawing solid rectangles as plain fills cut a frame
|
||||
from 11.48 ms to 2.12 ms, with the same pixels.
|
||||
|
||||
### How it was measured
|
||||
|
||||
```powershell
|
||||
./benchmarks/run.ps1 -Targets <arm> -Seconds 6 -Fps 60 -Runs 1 -PinClock
|
||||
./benchmarks/run.ps1 -Targets <arm> -Fps 60 -Runs 1 -Steady -PinClock
|
||||
```bash
|
||||
./benchmarks/run.ps1 -Seconds 6 -Fps 60 -Runs 10
|
||||
```
|
||||
|
||||
Forty passes of Reaktor's arms, twenty in each of two sessions, each running
|
||||
every arm once in each mode, the order of the arms rotated and reversed from
|
||||
pass to pass so none always runs first. Memory is
|
||||
peak private bytes and CPU the sum across each app's process tree, as a
|
||||
percent of one core: with startup over the whole 6-second run, steady from
|
||||
3 s to 8 s of a 9-second run. Every arm held 60 fps; the fewest frames a
|
||||
run drew were 356 of 361. Each figure is the median of the forty runs.
|
||||
Between runs of one arm, memory spread by up to 2.5 MB (`direct3d12`
|
||||
7.3 MB) and steady CPU by several points: the middle half of `software`'s
|
||||
runs read 5.6–6.7%, `direct3d11`'s 9.3–13.5%, `direct3d12`'s 4.2–6.1% and
|
||||
`opengl`'s 4.9–6.5%. A whole session moves too: from the same binaries,
|
||||
`direct3d11` read 9.7% steady in the first and 12.8% in the second, and
|
||||
the passes of 2026-11-10 read 9.1% for `direct3d11` and 5.0% for
|
||||
`opengl`. `-PinClock` runs
|
||||
on a copy of the power plan that holds the processor at full speed, and
|
||||
restores the plan after.
|
||||
|
||||
Reaktor's `software`, `direct3d11` and `direct3d12` arms are the default
|
||||
Release build; `opengl` is a build with
|
||||
`-DREAKTOR_RENDERERS=direct3d11,direct3d12,opengl`. `vulkan` falls back to
|
||||
`direct3d11` in this SDL build. Electron keeps its figures of 2026-11-09,
|
||||
twenty passes of the same script taken with Reaktor's arms then; the middle
|
||||
half of its steady runs read 19.0–22.1% and its memory spread by 5.5 MB.
|
||||
Flutter and Kotlin Multiplatform keep theirs of 2026-10-24, from the same
|
||||
machine and script with ten runs each: Flutter 3.47.8, and Kotlin 2.4.20 with
|
||||
Compose 1.12.0 on JDK 21, which held 59 fps.
|
||||
|
||||
Run the script from PowerShell: started through Git Bash, the same `bench`
|
||||
reads about 3 MB less private memory (2026-11-07).
|
||||
|
||||
## Interaction
|
||||
|
||||
Driving the showcase with input, 0.11.0 draws its frames in 42–43% less
|
||||
time each than 0.10.0, 22% less on the wheel, most of it saved in
|
||||
rendering; the process spends 13–31% less CPU on hover, slider drag and
|
||||
typing, and 15% less on the wheel. A harness build of the
|
||||
showcase feeds it synthetic SDL events every 8 ms after two seconds of
|
||||
warm-up, on `software` at 1100×680, vsync off, light theme, with the clock
|
||||
pinned as above:
|
||||
|
||||
- **Hover**: the pointer sweeps four rows of the Buttons page, 3 px a step.
|
||||
- **Slider drag**: on Inputs, a sweep over the fields, the Float slider
|
||||
dragged back and forth, then down and up the sidebar.
|
||||
- **Typing**: a word typed into a field and erased, eight times, a key every
|
||||
48 ms.
|
||||
- **Wheel**: 60 notches down and 60 up, twice, one every 32 ms.
|
||||
|
||||
Twelve pairs per workload, each pair one run of 0.10.0 and one of 0.11.0,
|
||||
which runs first alternating. Medians of the twelve:
|
||||
|
||||
| Workload | Frames drawn | A drawn frame, 0.10.0 | 0.11.0 | Process CPU, 0.10.0 | 0.11.0 |
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
| Hover | 40, 38 | 3.38 ms | **1.93 ms** | 8.9% | **7.7%** |
|
||||
| Slider drag | 344, 333 | 3.18 ms | **1.83 ms** | 17.2% | **12.8%** |
|
||||
| Typing | 128 | 3.36 ms | **1.96 ms** | 14.2% | **9.7%** |
|
||||
| Wheel | 208 | 3.40 ms | **2.65 ms** | 15.4% | **13.2%** |
|
||||
|
||||
Where two counts of frames drawn are given, the first is 0.10.0's: on hover
|
||||
and slider drag 0.11.0 draws a few fewer for the same input, as master did
|
||||
before #139. A drawn frame is build, render and present as the runtime
|
||||
times them; CPU is the whole process over the script. Every pair drew the
|
||||
frame faster on 0.11.0. Rendering is 52–57% shorter on hover, slider drag
|
||||
and typing, 25% on the wheel, whose frames redraw most of the window; build
|
||||
is 24–39% shorter. Present is no shorter. Process CPU was lower on 0.11.0
|
||||
in every slider and typing pair and ten of twelve hover and wheel pairs.
|
||||
|
||||
## Memory
|
||||
|
||||
Idle, ten seconds after launch with the pointer outside the window; medians of
|
||||
ten launches on 2026-11-10, 0.11.0 taken in turn with 0.10.0. Master before
|
||||
#137 was measured the same way earlier that day:
|
||||
|
||||
| | Private bytes | Working set | 0.10.0, private bytes | Before #137 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| `showcase` | **12.7 MB** | 31.7 MB | 12.9 MB | 15.8 MB |
|
||||
| `notepad` | **9.0 MB** | 25.3 MB | 9.1 MB | 10.6 MB |
|
||||
| `simple` | **6.6 MB** | 19.8 MB | 6.9 MB | 7.6 MB |
|
||||
|
||||
Private bytes are what the process asked the system to back; the working set
|
||||
is what is in RAM, shared pages of system DLLs included. Launches spread by up
|
||||
to 1.0 MB of private bytes. The showcase opens
|
||||
on its Login page; its figure includes a second copy of the glyph atlas,
|
||||
because its splash is a window of its own and the first such window keeps its
|
||||
atlas for the next.
|
||||
|
||||
- **Windows is mostly the system's.** Reaktor, SDL, Nuklear and FreeType
|
||||
allocate 1.1 MB in `bench`; most of the showcase's private bytes are the
|
||||
heaps of the Windows components it loads: UI Automation, the shell, the
|
||||
input method.
|
||||
- **Bitdefender is in every Windows figure here**, about 2.2 MB of each;
|
||||
[the chart's notes](#against-the-others) have the split.
|
||||
|
||||
`tools/vmwalk.c` (`cmake --build build --target vmwalk`) splits another
|
||||
process's private bytes into named buckets.
|
||||
|
||||
### On Linux
|
||||
|
||||
**Linux once started at 123.6 MB, almost none of it Reaktor's.** SDL's X11
|
||||
driver set up OpenGL whatever the renderer, and with no GPU that loads Mesa's
|
||||
software OpenGL and LLVM: 53 MB of libLLVM, 10 of Mesa, 30 of heap.
|
||||
Compiling SDL's GL drivers out brought that build to 4.3 MB;
|
||||
`-DREAKTOR_RENDERERS=opengl` puts them back.
|
||||
|
||||
**Three apps share 21% at most.** `tools/ci/pss.sh` runs `showcase`,
|
||||
`notepad` and `simple` together, idle, on a GitHub `ubuntu-24.04` runner;
|
||||
medians of ten launches. Each carries its own copy of libreaktor and SDL,
|
||||
which a shared library would map once.
|
||||
|
||||
| | PSS | Clean pages of its binary |
|
||||
| --- | --- | --- |
|
||||
| `showcase` | 9,180 KB | 2,796 KB |
|
||||
| `notepad` | 5,957 KB | 2,208 KB |
|
||||
| `simple` | 5,251 KB | 2,164 KB |
|
||||
|
||||
Of the 20,433 KB together, one copy instead of three would save 4,366 KB, or
|
||||
21.3%. That counts each app's own code as library code, so it is an upper
|
||||
bound. Counted page by page, it is 20.2%: `tools/ci/pss-pages.sh` links the
|
||||
three with maps and sorts each resident page of a binary by the object it came
|
||||
from, and sharing would save 4,120 KB of the 20,423. That still takes the
|
||||
largest app's library pages as all three's, and leaves out what the dynamic
|
||||
linker costs each app.
|
||||
|
||||
On a Linux Mint 22.3 desktop (Cinnamon on X11, llvmpipe, a KVM guest with 4
|
||||
cores of the Ryzen 5 4600H) it falls under 20%: `showcase` grows to
|
||||
14,224 KB, while the library pages barely move. Counting every clean page of a
|
||||
binary, sharing saves 4,602 KB of 24,157 KB, or 19.0%; page by page,
|
||||
4,176 KB of 24,200 KB, or 17.3%.
|
||||
|
||||
**Shared, it saves 19%.** The same three on that desktop, five launches each,
|
||||
static and then linked to `libreaktor.so` (`-DREAKTOR_SHARED=ON`):
|
||||
|
||||
| | Static PSS | Shared PSS |
|
||||
| --- | --- | --- |
|
||||
| `showcase` | 8,528 KB | 7,323 KB |
|
||||
| `notepad` | 5,480 KB | 4,280 KB |
|
||||
| `simple` | 4,473 KB | 3,379 KB |
|
||||
| Together | 18,544 KB | 14,941 KB |
|
||||
|
||||
3,603 KB less, 19.4%, near the estimate above. One app on its own pays for
|
||||
the split instead: its resident set is 0.6–0.9 MB larger shared (`simple`
|
||||
8.2 MB against 7.3, `showcase` 18.7 against 18.0), the library's relocations
|
||||
and a second SDL image that no other app is there to share.
|
||||
|
||||
## CPU
|
||||
|
||||
**At rest: 0% of a core** on Windows, Linux and GhostBSD, on every page; macOS
|
||||
settles around 0.3–0.5%, as CoreAnimation wakes the loop now and then for an
|
||||
iteration that draws nothing.
|
||||
|
||||
**Without a GPU, `software` beats Direct3D.** `direct3d11` then falls back to
|
||||
WARP, which rasterizes on threads of its own: drawing `bench` flat out, the
|
||||
process spent 1.78 ms of CPU a frame on WARP against 0.75 ms on `software`
|
||||
(medians of five runs, 2026-10-24), which made software the default.
|
||||
|
||||
**The accessibility tree adds 3.3 µs to a drawn frame** with 82 nodes
|
||||
(2026-10-23).
|
||||
CPU is a percent of one core: with startup over the whole 6-second run, steady
|
||||
from 3 s to 8 s of a 9-second run. Every arm is held to 60 fps and sleeps out
|
||||
the rest of each frame; Kotlin Multiplatform held 59. Each figure is the
|
||||
median of ten runs, the steady-state ones taken in turn across arms; passes
|
||||
differ by up to three points of CPU. Memory is peak private bytes, and CPU the
|
||||
sum, across each app's process tree. Every row was measured on 2026-10-22 with
|
||||
the GPU idle. The sampler counts what an app's own timers miss: `bench` times
|
||||
0.07 ms of work per `direct3d11` frame, where the sampler charged over 10%.
|
||||
`vulkan` falls back to `direct3d11` in this SDL build.
|
||||
|
||||
## Size
|
||||
|
||||
Everything links statically (SDL, plutosvg, plutovg, Nuklear, Onlay,
|
||||
FreeType, and mojibake and kb_text_shape with Text), so only the C runtime
|
||||
loads from outside. The Windows binary's icon is a 125 KB resource of nine
|
||||
sizes, built from the SVG by `tools/mkicon.c`.
|
||||
| Artifact | Bytes |
|
||||
| --- | --- |
|
||||
| Windows | 2,473,984 |
|
||||
| Linux, stripped | 3,967,504 |
|
||||
| macOS, stripped | 3,242,248 |
|
||||
| GhostBSD, stripped | 2,793,248 |
|
||||
| Web bundle (Windows emsdk) | 1,389,356 |
|
||||
| Web bundle (Linux emsdk) | 1,389,186 |
|
||||
| Web bundle (macOS emsdk) | 1,389,145 |
|
||||
| Web bundle (GhostBSD emsdk) | 1,389,525 |
|
||||
|
||||
Nuklear is compiled with `-Os` (`/Os` with MSVC): the stripped shared
|
||||
libreaktor on Linux x86-64 goes from 1,880,624 bytes at `-O3` to 1,737,264,
|
||||
and Nuklear's own code from 306,649 to 168,042. `bench --no-vsync --video
|
||||
dummy` on the Linux Mint desktop above, median of seven runs, CPU time a frame:
|
||||
|
||||
| Build | `-O3` | `-Os`, three rounds |
|
||||
| --- | --- | --- |
|
||||
| shared | 563 µs | 574, 563, 528 µs |
|
||||
| static | 527 µs | 548, 523, 511 µs |
|
||||
|
||||
The rounds spread wider than the change. Every showcase tab in both themes,
|
||||
`notepad` and `simple` draw and dump byte for byte as they did at `-O3`.
|
||||
|
||||
**With MSVC, a Release build is link-time optimized** (`REAKTOR_LTO`),
|
||||
Reaktor and SDL compiled as one program. `showcase.exe` grows from
|
||||
3,234,304 bytes to 3,385,344 (4.7%). Without it, SDL's software rasterizer
|
||||
ran faster or slower as the code linked before it changed size; with it,
|
||||
on 2026-11-10 against 0.10.0, `bench --no-vsync` renders a frame 8.9%
|
||||
faster (every one of twelve runs) and the showcase's pages, drawn every
|
||||
frame, 4–8% faster. Pixels and `--a11y-dump` are unchanged. Its static
|
||||
library holds objects only the same compiler can link, so
|
||||
`tools/libreaktor-pkg.sh` and the Windows and macOS releases build one with
|
||||
it off.
|
||||
|
||||
**With Apple Clang it is on as well**; with GCC and Clang on Linux it stays
|
||||
off. On GitHub runners on 2026-11-10, a CI job (since removed) built each
|
||||
twice and ran `bench --renderer software --no-vsync` ten times each way, in turn; shots and dumps were the same both
|
||||
ways:
|
||||
|
||||
| Compiler | Render, 64 boxes | 512 boxes | `showcase` |
|
||||
| --- | --- | --- | --- |
|
||||
| GCC 12.2, Linux x86-64 | 0.41 → 0.38 ms (10 of 10 faster) | 0.65 → 0.61 ms (10 of 10) | +84,936 bytes (2.0%) |
|
||||
| Clang 14.0, Linux x86-64 | 0.22 → 0.22 ms (2 of 10) | 0.35 → 0.34 ms (9 of 10) | +342,264 bytes (8.6%) |
|
||||
| Apple Clang 17.0, macOS arm64 | 0.59 → 0.56 ms (9 of 10) | 0.865 → 0.795 ms (9 of 10) | +225,120 bytes (6.8%) |
|
||||
|
||||
With it, GCC also warns 69 times more, in kb_text_shape and FreeType, and
|
||||
Clang on Linux gains nothing for its size. Apple Clang was measured on arm64
|
||||
only.
|
||||
|
||||
SDL's GPU API is left out unless `REAKTOR_SHADERS` is on. Built in, it costs
|
||||
the software renderer too: SDL then loads the Vulkan loader, every installed
|
||||
Vulkan driver and LLVM, and the Diagnostics page's "window and renderer" step
|
||||
goes from +0.2 MB private to +34.4 MB. On the same desktop, the shared build,
|
||||
`bench --no-vsync`, five runs each, both on the software backend:
|
||||
|
||||
| `REAKTOR_SHADERS` | A frame on the display | Private |
|
||||
| --- | --- | --- |
|
||||
| `OFF` | 2.08–2.35 ms | 5.0 MB |
|
||||
| `ON` | 13.59–16.31 ms | 63.1 MB |
|
||||
|
||||
The stripped `libreaktor-sdl3.so` is 2,659,344 bytes without it and 2,950,704
|
||||
with it. With `--video dummy`, where nothing reaches a display, the frame costs
|
||||
563–622 µs of CPU without it and 588–740 µs with it.
|
||||
The older single-executable build, on each platform. Everything links
|
||||
statically — SDL, libcss, plutosvg, plutovg, Nuklear, Onlay, and mojibake and
|
||||
kb_text_shape with Text — so only the C runtime loads from outside. The web
|
||||
bundles agree within 211 bytes on Windows, Linux and macOS (emscripten 6.0.9),
|
||||
and 380 with GhostBSD's emscripten 6.0.3; the Linux one is 1,221,689 bytes of
|
||||
`.wasm`, 86,001 of assets, 80,045 of `.js` and 1,451 of `.html`. The Windows
|
||||
binary's icon is a 125 KB resource of nine sizes, built from the SVG by
|
||||
`tools/mkicon.c`.
|
||||
|
||||
### Modules
|
||||
|
||||
`showcase.exe` on 2026-11-10, each module off in turn:
|
||||
`showcase`, each module off in turn; native on the Windows machine below, web
|
||||
on Windows emsdk 6.0.9.
|
||||
|
||||
| | Default | Module off | Saved |
|
||||
| `showcase` | Default | Module off | Saved |
|
||||
| --- | --- | --- | --- |
|
||||
| Accessibility bridges | 3,385,344 | 3,366,400 | 18,944 (0.56%) |
|
||||
| Locale | 3,385,344 | 3,361,280 | 24,064 (0.71%) |
|
||||
| Text | 3,385,344 | 2,764,288 | 621,056 (18.3%) |
|
||||
| `.exe`, accessibility bridges | 3,480,576 | 3,465,216 | 15,360 (0.44%) |
|
||||
| `.exe`, Locale | 3,480,576 | 3,466,240 | 14,336 (0.41%) |
|
||||
| `.exe`, Text | 3,480,576 | 2,692,608 | 787,968 (22.6%) |
|
||||
| `.wasm` + `.js`, accessibility bridges | 1,968,979 | 1,966,141 | 2,838 (0.14%) |
|
||||
| `.wasm` + `.js`, Locale | 1,968,979 | 1,953,842 | 15,137 (0.77%) |
|
||||
| `.wasm` + `.js`, Text | 1,968,979 | 1,464,437 | 504,542 (25.6%) |
|
||||
| `.data`, Locale | 1,810,099 | 44,478 | 1,765,621 (97.5%) |
|
||||
| `.data`, Text | 1,810,099 | 51,411 | 1,758,688 (97.2%) |
|
||||
|
||||
**The bridges are small**; turned off, they drop libraries more than bytes.
|
||||
Pixels and `--a11y-dump` stay byte-identical, and only a screen reader
|
||||
notices: UI Automation finds 99 elements on the Buttons page, none without
|
||||
them.
|
||||
|
||||
**Text is mostly tables and a font.** kb_text_shape is 95 KB of code and
|
||||
391 KB of tables, and mojibake 19 KB of code and 180 KB of line-breaking and
|
||||
bidirectional data; on the web, the `.data` it adds is M PLUS 1p, 1,758,688
|
||||
bytes. Locale is 24 KB of the executable and 7,581 bytes of catalogs;
|
||||
compiled in (`-DREAKTOR_LOCALE_EMBED=ON`), `showcase.exe` is 3,393,024 bytes.
|
||||
**Text is mostly tables and a font.** kb_text_shape is 113 KB of code and
|
||||
443 KB of tables, and mojibake adds its line-breaking and bidirectional data;
|
||||
the `.data` it saves is M PLUS 1p, 1,758,688 bytes. Locale is 14 KB of code
|
||||
and 6,933 bytes of catalogs; compiled in (`-DREAKTOR_LOCALE_EMBED=ON`),
|
||||
`showcase.exe` is 3,487,232 bytes.
|
||||
|
||||
**Text costs memory once it draws.** Medians of private bytes over ten
|
||||
launches: Diagnostics is 8.0 MB with every module, 7.6 MB without Text and
|
||||
8.2 MB without Locale — Text's 0.4 MB is kb_text_shape's tables, which are not
|
||||
`const` and so are committed untouched. Translations is 10.8 MB against 7.7 MB
|
||||
without Text: M PLUS 1p held open, what kb_text_shape parses from it, the
|
||||
glyph texture and the caches.
|
||||
|
||||
## Memory
|
||||
|
||||
Idle on the Login page.
|
||||
|
||||
| | Windows | Linux | macOS | GhostBSD |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| Committed / private / footprint | **9.0 MB** | **4.3 MB** | **~30 MB** | **5.1 MB** |
|
||||
| Resident / working set | **29–34 MB** | **11.4 MB** | **33–36 MB** | **11.9 MB** |
|
||||
|
||||
Committed is what the process asked the system to back; resident is what is
|
||||
in RAM, shared library pages included.
|
||||
|
||||
- **Linux started at 123.6 MB, almost none of it Reaktor's.** SDL's X11 driver
|
||||
set up OpenGL whatever the renderer, and with no GPU that loads Mesa's
|
||||
software OpenGL and LLVM: 53 MB of libLLVM, 10 of Mesa, 30 of heap.
|
||||
Compiling SDL's GL drivers out brought it to 4.3 MB; `-DREAKTOR_SDL_GL=ON`
|
||||
puts them back.
|
||||
- **GhostBSD lands beside Linux.** Of its 5.1 MB, 2.5 MB is SDL's framebuffer
|
||||
(960×680×4), shared with the X server. Its figures come from `ps` and
|
||||
`procstat -v`, macOS's from `vmmap`; `reaktor_process_memory` reads only
|
||||
Windows and Linux.
|
||||
- **macOS is ~7× Linux, outside this code.** `vmmap` splits the ~30 MB into
|
||||
~15 MB of Cocoa floor and ~12 MB of heap, mostly three ~2.5 MB bitmaps: SDL's
|
||||
render target, its staging copy and the atlas. Without a renderer rewrite
|
||||
the floor is 26–28 MB, and Retina pushes committed toward 50 MB.
|
||||
|
||||
Windows varies by about 2 MB between identical runs, so compare ten launches.
|
||||
`tools/vmwalk.c` (`cmake --build build --target vmwalk`) splits another
|
||||
process's private bytes into named buckets.
|
||||
|
||||
## CPU
|
||||
|
||||
**At rest: 0% of a core** on Windows, Linux and GhostBSD, on every page; macOS
|
||||
settles around **0.3–0.5%**, as CoreAnimation wakes the loop now and then for
|
||||
an iteration that draws nothing.
|
||||
|
||||
Redrawing continuously at 960×680, p10–p90 of 31 samples:
|
||||
|
||||
| Page | Windows | Linux | macOS | GhostBSD |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| Login | 6.8–6.9 ms/frame | 6.2–6.7 ms/frame | 17.5–20.5 ms/frame | 6.2–8.3 ms/frame |
|
||||
| Buttons (the busiest) | 11.5–12.2 ms/frame | 11.7–13.0 ms/frame | 29.6–30.2 ms/frame | 13.4–15.3 ms/frame |
|
||||
|
||||
The same rasterizer runs on all four. macOS also uploads the bitmap to a
|
||||
Metal texture to present it. On GhostBSD most of a frame is the present, a
|
||||
software blit into VMware's framebuffer: 6.7 ms of Login's 7.1 ms, 11.1 ms of
|
||||
Buttons' 14.8.
|
||||
|
||||
The accessibility tree adds **4.2 µs** to a drawn frame (82 nodes). Without a
|
||||
GPU, `direct3d11` falls back to WARP and a frame goes from 4.7 ms to
|
||||
**20.3 ms**, which made software the default. With a GPU, `direct3d12` and
|
||||
`opengl` take less CPU; see **Against the others**.
|
||||
|
||||
## What it needs to run
|
||||
|
||||
**No GPU**, and **7–13 MB of RAM** on Windows. The default look is compiled
|
||||
in, so a program needs no files beside it until it uses other Ionicons,
|
||||
Simple.css, the catalogs or the Japanese font, found under a `.reaktor-root`
|
||||
marker beside it or up to two folders above. The web build packs those into
|
||||
its `.data` and needs an HTTP server, since a `file://` page cannot fetch the
|
||||
`.wasm`.
|
||||
**No GPU**, and about **10 MB of RAM**. The default look is compiled in, so a
|
||||
program needs no files beside it until it uses other Ionicons, Simple.css, the
|
||||
catalogs or the Japanese font, found under a `.reaktor-root` marker beside it
|
||||
or up to two folders above. The web build packs those into its `.data` and needs an HTTP server,
|
||||
since a `file://` page cannot fetch the `.wasm`.
|
||||
|
||||
## Where the numbers came from
|
||||
|
||||
- **Windows**: a Lenovo laptop with an AMD Ryzen 5 4600H (6 cores, 12
|
||||
threads), a GeForce RTX 2060 and a 1920×1080 120 Hz display at 100%
|
||||
scaling, on Windows 11 Pro (build 26300), x64. MSVC 14.44 (Visual Studio
|
||||
2022 Build Tools) Release builds, link-time optimized; **Against the others** in the 800×600
|
||||
window every arm asks for.
|
||||
- **Linux**: the Linux Mint 22.3 desktop above, and for **Three apps share**
|
||||
a GitHub `ubuntu-24.04` runner, x86_64, in a Debian 12 container, GCC
|
||||
Release, Xvfb, no GPU.
|
||||
- **Windows** — 11 Pro (26200), x64, MSVC Release, Ryzen 5 4600H (6 cores,
|
||||
12 threads), GeForce RTX 2060, 1920×1080 at 120 Hz, no scaling. Sizes and
|
||||
**Modules** with MSVC 14.44 (Visual Studio 2022 Build Tools) and emscripten
|
||||
6.0.9; **Against the others** in the 800×600 window every arm asks for, with
|
||||
Electron 44.3.0 on Node 22, Flutter 3.38.0, and Compose Multiplatform 1.12.0
|
||||
on Kotlin 2.4.20 and Temurin JDK 21.
|
||||
- **Linux** — Debian 13, x86_64, GCC Release, X11, no GPU.
|
||||
- **macOS** — 11.7 Big Sur, Intel iMac, Apple Clang 12, 1024×768 non-Retina,
|
||||
built with `-DCMAKE_OSX_SYSROOT=…/MacOSX11.3.sdk`.
|
||||
- **GhostBSD** — 26.1-R15.0p2, x86_64, Clang 19.1.7, X11, VMware, no 3D.
|
||||
|
||||
The **Diagnostics** page shows the renderer, the frame breakdown and the
|
||||
resident set live; reproduce any of this there.
|
||||
|
||||
+37
-31
@@ -3,47 +3,53 @@
|
||||
<rect x="30" y="30" width="715" height="500" rx="14" fill="#353535"/>
|
||||
<text x="70" y="90" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="31" font-weight="600" fill="#ffffff">Memory</text>
|
||||
<text x="70" y="116" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="14" fill="#8e8e8e">private bytes, peak, whole process tree</text>
|
||||
<rect x="99.5" y="448.868" width="46" height="3.13205" fill="#56c7ff"/>
|
||||
<text x="122.5" y="418.868" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">8.8 MB</text>
|
||||
<rect x="99.5" y="448.612" width="46" height="3.38803" fill="#56c7ff"/>
|
||||
<text x="122.5" y="418.612" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">9.5 MB</text>
|
||||
<text x="122.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">Software</text>
|
||||
<path d="M205.5 452 v-36.8877 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v36.8877 z" fill="#56c7ff"/>
|
||||
<text x="228.5" y="379.112" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">120.5 MB</text>
|
||||
<text x="228.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">D3D12</text>
|
||||
<path d="M311.5 452 v-18.4513 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v18.4513 z" fill="#56c7ff"/>
|
||||
<text x="334.5" y="397.549" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">68.7 MB</text>
|
||||
<text x="334.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">OpenGL</text>
|
||||
<path d="M417.5 452 v-41.2298 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v41.2298 z" fill="#6e7a82"/>
|
||||
<text x="440.5" y="374.77" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">132.7 MB</text>
|
||||
<text x="440.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">Flutter</text>
|
||||
<path d="M523.5 452 v-49.2379 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v49.2379 z" fill="#6e7a82"/>
|
||||
<text x="546.5" y="366.762" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">155.2 MB</text>
|
||||
<text x="546.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">Electron</text>
|
||||
<path d="M187.833 452 v-15.1841 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v15.1841 z" fill="#56c7ff"/>
|
||||
<text x="210.833" y="400.816" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">59.4 MB</text>
|
||||
<text x="210.833" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">D3D11</text>
|
||||
<path d="M276.167 452 v-37.6164 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v37.6164 z" fill="#56c7ff"/>
|
||||
<text x="299.167" y="378.384" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">122.3 MB</text>
|
||||
<text x="299.167" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">D3D12</text>
|
||||
<path d="M364.5 452 v-18.9822 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v18.9822 z" fill="#56c7ff"/>
|
||||
<text x="387.5" y="397.018" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">70.1 MB</text>
|
||||
<text x="387.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">OpenGL</text>
|
||||
<path d="M452.833 452 v-26.3646 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v26.3646 z" fill="#6e7a82"/>
|
||||
<text x="475.833" y="389.635" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">90.8 MB</text>
|
||||
<text x="475.833" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">Flutter</text>
|
||||
<path d="M541.167 452 v-50.1878 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v50.1878 z" fill="#6e7a82"/>
|
||||
<text x="564.167" y="365.812" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">157.6 MB</text>
|
||||
<text x="564.167" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">Electron</text>
|
||||
<path d="M629.5 452 v-232 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v232 z" fill="#6e7a82"/>
|
||||
<text x="652.5" y="184" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">668.7 MB</text>
|
||||
<text x="652.5" y="184" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">667.4 MB</text>
|
||||
<text x="652.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">KMP</text>
|
||||
<line x1="60" y1="452.5" x2="715" y2="452.5" stroke="#4a4a4a" stroke-width="1"/>
|
||||
<rect x="755" y="30" width="715" height="500" rx="14" fill="#353535"/>
|
||||
<text x="795" y="90" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="31" font-weight="600" fill="#ffffff">CPU at 60 fps</text>
|
||||
<text x="795" y="116" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="14" fill="#8e8e8e">percent of one core, steady state (3 s to 8 s)</text>
|
||||
<path d="M824.5 452 v-42.5714 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v42.5714 z" fill="#56c7ff"/>
|
||||
<text x="847.5" y="373.429" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">6.0%</text>
|
||||
<path d="M824.5 452 v-36.9752 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v36.9752 z" fill="#56c7ff"/>
|
||||
<text x="847.5" y="379.025" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">6.0%</text>
|
||||
<text x="847.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">Software</text>
|
||||
<path d="M930.5 452 v-36.0952 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v36.0952 z" fill="#56c7ff"/>
|
||||
<text x="953.5" y="379.905" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">5.2%</text>
|
||||
<text x="953.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">D3D12</text>
|
||||
<path d="M1036.5 452 v-41.7619 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v41.7619 z" fill="#56c7ff"/>
|
||||
<text x="1059.5" y="374.238" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">5.9%</text>
|
||||
<text x="1059.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">OpenGL</text>
|
||||
<path d="M1142.5 452 v-117.857 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v117.857 z" fill="#6e7a82"/>
|
||||
<text x="1165.5" y="298.143" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">15.3%</text>
|
||||
<text x="1165.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">Flutter</text>
|
||||
<path d="M1248.5 452 v-161.571 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v161.571 z" fill="#6e7a82"/>
|
||||
<text x="1271.5" y="254.429" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">20.7%</text>
|
||||
<text x="1271.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">Electron</text>
|
||||
<path d="M912.833 452 v-67.1432 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v67.1432 z" fill="#56c7ff"/>
|
||||
<text x="935.833" y="348.857" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">10.3%</text>
|
||||
<text x="935.833" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">D3D11</text>
|
||||
<path d="M1001.17 452 v-29.5043 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v29.5043 z" fill="#56c7ff"/>
|
||||
<text x="1024.17" y="386.496" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">5.0%</text>
|
||||
<text x="1024.17" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">D3D12</text>
|
||||
<path d="M1089.5 452 v-29.5043 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v29.5043 z" fill="#56c7ff"/>
|
||||
<text x="1112.5" y="386.496" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">5.0%</text>
|
||||
<text x="1112.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="600" fill="#ffffff">OpenGL</text>
|
||||
<path d="M1177.83 452 v-105.138 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v105.138 z" fill="#6e7a82"/>
|
||||
<text x="1200.83" y="310.862" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">15.6%</text>
|
||||
<text x="1200.83" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">Flutter</text>
|
||||
<path d="M1266.17 452 v-179.491 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v179.491 z" fill="#6e7a82"/>
|
||||
<text x="1289.17" y="236.509" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">26.1%</text>
|
||||
<text x="1289.17" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">Electron</text>
|
||||
<path d="M1354.5 452 v-232 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v232 z" fill="#6e7a82"/>
|
||||
<text x="1377.5" y="184" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">29.4%</text>
|
||||
<text x="1377.5" y="184" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="18" font-weight="600" fill="#ffffff">33.5%</text>
|
||||
<text x="1377.5" y="478" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" font-weight="400" fill="#b9b9b9">KMP</text>
|
||||
<line x1="785" y1="452.5" x2="1440" y2="452.5" stroke="#4a4a4a" stroke-width="1"/>
|
||||
<text x="40" y="562" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="15" fill="#b9b9b9">Drawing 64 rotating boxes at 60 fps in an 800×600 window. Lower is better in both panels.</text>
|
||||
<text x="40" y="586" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="13" fill="#8e8e8e">Three Reaktor renderers (0.11.0) measured 2026-11-11, Electron 2026-11-09, Flutter and Kotlin Multiplatform 2026-10-24, all on the same machine — details in benchmarks/BENCHMARKS.md.</text>
|
||||
<text x="40" y="586" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="13" fill="#8e8e8e">Four Reaktor renderers against the alternatives from other tech stacks, on the same machine — details in benchmarks/BENCHMARKS.md.</text>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 7.9 KiB |
@@ -1,314 +0,0 @@
|
||||
# Requests from PapayaPlayer
|
||||
|
||||
What PapayaPlayer (a media player built on Reaktor) needs from Reaktor,
|
||||
checked against revision `5a8b7f3`. Each section says what is missing, why the
|
||||
app cannot do it on its own, a suggested shape and how to check it. No
|
||||
Reaktor code is changed here; this file is the request.
|
||||
|
||||
Contents:
|
||||
|
||||
1. [Linear gradients in CSS](#1-linear-gradients-in-css)
|
||||
2. [An option for HDR output](#2-an-option-for-hdr-output)
|
||||
3. [SDL's GPU renderer, for app shaders](#3-sdls-gpu-renderer-for-app-shaders)
|
||||
4. [The layout stays stale after a resize](#4-the-layout-stays-stale-after-a-resize)
|
||||
5. [A quiet list header](#5-a-quiet-list-header)
|
||||
|
||||
## 1. Linear gradients in CSS
|
||||
|
||||
**What PapayaPlayer needs:** `linear-gradient()` as a background in Reaktor
|
||||
stylesheets, so the "accent" controls style can be written in CSS. Decided
|
||||
2026-10-30 (TECH-STACK.md, UI direction): gradients come from Reaktor's CSS,
|
||||
not from PapayaPlayer drawing them itself.
|
||||
|
||||
Reaktor revision checked: `5a8b7f3` (the submodule in PapayaPlayer).
|
||||
|
||||
### Where it is used
|
||||
|
||||
From `design/mockups.html`, screen 02 (video, accent) and the audio bars:
|
||||
|
||||
| Element | Gradient |
|
||||
|---|---|
|
||||
| Seek bar fill, volume fill | horizontal / vertical, guava `#ff3d6e` to papaya `#ff7a45` |
|
||||
| Play button (pill), folder and file pills | horizontal, same colours, with `border-radius` |
|
||||
| Chosen row of the settings menu | horizontal, the same colours at 25 % / 18 % alpha |
|
||||
| Shade behind the control bars (both styles) | vertical, black at 55 - 75 % to transparent |
|
||||
|
||||
So: two colour stops are enough for all of it; angles `to right`, `to top`
|
||||
and `to bottom`; colours with alpha; rounded corners.
|
||||
|
||||
### What Reaktor has today
|
||||
|
||||
- `background` and `background-color` take a colour only (`core/css/css.c`,
|
||||
`K_BG`, around line 788: it takes the last colour in the value).
|
||||
- Boxes are filled with one colour by `reaktor_fill_round()`
|
||||
(`core/render/draw.c`, around line 553), called from `core/ui/declare.c`
|
||||
around line 478 with `s.bg`.
|
||||
- Nuklear already has `nk_fill_rect_multi_color()` (a colour per corner),
|
||||
which draws a two-stop gradient on a square rectangle.
|
||||
|
||||
### Suggested shape
|
||||
|
||||
1. **Parse** `background: linear-gradient(<angle>, <colour> [<pos>], <colour> [<pos>], ...)`
|
||||
with `to right | to left | to top | to bottom` and `<n>deg`. Store it in the
|
||||
style next to `bg` (say `bg2[4]` plus an angle, or a small stop list).
|
||||
Falling back to the first stop where a gradient is not drawable keeps old
|
||||
code paths working.
|
||||
2. **Draw** in `reaktor_fill_round()` (or a sibling): for square corners,
|
||||
`nk_fill_rect_multi_color()`; for rounded corners, the rounded shape's
|
||||
vertices coloured by their position along the gradient axis (the corner
|
||||
fans already exist for the solid fill).
|
||||
3. **Hover / active states** take gradients the same way (`core/ui/style_map.c`
|
||||
copies `bg` today).
|
||||
4. **Inspector:** show the gradient in the background row (`runtime/inspector.c`).
|
||||
|
||||
More than two stops and other angles are nice to have; PapayaPlayer's design
|
||||
needs only two stops and the four directions.
|
||||
|
||||
### Checks
|
||||
|
||||
- `tests/csstest.c`: the parse of each form above, and that a plain colour still
|
||||
parses as before.
|
||||
- The showcase with a gradient button, pill and progress bar, rounded and
|
||||
square, in `--shot` output: the colours at both ends match the stops, no seam
|
||||
at the corners.
|
||||
- Colours with alpha over another fill blend as solid ones do.
|
||||
|
||||
### In PapayaPlayer once it exists
|
||||
|
||||
`app/main.c`'s stylesheet gets the accent classes (`.accent .seek-fill`,
|
||||
`.accent .play`, ...); the control code itself does not change.
|
||||
|
||||
## 2. An option for HDR output
|
||||
|
||||
**What PapayaPlayer needs:** a launch option that creates Reaktor's renderer
|
||||
with an HDR output colorspace, so HDR10 video can light up an HDR screen.
|
||||
Today HDR video is tone-mapped down to SDR on every screen.
|
||||
|
||||
Reaktor revision checked: `5a8b7f3` (the submodule in PapayaPlayer).
|
||||
|
||||
### Why it has to be Reaktor
|
||||
|
||||
SDL fixes a renderer's output colorspace when the renderer is created
|
||||
(`SDL_PROP_RENDERER_CREATE_OUTPUT_COLORSPACE_NUMBER`). Nothing can change
|
||||
it afterwards. Reaktor creates the window and renderer itself, in
|
||||
`runtime/app.c` (around line 842) with `SDL_CreateWindowAndRenderer()`, which
|
||||
takes no properties. The app never sees renderer creation, so it cannot ask
|
||||
for HDR. Secondary windows (`runtime/window.c` around line 184) are created
|
||||
the same way.
|
||||
|
||||
This was found in PapayaPlayer's phase 0 spike S3 (`spikes/RESULTS.md`).
|
||||
|
||||
### What already works without it
|
||||
|
||||
- SDL's Direct3D / Metal renderers take P010 textures with a BT.2020 / PQ
|
||||
colorspace, convert YUV themselves, and tone-map HDR10 to the SDR output.
|
||||
- PapayaPlayer now gives each HDR10 texture a white point (203 cd/m²,
|
||||
BT.2408) and a headroom from the content's MaxCLL or mastering peak
|
||||
(`SDL_PROP_TEXTURE_CREATE_SDR_WHITE_POINT_FLOAT`,
|
||||
`SDL_PROP_TEXTURE_CREATE_HDR_HEADROOM_FLOAT`). Without a headroom, SDL clips
|
||||
everything brighter than white.
|
||||
|
||||
So SDR screens are handled. Only real HDR output is missing.
|
||||
|
||||
### Suggested option
|
||||
|
||||
```c
|
||||
/* in reaktor_launch */
|
||||
int hdr; /* 1: ask for an HDR output where the display and renderer have one */
|
||||
```
|
||||
|
||||
When it is set and the renderer is not software:
|
||||
|
||||
1. Create the window first, then the renderer with properties:
|
||||
```c
|
||||
SDL_PropertiesID p = SDL_CreateProperties();
|
||||
SDL_SetPointerProperty(p, SDL_PROP_RENDERER_CREATE_WINDOW_POINTER, win);
|
||||
SDL_SetStringProperty(p, SDL_PROP_RENDERER_CREATE_NAME_STRING, name); /* the --renderer choice */
|
||||
SDL_SetNumberProperty(p, SDL_PROP_RENDERER_CREATE_OUTPUT_COLORSPACE_NUMBER,
|
||||
SDL_COLORSPACE_SRGB_LINEAR); /* scRGB; SDL_COLORSPACE_HDR10 also works on D3D */
|
||||
ren = SDL_CreateRendererWithProperties(p);
|
||||
```
|
||||
If that fails, fall back to the normal SDR renderer as today.
|
||||
2. `SDL_COLORSPACE_SRGB_LINEAR` is the simplest choice for the UI. SDL converts
|
||||
sRGB draw colours and textures into it, scaled by the display's SDR white
|
||||
level (`SDL_PROP_RENDERER_SDR_WHITE_POINT_FLOAT`). Reaktor's widgets
|
||||
should then look as they do now, but this needs checking against
|
||||
Reaktor's own pixels (`--shot`).
|
||||
3. Follow the display: Windows lets the user switch HDR on and off at any
|
||||
time, and a window can move between an HDR and an SDR monitor. SDL reports
|
||||
both with `SDL_EVENT_WINDOW_HDR_STATE_CHANGED`; the renderer's
|
||||
`SDL_PROP_RENDERER_HDR_ENABLED_BOOLEAN` and `..._HDR_HEADROOM_FLOAT` give
|
||||
the current state. On an SDR display a linear output still works: SDL
|
||||
tone-maps into it as it does now.
|
||||
4. The same for secondary windows (`runtime/window.c`).
|
||||
|
||||
The software renderer has no HDR output, so the option does nothing there.
|
||||
|
||||
### Checks
|
||||
|
||||
- `--shot` / `--a11y-dump` of the showcase with the option on and off, on an
|
||||
SDR display: the pixels should match within rounding. The linear output
|
||||
path changes how blending is done, which may show in anti-aliased edges and
|
||||
in alpha.
|
||||
- On an HDR display (Windows with HDR on, or a Mac with an XDR screen): the UI
|
||||
at normal brightness, and an HDR10 P010 texture brighter than white.
|
||||
- Toggle HDR in Windows settings while running: the window keeps drawing.
|
||||
|
||||
### In PapayaPlayer once it exists
|
||||
|
||||
`app/main.c` sets `.hdr = 1` in its `reaktor_launch`. Nothing else changes:
|
||||
the HDR10 textures already carry their colorspace, white point and headroom.
|
||||
|
||||
|
||||
## 3. SDL's GPU renderer, for app shaders
|
||||
|
||||
**What PapayaPlayer needs:** a way to run its own fragment shaders when
|
||||
drawing video: BT.2390 tone mapping on SDR screens (SDL's built-in operator
|
||||
is not BT.2390), full chroma for 4:2:2 / 4:4:4 (SDL has no planar
|
||||
4:2:2 / 4:4:4 textures, so PapayaPlayer averages the chroma down to 4:2:0
|
||||
today), and later Lanczos scaling and deinterlacing.
|
||||
|
||||
**Why it has to be Reaktor:** `SDL_CreateGPURenderState()` (SDL 3.4) only
|
||||
works on a renderer backed by an SDL GPU device, that is SDL's `gpu`
|
||||
renderer. Reaktor builds SDL with `SDL_GPU` off, so the renderer is always
|
||||
the native Direct3D / Metal / OpenGL one (PapayaPlayer spike S4,
|
||||
`spikes/RESULTS.md`).
|
||||
|
||||
**Suggested option:** build SDL with `SDL_GPU` on, and a launch field such as
|
||||
`const char *renderer; /* NULL: as now; "gpu": SDL's GPU renderer */` passed
|
||||
as `SDL_HINT_RENDER_DRIVER` (or as the renderer name) before the window and
|
||||
renderer are created. With it, PapayaPlayer would create a
|
||||
`SDL_GPURenderState` with its shaders (built from HLSL with SDL_shadercross)
|
||||
and set it while drawing the video texture.
|
||||
|
||||
**Checks:** the showcase under the `gpu` renderer on Windows (D3D12 / Vulkan),
|
||||
macOS (Metal) and Linux (Vulkan) matches the default renderer within
|
||||
rounding; the software fallback still works where no GPU device exists.
|
||||
|
||||
## 4. The layout stays stale after a resize
|
||||
|
||||
**Status:** suspected, not yet confirmed by watching a real window. Found in
|
||||
PapayaPlayer on Windows; worked around there in `eafbafb`.
|
||||
|
||||
### What the user saw
|
||||
|
||||
After resizing PapayaPlayer's window, the window took "several seconds to
|
||||
update". PapayaPlayer was idle at the time (paused, or no file open), so
|
||||
nothing was animating.
|
||||
|
||||
### Why it happens
|
||||
|
||||
Three parts of Reaktor combine:
|
||||
|
||||
1. **Boxes are placed a frame late.** A box gets its rectangle from the
|
||||
previous frame and is found again by its `.name` (CLAUDE.md, "Traps that
|
||||
have cost real time"). The first frame at a new size is therefore laid out
|
||||
against the old sizes.
|
||||
|
||||
2. **A resize asks for exactly one frame.** `SDL_EVENT_WINDOW_RESIZED`,
|
||||
`PIXEL_SIZE_CHANGED`, `EXPOSED`, `MAXIMIZED` and the others set
|
||||
`app->dirty` and `app->must_draw` (`runtime/app.c`, the event switch around
|
||||
lines 981-1010). `must_draw` only stops the frame-hash check
|
||||
(`runtime/app.c` around 1431) from skipping that one frame. Nothing asks
|
||||
for a second one.
|
||||
|
||||
3. **An idle app draws nothing more.** `app_iterate` returns early while
|
||||
`!app->dirty` (`runtime/app.c` around 1690). The stale layout stays on
|
||||
screen until something else marks the window dirty: mouse motion over a
|
||||
hot rectangle, a key, a timer or a wake.
|
||||
|
||||
In PapayaPlayer the next wake is the control bar's auto-hide timer, 2.5 s
|
||||
later. That matches "several seconds". Any Reaktor app with nothing animating
|
||||
should show the same stale frame after a resize, until the next input.
|
||||
|
||||
### Reaktor already handles the same case elsewhere
|
||||
|
||||
The "settle" mechanism exists, but a resize never starts it:
|
||||
|
||||
| Event | What Reaktor does (`runtime/app.c`) |
|
||||
|---|---|
|
||||
| Mouse drag ends | `drag_end()` sets `restore_rate = 2` (around 961) |
|
||||
| Mouse wheel | `restore_rate = 2`, because "Nuklear scrolls a panel at its end, after drawing what it holds" (around 1055) |
|
||||
| Hover redraw | `restore_rate` at least 1 (around 1273) |
|
||||
| Keyboard click release | `restore_rate = 2` (around 1486) |
|
||||
| Window resize | `must_draw = 1` only: **no follow-up frame** |
|
||||
|
||||
At the end of a frame, `restore_rate > 0` counts down, sets `dirty` and calls
|
||||
`reaktor_app_wake()` (around 1637-1645). That is exactly the extra frame a
|
||||
resize needs.
|
||||
|
||||
### Suggested fix in Reaktor
|
||||
|
||||
In the second event switch (the `must_draw` one, around 1000-1010), also
|
||||
schedule a settle frame for the size-changing events:
|
||||
|
||||
```c
|
||||
case SDL_EVENT_WINDOW_RESIZED:
|
||||
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
|
||||
case SDL_EVENT_WINDOW_MAXIMIZED:
|
||||
case SDL_EVENT_WINDOW_RESTORED:
|
||||
case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
|
||||
if (!app->dragging && app->restore_rate < 2) app->restore_rate = 2;
|
||||
break;
|
||||
```
|
||||
|
||||
(`app->must_draw = 1` stays as it is.)
|
||||
|
||||
A more general fix: keep drawing while the layout still moves. After a frame,
|
||||
compare the boxes' rectangles with the previous frame's, and draw again
|
||||
(bounded, e.g. at most 3 frames) while any changed. That would also cover
|
||||
other one-frame-late cases, not just resizes.
|
||||
|
||||
#### How to check it
|
||||
|
||||
- Run a sample (e.g. `showcase`) with nothing animating, resize the window,
|
||||
and stop moving the mouse. Before the fix, boxes that depend on the window
|
||||
size should sit at their old place until the next input; after it, they
|
||||
should settle at once.
|
||||
- The regression oracle: a `--shot` / `--a11y-dump` taken after a scripted
|
||||
`SDL_SetWindowSize` should give the same bounds as one taken from a fresh
|
||||
start at that size.
|
||||
|
||||
### Not covered by this
|
||||
|
||||
- **Lag during the drag itself.** On Windows, the move/size loop is modal.
|
||||
If the window doesn't update *while* the edge is being dragged, that is a
|
||||
separate issue: whether SDL's live-resize callback runs `SDL_AppIterate`
|
||||
under Reaktor's `SDL_HINT_MAIN_CALLBACK_RATE` settings.
|
||||
- Whether Reaktor's own samples show the stale frame has not been checked yet.
|
||||
|
||||
### PapayaPlayer's workaround (remove once Reaktor is fixed)
|
||||
|
||||
`app/main.c`, at the top of `page()`:
|
||||
|
||||
```c
|
||||
/* Reaktor places boxes a frame late, so a new size needs a second frame;
|
||||
* when paused nothing else would draw it until the bar hides. */
|
||||
if (win_w != activity.win_w || win_h != activity.win_h) {
|
||||
activity.win_w = win_w;
|
||||
activity.win_h = win_h;
|
||||
reaktor_wake(app);
|
||||
}
|
||||
```
|
||||
|
||||
Reaktor revision checked: `5a8b7f3` (the submodule in PapayaPlayer).
|
||||
|
||||
## 5. A quiet list header
|
||||
|
||||
**What PapayaPlayer needs:** a `reaktor_list` header row in a dark, low-contrast
|
||||
colour of its own choosing (its playlist uses `--table: #232027` over rows of
|
||||
`#18161b` / `#1d1b21`).
|
||||
|
||||
**What happens today:** `core/ui/views.c` (`reaktor_list`, around line 377)
|
||||
takes `thead`'s background or `--table`, then passes it through
|
||||
`reaktor_visible()` against the page colour and the odd-row colour. A colour
|
||||
that close to the rows counts as not visible, so the header falls back to the
|
||||
accent: PapayaPlayer's playlist gets a bright papaya-orange header row.
|
||||
|
||||
**Suggested shape:** when the stylesheet sets the header colour explicitly
|
||||
(`thead { background-color: ... }` or `--table`), use it as written and keep
|
||||
the visibility fallback only for the built-in default. Or a flag on the spec,
|
||||
such as `.plain_header = 1`, or `.header = 0` to hide the row.
|
||||
|
||||
**Checks:** the showcase's list with `--table` set close to the rows shows that
|
||||
colour in `--shot`; with nothing set, the header looks as it does now.
|
||||
@@ -1,15 +1,10 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(consumer C)
|
||||
|
||||
find_package(reaktor 0.11 REQUIRED)
|
||||
find_package(reaktor 0.7 REQUIRED)
|
||||
|
||||
add_executable(simple WIN32 ../../samples/simple/simple.c)
|
||||
option(CONSUMER_SHARED "Link libreaktor.so instead of libreaktor.a" OFF)
|
||||
if(CONSUMER_SHARED)
|
||||
target_link_libraries(simple PRIVATE reaktor::shared)
|
||||
else()
|
||||
target_link_libraries(simple PRIVATE reaktor::reaktor)
|
||||
endif()
|
||||
target_link_libraries(simple PRIVATE reaktor::reaktor)
|
||||
if(EMSCRIPTEN)
|
||||
set_target_properties(simple PROPERTIES SUFFIX ".html")
|
||||
endif()
|
||||
|
||||
Vendored
-1
Submodule external/gibus deleted from 4a28f722e2
Vendored
+1
-1
Submodule external/kb updated: 7d811ad802...cc63806775
+1
Submodule external/lcui added at 749f907434
+1
Submodule external/mglibs added at 64b57a7275
Vendored
+1
-1
Submodule external/mojibake updated: ad2831dedd...aa3cc68b9b
Vendored
+1
-1
Submodule external/onlay updated: 1e57179742...0c75a1f91b
Vendored
-1
Submodule external/toml-c deleted from 6a38d40418
@@ -103,11 +103,9 @@ typedef struct reaktor_launch {
|
||||
void *user;
|
||||
int remember_window;
|
||||
int single_instance;
|
||||
int draw_every_frame;
|
||||
int skip_same_frames;
|
||||
reaktor_save save_settings;
|
||||
int save_ms;
|
||||
const char *renderer;
|
||||
int hdr;
|
||||
} reaktor_launch;
|
||||
|
||||
typedef struct reaktor_window {
|
||||
@@ -176,7 +174,6 @@ int reaktor_floater_is_open(App *app, int id);
|
||||
int reaktor_tray_open(App *app, const reaktor_tray *tray);
|
||||
void reaktor_tray_check(App *app, int item, int checked);
|
||||
void reaktor_tray_close(App *app);
|
||||
void reaktor_tray_hide_on_minimize(App *app, int on);
|
||||
|
||||
int reaktor_inspector_open(App *app);
|
||||
void reaktor_inspector_close(App *app);
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
enum { REAKTOR_SIDE_TOP = 0, REAKTOR_SIDE_RIGHT, REAKTOR_SIDE_BOTTOM, REAKTOR_SIDE_LEFT };
|
||||
enum { REAKTOR_CORNER_TL = 0, REAKTOR_CORNER_TR, REAKTOR_CORNER_BR, REAKTOR_CORNER_BL };
|
||||
enum { REAKTOR_GRADIENT_NONE = 0, REAKTOR_GRADIENT_ACROSS, REAKTOR_GRADIENT_DOWN };
|
||||
|
||||
typedef struct reaktor_style {
|
||||
unsigned char bg[4];
|
||||
@@ -28,10 +27,6 @@ typedef struct reaktor_style {
|
||||
int font_px;
|
||||
int bold;
|
||||
int matched;
|
||||
|
||||
unsigned char gradient_from[4];
|
||||
unsigned char gradient_to[4];
|
||||
int gradient;
|
||||
} reaktor_style;
|
||||
|
||||
void reaktor_style_get(const char *selector, reaktor_style *out);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef REAKTOR_TEXT_PUBLIC_H
|
||||
#define REAKTOR_TEXT_PUBLIC_H
|
||||
|
||||
/* Where the next line starts, at or before limit; 0 if nowhere. */
|
||||
int reaktor_text_break(const char *s, int len, int limit);
|
||||
int reaktor_text_rtl(const char *s, int len);
|
||||
void reaktor_text_describe(char *buf, int cap);
|
||||
|
||||
@@ -33,9 +33,6 @@ struct reaktor_color reaktor_visible(struct reaktor_color want,
|
||||
struct reaktor_color reaktor_page_color(App *app);
|
||||
struct reaktor_color reaktor_accent_color(App *app);
|
||||
const struct reaktor_user_font *reaktor_font(App *app, int px, int bold);
|
||||
struct reaktor_vec2 reaktor_item_spacing(struct reaktor_context *ctx);
|
||||
struct reaktor_color reaktor_text_color(struct reaktor_context *ctx);
|
||||
const struct reaktor_user_font *reaktor_current_font(struct reaktor_context *ctx);
|
||||
|
||||
struct reaktor_image reaktor_ionicon(App *app, const char *name, int px);
|
||||
struct reaktor_image reaktor_ionicon_exact(App *app, const char *name, int px,
|
||||
@@ -59,10 +56,6 @@ void reaktor_style_frame_pop(struct reaktor_context *ctx, reaktor_style_frame f)
|
||||
void reaktor_fill_round(App *app, struct reaktor_command_buffer *cv,
|
||||
struct reaktor_rect b, float rounding,
|
||||
struct reaktor_color col);
|
||||
void reaktor_fill_gradient(App *app, struct reaktor_command_buffer *cv,
|
||||
struct reaktor_rect b, float rounding,
|
||||
struct reaktor_color from, struct reaktor_color to,
|
||||
int axis);
|
||||
void reaktor_edge_round(App *app, struct reaktor_command_buffer *cv,
|
||||
struct reaktor_rect b, float rounding, float width,
|
||||
struct reaktor_color col);
|
||||
@@ -245,7 +238,6 @@ typedef struct reaktor_diag {
|
||||
int vsync, dark, sheets;
|
||||
const char *aa;
|
||||
float scale, style_ms, build_ms, render_ms, present_ms;
|
||||
float window_ms, atlas_ms, first_frame_ms;
|
||||
float frame_gap_ms;
|
||||
float cpu_ms_per_frame;
|
||||
int hover_gap_ms;
|
||||
|
||||
@@ -17,7 +17,6 @@ enum {
|
||||
enum {
|
||||
REAKTOR_LAY_FILL_X = 1u << 0,
|
||||
REAKTOR_LAY_FILL_Y = 1u << 1,
|
||||
REAKTOR_LAY_FILL = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y,
|
||||
REAKTOR_LAY_WRAP = 1u << 2,
|
||||
REAKTOR_LAY_CENTER_X = 1u << 3,
|
||||
REAKTOR_LAY_CENTER_Y = 1u << 4,
|
||||
|
||||
+408
-445
File diff suppressed because it is too large
Load Diff
@@ -268,35 +268,6 @@ reaktor_a11y_platform_init(reaktor_a11y_action activate,
|
||||
g.ready = 1;
|
||||
}
|
||||
|
||||
/* A control that changed in place: VoiceOver reads checks and selected tabs
|
||||
from the value, as accessibilityValue answers. */
|
||||
static void
|
||||
post_changes(void)
|
||||
{
|
||||
const reaktor_snap_diff *d;
|
||||
reaktor_snap_node n;
|
||||
char buf[REAKTOR_SNAP_TEXT];
|
||||
int i, count = reaktor_snap_diffs(&d);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
ReaktorElement *e;
|
||||
|
||||
if (!reaktor_snap_get(d[i].id, &n, buf, sizeof(buf)) || !(e = element_for(d[i].id)))
|
||||
continue;
|
||||
if (d[i].value ||
|
||||
(d[i].flipped & (REAKTOR_A11Y_CHECKED | REAKTOR_A11Y_EXPANDED)) ||
|
||||
((d[i].flipped & REAKTOR_A11Y_SELECTED) && n.role == REAKTOR_A11Y_TAB))
|
||||
NSAccessibilityPostNotification(e, NSAccessibilityValueChangedNotification);
|
||||
if ((d[i].flipped & REAKTOR_A11Y_SELECTED) && n.role == REAKTOR_A11Y_LISTITEM) {
|
||||
ReaktorElement *up = element_for(n.parent);
|
||||
|
||||
if (up)
|
||||
NSAccessibilityPostNotification(
|
||||
up, NSAccessibilitySelectedChildrenChangedNotification);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_a11y_platform_push(const reaktor_a11y *a, unsigned focus_id)
|
||||
{
|
||||
@@ -311,7 +282,6 @@ reaktor_a11y_platform_push(const reaktor_a11y *a, unsigned focus_id)
|
||||
NSAccessibilityPostNotification(
|
||||
g.root, NSAccessibilityLayoutChangedNotification);
|
||||
}
|
||||
post_changes();
|
||||
|
||||
if (focus_id != last_focus) {
|
||||
last_focus = focus_id;
|
||||
|
||||
+24
-132
@@ -29,7 +29,7 @@ struct reaktor_snap {
|
||||
|
||||
snap_node node[REAKTOR_A11Y_MAX_NODES];
|
||||
int count, first, last;
|
||||
snap_slot slot[SNAP_SLOTS], fresh[SNAP_SLOTS];
|
||||
snap_slot slot[SNAP_SLOTS];
|
||||
char str[SNAP_POOL];
|
||||
int str_used;
|
||||
unsigned focus;
|
||||
@@ -38,9 +38,6 @@ struct reaktor_snap {
|
||||
unsigned want_focus, want_activate;
|
||||
Uint32 window;
|
||||
|
||||
reaktor_snap_diff diff[REAKTOR_SNAP_DIFFS];
|
||||
int ndiff, overflow;
|
||||
|
||||
reaktor_a11y_action activate, focus_action;
|
||||
void *user;
|
||||
};
|
||||
@@ -62,73 +59,23 @@ intern(reaktor_snap *s, const char *t)
|
||||
return at;
|
||||
}
|
||||
|
||||
static int
|
||||
same_text(const reaktor_snap *s, int at, const char *t)
|
||||
{
|
||||
if (at < 0) return !t || !*t;
|
||||
return t && strcmp(s->str + at, t) == 0;
|
||||
}
|
||||
|
||||
static snap_slot *
|
||||
slot_in(snap_slot *slot, unsigned id)
|
||||
slot_of(reaktor_snap *s, unsigned id)
|
||||
{
|
||||
unsigned i = (id * 2654435761u) & (SNAP_SLOTS - 1);
|
||||
|
||||
while (slot[i].id && slot[i].id != id) i = (i + 1) & (SNAP_SLOTS - 1);
|
||||
return &slot[i];
|
||||
while (s->slot[i].id && s->slot[i].id != id) i = (i + 1) & (SNAP_SLOTS - 1);
|
||||
return &s->slot[i];
|
||||
}
|
||||
|
||||
static int
|
||||
find(reaktor_snap *s, unsigned id)
|
||||
{
|
||||
const snap_slot *at = id ? slot_in(s->slot, id) : NULL;
|
||||
const snap_slot *at = id ? slot_of(s, id) : NULL;
|
||||
|
||||
return at && at->id && at->at < s->count ? at->at : -1;
|
||||
}
|
||||
|
||||
/* Before the tree is replaced: what each node the core says changed in place
|
||||
had, against what it has now. */
|
||||
static void
|
||||
diff_tree(reaktor_snap *s, const reaktor_a11y *a, const reaktor_a11y_node *t, int n)
|
||||
{
|
||||
const reaktor_a11y_change *c;
|
||||
int m, i, j;
|
||||
|
||||
memset(s->fresh, 0, sizeof s->fresh);
|
||||
for (i = 0; i < n && i < REAKTOR_A11Y_MAX_NODES; i++) {
|
||||
snap_slot *at = t[i].id ? slot_in(s->fresh, t[i].id) : NULL;
|
||||
|
||||
if (at && !at->id) { at->id = t[i].id; at->at = i; }
|
||||
}
|
||||
c = reaktor_a11y_changes(a, &m);
|
||||
for (i = 0; i < m; i++) {
|
||||
reaktor_snap_diff d;
|
||||
snap_slot *now;
|
||||
const snap_node *o;
|
||||
|
||||
if (c[i].kind != REAKTOR_A11Y_RENAMED && c[i].kind != REAKTOR_A11Y_RESTATED) continue;
|
||||
if ((j = find(s, c[i].id)) < 0) continue;
|
||||
now = slot_in(s->fresh, c[i].id);
|
||||
if (!now->id || now->at < 0) continue;
|
||||
o = &s->node[j];
|
||||
j = now->at;
|
||||
now->at = -1;
|
||||
d.id = c[i].id;
|
||||
d.flipped = o->state ^ t[j].state;
|
||||
d.value = !same_text(s, o->value, t[j].value) || o->num != t[j].num;
|
||||
d.state = t[j].state;
|
||||
d.num = t[j].num;
|
||||
d.lo = t[j].lo;
|
||||
d.hi = t[j].hi;
|
||||
if (!d.value && !d.flipped) continue;
|
||||
if (s->ndiff == REAKTOR_SNAP_DIFFS) {
|
||||
s->overflow = 1;
|
||||
break;
|
||||
}
|
||||
s->diff[s->ndiff++] = d;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
link_tree(reaktor_snap *s)
|
||||
{
|
||||
@@ -137,7 +84,7 @@ link_tree(reaktor_snap *s)
|
||||
memset(s->slot, 0, sizeof s->slot);
|
||||
s->first = s->last = -1;
|
||||
for (i = 0; i < s->count; i++) {
|
||||
snap_slot *at = slot_in(s->slot, s->node[i].id);
|
||||
snap_slot *at = slot_of(s, s->node[i].id);
|
||||
|
||||
if (!at->id) { at->id = s->node[i].id; at->at = i; }
|
||||
s->node[i].first = s->node[i].last = s->node[i].next = -1;
|
||||
@@ -222,13 +169,11 @@ reaktor_snap_update_in(reaktor_snap *s, const reaktor_a11y *a, unsigned focus_id
|
||||
const reaktor_a11y_node *t;
|
||||
|
||||
if (!s || !s->ready) return 0;
|
||||
s->ndiff = s->overflow = 0;
|
||||
reaktor_a11y_changes(a, &m);
|
||||
t = reaktor_a11y_tree(a, &n);
|
||||
if (m == 0 && focus_id == s->focus && !s->stale) return 0;
|
||||
|
||||
SDL_LockMutex(s->lock);
|
||||
if (!s->stale) diff_tree(s, a, t, n);
|
||||
s->str_used = 0;
|
||||
s->count = 0;
|
||||
for (i = 0; i < n && i < REAKTOR_A11Y_MAX_NODES; i++) {
|
||||
@@ -260,7 +205,7 @@ copy_text(const reaktor_snap *s, int at, char **buf, size_t *left)
|
||||
size_t n;
|
||||
|
||||
if (at < 0 || *left < 2) return NULL;
|
||||
/* D-Bus refuses a string that is not valid UTF-8. */
|
||||
/* libdbus aborts on invalid UTF-8. */
|
||||
n = reaktor_utf8_clean(*buf, s->str + at, *left);
|
||||
{
|
||||
const char *out = *buf;
|
||||
@@ -270,81 +215,34 @@ copy_text(const reaktor_snap *s, int at, char **buf, size_t *left)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_snap_diffs_in(reaktor_snap *s, const reaktor_snap_diff **out)
|
||||
{
|
||||
*out = s ? s->diff : NULL;
|
||||
return s ? s->ndiff : 0;
|
||||
}
|
||||
|
||||
static void
|
||||
fill(const reaktor_snap *s, int i, reaktor_snap_node *out, char *buf, size_t cap)
|
||||
{
|
||||
const snap_node *d = &s->node[i];
|
||||
size_t left = cap;
|
||||
char *at = buf;
|
||||
|
||||
out->id = d->id; out->parent = d->parent;
|
||||
out->role = d->role; out->level = d->level;
|
||||
out->state = d->state;
|
||||
out->x = d->x; out->y = d->y; out->w = d->w; out->h = d->h;
|
||||
out->num = d->num; out->lo = d->lo;
|
||||
out->hi = d->hi; out->step = d->step;
|
||||
out->name = copy_text(s, d->name, &at, &left);
|
||||
out->value = copy_text(s, d->value, &at, &left);
|
||||
out->keys = copy_text(s, d->keys, &at, &left);
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_snap_get_in(reaktor_snap *s, unsigned id, reaktor_snap_node *out,
|
||||
char *buf, size_t cap)
|
||||
{
|
||||
int i;
|
||||
int i, ok = 0;
|
||||
|
||||
memset(out, 0, sizeof(*out));
|
||||
if (!s || !s->ready) return 0;
|
||||
SDL_LockMutex(s->lock);
|
||||
i = find(s, id);
|
||||
if (i >= 0) fill(s, i, out, buf, cap);
|
||||
SDL_UnlockMutex(s->lock);
|
||||
return i >= 0;
|
||||
}
|
||||
if (i >= 0) {
|
||||
const snap_node *d = &s->node[i];
|
||||
size_t left = cap;
|
||||
char *at = buf;
|
||||
|
||||
static int
|
||||
kids(const reaktor_snap *s, int first)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
for (; first >= 0; first = s->node[first].next) n++;
|
||||
return n;
|
||||
}
|
||||
|
||||
static void
|
||||
walk(const reaktor_snap *s, int first, reaktor_snap_node *n, char *buf,
|
||||
reaktor_snap_visit visit, void *user)
|
||||
{
|
||||
int k, at = 0;
|
||||
|
||||
for (k = first; k >= 0; k = s->node[k].next) {
|
||||
memset(n, 0, sizeof *n);
|
||||
fill(s, k, n, buf, REAKTOR_SNAP_TEXT);
|
||||
visit(user, n, at++, kids(s, s->node[k].first));
|
||||
walk(s, s->node[k].first, n, buf, visit, user);
|
||||
out->id = d->id; out->parent = d->parent;
|
||||
out->role = d->role; out->level = d->level;
|
||||
out->state = d->state;
|
||||
out->x = d->x; out->y = d->y; out->w = d->w; out->h = d->h;
|
||||
out->num = d->num; out->lo = d->lo;
|
||||
out->hi = d->hi; out->step = d->step;
|
||||
out->name = copy_text(s, d->name, &at, &left);
|
||||
out->value = copy_text(s, d->value, &at, &left);
|
||||
out->keys = copy_text(s, d->keys, &at, &left);
|
||||
ok = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_snap_walk_in(reaktor_snap *s, reaktor_snap_visit visit, void *user)
|
||||
{
|
||||
reaktor_snap_node n;
|
||||
char buf[REAKTOR_SNAP_TEXT];
|
||||
|
||||
if (!s || !s->ready) return;
|
||||
memset(&n, 0, sizeof n);
|
||||
SDL_LockMutex(s->lock);
|
||||
visit(user, &n, -1, kids(s, s->first));
|
||||
walk(s, s->first, &n, buf, visit, user);
|
||||
SDL_UnlockMutex(s->lock);
|
||||
return ok;
|
||||
}
|
||||
|
||||
unsigned
|
||||
@@ -435,12 +333,11 @@ reaktor_snap_pressable(unsigned char role)
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_snap_structural_in(reaktor_snap *s, const reaktor_a11y *a)
|
||||
reaktor_snap_structural(const reaktor_a11y *a)
|
||||
{
|
||||
int m, i;
|
||||
const reaktor_a11y_change *c = reaktor_a11y_changes(a, &m);
|
||||
|
||||
if (s && s->overflow) return 1;
|
||||
for (i = 0; i < m; i++)
|
||||
if (c[i].kind == REAKTOR_A11Y_ADDED || c[i].kind == REAKTOR_A11Y_REMOVED) return 1;
|
||||
return 0;
|
||||
@@ -526,7 +423,6 @@ reaktor_snap_drain_in(reaktor_snap *s)
|
||||
|
||||
int reaktor_snap_update(const reaktor_a11y *a, unsigned focus_id)
|
||||
{ return reaktor_snap_update_in(&g, a, focus_id); }
|
||||
int reaktor_snap_diffs(const reaktor_snap_diff **out) { return reaktor_snap_diffs_in(&g, out); }
|
||||
int reaktor_snap_get(unsigned id, reaktor_snap_node *out, char *buf, size_t cap)
|
||||
{ return reaktor_snap_get_in(&g, id, out, buf, cap); }
|
||||
unsigned reaktor_snap_child(unsigned parent, int last)
|
||||
@@ -534,10 +430,6 @@ unsigned reaktor_snap_child(unsigned parent, int last)
|
||||
unsigned reaktor_snap_sibling(unsigned id, int back)
|
||||
{ return reaktor_snap_sibling_in(&g, id, back); }
|
||||
unsigned reaktor_snap_parent(unsigned id) { return reaktor_snap_parent_in(&g, id); }
|
||||
void reaktor_snap_walk(reaktor_snap_visit visit, void *user)
|
||||
{ reaktor_snap_walk_in(&g, visit, user); }
|
||||
int reaktor_snap_structural(const reaktor_a11y *a)
|
||||
{ return reaktor_snap_structural_in(&g, a); }
|
||||
unsigned reaktor_snap_hit(float x, float y) { return reaktor_snap_hit_in(&g, x, y); }
|
||||
unsigned reaktor_snap_focus(void) { return reaktor_snap_focus_in(&g); }
|
||||
void reaktor_snap_request_focus(unsigned id)
|
||||
|
||||
@@ -16,22 +16,8 @@ typedef struct reaktor_snap_node {
|
||||
|
||||
#define REAKTOR_SNAP_TEXT 4096
|
||||
|
||||
/* A node the last update changed in place: whether its value changed, and
|
||||
which state bits flipped, with the state and value it has now. Its name is
|
||||
part of its id, so never changes. */
|
||||
typedef struct reaktor_snap_diff {
|
||||
unsigned id, flipped, state;
|
||||
int value;
|
||||
float num, lo, hi;
|
||||
} reaktor_snap_diff;
|
||||
|
||||
#define REAKTOR_SNAP_DIFFS 64
|
||||
|
||||
typedef struct reaktor_snap reaktor_snap;
|
||||
|
||||
typedef void (*reaktor_snap_visit)(void *user, const reaktor_snap_node *n,
|
||||
int index, int children);
|
||||
|
||||
int reaktor_snap_init(reaktor_a11y_action activate, reaktor_a11y_action focus,
|
||||
void *user);
|
||||
|
||||
@@ -57,12 +43,8 @@ void reaktor_snap_wake_in(reaktor_snap *s);
|
||||
void reaktor_snap_request_focus_in(reaktor_snap *s, unsigned id);
|
||||
void reaktor_snap_request_activate_in(reaktor_snap *s, unsigned id);
|
||||
void reaktor_snap_drain_in(reaktor_snap *s);
|
||||
int reaktor_snap_diffs_in(reaktor_snap *s, const reaktor_snap_diff **out);
|
||||
void reaktor_snap_walk_in(reaktor_snap *s, reaktor_snap_visit visit, void *user);
|
||||
int reaktor_snap_structural_in(reaktor_snap *s, const reaktor_a11y *a);
|
||||
|
||||
int reaktor_snap_update(const reaktor_a11y *a, unsigned focus_id);
|
||||
int reaktor_snap_diffs(const reaktor_snap_diff **out);
|
||||
|
||||
int reaktor_snap_get(unsigned id, reaktor_snap_node *out, char *buf,
|
||||
size_t cap);
|
||||
@@ -70,7 +52,6 @@ int reaktor_snap_get(unsigned id, reaktor_snap_node *out, char *buf,
|
||||
unsigned reaktor_snap_child(unsigned parent, int last);
|
||||
unsigned reaktor_snap_sibling(unsigned id, int back);
|
||||
unsigned reaktor_snap_parent(unsigned id);
|
||||
void reaktor_snap_walk(reaktor_snap_visit visit, void *user);
|
||||
|
||||
unsigned reaktor_snap_hit(float x, float y);
|
||||
|
||||
|
||||
+29
-75
@@ -72,7 +72,6 @@ typedef struct Provider {
|
||||
} Provider;
|
||||
|
||||
static Provider *provider_new(bridge *b, unsigned id);
|
||||
static HRESULT out_fragment(bridge *b, unsigned id, IRawElementProviderFragment **out);
|
||||
|
||||
#define FROM_SIMPLE(p) ((Provider *)((char *)(p) - offsetof(Provider, simple)))
|
||||
#define FROM_FRAGMENT(p) ((Provider *)((char *)(p) - offsetof(Provider, fragment)))
|
||||
@@ -89,6 +88,7 @@ provider_is_root(const Provider *p)
|
||||
return p->id == 0;
|
||||
}
|
||||
|
||||
/* A provider outlives its window; a slot given to another is not its tree. */
|
||||
static reaktor_snap *
|
||||
snap_of(const Provider *p)
|
||||
{
|
||||
@@ -345,7 +345,12 @@ fragment_Navigate(IRawElementProviderFragment *self,
|
||||
switch (dir) {
|
||||
case NavigateDirection_Parent:
|
||||
to = reaktor_snap_parent_in(t, p->id);
|
||||
if (!to) return out_fragment(p->b, 0, out);
|
||||
if (!to) {
|
||||
Provider *r = provider_new(p->b, 0);
|
||||
if (!r) return E_OUTOFMEMORY;
|
||||
*out = &r->fragment;
|
||||
return S_OK;
|
||||
}
|
||||
break;
|
||||
case NavigateDirection_FirstChild:
|
||||
to = reaktor_snap_child_in(t, p->id, 0);
|
||||
@@ -362,7 +367,13 @@ fragment_Navigate(IRawElementProviderFragment *self,
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
return to ? out_fragment(p->b, to, out) : S_OK;
|
||||
if (!to) return S_OK;
|
||||
{
|
||||
Provider *q = provider_new(p->b, to);
|
||||
if (!q) return E_OUTOFMEMORY;
|
||||
*out = &q->fragment;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT STDMETHODCALLTYPE
|
||||
@@ -460,7 +471,13 @@ root_ElementProviderFromPoint(IRawElementProviderFragmentRoot *self,
|
||||
if (!snap_of(p) || !ClientToScreen(p->b->hwnd, &origin)) return S_OK;
|
||||
hit = reaktor_snap_hit_in(snap_of(p), (float)(x - origin.x),
|
||||
(float)(y - origin.y));
|
||||
return hit ? out_fragment(p->b, hit, out) : S_OK;
|
||||
if (!hit) return S_OK;
|
||||
{
|
||||
Provider *q = provider_new(p->b, hit);
|
||||
if (!q) return E_OUTOFMEMORY;
|
||||
*out = &q->fragment;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT STDMETHODCALLTYPE
|
||||
@@ -472,7 +489,13 @@ root_GetFocus(IRawElementProviderFragmentRoot *self,
|
||||
|
||||
*out = NULL;
|
||||
id = reaktor_snap_focus_in(snap_of(p));
|
||||
return id ? out_fragment(p->b, id, out) : S_OK;
|
||||
if (!id) return S_OK;
|
||||
{
|
||||
Provider *q = provider_new(p->b, id);
|
||||
if (!q) return E_OUTOFMEMORY;
|
||||
*out = &q->fragment;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static IRawElementProviderFragmentRootVtbl g_root_vtbl = {
|
||||
@@ -669,16 +692,6 @@ static IRangeValueProviderVtbl g_range_vtbl = {
|
||||
range_get_SmallChange
|
||||
};
|
||||
|
||||
static HRESULT
|
||||
out_fragment(bridge *b, unsigned id, IRawElementProviderFragment **out)
|
||||
{
|
||||
Provider *q = provider_new(b, id);
|
||||
|
||||
if (!q) return E_OUTOFMEMORY;
|
||||
*out = &q->fragment;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static Provider *
|
||||
provider_new(bridge *b, unsigned id)
|
||||
{
|
||||
@@ -784,64 +797,6 @@ reaktor_a11y_platform_init(reaktor_a11y_action activate,
|
||||
SDL_free(wins);
|
||||
}
|
||||
|
||||
static void
|
||||
raise_property(Provider *p, PROPERTYID prop, VARIANT now)
|
||||
{
|
||||
VARIANT was;
|
||||
|
||||
VariantInit(&was);
|
||||
UiaRaiseAutomationPropertyChangedEvent((IRawElementProviderSimple *)&p->simple,
|
||||
prop, was, now);
|
||||
VariantClear(&now);
|
||||
}
|
||||
|
||||
/* A control that changed in place: its new value or state, for the
|
||||
properties the provider serves. */
|
||||
static void
|
||||
raise_changes(bridge *b)
|
||||
{
|
||||
const reaktor_snap_diff *d;
|
||||
reaktor_snap_node n;
|
||||
char buf[REAKTOR_SNAP_TEXT];
|
||||
VARIANT v;
|
||||
int i, count = reaktor_snap_diffs_in(b->snap, &d);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
Provider *p;
|
||||
|
||||
if (!reaktor_snap_get_in(b->snap, d[i].id, &n, buf, sizeof(buf))) continue;
|
||||
if (!(p = provider_new(b, d[i].id))) return;
|
||||
if (d[i].value) {
|
||||
if (n.hi > n.lo) {
|
||||
VariantInit(&v);
|
||||
v.vt = VT_R8;
|
||||
v.dblVal = n.num;
|
||||
raise_property(p, UIA_RangeValueValuePropertyId, v);
|
||||
} else {
|
||||
str_variant(&v, n.value);
|
||||
raise_property(p, UIA_ValueValuePropertyId, v);
|
||||
}
|
||||
}
|
||||
if ((d[i].flipped & REAKTOR_A11Y_CHECKED) &&
|
||||
(n.role == REAKTOR_A11Y_CHECKBOX || n.role == REAKTOR_A11Y_RADIO)) {
|
||||
VariantInit(&v);
|
||||
v.vt = VT_I4;
|
||||
v.lVal = (n.state & REAKTOR_A11Y_CHECKED) ? ToggleState_On : ToggleState_Off;
|
||||
raise_property(p, UIA_ToggleToggleStatePropertyId, v);
|
||||
}
|
||||
if ((d[i].flipped & REAKTOR_A11Y_SELECTED) &&
|
||||
(n.role == REAKTOR_A11Y_TAB || n.role == REAKTOR_A11Y_LISTITEM)) {
|
||||
bool_variant(&v, (n.state & REAKTOR_A11Y_SELECTED) != 0);
|
||||
raise_property(p, UIA_SelectionItemIsSelectedPropertyId, v);
|
||||
}
|
||||
if (d[i].flipped & REAKTOR_A11Y_DISABLED) {
|
||||
bool_variant(&v, !(n.state & REAKTOR_A11Y_DISABLED));
|
||||
raise_property(p, UIA_IsEnabledPropertyId, v);
|
||||
}
|
||||
IRawElementProviderSimple_Release(&p->simple);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
push_into(bridge *b, const reaktor_a11y *a, unsigned focus_id)
|
||||
{
|
||||
@@ -851,8 +806,7 @@ push_into(bridge *b, const reaktor_a11y *a, unsigned focus_id)
|
||||
}
|
||||
if (!reaktor_snap_update_in(b->snap, a, focus_id)) return;
|
||||
if (!UiaClientsAreListening()) return;
|
||||
raise_changes(b);
|
||||
if (reaktor_snap_structural_in(b->snap, a)) {
|
||||
if (reaktor_snap_structural(a)) {
|
||||
Provider *r = provider_new(b, 0);
|
||||
|
||||
if (!r) return;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* Windows other than the main one, where only UI Automation serves them. */
|
||||
#include "a11y.h"
|
||||
|
||||
void
|
||||
|
||||
@@ -69,6 +69,7 @@ console_ctrl(DWORD type)
|
||||
switch (type) {
|
||||
case CTRL_C_EVENT:
|
||||
case CTRL_BREAK_EVENT:
|
||||
/* A borrowed console's Ctrl+C belongs to the shell. */
|
||||
if (!g_own_ctrl_c) return TRUE;
|
||||
if (SDL_AddAtomicInt(&g_ctrl_c, 1) == 0) reaktor_console_quit();
|
||||
else reaktor_hard_quit(130);
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
/* Before SDL_Init. */
|
||||
void reaktor_process_start(int console, const char *title);
|
||||
void reaktor_session_watch(SDL_Window *win);
|
||||
void reaktor_process_stopped(void);
|
||||
void reaktor_process_end(void);
|
||||
|
||||
/* After SDL_Init. The reason + 1 of a bare quit, or 0; *again on a repeat. */
|
||||
void reaktor_signal_watch(void);
|
||||
void reaktor_signal_unwatch(void);
|
||||
int reaktor_signal_reason(int *again);
|
||||
|
||||
+38
-30
@@ -44,6 +44,7 @@ notify_gone(App *app, void *user)
|
||||
notify_remove();
|
||||
}
|
||||
|
||||
/* As much of s as fits, cut short rather than lost. */
|
||||
static void
|
||||
notify_text(const char *s, WCHAR *out, int cap)
|
||||
{
|
||||
@@ -55,6 +56,7 @@ notify_text(const char *s, WCHAR *out, int cap)
|
||||
SDL_free(w);
|
||||
}
|
||||
|
||||
/* A balloon from an icon of our own, which Windows 10 and 11 show as a toast. */
|
||||
static int
|
||||
notify_os(App *app, const char *title, const char *text)
|
||||
{
|
||||
@@ -90,44 +92,49 @@ notify_os(App *app, const char *title, const char *text)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#elif defined(REAKTOR_HAVE_GIBUS)
|
||||
#include "gibus.h"
|
||||
#elif defined(REAKTOR_HAVE_DBUS)
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
static int
|
||||
notify_os(App *app, const char *title, const char *body)
|
||||
{
|
||||
gibus_conn *c;
|
||||
gibus_msg *m;
|
||||
gibus_iter it, sub;
|
||||
const char *name = reaktor_app_ident(), *icon = "";
|
||||
uint32_t replaces = 0;
|
||||
int32_t expire = -1;
|
||||
int ok = 0;
|
||||
char *t = reaktor_utf8_clean_dup(title), *b = reaktor_utf8_clean_dup(body);
|
||||
DBusConnection *c;
|
||||
DBusMessage *m;
|
||||
DBusMessageIter it, sub;
|
||||
const char *name = reaktor_app_ident(), *icon = "";
|
||||
dbus_uint32_t replaces = 0;
|
||||
dbus_int32_t expire = -1;
|
||||
int ok = 0;
|
||||
size_t tn = SDL_strlen(title) * 3 + 1, bn = SDL_strlen(body) * 3 + 1;
|
||||
char *t = (char *)SDL_malloc(tn), *b = (char *)SDL_malloc(bn);
|
||||
|
||||
(void)app;
|
||||
if (!t || !b || !(c = gibus_session(NULL))) goto done;
|
||||
m = gibus_msg_call("org.freedesktop.Notifications", "/org/freedesktop/Notifications",
|
||||
"org.freedesktop.Notifications", "Notify");
|
||||
if (!t || !b) goto done;
|
||||
reaktor_utf8_clean(t, title, tn);
|
||||
reaktor_utf8_clean(b, body, bn);
|
||||
if (!(c = dbus_bus_get(DBUS_BUS_SESSION, NULL))) goto done;
|
||||
m = dbus_message_new_method_call("org.freedesktop.Notifications",
|
||||
"/org/freedesktop/Notifications",
|
||||
"org.freedesktop.Notifications", "Notify");
|
||||
if (!m) {
|
||||
gibus_unref(c);
|
||||
dbus_connection_unref(c);
|
||||
goto done;
|
||||
}
|
||||
gibus_iter_init_append(m, &it);
|
||||
gibus_iter_append_basic(&it, GIBUS_TYPE_STRING, &name);
|
||||
gibus_iter_append_basic(&it, GIBUS_TYPE_UINT32, &replaces);
|
||||
gibus_iter_append_basic(&it, GIBUS_TYPE_STRING, &icon);
|
||||
gibus_iter_append_basic(&it, GIBUS_TYPE_STRING, &t);
|
||||
gibus_iter_append_basic(&it, GIBUS_TYPE_STRING, &b);
|
||||
gibus_iter_open(&it, GIBUS_TYPE_ARRAY, "s", &sub);
|
||||
gibus_iter_close(&it, &sub);
|
||||
gibus_iter_open(&it, GIBUS_TYPE_ARRAY, "{sv}", &sub);
|
||||
gibus_iter_close(&it, &sub);
|
||||
gibus_iter_append_basic(&it, GIBUS_TYPE_INT32, &expire);
|
||||
ok = gibus_send(c, m, NULL);
|
||||
gibus_flush(c);
|
||||
gibus_msg_free(m);
|
||||
gibus_unref(c);
|
||||
dbus_message_iter_init_append(m, &it);
|
||||
dbus_message_iter_append_basic(&it, DBUS_TYPE_STRING, &name);
|
||||
dbus_message_iter_append_basic(&it, DBUS_TYPE_UINT32, &replaces);
|
||||
dbus_message_iter_append_basic(&it, DBUS_TYPE_STRING, &icon);
|
||||
dbus_message_iter_append_basic(&it, DBUS_TYPE_STRING, &t);
|
||||
dbus_message_iter_append_basic(&it, DBUS_TYPE_STRING, &b);
|
||||
dbus_message_iter_open_container(&it, DBUS_TYPE_ARRAY, "s", &sub);
|
||||
dbus_message_iter_close_container(&it, &sub);
|
||||
dbus_message_iter_open_container(&it, DBUS_TYPE_ARRAY, "{sv}", &sub);
|
||||
dbus_message_iter_close_container(&it, &sub);
|
||||
dbus_message_iter_append_basic(&it, DBUS_TYPE_INT32, &expire);
|
||||
ok = dbus_connection_send(c, m, NULL);
|
||||
dbus_connection_flush(c);
|
||||
dbus_message_unref(m);
|
||||
dbus_connection_unref(c);
|
||||
done:
|
||||
SDL_free(t);
|
||||
SDL_free(b);
|
||||
@@ -145,7 +152,8 @@ notify_os(App *app, const char *title, const char *text)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__EMSCRIPTEN__) || defined(_WIN32) || defined(REAKTOR_HAVE_GIBUS) || defined(__APPLE__)
|
||||
/* Without a backend the module is notify_none.c instead. */
|
||||
#if defined(__EMSCRIPTEN__) || defined(_WIN32) || defined(REAKTOR_HAVE_DBUS) || defined(__APPLE__)
|
||||
int
|
||||
reaktor_notify(App *app, const reaktor_notification *n)
|
||||
{
|
||||
|
||||
+119
-99
@@ -13,7 +13,11 @@
|
||||
|
||||
int reaktor_prefers_dark(void)
|
||||
{
|
||||
return SDL_GetSystemTheme() == SDL_SYSTEM_THEME_DARK;
|
||||
switch (SDL_GetSystemTheme()) {
|
||||
case SDL_SYSTEM_THEME_DARK: return 1;
|
||||
case SDL_SYSTEM_THEME_LIGHT: return 0;
|
||||
default: return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(__APPLE__) && !defined(__EMSCRIPTEN__)
|
||||
@@ -26,132 +30,146 @@ static int workspace_says(const char *what)
|
||||
|
||||
return ws && ask(ws, sel_registerName(what));
|
||||
}
|
||||
#elif defined(REAKTOR_HAVE_GIBUS)
|
||||
#include "gibus.h"
|
||||
#elif !defined(_WIN32) && !defined(__EMSCRIPTEN__) && !defined(__ANDROID__)
|
||||
/* The desktop portal's settings, through a libdbus loaded when first asked. */
|
||||
typedef struct { void *a, *b; unsigned c; void *d; } dbus_error;
|
||||
typedef union { void *p[16]; long long l[16]; } dbus_iter;
|
||||
|
||||
static int portal_value(gibus_iter *it)
|
||||
static struct {
|
||||
int tried;
|
||||
void *lib, *conn;
|
||||
void (*error_init)(dbus_error *);
|
||||
void (*error_free)(dbus_error *);
|
||||
void *(*bus_get)(int, dbus_error *);
|
||||
void *(*method_call)(const char *, const char *, const char *, const char *);
|
||||
int (*append_args)(void *, int, ...);
|
||||
void *(*send_block)(void *, void *, int, dbus_error *);
|
||||
void (*message_unref)(void *);
|
||||
int (*iter_init)(void *, dbus_iter *);
|
||||
int (*iter_type)(dbus_iter *);
|
||||
void (*iter_recurse)(dbus_iter *, dbus_iter *);
|
||||
void (*iter_basic)(dbus_iter *, void *);
|
||||
} g_dbus;
|
||||
|
||||
static int dbus_ready(void)
|
||||
{
|
||||
gibus_iter in;
|
||||
int type;
|
||||
dbus_error e;
|
||||
|
||||
while ((type = gibus_iter_type(it)) == GIBUS_TYPE_VARIANT) {
|
||||
gibus_iter_recurse(it, &in);
|
||||
*it = in;
|
||||
}
|
||||
if (type == GIBUS_TYPE_UINT32 || type == GIBUS_TYPE_INT32 || type == GIBUS_TYPE_BOOLEAN) {
|
||||
Uint32 v = 0;
|
||||
|
||||
gibus_iter_get_basic(it, &v);
|
||||
return (int)v;
|
||||
}
|
||||
return -1;
|
||||
if (g_dbus.tried) return g_dbus.conn != NULL;
|
||||
g_dbus.tried = 1;
|
||||
if (!(g_dbus.lib = SDL_LoadObject("libdbus-1.so.3"))) return 0;
|
||||
#define DBUS_FN(f, name) if (!(*(void **)&g_dbus.f = (void *)SDL_LoadFunction(g_dbus.lib, name))) return 0
|
||||
DBUS_FN(error_init, "dbus_error_init");
|
||||
DBUS_FN(error_free, "dbus_error_free");
|
||||
DBUS_FN(bus_get, "dbus_bus_get");
|
||||
DBUS_FN(method_call, "dbus_message_new_method_call");
|
||||
DBUS_FN(append_args, "dbus_message_append_args");
|
||||
DBUS_FN(send_block, "dbus_connection_send_with_reply_and_block");
|
||||
DBUS_FN(message_unref, "dbus_message_unref");
|
||||
DBUS_FN(iter_init, "dbus_message_iter_init");
|
||||
DBUS_FN(iter_type, "dbus_message_iter_get_arg_type");
|
||||
DBUS_FN(iter_recurse, "dbus_message_iter_recurse");
|
||||
DBUS_FN(iter_basic, "dbus_message_iter_get_basic");
|
||||
#undef DBUS_FN
|
||||
g_dbus.error_init(&e);
|
||||
g_dbus.conn = g_dbus.bus_get(0, &e);
|
||||
g_dbus.error_free(&e);
|
||||
return g_dbus.conn != NULL;
|
||||
}
|
||||
|
||||
static const char *const g_portal[][2] = {
|
||||
{ "org.freedesktop.appearance", "reduced-motion" },
|
||||
{ "org.gnome.desktop.interface", "enable-animations" },
|
||||
{ "org.freedesktop.appearance", "contrast" },
|
||||
{ "org.gnome.desktop.a11y.interface", "high-contrast" },
|
||||
};
|
||||
#define PORTAL_N ((int)(sizeof g_portal / sizeof g_portal[0]))
|
||||
|
||||
static int g_portal_gone;
|
||||
|
||||
static void portal_read(int out[PORTAL_N])
|
||||
/* A setting as a number, or -1 when the portal does not have it. */
|
||||
static int portal_read(const char *ns, const char *key)
|
||||
{
|
||||
static const char *const ns[] = { "org.freedesktop.appearance",
|
||||
"org.gnome.desktop.interface",
|
||||
"org.gnome.desktop.a11y.interface" };
|
||||
gibus_conn *bus;
|
||||
gibus_msg *msg, *reply = NULL;
|
||||
gibus_error e;
|
||||
gibus_iter top, all, one, keys, kv;
|
||||
int i;
|
||||
static const char *const how[2] = { "ReadOne", "Read" };
|
||||
int i, out = -1;
|
||||
|
||||
for (i = 0; i < PORTAL_N; i++) out[i] = -1;
|
||||
if (g_portal_gone) return;
|
||||
gibus_error_init(&e);
|
||||
if (!(bus = gibus_session(&e))) {
|
||||
g_portal_gone = 1;
|
||||
gibus_error_free(&e);
|
||||
return;
|
||||
}
|
||||
msg = gibus_msg_call("org.freedesktop.portal.Desktop", "/org/freedesktop/portal/desktop",
|
||||
"org.freedesktop.portal.Settings", "ReadAll");
|
||||
if (msg) {
|
||||
gibus_iter_init_append(msg, &top);
|
||||
gibus_iter_open(&top, GIBUS_TYPE_ARRAY, "s", &all);
|
||||
for (i = 0; i < (int)SDL_arraysize(ns); i++)
|
||||
gibus_iter_append_basic(&all, GIBUS_TYPE_STRING, &ns[i]);
|
||||
gibus_iter_close(&top, &all);
|
||||
reply = gibus_call(bus, msg, 300, &e);
|
||||
if (!reply)
|
||||
g_portal_gone = SDL_strcmp(e.name, "org.freedesktop.DBus.Error.ServiceUnknown") == 0 ||
|
||||
SDL_strcmp(e.name, GIBUS_ERROR_UNKNOWN_METHOD) == 0;
|
||||
gibus_msg_free(msg);
|
||||
}
|
||||
gibus_error_free(&e);
|
||||
gibus_unref(bus);
|
||||
if (!reply) return;
|
||||
if (gibus_msg_has_signature(reply, "a{sa{sv}}") && gibus_iter_init(reply, &top)) {
|
||||
for (gibus_iter_recurse(&top, &all); gibus_iter_type(&all) == GIBUS_TYPE_DICT_ENTRY;
|
||||
gibus_iter_next(&all)) {
|
||||
const char *n = NULL;
|
||||
if (!dbus_ready()) return -1;
|
||||
for (i = 0; i < 2 && out < 0; i++) {
|
||||
void *msg, *reply;
|
||||
dbus_error e;
|
||||
dbus_iter it, in;
|
||||
int type;
|
||||
|
||||
gibus_iter_recurse(&all, &one);
|
||||
gibus_iter_get_basic(&one, &n);
|
||||
gibus_iter_next(&one);
|
||||
for (gibus_iter_recurse(&one, &keys); gibus_iter_type(&keys) == GIBUS_TYPE_DICT_ENTRY;
|
||||
gibus_iter_next(&keys)) {
|
||||
const char *k = NULL;
|
||||
msg = g_dbus.method_call("org.freedesktop.portal.Desktop",
|
||||
"/org/freedesktop/portal/desktop",
|
||||
"org.freedesktop.portal.Settings", how[i]);
|
||||
if (!msg) return -1;
|
||||
if (!g_dbus.append_args(msg, 's', &ns, 's', &key, 0)) {
|
||||
g_dbus.message_unref(msg);
|
||||
return -1;
|
||||
}
|
||||
g_dbus.error_init(&e);
|
||||
reply = g_dbus.send_block(g_dbus.conn, msg, 300, &e);
|
||||
g_dbus.error_free(&e);
|
||||
g_dbus.message_unref(msg);
|
||||
if (!reply) continue;
|
||||
if (g_dbus.iter_init(reply, &it)) {
|
||||
while ((type = g_dbus.iter_type(&it)) == 'v') {
|
||||
g_dbus.iter_recurse(&it, &in);
|
||||
it = in;
|
||||
}
|
||||
if (type == 'u' || type == 'i' || type == 'b') {
|
||||
Uint32 v = 0;
|
||||
|
||||
gibus_iter_recurse(&keys, &kv);
|
||||
gibus_iter_get_basic(&kv, &k);
|
||||
gibus_iter_next(&kv);
|
||||
for (i = 0; i < PORTAL_N; i++)
|
||||
if (SDL_strcmp(n, g_portal[i][0]) == 0 && SDL_strcmp(k, g_portal[i][1]) == 0)
|
||||
out[i] = portal_value(&kv);
|
||||
g_dbus.iter_basic(&it, &v);
|
||||
out = (int)v;
|
||||
}
|
||||
}
|
||||
g_dbus.message_unref(reply);
|
||||
}
|
||||
gibus_msg_free(reply);
|
||||
return out;
|
||||
}
|
||||
#endif
|
||||
|
||||
void reaktor_prefers(int *reduced_motion, int *contrast)
|
||||
int reaktor_prefers_reduced_motion(void)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
BOOL on = TRUE;
|
||||
HIGHCONTRASTW hc;
|
||||
BOOL on = TRUE;
|
||||
|
||||
hc.cbSize = sizeof hc;
|
||||
*reduced_motion = SystemParametersInfoW(SPI_GETCLIENTAREAANIMATION, 0, &on, 0) && !on;
|
||||
*contrast = SystemParametersInfoW(SPI_GETHIGHCONTRAST, sizeof hc, &hc, 0) &&
|
||||
(hc.dwFlags & HCF_HIGHCONTRASTON);
|
||||
return SystemParametersInfoW(SPI_GETCLIENTAREAANIMATION, 0, &on, 0) && !on;
|
||||
#elif defined(__EMSCRIPTEN__)
|
||||
*reduced_motion = EM_ASM_INT({
|
||||
return EM_ASM_INT({
|
||||
return window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 1 : 0;
|
||||
});
|
||||
*contrast = EM_ASM_INT({
|
||||
#elif defined(__APPLE__)
|
||||
return workspace_says("accessibilityDisplayShouldReduceMotion");
|
||||
#elif !defined(__ANDROID__)
|
||||
int v = portal_read("org.freedesktop.appearance", "reduced-motion");
|
||||
|
||||
if (v >= 0) return v == 1;
|
||||
v = portal_read("org.gnome.desktop.interface", "enable-animations");
|
||||
return v == 0;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int reaktor_prefers_contrast(void)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
HIGHCONTRASTW hc;
|
||||
|
||||
hc.cbSize = sizeof hc;
|
||||
return SystemParametersInfoW(SPI_GETHIGHCONTRAST, sizeof hc, &hc, 0) &&
|
||||
(hc.dwFlags & HCF_HIGHCONTRASTON);
|
||||
#elif defined(__EMSCRIPTEN__)
|
||||
return EM_ASM_INT({
|
||||
return window.matchMedia && (window.matchMedia('(prefers-contrast: more)').matches ||
|
||||
window.matchMedia('(forced-colors: active)').matches) ? 1 : 0;
|
||||
});
|
||||
#elif defined(__APPLE__)
|
||||
*reduced_motion = workspace_says("accessibilityDisplayShouldReduceMotion");
|
||||
*contrast = workspace_says("accessibilityDisplayShouldIncreaseContrast");
|
||||
#elif defined(REAKTOR_HAVE_GIBUS)
|
||||
int v[PORTAL_N];
|
||||
return workspace_says("accessibilityDisplayShouldIncreaseContrast");
|
||||
#elif !defined(__ANDROID__)
|
||||
int v = portal_read("org.freedesktop.appearance", "contrast");
|
||||
|
||||
portal_read(v);
|
||||
*reduced_motion = v[0] >= 0 ? v[0] == 1 : v[1] == 0;
|
||||
*contrast = v[2] >= 0 ? v[2] == 1 : v[3] == 1;
|
||||
if (v >= 0) return v == 1;
|
||||
return portal_read("org.gnome.desktop.a11y.interface", "high-contrast") == 1;
|
||||
#else
|
||||
*reduced_motion = 0;
|
||||
*contrast = 0;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void reaktor_window_set_dark(SDL_Window *win, int dark)
|
||||
int reaktor_window_set_dark(SDL_Window *win, int dark)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
void *native_window =
|
||||
@@ -164,7 +182,7 @@ void reaktor_window_set_dark(SDL_Window *win, int dark)
|
||||
static int looked_up;
|
||||
int value = dark ? 1 : 0;
|
||||
|
||||
if (!native_window) return;
|
||||
if (!native_window) return 0;
|
||||
if (!looked_up) {
|
||||
void *dll = (void *)LoadLibraryExA("dwmapi.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
|
||||
if (dll)
|
||||
@@ -172,12 +190,14 @@ void reaktor_window_set_dark(SDL_Window *win, int dark)
|
||||
(HMODULE)dll, "DwmSetWindowAttribute");
|
||||
looked_up = 1;
|
||||
}
|
||||
if (!set_attr) return;
|
||||
if (!set_attr) return 0;
|
||||
|
||||
if (set_attr(native_window, 20, &value, sizeof(value)) != 0)
|
||||
set_attr(native_window, 19, &value, sizeof(value));
|
||||
return 1;
|
||||
#else
|
||||
(void)win;
|
||||
(void)dark;
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
+3
-2
@@ -2,10 +2,11 @@
|
||||
#define REAKTOR_THEME_H
|
||||
|
||||
int reaktor_prefers_dark(void);
|
||||
void reaktor_prefers(int *reduced_motion, int *contrast);
|
||||
int reaktor_prefers_reduced_motion(void);
|
||||
int reaktor_prefers_contrast(void);
|
||||
|
||||
struct SDL_Window;
|
||||
|
||||
void reaktor_window_set_dark(struct SDL_Window *win, int dark);
|
||||
int reaktor_window_set_dark(struct SDL_Window *win, int dark);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
static Uint32 g_type;
|
||||
|
||||
/* Through SDL's queue, so it stays in order with taps and keys. */
|
||||
EMSCRIPTEN_KEEPALIVE void
|
||||
reaktor_web_keys_typed(int code)
|
||||
{
|
||||
@@ -20,6 +21,7 @@ reaktor_web_keys_typed(int code)
|
||||
EM_JS(void, web_keys_make, (void), {
|
||||
var el = document.createElement("input");
|
||||
var canvas = Module["canvas"];
|
||||
/* Something for a soft Backspace to delete; never the app's text. */
|
||||
var base = " ";
|
||||
var k = {
|
||||
el: el, held: [], at: 0, composing: false, touching: 0, wanted: 0,
|
||||
@@ -71,6 +73,7 @@ EM_JS(void, web_keys_make, (void), {
|
||||
var without = function (s, i) {
|
||||
return i < 0 ? s : s.slice(0, i).concat(s.slice(i + 1));
|
||||
};
|
||||
/* A composition is left alone until it ends, or the word is typed twice. */
|
||||
var sync = function () {
|
||||
var was = k.held, cur = Array.from(el.value), at = k.at;
|
||||
var p = 0, e = 0, back = 0, i, c;
|
||||
@@ -78,6 +81,7 @@ EM_JS(void, web_keys_make, (void), {
|
||||
while (p < was.length && p < cur.length && was[p] === cur[p]) p++;
|
||||
while (e < was.length - p && e < cur.length - p &&
|
||||
was[was.length - 1 - e] === cur[cur.length - 1 - e]) e++;
|
||||
/* Deleting the base deletes the typed text too, so it is typed again. */
|
||||
if (at >= was.length - e) k.at = at + cur.length - was.length;
|
||||
else if (at >= p) { k.at = -1; back = 1; }
|
||||
was = without(was, at);
|
||||
@@ -96,6 +100,7 @@ EM_JS(void, web_keys_make, (void), {
|
||||
k.held = Array.from(el.value);
|
||||
if (!k.composing) reset();
|
||||
};
|
||||
/* The caret stays at the end, or the next edit reads as a delete. */
|
||||
var pin = function () {
|
||||
var end = el.value.length;
|
||||
|
||||
@@ -123,6 +128,7 @@ EM_JS(void, web_keys_make, (void), {
|
||||
}
|
||||
if (/^(Home|End|PageUp|PageDown|Arrow(Left|Right|Up|Down))$/.test(key))
|
||||
e.preventDefault();
|
||||
/* A soft key has no code, so SDL cannot tell what it is. */
|
||||
if (!e["code"] && soft[key]) put(soft[key]);
|
||||
});
|
||||
el.addEventListener("blur", function () {
|
||||
|
||||
+251
-192
@@ -6,7 +6,7 @@
|
||||
#include "locale.h"
|
||||
#include "reaktor/launch.h"
|
||||
#include "lifecycle.h"
|
||||
#include "css.h"
|
||||
#include "cssflat.h"
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include "keyboard_web.h"
|
||||
#endif
|
||||
@@ -16,7 +16,7 @@ effective_dark(const App *app)
|
||||
{
|
||||
if (app->theme_mode == REAKTOR_THEME_LIGHT) return 0;
|
||||
if (app->theme_mode == REAKTOR_THEME_DARK) return 1;
|
||||
return reaktor_prefers_dark();
|
||||
return reaktor_prefers_dark() > 0;
|
||||
}
|
||||
|
||||
size_t reaktor_rss[REAKTOR_RSS_STEPS];
|
||||
@@ -91,91 +91,21 @@ reaktor_asset_name(const reaktor_asset *a, const char *fallback)
|
||||
return name;
|
||||
}
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#define ON_WEB 1
|
||||
#else
|
||||
#define ON_WEB 0
|
||||
#endif
|
||||
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
#define GPU_DRIVERS "opengles2"
|
||||
#elif defined(__APPLE__)
|
||||
#define GPU_DRIVERS "metal"
|
||||
#elif defined(_WIN32)
|
||||
#define GPU_DRIVERS "opengl,direct3d12,direct3d11"
|
||||
#else
|
||||
#define GPU_DRIVERS "opengl,opengles2"
|
||||
#endif
|
||||
|
||||
SDL_Renderer *
|
||||
reaktor_renderer_for(SDL_Window *win, const char *name, int hdr)
|
||||
{
|
||||
SDL_Renderer *ren = NULL;
|
||||
|
||||
if (hdr) {
|
||||
SDL_PropertiesID p = SDL_CreateProperties();
|
||||
|
||||
SDL_SetPointerProperty(p, SDL_PROP_RENDERER_CREATE_WINDOW_POINTER, win);
|
||||
if (name) SDL_SetStringProperty(p, SDL_PROP_RENDERER_CREATE_NAME_STRING, name);
|
||||
SDL_SetNumberProperty(p, SDL_PROP_RENDERER_CREATE_OUTPUT_COLORSPACE_NUMBER,
|
||||
SDL_COLORSPACE_SRGB_LINEAR);
|
||||
ren = SDL_CreateRendererWithProperties(p);
|
||||
SDL_DestroyProperties(p);
|
||||
}
|
||||
/* SDL's gpu renderer keeps a linear output on a swapchain that cannot show
|
||||
one, and draws everything dark there. */
|
||||
if (ren) {
|
||||
SDL_GPUDevice *dev = (SDL_GPUDevice *)SDL_GetPointerProperty(
|
||||
SDL_GetRendererProperties(ren), SDL_PROP_RENDERER_GPU_DEVICE_POINTER, NULL);
|
||||
|
||||
if (dev && !SDL_WindowSupportsGPUSwapchainComposition(
|
||||
dev, win, SDL_GPU_SWAPCHAINCOMPOSITION_HDR_EXTENDED_LINEAR)) {
|
||||
SDL_DestroyRenderer(ren);
|
||||
ren = NULL;
|
||||
}
|
||||
}
|
||||
return ren ? ren : SDL_CreateRenderer(win, name);
|
||||
}
|
||||
|
||||
static const char *launch_title(void);
|
||||
|
||||
static bool
|
||||
open_window(App *app, int w, int h, SDL_WindowFlags flags)
|
||||
{
|
||||
app->win = SDL_CreateWindow(launch_title(), w, h, flags | SDL_WINDOW_HIDDEN);
|
||||
if (!app->win) return false;
|
||||
app->ren = reaktor_renderer_for(app->win, NULL, g_launch.hdr);
|
||||
if (!app->ren) {
|
||||
SDL_DestroyWindow(app->win);
|
||||
app->win = NULL;
|
||||
return false;
|
||||
}
|
||||
if (!(flags & SDL_WINDOW_HIDDEN)) SDL_ShowWindow(app->win);
|
||||
return true;
|
||||
}
|
||||
|
||||
static int
|
||||
capturing(const App *app)
|
||||
{
|
||||
return app->shot_path || app->dump_path;
|
||||
}
|
||||
|
||||
static int
|
||||
remembers(const App *app)
|
||||
{
|
||||
return !ON_WEB && g_launch.remember_window && !capturing(app);
|
||||
}
|
||||
|
||||
static int
|
||||
ms_x100(Uint64 from, Uint64 to)
|
||||
{
|
||||
return (int)(100000.0 * (double)(to - from) / (double)SDL_GetPerformanceFrequency());
|
||||
#ifdef __EMSCRIPTEN__
|
||||
(void)app;
|
||||
return 0;
|
||||
#else
|
||||
return g_launch.remember_window && !app->shot_path && !app->dump_path;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_capturing(void)
|
||||
{
|
||||
return g_app && capturing(g_app);
|
||||
return g_app && (g_app->shot_path || g_app->dump_path);
|
||||
}
|
||||
|
||||
reaktor_save
|
||||
@@ -194,13 +124,23 @@ reaktor_key_hook(App *app, const SDL_Event *event)
|
||||
static int
|
||||
starts_hidden(const App *app)
|
||||
{
|
||||
return !ON_WEB && g_launch.window.hidden && !capturing(app);
|
||||
#ifdef __EMSCRIPTEN__
|
||||
(void)app;
|
||||
return 0;
|
||||
#else
|
||||
return g_launch.window.hidden && !app->shot_path && !app->dump_path;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
placed(const App *app)
|
||||
{
|
||||
return !ON_WEB && (g_launch.window.centered || remembers(app));
|
||||
#ifdef __EMSCRIPTEN__
|
||||
(void)app;
|
||||
return 0;
|
||||
#else
|
||||
return g_launch.window.centered || remembers(app);
|
||||
#endif
|
||||
}
|
||||
|
||||
const char *
|
||||
@@ -230,10 +170,23 @@ reaktor_rss_mark(int step)
|
||||
reaktor_process_memory(&reaktor_rss[step], &reaktor_priv[step]);
|
||||
}
|
||||
|
||||
static char *
|
||||
from_here(const char *path)
|
||||
{
|
||||
char *cwd, *out = NULL;
|
||||
|
||||
if (reaktor_path_absolute(path)) return SDL_strdup(path);
|
||||
cwd = SDL_GetCurrentDirectory();
|
||||
if (!cwd) return NULL;
|
||||
if (SDL_asprintf(&out, "%s%s", cwd, path) < 0) out = NULL;
|
||||
SDL_free(cwd);
|
||||
return out;
|
||||
}
|
||||
|
||||
static void
|
||||
add_fallback(const char *path)
|
||||
{
|
||||
char *full = reaktor_path_from_cwd(path);
|
||||
char *full = from_here(path);
|
||||
|
||||
reaktor_text_add_fallback(full ? full : path);
|
||||
SDL_free(full);
|
||||
@@ -242,7 +195,7 @@ add_fallback(const char *path)
|
||||
static const char *
|
||||
own_here(const char *path)
|
||||
{
|
||||
char *full = reaktor_path_from_cwd(path);
|
||||
char *full = from_here(path);
|
||||
const char *owned = own(full ? full : path);
|
||||
|
||||
SDL_free(full);
|
||||
@@ -297,19 +250,6 @@ log_close(void)
|
||||
g_log = NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
pick(const char *v, const char *a, int va, const char *b, int vb, int other)
|
||||
{
|
||||
return SDL_strcmp(v, a) == 0 ? va : SDL_strcmp(v, b) == 0 ? vb : other;
|
||||
}
|
||||
|
||||
static void
|
||||
push_layer(const char **layers, int *n, const char *flag, const char *v)
|
||||
{
|
||||
if (*n < REAKTOR_LAYER_MAX) layers[(*n)++] = own_here(v);
|
||||
else SDL_Log("%s: four at most; %s is not read", flag, v);
|
||||
}
|
||||
|
||||
static int
|
||||
take_flags(App *app, int argc, char **argv)
|
||||
{
|
||||
@@ -323,17 +263,27 @@ take_flags(App *app, int argc, char **argv)
|
||||
|
||||
if (v && SDL_strcmp(a, "--shot") == 0) { app->shot_path = v; i++; }
|
||||
else if (v && SDL_strcmp(a, "--aa") == 0) {
|
||||
g_launch.anti_aliasing = (reaktor_aa)pick(v, "on", REAKTOR_AA_ON, "off",
|
||||
REAKTOR_AA_OFF, REAKTOR_AA_AUTO);
|
||||
g_launch.anti_aliasing = SDL_strcmp(v, "on") == 0 ? REAKTOR_AA_ON
|
||||
: SDL_strcmp(v, "off") == 0 ? REAKTOR_AA_OFF
|
||||
: REAKTOR_AA_AUTO;
|
||||
i++;
|
||||
}
|
||||
else if (v && SDL_strcmp(a, "--console") == 0) {
|
||||
g_launch.console = (reaktor_console)pick(v, "debug", REAKTOR_CONSOLE_DEBUG, "parent",
|
||||
REAKTOR_CONSOLE_PARENT, REAKTOR_CONSOLE_NONE);
|
||||
g_launch.console = SDL_strcmp(v, "debug") == 0 ? REAKTOR_CONSOLE_DEBUG
|
||||
: SDL_strcmp(v, "parent") == 0 ? REAKTOR_CONSOLE_PARENT
|
||||
: REAKTOR_CONSOLE_NONE;
|
||||
i++;
|
||||
}
|
||||
else if (v && SDL_strcmp(a, "--css") == 0) {
|
||||
if (g_cli_css_n < REAKTOR_LAYER_MAX) g_cli_css[g_cli_css_n++] = own_here(v);
|
||||
else SDL_Log("--css: four at most; %s is not read", v);
|
||||
i++;
|
||||
}
|
||||
else if (v && SDL_strcmp(a, "--icons") == 0) {
|
||||
if (g_cli_icon_n < REAKTOR_LAYER_MAX) g_cli_icons[g_cli_icon_n++] = own_here(v);
|
||||
else SDL_Log("--icons: four at most; %s is not read", v);
|
||||
i++;
|
||||
}
|
||||
else if (v && SDL_strcmp(a, "--css") == 0) { push_layer(g_cli_css, &g_cli_css_n, a, v); i++; }
|
||||
else if (v && SDL_strcmp(a, "--icons") == 0) { push_layer(g_cli_icons, &g_cli_icon_n, a, v); i++; }
|
||||
else if (v && SDL_strcmp(a, "--font") == 0) { g_cli_font = own_here(v); i++; }
|
||||
else if (v && SDL_strcmp(a, "--font-bold") == 0) { g_cli_font_bold = own_here(v); i++; }
|
||||
else if (v && SDL_strcmp(a, "--a11y-dump") == 0) { app->dump_path = v; i++; }
|
||||
@@ -341,14 +291,16 @@ take_flags(App *app, int argc, char **argv)
|
||||
else if (SDL_strcmp(a, "--inspect") == 0) g_inspect_flag = 1;
|
||||
else if (SDL_strcmp(a, "--no-inspector") == 0) g_inspect_flag = -1;
|
||||
else if (SDL_strcmp(a, "--watch-css") == 0) g_watch = 1;
|
||||
else if (v && SDL_strcmp(a, "--motion") == 0) { g_motion_flag = pick(v, "reduce", 1, "full", -1, 0); i++; }
|
||||
else if (v && SDL_strcmp(a, "--contrast") == 0) { g_contrast_flag = pick(v, "more", 1, "normal", -1, 0); i++; }
|
||||
else if (SDL_strcmp(a, "--new-instance") == 0) g_new_instance = 1;
|
||||
else if (v && SDL_strcmp(a, "--renderer") == 0) { app->renderer_pref = v; i++; }
|
||||
else if (v && SDL_strcmp(a, "--hdr") == 0) {
|
||||
g_launch.hdr = pick(v, "on", 1, "off", 0, g_launch.hdr);
|
||||
else if (v && SDL_strcmp(a, "--motion") == 0) {
|
||||
g_motion_flag = SDL_strcmp(v, "reduce") == 0 ? 1 : SDL_strcmp(v, "full") == 0 ? -1 : 0;
|
||||
i++;
|
||||
}
|
||||
else if (v && SDL_strcmp(a, "--contrast") == 0) {
|
||||
g_contrast_flag = SDL_strcmp(v, "more") == 0 ? 1 : SDL_strcmp(v, "normal") == 0 ? -1 : 0;
|
||||
i++;
|
||||
}
|
||||
else if (SDL_strcmp(a, "--new-instance") == 0) g_new_instance = 1;
|
||||
else if (v && SDL_strcmp(a, "--renderer") == 0) { app->renderer_pref = v; i++; }
|
||||
else if (v && SDL_strcmp(a, "--video") == 0) { app->video_pref = v; i++; }
|
||||
else if (v && SDL_strcmp(a, "--popups") == 0) {
|
||||
app->popups_inline = SDL_strcmp(v, "inline") == 0;
|
||||
@@ -357,8 +309,9 @@ take_flags(App *app, int argc, char **argv)
|
||||
else if (v && SDL_strcmp(a, "--lang") == 0) { app->lang_pref = v; i++; }
|
||||
else if (v && SDL_strcmp(a, "--font-fallback") == 0) { add_fallback(v); i++; }
|
||||
else if (v && SDL_strcmp(a, "--theme") == 0) {
|
||||
app->theme_mode = pick(v, "light", REAKTOR_THEME_LIGHT, "dark", REAKTOR_THEME_DARK,
|
||||
REAKTOR_THEME_SYSTEM);
|
||||
if (SDL_strcmp(v, "light") == 0) app->theme_mode = REAKTOR_THEME_LIGHT;
|
||||
else if (SDL_strcmp(v, "dark") == 0) app->theme_mode = REAKTOR_THEME_DARK;
|
||||
else app->theme_mode = REAKTOR_THEME_SYSTEM;
|
||||
i++;
|
||||
} else {
|
||||
argv[n++] = argv[i];
|
||||
@@ -383,6 +336,7 @@ read_roles(App *app)
|
||||
: reaktor_token("--links", app->text);
|
||||
}
|
||||
|
||||
/* Whether the sheets' own tokens already say what the role sheet would. */
|
||||
static int
|
||||
roles_hold(const App *app)
|
||||
{
|
||||
@@ -422,15 +376,13 @@ theme_sheet(int dark)
|
||||
: "external/watercss/src/variables-light.css";
|
||||
}
|
||||
|
||||
/* Whether the system's reduced motion or contrast changed what applies. */
|
||||
static int
|
||||
read_prefs(void)
|
||||
{
|
||||
int r = 0, c = 0, changed;
|
||||
|
||||
if (!g_motion_flag || !g_contrast_flag) reaktor_prefers(&r, &c);
|
||||
if (g_motion_flag) r = g_motion_flag > 0;
|
||||
if (g_contrast_flag) c = g_contrast_flag > 0;
|
||||
changed = r != g_reduced || c != g_contrast;
|
||||
int r = g_motion_flag ? g_motion_flag > 0 : reaktor_prefers_reduced_motion();
|
||||
int c = g_contrast_flag ? g_contrast_flag > 0 : reaktor_prefers_contrast();
|
||||
int changed = r != g_reduced || c != g_contrast;
|
||||
|
||||
g_reduced = r;
|
||||
g_contrast = c;
|
||||
@@ -529,6 +481,7 @@ load_theme(App *app)
|
||||
Uint64 t0, t1;
|
||||
|
||||
app->dark = effective_dark(app);
|
||||
read_prefs();
|
||||
if (g_watch) watch_begin();
|
||||
|
||||
sheets[n++] = theme_sheet(app->dark);
|
||||
@@ -545,22 +498,29 @@ load_theme(App *app)
|
||||
if (!reaktor_style_init(sheets, n, app->dark ? "dark" : "light"))
|
||||
SDL_Log("stylesheets failed to load; Nuklear defaults apply");
|
||||
read_roles(app);
|
||||
if (n > base && !roles_hold(app) && reaktor_style_add(role_sheet(app)))
|
||||
read_roles(app);
|
||||
if (n > base && n < SHEET_MAX && !roles_hold(app)) {
|
||||
sheets[n] = role_sheet(app);
|
||||
if (reaktor_style_init(sheets, n + 1, app->dark ? "dark" : "light"))
|
||||
read_roles(app);
|
||||
}
|
||||
t1 = SDL_GetPerformanceCounter();
|
||||
app->style_ms_x100 = ms_x100(t0, t1);
|
||||
app->style_ms_x100 = (int)(100000.0 * (double)(t1 - t0) /
|
||||
(double)SDL_GetPerformanceFrequency());
|
||||
app->card_bg = reaktor_style_token("--background", c)
|
||||
? nk_rgba(c[0], c[1], c[2], c[3]) : nk_rgb(226, 226, 226);
|
||||
app->icon_col = reaktor_style_token("--text-muted", c)
|
||||
? nk_rgb(c[0], c[1], c[2]) : nk_rgb(0x6a, 0x6a, 0x6a);
|
||||
if (reaktor_style_token("--text-muted", c))
|
||||
SDL_snprintf(app->icon_hex, sizeof(app->icon_hex),
|
||||
"#%02x%02x%02x", c[0], c[1], c[2]);
|
||||
else
|
||||
SDL_strlcpy(app->icon_hex, "#6a6a6a", sizeof(app->icon_hex));
|
||||
|
||||
reaktor_window_set_dark(app->win, app->dark);
|
||||
|
||||
img_cache_clear(app);
|
||||
apply_widget_style(app);
|
||||
|
||||
app->clear = app->page;
|
||||
app->dirty = 1;
|
||||
app->clear = app->page;
|
||||
app->dirty = 1;
|
||||
reaktor_windows_restyle();
|
||||
}
|
||||
|
||||
@@ -575,6 +535,12 @@ reaktor_app_wake(const App *app)
|
||||
return SDL_PushEvent(&e);
|
||||
}
|
||||
|
||||
static bool
|
||||
wake_loop(void)
|
||||
{
|
||||
return reaktor_app_wake(NULL);
|
||||
}
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
static void
|
||||
web_page_size(int *w, int *h)
|
||||
@@ -631,6 +597,7 @@ static int renderer_is_software(SDL_Renderer *ren) { (void)ren; return 0; }
|
||||
#define HOVER_GAP_MS 50
|
||||
|
||||
Uint64 g_hover_gap_ms = HOVER_GAP_MS;
|
||||
static int g_hover_gap_pinned;
|
||||
|
||||
#define CAL_SKIP 3
|
||||
#define CAL_FRAMES 8
|
||||
@@ -640,7 +607,7 @@ calibrate_hover_gap(App *app)
|
||||
{
|
||||
double now;
|
||||
|
||||
if (app->cal_done) return;
|
||||
if (g_hover_gap_pinned || app->cal_done) return;
|
||||
if (app->cal_frames < CAL_SKIP) { app->cal_frames++; return; }
|
||||
now = reaktor_process_cpu_ms();
|
||||
if (app->cal_frames == CAL_SKIP) app->cal_cpu0 = now;
|
||||
@@ -739,7 +706,7 @@ fail(App *app, const char *what)
|
||||
char msg[512];
|
||||
|
||||
SDL_Log("%s: %s", what, SDL_GetError());
|
||||
if (capturing(app)) return SDL_APP_FAILURE;
|
||||
if (app->shot_path || app->dump_path) return SDL_APP_FAILURE;
|
||||
SDL_snprintf(msg, sizeof(msg), "%s.\n\n%s", what, SDL_GetError());
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, launch_title(), msg, NULL);
|
||||
return SDL_APP_FAILURE;
|
||||
@@ -768,7 +735,7 @@ reaktor_hard_quit(int code)
|
||||
{
|
||||
SDL_SetAtomicInt(&g_exit_code, code);
|
||||
SDL_SetAtomicInt(&g_hard_quit, 1);
|
||||
reaktor_app_wake(NULL);
|
||||
wake_loop();
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -820,7 +787,6 @@ app_init(void **appstate, int argc, char *argv[])
|
||||
reaktor_rss_mark(REAKTOR_RSS_ENTRY);
|
||||
app = (App *)SDL_calloc(1, sizeof(App));
|
||||
if (!app) return SDL_APP_FAILURE;
|
||||
app->started = SDL_GetPerformanceCounter();
|
||||
*appstate = app;
|
||||
g_app = app;
|
||||
|
||||
@@ -833,7 +799,9 @@ app_init(void **appstate, int argc, char *argv[])
|
||||
|
||||
if (g_launch.name || g_launch.version || g_launch.id)
|
||||
SDL_SetAppMetadata(g_launch.name, g_launch.version, g_launch.id);
|
||||
if (g_launch.single_instance && !g_new_instance && !capturing(app) &&
|
||||
/* A later launch hands its files to the running copy and is done. */
|
||||
/* A run for a shot or a dump is a test, and always its own copy. */
|
||||
if (g_launch.single_instance && !g_new_instance && !app->shot_path && !app->dump_path &&
|
||||
!reaktor_instance_claim(argc, argv))
|
||||
return SDL_APP_SUCCESS;
|
||||
reaktor_hint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1");
|
||||
@@ -846,13 +814,8 @@ app_init(void **appstate, int argc, char *argv[])
|
||||
#endif
|
||||
|
||||
if (!SDL_Init(SDL_INIT_VIDEO)) return fail(app, "SDL could not start");
|
||||
/* SDL gives the first registration SDL_EVENT_USER, the type wakes push. */
|
||||
SDL_RegisterEvents(1);
|
||||
/* SDL makes every window a drop target while a drop event is enabled; on
|
||||
Windows that is COM's drag-and-drop, three DLLs and three threads. */
|
||||
if (!g_launch.file_opened) {
|
||||
SDL_SetEventEnabled(SDL_EVENT_DROP_FILE, false);
|
||||
SDL_SetEventEnabled(SDL_EVENT_DROP_TEXT, false);
|
||||
}
|
||||
reaktor_signal_watch();
|
||||
if (g_launch.console == REAKTOR_CONSOLE_DEBUG)
|
||||
SDL_SetLogPriorities(SDL_LOG_PRIORITY_DEBUG);
|
||||
@@ -860,16 +823,11 @@ app_init(void **appstate, int argc, char *argv[])
|
||||
reaktor_rss_mark(REAKTOR_RSS_SDL);
|
||||
take_assets(app);
|
||||
|
||||
if (!app->renderer_pref) app->renderer_pref = g_launch.renderer;
|
||||
if (app->renderer_pref && SDL_strcmp(app->renderer_pref, "software") != 0) {
|
||||
SDL_strlcpy(app->render_mode, app->renderer_pref,
|
||||
sizeof(app->render_mode));
|
||||
if (SDL_strcasecmp(app->renderer_pref, "directx") == 0)
|
||||
reaktor_hint(SDL_HINT_RENDER_DRIVER, "direct3d12,direct3d11");
|
||||
else if (SDL_strcasecmp(app->renderer_pref, "gpu") == 0)
|
||||
reaktor_hint(SDL_HINT_RENDER_DRIVER, GPU_DRIVERS);
|
||||
else if (SDL_strcasecmp(app->renderer_pref, "sdl-gpu") == 0)
|
||||
reaktor_hint(SDL_HINT_RENDER_DRIVER, "gpu");
|
||||
else if (SDL_strcmp(app->renderer_pref, "auto") != 0)
|
||||
reaktor_hint(SDL_HINT_RENDER_DRIVER, app->renderer_pref);
|
||||
} else {
|
||||
@@ -885,12 +843,11 @@ app_init(void **appstate, int argc, char *argv[])
|
||||
#endif
|
||||
|
||||
{
|
||||
float pre = SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay());
|
||||
int win_w, win_h;
|
||||
|
||||
if (pre <= 0.0f) pre = 1.0f;
|
||||
win_w = (int)((g_launch.window.w > 0 ? g_launch.window.w : WINDOW_WIDTH) * pre + 0.5f);
|
||||
win_h = (int)((g_launch.window.h > 0 ? g_launch.window.h : WINDOW_HEIGHT) * pre + 0.5f);
|
||||
float pre = reaktor_dpi_query_scale(NULL);
|
||||
int win_w = (int)((g_launch.window.w > 0 ? g_launch.window.w : WINDOW_WIDTH)
|
||||
* pre + 0.5f);
|
||||
int win_h = (int)((g_launch.window.h > 0 ? g_launch.window.h : WINDOW_HEIGHT)
|
||||
* pre + 0.5f);
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
web_page_size(&win_w, &win_h);
|
||||
@@ -901,14 +858,15 @@ app_init(void **appstate, int argc, char *argv[])
|
||||
(g_launch.window.skip_taskbar ? SDL_WINDOW_UTILITY : 0) |
|
||||
(placed(app) || starts_hidden(app) ? SDL_WINDOW_HIDDEN : 0);
|
||||
|
||||
Uint64 t0 = SDL_GetPerformanceCounter();
|
||||
|
||||
if (!open_window(app, win_w, win_h, flags)) {
|
||||
if (!SDL_CreateWindowAndRenderer(launch_title(), win_w, win_h, flags,
|
||||
&app->win, &app->ren)) {
|
||||
SDL_Log("renderer '%s' would not start (%s); falling back",
|
||||
app->render_mode, SDL_GetError());
|
||||
if (app->win) { SDL_DestroyWindow(app->win); app->win = NULL; }
|
||||
reaktor_hint(SDL_HINT_RENDER_DRIVER, NULL);
|
||||
SDL_strlcpy(app->render_mode, "auto", sizeof(app->render_mode));
|
||||
if (!open_window(app, win_w, win_h, flags))
|
||||
if (!SDL_CreateWindowAndRenderer(launch_title(), win_w, win_h, flags,
|
||||
&app->win, &app->ren))
|
||||
return fail(app, "The window could not be opened");
|
||||
}
|
||||
|
||||
@@ -933,7 +891,7 @@ app_init(void **appstate, int argc, char *argv[])
|
||||
}
|
||||
app->renderer_is_sw =
|
||||
SDL_strcmp(SDL_GetRendererName(app->ren), "software") == 0;
|
||||
app->window_ms_x100 = ms_x100(t0, SDL_GetPerformanceCounter());
|
||||
app->sw_noaa = 0;
|
||||
#ifndef __EMSCRIPTEN__
|
||||
if (g_launch.window.min_w > 0 || g_launch.window.min_h > 0)
|
||||
SDL_SetWindowMinimumSize(app->win,
|
||||
@@ -957,6 +915,7 @@ app_init(void **appstate, int argc, char *argv[])
|
||||
|
||||
app->vsync_on = SDL_SetRenderVSync(app->ren, 1) ? 1 : 0;
|
||||
app->aa_mode = (int)g_launch.anti_aliasing;
|
||||
app->redraw_always = 0;
|
||||
|
||||
SDL_strlcpy(app->frame_rate, "waitevent", sizeof(app->frame_rate));
|
||||
|
||||
@@ -981,6 +940,7 @@ app_init(void **appstate, int argc, char *argv[])
|
||||
if (!app->ctx) return fail(app, "The interface could not start");
|
||||
reaktor_rss_mark(REAKTOR_RSS_NUKLEAR);
|
||||
|
||||
/* Before the atlas, which bakes what the catalogs need. */
|
||||
reaktor_locale_start(app->lang_pref);
|
||||
rebuild_font(app);
|
||||
reaktor_rss_mark(REAKTOR_RSS_FONT);
|
||||
@@ -996,7 +956,6 @@ app_init(void **appstate, int argc, char *argv[])
|
||||
reaktor_rss_mark(REAKTOR_RSS_START);
|
||||
|
||||
take_pending(app);
|
||||
read_prefs();
|
||||
load_theme(app);
|
||||
reaktor_rss_mark(REAKTOR_RSS_STYLE);
|
||||
if (g_launch.single_instance) reaktor_instance_listen(app, g_launch.file_opened);
|
||||
@@ -1048,7 +1007,6 @@ reaktor_take_event(App *app, SDL_Event *event)
|
||||
case SDL_EVENT_SYSTEM_THEME_CHANGED:
|
||||
case SDL_EVENT_LOCALE_CHANGED:
|
||||
case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
|
||||
case SDL_EVENT_WINDOW_HDR_STATE_CHANGED:
|
||||
app->dirty = 1;
|
||||
app->why |= REAKTOR_WHY_INPUT;
|
||||
break;
|
||||
@@ -1056,17 +1014,15 @@ reaktor_take_event(App *app, SDL_Event *event)
|
||||
break;
|
||||
}
|
||||
|
||||
/* What the window shows may be gone, whatever the frame would draw. */
|
||||
switch (event->type) {
|
||||
case SDL_EVENT_WINDOW_RESIZED:
|
||||
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
|
||||
case SDL_EVENT_WINDOW_EXPOSED:
|
||||
case SDL_EVENT_WINDOW_SHOWN:
|
||||
case SDL_EVENT_WINDOW_RESTORED:
|
||||
case SDL_EVENT_WINDOW_MAXIMIZED:
|
||||
case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
|
||||
if (!app->dragging && app->restore_rate < 2) app->restore_rate = 2;
|
||||
/* fall through */
|
||||
case SDL_EVENT_WINDOW_EXPOSED:
|
||||
case SDL_EVENT_WINDOW_SHOWN:
|
||||
case SDL_EVENT_WINDOW_HDR_STATE_CHANGED:
|
||||
case SDL_EVENT_RENDER_TARGETS_RESET:
|
||||
case SDL_EVENT_RENDER_DEVICE_RESET:
|
||||
app->must_draw = 1;
|
||||
@@ -1097,6 +1053,8 @@ reaktor_take_event(App *app, SDL_Event *event)
|
||||
reaktor_hint(SDL_HINT_MAIN_CALLBACK_RATE, app->drag_rate);
|
||||
break;
|
||||
|
||||
/* Windows and most desktops send nothing when reduced motion or
|
||||
contrast changes; coming back from their settings is the cue. */
|
||||
case SDL_EVENT_WINDOW_FOCUS_GAINED:
|
||||
if (!app->secondary && read_prefs()) load_theme(app);
|
||||
break;
|
||||
@@ -1111,6 +1069,7 @@ reaktor_take_event(App *app, SDL_Event *event)
|
||||
drag_end(app);
|
||||
break;
|
||||
|
||||
/* Nuklear scrolls a panel at its end, after drawing what it holds. */
|
||||
case SDL_EVENT_MOUSE_WHEEL:
|
||||
if (!app->dragging) app->restore_rate = 2;
|
||||
break;
|
||||
@@ -1122,7 +1081,7 @@ reaktor_take_event(App *app, SDL_Event *event)
|
||||
break;
|
||||
|
||||
case SDL_EVENT_SYSTEM_THEME_CHANGED:
|
||||
if (read_prefs() || app->theme_mode == REAKTOR_THEME_SYSTEM) load_theme(app);
|
||||
if (app->theme_mode == REAKTOR_THEME_SYSTEM || read_prefs()) load_theme(app);
|
||||
break;
|
||||
|
||||
case SDL_EVENT_LOCALE_CHANGED:
|
||||
@@ -1140,7 +1099,7 @@ reaktor_take_event(App *app, SDL_Event *event)
|
||||
break;
|
||||
|
||||
case SDL_EVENT_KEY_DOWN:
|
||||
app->queue.hook_ate = reaktor_key_hook(app, event);
|
||||
app->queue.hook_ate = g_launch.key && g_launch.key(app, event);
|
||||
if (app->queue.hook_ate) return;
|
||||
if (focus_key(app, event)) return;
|
||||
break;
|
||||
@@ -1267,7 +1226,6 @@ app_event(void *appstate, SDL_Event *event)
|
||||
}
|
||||
if (!(to = app)) return SDL_APP_CONTINUE;
|
||||
}
|
||||
if (!to->secondary) reaktor_tray_event(to, event);
|
||||
reaktor_input_event(to, event);
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
@@ -1364,20 +1322,132 @@ file_answer(App *app)
|
||||
app->file_count = 0;
|
||||
}
|
||||
|
||||
/* A command by its fields, one at a time: the structs have gaps, and a gap
|
||||
keeps whatever the buffer or a copied struct held before. */
|
||||
#define H(f) (h = reaktor_fnv_n(h, &(f), sizeof(f)))
|
||||
|
||||
static unsigned
|
||||
command_hash(unsigned h, const struct nk_command *c)
|
||||
{
|
||||
H(c->type);
|
||||
switch (c->type) {
|
||||
case NK_COMMAND_SCISSOR: {
|
||||
const struct nk_command_scissor *x = (const void *)c;
|
||||
H(x->x); H(x->y); H(x->w); H(x->h);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_LINE: {
|
||||
const struct nk_command_line *x = (const void *)c;
|
||||
H(x->line_thickness); H(x->begin); H(x->end); H(x->color);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_CURVE: {
|
||||
const struct nk_command_curve *x = (const void *)c;
|
||||
H(x->line_thickness); H(x->begin); H(x->end); H(x->ctrl); H(x->color);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_RECT: {
|
||||
const struct nk_command_rect *x = (const void *)c;
|
||||
H(x->rounding); H(x->line_thickness); H(x->x); H(x->y); H(x->w); H(x->h); H(x->color);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_RECT_FILLED: {
|
||||
const struct nk_command_rect_filled *x = (const void *)c;
|
||||
H(x->rounding); H(x->x); H(x->y); H(x->w); H(x->h); H(x->color);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_RECT_MULTI_COLOR: {
|
||||
const struct nk_command_rect_multi_color *x = (const void *)c;
|
||||
H(x->x); H(x->y); H(x->w); H(x->h); H(x->left); H(x->top); H(x->bottom); H(x->right);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_TRIANGLE: {
|
||||
const struct nk_command_triangle *x = (const void *)c;
|
||||
H(x->line_thickness); H(x->a); H(x->b); H(x->c); H(x->color);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_TRIANGLE_FILLED: {
|
||||
const struct nk_command_triangle_filled *x = (const void *)c;
|
||||
H(x->a); H(x->b); H(x->c); H(x->color);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_CIRCLE: {
|
||||
const struct nk_command_circle *x = (const void *)c;
|
||||
H(x->x); H(x->y); H(x->line_thickness); H(x->w); H(x->h); H(x->color);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_CIRCLE_FILLED: {
|
||||
const struct nk_command_circle_filled *x = (const void *)c;
|
||||
H(x->x); H(x->y); H(x->w); H(x->h); H(x->color);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_ARC: {
|
||||
const struct nk_command_arc *x = (const void *)c;
|
||||
H(x->cx); H(x->cy); H(x->r); H(x->line_thickness); H(x->a); H(x->color);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_ARC_FILLED: {
|
||||
const struct nk_command_arc_filled *x = (const void *)c;
|
||||
H(x->cx); H(x->cy); H(x->r); H(x->a); H(x->color);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_POLYGON:
|
||||
case NK_COMMAND_POLYLINE: {
|
||||
const struct nk_command_polygon *x = (const void *)c;
|
||||
H(x->color); H(x->line_thickness); H(x->point_count);
|
||||
h = reaktor_fnv_n(h, x->points, (nk_size)x->point_count * sizeof x->points[0]);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_POLYGON_FILLED: {
|
||||
const struct nk_command_polygon_filled *x = (const void *)c;
|
||||
H(x->color); H(x->point_count);
|
||||
h = reaktor_fnv_n(h, x->points, (nk_size)x->point_count * sizeof x->points[0]);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_IMAGE: {
|
||||
const struct nk_command_image *x = (const void *)c;
|
||||
H(x->x); H(x->y); H(x->w); H(x->h);
|
||||
H(x->img.handle.ptr); H(x->img.w); H(x->img.h); H(x->img.region); H(x->col);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_CUSTOM: {
|
||||
const struct nk_command_custom *x = (const void *)c;
|
||||
H(x->x); H(x->y); H(x->w); H(x->h); H(x->callback_data.ptr); H(x->callback);
|
||||
break;
|
||||
}
|
||||
case NK_COMMAND_TEXT: {
|
||||
const struct nk_command_text *x = (const void *)c;
|
||||
H(x->font); H(x->background); H(x->foreground);
|
||||
H(x->x); H(x->y); H(x->w); H(x->h); H(x->height); H(x->length);
|
||||
h = reaktor_fnv_n(h, x->string, (nk_size)x->length);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
#undef H
|
||||
|
||||
/* With .skip_same_frames, a frame whose commands are those already on screen
|
||||
is neither rendered nor presented. */
|
||||
static int
|
||||
same_frame(App *app, struct nk_context *ctx)
|
||||
{
|
||||
unsigned h;
|
||||
int same;
|
||||
|
||||
if (g_launch.draw_every_frame) return 0;
|
||||
h = reaktor_damage_collect(app, ctx);
|
||||
if (!g_launch.skip_same_frames) return 0;
|
||||
h = REAKTOR_FNV;
|
||||
{
|
||||
const struct nk_command *c;
|
||||
|
||||
nk_foreach(c, ctx) h = command_hash(h, c);
|
||||
}
|
||||
h = reaktor_fnv_n(h, &app->laid_w, sizeof app->laid_w);
|
||||
h = reaktor_fnv_n(h, &app->laid_h, sizeof app->laid_h);
|
||||
h = reaktor_fnv_n(h, &app->clear, sizeof app->clear);
|
||||
app->damage.forced = app->must_draw || app->want_capture || app->shot_path ||
|
||||
!app->first_frame_done;
|
||||
same = h == app->frame_hash && !app->damage.forced;
|
||||
same = h == app->frame_hash && !app->must_draw && !app->want_capture &&
|
||||
!app->shot_path && app->first_frame_done;
|
||||
app->frame_hash = h;
|
||||
app->must_draw = 0;
|
||||
return same;
|
||||
@@ -1443,8 +1513,7 @@ reaktor_app_frame(App *app, int win_w, int win_h, const char *title,
|
||||
struct nk_context *ctx = app->ctx;
|
||||
struct nk_rect area = nk_rect(0, 0, (float)win_w, (float)win_h);
|
||||
int is_main = !app->secondary, shot = 0, shown;
|
||||
Uint64 now = SDL_GetTicks(), t_build0, t_render0, t_present0, t_end;
|
||||
int busy;
|
||||
Uint64 now = SDL_GetTicks(), f, t_build0, t_render0, t_present0, t_end;
|
||||
|
||||
app->laid_w = win_w;
|
||||
app->laid_h = win_h;
|
||||
@@ -1511,6 +1580,7 @@ reaktor_app_frame(App *app, int win_w, int win_h, const char *title,
|
||||
}
|
||||
app->stop_editing = 0;
|
||||
|
||||
/* A click for a held widget would land on whatever holds it. */
|
||||
if (app->activate_id && app->focus_seen && !app->focus_held &&
|
||||
!reaktor_focus_covered(app))
|
||||
reaktor_key_click_ask(app);
|
||||
@@ -1538,14 +1608,14 @@ reaktor_app_frame(App *app, int win_w, int win_h, const char *title,
|
||||
reader_activate, reader_focus, app);
|
||||
}
|
||||
|
||||
busy = app->anim && reaktor_anim_settle();
|
||||
if (busy) {
|
||||
if (app->anim && reaktor_anim_settle()) {
|
||||
app->dirty = 1;
|
||||
reaktor_app_wake(app);
|
||||
}
|
||||
|
||||
nk_sdl_update_TextInput(ctx);
|
||||
#ifdef __EMSCRIPTEN__
|
||||
/* After the frame, when a field has said whether it is being edited. */
|
||||
reaktor_web_keys_wants(app->editing);
|
||||
#endif
|
||||
reaktor_place_ime(app);
|
||||
@@ -1554,21 +1624,15 @@ reaktor_app_frame(App *app, int win_w, int win_h, const char *title,
|
||||
nk_style_pop_float(ctx);
|
||||
nk_style_pop_vec2(ctx);
|
||||
|
||||
f = SDL_GetPerformanceFrequency();
|
||||
t_render0 = SDL_GetPerformanceCounter();
|
||||
if (app->build_only || same_frame(app, ctx) || !reaktor_damage_render(app)) {
|
||||
/* A drawn frame clears in nk_sdl_frame_done; kept, the next build's
|
||||
popups and overlay never join the list. */
|
||||
nk_clear(ctx);
|
||||
if (same_frame(app, ctx)) {
|
||||
t_present0 = t_end = t_render0;
|
||||
app->frames_skipped++;
|
||||
if (busy && !app->build_only) {
|
||||
reaktor_hint(SDL_HINT_MAIN_CALLBACK_RATE, app->drag_rate);
|
||||
if (!reaktor_windows_holding()) app->restore_rate = 2;
|
||||
}
|
||||
} else {
|
||||
app->frames_drawn++;
|
||||
nk_sdl_frame_done(ctx);
|
||||
SDL_FlushRenderer(app->ren);
|
||||
if (is_main) reaktor_text_prepare(ctx, app->ren);
|
||||
reaktor_render(app);
|
||||
t_present0 = SDL_GetPerformanceCounter();
|
||||
if (is_main) shot = take_shot(app);
|
||||
if (app->want_capture) {
|
||||
@@ -1576,15 +1640,14 @@ reaktor_app_frame(App *app, int win_w, int win_h, const char *title,
|
||||
app->want_capture = 0;
|
||||
}
|
||||
SDL_RenderPresent(app->ren);
|
||||
reaktor_damage_presented(app);
|
||||
t_end = SDL_GetPerformanceCounter();
|
||||
}
|
||||
|
||||
app->last_draw_ms = SDL_GetTicks();
|
||||
if (is_main && app->first_frame_done) calibrate_hover_gap(app);
|
||||
app->build_ms_x100 = ms_x100(t_build0, t_render0);
|
||||
app->render_ms_x100 = ms_x100(t_render0, t_present0);
|
||||
app->present_ms_x100 = ms_x100(t_present0, t_end);
|
||||
app->build_ms_x100 = (int)(100000.0 * (double)(t_render0 - t_build0) / (double)f);
|
||||
app->render_ms_x100 = (int)(100000.0 * (double)(t_present0 - t_render0) / (double)f);
|
||||
app->present_ms_x100 = (int)(100000.0 * (double)(t_end - t_present0) / (double)f);
|
||||
|
||||
nk_input_begin(ctx);
|
||||
|
||||
@@ -1617,7 +1680,6 @@ app_iterate(void *appstate)
|
||||
}
|
||||
if (g_css_pending || app->theme_pending) {
|
||||
take_pending(app);
|
||||
read_prefs();
|
||||
load_theme(app);
|
||||
}
|
||||
reaktor_windows_draw();
|
||||
@@ -1643,14 +1705,13 @@ app_iterate(void *appstate)
|
||||
|
||||
reaktor_app_size(app, &win_w, &win_h);
|
||||
reaktor_app_due(app, win_w, win_h);
|
||||
if (!app->dirty)
|
||||
if (!app->dirty && !app->redraw_always)
|
||||
return SDL_APP_CONTINUE;
|
||||
if (reaktor_app_frame(app, win_w, win_h, launch_title(), main_page, NULL))
|
||||
return SDL_APP_SUCCESS;
|
||||
|
||||
if (!app->first_frame_done) {
|
||||
app->first_frame_done = 1;
|
||||
app->first_ms_x100 = ms_x100(app->started, SDL_GetPerformanceCounter());
|
||||
reaktor_hint(SDL_HINT_MAIN_CALLBACK_RATE, app->frame_rate);
|
||||
reaktor_release_free_memory();
|
||||
}
|
||||
@@ -1699,10 +1760,8 @@ app_quit(void *appstate, SDL_AppResult result)
|
||||
}
|
||||
}
|
||||
if (app->ren) img_cache_free(app);
|
||||
reaktor_damage_free(app);
|
||||
if (app->ctx) nk_sdl_shutdown(app->ctx);
|
||||
reaktor_fontset_free(&app->fonts);
|
||||
atlas_forget();
|
||||
if (app->ren) SDL_DestroyRenderer(app->ren);
|
||||
if (app->win) SDL_DestroyWindow(app->win);
|
||||
reaktor_anim_destroy(app->anim);
|
||||
@@ -1791,10 +1850,11 @@ reaktor_quit(App *app, int exit_code)
|
||||
void
|
||||
reaktor_request_quit(App *app)
|
||||
{
|
||||
(void)app;
|
||||
#ifdef __EMSCRIPTEN__
|
||||
(void)app;
|
||||
SDL_Log("quit is ignored on the web");
|
||||
#else
|
||||
(void)app;
|
||||
push_quit(REAKTOR_QUIT_APP);
|
||||
#endif
|
||||
}
|
||||
@@ -1805,6 +1865,7 @@ reaktor_wake(App *app)
|
||||
App *to = app ? app : g_app;
|
||||
|
||||
if (!to || !SDL_GetAtomicInt(&g_running)) return;
|
||||
/* A lost wake would hold back every later one. */
|
||||
if (SDL_CompareAndSwapAtomicInt(&to->wake, 0, 1) && !reaktor_app_wake(to))
|
||||
SDL_SetAtomicInt(&to->wake, 0);
|
||||
}
|
||||
@@ -1984,8 +2045,6 @@ reaktor_set_visible(App *app, int on)
|
||||
if (!app || !app->win) return;
|
||||
if (on) {
|
||||
SDL_ShowWindow(app->win);
|
||||
if (SDL_GetWindowFlags(app->win) & SDL_WINDOW_MINIMIZED)
|
||||
SDL_RestoreWindow(app->win);
|
||||
SDL_RaiseWindow(app->win);
|
||||
} else {
|
||||
SDL_HideWindow(app->win);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
static Uint32 g_page_key;
|
||||
static enum nk_keys g_web_key;
|
||||
|
||||
/* A phone's named keys, REAKTOR_WEB_KEY_BACKSPACE (-1) first. */
|
||||
static const struct { SDL_Keycode sdl; enum nk_keys nk; } g_soft[] = {
|
||||
{ SDLK_BACKSPACE, NK_KEY_BACKSPACE }, { SDLK_RETURN, NK_KEY_ENTER },
|
||||
{ SDLK_LEFT, NK_KEY_LEFT }, { SDLK_RIGHT, NK_KEY_RIGHT },
|
||||
@@ -16,6 +17,7 @@ static const struct { SDL_Keycode sdl; enum nk_keys nk; } g_soft[] = {
|
||||
};
|
||||
#define SOFT_KEYS ((int)(sizeof(g_soft) / sizeof(g_soft[0])))
|
||||
|
||||
/* Let go next frame, or Nuklear never sees it pressed. */
|
||||
static void
|
||||
page_key_take(struct nk_context *ctx, int code)
|
||||
{
|
||||
@@ -41,6 +43,7 @@ reaktor_input_page_key(App *app, SDL_Event *event)
|
||||
|
||||
if (event->type != g_page_key) return 0;
|
||||
app->dirty = 1;
|
||||
/* Not Backspace, which also replays edits. */
|
||||
if (c <= REAKTOR_WEB_KEY_ENTER && c >= REAKTOR_WEB_KEY_DELETE) {
|
||||
SDL_Event k;
|
||||
|
||||
@@ -185,6 +188,7 @@ hold_for_next_frame(App *app, const SDL_Event *event)
|
||||
size_t n;
|
||||
|
||||
if (!held_kind(event->type)) {
|
||||
/* Window events stay behind held input. */
|
||||
if (!q->n || event->type < SDL_EVENT_WINDOW_FIRST ||
|
||||
event->type > SDL_EVENT_WINDOW_LAST)
|
||||
return 0;
|
||||
@@ -328,6 +332,7 @@ touch_sample(App *app, float y, Uint64 ns)
|
||||
app->touch_n++;
|
||||
}
|
||||
|
||||
/* Nuklear moves a panel a tenth of its height per wheel step. */
|
||||
static float
|
||||
touch_unit(const App *app)
|
||||
{
|
||||
@@ -381,6 +386,7 @@ reaktor_fling_step(App *app)
|
||||
}
|
||||
}
|
||||
|
||||
/* A finger that moves mostly up or down scrolls, and presses nothing. */
|
||||
static int
|
||||
touch_takes(App *app, const SDL_Event *e)
|
||||
{
|
||||
@@ -427,6 +433,7 @@ touch_takes(App *app, const SDL_Event *e)
|
||||
app->touch = TOUCH_DRAGGING;
|
||||
return 0;
|
||||
}
|
||||
/* Released away from every widget, the press clicks nothing. */
|
||||
if (app->touch == TOUCH_PRESSED) touch_pointer(app, -1e4f, -1e4f, 1);
|
||||
touch_pointer(app, app->touch_x0, app->touch_y0, 0);
|
||||
app->touch = TOUCH_SCROLLING;
|
||||
|
||||
+8
-13
@@ -151,7 +151,7 @@ kv_list(const char *name)
|
||||
reaktor_list(&(reaktor_list_spec){
|
||||
.name = name, .count = g_rows, .columns = cols, .widths = widths,
|
||||
.column_count = 2, .cell = kv_cell,
|
||||
.box = { .flags = REAKTOR_LAY_FILL } });
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } });
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -184,7 +184,7 @@ tab_tree(void)
|
||||
reaktor_tree(&(reaktor_tree_spec){
|
||||
.name = "Widgets", .count = g_n, .parent = tree_parent, .label = tree_label,
|
||||
.open = g_open, .selected = &sel,
|
||||
.box = { .flags = REAKTOR_LAY_FILL } });
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } });
|
||||
if (sel != g_sel_ix && sel >= 0 && sel < g_n) {
|
||||
g_sel = g_node[sel].id;
|
||||
g_sel_ix = sel;
|
||||
@@ -299,12 +299,6 @@ tab_style(void)
|
||||
row("Selector", "%s%s", sel, st.matched ? "" : " (no rule matches)");
|
||||
color_row("color", st.fg);
|
||||
color_row("background", st.bg);
|
||||
if (st.gradient)
|
||||
row("background-image", "%s #%02x%02x%02x%02x to #%02x%02x%02x%02x",
|
||||
st.gradient == REAKTOR_GRADIENT_ACROSS ? "across" : "down",
|
||||
st.gradient_from[0], st.gradient_from[1], st.gradient_from[2],
|
||||
st.gradient_from[3], st.gradient_to[0], st.gradient_to[1],
|
||||
st.gradient_to[2], st.gradient_to[3]);
|
||||
color_row("border-color", st.border_col);
|
||||
row("border-width", "%.0f %.0f %.0f %.0f", st.border_w[0], st.border_w[1],
|
||||
st.border_w[2], st.border_w[3]);
|
||||
@@ -317,7 +311,7 @@ tab_style(void)
|
||||
row("min", "%.0f x %.0f", st.min_width, st.min_height);
|
||||
row("max", "%.0f x %.0f", st.max_width, st.max_height);
|
||||
row("font", "%dpx%s", st.font_px, st.bold ? " bold" : "");
|
||||
REAKTOR_COLUMN(.flags = REAKTOR_LAY_FILL, .gap = 8.0f) {
|
||||
REAKTOR_COLUMN(.flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y, .gap = 8.0f) {
|
||||
kv_list("Style");
|
||||
note("CSS here applies after every other sheet, to this run only.");
|
||||
reaktor_field(&(reaktor_field_spec){
|
||||
@@ -357,8 +351,6 @@ tab_frame(void)
|
||||
row("Present", "%.2f ms", d.present_ms);
|
||||
row("Since the previous frame", "%.1f ms", d.frame_gap_ms);
|
||||
row("Stylesheets", "%d, loaded in %.2f ms", d.sheets, d.style_ms);
|
||||
row("Startup", "window %.1f ms, atlas %.1f ms, first frame at %.0f ms",
|
||||
d.window_ms, d.atlas_ms, d.first_frame_ms);
|
||||
row("Renderer", "%s, %s", d.renderer ? d.renderer : "", d.mode ? d.mode : "");
|
||||
row("Scale", "%.2f", d.scale);
|
||||
row("Process memory", "%lu KiB", d.rss_bytes / 1024ul);
|
||||
@@ -413,9 +405,10 @@ tab_logs(void)
|
||||
reaktor_list(&(reaktor_list_spec){
|
||||
.name = "Log", .count = g_log_rows, .columns = cols, .widths = widths,
|
||||
.column_count = 3, .cell = log_cell,
|
||||
.box = { .flags = REAKTOR_LAY_FILL } });
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } });
|
||||
}
|
||||
|
||||
/* A flat icon beside the tabs; its name is also what the pointer shows. */
|
||||
static int
|
||||
tool(const char *icon, const char *name, const char *tip, int on, int off, float mr)
|
||||
{
|
||||
@@ -454,6 +447,7 @@ page(App *app, struct reaktor_context *ctx, int w, int h, void *user)
|
||||
g_sel = 0;
|
||||
redraw();
|
||||
}
|
||||
/* The page's floater has no titlebar to close it from. */
|
||||
if (tool("close-circle-outline", "Close the Inspector", NULL, 0, 0, 8.0f))
|
||||
reaktor_inspector_close(g_main);
|
||||
#else
|
||||
@@ -463,7 +457,7 @@ page(App *app, struct reaktor_context *ctx, int w, int h, void *user)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
REAKTOR_COLUMN(.flags = REAKTOR_LAY_FILL, .gap = 8.0f) {
|
||||
REAKTOR_COLUMN(.flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y, .gap = 8.0f) {
|
||||
switch (g_tab) {
|
||||
case TAB_TREE: tab_tree(); break;
|
||||
case TAB_BOX: tab_box(); break;
|
||||
@@ -627,6 +621,7 @@ reaktor_inspector_frame(App *app)
|
||||
g_why = app->why;
|
||||
app->why = 0;
|
||||
if (!shown()) return;
|
||||
/* Only the Frame tab changes with every frame; the rest follow the tree. */
|
||||
{
|
||||
static unsigned last;
|
||||
const reaktor_a11y_node *n;
|
||||
|
||||
+21
-1
@@ -1,3 +1,6 @@
|
||||
/* One running copy per app when .single_instance asks for it: a later launch
|
||||
hands its file arguments to the running copy and exits. Each message is a
|
||||
count of paths, then each path as a length and its bytes. */
|
||||
#include "internal.h"
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
@@ -23,6 +26,7 @@ deliver_raise(App *app, void *user)
|
||||
SDL_RaiseWindow(app->win);
|
||||
}
|
||||
|
||||
/* What a read gives back: the paths, posted to the main thread in order. */
|
||||
typedef int (*instance_read)(void *conn, void *buf, Uint32 n);
|
||||
|
||||
static void
|
||||
@@ -46,6 +50,8 @@ receive(App *app, instance_read rd, void *conn)
|
||||
reaktor_post(app, deliver_raise, NULL);
|
||||
}
|
||||
|
||||
/* The message a later launch sends: its arguments, made absolute, since the
|
||||
running copy's working folder is its own. */
|
||||
static int
|
||||
message(int argc, char **argv, char **out, Uint32 *out_len)
|
||||
{
|
||||
@@ -55,7 +61,16 @@ message(int argc, char **argv, char **out, Uint32 *out_len)
|
||||
|
||||
for (i = 1; i < argc && count < INSTANCE_PATHS_MAX; i++) {
|
||||
if (!argv[i] || !*argv[i]) continue;
|
||||
if (!(abs[count] = reaktor_path_from_cwd(argv[i]))) continue;
|
||||
if (reaktor_path_absolute(argv[i])) {
|
||||
abs[count] = SDL_strdup(argv[i]);
|
||||
} else {
|
||||
char *cwd = SDL_GetCurrentDirectory();
|
||||
|
||||
abs[count] = NULL;
|
||||
if (cwd && SDL_asprintf(&abs[count], "%s%s", cwd, argv[i]) < 0) abs[count] = NULL;
|
||||
SDL_free(cwd);
|
||||
}
|
||||
if (!abs[count]) continue;
|
||||
total += (Uint32)(sizeof(Uint32) + SDL_strlen(abs[count]));
|
||||
count++;
|
||||
}
|
||||
@@ -191,6 +206,7 @@ reaktor_instance_claim(int argc, char **argv)
|
||||
if (g_mutex) CloseHandle(g_mutex);
|
||||
g_mutex = NULL;
|
||||
|
||||
/* The first copy may still be starting its listener. */
|
||||
for (tries = 0; tries < 50; tries++) {
|
||||
pipe = CreateFileA(g_pipe, GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
|
||||
SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION, NULL);
|
||||
@@ -306,6 +322,8 @@ sock_read(void *conn, void *buf, Uint32 n)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Beside the app's settings when that fits a socket's path, else in a /tmp
|
||||
folder only this user can reach. */
|
||||
static int
|
||||
sock_path(void)
|
||||
{
|
||||
@@ -377,6 +395,7 @@ reaktor_instance_claim(int argc, char **argv)
|
||||
close(s);
|
||||
return 0;
|
||||
}
|
||||
/* Nobody listens: a copy that crashed left its socket behind. */
|
||||
unlink(g_sock);
|
||||
}
|
||||
return 1;
|
||||
@@ -417,6 +436,7 @@ reaktor_instance_stop(void)
|
||||
{
|
||||
if (g_listen < 0) return;
|
||||
SDL_SetAtomicInt(&g_stop, 1);
|
||||
/* The listener waits in accept; one connection releases it. */
|
||||
if (g_thread) {
|
||||
int s = sock_connect();
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ reaktor_window_popup(struct nk_rect r,
|
||||
return reaktor_window_spawn(&spec, &r);
|
||||
}
|
||||
|
||||
/* The usable display, in the main window's logical units. */
|
||||
int
|
||||
reaktor_window_bounds(struct nk_rect *out)
|
||||
{
|
||||
|
||||
+3
-2
@@ -65,6 +65,7 @@ put(buffer *b, const char *fmt, ...)
|
||||
else put_bytes(b, line, n);
|
||||
}
|
||||
|
||||
/* A PDF text string: as it is when it is plain ASCII, else UTF-16BE. */
|
||||
static void
|
||||
put_text(buffer *b, const char *s)
|
||||
{
|
||||
@@ -91,6 +92,7 @@ put_text(buffer *b, const char *s)
|
||||
put(b, ">");
|
||||
}
|
||||
|
||||
/* Each page a JPEG drawn over the whole of it. */
|
||||
static int
|
||||
pdf_write(const char *path, const char *title, SDL_Surface *const *page, int n,
|
||||
float pt_w, float pt_h)
|
||||
@@ -162,6 +164,7 @@ pdf_write(const char *path, const char *title, SDL_Surface *const *page, int n,
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
/* The system's print dialog, then each page stretched over the printable area. */
|
||||
static int
|
||||
print_win32(App *app, SDL_Surface *const *page, int n, const char *title)
|
||||
{
|
||||
@@ -232,10 +235,8 @@ print_run(App *app, void *user)
|
||||
|
||||
job->index = i;
|
||||
reaktor_app_size(pa, &w, &h);
|
||||
pa->build_only = 1;
|
||||
for (k = 0; k < 3 || (!reaktor_frame_settled(pa) && k < 24); k++)
|
||||
reaktor_app_frame(pa, w, h, "", print_page, job);
|
||||
pa->build_only = 0;
|
||||
pa->want_capture = 1;
|
||||
reaktor_app_frame(pa, w, h, "", print_page, job);
|
||||
page[i] = pa->capture ? SDL_ConvertSurface(pa->capture, SDL_PIXELFORMAT_ARGB8888) : NULL;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <PDFKit/PDFKit.h>
|
||||
|
||||
/* The PDF through the system's print dialog. */
|
||||
int
|
||||
reaktor_print_macos(const char *path)
|
||||
{
|
||||
|
||||
+85
-162
@@ -1,16 +1,19 @@
|
||||
#include "internal.h"
|
||||
|
||||
#include "toml.h"
|
||||
#define INI_IMPLEMENTATION
|
||||
#define INI_MALLOC(ctx, size) ((void)(ctx), SDL_malloc(size))
|
||||
#define INI_FREE(ctx, ptr) ((void)(ctx), SDL_free(ptr))
|
||||
#define INI_MEMCPY(dst, src, cnt) SDL_memcpy(dst, src, cnt)
|
||||
#define INI_STRLEN(s) SDL_strlen(s)
|
||||
#define INI_STRNICMP(s1, s2, cnt) SDL_strncasecmp(s1, s2, cnt)
|
||||
#include "ini.h"
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
typedef struct { char *key, *value; } setting;
|
||||
|
||||
static setting *g_set;
|
||||
static int g_count, g_cap, g_loaded;
|
||||
static int g_dirty;
|
||||
static ini_t *g_ini;
|
||||
static int g_ini_dirty;
|
||||
static unsigned g_save_timer;
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
@@ -27,137 +30,70 @@ settings_path(void)
|
||||
char *dir = SDL_GetPrefPath(NULL, reaktor_app_ident());
|
||||
char *path = NULL;
|
||||
|
||||
if (dir) SDL_asprintf(&path, "%ssettings.toml", dir);
|
||||
if (dir) SDL_asprintf(&path, "%ssettings.conf", dir);
|
||||
SDL_free(dir);
|
||||
return path;
|
||||
}
|
||||
|
||||
static int
|
||||
setting_index(const char *key)
|
||||
static ini_t *
|
||||
settings(void)
|
||||
{
|
||||
int i;
|
||||
char *text;
|
||||
|
||||
for (i = 0; i < g_count; i++)
|
||||
if (SDL_strcmp(g_set[i].key, key) == 0) return i;
|
||||
return -1;
|
||||
}
|
||||
if (g_ini) return g_ini;
|
||||
if (reaktor_capturing()) return g_ini = ini_create(NULL);
|
||||
{
|
||||
char *path = settings_path();
|
||||
|
||||
static void
|
||||
setting_put(char *key, char *value)
|
||||
{
|
||||
int i = setting_index(key);
|
||||
|
||||
if (i >= 0) {
|
||||
SDL_free(key);
|
||||
SDL_free(g_set[i].value);
|
||||
g_set[i].value = value;
|
||||
return;
|
||||
}
|
||||
if (!reaktor_grow((void **)&g_set, &g_cap, g_count + 1, sizeof *g_set)) {
|
||||
SDL_free(key);
|
||||
SDL_free(value);
|
||||
return;
|
||||
}
|
||||
g_set[g_count].key = key;
|
||||
g_set[g_count++].value = value;
|
||||
}
|
||||
|
||||
static void
|
||||
settings_take(const toml_table_t *t, const char *prefix)
|
||||
{
|
||||
int i, len, n = toml_table_len(t);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
const char *name = toml_table_key(t, i, &len);
|
||||
toml_value_t v;
|
||||
toml_table_t *sub;
|
||||
char *key = NULL, *value = NULL;
|
||||
|
||||
SDL_asprintf(&key, "%s%s", prefix, name);
|
||||
if (!key) continue;
|
||||
if ((sub = toml_table_table(t, name)) != NULL) {
|
||||
SDL_asprintf(&value, "%s.", key);
|
||||
if (value) settings_take(sub, value);
|
||||
SDL_free(value);
|
||||
SDL_free(key);
|
||||
continue;
|
||||
}
|
||||
if ((v = toml_table_string(t, name)).ok) {
|
||||
value = SDL_strdup(v.u.s);
|
||||
free(v.u.s);
|
||||
} else if ((v = toml_table_int(t, name)).ok) {
|
||||
SDL_asprintf(&value, "%lld", (long long)v.u.i);
|
||||
} else if ((v = toml_table_double(t, name)).ok) {
|
||||
SDL_asprintf(&value, "%g", v.u.d);
|
||||
} else if ((v = toml_table_bool(t, name)).ok) {
|
||||
value = SDL_strdup(v.u.b ? "true" : "false");
|
||||
}
|
||||
if (value) setting_put(key, value);
|
||||
else SDL_free(key);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
settings_load(void)
|
||||
{
|
||||
char *text, *path;
|
||||
|
||||
if (g_loaded) return;
|
||||
g_loaded = 1;
|
||||
if (reaktor_capturing()) return;
|
||||
path = settings_path();
|
||||
text = path ? (char *)SDL_LoadFile(path, NULL) : NULL;
|
||||
SDL_free(path);
|
||||
if (text) {
|
||||
char err[200];
|
||||
toml_table_t *root = toml_parse(text, err, sizeof err);
|
||||
|
||||
if (root) settings_take(root, "");
|
||||
else SDL_Log("settings not read: %s", err);
|
||||
toml_free(root);
|
||||
text = path ? (char *)SDL_LoadFile(path, NULL) : NULL;
|
||||
SDL_free(path);
|
||||
}
|
||||
g_ini = text ? ini_load(text, NULL) : ini_create(NULL);
|
||||
SDL_free(text);
|
||||
return g_ini;
|
||||
}
|
||||
|
||||
static void
|
||||
put_string(SDL_IOStream *out, const char *s)
|
||||
static int
|
||||
setting_find(const char *key, int *section, int add)
|
||||
{
|
||||
SDL_WriteU8(out, '"');
|
||||
for (; *s; s++) {
|
||||
unsigned char c = (unsigned char)*s;
|
||||
const char *dot = SDL_strrchr(key, '.');
|
||||
ini_t *ini = settings();
|
||||
|
||||
if (c == '"' || c == '\\') SDL_IOprintf(out, "\\%c", c);
|
||||
else if (c == '\n') SDL_IOprintf(out, "\\n");
|
||||
else if (c == '\t') SDL_IOprintf(out, "\\t");
|
||||
else if (c < 0x20 || c == 0x7f) SDL_IOprintf(out, "\\u%04X", c);
|
||||
else SDL_WriteU8(out, c);
|
||||
*section = INI_GLOBAL_SECTION;
|
||||
if (!ini) return INI_NOT_FOUND;
|
||||
if (dot) {
|
||||
*section = ini_find_section(ini, key, (int)(dot - key));
|
||||
if (*section == INI_NOT_FOUND && add)
|
||||
*section = ini_section_add(ini, key, (int)(dot - key));
|
||||
if (*section == INI_NOT_FOUND) return INI_NOT_FOUND;
|
||||
key = dot + 1;
|
||||
}
|
||||
SDL_WriteU8(out, '"');
|
||||
return ini_find_property(ini, *section, key, 0);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_settings_save(void)
|
||||
{
|
||||
char *path, *tmp = NULL;
|
||||
SDL_IOStream *out;
|
||||
int i, ok;
|
||||
int size;
|
||||
char *text;
|
||||
|
||||
if (!g_dirty || reaktor_capturing()) return;
|
||||
path = settings_path();
|
||||
if (path) SDL_asprintf(&tmp, "%s.new", path);
|
||||
out = tmp ? SDL_IOFromFile(tmp, "wb") : NULL;
|
||||
for (i = 0; out && i < g_count; i++) {
|
||||
put_string(out, g_set[i].key);
|
||||
SDL_IOprintf(out, " = ");
|
||||
put_string(out, g_set[i].value);
|
||||
SDL_WriteU8(out, '\n');
|
||||
if (!g_ini_dirty || !g_ini || reaktor_capturing()) return;
|
||||
size = ini_save(g_ini, NULL, 0);
|
||||
text = (char *)SDL_malloc((size_t)size);
|
||||
if (!text) return;
|
||||
ini_save(g_ini, text, size);
|
||||
{
|
||||
char *path = settings_path(), *tmp = NULL;
|
||||
|
||||
if (path) SDL_asprintf(&tmp, "%s.new", path);
|
||||
if (!tmp || !SDL_SaveFile(tmp, text, (size_t)size - 1) || !SDL_RenamePath(tmp, path))
|
||||
SDL_Log("settings not saved: %s", SDL_GetError());
|
||||
SDL_free(tmp);
|
||||
SDL_free(path);
|
||||
}
|
||||
ok = out && SDL_CloseIO(out) && SDL_RenamePath(tmp, path);
|
||||
if (!ok) SDL_Log("settings not saved: %s", SDL_GetError());
|
||||
SDL_free(tmp);
|
||||
SDL_free(path);
|
||||
settings_persist();
|
||||
g_dirty = 0;
|
||||
SDL_free(text);
|
||||
g_ini_dirty = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -174,7 +110,7 @@ settings_changed(void)
|
||||
int ms;
|
||||
reaktor_save mode = reaktor_save_mode(&ms);
|
||||
|
||||
g_dirty = 1;
|
||||
g_ini_dirty = 1;
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (mode == REAKTOR_SAVE_ON_QUIT) mode = REAKTOR_SAVE_ON_CHANGE;
|
||||
#endif
|
||||
@@ -187,74 +123,61 @@ settings_changed(void)
|
||||
const char *
|
||||
reaktor_setting(const char *key)
|
||||
{
|
||||
int i;
|
||||
int section, property = key ? setting_find(key, §ion, 0) : INI_NOT_FOUND;
|
||||
|
||||
if (!key) return NULL;
|
||||
settings_load();
|
||||
i = setting_index(key);
|
||||
return i < 0 ? NULL : g_set[i].value;
|
||||
return property == INI_NOT_FOUND ? NULL
|
||||
: ini_property_value(g_ini, section, property);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_setting_set(const char *key, const char *value)
|
||||
{
|
||||
int i;
|
||||
const char *name;
|
||||
int section, property;
|
||||
|
||||
if (!key || !*key) return;
|
||||
settings_load();
|
||||
i = setting_index(key);
|
||||
if (i < 0 && !value) return;
|
||||
if (i >= 0 && value && SDL_strcmp(g_set[i].value, value) == 0) return;
|
||||
if (i >= 0 && value) {
|
||||
SDL_free(g_set[i].value);
|
||||
g_set[i].value = SDL_strdup(value);
|
||||
} else if (value) {
|
||||
setting_put(SDL_strdup(key), SDL_strdup(value));
|
||||
} else {
|
||||
SDL_free(g_set[i].key);
|
||||
SDL_free(g_set[i].value);
|
||||
SDL_memmove(&g_set[i], &g_set[i + 1], (size_t)(g_count - i - 1) * sizeof *g_set);
|
||||
g_count--;
|
||||
}
|
||||
if (!key || !*key || SDL_strpbrk(key, "=[]\n") || (value && SDL_strchr(value, '\n')))
|
||||
return;
|
||||
property = setting_find(key, §ion, value != NULL);
|
||||
name = SDL_strrchr(key, '.') ? SDL_strrchr(key, '.') + 1 : key;
|
||||
if (property != INI_NOT_FOUND && value &&
|
||||
SDL_strcmp(ini_property_value(g_ini, section, property), value) == 0)
|
||||
return;
|
||||
if (!value && property == INI_NOT_FOUND) return;
|
||||
if (!value)
|
||||
ini_property_remove(g_ini, section, property);
|
||||
else if (property != INI_NOT_FOUND)
|
||||
ini_property_value_set(g_ini, section, property, value, 0);
|
||||
else if (section != INI_NOT_FOUND)
|
||||
ini_property_add(g_ini, section, name, 0, value, 0);
|
||||
else
|
||||
return;
|
||||
settings_changed();
|
||||
}
|
||||
|
||||
static void
|
||||
settings_empty(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < g_count; i++) {
|
||||
SDL_free(g_set[i].key);
|
||||
SDL_free(g_set[i].value);
|
||||
}
|
||||
SDL_free(g_set);
|
||||
g_set = NULL;
|
||||
g_count = g_cap = 0;
|
||||
g_dirty = 0;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_settings_clear(void)
|
||||
{
|
||||
char *path;
|
||||
|
||||
settings_empty();
|
||||
g_loaded = 1;
|
||||
ini_destroy(g_ini);
|
||||
g_ini = ini_create(NULL);
|
||||
g_ini_dirty = 0;
|
||||
if (g_save_timer) reaktor_timer_stop(g_save_timer);
|
||||
g_save_timer = 0;
|
||||
if (reaktor_capturing()) return;
|
||||
path = settings_path();
|
||||
if (path) SDL_RemovePath(path);
|
||||
SDL_free(path);
|
||||
{
|
||||
char *path = settings_path();
|
||||
|
||||
if (path) SDL_RemovePath(path);
|
||||
SDL_free(path);
|
||||
}
|
||||
settings_persist();
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_settings_free(void)
|
||||
{
|
||||
settings_empty();
|
||||
g_loaded = 0;
|
||||
ini_destroy(g_ini);
|
||||
g_ini = NULL;
|
||||
g_ini_dirty = 0;
|
||||
g_save_timer = 0;
|
||||
}
|
||||
|
||||
|
||||
+11
-8
@@ -1,6 +1,8 @@
|
||||
/* The script runs on a thread of its own. Every look at the tree happens on
|
||||
the main thread, and every action waits until the window has drawn and
|
||||
settled. */
|
||||
/* An application driven from a script, as a person would: the script runs on
|
||||
a thread of its own, finds widgets in the accessibility tree by name or
|
||||
mark, and acts through the same SDL events a mouse and keyboard send. Every
|
||||
look at the tree happens on the main thread, and every action waits until
|
||||
the window has drawn and settled. */
|
||||
#include "internal.h"
|
||||
#include "reaktor/test.h"
|
||||
#include "declare.h"
|
||||
@@ -54,6 +56,7 @@ matches(const reaktor_a11y_node *n, const char *target)
|
||||
return n->name && SDL_strcmp(n->name, target) == 0;
|
||||
}
|
||||
|
||||
/* Whether the node at i sits, at any depth, inside a node marked scope. */
|
||||
static int
|
||||
within(const reaktor_a11y_node *tree, int i, const char *scope)
|
||||
{
|
||||
@@ -78,6 +81,8 @@ look_main(App *app, void *user)
|
||||
const char *target = q->target, *space;
|
||||
int scoped = 0;
|
||||
|
||||
/* "#list Delete": a mark, then what to find inside it. A whole target
|
||||
that is itself a mark, spaces and all, is taken as one. */
|
||||
if (target[0] == '#' && !reaktor_mark_has(0, target + 1) &&
|
||||
(space = SDL_strchr(target, ' ')) && (size_t)(space - target) < sizeof scope) {
|
||||
SDL_strlcpy(scope, target + 1, (size_t)(space - target));
|
||||
@@ -232,6 +237,7 @@ reaktor_test_type(reaktor_test *t, const char *target, const char *text)
|
||||
return !t->stuck;
|
||||
}
|
||||
|
||||
/* "Ctrl+Shift+S", "Enter", "Escape": the modifiers, then one key by its SDL name. */
|
||||
int
|
||||
reaktor_test_key(reaktor_test *t, const char *chord)
|
||||
{
|
||||
@@ -292,22 +298,19 @@ script_thread(void *data)
|
||||
reaktor_test *t = (reaktor_test *)data;
|
||||
|
||||
g_script(t, g_user);
|
||||
reaktor_test_settle(t);
|
||||
if (t->app->damage.partial)
|
||||
reaktor_test_check(t, !t->app->damage.mismatched,
|
||||
"every partial frame matches a full redraw");
|
||||
if (!t->checks) reaktor_test_check(t, 0, "the script checked nothing");
|
||||
SDL_Log("test: %d of %d checks passed", t->checks - t->fails, t->checks);
|
||||
reaktor_quit(t->app, t->fails || t->stuck ? 1 : 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* From the main window's frame: the script starts once the first frame settles. */
|
||||
static void
|
||||
test_frame(App *app)
|
||||
{
|
||||
test_ask *q = (test_ask *)SDL_GetAtomicPointer(&g_settle);
|
||||
|
||||
app->damage.checking = 1;
|
||||
/* A settle asked for: two frames drawn since, and the last one settled. */
|
||||
if (q) {
|
||||
if (!q->seq) q->seq = app->ctx->seq + 1;
|
||||
if (app->ctx->seq >= q->seq + 2 && reaktor_frame_settled(app)) {
|
||||
|
||||
+9
-804
@@ -3,796 +3,10 @@
|
||||
|
||||
#define TRAY_ITEMS 16
|
||||
|
||||
#ifdef REAKTOR_TRAY_DBUS
|
||||
/* SDL's tray here builds its menu from GTK widgets, and loading GTK cost the
|
||||
showcase hundreds of libraries and half a second. */
|
||||
#include "gibus.h"
|
||||
#include <poll.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define SNI_PATH "/StatusNotifierItem"
|
||||
#define SNI_IFACE "org.kde.StatusNotifierItem"
|
||||
#define MENU_PATH "/MenuBar"
|
||||
#define MENU_IFACE "com.canonical.dbusmenu"
|
||||
#define WATCHER "org.kde.StatusNotifierWatcher"
|
||||
#define PROPS_IFACE GIBUS_INTERFACE_PROPERTIES
|
||||
|
||||
static gibus_conn *g_bus;
|
||||
static reaktor_tray_item g_item[TRAY_ITEMS];
|
||||
static int g_on[TRAY_ITEMS];
|
||||
static char *g_label[TRAY_ITEMS];
|
||||
static char *g_tip;
|
||||
static char g_name[64];
|
||||
static int g_n, g_hide_on_minimize, g_tag;
|
||||
static Uint8 *g_icon[4];
|
||||
static int g_icon_px[4], g_icons;
|
||||
|
||||
/* SDL has no way to wait on another descriptor, so one thread sleeps in
|
||||
poll() on the bus and wakes the frame loop, which reads and answers. It
|
||||
never touches the connection; it waits for the main thread to drain it. */
|
||||
static SDL_Thread *g_thread;
|
||||
static SDL_Semaphore *g_drained;
|
||||
static SDL_AtomicInt g_running;
|
||||
static int g_stop[2] = { -1, -1 };
|
||||
static Sint32 g_gen;
|
||||
|
||||
static reaktor_tray_item g_chosen[TRAY_ITEMS];
|
||||
static int g_chosen_on[TRAY_ITEMS], g_chosen_n;
|
||||
|
||||
static int SDLCALL
|
||||
watch_bus(void *fdp)
|
||||
{
|
||||
struct pollfd p[2];
|
||||
Sint32 gen = g_gen;
|
||||
|
||||
p[0].fd = (int)(intptr_t)fdp;
|
||||
p[0].events = POLLIN;
|
||||
p[1].fd = g_stop[0];
|
||||
p[1].events = POLLIN;
|
||||
while (SDL_GetAtomicInt(&g_running)) {
|
||||
SDL_Event e;
|
||||
|
||||
if (poll(p, 2, -1) < 0) continue;
|
||||
if (p[1].revents || !SDL_GetAtomicInt(&g_running)) break;
|
||||
if (!p[0].revents) continue;
|
||||
SDL_zero(e);
|
||||
e.type = SDL_EVENT_USER;
|
||||
e.user.data1 = &g_tag;
|
||||
e.user.code = gen;
|
||||
if (!SDL_PushEvent(&e)) break;
|
||||
SDL_WaitSemaphore(g_drained);
|
||||
if (p[0].revents & (POLLHUP | POLLERR)) break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
put_variant(gibus_iter *it, int type, const char *sig, const void *v)
|
||||
{
|
||||
gibus_iter var;
|
||||
|
||||
gibus_iter_open(it, GIBUS_TYPE_VARIANT, sig, &var);
|
||||
gibus_iter_append_basic(&var, type, v);
|
||||
gibus_iter_close(it, &var);
|
||||
}
|
||||
|
||||
static void
|
||||
put_entry(gibus_iter *dict, const char *key, int type, const char *sig, const void *v)
|
||||
{
|
||||
gibus_iter e;
|
||||
|
||||
gibus_iter_open(dict, GIBUS_TYPE_DICT_ENTRY, NULL, &e);
|
||||
gibus_iter_append_basic(&e, GIBUS_TYPE_STRING, &key);
|
||||
put_variant(&e, type, sig, v);
|
||||
gibus_iter_close(dict, &e);
|
||||
}
|
||||
|
||||
static void
|
||||
put_empty(gibus_iter *it, const char *sig)
|
||||
{
|
||||
gibus_iter arr;
|
||||
|
||||
gibus_iter_open(it, GIBUS_TYPE_ARRAY, sig, &arr);
|
||||
gibus_iter_close(it, &arr);
|
||||
}
|
||||
|
||||
static void
|
||||
put_pixmaps(gibus_iter *it, int all)
|
||||
{
|
||||
gibus_iter arr, st, bytes;
|
||||
int i;
|
||||
|
||||
gibus_iter_open(it, GIBUS_TYPE_ARRAY, "(iiay)", &arr);
|
||||
for (i = 0; all && i < g_icons; i++) {
|
||||
int32_t px = g_icon_px[i];
|
||||
|
||||
gibus_iter_open(&arr, GIBUS_TYPE_STRUCT, NULL, &st);
|
||||
gibus_iter_append_basic(&st, GIBUS_TYPE_INT32, &px);
|
||||
gibus_iter_append_basic(&st, GIBUS_TYPE_INT32, &px);
|
||||
gibus_iter_open(&st, GIBUS_TYPE_ARRAY, "y", &bytes);
|
||||
gibus_iter_append_fixed_array(&bytes, GIBUS_TYPE_BYTE, g_icon[i], px * px * 4);
|
||||
gibus_iter_close(&st, &bytes);
|
||||
gibus_iter_close(&arr, &st);
|
||||
}
|
||||
gibus_iter_close(it, &arr);
|
||||
}
|
||||
|
||||
static void
|
||||
put_tooltip(gibus_iter *it)
|
||||
{
|
||||
gibus_iter var, st;
|
||||
const char *none = "", *tip = g_tip ? g_tip : "";
|
||||
|
||||
gibus_iter_open(it, GIBUS_TYPE_VARIANT, "(sa(iiay)ss)", &var);
|
||||
gibus_iter_open(&var, GIBUS_TYPE_STRUCT, NULL, &st);
|
||||
gibus_iter_append_basic(&st, GIBUS_TYPE_STRING, &none);
|
||||
put_pixmaps(&st, 0);
|
||||
gibus_iter_append_basic(&st, GIBUS_TYPE_STRING, &tip);
|
||||
gibus_iter_append_basic(&st, GIBUS_TYPE_STRING, &none);
|
||||
gibus_iter_close(&var, &st);
|
||||
gibus_iter_close(it, &var);
|
||||
}
|
||||
|
||||
static int
|
||||
sni_prop(gibus_iter *it, const char *name)
|
||||
{
|
||||
const char *none = "", *menu = MENU_PATH, *id = reaktor_app_ident();
|
||||
const char *cat = "ApplicationStatus", *status = "Active";
|
||||
const char *title = g_tip ? g_tip : id;
|
||||
gibus_bool yes = 1;
|
||||
int32_t zero = 0;
|
||||
gibus_iter var;
|
||||
|
||||
if (!SDL_strcmp(name, "Category")) put_variant(it, GIBUS_TYPE_STRING, "s", &cat);
|
||||
else if (!SDL_strcmp(name, "Id")) put_variant(it, GIBUS_TYPE_STRING, "s", &id);
|
||||
else if (!SDL_strcmp(name, "Title")) put_variant(it, GIBUS_TYPE_STRING, "s", &title);
|
||||
else if (!SDL_strcmp(name, "Status")) put_variant(it, GIBUS_TYPE_STRING, "s", &status);
|
||||
else if (!SDL_strcmp(name, "WindowId")) put_variant(it, GIBUS_TYPE_INT32, "i", &zero);
|
||||
else if (!SDL_strcmp(name, "IconName") || !SDL_strcmp(name, "OverlayIconName") ||
|
||||
!SDL_strcmp(name, "AttentionIconName") ||
|
||||
!SDL_strcmp(name, "AttentionMovieName"))
|
||||
put_variant(it, GIBUS_TYPE_STRING, "s", &none);
|
||||
else if (!SDL_strcmp(name, "IconPixmap") || !SDL_strcmp(name, "OverlayIconPixmap") ||
|
||||
!SDL_strcmp(name, "AttentionIconPixmap")) {
|
||||
gibus_iter_open(it, GIBUS_TYPE_VARIANT, "a(iiay)", &var);
|
||||
put_pixmaps(&var, name[0] == 'I');
|
||||
gibus_iter_close(it, &var);
|
||||
} else if (!SDL_strcmp(name, "ToolTip")) put_tooltip(it);
|
||||
else if (!SDL_strcmp(name, "ItemIsMenu")) put_variant(it, GIBUS_TYPE_BOOLEAN, "b", &yes);
|
||||
else if (!SDL_strcmp(name, "Menu")) put_variant(it, GIBUS_TYPE_OBJECT_PATH, "o", &menu);
|
||||
else return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char *const sni_props[] = {
|
||||
"Category", "Id", "Title", "Status", "WindowId", "IconName", "IconPixmap",
|
||||
"OverlayIconName", "OverlayIconPixmap", "AttentionIconName",
|
||||
"AttentionIconPixmap", "AttentionMovieName", "ToolTip", "ItemIsMenu", "Menu"
|
||||
};
|
||||
|
||||
static int
|
||||
menu_prop(gibus_iter *it, const char *name)
|
||||
{
|
||||
const char *dir = "ltr", *status = "normal";
|
||||
uint32_t version = 3;
|
||||
gibus_iter var;
|
||||
|
||||
if (!SDL_strcmp(name, "Version")) put_variant(it, GIBUS_TYPE_UINT32, "u", &version);
|
||||
else if (!SDL_strcmp(name, "TextDirection")) put_variant(it, GIBUS_TYPE_STRING, "s", &dir);
|
||||
else if (!SDL_strcmp(name, "Status")) put_variant(it, GIBUS_TYPE_STRING, "s", &status);
|
||||
else if (!SDL_strcmp(name, "IconThemePath")) {
|
||||
gibus_iter_open(it, GIBUS_TYPE_VARIANT, "as", &var);
|
||||
put_empty(&var, "s");
|
||||
gibus_iter_close(it, &var);
|
||||
} else return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char *const menu_props[] = { "Version", "TextDirection", "Status", "IconThemePath" };
|
||||
|
||||
typedef struct item_out {
|
||||
gibus_iter *it;
|
||||
const char *want;
|
||||
int found;
|
||||
} item_out;
|
||||
|
||||
static void
|
||||
put_prop(item_out *o, const char *key, int type, const char *sig, const void *v)
|
||||
{
|
||||
if (!o->want) {
|
||||
put_entry(o->it, key, type, sig, v);
|
||||
} else if (!o->found && !SDL_strcmp(key, o->want)) {
|
||||
put_variant(o->it, type, sig, v);
|
||||
o->found = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
item_props(item_out *o, int id)
|
||||
{
|
||||
const reaktor_tray_item *t = id > 0 ? &g_item[id - 1] : NULL;
|
||||
|
||||
if (!t) {
|
||||
const char *sub = "submenu";
|
||||
|
||||
put_prop(o, "children-display", GIBUS_TYPE_STRING, "s", &sub);
|
||||
} else if (!t->label) {
|
||||
const char *sep = "separator";
|
||||
|
||||
put_prop(o, "type", GIBUS_TYPE_STRING, "s", &sep);
|
||||
} else {
|
||||
const char *label = g_label[id - 1] ? g_label[id - 1] : "";
|
||||
gibus_bool on = !t->disabled;
|
||||
|
||||
put_prop(o, "label", GIBUS_TYPE_STRING, "s", &label);
|
||||
put_prop(o, "enabled", GIBUS_TYPE_BOOLEAN, "b", &on);
|
||||
if (t->checkbox) {
|
||||
const char *mark = "checkmark";
|
||||
int32_t state = g_on[id - 1];
|
||||
|
||||
put_prop(o, "toggle-type", GIBUS_TYPE_STRING, "s", &mark);
|
||||
put_prop(o, "toggle-state", GIBUS_TYPE_INT32, "i", &state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
put_item_props(gibus_iter *it, int id)
|
||||
{
|
||||
gibus_iter dict;
|
||||
item_out o;
|
||||
|
||||
gibus_iter_open(it, GIBUS_TYPE_ARRAY, "{sv}", &dict);
|
||||
o.it = &dict;
|
||||
o.want = NULL;
|
||||
o.found = 0;
|
||||
item_props(&o, id);
|
||||
gibus_iter_close(it, &dict);
|
||||
}
|
||||
|
||||
static void
|
||||
put_layout(gibus_iter *it, int id, int depth)
|
||||
{
|
||||
gibus_iter st, kids, var;
|
||||
int32_t i32 = id;
|
||||
int i;
|
||||
|
||||
gibus_iter_open(it, GIBUS_TYPE_STRUCT, NULL, &st);
|
||||
gibus_iter_append_basic(&st, GIBUS_TYPE_INT32, &i32);
|
||||
put_item_props(&st, id);
|
||||
gibus_iter_open(&st, GIBUS_TYPE_ARRAY, "v", &kids);
|
||||
for (i = 0; id == 0 && depth != 0 && i < g_n; i++) {
|
||||
gibus_iter_open(&kids, GIBUS_TYPE_VARIANT, "(ia{sv}av)", &var);
|
||||
put_layout(&var, i + 1, depth - 1);
|
||||
gibus_iter_close(&kids, &var);
|
||||
}
|
||||
gibus_iter_close(&st, &kids);
|
||||
gibus_iter_close(it, &st);
|
||||
}
|
||||
|
||||
static void
|
||||
put_item(gibus_iter *arr, int32_t id)
|
||||
{
|
||||
gibus_iter st;
|
||||
|
||||
gibus_iter_open(arr, GIBUS_TYPE_STRUCT, NULL, &st);
|
||||
gibus_iter_append_basic(&st, GIBUS_TYPE_INT32, &id);
|
||||
put_item_props(&st, id);
|
||||
gibus_iter_close(arr, &st);
|
||||
}
|
||||
|
||||
static void
|
||||
send_and_free(gibus_msg *m)
|
||||
{
|
||||
if (!m) return;
|
||||
gibus_send(g_bus, m, NULL);
|
||||
gibus_msg_free(m);
|
||||
gibus_flush(g_bus);
|
||||
}
|
||||
|
||||
static void
|
||||
items_updated(int id)
|
||||
{
|
||||
gibus_msg *m = gibus_msg_signal(MENU_PATH, MENU_IFACE, "ItemsPropertiesUpdated");
|
||||
gibus_iter it, arr;
|
||||
|
||||
if (!m) return;
|
||||
gibus_iter_init_append(m, &it);
|
||||
gibus_iter_open(&it, GIBUS_TYPE_ARRAY, "(ia{sv})", &arr);
|
||||
put_item(&arr, id);
|
||||
gibus_iter_close(&it, &arr);
|
||||
put_empty(&it, "(ias)");
|
||||
send_and_free(m);
|
||||
}
|
||||
|
||||
static void
|
||||
clicked(int id)
|
||||
{
|
||||
const reaktor_tray_item *it;
|
||||
|
||||
if (id < 1 || id > g_n) return;
|
||||
it = &g_item[id - 1];
|
||||
if (!it->label || it->disabled) return;
|
||||
if (it->checkbox) {
|
||||
g_on[id - 1] = !g_on[id - 1];
|
||||
items_updated(id);
|
||||
}
|
||||
if (it->chosen && g_chosen_n < TRAY_ITEMS) {
|
||||
g_chosen[g_chosen_n] = *it;
|
||||
g_chosen_on[g_chosen_n++] = it->checkbox && g_on[id - 1];
|
||||
}
|
||||
}
|
||||
|
||||
static const char sni_xml[] =
|
||||
GIBUS_INTROSPECT_DOCTYPE
|
||||
"<node><interface name=\"" SNI_IFACE "\">"
|
||||
"<method name=\"Activate\"><arg type=\"i\" direction=\"in\"/><arg type=\"i\" direction=\"in\"/></method>"
|
||||
"<method name=\"SecondaryActivate\"><arg type=\"i\" direction=\"in\"/><arg type=\"i\" direction=\"in\"/></method>"
|
||||
"<method name=\"ContextMenu\"><arg type=\"i\" direction=\"in\"/><arg type=\"i\" direction=\"in\"/></method>"
|
||||
"<method name=\"Scroll\"><arg type=\"i\" direction=\"in\"/><arg type=\"s\" direction=\"in\"/></method>"
|
||||
"<property name=\"Category\" type=\"s\" access=\"read\"/>"
|
||||
"<property name=\"Id\" type=\"s\" access=\"read\"/>"
|
||||
"<property name=\"Title\" type=\"s\" access=\"read\"/>"
|
||||
"<property name=\"Status\" type=\"s\" access=\"read\"/>"
|
||||
"<property name=\"WindowId\" type=\"i\" access=\"read\"/>"
|
||||
"<property name=\"IconName\" type=\"s\" access=\"read\"/>"
|
||||
"<property name=\"IconPixmap\" type=\"a(iiay)\" access=\"read\"/>"
|
||||
"<property name=\"OverlayIconName\" type=\"s\" access=\"read\"/>"
|
||||
"<property name=\"OverlayIconPixmap\" type=\"a(iiay)\" access=\"read\"/>"
|
||||
"<property name=\"AttentionIconName\" type=\"s\" access=\"read\"/>"
|
||||
"<property name=\"AttentionIconPixmap\" type=\"a(iiay)\" access=\"read\"/>"
|
||||
"<property name=\"AttentionMovieName\" type=\"s\" access=\"read\"/>"
|
||||
"<property name=\"ToolTip\" type=\"(sa(iiay)ss)\" access=\"read\"/>"
|
||||
"<property name=\"ItemIsMenu\" type=\"b\" access=\"read\"/>"
|
||||
"<property name=\"Menu\" type=\"o\" access=\"read\"/>"
|
||||
"<signal name=\"NewTitle\"/><signal name=\"NewIcon\"/><signal name=\"NewToolTip\"/>"
|
||||
"<signal name=\"NewStatus\"><arg type=\"s\"/></signal>"
|
||||
"</interface></node>";
|
||||
|
||||
static const char menu_xml[] =
|
||||
GIBUS_INTROSPECT_DOCTYPE
|
||||
"<node><interface name=\"" MENU_IFACE "\">"
|
||||
"<method name=\"GetLayout\"><arg type=\"i\" direction=\"in\"/><arg type=\"i\" direction=\"in\"/>"
|
||||
"<arg type=\"as\" direction=\"in\"/><arg type=\"u\" direction=\"out\"/>"
|
||||
"<arg type=\"(ia{sv}av)\" direction=\"out\"/></method>"
|
||||
"<method name=\"GetGroupProperties\"><arg type=\"ai\" direction=\"in\"/>"
|
||||
"<arg type=\"as\" direction=\"in\"/><arg type=\"a(ia{sv})\" direction=\"out\"/></method>"
|
||||
"<method name=\"GetProperty\"><arg type=\"i\" direction=\"in\"/><arg type=\"s\" direction=\"in\"/>"
|
||||
"<arg type=\"v\" direction=\"out\"/></method>"
|
||||
"<method name=\"Event\"><arg type=\"i\" direction=\"in\"/><arg type=\"s\" direction=\"in\"/>"
|
||||
"<arg type=\"v\" direction=\"in\"/><arg type=\"u\" direction=\"in\"/></method>"
|
||||
"<method name=\"EventGroup\"><arg type=\"a(isvu)\" direction=\"in\"/>"
|
||||
"<arg type=\"ai\" direction=\"out\"/></method>"
|
||||
"<method name=\"AboutToShow\"><arg type=\"i\" direction=\"in\"/><arg type=\"b\" direction=\"out\"/></method>"
|
||||
"<method name=\"AboutToShowGroup\"><arg type=\"ai\" direction=\"in\"/>"
|
||||
"<arg type=\"ai\" direction=\"out\"/><arg type=\"ai\" direction=\"out\"/></method>"
|
||||
"<property name=\"Version\" type=\"u\" access=\"read\"/>"
|
||||
"<property name=\"TextDirection\" type=\"s\" access=\"read\"/>"
|
||||
"<property name=\"Status\" type=\"s\" access=\"read\"/>"
|
||||
"<property name=\"IconThemePath\" type=\"as\" access=\"read\"/>"
|
||||
"<signal name=\"ItemsPropertiesUpdated\"><arg type=\"a(ia{sv})\"/><arg type=\"a(ias)\"/></signal>"
|
||||
"<signal name=\"LayoutUpdated\"><arg type=\"u\"/><arg type=\"i\"/></signal>"
|
||||
"<signal name=\"ItemActivationRequested\"><arg type=\"i\"/><arg type=\"u\"/></signal>"
|
||||
"</interface></node>";
|
||||
|
||||
static gibus_msg *
|
||||
properties(gibus_msg *m, int menu)
|
||||
{
|
||||
int (*prop)(gibus_iter *, const char *) = menu ? menu_prop : sni_prop;
|
||||
const char *const *names = menu ? menu_props : sni_props;
|
||||
int count = menu ? (int)SDL_arraysize(menu_props) : (int)SDL_arraysize(sni_props);
|
||||
const char *iface = NULL, *name = NULL;
|
||||
gibus_msg *r;
|
||||
gibus_iter it, dict, e;
|
||||
int i;
|
||||
|
||||
if (gibus_msg_is_call(m, PROPS_IFACE, "GetAll")) {
|
||||
if (!gibus_msg_get_args(m, NULL, GIBUS_TYPE_STRING, &iface, GIBUS_TYPE_INVALID))
|
||||
return gibus_msg_error(m, GIBUS_ERROR_INVALID_ARGS, "GetAll(s)");
|
||||
if (!(r = gibus_msg_return(m))) return NULL;
|
||||
gibus_iter_init_append(r, &it);
|
||||
gibus_iter_open(&it, GIBUS_TYPE_ARRAY, "{sv}", &dict);
|
||||
for (i = 0; i < count; i++) {
|
||||
gibus_iter_open(&dict, GIBUS_TYPE_DICT_ENTRY, NULL, &e);
|
||||
gibus_iter_append_basic(&e, GIBUS_TYPE_STRING, &names[i]);
|
||||
prop(&e, names[i]);
|
||||
gibus_iter_close(&dict, &e);
|
||||
}
|
||||
gibus_iter_close(&it, &dict);
|
||||
return r;
|
||||
}
|
||||
if (gibus_msg_is_call(m, PROPS_IFACE, "Get")) {
|
||||
if (!gibus_msg_get_args(m, NULL, GIBUS_TYPE_STRING, &iface,
|
||||
GIBUS_TYPE_STRING, &name, GIBUS_TYPE_INVALID))
|
||||
return gibus_msg_error(m, GIBUS_ERROR_INVALID_ARGS, "Get(ss)");
|
||||
if (!(r = gibus_msg_return(m))) return NULL;
|
||||
gibus_iter_init_append(r, &it);
|
||||
if (prop(&it, name)) return r;
|
||||
gibus_msg_free(r);
|
||||
return gibus_msg_error(m, GIBUS_ERROR_UNKNOWN_PROPERTY, name);
|
||||
}
|
||||
return gibus_msg_error(m, GIBUS_ERROR_PROPERTY_READ_ONLY, "read only");
|
||||
}
|
||||
|
||||
static gibus_msg *
|
||||
menu_call(gibus_msg *m, const char *member)
|
||||
{
|
||||
gibus_msg *r = NULL;
|
||||
gibus_iter in, out, arr;
|
||||
int32_t id = 0, depth = -1;
|
||||
int i;
|
||||
|
||||
if (!SDL_strcmp(member, "GetLayout")) {
|
||||
if (!gibus_msg_get_args(m, NULL, GIBUS_TYPE_INT32, &id, GIBUS_TYPE_INT32, &depth,
|
||||
GIBUS_TYPE_INVALID) || id < 0 || id > g_n)
|
||||
return gibus_msg_error(m, GIBUS_ERROR_INVALID_ARGS, "no such item");
|
||||
if (!(r = gibus_msg_return(m))) return NULL;
|
||||
uint32_t revision = 1;
|
||||
|
||||
gibus_iter_init_append(r, &out);
|
||||
gibus_iter_append_basic(&out, GIBUS_TYPE_UINT32, &revision);
|
||||
put_layout(&out, id, depth);
|
||||
} else if (!SDL_strcmp(member, "GetGroupProperties")) {
|
||||
const int32_t *ids = NULL;
|
||||
int n = 0;
|
||||
|
||||
if (!gibus_msg_get_args(m, NULL, GIBUS_TYPE_ARRAY, GIBUS_TYPE_INT32, &ids, &n,
|
||||
GIBUS_TYPE_INVALID))
|
||||
n = 0;
|
||||
if (!(r = gibus_msg_return(m))) return NULL;
|
||||
gibus_iter_init_append(r, &out);
|
||||
gibus_iter_open(&out, GIBUS_TYPE_ARRAY, "(ia{sv})", &arr);
|
||||
for (i = 0; i < (n ? n : g_n + 1); i++) {
|
||||
id = n ? ids[i] : i;
|
||||
if (id >= 0 && id <= g_n) put_item(&arr, id);
|
||||
}
|
||||
gibus_iter_close(&out, &arr);
|
||||
} else if (!SDL_strcmp(member, "GetProperty")) {
|
||||
const char *name = NULL;
|
||||
item_out o;
|
||||
|
||||
if (!gibus_msg_get_args(m, NULL, GIBUS_TYPE_INT32, &id, GIBUS_TYPE_STRING, &name,
|
||||
GIBUS_TYPE_INVALID) || id < 0 || id > g_n)
|
||||
return gibus_msg_error(m, GIBUS_ERROR_INVALID_ARGS, "no such item");
|
||||
if (!(r = gibus_msg_return(m))) return NULL;
|
||||
gibus_iter_init_append(r, &out);
|
||||
o.it = &out;
|
||||
o.want = name;
|
||||
o.found = 0;
|
||||
item_props(&o, id);
|
||||
if (!o.found) {
|
||||
gibus_msg_free(r);
|
||||
return gibus_msg_error(m, GIBUS_ERROR_INVALID_ARGS, "no such property");
|
||||
}
|
||||
} else if (!SDL_strcmp(member, "Event")) {
|
||||
const char *what = NULL;
|
||||
|
||||
if (!gibus_msg_get_args(m, NULL, GIBUS_TYPE_INT32, &id, GIBUS_TYPE_STRING, &what,
|
||||
GIBUS_TYPE_INVALID))
|
||||
what = NULL;
|
||||
r = gibus_msg_return(m);
|
||||
if (what && !SDL_strcmp(what, "clicked")) {
|
||||
send_and_free(r);
|
||||
clicked(id);
|
||||
return NULL;
|
||||
}
|
||||
} else if (!SDL_strcmp(member, "EventGroup")) {
|
||||
gibus_iter evs, ev;
|
||||
int n = 0, chosen[TRAY_ITEMS];
|
||||
|
||||
if (gibus_msg_has_signature(m, "a(isvu)") && gibus_iter_init(m, &in)) {
|
||||
gibus_iter_recurse(&in, &evs);
|
||||
while (gibus_iter_type(&evs) == GIBUS_TYPE_STRUCT) {
|
||||
const char *what = NULL;
|
||||
|
||||
gibus_iter_recurse(&evs, &ev);
|
||||
gibus_iter_get_basic(&ev, &id);
|
||||
gibus_iter_next(&ev);
|
||||
if (gibus_iter_type(&ev) == GIBUS_TYPE_STRING)
|
||||
gibus_iter_get_basic(&ev, &what);
|
||||
if (what && !SDL_strcmp(what, "clicked") && n < TRAY_ITEMS) chosen[n++] = id;
|
||||
gibus_iter_next(&evs);
|
||||
}
|
||||
}
|
||||
if ((r = gibus_msg_return(m))) {
|
||||
gibus_iter_init_append(r, &out);
|
||||
put_empty(&out, "i");
|
||||
send_and_free(r);
|
||||
}
|
||||
for (i = 0; i < n; i++) clicked(chosen[i]);
|
||||
return NULL;
|
||||
} else if (!SDL_strcmp(member, "AboutToShow")) {
|
||||
gibus_bool no = 0;
|
||||
|
||||
if ((r = gibus_msg_return(m)))
|
||||
gibus_msg_append_args(r, GIBUS_TYPE_BOOLEAN, &no, GIBUS_TYPE_INVALID);
|
||||
} else if (!SDL_strcmp(member, "AboutToShowGroup")) {
|
||||
if ((r = gibus_msg_return(m))) {
|
||||
gibus_iter_init_append(r, &out);
|
||||
put_empty(&out, "i");
|
||||
put_empty(&out, "i");
|
||||
}
|
||||
} else {
|
||||
r = gibus_msg_error(m, GIBUS_ERROR_UNKNOWN_METHOD, member);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
static int
|
||||
on_message(gibus_conn *c, gibus_msg *m, void *menup)
|
||||
{
|
||||
int menu = menup != NULL;
|
||||
const char *iface = gibus_msg_interface(m);
|
||||
const char *member = gibus_msg_member(m);
|
||||
gibus_msg *r = NULL;
|
||||
|
||||
(void)c;
|
||||
if (gibus_msg_type(m) != GIBUS_MESSAGE_METHOD_CALL || !member)
|
||||
return GIBUS_NOT_YET_HANDLED;
|
||||
if (iface && !SDL_strcmp(iface, GIBUS_INTERFACE_INTROSPECTABLE)) {
|
||||
const char *xml = menu ? menu_xml : sni_xml;
|
||||
|
||||
if ((r = gibus_msg_return(m)))
|
||||
gibus_msg_append_args(r, GIBUS_TYPE_STRING, &xml, GIBUS_TYPE_INVALID);
|
||||
} else if (iface && !SDL_strcmp(iface, PROPS_IFACE)) {
|
||||
r = properties(m, menu);
|
||||
} else if (menu) {
|
||||
r = menu_call(m, member);
|
||||
} else if (!SDL_strcmp(member, "Activate") || !SDL_strcmp(member, "SecondaryActivate") ||
|
||||
!SDL_strcmp(member, "ContextMenu") || !SDL_strcmp(member, "Scroll")) {
|
||||
r = gibus_msg_return(m);
|
||||
} else {
|
||||
r = gibus_msg_error(m, GIBUS_ERROR_UNKNOWN_METHOD, member);
|
||||
}
|
||||
send_and_free(r);
|
||||
return GIBUS_HANDLED;
|
||||
}
|
||||
|
||||
static int
|
||||
register_item(int block)
|
||||
{
|
||||
gibus_msg *m = gibus_msg_call(WATCHER, "/StatusNotifierWatcher", WATCHER,
|
||||
"RegisterStatusNotifierItem");
|
||||
const char *name = g_name;
|
||||
gibus_msg *r;
|
||||
gibus_error err;
|
||||
|
||||
if (!m) return 0;
|
||||
gibus_msg_append_args(m, GIBUS_TYPE_STRING, &name, GIBUS_TYPE_INVALID);
|
||||
if (!block) {
|
||||
send_and_free(m);
|
||||
return 1;
|
||||
}
|
||||
gibus_error_init(&err);
|
||||
r = gibus_call(g_bus, m, 2000, &err);
|
||||
gibus_msg_free(m);
|
||||
if (!r) {
|
||||
SDL_Log("tray: no StatusNotifierWatcher (%s)", err.message);
|
||||
gibus_error_free(&err);
|
||||
return 0;
|
||||
}
|
||||
gibus_msg_free(r);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
on_signal(gibus_conn *c, gibus_msg *m, void *user)
|
||||
{
|
||||
const char *name = NULL, *was = NULL, *now = NULL;
|
||||
|
||||
(void)c; (void)user;
|
||||
if (gibus_msg_is_signal(m, GIBUS_INTERFACE_DBUS, "NameOwnerChanged") &&
|
||||
gibus_msg_get_args(m, NULL, GIBUS_TYPE_STRING, &name, GIBUS_TYPE_STRING, &was,
|
||||
GIBUS_TYPE_STRING, &now, GIBUS_TYPE_INVALID) &&
|
||||
!SDL_strcmp(name, WATCHER) && now && now[0])
|
||||
register_item(0);
|
||||
return GIBUS_NOT_YET_HANDLED;
|
||||
}
|
||||
|
||||
static void
|
||||
dispatch(void)
|
||||
{
|
||||
if (!g_bus) return;
|
||||
gibus_read_write(g_bus, 0);
|
||||
while (gibus_dispatch(g_bus))
|
||||
;
|
||||
}
|
||||
|
||||
/* Menu callbacks run between frames, after dispatch, where closing the tray
|
||||
or pumping again is safe; one that closes it drops the rest. */
|
||||
static void
|
||||
pump(void)
|
||||
{
|
||||
reaktor_tray_item chosen[TRAY_ITEMS];
|
||||
int on[TRAY_ITEMS], i, n;
|
||||
App *app = reaktor_main_app();
|
||||
Sint32 gen = g_gen;
|
||||
|
||||
if (!g_bus) return;
|
||||
dispatch();
|
||||
n = g_chosen_n;
|
||||
g_chosen_n = 0;
|
||||
SDL_memcpy(chosen, g_chosen, sizeof chosen[0] * (size_t)n);
|
||||
SDL_memcpy(on, g_chosen_on, sizeof on[0] * (size_t)n);
|
||||
for (i = 0; app && i < n && g_bus && g_gen == gen; i++) {
|
||||
chosen[i].chosen(app, on[i], chosen[i].user);
|
||||
reaktor_wake(app);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
icons_make(void)
|
||||
{
|
||||
static const int sizes[] = { 22, 32, 48, 64 };
|
||||
int i;
|
||||
|
||||
for (i = g_icons = 0; i < (int)SDL_arraysize(sizes); i++) {
|
||||
SDL_Surface *s = reaktor_icon_surface(reaktor_launch_icon(), sizes[i]);
|
||||
Uint8 *out;
|
||||
|
||||
if (!s) continue;
|
||||
if (s->w != sizes[i] || s->h != sizes[i] ||
|
||||
!(out = (Uint8 *)SDL_malloc((size_t)s->w * (size_t)s->h * 4))) {
|
||||
SDL_DestroySurface(s);
|
||||
continue;
|
||||
}
|
||||
if (!SDL_ConvertPixels(s->w, s->h, s->format, s->pixels, s->pitch,
|
||||
SDL_PIXELFORMAT_ARGB32, out, s->w * 4)) {
|
||||
SDL_free(out);
|
||||
SDL_DestroySurface(s);
|
||||
continue;
|
||||
}
|
||||
g_icon[g_icons] = out;
|
||||
g_icon_px[g_icons++] = sizes[i];
|
||||
SDL_DestroySurface(s);
|
||||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
label_dup(const char *s)
|
||||
{
|
||||
char *c = reaktor_utf8_clean_dup(s), *out;
|
||||
size_t i, j;
|
||||
|
||||
if (!c || !(out = (char *)SDL_malloc(SDL_strlen(c) * 2 + 1))) return c;
|
||||
/* dbusmenu reads an underscore as a mnemonic; GTK's label under SDL did not. */
|
||||
for (i = j = 0; c[i]; i++) {
|
||||
if (c[i] == '_') out[j++] = '_';
|
||||
out[j++] = c[i];
|
||||
}
|
||||
out[j] = 0;
|
||||
SDL_free(c);
|
||||
return out;
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_tray_open(App *app, const reaktor_tray *spec)
|
||||
{
|
||||
const char *drv = SDL_GetCurrentVideoDriver();
|
||||
gibus_error err;
|
||||
int i, fd, owner;
|
||||
|
||||
reaktor_tray_close(app);
|
||||
if (!spec) return 0;
|
||||
if (!drv || SDL_strcmp(drv, "dummy") == 0 || SDL_strcmp(drv, "offscreen") == 0)
|
||||
return 0;
|
||||
gibus_error_init(&err);
|
||||
if (!(g_bus = gibus_session_private(&err))) {
|
||||
SDL_Log("tray: %s", err.set && err.message[0] ? err.message : "no session bus");
|
||||
gibus_error_free(&err);
|
||||
return 0;
|
||||
}
|
||||
g_n = spec->count < 0 ? 0 : spec->count < TRAY_ITEMS ? spec->count : TRAY_ITEMS;
|
||||
for (i = 0; i < g_n; i++) {
|
||||
g_item[i] = spec->items[i];
|
||||
g_on[i] = spec->items[i].checkbox && spec->items[i].checked;
|
||||
g_label[i] = spec->items[i].label ? label_dup(spec->items[i].label) : NULL;
|
||||
}
|
||||
g_tip = spec->tooltip ? reaktor_utf8_clean_dup(spec->tooltip) : NULL;
|
||||
icons_make();
|
||||
SDL_snprintf(g_name, sizeof g_name, "org.kde.StatusNotifierItem-%d-1", (int)getpid());
|
||||
owner = 0;
|
||||
if (gibus_register_path(g_bus, SNI_PATH, on_message, NULL) &&
|
||||
gibus_register_path(g_bus, MENU_PATH, on_message, (void *)1)) {
|
||||
owner = gibus_request_name(g_bus, g_name, GIBUS_NAME_FLAG_DO_NOT_QUEUE, NULL) ==
|
||||
GIBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER;
|
||||
}
|
||||
if (!owner || !register_item(1)) {
|
||||
reaktor_tray_close(app);
|
||||
return 0;
|
||||
}
|
||||
gibus_add_filter(g_bus, on_signal, NULL);
|
||||
gibus_add_match(g_bus, "type='signal',sender='" GIBUS_SERVICE_DBUS "',"
|
||||
"interface='" GIBUS_INTERFACE_DBUS "',member='NameOwnerChanged',"
|
||||
"arg0='" WATCHER "'", NULL);
|
||||
gibus_flush(g_bus);
|
||||
if ((fd = gibus_fd(g_bus)) >= 0 && pipe(g_stop) == 0 &&
|
||||
(g_drained = SDL_CreateSemaphore(0))) {
|
||||
g_gen++;
|
||||
SDL_SetAtomicInt(&g_running, 1);
|
||||
g_thread = SDL_CreateThread(watch_bus, "reaktor-tray", (void *)(intptr_t)fd);
|
||||
}
|
||||
if (!g_thread) {
|
||||
reaktor_tray_close(app);
|
||||
return 0;
|
||||
}
|
||||
dispatch();
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_tray_check(App *app, int item, int checked)
|
||||
{
|
||||
(void)app;
|
||||
if (!g_bus || item < 0 || item >= g_n || !g_item[item].checkbox) return;
|
||||
if (g_on[item] == (checked != 0)) return;
|
||||
g_on[item] = checked != 0;
|
||||
items_updated(item + 1);
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_tray_close(App *app)
|
||||
{
|
||||
int i;
|
||||
|
||||
(void)app;
|
||||
if (g_thread) {
|
||||
SDL_SetAtomicInt(&g_running, 0);
|
||||
if (write(g_stop[1], "", 1) < 0) { /* the thread also checks the flag */ }
|
||||
SDL_SignalSemaphore(g_drained);
|
||||
SDL_WaitThread(g_thread, NULL);
|
||||
g_thread = NULL;
|
||||
}
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (g_stop[i] >= 0) close(g_stop[i]);
|
||||
g_stop[i] = -1;
|
||||
}
|
||||
if (g_drained) SDL_DestroySemaphore(g_drained);
|
||||
g_drained = NULL;
|
||||
if (g_bus) gibus_unref(g_bus);
|
||||
g_bus = NULL;
|
||||
for (i = 0; i < g_n; i++) {
|
||||
SDL_free(g_label[i]);
|
||||
g_label[i] = NULL;
|
||||
}
|
||||
for (i = 0; i < g_icons; i++) SDL_free(g_icon[i]);
|
||||
g_icons = 0;
|
||||
SDL_free(g_tip);
|
||||
g_tip = NULL;
|
||||
g_n = 0;
|
||||
g_chosen_n = 0;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_tray_hide_on_minimize(App *app, int on)
|
||||
{
|
||||
(void)app;
|
||||
g_hide_on_minimize = on != 0;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_tray_event(App *app, const SDL_Event *e)
|
||||
{
|
||||
if (e->type == SDL_EVENT_USER && e->user.data1 == &g_tag) {
|
||||
gibus_conn *c = g_bus;
|
||||
SDL_Semaphore *drained = g_drained;
|
||||
|
||||
if (!c) return;
|
||||
pump();
|
||||
if (g_bus == c && g_drained == drained && e->user.code == g_gen)
|
||||
SDL_SignalSemaphore(drained);
|
||||
return;
|
||||
}
|
||||
if (e->type == SDL_EVENT_WINDOW_MINIMIZED && g_hide_on_minimize && g_bus)
|
||||
reaktor_set_visible(app, 0);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static SDL_Tray *g_tray;
|
||||
static SDL_TrayEntry *g_entry[TRAY_ITEMS];
|
||||
static reaktor_tray_item g_item[TRAY_ITEMS];
|
||||
static int g_n, g_hide_on_minimize;
|
||||
static int g_n;
|
||||
|
||||
static void SDLCALL
|
||||
chosen(void *userdata, SDL_TrayEntry *entry)
|
||||
@@ -808,7 +22,7 @@ chosen(void *userdata, SDL_TrayEntry *entry)
|
||||
int
|
||||
reaktor_tray_open(App *app, const reaktor_tray *spec)
|
||||
{
|
||||
#if defined(__EMSCRIPTEN__) || (defined(__unix__) && !defined(__APPLE__) && !defined(__ANDROID__))
|
||||
#ifdef __EMSCRIPTEN__
|
||||
(void)app; (void)spec;
|
||||
return 0;
|
||||
#else
|
||||
@@ -823,7 +37,13 @@ reaktor_tray_open(App *app, const reaktor_tray *spec)
|
||||
if (!drv || SDL_strcmp(drv, "dummy") == 0 || SDL_strcmp(drv, "offscreen") == 0)
|
||||
return 0;
|
||||
icon = reaktor_icon_surface(reaktor_launch_icon(), 32);
|
||||
g_tray = SDL_CreateTray(icon, spec->tooltip);
|
||||
{
|
||||
/* GTK, under the tray on Linux and the BSDs, sets the user's locale. */
|
||||
char *was = reaktor_c_locale_keep(0);
|
||||
|
||||
g_tray = SDL_CreateTray(icon, spec->tooltip);
|
||||
reaktor_c_locale_put(0, was);
|
||||
}
|
||||
if (icon) SDL_DestroySurface(icon);
|
||||
if (!g_tray) {
|
||||
SDL_Log("tray: %s", SDL_GetError());
|
||||
@@ -863,18 +83,3 @@ reaktor_tray_close(App *app)
|
||||
g_tray = NULL;
|
||||
g_n = 0;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_tray_hide_on_minimize(App *app, int on)
|
||||
{
|
||||
(void)app;
|
||||
g_hide_on_minimize = on != 0;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_tray_event(App *app, const SDL_Event *e)
|
||||
{
|
||||
if (e->type == SDL_EVENT_WINDOW_MINIMIZED && g_hide_on_minimize && g_tray)
|
||||
reaktor_set_visible(app, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -4,5 +4,3 @@
|
||||
int reaktor_tray_open(App *app, const reaktor_tray *spec) { (void)app; (void)spec; return 0; }
|
||||
void reaktor_tray_check(App *app, int item, int checked) { (void)app; (void)item; (void)checked; }
|
||||
void reaktor_tray_close(App *app) { (void)app; }
|
||||
void reaktor_tray_hide_on_minimize(App *app, int on) { (void)app; (void)on; }
|
||||
void reaktor_tray_event(App *app, const SDL_Event *e) { (void)app; (void)e; }
|
||||
|
||||
+28
-39
@@ -16,6 +16,7 @@ typedef struct rwin {
|
||||
static rwin g_win[WINDOW_MAX];
|
||||
static int g_win_n, g_win_next = 1;
|
||||
|
||||
/* Closed with the picker still open: its thread answers into the App. */
|
||||
static App *g_parked[WINDOW_MAX];
|
||||
static int g_parked_n;
|
||||
|
||||
@@ -49,7 +50,7 @@ take_look(App *a, const App *m)
|
||||
a->text = m->text;
|
||||
a->accent = m->accent;
|
||||
a->clear = m->clear;
|
||||
a->icon_col = m->icon_col;
|
||||
SDL_memcpy(a->icon_hex, m->icon_hex, sizeof a->icon_hex);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -62,6 +63,7 @@ unpark(int all)
|
||||
g_parked[i] = g_parked[--g_parked_n];
|
||||
}
|
||||
|
||||
/* 0 while the picker's thread may still write into it. */
|
||||
int
|
||||
reaktor_app_free(App *a)
|
||||
{
|
||||
@@ -88,7 +90,6 @@ teardown(App *a)
|
||||
reaktor_undo_clear(a);
|
||||
reaktor_layout_free(&a->lay);
|
||||
if (a->ren) img_cache_free(a);
|
||||
reaktor_damage_free(a);
|
||||
if (a->ctx) nk_sdl_shutdown(a->ctx);
|
||||
if (a->ren) SDL_DestroyRenderer(a->ren);
|
||||
if (a->win) SDL_DestroyWindow(a->win);
|
||||
@@ -115,6 +116,7 @@ shut(int i, int tell)
|
||||
if (m) {
|
||||
int k;
|
||||
|
||||
/* Its cursor would outlive it; each window sets its own again. */
|
||||
SDL_SetCursor(reaktor_cursor(REAKTOR_CURSOR_DEFAULT));
|
||||
m->cur_shown = 0;
|
||||
m->dirty = 1;
|
||||
@@ -122,6 +124,7 @@ shut(int i, int tell)
|
||||
}
|
||||
}
|
||||
|
||||
/* Logical units of the main window to its window coordinates. */
|
||||
static float
|
||||
to_points(const App *m)
|
||||
{
|
||||
@@ -130,8 +133,8 @@ to_points(const App *m)
|
||||
return reaktor_scale() / (d > 0.0f ? d : 1.0f);
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_window_spawn(const reaktor_window *spec, const struct nk_rect *popup)
|
||||
static int
|
||||
open_window(const reaktor_window *spec, const struct nk_rect *popup)
|
||||
{
|
||||
#ifdef __EMSCRIPTEN__
|
||||
(void)spec; (void)popup;
|
||||
@@ -140,7 +143,6 @@ reaktor_window_spawn(const reaktor_window *spec, const struct nk_rect *popup)
|
||||
#else
|
||||
App *m = reaktor_main_app(), *a;
|
||||
rwin *w;
|
||||
float k;
|
||||
int i;
|
||||
|
||||
if (!m || !spec || !spec->page || g_win_n == WINDOW_MAX) return 0;
|
||||
@@ -148,21 +150,21 @@ reaktor_window_spawn(const reaktor_window *spec, const struct nk_rect *popup)
|
||||
a->secondary = 1;
|
||||
a->hot_last = -1;
|
||||
a->queue.moved_ok = 1;
|
||||
k = to_points(m);
|
||||
if (popup) {
|
||||
float k = to_points(m);
|
||||
|
||||
a->win = SDL_CreatePopupWindow(m->win, (int)(popup->x * k), (int)(popup->y * k),
|
||||
(int)(popup->w * k + 0.5f), (int)(popup->h * k + 0.5f),
|
||||
SDL_WINDOW_POPUP_MENU | SDL_WINDOW_NOT_FOCUSABLE |
|
||||
SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_HIDDEN);
|
||||
} else {
|
||||
a->win = SDL_CreateWindow(spec->window.title ? spec->window.title : "",
|
||||
(int)((spec->window.w > 0 ? (float)spec->window.w : 420.0f) * k + 0.5f),
|
||||
(int)((spec->window.h > 0 ? (float)spec->window.h : 280.0f) * k + 0.5f),
|
||||
SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY |
|
||||
SDL_WINDOW_HIDDEN |
|
||||
(spec->window.borderless ? SDL_WINDOW_BORDERLESS : 0) |
|
||||
(spec->window.skip_taskbar ? SDL_WINDOW_UTILITY : 0));
|
||||
}
|
||||
} else
|
||||
a->win = SDL_CreateWindow(spec->window.title ? spec->window.title : "",
|
||||
reaktor_px(spec->window.w > 0 ? (float)spec->window.w : 420.0f),
|
||||
reaktor_px(spec->window.h > 0 ? (float)spec->window.h : 280.0f),
|
||||
SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY |
|
||||
SDL_WINDOW_HIDDEN |
|
||||
(spec->window.borderless ? SDL_WINDOW_BORDERLESS : 0) |
|
||||
(spec->window.skip_taskbar ? SDL_WINDOW_UTILITY : 0));
|
||||
if (a->win && spec->window.centered) {
|
||||
SDL_DisplayID d = SDL_GetDisplayForWindow(m->win);
|
||||
|
||||
@@ -170,20 +172,15 @@ reaktor_window_spawn(const reaktor_window *spec, const struct nk_rect *popup)
|
||||
SDL_WINDOWPOS_CENTERED_DISPLAY(d));
|
||||
}
|
||||
if (a->win && (spec->window.min_w > 0 || spec->window.min_h > 0))
|
||||
SDL_SetWindowMinimumSize(a->win, (int)((float)spec->window.min_w * k + 0.5f),
|
||||
(int)((float)spec->window.min_h * k + 0.5f));
|
||||
SDL_SetWindowMinimumSize(a->win, reaktor_px((float)spec->window.min_w),
|
||||
reaktor_px((float)spec->window.min_h));
|
||||
if (a->win && spec->window.borderless && spec->window.hit_test)
|
||||
SDL_SetWindowHitTest(a->win, spec->window.hit_test, a);
|
||||
if (a->win && spec->modal) {
|
||||
SDL_SetWindowParent(a->win, m->win);
|
||||
SDL_SetWindowModal(a->win, true);
|
||||
}
|
||||
if (a->win)
|
||||
a->ren = reaktor_renderer_for(
|
||||
a->win, SDL_GetRendererName(m->ren),
|
||||
SDL_GetNumberProperty(SDL_GetRendererProperties(m->ren),
|
||||
SDL_PROP_RENDERER_OUTPUT_COLORSPACE_NUMBER,
|
||||
SDL_COLORSPACE_SRGB) == SDL_COLORSPACE_SRGB_LINEAR);
|
||||
if (a->win) a->ren = SDL_CreateRenderer(a->win, SDL_GetRendererName(m->ren));
|
||||
if (a->ren) a->ctx = nk_sdl_init(a->win, a->ren, nk_sdl_allocator());
|
||||
if (!a->ctx) {
|
||||
SDL_Log("window: %s", SDL_GetError());
|
||||
@@ -193,6 +190,7 @@ reaktor_window_spawn(const reaktor_window *spec, const struct nk_rect *popup)
|
||||
a->win_id = SDL_GetWindowID(a->win);
|
||||
SDL_SetRenderVSync(a->ren, 1);
|
||||
a->renderer_is_sw = SDL_strcmp(SDL_GetRendererName(a->ren), "software") == 0;
|
||||
a->sw_noaa = m->sw_noaa;
|
||||
a->aa_mode = m->aa_mode;
|
||||
a->font_face = m->font_face;
|
||||
a->font_face_bold = m->font_face_bold;
|
||||
@@ -233,7 +231,13 @@ int
|
||||
reaktor_window_open(App *app, const reaktor_window *spec)
|
||||
{
|
||||
(void)app;
|
||||
return reaktor_window_spawn(spec, NULL);
|
||||
return open_window(spec, NULL);
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_window_spawn(const reaktor_window *spec, const struct nk_rect *popup)
|
||||
{
|
||||
return open_window(spec, popup);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -372,21 +376,6 @@ reaktor_windows_restyle(void)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
reaktor_windows_holding(void)
|
||||
{
|
||||
App *m = reaktor_main_app();
|
||||
int i;
|
||||
|
||||
if (m && (m->dragging || m->fling_v != 0.0f)) return 1;
|
||||
for (i = 0; i < g_win_n; i++) {
|
||||
const App *a = g_win[i].app;
|
||||
|
||||
if (!g_win[i].closing && (a->dragging || a->fling_v != 0.0f)) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
reaktor_windows_dirty(void)
|
||||
{
|
||||
|
||||
@@ -65,6 +65,7 @@ page_shell(App *app, struct reaktor_context *ctx, int win_w, int win_h)
|
||||
{
|
||||
size_t rss = 0, priv = 0;
|
||||
|
||||
/* On Linux and the BSDs a read walks /proc; not inside every timed frame. */
|
||||
if (g_frames % 30 == 0) {
|
||||
reaktor_process_memory(&rss, &priv);
|
||||
if (priv > g_priv_peak) g_priv_peak = priv;
|
||||
@@ -138,11 +139,10 @@ int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
return launchApp(argc, argv, &(reaktor_launch){
|
||||
.name = "Bench",
|
||||
.window = { .w = 800, .h = 600 },
|
||||
.console = REAKTOR_CONSOLE_PARENT,
|
||||
.draw_every_frame = 1,
|
||||
.page = page_shell,
|
||||
.key = sample_key,
|
||||
.start = sample_start });
|
||||
.name = "Bench",
|
||||
.window = { .w = 800, .h = 600 },
|
||||
.console = REAKTOR_CONSOLE_PARENT,
|
||||
.page = page_shell,
|
||||
.key = sample_key,
|
||||
.start = sample_start });
|
||||
}
|
||||
|
||||
@@ -168,6 +168,7 @@ line_count(void)
|
||||
return n;
|
||||
}
|
||||
|
||||
/* One printed page: its sixty lines on white, as plain labels. */
|
||||
static void
|
||||
print_page(App *app, struct reaktor_context *ctx, int index, int w, int h, void *user)
|
||||
{
|
||||
@@ -328,7 +329,7 @@ page_shell(App *app, struct reaktor_context *ctx, int win_w, int win_h)
|
||||
.heap = &g.text, .heap_cap = &g.cap, .len = &g.len,
|
||||
.name = "Document", .multiline = 1, .line_numbers = 1,
|
||||
.box = { .ml = 6.0f, .mr = 6.0f, .mt = 2.0f, .mb = 3.0f,
|
||||
.flags = REAKTOR_LAY_FILL } });
|
||||
.flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } });
|
||||
|
||||
REAKTOR_ROW(.h = STATUS_H, .flags = REAKTOR_LAY_FILL_X) {
|
||||
SDL_snprintf(line, sizeof(line), "%s%s - %d characters - %s",
|
||||
|
||||
@@ -89,7 +89,7 @@ static void
|
||||
well_caption(struct reaktor_context *ctx, struct reaktor_rect r,
|
||||
const char *text)
|
||||
{
|
||||
const struct reaktor_user_font *f = reaktor_current_font(ctx);
|
||||
const struct reaktor_user_font *f = ctx->style.font;
|
||||
int len = (int)strlen(text);
|
||||
float w = f->width(f->userdata, f->height, text, len);
|
||||
|
||||
@@ -377,7 +377,7 @@ fx_demo(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
|
||||
REAKTOR_COLUMN(.gap = 6.0f) REAKTOR_ROW(.h = 120.0f, .gap = 12.0f, .flags = REAKTOR_LAY_FILL_X) {
|
||||
for (i = 0; i < 3; i++)
|
||||
REAKTOR_ROW(.name = what[i], .flags = REAKTOR_LAY_FILL) {
|
||||
REAKTOR_ROW(.name = what[i], .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y) {
|
||||
struct reaktor_rect r;
|
||||
|
||||
if (reaktor_box_rect(&r)) {
|
||||
@@ -437,9 +437,9 @@ fx_demo(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
}
|
||||
}
|
||||
|
||||
REAKTOR_COLUMN(.gap = 6.0f) REAKTOR_ROW(.h = 40.0f, .gap = reaktor_item_spacing(ctx).x,
|
||||
REAKTOR_COLUMN(.gap = 6.0f) REAKTOR_ROW(.h = 40.0f, .gap = ctx->style.window.spacing.x,
|
||||
.flags = REAKTOR_LAY_FILL_X) {
|
||||
REAKTOR_ROW(.name = "Password", .flags = REAKTOR_LAY_FILL) {
|
||||
REAKTOR_ROW(.name = "Password", .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y) {
|
||||
float dx = reaktor_anim_shake(a, shake, 26.0f, 22.0f, 0.6f);
|
||||
struct reaktor_rect r;
|
||||
|
||||
@@ -507,7 +507,7 @@ color_demo(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = name[i], .color = "--text-bright",
|
||||
.box = { .w = 74.0f, .flags = REAKTOR_LAY_CENTER_Y } });
|
||||
REAKTOR_ROW(.flags = REAKTOR_LAY_FILL) {
|
||||
REAKTOR_ROW(.flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y) {
|
||||
if (reaktor_box_rect(&r)) {
|
||||
struct reaktor_command_buffer *cv = reaktor_window_get_canvas(ctx);
|
||||
int n = (int)(r.w / 4.0f), j;
|
||||
@@ -566,7 +566,7 @@ text_demo(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = name[i], .color = "--text-bright",
|
||||
.box = { .w = 74.0f, .flags = REAKTOR_LAY_CENTER_Y } });
|
||||
REAKTOR_ROW(.flags = REAKTOR_LAY_FILL) {
|
||||
REAKTOR_ROW(.flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y) {
|
||||
struct reaktor_anim_text_stagger_opts o = reaktor_anim_text_stagger_opts_default();
|
||||
float t = 1.0f;
|
||||
struct reaktor_rect r;
|
||||
@@ -588,7 +588,7 @@ text_demo(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
float y1 = r.y + r.h < keep.y + keep.h ? r.y + r.h : keep.y + keep.h;
|
||||
|
||||
reaktor_fill_round(app, cv, r, 6.0f, well_color());
|
||||
o.pos = reaktor_vec2(r.x + 12.0f, r.y + (r.h - reaktor_current_font(ctx)->height) * 0.5f);
|
||||
o.pos = reaktor_vec2(r.x + 12.0f, r.y + (r.h - ctx->style.font->height) * 0.5f);
|
||||
reaktor_push_scissor(cv, reaktor_rect(x0, y0, x1 > x0 ? x1 - x0 : 0.0f, y1 > y0 ? y1 - y0 : 0.0f));
|
||||
reaktor_anim_text_stagger(a, ctx, line, t, &o);
|
||||
reaktor_push_scissor(cv, keep);
|
||||
@@ -630,12 +630,13 @@ page_animation(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
"reaktor_anim_tween_float(reaktor_anim(app), id, 0, to, 0.6f, "
|
||||
"reaktor_anim_ease_spring(1, 170, 16, 0), ...)");
|
||||
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x) {
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
for (i = 0; i < 3; i++)
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = stop_name[i],
|
||||
.accent = (unsigned char)(s->anim_slot == i),
|
||||
.box = { .flags = REAKTOR_LAY_FILL } }))
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X |
|
||||
REAKTOR_LAY_FILL_Y } }))
|
||||
s->anim_slot = i;
|
||||
}
|
||||
|
||||
@@ -644,7 +645,7 @@ page_animation(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = "instant", .color = "--text-muted",
|
||||
.box = { .w = 74.0f, .flags = REAKTOR_LAY_CENTER_Y } });
|
||||
REAKTOR_ROW(.flags = REAKTOR_LAY_FILL) {
|
||||
REAKTOR_ROW(.flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y) {
|
||||
struct reaktor_rect r;
|
||||
if (reaktor_box_rect(&r))
|
||||
track_at(app, ctx, r, stop[s->anim_slot], 0);
|
||||
@@ -655,7 +656,7 @@ page_animation(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = "eased", .color = "--text-bright",
|
||||
.box = { .w = 74.0f, .flags = REAKTOR_LAY_CENTER_Y } });
|
||||
REAKTOR_ROW(.flags = REAKTOR_LAY_FILL) {
|
||||
REAKTOR_ROW(.flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y) {
|
||||
unsigned id = reaktor_box_id();
|
||||
float where = reaktor_animate(id, 0, stop[s->anim_slot],
|
||||
ms, curve);
|
||||
@@ -671,7 +672,7 @@ page_animation(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = kind[i], .color = "--text-bright",
|
||||
.box = { .w = 74.0f, .flags = REAKTOR_LAY_CENTER_Y } });
|
||||
REAKTOR_ROW(.flags = REAKTOR_LAY_FILL) {
|
||||
REAKTOR_ROW(.flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y) {
|
||||
unsigned id = reaktor_box_id();
|
||||
float to = stop[s->anim_slot];
|
||||
float where = reaktor_anim_tween_float(reaktor_anim(app), id, 0, to, 0.6f,
|
||||
@@ -696,7 +697,7 @@ page_animation(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
"chose, which is the value arriving.");
|
||||
api(app, ctx, "reaktor_ease_at(curve, t) / REAKTOR_EASE_*");
|
||||
|
||||
REAKTOR_ROW(.gap = reaktor_item_spacing(ctx).x,
|
||||
REAKTOR_ROW(.gap = ctx->style.window.spacing.x,
|
||||
.flags = REAKTOR_LAY_PACK_CENTER | REAKTOR_LAY_WRAP) {
|
||||
unsigned id = reaktor_box_id();
|
||||
|
||||
@@ -737,7 +738,8 @@ page_animation(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
.fill = reaktor_token(on ? "--background-hover"
|
||||
: "--background-alt",
|
||||
reaktor_rgb(48, 48, 48)),
|
||||
.box = { .flags = REAKTOR_LAY_FILL } }))
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X |
|
||||
REAKTOR_LAY_FILL_Y } }))
|
||||
s->anim_curve = i;
|
||||
|
||||
if (reaktor_box_rect(&r))
|
||||
@@ -761,12 +763,12 @@ page_animation(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
static const char *const word[4] = { "Home", "Search", "Library", "Profile" };
|
||||
struct reaktor_anim_context *anim = reaktor_anim(app);
|
||||
struct reaktor_command_buffer *cv = reaktor_window_get_canvas(ctx);
|
||||
const struct reaktor_user_font *f = reaktor_current_font(ctx);
|
||||
const struct reaktor_user_font *f = ctx->style.font;
|
||||
struct reaktor_colorf rest = reaktor_color_cf(reaktor_token("--background-alt", reaktor_rgb(48, 48, 48)));
|
||||
struct reaktor_colorf lit = reaktor_color_cf(reaktor_accent_color(app));
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
REAKTOR_ROW(.name = word[i], .flags = REAKTOR_LAY_FILL) {
|
||||
REAKTOR_ROW(.name = word[i], .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y) {
|
||||
struct reaktor_rect r;
|
||||
|
||||
if (reaktor_box_rect(&r)) {
|
||||
|
||||
@@ -13,6 +13,7 @@ static const struct { const char *icon, *label; } g_icons[] = {
|
||||
};
|
||||
#define ICON_N ((int)(sizeof(g_icons) / sizeof(g_icons[0])))
|
||||
|
||||
/* A count after the label, in a pill of the accent. */
|
||||
static void
|
||||
paint_inbox(App *app, struct reaktor_command_buffer *cv, struct reaktor_rect c,
|
||||
struct reaktor_color ink, void *user)
|
||||
@@ -33,6 +34,7 @@ paint_inbox(App *app, struct reaktor_command_buffer *cv, struct reaktor_rect c,
|
||||
(int)SDL_strlen(n), f, reaktor_rgba(0, 0, 0, 0), reaktor_on(accent));
|
||||
}
|
||||
|
||||
/* An icon over two lines of text, as a download list shows one. */
|
||||
static void
|
||||
paint_download(App *app, struct reaktor_command_buffer *cv, struct reaktor_rect c,
|
||||
struct reaktor_color ink, void *user)
|
||||
@@ -68,16 +70,19 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
|
||||
{
|
||||
REAKTOR_ROW(.h = 38.0f,
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = "Default",
|
||||
.box = { .flags = REAKTOR_LAY_FILL } })) s->presses++;
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X |
|
||||
REAKTOR_LAY_FILL_Y } })) s->presses++;
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = "Primary", .accent = 1,
|
||||
.box = { .flags = REAKTOR_LAY_FILL } })) s->presses++;
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X |
|
||||
REAKTOR_LAY_FILL_Y } })) s->presses++;
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = "With icon", .icon = "key-outline",
|
||||
.box = { .flags = REAKTOR_LAY_FILL } })) s->presses++;
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X |
|
||||
REAKTOR_LAY_FILL_Y } })) s->presses++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +102,7 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
{ "menu-outline", "Menu" }
|
||||
};
|
||||
REAKTOR_ROW(.flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_WRAP,
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
for (i = 0; i < ICON_N; i++)
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = g_icons[i].label, .icon = g_icons[i].icon,
|
||||
@@ -129,7 +134,7 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
|
||||
for (m = 0; m < 4; m++) {
|
||||
REAKTOR_ROW(.h = 38.0f, .flags = REAKTOR_LAY_FILL_X,
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
reaktor_label(&(reaktor_label_spec){ .text = how[m],
|
||||
.box = { .w = 110.0f, .flags = REAKTOR_LAY_FILL_Y } });
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
@@ -155,7 +160,7 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
"text color for the button's state. Its name is what a reader hears.");
|
||||
api(app, ctx, ".paint / .paint_user / reaktor_button_custom(app, ctx, name, paint, user)");
|
||||
REAKTOR_ROW(.h = 52.0f, .flags = REAKTOR_LAY_FILL_X,
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = "Inbox, 12 new", .paint = paint_inbox, .paint_user = "12",
|
||||
.box = { .w = 180.0f, .flags = REAKTOR_LAY_FILL_Y } }))
|
||||
@@ -208,7 +213,7 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
|
||||
{
|
||||
REAKTOR_ROW(.h = 40.0f,
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
compact_push(ctx);
|
||||
if (reaktor_swatch(&(reaktor_swatch_spec){
|
||||
.name = "Tint swatch", .fill = reaktor_rgb_cf(s->tint),
|
||||
@@ -222,11 +227,13 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = "Hold me", .repeat = 1,
|
||||
.box = { .flags = REAKTOR_LAY_FILL } }))
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X |
|
||||
REAKTOR_LAY_FILL_Y } }))
|
||||
s->repeats++;
|
||||
reaktor_button(&(reaktor_button_spec){
|
||||
.label = "Disabled", .disabled = 1,
|
||||
.box = { .flags = REAKTOR_LAY_FILL } });
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X |
|
||||
REAKTOR_LAY_FILL_Y } });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,7 +242,7 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
s->presses, s->repeats);
|
||||
reaktor_style_push_font(ctx, reaktor_style_font(app, ".small", 13, 0));
|
||||
reaktor_label_colored(ctx, line, REAKTOR_TEXT_LEFT,
|
||||
reaktor_token("--text-muted", reaktor_text_color(ctx)));
|
||||
reaktor_token("--text-muted", ctx->style.text.color));
|
||||
reaktor_style_pop_font(ctx);
|
||||
|
||||
section(app, ctx, "Checkboxes and radios",
|
||||
@@ -254,9 +261,9 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
{ "read", 1u }, { "write", 2u }, { "execute", 4u }
|
||||
};
|
||||
|
||||
REAKTOR_COLUMN(.gap = reaktor_item_spacing(ctx).y) {
|
||||
REAKTOR_COLUMN(.gap = ctx->style.window.spacing.y) {
|
||||
REAKTOR_ROW(.h = ROW, .flags = REAKTOR_LAY_FILL_X,
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
reaktor_check(&(reaktor_check_spec){
|
||||
.label = "Wrap long lines", .on = &s->check_wrap,
|
||||
.box_right = 1,
|
||||
@@ -273,7 +280,7 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
}
|
||||
|
||||
REAKTOR_ROW(.h = ROW, .flags = REAKTOR_LAY_FILL_X,
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
for (i = 0; i < 3; i++) {
|
||||
reaktor_check(&(reaktor_check_spec){
|
||||
.label = perms[i].label, .flags = &s->flags,
|
||||
@@ -291,14 +298,14 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
SDL_snprintf(line, sizeof(line), "flags = 0x%02x", s->flags);
|
||||
reaktor_style_push_font(ctx, reaktor_style_font(app, ".small", 13, 0));
|
||||
reaktor_label_colored(ctx, line, REAKTOR_TEXT_LEFT,
|
||||
reaktor_token("--text-muted", reaktor_text_color(ctx)));
|
||||
reaktor_token("--text-muted", ctx->style.text.color));
|
||||
reaktor_style_pop_font(ctx);
|
||||
|
||||
{
|
||||
static const char *const names[3] = { "Never", "On Wi-Fi", "Always" };
|
||||
|
||||
REAKTOR_ROW(.h = ROW,
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
for (i = 0; i < 3; i++) {
|
||||
reaktor_radio(&(reaktor_radio_spec){
|
||||
.label = names[i], .choice = &s->radio, .value = i,
|
||||
@@ -319,7 +326,7 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
|
||||
{
|
||||
REAKTOR_ROW(.h = 32.0f,
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
for (i = 0; i < 4; i++) {
|
||||
char lab[16];
|
||||
|
||||
@@ -333,7 +340,7 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
|
||||
{
|
||||
REAKTOR_ROW(.h = 32.0f,
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
reaktor_select(&(reaktor_select_spec){
|
||||
.label = "With a symbol", .on = &s->sel_row,
|
||||
.disc = 1, .centered = 1,
|
||||
|
||||
@@ -10,7 +10,7 @@ static void
|
||||
diag_row(App *app, struct reaktor_context *ctx, const char *name,
|
||||
const char *value)
|
||||
{
|
||||
REAKTOR_ROW(.h = 24.0f, .gap = reaktor_item_spacing(ctx).x,
|
||||
REAKTOR_ROW(.h = 24.0f, .gap = ctx->style.window.spacing.x,
|
||||
.flags = REAKTOR_LAY_FILL_X) {
|
||||
struct reaktor_rect r;
|
||||
unsigned id;
|
||||
@@ -32,13 +32,14 @@ diag_row(App *app, struct reaktor_context *ctx, const char *name,
|
||||
.text = value,
|
||||
.name = "value",
|
||||
.silent = 1,
|
||||
.box = { .flags = REAKTOR_LAY_FILL } });
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X |
|
||||
REAKTOR_LAY_FILL_Y } });
|
||||
}
|
||||
}
|
||||
|
||||
#define DIAG_ROWS(ctx) \
|
||||
REAKTOR_COLUMN(.w = reaktor_widget_bounds(ctx).w, \
|
||||
.gap = reaktor_item_spacing(ctx).y)
|
||||
.gap = (ctx)->style.window.spacing.y)
|
||||
|
||||
void
|
||||
page_diagnostics(App *app, struct reaktor_context *ctx, showcase_state *st)
|
||||
@@ -55,7 +56,7 @@ page_diagnostics(App *app, struct reaktor_context *ctx, showcase_state *st)
|
||||
"page; Pick, then a click here, finds the widget under the "
|
||||
"pointer.");
|
||||
api(app, ctx, ".inspector = { .attach = 1 } / reaktor_inspector_open");
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x) {
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
int shown = reaktor_inspector_shown(app);
|
||||
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
@@ -75,6 +76,33 @@ page_diagnostics(App *app, struct reaktor_context *ctx, showcase_state *st)
|
||||
"front, and the new copy exits. --new-instance starts a separate copy "
|
||||
"anyway.");
|
||||
api(app, ctx, ".single_instance / .file_opened / --new-instance");
|
||||
#ifndef __EMSCRIPTEN__
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
if (reaktor_button(&(reaktor_button_spec){
|
||||
.label = "Launch the showcase again, with a file",
|
||||
.name = "Launch again", .box = { .w = 340.0f } })) {
|
||||
char exe[1024];
|
||||
const char *base = SDL_GetBasePath();
|
||||
const char *args[3];
|
||||
SDL_Process *p;
|
||||
|
||||
SDL_snprintf(exe, sizeof exe, "%sshowcase%s", base ? base : "",
|
||||
#ifdef _WIN32
|
||||
".exe"
|
||||
#else
|
||||
""
|
||||
#endif
|
||||
);
|
||||
args[0] = exe;
|
||||
args[1] = exe;
|
||||
args[2] = NULL;
|
||||
p = SDL_CreateProcess(args, false);
|
||||
if (p) SDL_DestroyProcess(p);
|
||||
else SDL_Log("could not launch %s: %s", exe, SDL_GetError());
|
||||
}
|
||||
reaktor_soak();
|
||||
}
|
||||
#endif
|
||||
SDL_snprintf(v, sizeof v, "%d, the last %s", st->handed,
|
||||
st->handed ? st->file_pick : "none yet");
|
||||
REAKTOR_ROW(.h = ROW_SMALL) {
|
||||
@@ -139,9 +167,9 @@ page_diagnostics(App *app, struct reaktor_context *ctx, showcase_state *st)
|
||||
|
||||
section(app, ctx, "Where a frame goes",
|
||||
"Split three ways because guessing which one dominates has been "
|
||||
"wrong more than once. Render holds the rasterizing on the "
|
||||
"software renderer; present is the copy to the window, or the "
|
||||
"wait for the display.");
|
||||
"wrong more than once. Building the UI and converting it to "
|
||||
"geometry are both fractions of a millisecond; the wait on "
|
||||
"present is the whole frame.");
|
||||
|
||||
SDL_snprintf(v, sizeof(v), "%.2f ms", (double)d.build_ms);
|
||||
DIAG_ROWS(ctx) {
|
||||
@@ -153,7 +181,7 @@ page_diagnostics(App *app, struct reaktor_context *ctx, showcase_state *st)
|
||||
}
|
||||
|
||||
section(app, ctx, "Style and text",
|
||||
"The stylesheets are parsed by Reaktor's own CSS engine on every theme "
|
||||
"The stylesheets are parsed by LCUI's libcss on every theme "
|
||||
"change, and the font atlas is baked per size at the display's "
|
||||
"scale. The system's reduced motion and contrast reach the sheets as "
|
||||
"@media queries, and with --watch-css a sheet saved on disk restyles "
|
||||
@@ -167,9 +195,6 @@ page_diagnostics(App *app, struct reaktor_context *ctx, showcase_state *st)
|
||||
SDL_snprintf(v, sizeof(v), "%d, parsed in %.2f ms", d.sheets,
|
||||
(double)d.style_ms);
|
||||
diag_row(app, ctx, "stylesheets", v);
|
||||
SDL_snprintf(v, sizeof(v), "window %.1f ms, atlas %.1f ms, first frame at %.0f ms",
|
||||
(double)d.window_ms, (double)d.atlas_ms, (double)d.first_frame_ms);
|
||||
diag_row(app, ctx, "startup", v);
|
||||
SDL_snprintf(v, sizeof(v), "%.2fx", (double)d.scale);
|
||||
diag_row(app, ctx, "display scale", v);
|
||||
diag_row(app, ctx, "font", d.font);
|
||||
|
||||
@@ -3,13 +3,14 @@
|
||||
static const char *const g_grid[7][3] = {
|
||||
{ "SDL3", "Zlib", "window, input, renderer, main loop" },
|
||||
{ "Nuklear", "MIT/PD", "the widgets and their layout" },
|
||||
{ "FreeType", "FTL", "draws the glyphs" },
|
||||
{ "LCUI css", "MIT", "parses the stylesheet, computes values" },
|
||||
{ "Water.css", "MIT", "the stylesheet itself" },
|
||||
{ "plutosvg", "MIT", "rasterises the icons" },
|
||||
{ "Ionicons", "MIT", "the icons" },
|
||||
{ "Aileron", "CC0", "the typeface" }
|
||||
};
|
||||
|
||||
/* Example figures: scans and threats per hour over a day. */
|
||||
static const int g_scans[24] = { 0, 0, 0, 0, 0, 0, 0, 1, 3, 2, 0, 0,
|
||||
9, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2 };
|
||||
static const int g_threats[24] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
|
||||
@@ -118,6 +119,7 @@ static int file_parent(int n, void *u) { (void)u; return g_files[n].pare
|
||||
static const char *file_label(int n, void *u) { (void)u; return g_files[n].label; }
|
||||
static const char *file_icon(int n, void *u) { (void)u; return g_files[n].icon; }
|
||||
|
||||
/* Two lists of task numbers; a drop moves one from a list to a place in another. */
|
||||
static const char *const g_tasks[] = {
|
||||
"Write the release notes", "Check the BSD builds", "Answer the issue on fonts",
|
||||
"Draw the new icon", "Measure the web build", "Update the screenshots"
|
||||
@@ -187,21 +189,23 @@ page_display(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
};
|
||||
int i;
|
||||
|
||||
REAKTOR_COLUMN(.gap = reaktor_item_spacing(ctx).y) {
|
||||
REAKTOR_COLUMN(.gap = ctx->style.window.spacing.y) {
|
||||
REAKTOR_ROW(.h = ROW_SMALL, .flags = REAKTOR_LAY_FILL_X,
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
for (i = 0; i < 3; i++)
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = edges[i], .align = (unsigned char)i,
|
||||
.box = { .flags = REAKTOR_LAY_FILL } });
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X |
|
||||
REAKTOR_LAY_FILL_Y } });
|
||||
}
|
||||
REAKTOR_ROW(.h = ROW_SMALL, .flags = REAKTOR_LAY_FILL_X,
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
for (i = 0; i < 3; i++)
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = tokens[i], .color = tokens[i],
|
||||
.align = (unsigned char)i,
|
||||
.box = { .flags = REAKTOR_LAY_FILL } });
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X |
|
||||
REAKTOR_LAY_FILL_Y } });
|
||||
}
|
||||
reaktor_label(&(reaktor_label_spec){
|
||||
.text = "A wrapped label breaks between words inside the row "
|
||||
@@ -234,7 +238,7 @@ page_display(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
static const int accent = 5;
|
||||
|
||||
REAKTOR_ROW(.h = 30.0f,
|
||||
.gap = reaktor_item_spacing(ctx).x) {
|
||||
.gap = ctx->style.window.spacing.x) {
|
||||
for (k = 0; k < 8; k++)
|
||||
reaktor_icon(&(reaktor_icon_spec){
|
||||
.name = names[k],
|
||||
@@ -327,28 +331,28 @@ page_display(App *app, struct reaktor_context *ctx, showcase_state *s)
|
||||
api(app, ctx, "reaktor_list .drag / .dropped / reaktor_undo_push");
|
||||
g_lane_app = app;
|
||||
|
||||
REAKTOR_ROW(.h = 200.0f, .gap = reaktor_item_spacing(ctx).x, .flags = REAKTOR_LAY_FILL_X) {
|
||||
REAKTOR_ROW(.h = 200.0f, .gap = ctx->style.window.spacing.x, .flags = REAKTOR_LAY_FILL_X) {
|
||||
reaktor_list(&(reaktor_list_spec){
|
||||
.name = "To do", .count = g_lane_n[0], .cell = lane_cell, .user = (void *)0,
|
||||
.drag = "task", .dropped = lane_dropped, .columns = (const char *const[]){ "To do" },
|
||||
.box = { .flags = REAKTOR_LAY_FILL } });
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } });
|
||||
reaktor_list(&(reaktor_list_spec){
|
||||
.name = "Done", .count = g_lane_n[1], .cell = lane_cell, .user = (void *)1,
|
||||
.drag = "task", .dropped = lane_dropped, .columns = (const char *const[]){ "Done" },
|
||||
.box = { .flags = REAKTOR_LAY_FILL } });
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } });
|
||||
}
|
||||
REAKTOR_ROW(.h = ROW, .gap = reaktor_item_spacing(ctx).x) {
|
||||
REAKTOR_ROW(.h = ROW, .gap = ctx->style.window.spacing.x) {
|
||||
char undo[48], redo[48];
|
||||
|
||||
SDL_snprintf(undo, sizeof undo, "Undo %s", reaktor_undo_label(app) ? reaktor_undo_label(app) : "");
|
||||
SDL_snprintf(redo, sizeof redo, "Redo %s", reaktor_redo_label(app) ? reaktor_redo_label(app) : "");
|
||||
if (reaktor_button(&(reaktor_button_spec){ .label = undo, .name = "Undo",
|
||||
.disabled = !reaktor_undo_label(app),
|
||||
.box = { .flags = REAKTOR_LAY_FILL } }))
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } }))
|
||||
reaktor_undo(app);
|
||||
if (reaktor_button(&(reaktor_button_spec){ .label = redo, .name = "Redo",
|
||||
.disabled = !reaktor_redo_label(app),
|
||||
.box = { .flags = REAKTOR_LAY_FILL } }))
|
||||
.box = { .flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_FILL_Y } }))
|
||||
reaktor_redo(app);
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user