92 Commits
Author SHA1 Message Date
adminandClaude Opus 5.5 3a62f78849 Submodules: point at the Gitea repositories
The GitHub repositories are gone with the suspended account (or are
mirrored on Gitea). Relative URLs (../<repo>.git) resolve against wherever
this repository is cloned from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 16:45:27 +01:00
Roman ChojnackiandClaude Opus 5.5 865bd70f9c MSVC: /Gw, so the linker drops unused data as it drops unused functions
The data counterpart of /Gy, which Release already sets, and of the
-fdata-sections GCC and Clang get. mojibake's unused tables go: the showcase
is about 100 KB smaller.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-23 10:35:05 +02:00
admin 9925feeeba Merge pull request #96 from Alpaq92/sdl-no-dynapi
SDL: its dynamic API is compiled out
2026-10-23 09:58:19 +02:00
admin 7b9d59e926 Merge pull request #95 from Alpaq92/onlay-tidy
Layout: a child goes after its container's last, not after a walk to it
2026-10-23 09:58:05 +02:00
admin 45a993cb0e Merge pull request #94 from Alpaq92/drop-pdfgen
Print: Reaktor writes its PDFs; PDFGen goes
2026-10-23 09:57:34 +02:00
Roman Chojnacki 9f4eefaa07 Merge remote-tracking branch 'origin/master' into drop-pdfgen
# Conflicts:
#	.gitmodules
#	CMakeLists.txt
#	docs/NOTICE.md
2026-10-23 09:56:45 +02:00
Roman ChojnackiandClaude Opus 5.5 43015fce0f Layout: a child goes after its container's last, not after a walk to it
Each open container remembers the child declared last in it, and the next is
appended there. lay_insert walked every earlier sibling, so a container's
children cost their count squared: 256 boxes in one list took 79.5 µs to build
and lay out, and take 11.2 µs now. The tree and every rectangle are the same.

Onlay moves to its tidied header: comments only where the code cannot say it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-23 09:49:11 +02:00
admin aebabc0535 Merge pull request #93 from Alpaq92/docs-machine
Docs: one Windows machine, the one the numbers came from
2026-10-23 09:42:37 +02:00
admin 3a45514f1e Merge pull request #92 from Alpaq92/freetype
Fonts: FreeType reads and draws them; stb_truetype goes
2026-10-23 09:42:23 +02:00
Roman ChojnackiandClaude Opus 5.5 eff48d8f13 Docs: one Windows machine, the one the numbers came from
PERFORMANCE.md listed it twice, once as a VirtualBox VM with no Direct3D 11
adapter, which it is not. DEMO.md pointed at that VM too.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-23 09:41:52 +02:00
Roman Chojnacki 06e7a4c0cf Merge remote-tracking branch 'origin/master' into freetype 2026-10-23 09:38:53 +02:00
Roman ChojnackiandClaude Opus 5.5 c523e0be65 SDL: its dynamic API is compiled out
The dynamic API kept every SDL function linked and let the SDL3_DYNAMIC_API
environment variable load another SDL library into the program. SDL takes no
switch for it, so core/sdl/no_dynapi.h is forced into SDL's sources ahead of
its own header, and CMake checks that header's guard is still the one it
claims. No SDL file is edited.

simple is 499 KB smaller, notepad 452 KB, showcase 436 KB.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-23 09:35:58 +02:00
Roman ChojnackiandClaude Opus 5.5 36d4a9c9c5 Print: Reaktor writes its PDFs; PDFGen goes
A PDF here is a JPEG per page and the objects that frame it, so print.c
writes them itself: the same pages, images and info, without the font and
transparency states PDFGen added to every page. The creation date is UTC,
where PDFGen wrote local time marked as UTC, and a title past ASCII is
UTF-16.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-23 09:09:07 +02:00
admin 143942791c Merge pull request #91 from Alpaq92/msvc-c5287
MSVC: silence nuklear.h's C5287 for every target
2026-10-23 08:53:35 +02:00
Roman ChojnackiandClaude Opus 5.5 67b966ff3a Docs: FreeType in NOTICE, the font path in DOCUMENTATION
NOTICE gains FreeType's row and the credit its license asks for, and loses
stb_truetype. DOCUMENTATION drops the Nuklear traps that went with its font
baking. A comment in cssflat.c no longer holds the two characters that open
one.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-23 08:35:37 +02:00
Roman ChojnackiandClaude Opus 5.5 37988199de Fonts: FreeType reads and draws them; Nuklear's baking and stb_truetype go
core/render/font.c builds the atlas: FreeType 2.15.0 draws each glyph with
light hinting, and the metrics are Nuklear's, so layout is unchanged. The
Text module draws its fallback glyphs with FreeType too, and a font is
checked by opening it with FreeType. NK_INCLUDE_FONT_BAKING and
NK_INCLUDE_DEFAULT_FONT are off, which takes stb_truetype and stb_rect_pack
out of the build.

FreeType builds only its TrueType, CFF, autofit and smooth modules, and
reaktor_ftoption.h drops what Reaktor never reads, its environment override
among them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-23 08:29:04 +02:00
Roman ChojnackiandClaude Opus 5.5 f61062b064 MSVC: silence nuklear.h's C5287 for every target that includes it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-23 00:49:12 +02:00
admin af5e951132 Merge pull request #90 from Alpaq92/css-token-guard
Security hardening, menu bar, link schemes and plain version tags
2026-10-23 00:04:41 +02:00
Roman Chojnacki e1c22baff2 Merge remote-tracking branch 'origin/master' into css-token-guard 2026-10-22 23:47:08 +02:00
Roman ChojnackiandClaude Opus 5.5 2d982889fc Simplify the unmerged changes and fix two of them
The tree's jump to a parent checks the parent against the tree's count, not
the list's. A font's name table is checked in reaktor_font_valid, before
Nuklear reads it, in place of the late check in text.c.

cssflat.c checks every token with one token_ok, frees in one place in
emit_one, and drops unresolved variables once. UTF-8 cleaning uses SDL's
decoder. The file dialog flag becomes file_busy, freed by reaktor_app_free.
urltest becomes basetest and holds the UTF-8 checks.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 23:47:08 +02:00
Roman ChojnackiandClaude Opus 5.5 63b4fe6dc1 Web page: a Content-Security-Policy
The page allowed any script. It now sets a policy: scripts only from its own origin, plus WebAssembly; images from its own origin, data: and blob:, which the app creates; nothing from elsewhere. The inline script moved to shell.js, copied beside the page like keylog.js, and the canvas's inline context-menu handler went with it. Checked in headless Edge: showcase, notepad and simple start and draw the same pixels with the policy as without, the showcase's accessibility tree is the same, and the console shows no violation, with ?keylog too.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 23:27:29 +02:00
Roman ChojnackiandClaude Opus 5.5 09b3aa5767 build-wasm.ps1 picks a Visual Studio that has CMake
It took the newest installation, and on a machine with a newer Visual Studio lacking the C++ CMake tools beside the Build Tools that have them, it failed to find cmake.exe. It now asks vswhere for an installation with the CMake component, as build.ps1 asks for the C++ tools.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 23:27:29 +02:00
Roman ChojnackiandClaude Opus 5.5 dc62c39da2 Fonts: a name record past the end of the file is not read
The Text module copied a fallback font's name from wherever its name table pointed, up to 64 KB past the font's data, since reaktor_font_valid checks only the table directory. The string is now checked to lie inside the file, and the name falls back to the file's own name otherwise. With AddressSanitizer, a font whose English name record points past its end crashed texttest on master and loads cleanly now. The documentation says plainly that fonts should come from a trusted source.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 23:20:31 +02:00
Roman ChojnackiandClaude Opus 5.5 14918d2163 PERFORMANCE.md: the CPU draws by default, and a GPU can
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 23:17:37 +02:00
Roman ChojnackiandClaude Opus 5.5 0aa17d2085 NOTICE: name what assets/icons holds
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 23:16:51 +02:00
Roman ChojnackiandClaude Opus 5.5 5e19edac62 BSD releases build from scratch, keeping only ccache
Tag runs restored master's whole build folders, linked programs included, and rebuilt only what had changed since, so a release could carry objects from an earlier run. A release now deletes the build folders after the restore; ccache, which checks each object against its exact inputs, still saves the compile time.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 23:16:35 +02:00
Roman ChojnackiandClaude Opus 5.5 54911cfc2d NOTICE: say who writes the .reaktor-root marker
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 23:16:35 +02:00
Roman ChojnackiandClaude Opus 5.5 e07df3fb29 NOTICE: drop the note on hamza; tighten the AFL-2.1 paragraph
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 23:16:03 +02:00
Roman ChojnackiandClaude Opus 5.5 010d184461 Single instance elsewhere: the /tmp fallback socket lives in a folder only the user can reach
When the settings folder's path was too long for a socket, the socket went to a name in /tmp that another user could bind first, receiving the paths a later launch sent. It now goes into /tmp/reaktor-<uid>, created 0700 and checked to be a real folder owned by the user and closed to others; if it is not, the app logs it and runs as a copy of its own.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 23:15:39 +02:00
Roman ChojnackiandClaude Opus 5.5 eb7fb5f69d Links open only http, https and mailto, unless the link names more
A link handed its URL straight to SDL_OpenURL, which on Windows opens anything: a file: URL runs a program, a share path sends the user's network credentials, a registered protocol reaches whatever handles it. An app showing links from documents or user content let that content do so. reaktor_link now opens http, https and mailto, plus the schemes its .schemes lists, as "file,ftp", and logs anything else. urltest covers the schemes, drive and share paths, and blank or missing schemes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 23:15:06 +02:00
Roman ChojnackiandClaude Opus 5.5 c13c0d3644 csstest finds Simple.css from any folder, build/ included
It opened its sheets by a path relative to where it was started, so it failed when run from build/, where the documentation says the tests run.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 23:13:14 +02:00
Roman ChojnackiandClaude Opus 5.5 608ce8de26 Assets: the marker is looked for at most two folders above the program
Without a .reaktor-root beside it, a program climbed to the root of the drive looking for one, and started from the working directory when its own folder was unknown, so whoever could write a parent folder, or chose where it was launched from, could hand it stylesheets, fonts, icons and catalogs. The search now stops two folders up, enough for build/ in a checkout, and never uses the working directory, as the documentation already said. Further down, a program draws from its compiled-in look; every showcase page draws the same from build/.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 23:12:50 +02:00
Roman ChojnackiandClaude Opus 5.5 a392ab3ba4 NOTICE: Simple.css described plainly
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 23:11:29 +02:00
Roman ChojnackiandClaude Opus 5.5 0d3e5b271e File dialogs: a window is freed only once its dialog's callback has finished
The callback marks its answer ready, wakes the window, then marks itself done as its last touch, but a closing window was freed once its answer had been handled, which can happen between those steps. file_done now means no callback is outstanding: it starts set, a dialog clears it, the callback sets it last, and a closing window is parked until it is set. A window freed with an answer it never handled also frees the answer's list. launchtest win-picker-close, which closes a window over its open dialog, exits cleanly.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 23:10:53 +02:00
Roman ChojnackiandClaude Opus 5.5 3f3be58ee9 Single instance on Windows: no impersonation, no paths to another user's pipe
The pipe's name can be predicted, so another account on the machine could create it first. A later launch then handed that pipe its file paths and connected at the default impersonation level, letting an account with the impersonation privilege act as the user. Launches now connect at identification level only, send nothing unless the pipe's server runs as the same user, and the listener claims the name exclusively. Whenever any of this fails, the app logs it and runs as a copy of its own.

Tested with PowerShell holding the pipe first: the showcase logged that the name was held and ran on its own, and the squatting server was granted Identification only; a normal second launch still hands over, in 184 ms.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 23:09:04 +02:00
Roman ChojnackiandClaude Opus 5.5 0ae308f909 Linux: invalid UTF-8 no longer aborts the app over D-Bus
libdbus aborts the process on a string that is not UTF-8, and a Linux file name need not be. The accessibility snapshot relied on SDL_utf8strlcpy, which only trims a cut-off character at the end, so a label showing such a name killed the app as soon as a screen reader read it; notifications passed their text straight through. reaktor_utf8_clean replaces every invalid sequence with U+FFFD, and both paths use it. The notification path also no longer leaks its connection when the message cannot be made. a11ytest checks stray, cut-off, overlong, surrogate and out-of-range sequences.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 23:06:17 +02:00
Roman ChojnackiandClaude Opus 5.5 2c956b7304 Menu bar: any number of menus, with no per-title arrays
Every title's id and rectangle were kept in fixed arrays, but only the open menu's were ever read back: to place its dropdown and to return focus to it. The bar now keeps just those two, so there is no limit and no index to run past; the arrow keys cycle through every menu. launchtest menu-keys logs the same as before, and every showcase page draws byte-identical.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 22:59:24 +02:00
admin 1621d72296 Update NOTICE.md 2026-10-22 22:56:23 +02:00
Roman ChojnackiandClaude Opus 5.5 e46eaf2ea1 Single instance: a silent client can no longer stall forwarding or quitting
The listener read with no time limit, so a client that connected and sent nothing held it: later launches could not hand over their files, and quitting hung, since stopping the listener meant connecting to it. On Windows the pipe is now overlapped, each read waits at most 2 seconds, and a stop event ends any wait; elsewhere each connection has a 2-second receive timeout. A launch whose message never arrives no longer raises the window. Checked on Windows against master: with a silent client connected, a second launch handed over in 2.1 s instead of never, and quitting took 29 ms instead of hanging.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 22:50:36 +02:00
Roman ChojnackiandClaude Opus 5.5 2ad7acc200 PERFORMANCE.md names the benchmark machine where the workload is described
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 22:47:10 +02:00
Roman ChojnackiandClaude Opus 5.5 d12d28d413 Menu bar: up to 32 menus
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 22:44:03 +02:00
Roman ChojnackiandClaude Opus 5.5 d8e6d7481b Release tags are plain versions: 1.2.3 or 1.2.3-rc1, without a v
release.yml now triggers on such tags and refuses anything else; the workflows name packages from the tag as it is, so the strips of a leading v are gone, and CLAUDE.md and DOCUMENTATION.md say how to tag.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 22:41:05 +02:00
Roman ChojnackiandClaude Opus 5.5 1b239460c6 Pages and web: actions pinned by commit, emsdk cloned at its tag
pages.yml was the only workflow pinning actions by tag, and kept the checkout's token on disk while it built; it now pins every action by commit and drops the token, as the others do. Both web workflows cloned emsdk's newest commit; they clone the tag matching the SDK version, under a new cache key so the pin takes effect.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 22:36:27 +02:00
Roman ChojnackiandClaude Opus 5.5 067edc913c Release: refuse a tag that is not a version before anything uses it
Every platform's workflow pastes the tag name into its scripts, some inside a BSD virtual machine. A tag holding a quote or $( ) would have run as shell; a first job now stops the release unless the tag reads like v1.2.3 or v1.2.3-rc1.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 22:36:27 +02:00
Roman ChojnackiandClaude Opus 5.5 c4926d7953 Notepad sample: refuse files of 2 GB or more
Their size wrapped to a negative int, passed the capacity check and overran the buffer.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 22:34:43 +02:00
Roman ChojnackiandClaude Opus 5.5 9815454268 Windows: dwmapi.dll is loaded from System32 only
LoadLibraryA searched the program's folder first, where a planted DLL would load.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 22:34:42 +02:00
Roman ChojnackiandClaude Opus 5.5 896be154f7 Out-of-memory edges in text fields and rounded fills
A field whose buffer could not grow reported the larger capacity it asked for, and a rounded fill whose scissor could not be pushed linked a command at the buffer's end. Both now leave things as they were.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 22:34:42 +02:00
Roman ChojnackiandClaude Opus 5.5 4b9417fe9a Dates without localization: a negative month wraps instead of reading before the names
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 22:34:42 +02:00
Roman ChojnackiandClaude Opus 5.5 c6408e1f8f Accessibility: nodes deeper than 32 take the deepest recorded parent
push stops recording parents at 32 levels, but a node below read one past the parent stack.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 22:34:42 +02:00
Roman ChojnackiandClaude Opus 5.5 04794ff932 Tooltips: a declared tooltip is copied, as reaktor_tip already did
decl_tip_at kept the caller's pointer and read it after the frame, when a tooltip built in a temporary buffer was gone.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 22:34:42 +02:00
Roman ChojnackiandClaude Opus 5.5 ad46d4a16d Menus and trees: indices checked against what is there this frame
The menu bar's arrow keys cycled through every menu while only the first 16 have a title slot, so a 17th was read past the arrays; they now cycle through the menus drawn, and the documentation names the limit. A tree's carried keyboard target and a menu's picked entry were indices from an earlier frame, used even after the app's tree or items shrank; both are checked against this frame's counts.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 22:34:41 +02:00
Roman ChojnackiandClaude Opus 5.5 d188933b49 Test harness: requests live in the harness, not on the script's stack
A lookup or settle posted to the main thread pointed into the script
thread's stack. After a 5-second timeout the script returned while the post
was still queued, and the main thread later wrote the answer into a frame
that no longer existed. Requests now use harness-owned memory, copy the
target they search for, and nothing is posted once the window has stopped
answering. uitest passes all its checks.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 22:32:00 +02:00
Roman ChojnackiandClaude Opus 5.5 0ffc1f75fe Accessibility: a full slot table no longer spins forever
The probe loops in the tree's hash tables had no bound, and the bucket
table fills when a frame declares more distinct silent elements than it has
slots, freezing the app every frame. A full table now answers "none", and
the element simply gets an id without its occurrence count. a11ytest
declares twice the slots and hung on the old code.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 22:30:59 +02:00
Roman ChojnackiandClaude Opus 5.5 93a840b816 Toasts: the expiry timer wakes the main window, not the one that asked
A toast's timer held the App that called reaktor_toast, but toasts are
drawn by the main window and a secondary window is freed when it closes, so
closing one within a toast's timeout left the timer to wake freed memory.
The timer now wakes the main window, which draws the toast.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 22:30:58 +02:00
Roman ChojnackiandClaude Opus 5.5 12885eae41 Images: decode PNG and JPEG only
plutovg's stb_image 2.30 compiled in every decoder, and picks one by the
data's own bytes, so an image asset or an image inside an SVG could reach
the GIF decoder and its open heap overflow (CVE-2026-5185). Only the PNG and
JPEG the documentation promises are compiled in now. imagetest decodes a
PNG and a JPEG and refuses a GIF, and failed with the old build.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 22:27:57 +02:00
Roman ChojnackiandClaude Opus 5.5 b9f10e6431 CSS: bound calc() nesting, @import fan-out and var() expansion
A stylesheet could crash or stall the app:
- calc() nested deeper than 32 levels overflowed the stack; such a
  declaration is now dropped as invalid.
- A sheet importing itself, directly or through others, loaded until the
  app hung. As in Blink, an import of a sheet already in the chain above is
  skipped, and no import starts once the flattened sheet passes 4 MB.
- var() fallbacks nested without limit, and variables built from variables
  could grow to gigabytes. A value whose source or result passes 4 KB is
  left unresolved, as CSS Values 5 asks of overly long substitutions, and a
  declaration still holding var() after substitution is dropped.

csstest covers each case; the crafted sheets no longer crash or hang the
showcase, and every showcase page draws byte-identical in both themes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 22:27:57 +02:00
Roman ChojnackiandClaude Opus 5.5 e1e2dcbd4d CSS: drop declarations and selectors that would overflow the parser's token
libcss copies each token into a 512-byte buffer without a bound. cssflat
kept every emitted declaration under that size, but the engine also reads
'//' or '/*' as a comment that does not end the token, and '}' inside a
value as the end of the block, so the lines after one ran on into the same
buffer: a stylesheet could write past it. A declaration whose value holds
';', '}', '//' or '/*', or whose property holds '}', is now dropped, and so
is a selector with any of them; the engine misread all of these already.

The crafted sheets no longer crash the showcase; every showcase page draws
byte-identical in both themes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 21:47:51 +02:00
admin 663d85755b Update PERFORMANCE.md 2026-10-22 21:47:34 +02:00
admin 143c3dbcfe Update PERFORMANCE.md 2026-10-22 21:46:47 +02:00
admin adf7c002c1 Update PERFORMANCE.md 2026-10-22 21:46:22 +02:00
admin 7a66fb63d2 Merge pull request #89 from Alpaq92/full-benchmark
Benchmark: every arm from one pass, with steady-state CPU for all seven
2026-10-22 21:28:48 +02:00
Roman ChojnackiandClaude Opus 5.5 f7b65703cb Benchmark: every arm from one pass, with steady-state CPU for all seven
Flutter 3.38.0, Electron 44.3.0 and Compose Multiplatform 1.12.0 were built
again and measured beside Reaktor's four renderers on the same laptop, with
the GPU idle. The steady-state column now covers all seven, CPU summed across
each app's process tree; the chart's CPU panel shows it.

| Arm | Memory | With startup | Steady |
| software | 9.5 MB | 8.6% | 6.0% |
| direct3d11 | 59.4 MB | 14.1% | 10.3% |
| direct3d12 | 122.3 MB | 11.8% | 5.0% |
| 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% |

The CPU column is named for what it holds, the run with startup, and the
measurement notes say how each figure was taken.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 21:27:44 +02:00
admin 0db611c1db Merge pull request #88 from Alpaq92/direct3d12-renderer
Direct3D 12 renderer and --renderer directx; renderer guide in the docs
2026-10-22 19:47:47 +02:00
Roman ChojnackiandClaude Opus 5.5 a6c09d8469 Fewer comments in the splash and the software geometry path
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 19:46:23 +02:00
Roman ChojnackiandClaude Opus 5.5 e8ac46460f Renderer guide in DOCUMENTATION and FAQ; direct3d12 in PERFORMANCE
- DOCUMENTATION's renderer section says why software is the default and lists
  the GPU renderers with their pros and cons; the FAQ asks whether an app
  should use one.
- PERFORMANCE gains a direct3d12 row (121.5 MB, 11.0%, 5.2% steady) and a
  seventh bar, names the benchmark machine correctly (a laptop, not a VM),
  and is shorter where it ran long.
- Binary sizes follow the Direct3D 12 renderer: 2.4 MB.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 19:46:23 +02:00
Roman ChojnackiandClaude Opus 5.5 3f3c1808bf Bench runner: a reaktor-d3d12 arm, and no runs under a fallen-back renderer
An arm whose renderer would not start is skipped instead of being measured
under another renderer's name.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 19:46:23 +02:00
Roman ChojnackiandClaude Opus 5.5 22e94bef52 Direct3D 12 renderer on Windows, and --renderer directx
SDL's Direct3D 12 renderer is built on Windows, adding 62,464 bytes to each
program. --renderer directx tries direct3d12, then direct3d11. Showcase pages
draw byte-identical on direct3d12 and direct3d11 in both themes; a build
without Direct3D 12 lands directx on direct3d11.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 19:46:23 +02:00
admin 6fe21110a0 Merge pull request #87 from Alpaq92/perf-machine
PERFORMANCE.md names the machine the benchmark ran on
2026-10-22 19:34:11 +02:00
adminandClaude Opus 5.5 941783205b PERFORMANCE.md names the machine: a 4-core Ryzen 5 4600H VirtualBox VM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 19:31:36 +02:00
admin 1147cd1238 Merge pull request #86 from Alpaq92/gpu-idle-benchmark
REAKTOR_SDL_GL switches back on; benchmark re-run with the GPU idle
2026-10-22 19:10:49 +02:00
Roman ChojnackiandClaude Opus 5.5 6a0cc60d68 Benchmark re-run with the GPU idle, and a steady-state column
Reaktor's three rows were measured again with nothing else loading the GPU
(power state P8). Earlier GPU rows had shared it with another program, which
made Direct3D 11 and OpenGL miss 60 fps and spend 16-28% of a core waiting to
present. direct3d11 59.0 MB, 16.0%; opengl 69.9 MB, 11.2%; software keeps
8.9%, its re-run being within noise of it.

- A steady-state column: CPU from 3 s to 8 s, median of ten runs per
  renderer taken in turn, every run at 60 fps: software 7.2%, direct3d11
  12.3%, opengl 6.6%.
- Startup is called out: a run that draws for 0.2 s takes 0.16 s of CPU on
  software and 0.41-0.44 s on a GPU driver, which the 6-second run counts.
- A GPU renderer's CPU depends on what else uses the GPU.
- Chart, README alt text and the bench-versus-sampler note follow.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 19:09:19 +02:00
Roman ChojnackiandClaude Opus 5.5 db6c069b02 REAKTOR_SDL_GL switches SDL's GL drivers back on, not only off
A build directory configured without it had SDL_OPENGL and SDL_OPENGLES
forced off in its cache, and a later -DREAKTOR_SDL_GL=ON left them off, so
--renderer opengl fell back to Direct3D 11 with only a line on stderr. Both
now follow the option either way. Checked in one build directory: OFF, ON,
OFF again, with the cache and --renderer opengl following each step.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 19:09:19 +02:00
admin ddb5896fd8 Merge pull request #81 from Alpaq92/ui-test
Scripted UI tests: drive an app through its accessibility tree
2026-10-22 16:03:14 +02:00
admin 40fa5063eb Merge pull request #85 from Alpaq92/small-fixes
No MSVC warnings from Reaktor's code; bench runner on PowerShell 5.1; a startup step for the app's start
2026-10-22 15:52:00 +02:00
adminandClaude Opus 5.5 52f8ac52ec Marks scope lookups and may repeat; apps that run no test link no test code
- A container takes a mark too, and "#row Delete" finds Delete only inside a
  container carrying that mark, at any depth. One mark may sit on many
  widgets (every row's Delete as "del"), so "#row1 #del" reaches that row's
  button and "#del" reports how many matched. A target that is itself a mark
  is taken whole, spaces and all.
- The mark table grows as needed and keeps 63 characters, saying once when a
  mark is cut; --a11y-dump lists marks after the tree when there are any.
- When several widgets match, the log says how many and the first is used.
- The frame loop calls the test runner through a hook only reaktor_test_app
  sets, so runtime/test.c is linked into test programs alone: showcase,
  simple, notepad and bench no longer carry it.

Found by an independent review: repeated marks resolving to their first
holder only, a mark with a space split as a scope, silent truncation at 31
characters, and silent drops past 64 marks a frame.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 15:45:09 +02:00
adminandClaude Opus 5.5 b442e10ab2 No MSVC warnings from Reaktor's code, bench runner on PowerShell 5.1, a startup step for the app's start
- nk_impl.c builds with /wd4116 (Nuklear's NK_ALIGNOF) and the core library
  with /wd5287 (nuklear.h's own enum arithmetic), as the showcase already did.
- benchmarks/run.ps1 holds the process handle, without which Windows
  PowerShell 5.1 reports no exit code and every arm reads as failed.
- Diagnostics' startup memory gets REAKTOR_RSS_START after the application's
  start callback, so the stylesheets line no longer carries the showcase's
  splash window and tray (+2.4 MB private there, +0.0 MB for the sheets).
- The button row of the widget table says .keys is announced, and the key
  hook binds it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 15:23:38 +02:00
adminandClaude Opus 5.5 a09ee1e4c0 BSD cache: an unfinished arm64 cross build is dropped and built again in full
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 15:04:00 +02:00
admin 6a549439d9 Merge pull request #84 from Alpaq92/skip-identical
Skip frames that draw what is already on screen (.skip_same_frames)
2026-10-22 15:02:43 +02:00
adminandClaude Opus 5.5 88904a93ee BSD cache: record its commit only when every build finished; marks off the tree
The NetBSD arm64 showcase crashed because the first push's arm64 cross build
stopped halfway, yet the cache was saved under that run's commit. The next
run dated only the five files changed since as new, so objects the failed
build never reached were linked against the accessibility node's old layout.
The commit is now noted only when the cross build did not fail, and the cache
key moves to v2 so the bad cache is never restored.

Marks no longer sit in every accessibility node (4 KB per window, paid by
every app): they live in a table declare.c allocates when the first widget
sets one, so an application without marks pays nothing and the tree is the
size it was.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 15:01:37 +02:00
adminandClaude Opus 5.5 0eeb7300c0 Skip frames that draw what is already on screen, with .skip_same_frames
A launch that sets .skip_same_frames hashes each frame's draw commands field
by field (the command structs have gaps holding stale bytes, and the buffer
can still hold a pass that was laid out again) and neither renders nor
presents a frame that matches the last presented one. Exposed, shown,
resized, restored or rescaled windows, renderer resets, shots and captures
are always drawn. Off by default; the showcase turns it on and its
Diagnostics page counts frames drawn and skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 14:45:38 +02:00
admin 98c306c095 Merge pull request #83 from Alpaq92/software-opaque-geometry
Showcase splash on the quieter background; plainer benchmark notes
2026-10-22 14:36:11 +02:00
Roman ChojnackiandClaude Opus 5.5 ceeae331d9 PERFORMANCE.md: plainer wording for the benchmark notes
The 67.3% paragraph is written for a reader without the renderer's
vocabulary, and the comparison bullet names Kotlin Multiplatform as the
table does.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 14:32:41 +02:00
Roman ChojnackiandClaude Opus 5.5 803de74d59 Showcase splash on the quieter background, with an edge
The splash filled itself with the page's brightest background, white in the
light theme, and a borderless window has no shadow to part it from the
desktop. It now takes --background with a one-pixel --border edge. Peak
memory and startup CPU measure the same as before.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 14:32:40 +02:00
adminandClaude Opus 5.5 c373138e05 Declare reaktor_frame_settled for the test runner; clang refuses an implicit one
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 14:28:48 +02:00
admin b75054260a Merge remote-tracking branch 'origin/master' into ui-test 2026-10-22 14:14:23 +02:00
admin ae1e9641ae Merge pull request #82 from Alpaq92/software-opaque-geometry
Opaque geometry drawn unblended on the software renderer; benchmark r…
2026-10-22 14:10:11 +02:00
Roman ChojnackiandClaude Opus 5.5 13632a4ccc Opaque geometry drawn unblended on the software renderer; benchmark re-run
- SDL's software renderer blends a triangle through a surface of its own,
  so untextured triangles that are all opaque now go to it with blending
  off, as opaque rectangles already did. Pixels and a11y dumps are
  byte-identical on every showcase page in both themes.
- Reaktor's three benchmark rows re-measured from a fresh Release build
  with the submodules at their pinned commits: software 9.5 MB and 8.9% of
  a core (was 10.0 MB, 16.4%), direct3d11 60.0 MB, 13.9%, opengl 90.1 MB,
  12.8%. Table, chart, README alt text and the bench-versus-sampler note
  follow.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 14:08:46 +02:00
adminandClaude Opus 5.5 ae57c33d7c Keep the CI smoke folder out of the repository
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 13:15:58 +02:00
adminandClaude Opus 5.5 f74a2ea340 Scripted UI tests: drive an app through its accessibility tree
reaktor_test_app launches an application on SDL's dummy video driver and
runs a script on its own thread once the first frame settles. The script
finds widgets by name or by a .box.mark ("#mark"), clicks, types and presses
keys through SDL events, reads values and states, and waits for each frame
to settle; the run exits 0 when every check passed. tests/uitest.c covers
it, and CI runs it on every platform.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 13:15:46 +02:00
admin f36e02c2b1 Merge pull request #80 from Alpaq92/button-width
Buttons sized and drawn like GTK's; custom content; version 0.7.2
2026-10-20 15:43:05 +02:00
adminandClaude Opus 5.5 35586673e9 Version 0.7.2
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 15:41:24 +02:00
adminandClaude Opus 5.5 d0e3ae843c Buttons sized and drawn like GTK's: content width, centered icon, custom content
- .fit_content sizes an icon button to the icon's drawn width, a 12 px gap,
  the label and half the sheet's padding; a .box.w is then its least width,
  and the button rule's min-width applies.
- At any width the icon and label are centered together on the icon's drawn
  pixels; the icon follows the button font, or 'button .icon' in the sheet.
- reaktor_button_width, reaktor_button_accent_icon, .accent with .icon.
- reaktor_button_custom and .paint/.paint_user: the sheet's button with the
  inside painted by the app.
- Showcase: icon buttons sized to content and wrapping, a Width section with
  the four ways to size a button, and a Custom content section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 15:41:20 +02:00
83 changed files with 3204 additions and 910 deletions
+27 -8
View File
@@ -54,8 +54,13 @@ jobs:
.ccache
build
build-arm64
key: build-${{ matrix.os }}-${{ matrix.version }}-${{ matrix.arch }}-${{ github.run_id }}
restore-keys: build-${{ 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
# ninja rebuilds by mtime, and a checkout dates every file now. Date them
# before the cached objects instead, and only what changed since the
@@ -182,7 +187,7 @@ jobs:
echo "the program carries the sysroot's path"; exit 1
fi
version='${{ inputs.version || 'dev' }}'
name="libreaktor-${version#v}-${{ matrix.os }}-arm64"
name="libreaktor-${version}-${{ matrix.os }}-arm64"
cmake --install build-arm64 --prefix "dist/$name" --component libreaktor </dev/null
if grep -rq "$sysroot" "dist/$name/lib/cmake" "dist/$name/lib/pkgconfig"; then
echo "the package carries the sysroot's path"; exit 1
@@ -200,6 +205,13 @@ jobs:
shell: cpa.sh {0} --sync-files vm-to-runner
run: ':'
# A cross build that stopped halfway holds objects from before the change,
# which the next run would take as current: it is built again in full.
- name: Drop an unfinished cross build
if: ${{ always() && steps.cross.outcome == 'failure' }}
shell: bash
run: rm -rf build-arm64
- name: Note which commit the cached build is from
if: ${{ always() && steps.build.outcome == 'success' }}
shell: bash
@@ -213,7 +225,7 @@ jobs:
.ccache
build
build-arm64
key: build-${{ 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' }}
@@ -260,6 +272,13 @@ jobs:
export PATH
sh tools/ci/instance.sh -w "dbus-run-session -- timeout 120" build
- name: Scripted UI test
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
export PATH
sh tools/ci/uitest.sh -w "dbus-run-session -- timeout 120" build
- name: Build mkicon
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
@@ -274,7 +293,7 @@ jobs:
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
export PATH
version='${{ inputs.version || 'dev' }}'
sh tools/ci/check-package.sh -w "dbus-run-session --" build "reaktor-${version#v}-${{ matrix.os }}-${{ matrix.arch }}"
sh tools/ci/check-package.sh -w "dbus-run-session --" build "reaktor-${version}-${{ matrix.os }}-${{ matrix.arch }}"
- name: Check and pack libreaktor
id: libcheck
@@ -283,7 +302,7 @@ jobs:
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 -w "dbus-run-session --" build "libreaktor-${version#v}-${{ matrix.os }}-${{ matrix.arch }}"
sh tools/ci/check-libreaktor.sh -w "dbus-run-session --" build "libreaktor-${version}-${{ matrix.os }}-${{ matrix.arch }}"
- name: Check the libreaktor system package
if: ${{ !cancelled() && steps.libcheck.outcome == 'success' }}
@@ -468,7 +487,7 @@ jobs:
PATH=/usr/pkg/sbin:/usr/pkg/bin:/usr/local/sbin:/usr/local/bin:$PATH
export PATH
version='${{ inputs.version || 'dev' }}'
sh tools/ci/check-package.sh -w "dbus-run-session --" build-arm64 "reaktor-${version#v}-${{ matrix.os }}-arm64"
sh tools/ci/check-package.sh -w "dbus-run-session --" build-arm64 "reaktor-${version}-${{ matrix.os }}-arm64"
- name: Check and pack libreaktor
id: libcheck
@@ -477,7 +496,7 @@ jobs:
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-${version#v}-${{ matrix.os }}-arm64"
sh tools/ci/check-libreaktor.sh -i -w "dbus-run-session --" build-arm64 "libreaktor-${version}-${{ matrix.os }}-arm64"
- name: Collect the shots
if: ${{ always() && steps.vm.outcome == 'success' }}
+7 -3
View File
@@ -100,7 +100,7 @@ jobs:
cross="-DCMAKE_TOOLCHAIN_FILE=/src/tools/cross/linux-cross.cmake -DREAKTOR_CROSS_TRIPLE=${{ matrix.triple }}"
fi
version='${{ inputs.version || 'dev' }}'
docker exec -i -e CROSS="$cross" -e TRIPLE="${{ matrix.triple }}" -e LIBNAME="libreaktor-${version#v}-linux-${{ matrix.arch }}" "$ctr" sh -eu <<'EOF'
docker exec -i -e CROSS="$cross" -e TRIPLE="${{ matrix.triple }}" -e LIBNAME="libreaktor-${version}-linux-${{ matrix.arch }}" "$ctr" sh -eu <<'EOF'
uname -a
cmake --version
export CCACHE_DIR=/src/.ccache CCACHE_BASEDIR=/src CCACHE_MAXSIZE=500M
@@ -147,12 +147,16 @@ jobs:
if: ${{ !cancelled() && steps.build.outcome == 'success' && matrix.arch == 'x86-64' }}
run: docker exec -i debian sh tools/ci/instance.sh -w "dbus-run-session -- timeout 120" build </dev/null
- name: Scripted UI test
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: Package
id: package
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
version='${{ inputs.version || 'dev' }}'
docker exec -i debian sh -eu tools/ci/check-package.sh -w "timeout 600" build "reaktor-${version#v}-linux-${{ matrix.arch }}" </dev/null
docker exec -i debian sh -eu tools/ci/check-package.sh -w "timeout 600" build "reaktor-${version}-linux-${{ matrix.arch }}" </dev/null
- name: Upload the package
if: ${{ !cancelled() && steps.package.outcome == 'success' }}
@@ -170,7 +174,7 @@ jobs:
version='${{ inputs.version || 'dev' }}'
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 "libreaktor-${version#v}-linux-${{ matrix.arch }}" </dev/null
docker exec -i debian sh -eu tools/ci/check-libreaktor.sh $installed -w "timeout 600" build "libreaktor-${version}-linux-${{ matrix.arch }}" </dev/null
- name: Pack libreaktor as a .deb
id: deb
+6 -2
View File
@@ -88,12 +88,16 @@ jobs:
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: sh tools/ci/instance.sh build
- name: Scripted UI test
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: sh tools/ci/uitest.sh build
- name: Package
id: package
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
version='${{ inputs.version || 'dev' }}'
name="reaktor-${version#v}-macos-${{ matrix.arch }}"
name="reaktor-${version}-macos-${{ matrix.arch }}"
sh tools/package.sh build "dist/$name"
for p in showcase notepad simple bench; do
codesign --force --sign - "dist/$name/$p"
@@ -133,7 +137,7 @@ jobs:
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
version='${{ inputs.version || 'dev' }}'
name="libreaktor-${version#v}-macos-${{ matrix.arch }}"
name="libreaktor-${version}-macos-${{ matrix.arch }}"
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 \
+8 -7
View File
@@ -19,20 +19,21 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
submodules: recursive
persist-credentials: false
- name: Cache emsdk
uses: actions/cache@v4
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/emsdk
key: emsdk-${{ env.EMSCRIPTEN_VERSION }}
key: emsdk-${{ env.EMSCRIPTEN_VERSION }}-tag
- name: Install emsdk
run: |
if [ ! -x "$HOME/emsdk/emsdk" ]; then
git clone --depth 1 https://github.com/emscripten-core/emsdk.git "$HOME/emsdk"
git clone --depth 1 --branch "$EMSCRIPTEN_VERSION" https://github.com/emscripten-core/emsdk.git "$HOME/emsdk"
fi
"$HOME/emsdk/emsdk" install "$EMSCRIPTEN_VERSION"
"$HOME/emsdk/emsdk" activate "$EMSCRIPTEN_VERSION"
@@ -47,10 +48,10 @@ jobs:
run: |
mkdir -p site
cp build-wasm/showcase.js build-wasm/showcase.wasm build-wasm/showcase.data site/
cp build-wasm/keylog.js build-wasm/reaktor-icon.svg build-wasm/reaktor-icon.png site/
cp build-wasm/shell.js build-wasm/keylog.js build-wasm/reaktor-icon.svg build-wasm/reaktor-icon.png site/
cp build-wasm/showcase.html site/index.html
- uses: actions/upload-pages-artifact@v3
- uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1
with:
path: site
@@ -65,4 +66,4 @@ jobs:
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@v4
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5
+21 -6
View File
@@ -2,40 +2,56 @@ name: Release
on:
push:
tags: ['v*']
tags: ['[0-9]+.[0-9]+.[0-9]+', '[0-9]+.[0-9]+.[0-9]+-*']
permissions:
contents: read
jobs:
tag:
runs-on: ubuntu-24.04
steps:
- name: Check the tag is a version
run: |
if ! printf '%s' "$GITHUB_REF_NAME" | grep -Eqx '[0-9]+[.][0-9]+[.][0-9]+(-[0-9A-Za-z.]+)?'; then
echo "$GITHUB_REF_NAME is not a version tag like 1.2.3 or 1.2.3-rc1"
exit 1
fi
windows:
needs: tag
uses: ./.github/workflows/windows.yml
with:
version: ${{ github.ref_name }}
macos:
needs: tag
uses: ./.github/workflows/macos.yml
with:
version: ${{ github.ref_name }}
linux:
needs: tag
uses: ./.github/workflows/linux.yml
with:
version: ${{ github.ref_name }}
strict: true
bsd:
needs: tag
uses: ./.github/workflows/bsd.yml
with:
version: ${{ github.ref_name }}
strict: true
web:
needs: tag
uses: ./.github/workflows/web.yml
with:
version: ${{ github.ref_name }}
source:
needs: tag
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -46,8 +62,7 @@ jobs:
- name: Version
run: |
v=${GITHUB_REF_NAME#v}
v=${v%%-*}
v=${GITHUB_REF_NAME%%-*}
if ! grep -qF "project(reaktor VERSION $v " src/CMakeLists.txt; then
echo "$GITHUB_REF_NAME, but CMakeLists.txt is not at $v"
exit 1
@@ -59,7 +74,7 @@ jobs:
- name: Archive
run: |
name="reaktor-${GITHUB_REF_NAME#v}-source"
name="reaktor-$GITHUB_REF_NAME-source"
mkdir dist
tar --exclude=.git --transform "s,^src,$name," -czf "dist/$name.tar.gz" src
@@ -87,7 +102,7 @@ jobs:
GH_TOKEN: ${{ github.token }}
run: |
ls -l dist
v=${GITHUB_REF_NAME#v}
v=$GITHUB_REF_NAME
cat >notes.md <<EOF
| System | Architectures | Download |
| --- | --- | --- |
@@ -123,7 +138,7 @@ jobs:
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, libcss, plutosvg, Onlay, NukAnim, mojibake, kb_text_shape and PDFGen
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.
+6 -6
View File
@@ -37,7 +37,7 @@ jobs:
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/emsdk
key: emsdk-${{ env.EMSCRIPTEN_VERSION }}
key: emsdk-${{ env.EMSCRIPTEN_VERSION }}-tag
# ccache only: the build folder is rebuilt, so a stale cache cannot hide a broken one.
- name: Restore the compiler cache
@@ -51,7 +51,7 @@ jobs:
- name: Install emsdk
run: |
if [ ! -d "$HOME/emsdk" ]; then
git clone --depth 1 https://github.com/emscripten-core/emsdk.git "$HOME/emsdk"
git clone --depth 1 --branch "$EMSCRIPTEN_VERSION" https://github.com/emscripten-core/emsdk.git "$HOME/emsdk"
"$HOME/emsdk/emsdk" install "$EMSCRIPTEN_VERSION"
fi
"$HOME/emsdk/emsdk" activate "$EMSCRIPTEN_VERSION"
@@ -62,7 +62,7 @@ jobs:
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/emsdk
key: emsdk-${{ env.EMSCRIPTEN_VERSION }}
key: emsdk-${{ env.EMSCRIPTEN_VERSION }}-tag
- name: Build
id: build
@@ -82,13 +82,13 @@ jobs:
- name: Package
run: |
version='${{ inputs.version || 'dev' }}'
name="reaktor-${version#v}-web"
name="reaktor-${version}-web"
mkdir -p "dist/$name/licenses"
for p in showcase notepad simple; do
cp "build-wasm/$p.html" "build-wasm/$p.js" "build-wasm/$p.wasm" \
"build-wasm/$p.data" "dist/$name/"
done
cp build-wasm/keylog.js build-wasm/reaktor-icon.svg build-wasm/reaktor-icon.png \
cp build-wasm/shell.js build-wasm/keylog.js build-wasm/reaktor-icon.svg build-wasm/reaktor-icon.png \
"dist/$name/"
cp build-wasm/licenses/*.txt "dist/$name/licenses/"
cp external/simplecss/LICENSE "dist/$name/licenses/simplecss.txt"
@@ -108,7 +108,7 @@ jobs:
- name: Check and pack libreaktor
run: |
version='${{ inputs.version || 'dev' }}'
name="libreaktor-${version#v}-wasm"
name="libreaktor-${version}-wasm"
cmake --build build-wasm --target libreaktor
cmake --install build-wasm --prefix "dist/$name" --component libreaktor
cmake -S examples/consumer -B build-consumer -G Ninja -DCMAKE_BUILD_TYPE=Release \
+11 -2
View File
@@ -152,13 +152,22 @@ jobs:
}
Write-Host "second launch handed its file over: ok"
- name: Scripted UI test
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: |
New-Item -ItemType Directory -Force smoke | Out-Null
$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
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
shell: bash
run: |
version='${{ inputs.version || 'dev' }}'
name="reaktor-${version#v}-windows-${{ matrix.arch }}"
name="reaktor-${version}-windows-${{ matrix.arch }}"
sh tools/package.sh "${{ matrix.out }}" "dist/$name" .exe
echo "name=$name" >>"$GITHUB_OUTPUT"
@@ -213,7 +222,7 @@ jobs:
id: libcheck
if: ${{ !cancelled() && steps.lib.outcome == 'success' }}
run: |
$version = '${{ inputs.version || 'dev' }}' -replace '^v', ''
$version = '${{ inputs.version || 'dev' }}'
$name = "libreaktor-$version-windows-${{ matrix.arch }}"
cmake --install build-lib --prefix "dist/$name" --component libreaktor
if ($LASTEXITCODE -ne 0) { throw "install failed" }
+1
View File
@@ -32,3 +32,4 @@ benchmarks/flutter-bench/*.iml
build-pkg/
build-pkg-consumer/
dist/
smoke/
+15 -15
View File
@@ -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 = https://github.com/lc-soft/LCUI.git
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 = https://github.com/mattiasgustavsson/libs.git
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
[submodule "external/pdfgen"]
path = external/pdfgen
url = https://github.com/AndreRenaud/PDFGen
url = ../simple.css.git
[submodule "external/freetype"]
path = external/freetype
url = ../freetype.git
+3 -2
View File
@@ -10,7 +10,7 @@ script finds MSVC's. `./build.ps1 <target>` builds one. Targets: `showcase`,
`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
`v*` tag publishes one through `release.yml`.
version tag such as `1.2.3` publishes one 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
@@ -114,7 +114,8 @@ regression oracle for every layout or style change.
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.
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.
+79 -27
View File
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.16)
project(reaktor VERSION 0.7.1 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)
@@ -33,14 +33,17 @@ foreach(sub AUDIO JOYSTICK HAPTIC HIDAPI SENSOR CAMERA POWER GPU OFFSCREEN)
endforeach()
set(SDL_TRAY ON CACHE BOOL "" FORCE)
foreach(drv RENDER_D3D RENDER_D3D12 RENDER_VULKAN VULKAN)
foreach(drv RENDER_D3D RENDER_VULKAN VULKAN)
set(SDL_${drv} OFF CACHE BOOL "" FORCE)
endforeach()
if(WIN32)
set(SDL_RENDER_D3D12 ON CACHE BOOL "" FORCE)
endif()
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 AND NOT REAKTOR_SDL_GL)
set(SDL_OPENGL OFF CACHE BOOL "" FORCE)
set(SDL_OPENGLES OFF CACHE BOOL "" FORCE)
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()
set(SDL_X11_XSCRNSAVER OFF CACHE BOOL "" FORCE)
@@ -53,12 +56,31 @@ if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
set(SDL_DEPS_SHARED OFF CACHE BOOL "" FORCE)
endif()
# A static program keeps only the functions it calls; MSVC's Release does this already.
if(NOT MSVC AND NOT EMSCRIPTEN)
# A static program keeps only the functions and data it uses. MSVC's Release
# already splits functions; /Gw splits data.
if(MSVC)
add_compile_options(/Gw)
elseif(NOT EMSCRIPTEN)
add_compile_options(-ffunction-sections -fdata-sections)
endif()
add_subdirectory("${TP}/SDL" EXCLUDE_FROM_ALL)
# SDL's dynamic API keeps every SDL function linked and loads whichever SDL
# library the SDL3_DYNAMIC_API environment variable names. Reaktor links SDL
# statically and reads no environment, so it is compiled out.
file(STRINGS "${TP}/SDL/src/dynapi/SDL_dynapi.h" _dynapi_guard REGEX "^#ifndef SDL_dynapi_h_")
if(NOT _dynapi_guard)
message(FATAL_ERROR "SDL_dynapi.h no longer opens with #ifndef SDL_dynapi_h_; "
"core/sdl/no_dynapi.h needs its new guard")
endif()
if(MSVC)
target_compile_options(SDL3-static PRIVATE
"/FI${CMAKE_CURRENT_SOURCE_DIR}/core/sdl/no_dynapi.h")
else()
target_compile_options(SDL3-static PRIVATE
-include "${CMAKE_CURRENT_SOURCE_DIR}/core/sdl/no_dynapi.h")
endif()
set(LC "${TP}/lcui/lib")
set(LCUI_CFG "${CMAKE_BINARY_DIR}/gen/lcui")
file(MAKE_DIRECTORY "${LCUI_CFG}")
@@ -123,13 +145,24 @@ 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")
target_compile_definitions(plutovg PUBLIC PLUTOVG_BUILD_STATIC)
target_compile_definitions(plutovg PUBLIC PLUTOVG_BUILD_STATIC
PRIVATE STBI_ONLY_PNG STBI_ONLY_JPEG)
add_library(plutosvg STATIC "${TP}/plutosvg/source/plutosvg.c")
target_include_directories(plutosvg PUBLIC "${TP}/plutosvg/source")
target_compile_definitions(plutosvg PUBLIC PLUTOSVG_BUILD_STATIC)
target_link_libraries(plutosvg PUBLIC plutovg)
set(FT "${TP}/freetype/src")
add_library(freetype STATIC
${FT}/base/ftsystem.c ${FT}/base/ftinit.c ${FT}/base/ftdebug.c ${FT}/base/ftbase.c
${FT}/autofit/autofit.c ${FT}/cff/cff.c ${FT}/psaux/psaux.c ${FT}/pshinter/pshinter.c
${FT}/psnames/psnames.c ${FT}/sfnt/sfnt.c ${FT}/smooth/smooth.c ${FT}/truetype/truetype.c)
target_include_directories(freetype PUBLIC "${TP}/freetype/include" core/render/ft)
target_compile_definitions(freetype
PUBLIC "FT_CONFIG_OPTIONS_H=<reaktor_ftoption.h>"
PRIVATE FT2_BUILD_LIBRARY "FT_CONFIG_MODULES_H=<reaktor_ftmodule.h>")
add_library(onlay STATIC ${TP}/onlay/onlay.c)
target_include_directories(onlay PUBLIC ${TP}/onlay)
target_compile_definitions(onlay PUBLIC LAY_FLOAT=1)
@@ -197,11 +230,14 @@ target_include_directories(reaktor_headers INTERFACE include "${TP}/nuklear" "${
add_library(reaktor_core STATIC
core/base/util.c
core/base/utf8.c
core/base/url.c
core/render/font.c
core/render/nk_impl.c
core/render/svg.c
"${_builtins}")
target_include_directories(reaktor_core PUBLIC core/base core/render)
target_link_libraries(reaktor_core PUBLIC plutosvg reaktor_headers SDL3::SDL3-static)
target_link_libraries(reaktor_core PUBLIC plutosvg freetype reaktor_headers SDL3::SDL3-static)
set(APP_ICON assets/icons/reaktor-icon.ico)
set(APP_RESOURCES "")
@@ -222,10 +258,10 @@ endif()
if(REAKTOR_TESTS AND NOT EMSCRIPTEN)
add_executable(a11ytest tests/a11ytest.c core/a11y/a11y.c
platform/a11y/a11y_snapshot.c)
platform/a11y/a11y_snapshot.c core/base/utf8.c)
target_link_libraries(a11ytest PRIVATE reaktor_headers SDL3::SDL3-static)
target_include_directories(a11ytest PRIVATE core/a11y core/render
platform/a11y)
platform/a11y core/base)
set_target_properties(a11ytest PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
endif()
@@ -257,9 +293,21 @@ if(REAKTOR_TESTS AND NOT EMSCRIPTEN)
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)
target_compile_definitions(csstest PRIVATE _CRT_SECURE_NO_WARNINGS)
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 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)
set_target_properties(imagetest PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
endif()
if(WIN32 AND NOT EMSCRIPTEN)
@@ -504,7 +552,7 @@ else()
endif()
endif()
option(REAKTOR_PRINT "Printing and PDF export, through PDFGen" ON)
option(REAKTOR_PRINT "Printing and PDF export" ON)
add_library(reaktor_print_none INTERFACE)
target_sources(reaktor_print_none INTERFACE
@@ -514,17 +562,8 @@ if(NOT REAKTOR_PRINT OR EMSCRIPTEN)
target_link_libraries(reaktor_print INTERFACE reaktor_print_none)
message(STATUS "print: off")
else()
add_library(pdfgen STATIC "${CMAKE_CURRENT_SOURCE_DIR}/runtime/pdfgen_unit.c")
target_include_directories(pdfgen PUBLIC "${TP}/pdfgen")
if(MSVC)
target_compile_options(pdfgen PRIVATE /w)
target_compile_definitions(pdfgen PRIVATE _CRT_SECURE_NO_WARNINGS)
else()
target_compile_options(pdfgen PRIVATE -w)
target_link_libraries(pdfgen PUBLIC m)
endif()
target_sources(reaktor_print INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/runtime/print.c")
target_link_libraries(reaktor_print INTERFACE pdfgen plutovg)
target_link_libraries(reaktor_print INTERFACE plutovg)
if(WIN32)
target_link_libraries(reaktor_print INTERFACE comdlg32 gdi32)
elseif(APPLE)
@@ -559,6 +598,7 @@ add_library(reaktor_runtime STATIC
runtime/app.c
runtime/input.c
runtime/instance.c
runtime/test.c
runtime/services.c
runtime/undo.c
runtime/window.c)
@@ -600,13 +640,15 @@ set(REAKTOR_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE INTERNAL "")
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 pdfgen/LICENSE)
kb/LICENSE)
string(REGEX REPLACE "/.*" "" _who "${_lic}")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/external/${_lic}"
"${CMAKE_BINARY_DIR}/licenses/${_who}.txt" COPYONLY)
endforeach()
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/mglibs/ini.h"
"${CMAKE_BINARY_DIR}/licenses/ini.h.txt" COPYONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/LICENSE"
@@ -696,6 +738,7 @@ reaktor_add_app(notepad MODULES settings popups print SOURCES samples/notepad/no
if(NOT EMSCRIPTEN)
reaktor_add_app(bench MODULES none SOURCES samples/bench/bench.c)
reaktor_add_app(launchtest MODULES settings popups print SOURCES tests/launchtest.c)
reaktor_add_app(uitest MODULES none SOURCES tests/uitest.c)
set_target_properties(launchtest PROPERTIES EXCLUDE_FROM_ALL ON)
endif()
@@ -704,6 +747,7 @@ if(EMSCRIPTEN)
target_compile_options(lcui PRIVATE -Oz)
target_compile_options(plutovg PRIVATE -Oz)
target_compile_options(plutosvg PRIVATE -Oz)
target_compile_options(freetype PRIVATE -Oz)
target_compile_options(reaktor_core PRIVATE -Oz)
if(TARGET mojibake_lib)
target_compile_options(mojibake_lib PRIVATE -Oz)
@@ -801,12 +845,19 @@ if(EMSCRIPTEN)
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/tools/keylog.js"
"${CMAKE_BINARY_DIR}/keylog.js"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/tools/shell.js"
"${CMAKE_BINARY_DIR}/shell.js"
COMMENT "Copying page assets"
VERBATIM)
endif()
if(MSVC)
target_compile_options(showcase PRIVATE /wd5287 /wd4101)
# Nuklear's NK_ALIGNOF takes the offset of a member of an unnamed struct.
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)
target_compile_definitions(showcase PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
@@ -837,8 +888,9 @@ 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 lcui onlay SDL3-static)
foreach(_t mojibake_lib kb_text_shape pdfgen)
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})
list(APPEND _parts ${_t})
endif()
+2 -2
View File
@@ -11,7 +11,7 @@ Tired of C having no cross-platform GUI — nothing like
[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.3 MB binary, about 10 MB of RAM, and no GPU
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
@@ -23,7 +23,7 @@ yourself.
> ⚠️ **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 10.0 MB, the same binary on D3D11 60.7 MB and on OpenGL 90.2 MB, Flutter 92.2 MB, Electron 158.3 MB, Kotlin Multiplatform 669.8 MB. CPU as a percent of one core: Reaktor 16.4%, D3D11 14.4%, OpenGL 14.1%, Flutter 16.6%, Electron 39.0%, Kotlin Multiplatform 56.1%"></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).
+7 -5
View File
@@ -25,11 +25,13 @@ 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 three times — `reaktor-software`, its default, and
`reaktor-d3d11` 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
two are the like-for-like comparison. SDL's OpenGL driver is built only with
`-DREAKTOR_SDL_GL=ON`, which the `reaktor-opengl` arm's build passes.
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 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
+14 -2
View File
@@ -1,7 +1,7 @@
param(
[string[]] $Targets = @("reaktor-software", "reaktor-d3d11",
"reaktor-opengl", "shaft", "flutter", "electron",
"kmp"),
"reaktor-d3d12", "reaktor-opengl", "shaft",
"flutter", "electron", "kmp"),
[double] $Seconds = 6,
[double] $Fps = 60,
[int] $Boxes = 64,
@@ -28,6 +28,12 @@ function Get-Arm([string]$name) {
dir = $root
make = "./build.ps1 bench" }
}
"reaktor-d3d12" {
@{ exe = Join-Path $root "build\bench.exe"
args = @("--renderer", "direct3d12")
dir = $root
make = "./build.ps1 bench" }
}
"reaktor-opengl" {
@{ exe = Join-Path $root "build\bench.exe"
args = @("--renderer", "opengl")
@@ -89,6 +95,8 @@ function Invoke-Arm($spec, [string[]]$argv) {
$err = [IO.Path]::GetTempFileName()
$proc = Start-Process -FilePath $spec.exe -ArgumentList ($spec.args + $argv) -WorkingDirectory $spec.dir -PassThru -RedirectStandardOutput $out -RedirectStandardError $err
# Windows PowerShell 5.1 reports no exit code unless the handle is held.
$null = $proc.Handle
$cpuMs = @{}
$peakPrivate = 0L
@@ -173,6 +181,10 @@ foreach ($name in $Targets) {
Write-Host ("{0,-18} exited {1}: {2}" -f $name, $r.exit, $r.stderr.Trim())
break
}
if ($r.stderr -match "would not start") {
Write-Host ("{0,-18} skipped - its renderer would not start: {1}" -f $name, $r.stderr.Trim())
break
}
$private += $r.private_mb
$cpuCore += $r.cpu_core
+2 -1
View File
@@ -14,7 +14,8 @@ if (-not (Test-Path $toolchain)) {
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if (-not (Test-Path $vswhere)) { throw "vswhere.exe not found - install Visual Studio Build Tools" }
$vsPath = & $vswhere -latest -products * -property installationPath
$vsPath = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.CMake.Project -property installationPath
if (-not $vsPath) { throw "no Visual Studio with the C++ CMake tools - add them in the Visual Studio Installer" }
$cmake = Join-Path $vsPath "Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe"
$ninja = Join-Path $vsPath "Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.exe"
foreach ($t in @($cmake, $ninja)) {
+11 -9
View File
@@ -57,9 +57,9 @@ intern(reaktor_a11y *a, const char *s, unsigned h)
static reaktor_a11y_slot *
slot_of(reaktor_a11y_slot *tab, unsigned gen, unsigned key)
{
unsigned i = key & (REAKTOR_A11Y_SLOTS - 1);
unsigned i = key & (REAKTOR_A11Y_SLOTS - 1), n;
for (;;) {
for (n = 0; n < REAKTOR_A11Y_SLOTS; n++) {
reaktor_a11y_slot *sl = &tab[i];
if (sl->gen != gen) {
sl->gen = gen;
@@ -70,19 +70,21 @@ slot_of(reaktor_a11y_slot *tab, unsigned gen, unsigned key)
if (sl->key == key) return sl;
i = (i + 1) & (REAKTOR_A11Y_SLOTS - 1);
}
return NULL;
}
static int
slot_get(const reaktor_a11y_slot *tab, unsigned gen, unsigned key)
{
unsigned i = key & (REAKTOR_A11Y_SLOTS - 1);
unsigned i = key & (REAKTOR_A11Y_SLOTS - 1), n;
for (;;) {
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
@@ -106,15 +108,14 @@ emit(reaktor_a11y *a, unsigned char role, const char *name, const char *value,
return 0;
}
parent = a->depth > 0 ? a->parent[a->depth - 1] : 0u;
parent = a->depth > 0 ? a->parent[NK_MIN(a->depth, REAKTOR_A11Y_MAX_DEPTH) - 1] : 0u;
nh = hash_str(REAKTOR_FNV, name);
base = nh ^ ((unsigned)role * 0x9e3779b9u);
base ^= parent + 0x9e3779b9u + (base << 6) + (base >> 2);
sl = slot_of(a->bucket, a->bucket_gen, base);
id = base ^ ((unsigned)sl->val * 0x85ebca6bu);
sl->val++;
id = sl ? base ^ ((unsigned)sl->val++ * 0x85ebca6bu) : base;
if (id == 0) id = 1;
if (role == REAKTOR_A11Y_NONE) return id;
@@ -258,6 +259,7 @@ reaktor_a11y_end(reaktor_a11y *a)
const reaktor_a11y_node *cur = a->node[f], *old = a->node[b];
int ncur = a->count[f], nold = a->count[b];
int i;
reaktor_a11y_slot *sl;
if (!a->building) return 0;
a->building = 0;
@@ -265,7 +267,7 @@ reaktor_a11y_end(reaktor_a11y *a)
a->index_gen++;
for (i = 0; i < ncur; i++)
slot_of(a->index, a->index_gen, cur[i].id)->val = i + 1;
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;
@@ -289,7 +291,7 @@ reaktor_a11y_end(reaktor_a11y *a)
a->index_gen++;
for (i = 0; i < nold; i++)
slot_of(a->index, a->index_gen, old[i].id)->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++) {
+27
View File
@@ -0,0 +1,27 @@
#include <SDL3/SDL.h>
#include "util.h"
static int scheme_listed(const char *url, size_t n, const char *list)
{
while (list && *list) {
const char *end = SDL_strchr(list, ',');
size_t k = end ? (size_t)(end - list) : SDL_strlen(list);
if (k == n && SDL_strncasecmp(url, list, n) == 0) return 1;
list = end ? end + 1 : list + k;
}
return 0;
}
int reaktor_url_allowed(const char *url, const char *extra)
{
size_t n;
if (!url || !SDL_isalpha((unsigned char)url[0])) return 0;
for (n = 1; url[n] != ':'; n++)
if (!SDL_isalnum((unsigned char)url[n]) && url[n] != '+' && url[n] != '-' &&
url[n] != '.')
return 0;
return scheme_listed(url, n, "http,https,mailto") || scheme_listed(url, n, extra);
}
+21
View File
@@ -0,0 +1,21 @@
#include <string.h>
#include <SDL3/SDL.h>
#include "util.h"
size_t reaktor_utf8_clean(char *dst, const char *src, size_t cap)
{
size_t left = strlen(src), n = 0;
char ch[4];
if (!cap) return 0;
while (left) {
size_t k = (size_t)(SDL_UCS4ToUTF8(SDL_StepUTF8(&src, &left), ch) - ch);
if (n + k >= cap) break;
memcpy(dst + n, ch, k);
n += k;
}
dst[n] = 0;
return n;
}
+4 -11
View File
@@ -74,24 +74,16 @@ static int reaktor_root(char *out, size_t cap)
const char *base = SDL_GetBasePath();
char dir[REAKTOR_PATH_CAP], probe[REAKTOR_PATH_CAP];
size_t n;
int i;
int i, up;
if (base) {
if (!copy_out(dir, sizeof(dir), base)) return 0;
} else {
char *cwd = SDL_GetCurrentDirectory();
int ok = cwd && copy_out(dir, sizeof(dir), cwd);
SDL_free(cwd);
if (!ok) return 0;
}
if (!base || !copy_out(dir, sizeof(dir), base)) return 0;
for (i = 0; dir[i]; i++) if (dir[i] == '\\') dir[i] = '/';
n = strlen(dir);
while (n > 1 && dir[n - 1] == '/') dir[--n] = '\0';
if (n > 19 && strcmp(dir + n - 19, "/Contents/Resources") == 0)
return copy_out(out, cap, dir);
for (;;) {
for (up = 0; up <= 2; up++) {
char *slash;
if (snprintf(probe, sizeof(probe), "%s/.reaktor-root", dir) < 0)
@@ -107,6 +99,7 @@ static int reaktor_root(char *out, size_t cap)
if (!slash) return 0;
*slash = '\0';
}
return 0;
}
#endif
}
+2
View File
@@ -33,6 +33,8 @@ extern const int reaktor_builtin_count;
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);
int reaktor_url_allowed(const char *url, const char *extra);
void reaktor_release_free_memory(void);
+106 -51
View File
@@ -299,11 +299,14 @@ void reaktor_cssvars_free(reaktor_cssvars *m)
free(m);
}
#define VAR_MAX 4096
static int subst_vars(const reaktor_cssvars *m, const char *src, size_t len,
buf *out)
{
size_t i = 0;
if (len > VAR_MAX) return 0;
while (i < len) {
const char *at;
size_t j, depth, name_s, name_e, fb_s, fb_e;
@@ -352,6 +355,7 @@ static int subst_vars(const reaktor_cssvars *m, const char *src, size_t len,
} else {
return 0;
}
if (out->len > VAR_MAX) return 0;
i = j + 1;
}
return 1;
@@ -408,7 +412,9 @@ static void convert_units(const char *s, size_t len, float rem_px, float em_px,
}
typedef struct calc_val { double v; int px; } calc_val;
typedef struct calc_in { const char *s; size_t i, n; } calc_in;
#define CALC_DEPTH 32
typedef struct calc_in { const char *s; size_t i, n; int depth, deep; } calc_in;
static void calc_space(calc_in *c)
{
@@ -420,30 +426,40 @@ static int calc_sum(calc_in *c, calc_val *out);
static int calc_atom(calc_in *c, calc_val *out)
{
const char *end;
int neg = 0, ok;
calc_space(c);
if (c->i < c->n && c->s[c->i] == '-') {
while (c->i < c->n && c->s[c->i] == '-') {
neg = !neg;
c->i++;
if (!calc_atom(c, out)) return 0;
out->v = -out->v;
return 1;
calc_space(c);
}
if (c->i + 5 <= c->n && strncmp(c->s + c->i, "calc(", 5) == 0) c->i += 4;
if (c->i < c->n && c->s[c->i] == '(') {
if (c->depth >= CALC_DEPTH) {
c->deep = 1;
return 0;
}
c->i++;
if (!calc_sum(c, out)) return 0;
c->depth++;
ok = calc_sum(c, out);
c->depth--;
if (!ok) return 0;
calc_space(c);
if (c->i >= c->n || c->s[c->i] != ')') return 0;
c->i++;
return 1;
} else {
if (c->i >= c->n || (!isdigit((unsigned char)c->s[c->i]) && c->s[c->i] != '.'))
return 0;
out->v = css_number(c->s + c->i, &end);
c->i = (size_t)(end - c->s);
out->px = c->i + 2 <= c->n && strncmp(c->s + c->i, "px", 2) == 0;
if (out->px) c->i += 2;
if (c->i < c->n && (isalpha((unsigned char)c->s[c->i]) || c->s[c->i] == '%'))
return 0;
}
if (c->i >= c->n || (!isdigit((unsigned char)c->s[c->i]) && c->s[c->i] != '.'))
return 0;
out->v = css_number(c->s + c->i, &end);
c->i = (size_t)(end - c->s);
out->px = c->i + 2 <= c->n && strncmp(c->s + c->i, "px", 2) == 0;
if (out->px) c->i += 2;
return c->i >= c->n || !(isalpha((unsigned char)c->s[c->i]) || c->s[c->i] == '%');
if (neg) out->v = -out->v;
return 1;
}
static int calc_product(calc_in *c, calc_val *out)
@@ -633,7 +649,7 @@ static int expand_border(buf *out, const char *p, size_t plen, const char *v, si
return 1;
}
static void resolve_pixel_calcs(buf *b)
static int resolve_pixel_calcs(buf *b)
{
static const char fn[] = "calc(";
size_t from = 0;
@@ -649,7 +665,12 @@ static void resolve_pixel_calcs(buf *b)
c.s = b->p;
c.i = s;
c.n = b->len;
if (!calc_atom(&c, &v)) { from = s + 1; continue; }
c.depth = c.deep = 0;
if (!calc_atom(&c, &v)) {
if (c.deep) return 0;
from = s + 1;
continue;
}
snprintf(out, sizeof(out), v.px ? "%gpx" : "%g", v.v);
memset(&r, 0, sizeof(r));
buf_add(&r, b->p, s);
@@ -659,6 +680,7 @@ static void resolve_pixel_calcs(buf *b)
*b = r;
from = s + strlen(out);
}
return 1;
}
static void strip_comments(char *s)
@@ -924,6 +946,21 @@ static void body_one(void *c, const char *p, size_t plen,
if (n > 0.0f) ctx->em = n;
}
/* The engine ends a token at any ';' or '}', even one inside url(), and
reads two slashes, or a slash and a star, as a comment without ending it. */
static int token_ok(const char *s, size_t n, size_t max)
{
size_t i;
if (n >= max) return 0;
for (i = 0; i < n; i++) {
if (s[i] == ';' || s[i] == '}') return 0;
if (s[i] == '/' && i + 1 < n && (s[i + 1] == '/' || s[i + 1] == '*'))
return 0;
}
return 1;
}
typedef struct emit_ctx {
const reaktor_cssvars *m;
buf *out;
@@ -937,15 +974,16 @@ static void emit_one(void *c, const char *p, size_t plen,
{
emit_ctx *ctx = (emit_ctx *)c;
buf tmp, conv;
int done;
if (plen > 2 && p[0] == '-' && p[1] == '-') return;
memset(&tmp, 0, sizeof(tmp));
if (!subst_vars(ctx->m, v, vlen, &tmp)) { free(tmp.p); return; }
mix_colors(&tmp);
if (!canon_colors(&tmp)) { free(tmp.p); return; }
memset(&conv, 0, sizeof(conv));
if (!subst_vars(ctx->m, v, vlen, &tmp)) goto out;
mix_colors(&tmp);
if (!canon_colors(&tmp)) goto out;
if (plen == 9 && strncmp(p, "font-size", 9) == 0 &&
tmp.len > 1 && tmp.p[tmp.len - 1] == '%') {
char px[64];
@@ -955,34 +993,25 @@ static void emit_one(void *c, const char *p, size_t plen,
} else {
convert_units(tmp.p ? tmp.p : "", tmp.len,
ctx->rem_px, ctx->em_px, &conv);
resolve_pixel_calcs(&conv);
if (!resolve_pixel_calcs(&conv)) goto out;
}
if ((plen >= 6 && strncmp(p, "border", 6) == 0) ||
(plen >= 7 && strncmp(p, "outline", 7) == 0))
line_width_keywords(&conv);
/* The engine ends a value at any ';', even one inside url(). */
if (plen >= ctx->token_max || conv.len >= ctx->token_max ||
(conv.p && memchr(conv.p, ';', conv.len))) {
free(tmp.p);
free(conv.p);
return;
if (!token_ok(p, plen, ctx->token_max) || !token_ok(conv.p, conv.len, ctx->token_max))
goto out;
done = expand_border(ctx->out, p, plen, conv.p ? conv.p : "", conv.len);
if (done >= 0) {
ctx->wrote |= done;
} else {
buf_add(ctx->out, p, plen);
buf_str(ctx->out, ": ");
buf_add(ctx->out, conv.p ? conv.p : "", conv.len);
buf_str(ctx->out, ";\n");
ctx->wrote = 1;
}
{
int done = expand_border(ctx->out, p, plen, conv.p ? conv.p : "", conv.len);
if (done >= 0) {
ctx->wrote |= done;
free(tmp.p);
free(conv.p);
return;
}
}
buf_add(ctx->out, p, plen);
buf_str(ctx->out, ": ");
buf_add(ctx->out, conv.p ? conv.p : "", conv.len);
buf_str(ctx->out, ";\n");
ctx->wrote = 1;
out:
free(tmp.p);
free(conv.p);
}
@@ -1184,6 +1213,19 @@ static char *flatten(char *src, const char *theme, size_t token_max,
}
if (!changed) break;
}
{
size_t k, kept = 0;
for (k = 0; k < m->n; k++) {
if (strstr(m->v[k].value, "var(")) {
free(m->v[k].name);
free(m->v[k].value);
} else {
m->v[kept++] = m->v[k];
}
}
m->n = kept;
}
memset(&out, 0, sizeof(out));
buf_str(&out, "/* Flattened by cssflat.c: custom properties resolved,\n"
@@ -1221,7 +1263,7 @@ static char *flatten(char *src, const char *theme, size_t token_max,
t = rw;
if (!tn) continue;
}
if (tn >= token_max || selector_repeats(t, tn)) continue;
if (!token_ok(t, tn, token_max) || selector_repeats(t, tn)) continue;
if (n_emitted) buf_str(&sel, ", ");
buf_add(&sel, t, tn);
}
@@ -1255,7 +1297,8 @@ static char *flatten(char *src, const char *theme, size_t token_max,
return out.p;
}
#define IMPORT_DEPTH 8
#define IMPORT_DEPTH 8
#define IMPORT_BUDGET (4u << 20)
/* `to` resolved against the folder of `from`, with "." and ".." folded away. */
static char *import_path(const char *from, const char *to, size_t n)
@@ -1289,10 +1332,20 @@ static void (*g_seen)(const char *path);
void reaktor_css_track(void (*seen)(const char *path)) { g_seen = seen; }
static int load_sheet(const char *path, int depth, buf *all)
static int in_chain(const char *const *chain, int depth, const char *path)
{
int i;
for (i = 0; i <= depth; i++)
if (strcmp(chain[i], path) == 0) return 1;
return 0;
}
static int load_sheet(const char *path, int depth, const char **chain, buf *all)
{
char *t;
chain[depth] = path;
if (g_seen) g_seen(path);
t = reaktor_asset_load(path, NULL);
size_t i = 0, from = 0, n;
@@ -1330,15 +1383,16 @@ static int load_sheet(const char *path, int depth, buf *all)
ok = buf_add(all, t + from, i - from);
from = i = q_e < n ? q_e + 1 : n;
if (!ok || depth >= IMPORT_DEPTH || e == s) continue;
if (!ok || depth >= IMPORT_DEPTH || e == s || all->len > IMPORT_BUDGET) continue;
if (!(to = import_path(path, t + s, e - s))) { ok = 0; continue; }
if (in_chain(chain, depth, to)) { free(to); continue; }
trim(t, &q_s, &q_e);
if (q_e > q_s) {
ok = buf_str(all, "@media ") && buf_add(all, t + q_s, q_e - q_s) &&
buf_str(all, " {\n") && load_sheet(to, depth + 1, all) &&
buf_str(all, " {\n") && load_sheet(to, depth + 1, chain, all) &&
buf_str(all, "}\n");
} else {
ok = load_sheet(to, depth + 1, all);
ok = load_sheet(to, depth + 1, chain, all);
}
free(to);
}
@@ -1350,12 +1404,13 @@ static int load_sheet(const char *path, int depth, buf *all)
char *reaktor_css_flatten(const char *const *paths, int count, const char *theme,
size_t token_max, reaktor_cssvars **out_vars)
{
buf all;
int i;
const char *chain[IMPORT_DEPTH + 1];
buf all;
int i;
memset(&all, 0, sizeof(all));
for (i = 0; i < count; i++)
if (!load_sheet(paths[i], 0, &all)) {
if (!load_sheet(paths[i], 0, chain, &all)) {
free(all.p);
return NULL;
}
+26 -10
View File
@@ -9,6 +9,7 @@
#include "nk_common.h"
#include "nk_sdl3_renderer.h"
#include "font.h"
#include "svg.h"
#include "theme.h"
#include "metrics.h"
@@ -63,6 +64,7 @@ struct img_slot {
char src[192];
unsigned hash;
int px, w, h;
float ink_l, ink_r;
};
static inline float
@@ -119,13 +121,11 @@ struct App {
struct round_slot round[ROUND_CACHE_MAX];
int round_count;
struct nk_font *faces[FONT_STEPS];
struct nk_font *bolds[FONT_STEPS];
char font_status[160];
struct nk_font_atlas *atlas;
int atlas_w, atlas_h, atlas_bpp;
/* Nuklear reads these until the next bake. */
unsigned *glyphs;
struct reaktor_font *faces[FONT_STEPS];
struct reaktor_font *bolds[FONT_STEPS];
char font_status[160];
struct reaktor_fontset fonts;
int atlas_w, atlas_h, atlas_bpp;
int want_cursor, cur_shown;
const char *tip;
@@ -137,6 +137,9 @@ struct App {
char frame_rate[16];
char drag_rate[16];
int first_frame_done;
unsigned frame_hash;
unsigned long frames_drawn, frames_skipped;
int must_draw;
int dragging;
int drag_mouse;
@@ -171,7 +174,7 @@ struct App {
int ime_cursor;
int ime_valid;
SDL_AtomicInt file_ready, file_done;
SDL_AtomicInt file_ready, file_busy;
char **file_list;
int file_count;
reaktor_file_dialog file_dialog;
@@ -268,6 +271,7 @@ void img_cache_clear(App *app);
void img_cache_free(App *app);
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);
@@ -328,10 +332,19 @@ App *reaktor_window_app(int id);
extern Uint64 g_hover_gap_ms;
void a11y_dump_once(App *app);
/* Set by reaktor_test_app alone, so an application that runs no test links no test code. */
extern void (*reaktor_test_hook)(App *app);
void hot_push(App *app, struct nk_rect r, int cursor, int repaint);
#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 *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 *icon_src,
const char *label);
int reaktor_css_button_flat(App *app, struct nk_context *ctx, const char *icon,
const char *name, int accent);
@@ -378,6 +391,7 @@ void reaktor_input_start(void);
int reaktor_input_page_key(App *app, SDL_Event *event);
#endif
int reaktor_app_alive(const App *a);
int reaktor_app_free(App *a);
const char *reaktor_app_ident(void);
void reaktor_timers_drop(App *app);
int reaktor_capturing(void);
@@ -436,8 +450,10 @@ 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 *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,
const char *name, reaktor_button_paint paint, void *user);
int reaktor_button_icon_as(App *app, struct nk_context *ctx, const char *sel,
const char *ionicon, const char *label);
void note_field_rect(App *app, struct nk_context *ctx, struct nk_rect bounds);
+1 -1
View File
@@ -3,7 +3,7 @@
#include "reaktor/locale.h"
unsigned *reaktor_locale_glyphs(const unsigned char *ttf);
unsigned *reaktor_locale_glyphs(void);
void reaktor_locale_start(const char *lang);
#endif
+2 -3
View File
@@ -20,9 +20,8 @@ reaktor_trn(const char *key, unsigned long n, char *buf, size_t cap)
}
unsigned *
reaktor_locale_glyphs(const unsigned char *ttf)
reaktor_locale_glyphs(void)
{
(void)ttf;
return NULL;
}
@@ -63,7 +62,7 @@ reaktor_format_pattern(char *buf, size_t cap, const struct tm *t, const char *pa
case 'd': w = snprintf(buf + n, cap - n, run > 1 ? "%02d" : "%d", t->tm_mday); break;
case 'L':
case 'M': w = run >= 3 ? snprintf(buf + n, cap - n, run == 3 ? "%.3s" : "%s",
months[t->tm_mon % 12])
months[(t->tm_mon % 12 + 12) % 12])
: snprintf(buf + n, cap - n, run > 1 ? "%02d" : "%d",
t->tm_mon + 1);
break;
+18 -9
View File
@@ -29,18 +29,27 @@ reaktor_locale_system_code(void)
}
unsigned *
reaktor_locale_glyphs(const unsigned char *ttf)
reaktor_locale_glyphs(void)
{
unsigned *cp, *ranges = NULL;
int n = reaktor_locale_codepoints(NULL, 0);
unsigned *cp, *out;
int n = reaktor_locale_codepoints(NULL, 0), i, at = 0;
if (n <= 0 || !ttf) return NULL;
cp = SDL_malloc((size_t)n * sizeof *cp);
if (cp) {
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);
ranges = reaktor_font_ranges(ttf, cp, n);
out[at++] = 0x0020;
out[at++] = 0x00FF;
for (i = 0; i < n; i++) {
if (cp[i] == out[at - 1] + 1) {
out[at - 1] = cp[i];
} else if (cp[i] > out[at - 1]) {
out[at++] = cp[i];
out[at++] = cp[i];
}
}
out[at] = 0;
}
SDL_free(cp);
return ranges;
return out;
}
+99 -83
View File
@@ -174,6 +174,8 @@ img_lookup(App *app, const char *src, int px)
slot->px = px;
slot->s.tex = NULL;
slot->w = slot->h = 0;
slot->ink_l = 0.0f;
slot->ink_r = 1.0f;
slot->s.seen = app->ctx->seq;
if (!surf) return NULL;
@@ -193,9 +195,25 @@ img_lookup(App *app, const char *src, int px)
w /= 2;
h /= 2;
}
if (sdlsurf)
if (sdlsurf) {
int x, y, lo = w, hi = -1;
reaktor_unpremultiply((unsigned char *)sdlsurf->pixels, w, h,
sdlsurf->pitch);
for (y = 0; y < h; y++) {
const Uint32 *row = (const Uint32 *)((const Uint8 *)sdlsurf->pixels + y * sdlsurf->pitch);
for (x = 0; x < w; x++)
if (row[x] >> 24 > 32) {
if (x < lo) lo = x;
if (x > hi) hi = x;
}
}
if (hi >= lo) {
slot->ink_l = (float)lo / (float)w;
slot->ink_r = (float)(hi + 1) / (float)w;
}
}
tex = sdlsurf ? SDL_CreateTextureFromSurface(app->ren, sdlsurf) : NULL;
if (sdlsurf) SDL_DestroySurface(sdlsurf);
plutovg_surface_destroy(surf);
@@ -210,23 +228,43 @@ img_lookup(App *app, const char *src, int px)
return slot;
}
struct nk_image
icon_over(App *app, const char *src, int px, float over)
static struct nk_image
slot_image(App *app, const struct img_slot *slot)
{
int raster = (int)(px * reaktor_scale() * over + 0.5f);
struct img_slot *slot = img_lookup(app, src, raster);
if (!slot) return blank_image(app);
return nk_subimage_ptr(slot->s.tex, (nk_ushort)slot->w, (nk_ushort)slot->h,
nk_rect(0.0f, 0.0f, (float)slot->w, (float)slot->h));
}
static struct img_slot *
icon_slot(App *app, const char *src, int px, float over)
{
return img_lookup(app, src, (int)(px * reaktor_scale() * over + 0.5f));
}
struct nk_image
icon_over(App *app, const char *src, int px, float over)
{
return slot_image(app, icon_slot(app, src, px, over));
}
struct nk_image
icon(App *app, const char *src, int px)
{
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;
return slot_image(app, slot);
}
struct nk_image
reaktor_image_file(App *app, const char *src, int px)
{
@@ -334,6 +372,7 @@ splice_fill(App *app, nk_size at, struct nk_rect clip)
run.clip = clip;
run.begin = run.end = run.last = ctx->memory.allocated;
nk_push_scissor(&run, clip);
if (run.end == run.begin) return at;
first = run.last;
reaktor_fill_round(app, &run, nk_rect(f.x, f.y, f.w, f.h), f.rounding, f.color);
base = (nk_byte *)ctx->memory.memory.ptr;
@@ -544,41 +583,36 @@ reaktor_fill_round(App *app, struct nk_command_buffer *cv, struct nk_rect b,
static void
center_glyphs_optically(struct nk_font *f)
center_glyphs_optically(struct reaktor_font *f)
{
const struct nk_font_glyph *ex;
const struct reaktor_glyph *ex = reaktor_font_glyph(f, 'x');
float shift;
nk_rune i;
int i;
if (!f || !f->glyphs || f->info.glyph_count == 0) return;
ex = nk_font_find_glyph(f, 'x');
if (!ex) return;
shift = f->info.height * 0.5f - (ex->y0 + ex->y1) * 0.5f;
shift = f->height * 0.5f - (ex->y0 + ex->y1) * 0.5f;
if (shift > -0.01f && shift < 0.01f) return;
for (i = 0; i < f->info.glyph_count; i++) {
for (i = 0; i < f->glyph_count; i++) {
f->glyphs[i].y0 += shift;
f->glyphs[i].y1 += shift;
}
f->baseline += shift;
}
static void
nbsp_as_space(struct nk_font *f)
nbsp_as_space(struct reaktor_font *f)
{
const struct nk_font_glyph *sp;
struct nk_font_glyph *nbsp;
const struct reaktor_glyph *sp = reaktor_font_glyph(f, 0x20);
struct reaktor_glyph *nbsp = (struct reaktor_glyph *)reaktor_font_glyph(f, 0xA0);
if (!f || !f->glyphs) return;
sp = nk_font_find_glyph(f, 0x20);
nbsp = (struct nk_font_glyph *)nk_font_find_glyph(f, 0xA0);
if (!sp || !nbsp || nbsp == sp || nbsp == f->fallback) return;
if (!sp || !nbsp) return;
*nbsp = *sp;
nbsp->codepoint = 0xA0;
}
static void
finish_face(struct nk_font *f, float height, const char *path)
finish_face(struct reaktor_font *f, float height, const char *path)
{
if (!f) return;
f->handle.height = height;
@@ -646,72 +680,57 @@ load_face(const char **name, const char *stand_in, size_t *size)
void
rebuild_font(App *app)
{
struct nk_font_atlas *atlas;
struct nk_font *font = NULL;
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;
int is_default = 0, i;
unsigned *ranges;
int n = 0, bold, ok, i;
ttf = load_face(&app->font_face, FONT_FILE, &size);
if (app->atlas && !ttf) {
SDL_Log("could not load %s; keeping the font already baked",
app->font_face);
return;
}
if (ttf) bttf = load_face(&app->font_face_bold, FONT_BOLD_FILE, &bsize);
if (!app->secondary) reaktor_text_attach_font(NULL, NULL);
if (app->atlas) {
nk_font_atlas_clear(app->atlas);
SDL_memset(app->faces, 0, sizeof(app->faces));
SDL_memset(app->bolds, 0, sizeof(app->bolds));
for (i = 0; ttf && i < FONT_STEPS; i++) {
src[n].ttf = ttf;
src[n].size = size;
src[n++].px = (float)reaktor_px(g_font_px[i]);
}
SDL_free(app->glyphs);
app->glyphs = NULL;
atlas = nk_sdl_font_stash_begin(app->ctx);
app->atlas = atlas;
if (ttf) {
struct nk_font_config cfg = nk_font_config(0);
app->glyphs = reaktor_locale_glyphs((const unsigned char *)ttf);
cfg.oversample_h = 1;
cfg.oversample_v = 1;
cfg.pixel_snap = 1;
if (app->glyphs) cfg.range = app->glyphs;
for (i = 0; i < FONT_STEPS; i++) {
app->faces[i] = nk_font_atlas_add_from_memory(
atlas, ttf, size, (float)reaktor_px(g_font_px[i]), &cfg);
if (g_font_px[i] == FONT_SIZE) font = app->faces[i];
if (!font) font = app->faces[i];
}
for (i = 0; bttf && i < FONT_STEPS; i++)
app->bolds[i] = nk_font_atlas_add_from_memory(
atlas, bttf, bsize, (float)reaktor_px(g_font_px[i]), &cfg);
if (!font)
SDL_snprintf(app->font_status, sizeof(app->font_status),
"FALLBACK (ProggyClean) - could not load %s",
app->font_face);
} else {
SDL_snprintf(app->font_status, sizeof(app->font_status),
"FALLBACK - could not load %s", app->font_face);
for (i = 0; bttf && i < FONT_STEPS; i++) {
src[n].ttf = bttf;
src[n].size = bsize;
src[n++].px = (float)reaktor_px(g_font_px[i]);
}
bold = bttf != NULL;
ranges = reaktor_locale_glyphs();
ok = n > 0 && reaktor_fontset_bake(&set, src, n, ranges ? ranges : latin);
SDL_free(ranges);
reaktor_free(ttf);
reaktor_free(bttf);
if (!font) {
font = nk_font_atlas_add_default(atlas, (float)reaktor_px(FONT_SIZE), NULL);
is_default = 1;
} else {
SDL_snprintf(app->font_status, sizeof(app->font_status),
"%s, %d sizes %d-%dpx%s", face_label(app->font_face), FONT_STEPS,
reaktor_px(g_font_px[0]), reaktor_px(g_font_px[FONT_STEPS - 1]),
app->bolds[0] ? ", bold at each" : "");
if (!ok) {
SDL_Log("could not bake %s; keeping the font already baked", app->font_face);
if (!app->fonts.count)
SDL_snprintf(app->font_status, sizeof(app->font_status),
"FALLBACK - could not load %s", app->font_face);
return;
}
nk_sdl_font_stash_end(app->ctx);
if (!app->secondary) reaktor_text_attach_font(NULL, NULL);
reaktor_fontset_free(&app->fonts);
app->fonts = set;
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];
app->bolds[i] = bold ? &app->fonts.fonts[FONT_STEPS + i] : NULL;
if (g_font_px[i] == FONT_SIZE) font = app->faces[i];
}
if (!font) font = app->faces[0];
SDL_snprintf(app->font_status, sizeof(app->font_status),
"%s, %d sizes %d-%dpx%s", face_label(app->font_face), FONT_STEPS,
reaktor_px(g_font_px[0]), reaktor_px(g_font_px[FONT_STEPS - 1]),
bold ? ", bold at each" : "");
for (i = 0; i < FONT_STEPS; i++) {
finish_face(app->faces[i], (float)g_font_px[i],
@@ -719,13 +738,10 @@ rebuild_font(App *app)
finish_face(app->bolds[i], (float)g_font_px[i],
app->secondary ? NULL : app->font_face_bold);
}
if (is_default) finish_face(font, (float)FONT_SIZE, NULL);
nk_font_atlas_cleanup(atlas);
app->atlas_w = app->atlas_h = app->atlas_bpp = 0;
if (font && font->texture.ptr) {
SDL_Texture *tex = (SDL_Texture *)font->texture.ptr;
if (font->handle.texture.ptr) {
SDL_Texture *tex = (SDL_Texture *)font->handle.texture.ptr;
float tw = 0.0f, th = 0.0f;
if (SDL_GetTextureSize(tex, &tw, &th)) {
app->atlas_w = (int)tw;
@@ -733,7 +749,7 @@ rebuild_font(App *app)
}
app->atlas_bpp = SDL_BYTESPERPIXEL(tex->format);
}
if (font) nk_style_set_font(app->ctx, is_default ? &font->handle : base_font(app));
nk_style_set_font(app->ctx, base_font(app));
}
void
+370
View File
@@ -0,0 +1,370 @@
#include <SDL3/SDL.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_ADVANCES_H
#include FT_MODULE_H
#include "font.h"
typedef struct baked {
int w, h, left, top, at;
int x, y;
} baked;
static void *
ft_alloc(FT_Memory m, long size)
{
(void)m;
return SDL_malloc((size_t)size);
}
static void
ft_free(FT_Memory m, void *p)
{
(void)m;
SDL_free(p);
}
static void *
ft_realloc(FT_Memory m, long cur, long size, void *p)
{
(void)m; (void)cur;
return SDL_realloc(p, (size_t)size);
}
FT_Library
reaktor_ft(void)
{
static struct FT_MemoryRec_ memory = { NULL, ft_alloc, ft_free, ft_realloc };
static FT_Library lib;
if (!lib) {
if (FT_New_Library(&memory, &lib)) return lib = NULL;
FT_Add_Default_Modules(lib);
}
return lib;
}
FT_Face
reaktor_ft_open(const void *ttf, size_t size)
{
FT_Library lib = reaktor_ft();
FT_Face face;
if (!lib || !ttf || size > (size_t)SDL_MAX_SINT32 ||
FT_New_Memory_Face(lib, (const FT_Byte *)ttf, (FT_Long)size, 0, &face))
return NULL;
if (!FT_IS_SCALABLE(face) || face->ascender <= face->descender) {
FT_Done_Face(face);
return NULL;
}
return face;
}
static size_t
be32(const unsigned char *p)
{
return (size_t)p[0] << 24 | (size_t)p[1] << 16 | (size_t)p[2] << 8 | p[3];
}
int
reaktor_font_valid(const void *ttf, size_t size)
{
const unsigned char *p = (const unsigned char *)ttf;
FT_Face face;
size_t at = 0, n, i;
if (!p || size < 16) return 0;
if (SDL_memcmp(p, "ttcf", 4) == 0) {
at = be32(p + 12);
if (at > size - 12) return 0;
}
n = (size_t)p[at + 4] << 8 | p[at + 5];
if (!n || n > (size - at - 12) / 16) return 0;
for (i = 0; i < n; i++) {
const unsigned char *r = p + at + 12 + 16 * i;
size_t start = be32(r + 8), len = be32(r + 12);
if (start > size || len > size - start) return 0;
}
if (!(face = reaktor_ft_open(ttf, size))) return 0;
FT_Done_Face(face);
return 1;
}
static float
unit_scale(FT_Face face, float px)
{
return px / (float)(face->ascender - face->descender);
}
void
reaktor_ft_size(FT_Face face, float px)
{
FT_Set_Char_Size(face, 0, (FT_F26Dot6)(face->units_per_EM * unit_scale(face, px) * 64.0f + 0.5f),
72, 72);
}
const struct reaktor_glyph *
reaktor_font_glyph(const struct reaktor_font *f, nk_rune cp)
{
int lo = 0, hi = f->glyph_count - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (f->glyphs[mid].codepoint == cp) return &f->glyphs[mid];
if (f->glyphs[mid].codepoint < cp) lo = mid + 1;
else hi = mid - 1;
}
return NULL;
}
static const struct reaktor_glyph *
glyph_or_fallback(const struct reaktor_font *f, nk_rune cp)
{
const struct reaktor_glyph *g = reaktor_font_glyph(f, cp);
return g ? g : f->fallback;
}
static float
text_width(nk_handle handle, float height, const char *text, int len)
{
const struct reaktor_font *font = (const struct reaktor_font *)handle.ptr;
float scale, width = 0.0f;
nk_rune cp;
int at, n;
if (!font || !text || len <= 0 || !font->fallback) return 0.0f;
scale = height / font->height;
for (at = 0; at < len && (n = nk_utf_decode(text + at, &cp, len - at)) > 0; at += n) {
if (cp == NK_UTF_INVALID) break;
width += glyph_or_fallback(font, cp)->xadvance * scale;
}
return width;
}
static void
query(nk_handle handle, float height, struct nk_user_font_glyph *out, nk_rune cp,
nk_rune next)
{
const struct reaktor_font *font = (const struct reaktor_font *)handle.ptr;
const struct reaktor_glyph *g;
float scale;
(void)next;
if (!font || !out || !font->fallback) return;
scale = height / font->height;
g = glyph_or_fallback(font, cp);
out->width = (g->x1 - g->x0) * scale;
out->height = (g->y1 - g->y0) * scale;
out->offset = nk_vec2(g->x0 * scale, g->y0 * scale);
out->xadvance = g->xadvance * scale;
out->uv[0] = nk_vec2(g->u0, g->v0);
out->uv[1] = nk_vec2(g->u1, g->v1);
}
static int SDLCALL
by_rune(const void *a, const void *b)
{
nk_rune x = *(const nk_rune *)a, y = *(const nk_rune *)b;
return x < y ? -1 : x > y;
}
static nk_rune *
codepoints(const nk_rune *ranges, int *count)
{
nk_rune *cp;
int n = 0, i, k;
for (i = 0; ranges[i] && ranges[i + 1]; i += 2)
if (ranges[i + 1] >= ranges[i]) n += (int)(ranges[i + 1] - ranges[i]) + 1;
if (!(cp = SDL_malloc((size_t)(n ? n : 1) * sizeof *cp))) return NULL;
for (i = 0, n = 0; ranges[i] && ranges[i + 1]; i += 2)
for (k = (int)ranges[i]; k <= (int)ranges[i + 1]; k++) cp[n++] = (nk_rune)k;
SDL_qsort(cp, (size_t)n, sizeof *cp, by_rune);
for (i = k = 0; i < n; i++)
if (!k || cp[i] != cp[k - 1]) cp[k++] = cp[i];
*count = k;
return cp;
}
static int SDLCALL
by_height(void *all, const void *a, const void *b)
{
const baked *x = (const baked *)all + *(const int *)a;
const baked *y = (const baked *)all + *(const int *)b;
if (x->h != y->h) return y->h - x->h;
if (x->w != y->w) return y->w - x->w;
return *(const int *)a - *(const int *)b;
}
static int
pack(baked *b, int n, int *w, int *h)
{
long area = 0;
int *order, i, x = 1, y = 1, row = 0;
for (i = 0; i < n; i++) area += (long)(b[i].w + 1) * (b[i].h + 1);
for (*w = 256; *w < 4096 && (long)*w * *w < area + area / 3; *w *= 2) {}
if (!(order = SDL_malloc((size_t)(n ? n : 1) * sizeof *order))) return 0;
for (i = 0; i < n; i++) order[i] = i;
SDL_qsort_r(order, (size_t)n, sizeof *order, by_height, b);
for (i = 0; i < n; i++) {
baked *g = &b[order[i]];
if (!g->w || !g->h) continue;
if (g->w + 2 > *w) {
SDL_free(order);
return 0;
}
if (x + g->w + 1 > *w) {
x = 1;
y += row;
row = 0;
}
g->x = x;
g->y = y;
x += g->w + 1;
if (g->h + 1 > row) row = g->h + 1;
}
SDL_free(order);
*h = y + row + 1;
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;
baked *b = NULL;
unsigned char *bits = NULL;
int ncp = 0, nb = 0, cap_b = 0, cap_bits = 0, used = 0, i, k, ok = 0;
SDL_zerop(set);
if (!(cp = codepoints(ranges, &ncp))) return 0;
if (!(set->fonts = SDL_calloc((size_t)(n ? n : 1), sizeof *set->fonts)) ||
!(set->glyphs = SDL_calloc((size_t)(n * ncp ? n * ncp : 1), sizeof *set->glyphs)))
goto done;
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;
f->glyphs = set->glyphs + nb;
f->height = src[i].px;
if (!face) continue;
scale = unit_scale(face, src[i].px);
f->ascent = (float)face->ascender * scale;
f->baseline = f->ascent + 0.5f;
reaktor_ft_size(face, src[i].px);
for (k = 0; k < ncp; k++) {
FT_UInt id = FT_Get_Char_Index(face, cp[k]);
FT_Fixed adv = 0;
FT_Bitmap *bm;
struct reaktor_glyph *g;
baked *d;
int y;
if (!id || FT_Load_Glyph(face, id, REAKTOR_FT_LOAD) ||
FT_Get_Advance(face, id, FT_LOAD_NO_SCALE, &adv))
continue;
bm = &face->glyph->bitmap;
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;
d->left = face->glyph->bitmap_left;
d->top = face->glyph->bitmap_top;
d->at = used;
d->x = d->y = 0;
for (y = 0; y < d->h; y++)
SDL_memcpy(bits + used + y * d->w, bm->buffer + y * bm->pitch, (size_t)d->w);
used += d->w * d->h;
g = &set->glyphs[nb++];
g->codepoint = cp[k];
g->xadvance = (float)(int)((float)adv * scale + 0.5f);
g->x0 = (float)d->left;
g->x1 = (float)(d->left + d->w);
g->y0 = (float)-d->top + f->ascent + 0.5f;
g->y1 = g->y0 + (float)d->h;
f->glyph_count++;
}
FT_Done_Face(face);
f->fallback = reaktor_font_glyph(f, '?');
if (!f->fallback && f->glyph_count) f->fallback = &f->glyphs[0];
}
if (!pack(b, nb, &set->w, &set->h) ||
!(set->pixels = SDL_calloc((size_t)set->w * (size_t)set->h, 1)))
goto done;
for (i = 0; i < nb; i++) {
struct reaktor_glyph *g = &set->glyphs[i];
int y;
for (y = 0; y < b[i].h; y++)
SDL_memcpy(set->pixels + (size_t)(b[i].y + y) * set->w + b[i].x,
bits + b[i].at + y * b[i].w, (size_t)b[i].w);
g->u0 = (float)b[i].x / (float)set->w;
g->v0 = (float)b[i].y / (float)set->h;
g->u1 = (float)(b[i].x + b[i].w) / (float)set->w;
g->v1 = (float)(b[i].y + b[i].h) / (float)set->h;
}
ok = 1;
done:
SDL_free(cp);
SDL_free(b);
SDL_free(bits);
if (!ok) reaktor_fontset_free(set);
return ok;
}
void
reaktor_fontset_bind(struct reaktor_fontset *set, nk_handle texture)
{
int i;
for (i = 0; i < set->count; i++) {
struct reaktor_font *f = &set->fonts[i];
f->handle.userdata.ptr = f;
f->handle.height = f->height;
f->handle.width = text_width;
f->handle.query = query;
f->handle.texture = texture;
}
}
void
reaktor_fontset_free(struct reaktor_fontset *set)
{
SDL_free(set->fonts);
SDL_free(set->glyphs);
SDL_free(set->pixels);
SDL_zerop(set);
}
+52
View File
@@ -0,0 +1,52 @@
#ifndef REAKTOR_FONT_H
#define REAKTOR_FONT_H
#include <ft2build.h>
#include FT_FREETYPE_H
#include "reaktor/nuklear.h"
#define REAKTOR_FT_LOAD (FT_LOAD_RENDER | FT_LOAD_TARGET_LIGHT | FT_LOAD_NO_BITMAP)
struct reaktor_glyph {
nk_rune codepoint;
float xadvance;
float x0, y0, x1, y1;
float u0, v0, u1, v1;
};
struct reaktor_font {
struct nk_user_font handle;
float height, ascent, baseline;
struct reaktor_glyph *glyphs;
int glyph_count;
const struct reaktor_glyph *fallback;
};
struct reaktor_face_src {
const void *ttf;
size_t size;
float px;
};
struct reaktor_fontset {
struct reaktor_font *fonts;
int count;
struct reaktor_glyph *glyphs;
unsigned char *pixels;
int w, h;
};
int reaktor_font_valid(const void *ttf, size_t size);
FT_Library reaktor_ft(void);
FT_Face reaktor_ft_open(const void *ttf, size_t size);
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);
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);
#endif
+8
View File
@@ -0,0 +1,8 @@
FT_USE_MODULE( FT_Module_Class, autofit_module_class )
FT_USE_MODULE( FT_Driver_ClassRec, tt_driver_class )
FT_USE_MODULE( FT_Driver_ClassRec, cff_driver_class )
FT_USE_MODULE( FT_Module_Class, psaux_module_class )
FT_USE_MODULE( FT_Module_Class, psnames_module_class )
FT_USE_MODULE( FT_Module_Class, pshinter_module_class )
FT_USE_MODULE( FT_Module_Class, sfnt_module_class )
FT_USE_MODULE( FT_Renderer_Class, ft_smooth_renderer_class )
+27
View File
@@ -0,0 +1,27 @@
#ifndef REAKTOR_FTOPTION_H
#define REAKTOR_FTOPTION_H
#include <freetype/config/ftoption.h>
/* FreeType's options as shipped, less what Reaktor never reads: an
environment override, compressed and Mac fonts, SVG and color glyphs,
bitmap strikes, variations and the TrueType bytecode hinter. */
#undef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES
#undef FT_CONFIG_OPTION_USE_LZW
#undef FT_CONFIG_OPTION_USE_ZLIB
#undef FT_CONFIG_OPTION_MAC_FONTS
#undef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK
#undef FT_CONFIG_OPTION_INCREMENTAL
#undef FT_CONFIG_OPTION_SVG
#undef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
#undef TT_CONFIG_OPTION_COLOR_LAYERS
#undef TT_SUPPORT_COLRV1
#undef TT_CONFIG_OPTION_BDF
#undef TT_CONFIG_OPTION_GX_VAR_SUPPORT
#undef TT_CONFIG_OPTION_VARC
#undef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
#undef TT_CONFIG_OPTION_SUBPIXEL_HINTING
#undef TT_USE_BYTECODE_INTERPRETER
#undef TT_SUPPORT_SUBPIXEL_HINTING_MINIMAL
#endif
-4
View File
@@ -3,8 +3,4 @@
#include "reaktor/nuklear.h"
int reaktor_font_valid(const void *ttf, size_t size);
nk_rune *reaktor_font_ranges(const unsigned char *ttf, const unsigned *cp,
int n);
#endif
-59
View File
@@ -5,62 +5,3 @@
#define NK_SDL3_RENDERER_IMPLEMENTATION
#include "nk_sdl3_renderer.h"
static size_t
be32(const unsigned char *p)
{
return (size_t)p[0] << 24 | (size_t)p[1] << 16 | (size_t)p[2] << 8 | p[3];
}
int
reaktor_font_valid(const void *ttf, size_t size)
{
const unsigned char *p = (const unsigned char *)ttf;
stbtt_fontinfo info;
size_t at, n, i;
int off;
if (!p || size < 16 || size > (size_t)SDL_MAX_SINT32) return 0;
off = stbtt_GetFontOffsetForIndex(p, 0);
if (off < 0 || (size_t)off > size - 12) return 0;
at = (size_t)off;
n = (size_t)p[at + 4] << 8 | p[at + 5];
if (!n || n > (size - at - 12) / 16) return 0;
for (i = 0; i < n; i++) {
const unsigned char *r = p + at + 12 + 16 * i;
size_t start = be32(r + 8), len = be32(r + 12);
if (start > size || len > size - start) return 0;
}
return stbtt_InitFont(&info, p, off);
}
nk_rune *
reaktor_font_ranges(const unsigned char *ttf, const unsigned *cp, int n)
{
stbtt_fontinfo info;
nk_rune *out;
int i, at = 0, run = 0;
if (!ttf || n < 0 ||
!stbtt_InitFont(&info, ttf, stbtt_GetFontOffsetForIndex(ttf, 0)))
return NULL;
out = SDL_malloc(((size_t)n * 2 + 3) * sizeof *out);
if (!out) return NULL;
out[at++] = 0x0020;
out[at++] = 0x00FF;
for (i = 0; i < n; i++) {
if (!stbtt_FindGlyphIndex(&info, (int)cp[i])) {
run = 0;
} else if (run && cp[i] == out[at - 1] + 1) {
out[at - 1] = cp[i];
} else {
out[at++] = cp[i];
out[at++] = cp[i];
run = 1;
}
}
out[at] = 0;
return out;
}
+44 -13
View File
@@ -38,6 +38,8 @@ NK_API struct nk_context* nk_sdl_init(SDL_Window *win, SDL_Renderer *renderer,
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. */
NK_API void nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA, enum nk_anti_aliasing line_AA);
@@ -179,13 +181,15 @@ nk_sdl_device_upload_atlas(struct nk_context* ctx, const void *image, int width,
if (sdl->ogl.font_tex) {
SDL_UpdateTexture(sdl->ogl.font_tex, NULL, image, width);
} else {
size_t n = (size_t)width * (size_t)height;
void *rgba = SDL_malloc(n * 4);
size_t n = (size_t)width * (size_t)height, i;
Uint32 *rgba = (Uint32 *)SDL_malloc(n * 4);
SDL_Log("nk_sdl: indexed font atlas unavailable (%s); using RGBA32",
SDL_GetError());
if (rgba) {
nk_font_bake_convert(rgba, width, height, image);
/* REAKTOR: Nuklear's converter is part of its font baking. */
for (i = 0; i < n; i++)
rgba[i] = (Uint32)((const Uint8 *)image)[i] << 24 | 0x00FFFFFFu;
sdl->ogl.font_tex = SDL_CreateTexture(sdl->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, width, height);
if (sdl->ogl.font_tex)
SDL_UpdateTexture(sdl->ogl.font_tex, NULL, rgba, 4 * width);
@@ -266,6 +270,21 @@ nk_sdl_geometry(SDL_Renderer *ren, SDL_Texture *tex, const void *vertices,
vs, v->uv, vs, n, ix, count, (int)sizeof(*ix));
}
/* REAKTOR: opaque triangles unblended on software. */
NK_INTERN void
nk_sdl_geometry_sw(SDL_Renderer *ren, SDL_Texture *tex, const void *vertices,
int n, const nk_draw_index *ix, int count)
{
const struct nk_sdl_vertex *v = (const struct nk_sdl_vertex *)vertices;
int k, opaque = !tex;
for (k = 0; opaque && k < count; k++)
if (v[ix[k]].col[3] < 1.0f) opaque = 0;
if (opaque) SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_NONE);
nk_sdl_geometry(ren, tex, vertices, n, ix, count);
if (opaque) SDL_SetRenderDrawBlendMode(ren, SDL_BLENDMODE_BLEND);
}
/* REAKTOR: a rectangle among the triangles, on whole device pixels. */
struct nk_sdl_rect {
SDL_FRect d, src;
@@ -496,15 +515,16 @@ nk_sdl_render_ex(struct nk_context* ctx, enum nk_anti_aliasing shape_AA,
}
/* What came before it in the list is drawn before it. */
if (k > from)
nk_sdl_geometry(sdl->renderer, tex, vertices, n,
offset + from, (int)(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;
}
if (cmd->elem_count > from)
nk_sdl_geometry(sdl->renderer, tex, vertices, n,
offset + from, (int)(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;
}
@@ -652,8 +672,22 @@ nk_sdl_font_stash_end(struct nk_context* ctx)
/* REAKTOR: alpha8. */
image = nk_font_atlas_bake(&sdl->atlas, &w, &h, NK_FONT_ATLAS_ALPHA8);
NK_ASSERT(image);
nk_sdl_device_upload_atlas(&sdl->ctx, image, w, h);
nk_font_atlas_end(&sdl->atlas, nk_handle_ptr(sdl->ogl.font_tex), &sdl->ogl.tex_null);
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
nk_sdl_font_upload(struct nk_context* ctx, const void *image, int width, int height)
{
struct nk_sdl* sdl;
NK_ASSERT(ctx);
sdl = (struct nk_sdl*)ctx->userdata.ptr;
NK_ASSERT(sdl);
nk_sdl_device_upload_atlas(&sdl->ctx, image, width, height);
/* REAKTOR: see white_tex. */
if (!sdl->ogl.white_tex) {
Uint32 px = 0xFFFFFFFFu;
@@ -669,11 +703,8 @@ nk_sdl_font_stash_end(struct nk_context* ctx)
sdl->ogl.tex_null.texture = nk_handle_ptr(sdl->ogl.white_tex);
sdl->ogl.tex_null.uv = nk_vec2(0.5f, 0.5f);
}
if (sdl->atlas.default_font) {
nk_style_set_font(&sdl->ctx, &sdl->atlas.default_font->handle);
}
return nk_handle_ptr(sdl->ogl.font_tex);
}
#endif
/* REAKTOR: Nuklear counts an up for a key that is not down as a press. */
NK_INTERN void
+4
View File
@@ -0,0 +1,4 @@
/* Forced into SDL's sources by CMakeLists.txt, ahead of its own
src/dynapi/SDL_dynapi.h, which takes no switch from the command line. */
#define SDL_dynapi_h_
#define SDL_DYNAMIC_API 0
+49 -72
View File
@@ -4,10 +4,10 @@
#include "nk_common.h"
#include "nk_sdl3_renderer.h"
#include "font.h"
#include "text.h"
#include "util.h"
#include "../../external/nuklear/src/stb_truetype.h"
#include "kb_text_shape.h"
#include "mojibake.h"
@@ -29,7 +29,8 @@ typedef struct text_font {
char name[64];
unsigned char *data;
int state;
stbtt_fontinfo info;
FT_Face face;
float px;
kbts_font kb;
float unit;
Uint8 *drawn;
@@ -37,11 +38,9 @@ typedef struct text_font {
} text_font;
typedef struct text_face {
struct nk_font *font;
int file;
int baseline_known;
float baseline;
nk_text_width_f atlas_width;
struct reaktor_font *font;
int file;
nk_text_width_f atlas_width;
} text_face;
typedef struct shaped {
@@ -103,7 +102,6 @@ static text_font g_font[FONTS_MAX];
static int g_fonts;
static int g_fallback[FONTS_MAX];
static int g_fallbacks;
static struct nk_allocator g_raster;
static text_face g_face[FACES_MAX];
static int g_faces;
@@ -168,14 +166,11 @@ font_add(const char *path)
static void
font_name(text_font *f)
{
const char *s, *base, *dot;
int len = 0, i, at = 0;
const char *s = f->face->family_name, *base, *dot;
int at = 0;
s = stbtt_GetFontNameString(&f->info, &len, STBTT_PLATFORM_ID_MICROSOFT,
STBTT_MS_EID_UNICODE_BMP, STBTT_MS_LANG_ENGLISH, 1);
for (i = 0; s && i + 1 < len && at + 1 < (int)sizeof f->name; i += 2)
if (s[i] == 0 && s[i + 1] >= 0x20 && s[i + 1] < 0x7F)
f->name[at++] = s[i + 1];
for (; s && *s && at + 1 < (int)sizeof f->name; s++)
if (*s >= 0x20 && *s < 0x7F) f->name[at++] = *s;
f->name[at] = 0;
if (at > 0) return;
base = reaktor_path_leaf(f->path);
@@ -189,26 +184,22 @@ font_open(int i)
{
text_font *f = &g_font[i];
size_t size = 0;
int at;
if (f->state) return f->state > 0;
f->state = -1;
f->data = (unsigned char *)reaktor_asset_load(f->path, &size);
if (f->data && reaktor_font_valid(f->data, size)) {
at = stbtt_GetFontOffsetForIndex(f->data, 0);
if (stbtt_InitFont(&f->info, f->data, at)) {
/* Nuklear's stb_truetype allocates through userdata. */
if (!g_raster.alloc) g_raster = nk_sdl_allocator();
f->info.userdata = &g_raster;
f->kb = kbts_FontFromMemory(f->data, (int)size, 0, NULL, NULL);
if (kbts_FontIsValid(&f->kb)) {
f->unit = stbtt_ScaleForPixelHeight(&f->info, 1.0f);
f->state = 1;
font_name(f);
return 1;
}
kbts_FreeFont(&f->kb);
if (f->data && reaktor_font_valid(f->data, size) &&
(f->face = reaktor_ft_open(f->data, size))) {
f->kb = kbts_FontFromMemory(f->data, (int)size, 0, NULL, NULL);
if (kbts_FontIsValid(&f->kb)) {
f->unit = 1.0f / (float)(f->face->ascender - f->face->descender);
f->state = 1;
font_name(f);
return 1;
}
kbts_FreeFont(&f->kb);
FT_Done_Face(f->face);
f->face = NULL;
}
SDL_Log("text: could not open the font %s", f->path);
reaktor_free(f->data);
@@ -226,7 +217,7 @@ reaktor_text_add_fallback(const char *path)
}
static int
face_of(const struct nk_font *font)
face_of(const struct reaktor_font *font)
{
static int last;
int i;
@@ -238,14 +229,13 @@ face_of(const struct nk_font *font)
}
static int
atlas_draws(const struct nk_font *font, const char *s, int len)
atlas_draws(const struct reaktor_font *font, const char *s, int len)
{
int i = 0;
while (i < len) {
const struct nk_font_glyph *g;
nk_rune cp;
int n;
nk_rune cp;
int n;
if (!((unsigned char)s[i] & 0x80)) {
i++;
@@ -253,33 +243,12 @@ atlas_draws(const struct nk_font *font, const char *s, int len)
}
n = nk_utf_decode(s + i, &cp, len - i);
if (n <= 0) return 1;
g = nk_font_find_glyph(font, cp);
if (g == font->fallback && cp != font->fallback_codepoint) return 0;
if (!reaktor_font_glyph(font, cp)) return 0;
i += n;
}
return 1;
}
static float
baseline(text_face *f)
{
const struct nk_font_glyph *x;
text_font *t = &g_font[f->file];
float scale;
int x0, y0, x1, y1;
if (f->baseline_known) return f->baseline;
f->baseline_known = 1;
f->baseline = f->font->info.ascent + 0.5f;
x = nk_font_find_glyph(f->font, 'x');
if (x && x != f->font->fallback && font_open(f->file)) {
scale = stbtt_ScaleForPixelHeight(&t->info, f->font->info.height);
stbtt_GetCodepointBitmapBox(&t->info, 'x', scale, scale, &x0, &y0, &x1, &y1);
f->baseline = x->y1 - (float)y1;
}
return f->baseline;
}
static int
decode(const char *s, int len)
{
@@ -651,16 +620,17 @@ pack(int w, int h, int *x, int *y)
}
static int
upload(int page, int x, int y, int w, int h, text_font *f, int id, float scale)
upload(int page, int x, int y, const FT_Bitmap *bm)
{
SDL_Rect r;
void *p;
int bw = w + 2, bh = h + 2, i;
int w = (int)bm->width, h = (int)bm->rows, bw = w + 2, bh = h + 2, i;
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));
stbtt_MakeGlyphBitmap(&f->info, g_bitmap + bw + 1, w, h, bw, scale, scale, id);
for (i = 0; i < h; i++)
SDL_memcpy(g_bitmap + (i + 1) * bw + 1, bm->buffer + i * bm->pitch, (size_t)w);
r.x = x - 1;
r.y = y - 1;
r.w = bw;
@@ -703,8 +673,8 @@ glyph_get(int font, int id, int px)
{
text_font *f = &g_font[font];
glyph_slot *s;
FT_Bitmap *bm;
Uint32 key;
float scale;
int x0, y0, x1, y1, x = 0, y = 0, page = 0;
if (px < 1) px = 1;
@@ -721,15 +691,23 @@ glyph_get(int font, int id, int px)
s = slot_at(g_slot, g_slot_cap, key);
}
scale = stbtt_ScaleForPixelHeight(&f->info, (float)px);
stbtt_GetGlyphBitmapBox(&f->info, id, scale, scale, &x0, &y0, &x1, &y1);
if (f->px != (float)px) {
reaktor_ft_size(f->face, (float)px);
f->px = (float)px;
}
if (FT_Load_Glyph(f->face, (FT_UInt)id, REAKTOR_FT_LOAD)) return NULL;
bm = &f->face->glyph->bitmap;
x0 = f->face->glyph->bitmap_left;
y0 = -f->face->glyph->bitmap_top;
x1 = x0 + (int)bm->width;
y1 = y0 + (int)bm->rows;
if (x1 > x0 && y1 > y0) {
page = pack(x1 - x0, y1 - y0, &x, &y);
if (page < 0) {
g_full = 1;
return NULL;
}
if (!upload(page, x, y, x1 - x0, y1 - y0, f, id, scale)) return NULL;
if (!upload(page, x, y, bm)) return NULL;
} else {
x1 = x0;
y1 = y0;
@@ -768,8 +746,8 @@ mark_drawn(int font, int id)
static float
measure(nk_handle handle, float height, const char *s, int len)
{
const struct nk_font *font = (const struct nk_font *)handle.ptr;
int face = face_of(font), e = -1;
const struct reaktor_font *font = (const struct reaktor_font *)handle.ptr;
int face = face_of(font), e = -1;
if (face < 0) return 0.0f;
if (!atlas_draws(font, s, len)) {
@@ -781,7 +759,7 @@ measure(nk_handle handle, float height, const char *s, int len)
}
void
reaktor_text_attach_font(struct nk_font *font, const char *path)
reaktor_text_attach_font(struct reaktor_font *font, const char *path)
{
text_face *f;
int file;
@@ -796,7 +774,6 @@ reaktor_text_attach_font(struct nk_font *font, const char *path)
f = &g_face[g_faces++];
f->font = font;
f->file = file;
f->baseline_known = 0;
f->atlas_width = font->handle.width;
font->handle.width = measure;
}
@@ -819,9 +796,9 @@ draw(void *canvas, short x, short y, unsigned short w, unsigned short h,
d = &g_draw[data.id];
f = &g_face[d->face];
if ((e = shape(f->file, d->text, d->len)) < 0) return;
px = f->font->info.height * d->height / f->font->handle.height;
px = f->font->height * d->height / f->font->handle.height;
k = d->height / px;
top = baseline(f) * px / f->font->info.height;
top = f->font->baseline * px / f->font->height;
fg = d->fg;
fg.a = (nk_byte)((float)fg.a * list->config.global_alpha);
for (i = 0; i < g_entry[e].glyphs; i++) {
@@ -863,7 +840,7 @@ reaktor_text_prepare(struct nk_context *ctx, struct SDL_Renderer *renderer)
nk_foreach(cmd, ctx) {
struct nk_command_text *t = (struct nk_command_text *)cmd;
struct nk_command_custom *c = (struct nk_command_custom *)cmd;
const struct nk_font *font;
const struct reaktor_font *font;
text_draw d;
void *p;
short x, y;
@@ -871,7 +848,7 @@ reaktor_text_prepare(struct nk_context *ctx, struct SDL_Renderer *renderer)
int face;
if (cmd->type != NK_COMMAND_TEXT || t->font->width != measure) continue;
font = (const struct nk_font *)t->font->userdata.ptr;
font = (const struct reaktor_font *)t->font->userdata.ptr;
face = face_of(font);
if (face < 0 || atlas_draws(font, t->string, t->length) ||
!font_open(g_face[face].file))
+2 -2
View File
@@ -4,11 +4,11 @@
#include "reaktor/text.h"
struct nk_context;
struct nk_font;
struct reaktor_font;
struct SDL_Renderer;
void reaktor_text_add_fallback(const char *path);
void reaktor_text_attach_font(struct nk_font *font, 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);
#endif
+1 -1
View File
@@ -3,7 +3,7 @@
void reaktor_text_add_fallback(const char *path) { (void)path; }
void
reaktor_text_attach_font(struct nk_font *font, const char *path)
reaktor_text_attach_font(struct reaktor_font *font, const char *path)
{
(void)font; (void)path;
}
+21 -29
View File
@@ -9,33 +9,18 @@ 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");
const struct nk_user_font *f = decl_style_font(sel);
reaktor_style st;
float pad_x, pad_y, border, edge, text = 0.0f, w;
float least = box->w, w;
char src[192];
box->w = box->h = 0.0f;
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);
reaktor_style_get(sel, &st);
pad_x = st.matched ? st.pad_x : nb->padding.x;
pad_y = st.matched ? st.pad_y : nb->padding.y;
border = st.matched ? st.border : nb->border;
edge = border + (st.matched ? st.rounding : nb->rounding);
if (s->label)
text = reaktor_text_w(f, s->label);
w = text + 2.0f * (pad_x + (st.matched ? border : edge));
if (s->icon && s->label) {
float room = SDL_max(box->h * 0.5f - edge, 0.0f);
float icon = box->h - 2.0f * SDL_min(pad_y, room)
- 2.0f * nb->image_padding.x;
w = SDL_max(w, text + 2.0f * (3.0f * pad_x + nb->image_padding.x + icon));
} else if (s->icon) {
if (s->icon && !s->label)
w = box->h;
}
box->w = SDL_ceilf(w);
else
w = css_button_content_w(g_frame_app, g_frame_ctx, sel, decl_style_font(sel),
reaktor_button_src(src, s->icon), s->label);
box->w = SDL_ceilf(SDL_max(w, least));
}
static float
@@ -93,7 +78,11 @@ reaktor_button(const reaktor_button_spec *s)
}
fitted = reaktor_fit_label(g_frame_app, g_frame_ctx, r);
reaktor_note_mute(g_frame_app, 1);
if (s->flat && s->icon && !s->label) {
if (s->paint) {
hit = reaktor_css_button_custom(g_frame_app, g_frame_ctx, sel,
s->name ? s->name : s->label, s->paint,
s->paint_user);
} else if (s->flat && s->icon && !s->label) {
hit = reaktor_css_button_flat(g_frame_app, g_frame_ctx, s->icon, s->name,
s->accent);
} else if (s->icon && !s->label) {
@@ -102,12 +91,10 @@ reaktor_button(const reaktor_button_spec *s)
hit = reaktor_css_button_image(g_frame_app, g_frame_ctx, sel,
reaktor_ionicon(g_frame_app, s->icon, (int)px),
px, s->name);
} else if (s->icon)
hit = reaktor_button_icon_as(g_frame_app, g_frame_ctx, sel, s->icon, s->label);
else if (s->accent && !s->disabled)
hit = reaktor_button_accent_as(g_frame_app, g_frame_ctx, sel, s->label);
} else if (s->accent && !s->disabled)
hit = reaktor_button_accent_as(g_frame_app, g_frame_ctx, sel, s->icon, s->label);
else
hit = reaktor_button_label_as(g_frame_app, g_frame_ctx, sel, s->label);
hit = reaktor_button_icon_as(g_frame_app, g_frame_ctx, sel, s->icon, s->label);
reaktor_note_mute(g_frame_app, 0);
reaktor_unfit_label(g_frame_ctx, fitted);
if (s->disabled) {
@@ -363,7 +350,10 @@ field_room(const reaktor_field_spec *s, int *cap)
int room = NK_MAX(need, *s->heap_cap * 2);
char *more = (char *)SDL_realloc(*s->heap, (size_t)room);
if (!more) return *s->heap;
if (!more) {
*cap = *s->heap_cap;
return *s->heap;
}
if (!*s->heap) more[0] = '\0';
*s->heap = more;
*s->heap_cap = room;
@@ -477,6 +467,8 @@ reaktor_link(const reaktor_link_spec *s)
if (reaktor_focus_activated(g_frame_app, id)) hit = 1;
if (hit && s->on_press.fn) s->on_press.fn(s->on_press.user);
else if (hit && s->url && !reaktor_url_allowed(s->url, s->schemes))
SDL_Log("not opening %s: its scheme is not one this link allows", s->url);
else if (hit && s->url && !SDL_OpenURL(s->url))
SDL_Log("could not open %s: %s", s->url, SDL_GetError());
return hit;
+60 -2
View File
@@ -22,10 +22,64 @@ 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 {
unsigned id;
char mark[MARK_LEN];
} decl_mark;
static decl_mark *g_marks;
static int g_mark_n, g_mark_cap;
static void
mark_note(unsigned id, const char *mark)
{
static int told;
if (g_frame_app->secondary) return;
if (g_mark_n == g_mark_cap) {
int cap = g_mark_cap ? 2 * g_mark_cap : 32;
decl_mark *m = (decl_mark *)SDL_realloc(g_marks, (size_t)cap * sizeof *m);
if (!m) return;
g_marks = m;
g_mark_cap = cap;
}
if (SDL_strlen(mark) >= MARK_LEN && !told++)
SDL_Log("reaktor: mark \"%s\" is cut to %d characters", mark, MARK_LEN - 1);
g_marks[g_mark_n].id = id;
SDL_strlcpy(g_marks[g_mark_n].mark, mark, sizeof g_marks[g_mark_n].mark);
g_mark_n++;
}
const char *
reaktor_mark_at(int i, unsigned *id)
{
if (i < 0 || i >= g_mark_n) return NULL;
*id = g_marks[i].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)
{
int i;
for (i = 0; i < g_mark_n; i++)
if ((!id || g_marks[i].id == id) && SDL_strcmp(g_marks[i].mark, mark) == 0) return 1;
return 0;
}
void
reaktor_frame_begin(App *app, struct nk_context *ctx, struct nk_rect area)
{
g_frame_app = app;
if (!app->secondary) g_mark_n = 0;
g_frame_ctx = ctx;
g_depth = 0;
g_space = 0;
@@ -118,6 +172,7 @@ reaktor_box_open(unsigned char dir, const reaktor_box *b)
id = reaktor_note_push(g_frame_app, REAKTOR_A11Y_GROUP, box.name, NULL, 0u,
nk_rect(0, 0, 0, 0));
if (box.mark) mark_note(id, box.mark);
reaktor_layout_open(&g_frame_app->lay, id, &box);
if (g_depth < REAKTOR_LAY_DEPTH) g_boxid[g_depth + 1] = id;
@@ -195,6 +250,7 @@ decl_emit(unsigned id, const char *keys, const reaktor_box *b)
reaktor_layout_leaf(&g_frame_app->lay, id, b);
if (keys) reaktor_note_keys(g_frame_app, id, keys);
if (b && b->mark) mark_note(id, b->mark);
if (!g_space) { g_frame_unsettled++; return 0; }
if (!reaktor_layout_rect(&g_frame_app->lay, id, &r)) { g_frame_unsettled++; return 0; }
@@ -379,8 +435,10 @@ decl_tip_at(const char *tip, struct nk_rect r, int cursor)
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))
g_frame_app->tip = tip;
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
+2
View File
@@ -13,6 +13,8 @@ void reaktor_frame_begin(App *app, struct nk_context *ctx, struct nk_rect area);
void reaktor_frame_end(void);
int reaktor_frame_settled(const App *app);
int reaktor_mark_has(unsigned id, const char *mark);
const char *reaktor_mark_at(int i, unsigned *id);
extern App *g_frame_app;
extern struct nk_context *g_frame_ctx;
+20 -15
View File
@@ -51,14 +51,25 @@ behave_of(const reaktor_box *b)
return f;
}
static lay_id
parent_of(const reaktor_layout *l)
static void
attach(reaktor_layout *l, lay_id it)
{
int d = l->depth;
int d = l->depth > REAKTOR_LAY_DEPTH ? REAKTOR_LAY_DEPTH : l->depth;
if (d <= 0) return LAY_INVALID_ID;
if (d > REAKTOR_LAY_DEPTH) d = REAKTOR_LAY_DEPTH;
return l->stack[d - 1];
if (d <= 0 || l->stack[d - 1] == LAY_INVALID_ID) return;
if (l->last[d - 1] == LAY_INVALID_ID) lay_insert(&l->ctx, l->stack[d - 1], it);
else lay_append(&l->ctx, l->last[d - 1], it);
l->last[d - 1] = it;
}
static void
push(reaktor_layout *l, lay_id it)
{
if (l->depth < REAKTOR_LAY_DEPTH) {
l->stack[l->depth] = it;
l->last[l->depth] = LAY_INVALID_ID;
}
l->depth++;
}
static lay_id
@@ -81,10 +92,7 @@ declare(reaktor_layout *l, unsigned id, const reaktor_box *b)
lay_set_margins_ltrb(&l->ctx, it, (lay_scalar)b->ml, (lay_scalar)b->mt,
(lay_scalar)b->mr, (lay_scalar)b->mb);
{
lay_id parent = parent_of(l);
if (parent != LAY_INVALID_ID) lay_insert(&l->ctx, parent, it);
}
attach(l, it);
l->id[l->count] = id;
l->item[l->count] = it;
@@ -117,16 +125,13 @@ reaktor_layout_begin(reaktor_layout *l, struct nk_rect root)
rb.dir = REAKTOR_LAY_FREE;
it = declare(l, 0u, &rb);
if (it != LAY_INVALID_ID) l->stack[l->depth++] = it;
if (it != LAY_INVALID_ID) push(l, it);
}
void
reaktor_layout_open(reaktor_layout *l, unsigned id, const reaktor_box *b)
{
lay_id it = declare(l, id, b);
if (l->depth < REAKTOR_LAY_DEPTH) l->stack[l->depth] = it;
l->depth++;
push(l, declare(l, id, b));
}
void
+1
View File
@@ -33,6 +33,7 @@ typedef struct reaktor_layout {
unsigned flags[REAKTOR_LAY_MAX];
lay_id stack[REAKTOR_LAY_DEPTH];
lay_id last[REAKTOR_LAY_DEPTH];
int depth;
reaktor_lay_slot slot[REAKTOR_LAY_SLOTS];
+158 -39
View File
@@ -323,9 +323,132 @@ 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)
{
const struct nk_style_button *nb = &ctx->style.button;
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 *icon_src,
button_glyph *g)
{
reaktor_style st;
char q[128];
SDL_snprintf(q, sizeof q, "%s .icon", selector);
reaktor_style_get(q, &st);
g->px = st.matched && st.width > 0.0f ? st.width
: 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 = 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)
{
return (label ? reaktor_text_w(f, label) : 0.0f) +
(g ? (g->ink_r - g->ink_l) * g->px + g->gap : 0.0f);
}
static float
content_w(struct nk_context *ctx, const char *selector, float group, int glyph)
{
reaktor_style st;
float w;
reaktor_style_get(selector, &st);
w = group + 2.0f * button_inset(ctx, &st, glyph);
return st.matched && st.min_width > w ? st.min_width : w;
}
float
css_button_content_w(App *app, struct nk_context *ctx, const char *selector,
const struct nk_user_font *f, const char *icon_src, const char *label)
{
button_glyph g;
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
state_ink(struct nk_context *ctx)
{
const struct nk_style_button *bs = &ctx->style.button;
nk_flags state = ctx->last_widget_state;
struct nk_color ink = (state & NK_WIDGET_STATE_HOVER) ? bs->text_hover
: (state & NK_WIDGET_STATE_ACTIVED) ? bs->text_active
: bs->text_normal;
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)
{
struct nk_style_button *bs = &ctx->style.button;
float group, side;
group = group_w(ctx->style.font, g, label);
if (b.w + 1.0f < content_w(ctx, selector, group, 1)) return 0;
side = (b.w - group) * 0.5f;
at->x = (float)(int)(b.x + side - g->ink_l * g->px + 0.5f);
at->y = (float)(int)(b.y + (b.h - g->px) * 0.5f);
at->w = at->h = g->px;
nk_style_push_flags(ctx, &bs->text_alignment, NK_TEXT_ALIGN_RIGHT | NK_TEXT_ALIGN_MIDDLE);
nk_style_push_vec2(ctx, &bs->padding, nk_vec2(side - bs->border - bs->rounding, bs->padding.y));
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 *icon_src,
const char *label)
{
button_glyph g;
struct nk_rect at;
int drawn = 0, clicked;
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);
clicked = nk_button_label(ctx, label);
reaktor_chrome_disarm();
if (drawn) {
nk_style_pop_vec2(ctx);
nk_style_pop_flags(ctx);
nk_draw_image(nk_window_get_canvas(ctx), at, &g.im, state_ink(ctx));
}
return clicked;
}
int
css_button_accent(App *app, struct nk_context *ctx, const char *selector,
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];
@@ -356,62 +479,58 @@ 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;
reaktor_button_arm(ctx);
clicked = nk_button_label(ctx, label);
reaktor_chrome_disarm();
clicked = group_press(app, ctx, selector, icon_src, label);
reaktor_style_frame_pop(ctx, a);
reaktor_style_frame_pop(ctx, f);
return clicked;
}
static int
icon_place(struct nk_context *ctx, struct nk_rect b, float pad_x,
const char *label, struct nk_rect *at)
{
const struct nk_style_button *s = &ctx->style.button;
const struct nk_user_font *f = ctx->style.font;
float text = reaktor_text_w(f, label);
at->x = b.x + 2.0f * pad_x + s->image_padding.x;
at->y = b.y + s->padding.y + s->image_padding.y;
at->w = b.h - 2.0f * s->padding.y - 2.0f * s->image_padding.x;
at->h = b.h - 2.0f * s->padding.y - 2.0f * s->image_padding.y;
if (b.w >= text + 2.0f * (3.0f * pad_x + s->image_padding.x + at->w)) return 1;
/* A wide padding still leaves room once the icon moves to the edge. */
at->x = b.x + pad_x + s->image_padding.x;
return b.w >= text + 2.0f * (1.5f * pad_x + s->image_padding.x + at->w);
}
int
css_button_icon(App *app, struct nk_context *ctx, const char *selector,
const char *icon_src, const char *label)
{
reaktor_button_look k;
reaktor_style_frame f;
struct nk_rect b = nk_widget_bounds(ctx), at;
int clicked, drawn;
int clicked;
hot_push(app, b, REAKTOR_CURSOR_POINTER, 1);
hot_push(app, nk_widget_bounds(ctx), REAKTOR_CURSOR_POINTER, 1);
reaktor_note_here(app, ctx, REAKTOR_A11Y_BUTTON, label, 0);
reaktor_button_look_of(selector, &k);
f = push_button_look(app, ctx, &k);
drawn = icon_place(ctx, b, k.s.matched ? k.s.pad_x : ctx->style.button.padding.x,
label, &at);
reaktor_button_arm(ctx);
clicked = nk_button_label(ctx, label);
reaktor_chrome_disarm();
if (drawn) {
const struct nk_style_button *bs = &ctx->style.button;
nk_flags state = ctx->last_widget_state;
struct nk_image im = icon(app, icon_src, 18);
struct nk_color ink = (state & NK_WIDGET_STATE_HOVER) ? bs->text_hover
: (state & NK_WIDGET_STATE_ACTIVED) ? bs->text_active
: bs->text_normal;
clicked = group_press(app, ctx, selector, icon_src, label);
reaktor_style_frame_pop(ctx, f);
return clicked;
}
nk_draw_image(nk_window_get_canvas(ctx), at, &im,
nk_rgb_factor(ink, bs->color_factor_text));
/* 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)
{
reaktor_button_look k;
reaktor_style_frame f;
struct nk_rect b = nk_widget_bounds(ctx);
float in_x;
unsigned id;
int clicked;
hot_push(app, b, REAKTOR_CURSOR_POINTER, 1);
id = reaktor_note_here(app, ctx, REAKTOR_A11Y_BUTTON, name, 0);
reaktor_button_look_of(sel, &k);
in_x = button_inset(ctx, &k.s, 0);
f = push_button_look(app, ctx, &k);
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);
if (c.h < 0.0f) c = nk_rect(c.x, b.y, c.w, b.h);
if (c.w > 0.0f) paint(app, nk_window_get_canvas(ctx), c, state_ink(ctx), user);
}
reaktor_style_frame_pop(ctx, f);
if (reaktor_focus_activated(app, id)) clicked = 1;
return clicked;
}
+3 -3
View File
@@ -23,8 +23,8 @@ static int g_toast_n, g_toast_next = 1, g_toast_fresh;
static Uint32 SDLCALL
expire(void *userdata, SDL_TimerID id, Uint32 interval)
{
(void)id; (void)interval;
reaktor_wake((App *)userdata);
(void)userdata; (void)id; (void)interval;
reaktor_wake(NULL);
return 0;
}
@@ -67,7 +67,7 @@ reaktor_toast(App *app, const reaktor_toast_spec *spec)
if (ms <= 0 && spec->no_close && !spec->action) ms = 5000;
if (ms > 0) {
t->until = SDL_GetTicks() + (Uint64)ms;
t->timer = SDL_AddTimer((Uint32)ms, expire, app);
t->timer = SDL_AddTimer((Uint32)ms, expire, NULL);
}
g_toast_fresh = 1;
app->dirty = 1;
+26 -21
View File
@@ -199,7 +199,7 @@ 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;
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;
@@ -238,7 +238,7 @@ tree_first(tree_rows *t, int r, unsigned id, struct nk_color fg, float pad)
if (step > 0 && branch && !s->open[node]) s->open[node] = 1;
else if (step > 0 && branch && r + 1 < t->n) t->jump = t->node[r + 1];
else if (step < 0 && branch && s->open[node]) s->open[node] = 0;
else if (step < 0 && s->parent(node, s->user) >= 0) t->jump = s->parent(node, s->user);
else if (step < 0 && (up = s->parent(node, s->user)) >= 0 && up < s->count) t->jump = up;
if (step) {
g_frame_app->dirty = 1;
reaktor_wake(g_frame_app);
@@ -320,7 +320,7 @@ reaktor_tree(const reaktor_tree_spec *s)
t.depth = buf + s->count;
t.row = buf + 2 * s->count;
t.n = 0;
t.jump = jump_in == s->name ? jump : -1;
t.jump = jump_in == s->name && jump < s->count ? jump : -1;
for (i = 0; i < s->count; i++) {
int p = s->parent(i, s->user);
@@ -551,7 +551,6 @@ reaktor_splitter(const reaktor_splitter_spec *s)
#define MENU_DEPTH 4
#define MENU_COLS (MENU_DEPTH + 1)
#define MENU_TITLES 16
#define MENU_ITEMS 32
/* The windows that draw a column run after the frame that declared it: they draw a copy. */
@@ -570,8 +569,8 @@ static struct {
int path[MENU_DEPTH], hi[MENU_COLS], win[MENU_COLS];
menu_col col[MENU_COLS];
int n, inline_;
unsigned tid[MENU_TITLES];
struct nk_rect title[MENU_TITLES];
unsigned open_tid;
struct nk_rect open_title;
int picked_k, picked_i;
} g_menu = { -1 };
@@ -851,7 +850,7 @@ menu_key(const reaktor_menubar_spec *s, App *app)
return;
case SDLK_ESCAPE:
if (k > 0) { g_menu.depth = k - 1; g_menu.kcol = k - 1; return; }
reaktor_focus_take(app, g_menu.tid[g_menu.open], g_menu.title[g_menu.open]);
reaktor_focus_take(app, g_menu.open_tid, g_menu.open_title);
g_menu.open = -1;
return;
default:
@@ -899,10 +898,10 @@ menu_build(const reaktor_menubar_spec *s)
menu_col *c = &g_menu.col[k];
menu_measure(c, ctx->style.font, pad);
menu_fit(c, k ? &g_menu.col[k - 1] : NULL, g_menu.title[g_menu.open], b);
menu_fit(c, k ? &g_menu.col[k - 1] : NULL, g_menu.open_title, b);
if (k) {
c->r.y = menu_entry_y(&g_menu.col[k - 1], g_menu.path[k - 1]) - pad.y;
menu_fit(c, &g_menu.col[k - 1], g_menu.title[g_menu.open], b);
menu_fit(c, &g_menu.col[k - 1], g_menu.open_title, b);
if (c->r.y + c->r.h > b.y + b.h) c->r.y = b.y + b.h - c->r.h;
}
}
@@ -972,9 +971,10 @@ reaktor_menubar(const reaktor_menubar_spec *s)
reaktor_box_open(REAKTOR_LAY_ROW, &bar);
reaktor_note_push(app, REAKTOR_A11Y_MENUBAR, s->name ? s->name : "Menu bar",
NULL, 0u, reaktor_box_rect(&r) ? r : nk_rect(0, 0, 0, 0));
for (m = 0; m < s->count && m < MENU_TITLES; m++) {
for (m = 0; m < s->count; m++) {
const char *label = s->menus[m].label;
struct nk_style_button st = *mb;
unsigned tid = 0;
memset(&title, 0, sizeof(title));
title.w = (float)(int)(reaktor_text_w(f, label) +
@@ -982,20 +982,24 @@ reaktor_menubar(const reaktor_menubar_spec *s)
title.h = h;
if (!decl_place(REAKTOR_A11Y_MENU, label, NULL,
g_menu.open == m ? REAKTOR_A11Y_EXPANDED : 0u, NULL, &title,
&g_menu.tid[m]))
&tid))
continue;
r = nk_widget_bounds(ctx);
g_menu.title[m] = r;
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 (!nk_input_is_mouse_hovering_rect(&ctx->input, r)) continue;
on_title = 1;
if (g_menu.open >= 0 && g_menu.open != m && nk_input_is_mouse_moved(&ctx->input))
menu_open_at(m, 0);
if (nk_input_is_mouse_released(&ctx->input, NK_BUTTON_LEFT)) {
if (g_menu.open == m) g_menu.open = -1;
else menu_open_at(m, app->focus_id == g_menu.tid[m] && app->focus_visible);
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);
if (nk_input_is_mouse_released(&ctx->input, NK_BUTTON_LEFT)) {
if (g_menu.open == m) g_menu.open = -1;
else menu_open_at(m, app->focus_id == tid && app->focus_visible);
}
}
if (g_menu.open == m) {
g_menu.open_tid = tid;
g_menu.open_title = r;
}
}
reaktor_note_pop(app);
@@ -1032,7 +1036,8 @@ reaktor_menubar(const reaktor_menubar_spec *s)
}
if (g_menu.open >= 0) app->popup_open = 1;
if (g_menu.open >= 0 && g_menu.picked_k >= 0 && g_menu.picked_k < g_menu.n) {
if (g_menu.open >= 0 && g_menu.picked_k >= 0 && g_menu.picked_k < g_menu.n &&
g_menu.picked_i >= 0 && g_menu.picked_i < g_menu.col[g_menu.picked_k].count) {
const reaktor_menu_entry *e = &g_menu.col[g_menu.picked_k].src[g_menu.picked_i];
if (e->checked) *e->checked = !*e->checked;
@@ -1041,7 +1046,7 @@ reaktor_menubar(const reaktor_menubar_spec *s)
if (s->picked_item) *s->picked_item = g_menu.picked_i;
if (s->picked) *s->picked = e;
if (g_menu.open >= 0 && g_menu.keyed)
reaktor_focus_take(app, g_menu.tid[g_menu.open], g_menu.title[g_menu.open]);
reaktor_focus_take(app, g_menu.open_tid, g_menu.open_title);
g_menu.picked_k = -1;
g_menu.open = -1;
app->popup_open = 0;
+67 -22
View File
@@ -25,8 +25,8 @@ reaktor_font(App *app, int px, int bold)
#define ICON_HAIRLINE_BELOW 20
static const char *
icon_src(char out[192], const char *name, const char *hex, float sw)
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);
@@ -54,7 +54,7 @@ reaktor_ionicon(App *app, const char *name, int px)
{
char src[192];
return icon(app, icon_src(src, name, app->icon_hex,
return icon(app, reaktor_ionicon_src(src, name, app->icon_hex,
px < ICON_HAIRLINE_BELOW ? GLYPH_STROKE : -1.0f), px);
}
@@ -66,7 +66,7 @@ reaktor_ionicon_exact(App *app, const char *name, int px,
if (sw <= 0.0f) sw = px < ICON_HAIRLINE_BELOW ? GLYPH_STROKE : 1.0f;
reaktor_hex(stroke, hex);
return icon_over(app, icon_src(src, name, hex, sw), px, 1.0f);
return icon_over(app, reaktor_ionicon_src(src, name, hex, sw), px, 1.0f);
}
struct nk_image
@@ -75,7 +75,8 @@ reaktor_ionicon_col(App *app, const char *name, int px, struct nk_color stroke)
char hex[8], src[192];
reaktor_hex(stroke, hex);
return icon(app, icon_src(src, name, hex, px < ICON_HAIRLINE_BELOW ? GLYPH_STROKE : 1.0f), px);
return icon(app, reaktor_ionicon_src(src, name, hex,
px < ICON_HAIRLINE_BELOW ? GLYPH_STROKE : 1.0f), px);
}
struct nk_color
@@ -406,11 +407,11 @@ stepper_wash(App *app, struct nk_context *ctx, struct nk_rect sq)
static float
reaktor_cap_offset(const struct nk_user_font *f)
{
const struct nk_font *nf = f ? (const struct nk_font *)f->userdata.ptr : NULL;
const struct nk_font_glyph *g = nf ? nk_font_find_glyph((struct nk_font *)nf, 'H') : NULL;
const struct reaktor_font *rf = f ? (const struct reaktor_font *)f->userdata.ptr : NULL;
const struct reaktor_glyph *g = rf ? reaktor_font_glyph(rf, 'H') : NULL;
if (!g || nf->info.height <= 0.0f) return 0.0f;
return ((g->y0 + g->y1) * 0.5f - nf->info.height * 0.5f) * f->height / nf->info.height;
if (!g || rf->height <= 0.0f) return 0.0f;
return ((g->y0 + g->y1) * 0.5f - rf->height * 0.5f) * f->height / rf->height;
}
void
@@ -502,11 +503,20 @@ reaktor_button_label_as(App *app, struct nk_context *ctx, const char *sel,
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 *label)
const char *ionicon, const char *label)
{
return css_button_accent(app, ctx, sel, label);
char src[192];
return css_button_accent(app, ctx, sel, reaktor_button_src(src, ionicon), label);
}
int
@@ -515,15 +525,37 @@ reaktor_button_icon_as(App *app, struct nk_context *ctx, const char *sel,
{
char src[192];
SDL_snprintf(src, sizeof(src),
"external/ionicons/src/svg/%s.svg?stroke=#ffffff", ionicon);
return css_button_icon(app, ctx, sel, src, label);
return css_button_icon(app, ctx, sel, reaktor_button_src(src, ionicon), label);
}
int
reaktor_button_accent(App *app, struct nk_context *ctx, const char *label)
{
return css_button_accent(app, ctx, "button", label);
return css_button_accent(app, ctx, "button", NULL, label);
}
int
reaktor_button_accent_icon(App *app, struct nk_context *ctx, const char *ionicon,
const char *label)
{
return reaktor_button_accent_as(app, ctx, "button", ionicon, label);
}
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,
reaktor_button_src(src, ionicon), label));
}
int
reaktor_button_custom(App *app, struct nk_context *ctx, const char *name,
reaktor_button_paint paint, void *user)
{
return reaktor_css_button_custom(app, ctx, "button", name, paint, user);
}
int
@@ -582,11 +614,7 @@ int
reaktor_button_icon(App *app, struct nk_context *ctx, const char *ionicon,
const char *label)
{
char src[192];
SDL_snprintf(src, sizeof(src),
"external/ionicons/src/svg/%s.svg?stroke=#ffffff", ionicon);
return css_button_icon(app, ctx, "button", src, label);
return reaktor_button_icon_as(app, ctx, "button", ionicon, label);
}
static void
@@ -808,7 +836,7 @@ file_chosen(void *userdata, const char * const *filelist, int filter)
SDL_SetAtomicInt(&app->file_ready, 1);
reaktor_wake(app);
/* The last touch: a closed window's App may be freed after it. */
SDL_SetAtomicInt(&app->file_done, 1);
SDL_SetAtomicInt(&app->file_busy, 0);
}
int
@@ -817,7 +845,7 @@ reaktor_file_dialog_open(App *app, const reaktor_file_dialog *d)
if (!d || app->file_pending) return 0;
app->file_pending = 1;
app->file_dialog = *d;
SDL_SetAtomicInt(&app->file_done, 0);
SDL_SetAtomicInt(&app->file_busy, 1);
if (d->kind == REAKTOR_FILE_SAVE)
SDL_ShowSaveFileDialog(file_chosen, app, app->win, d->filters,
d->filter_count, d->location);
@@ -864,6 +892,21 @@ a11y_dump_once(App *app)
REAKTOR_A11Y_POOL, app->a11y.pool_entries,
(int)sizeof(reaktor_a11y));
}
{
const reaktor_a11y_node *t;
const char *mark;
unsigned id;
int i, k, n = 0;
t = reaktor_a11y_tree(&app->a11y, &n);
for (i = 0; (mark = reaktor_mark_at(i, &id)); i++)
for (k = 0; k < n; k++)
if (t[k].id == id) {
fprintf(f, "# #%s: %s \"%s\"\n", mark, reaktor_a11y_role_name(t[k].role),
t[k].name ? t[k].name : "");
break;
}
}
fclose(f);
}
@@ -1276,6 +1319,8 @@ reaktor_diagnostics(App *app, reaktor_diag *out)
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;
out->frames_drawn = app->frames_drawn;
out->frames_skipped = app->frames_skipped;
out->nk_bytes = (unsigned long)app->ctx->memory.size;
out->nk_used = (unsigned long)app->ctx->memory.allocated;
+1 -1
View File
@@ -71,7 +71,7 @@ item lands when its popup is a pixel short; this does.
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 VM that
seconds flat out, on the Windows machine that
[PERFORMANCE.md](PERFORMANCE.md#where-the-numbers-came-from) names:
```
+113 -25
View File
@@ -73,7 +73,7 @@ errors, so an internal function cannot slip back in.
| `reaktor_lang_pref(app)` | The language `--lang` asked for, or `NULL` |
| `reaktor_set_borderless(app, on)`, `reaktor_borderless(app)` | Switch the main window's frame off for a titlebar of your own, drawn with `.window.hit_test` |
| `reaktor_set_visible(app, on)` | Show or hide that App's window; with `.window.hidden`, the main window waits for it |
| `reaktor_version()` | Reaktor's version, such as `"0.7.1"` |
| `reaktor_version()` | Reaktor's version, such as `"0.7.2"` |
The `set` calls are for the main thread, take effect at the next frame, and do
nothing when nothing changes.
@@ -154,8 +154,8 @@ when unset. Each page is laid out and drawn as on screen, in a hidden window
at `.dpi` (200 unset), so it carries the window's look: a page that should be
white paints itself white. Both calls answer 1 when the job is queued; it runs
between frames, and `.done(app, ok, user)` says how it went. A page is an
image in the PDF, through [PDFGen](https://github.com/AndreRenaud/PDFGen) and
plutovg's JPEG writer, so its text is not selectable. To print, Windows shows
image in the PDF, a JPEG from plutovg's writer that `runtime/print.c` wraps
in the file itself, so its text is not selectable. To print, Windows shows
its print dialog and draws the pages to the printer; macOS opens its print
dialog on the PDF; Linux and the BSDs open the PDF in the user's viewer, which
prints it. The web build does not print.
@@ -228,8 +228,8 @@ again), `.style` (a selector to read instead of the widget's own) and `.box`
| Widget | Call | Answers 1 | Its own fields |
| --- | --- | --- | --- |
| Button | `reaktor_button` | when pressed | `.label`, `.icon`, `.accent`, `.disabled`, `.repeat` (fires while held), `.keys`, `.on_press`, `.tooltip`, `.fit_content` (exactly as large as its label and icon, whatever `.box` asks) |
| Link | `reaktor_link` | when pressed | `.text`, `.active`, `.on_press`, or `.url` to open in the browser |
| Button | `reaktor_button` | when pressed | `.label`, `.icon`, `.accent`, `.disabled`, `.repeat` (fires while held), `.keys` (the shortcut readers announce; the `key` hook binds it, see [Keyboard](#keyboard)), `.on_press`, `.tooltip`, `.fit_content` (as large as its label and icon need; a `.box.w` is then the least it takes, so short labels line up and long ones grow); `.accent` with `.icon` draws both; `.paint` and `.paint_user` draw the inside as `reaktor_button_custom` does, with `.label` measured for `.fit_content` and read as the name unless `.name` is set |
| Link | `reaktor_link` | when pressed | `.text`, `.active`, `.on_press`, or `.url` to open in the browser: `http`, `https` or `mailto`, and the schemes `.schemes` lists, as `"file,ftp"` |
| Label | `reaktor_label` | — | `.text`, `.wrap`, `.align` (`REAKTOR_LEFT`, `_CENTER`, `_RIGHT`), `.color` (a token), `.value`, `.silent` (left out of the tree) |
| Icon | `reaktor_icon` | — | `.name` (an Ionicon) and `.accent`, or `.src` (any image asset: SVG, PNG, JPEG), stretched to its box; `.tooltip` |
| Swatch | `reaktor_swatch` | when pressed | `.fill`, `.on_press` |
@@ -253,8 +253,14 @@ again), `.style` (a selector to read instead of the widget's own) and `.box`
| Tree | `reaktor_tree` | when another node is chosen | `.count`, `.parent(node, user)`, `.label(node, user)`, `.icon(node, user)`, `.open` (a flag per node), `.selected` (a node), `.row_h` |
| Splitter | `reaktor_splitter` | while dragged | `.value` (the first child's share, 0 to 1), `.lo`, `.hi` (0.1 and 0.9 unset), `.vertical` |
The icon is 1.125 times the button font's height, 18 px at 16 px, unless the sheet sizes `button .icon` with `width`; its `margin-right` is then the gap. A `min-width` on the button's rule is the least `.fit_content` takes.
**An icon gives way to its label**: a button too narrow for both draws the
label alone. `.fit_content` makes it as large as both need.
label alone. `.fit_content` makes it as large as both need, as GTK and Qt size
a button: the label, the icon's drawn width and 12 px between them, plus half
the sheet's padding and its border on each side, since an icon tightens a
button as it does GTK's. At any width the icon and label are centered together
on the icon's drawn pixels, since an Ionicon sits anywhere in its square.
**A field writes back** its bytes into `.buf` and its length into `*.len`, and
reads both next frame, so the length must be the field's own: one from
@@ -449,6 +455,7 @@ A container's fields, and a widget's `.box`:
| `.ml .mt .mr .mb` | Margins |
| `.flags` | `REAKTOR_LAY_FILL_X`, `_FILL_Y`, `_WRAP`, `_CENTER_X`, `_CENTER_Y`, `_PACK_CENTER`, `_PACK_END`, `_PACK_SPREAD` |
| `.name` | How a container is found again; a widget uses its spec's `.name` |
| `.mark` | A handle for a [scripted test](#testing-an-application), on a widget or a container: `"#mark"` finds it, `"#mark Delete"` finds Delete inside it, and no reader hears it. One mark may sit on many widgets, every row of a list for one; up to 63 characters are kept. Marks are kept apart from the tree, in a table made only once something sets one; `--a11y-dump` lists them after the tree |
So `.w` alone is fixed, `.w` with `FILL_X` a minimum that grows, and `FILL_X`
with `.weight` a fraction. The outermost container is as wide as the panel it
@@ -821,7 +828,9 @@ out by hand inside a declared page. [`include/reaktor/ui.h`](../include/reaktor/
| `reaktor_fill_round`, `reaktor_edge_round` | Rounded fills and borders, smooth on the software renderer |
| `reaktor_hot`, `reaktor_hot_top`, `reaktor_hot_follow` | A rectangle that redraws on hover ([the frame loop](#the-frame-loop)), with a `REAKTOR_CURSOR_*` over it: default, pointer, text, or a horizontal or vertical resize |
| `reaktor_tip(app, rect, text)` | A tooltip over a rectangle you drew yourself, such as a bar of a chart; the text is copied, and the rectangle redraws as the pointer crosses it |
| `reaktor_button_label`, `reaktor_button_icon`, `reaktor_button_accent`, `reaktor_field_text`, `reaktor_slider_bar`, `reaktor_progress_bar`, `reaktor_chevron_at` | Styled controls inside hand-laid rows |
| `reaktor_button_label`, `reaktor_button_icon`, `reaktor_button_accent`, `reaktor_button_accent_icon`, `reaktor_field_text`, `reaktor_slider_bar`, `reaktor_progress_bar`, `reaktor_chevron_at` | Styled controls inside hand-laid rows |
| `reaktor_button_width(app, ctx, ionicon, label)` | The width `.fit_content` gives that button, for a hand-laid row; `ionicon` may be `NULL`. An icon button laid out at that width centers its icon and label together |
| `reaktor_button_custom(app, ctx, name, paint, user)` | The sheet's button with the inside left to `paint(app, canvas, content, ink, user)`: `content` is the box inside the padding, `ink` the text color for the button's state, and `name` what a reader hears. Fill, edge, hover, focus and the click stay the runtime's |
| `reaktor_menu_item`, `reaktor_menu_style_push`, `_pop`, `reaktor_menu_height`, `reaktor_menu_edge`, `reaktor_popup_rounding` | Menus and popups |
| `reaktor_note`, `_push`, `_pop`, `_here`, `_keys`, `_value`, `_bounds`, `reaktor_focus_activated` | The accessibility tree, and keyboard presses |
| `reaktor_focus_area`, `reaktor_focus_scroll` | A scrolling page body: the area and node focus moves within, and the rectangle it asks to see |
@@ -886,7 +895,8 @@ in `core/` knows which application it is in.
seven Ionicons the widgets draw (three chevrons, three discs and the toast's
close cross), `reaktor.css` and Water.css's palettes and parts, copied byte for byte
at configure time. `reaktor_asset_load` still tries the file under the
`.reaktor-root` marker first, so an edited sheet shows without a rebuild.
`.reaktor-root` marker first, so an edited sheet shows without a rebuild; the
marker is looked for beside the program and at most two folders above it.
Nothing is read from the working directory, and a path a user hands over is
made absolute where it is taken. The rest of Ionicons, Simple.css and the
catalogs are read from files; an icon that is not there is drawn as nothing,
@@ -909,6 +919,16 @@ While a mouse button is held, frames follow the display's refresh, with two
more after the release. A turn of the wheel takes two frames, because Nuklear
scrolls a panel after drawing it.
**A frame that draws what is already on screen** is still rendered and
presented, unless the launch sets `.skip_same_frames`. Then each frame's draw
commands are hashed field by field, and one that matches the last presented
frame is neither rendered nor presented. A key nothing takes, or a focus
change that moves no ring, then costs the build and nothing more. A window
uncovered, shown, resized, restored or moved to another scale is always drawn,
and so is a frame a `--shot` or a capture waits for. It is off by default; the
showcase turns it on, and its Diagnostics page counts the frames drawn and
skipped.
A finger that moves mostly up or down, by more than 8 pixels, scrolls the
panel under it: the runtime releases what the finger pressed away from every
widget, so nothing is clicked, and turns its movement into wheel steps sized
@@ -961,7 +981,7 @@ by hand in headless Edge, as desktop, Android and iOS.
`build-<arch>` when it is not the machine's own; ARM64 needs Visual Studio's
ARM64 build tools.
**Releases.** Pushing a `v*` tag runs `release.yml`: the four native
**Releases.** Pushing a version tag such as `1.2.3` or `1.2.3-rc1` runs `release.yml`: the four native
workflows again, with every job required, a web build, and a GitHub release
of what they packed — one archive per system and architecture, the three
WebAssembly programs, libreaktor for each ([In your own project](#in-your-own-project)),
@@ -1060,7 +1080,7 @@ Passed to CMake, through either script:
| `REAKTOR_TRAY` | `ON` | The tray icon |
| `REAKTOR_POPUP_WINDOWS` | `ON` | Menus in windows of their own |
| `REAKTOR_NOTIFY` | `ON` | System notifications |
| `REAKTOR_PRINT` | `ON` | Printing and PDF export, through PDFGen |
| `REAKTOR_PRINT` | `ON` | Printing and PDF export |
| `REAKTOR_INSPECTOR` | `ON` | The [Inspector](#inspector) |
| `REAKTOR_SDL_GL` | `OFF` | Build SDL's OpenGL and GLES drivers on Windows, Linux and the BSDs |
| `REAKTOR_SAMPLES`, `REAKTOR_TESTS` | `ON` at the top | Build the samples, and the tests in `tests/` |
@@ -1102,7 +1122,7 @@ options a page needs; `ASSETS <file>@<path>` packs files beside it there.
`.remember_window` is ignored.
- **`REAKTOR_TRAY=OFF`** answers 0 from `reaktor_tray_open`, so AppIndicator
and GTK 3 are never loaded on Linux and the BSDs.
- **`REAKTOR_PRINT=OFF`** leaves PDFGen out; `reaktor_print` and
- **`REAKTOR_PRINT=OFF`** leaves the print module out; `reaktor_print` and
`reaktor_print_pdf` answer 0.
- **`REAKTOR_INSPECTOR=OFF`** answers 0 from `reaktor_inspector_open` and
ignores `.inspector`, its shortcut and its flags.
@@ -1123,7 +1143,7 @@ removes them from `argv` before the application sees it:
| `--theme <system\|light\|dark>` | Open in that scheme; on OpenBSD `system` reads as light |
| `--lang <code>` | Open in that catalog: `en`, `pl`, `ja` |
| `--font-fallback <path>` | A font for the Text module, before the application's; repeatable |
| `--renderer <name>` | `software` (default), `auto`, or a driver name |
| `--renderer <name>` | `software` (default), `auto`, `directx`, or a driver name; see [The renderer](#the-renderer) |
| `--aa <auto\|on\|off>` | Override `.anti_aliasing` |
| `--video <name>` | SDL's video driver: `x11`, `wayland`, `dummy` |
| `--popups inline` | Menus inside the window, not in windows of their own |
@@ -1178,19 +1198,87 @@ Built by default and run from `build/`:
| `keytest` | Chord parsing and formatting |
| `localetest` | Catalogs, lookup, plural rules, formatting |
| `csstest` | Flattening a sheet for libcss: what is rewritten, what is dropped, and Simple.css read through it |
| `imagetest` | PNG and JPEG decode; other formats are not compiled in |
| `basetest` | Which URL schemes a link opens, and UTF-8 cleaning |
| `uitest` | The scripted UI test below, driving its own window: find by name and mark, click, type, a check box, a key hook |
| `texttest` | Line breaks, direction, measuring and glyph order, against `assets/fonts`; with the Text module |
| `launchtest` | Opt-in (`./build.ps1 launchtest`): `launchApp`'s hooks by mode (`start-fail`, `quit`, `veto`, `title`, `confirm`, `confirm-cancel`), the services (`ask`, `timer`, `post`, `settings`, `save-change`, `save-timer`, `settings-clear`, `list`, `list-keys`, `tree-keys`, `field-find`, `spin-keys`, `date-keys`, `undo`, `print-pdf`, `split-keys`, `split-vkeys`, `menu-keys`, `tip`; `dialog-open`, `dialog-many`, `dialog-save` and `dialog-folder` wait for someone to answer the system's dialog), what a floater, toast or popup holds and where keys go (the `hold-` modes), and a window beside the main one (`window-text` and the `win-` modes: keys, drops, animation, title, theme, wakes, a drag, one change a frame, the picker, memory, `win-hints`) |
Beyond those, check a visual change against the framebuffer (`--shot`) and the
dump, not against a reading of the source.
### Testing an application
`reaktor_test_app` launches an application with SDL's dummy video driver, so
no window shows, and runs a script on a thread of its own once the first frame
settles. The script acts as a person would: it finds widgets in the
accessibility tree by their name, or by a `.box.mark` written `"#mark"`, and
clicks and types through the same SDL events a mouse and keyboard send. Every
call returns once the window has drawn and settled. The run exits 0 when every
check passed, and each check is logged (`--log` writes it to a file).
```c
static void script(reaktor_test *t, void *user)
{
char v[64];
reaktor_test_type(t, "Name", "Ada");
reaktor_test_click(t, "Greet");
reaktor_test_check(t, reaktor_test_value(t, "#greeting", v, sizeof v) &&
SDL_strcmp(v, "Hello, Ada") == 0, "greets by name");
}
int main(int argc, char **argv)
{
return reaktor_test_app(argc, argv, &my_launch, script, NULL);
}
```
| Call | What it does |
| --- | --- |
| `reaktor_test_find(t, target)` | 1 once the target is in the tree, waiting a few frames for it |
| `reaktor_test_click(t, target)` | A left click at its center; 0 if it is missing or scrolled out of view |
| `reaktor_test_type(t, target, text)` | Clicks it, then types `text`; `NULL` types where the focus is |
| `reaktor_test_key(t, chord)` | `"Ctrl+S"`, `"Enter"`: modifiers, then one key by SDL's name |
| `reaktor_test_value(t, target, out, cap)`, `reaktor_test_state(t, target)` | Its value as a reader hears it, and its `REAKTOR_A11Y_*` state |
| `reaktor_test_settle(t)` | Wait until the window has drawn and settled |
| `reaktor_test_check(t, ok, what)` | Count and log one check |
A target names a widget by what a reader hears, or by its mark as `"#mark"`; `"#rows Delete"` looks for Delete only inside the container marked `rows`, at any depth. When several widgets match, the first is used and the log says how many there were. A test reads only the main window. The video driver is dummy unless the
command line names one, and `--new-instance` is passed for it.
## The renderer
`software` is the default on every platform. The app draws nothing at rest,
so a GPU buys it nothing measurable, and costs a great deal on a machine
without one: SDL's software renderer took 13.1 ms of CPU a frame where
Direct3D on WARP took 78.7. One rasterizer is also one set of pixels to reason
about. `--renderer auto` lets SDL choose; a driver name pins one.
`software` is the default on every platform:
- **It needs no GPU.** Without one, Direct3D falls back to Microsoft's WARP
emulation: SDL's software renderer took 13.1 ms of CPU a frame where
Direct3D on WARP took 78.7.
- **It uses the least memory**, 9.5 MB in `bench` against 59–122 MB on a GPU
renderer, most of that the graphics driver's.
- **It starts fastest, and its cost does not depend on other programs** using
the GPU.
- **An app at rest draws nothing**, so a GPU has little to speed up, and one
rasterizer is one set of pixels to reason about.
`--renderer` picks another:
| Name | Where | For | Against |
| --- | --- | --- | --- |
| `directx` | Windows | Direct3D 12 where it starts, else 11 | As below |
| `direct3d12` | Windows 10 and later | Least CPU once running | Most memory, slowest start |
| `direct3d11` | Windows | Any Windows GPU | Most CPU of the GPU renderers measured |
| `opengl` | Windows, Linux, BSDs | Little CPU once running | Built only with `-DREAKTOR_SDL_GL=ON`; on Linux without a GPU it loads Mesa and LLVM |
| `opengles2` | Where the driver offers it | | Built only with `-DREAKTOR_SDL_GL=ON`; not measured |
| `metal` | macOS | | |
| `auto` | Everywhere | SDL chooses | |
A GPU renderer smooths the edges of fills unless `.anti_aliasing` says
otherwise, and keeps the CPU free during long animations. It costs six to
thirteen times the memory and more CPU to start, and it shares the GPU: with
another program keeping the GPU busy, frames missed 60 fps and took 16–28% of
a core. A renderer that would not start falls back to SDL's choice and logs
why. The figures are in [PERFORMANCE.md](PERFORMANCE.md#against-the-others).
- **Every vertex is snapped to the pixel grid**, so a sub-pixel correction is
discarded, and abutting rectangles can round apart into a seam.
@@ -1205,11 +1293,11 @@ about. `--renderer auto` lets SDL choose; a driver name pins one.
masks before the frame is drawn.
`core/render/nk_sdl3_renderer.h` is Nuklear's SDL3 backend, vendored because
one change sits inside `nk_sdl_font_stash_end`. Every deviation is marked
its changes sit inside its functions. 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 from device pixels, `tex_null`
repointed after every bake, a key-up dropped for a key Nuklear does not hold,
shared with the Text module, rectangles from device pixels, 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.
@@ -1349,7 +1437,11 @@ has it:
./build/showcase --font-fallback C:/Windows/Fonts/segoeui.ttf --font-fallback C:/Windows/Fonts/Nirmala.ttc
```
A collection is read at its first font. Without the module,
Load fonts you trust, the application's own or the system's: kb_text_shape
says it is not safe on a font file built to attack it, so a font a user hands
over is a risk. FreeType, which reads and draws every font, is fuzzed
continuously by OSS-Fuzz. A collection is read at its first
font. Without the module,
`reaktor_text_none` breaks after a space, or before the glyph that would not
fit, keeping the glyph `nk_label_wrap` would lose. mojibake is built with only
what is called, and kb_text_shape is one header compiled in `core/text/kb.c`;
@@ -1393,12 +1485,8 @@ None is a bug, and each cost an afternoon.
- **`reaktor_layout_space_begin` does not nest.**
- **`reaktor_image` stretches to its slot**, whatever its raster size.
- **`reaktor_rule_horizontal` fills its widget rect**: the row height is the line.
- **`nk_sdl_font_stash_begin` leaks the atlas it replaces.**
- **`nk_label_wrap` breaks at spaces only**, losing the glyph that overflowed a
line without one; `reaktor_label` breaks its own lines.
- **A merged font joins the atlas's first font**, whichever the call meant.
- **`cfg.range` is read on every glyph lookup**, so the ranges live as long as
the fonts; `App` holds them.
- **Edit state lives on the window**, so the page's window misses every field
inside a group; `app->editing` is what navigation asks.
- **`nk_edit_string` leaves the bytes past the length alone**, so a field's
+11 -1
View File
@@ -42,6 +42,7 @@
**Debugging**
- [How do I capture a screenshot or accessibility dump for a bug report?](#how-do-i-capture-a-screenshot-or-accessibility-dump-for-a-bug-report)
- [Should my app use a GPU renderer?](#should-my-app-use-a-gpu-renderer)
- [Why is the frame time high on a machine with no GPU?](#why-is-the-frame-time-high-on-a-machine-with-no-gpu)
- [Why does Japanese or Arabic text draw differently from Latin?](#why-does-japanese-or-arabic-text-draw-differently-from-latin)
- [How do I report a bug?](#how-do-i-report-a-bug)
@@ -77,7 +78,7 @@ 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.3 MB binary, about 10 MB of RAM, no GPU, and nothing to
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).
@@ -236,6 +237,15 @@ 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 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 `SDL_RenderPresent`, copying the frame to the screen,
+45 -30
View File
@@ -8,35 +8,36 @@ from the project's own license file at the pinned revision.
| 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, font baking, the SDL3 backend, and the stb_truetype the Text module rasterizes with | MIT **or** public domain |
| [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) | The sheet the Styling page swaps in | MIT |
| [Simple.css](https://github.com/kevquirk/simple.css) | Alternative style used in the demo app | MIT |
| [Ionicons](https://github.com/ionic-team/ionicons) | Every icon, as SVG; the seven the widgets draw are compiled in | MIT |
| [FreeType](https://freetype.org) | Reading fonts and drawing their glyphs, for the atlas and the Text module | FreeType License **or** GPL-2.0 — taken under the FreeType License |
| [plutosvg](https://github.com/sammycage/plutosvg) | Rasterizing the SVGs | MIT |
| [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 |
| [ini.h](https://github.com/mattiasgustavsson/libs) | Reading and writing `settings.conf` | MIT or public domain |
| [PDFGen](https://github.com/AndreRenaud/PDFGen) | Writing PDFs, for the print module | Unlicense |
| [ini.h](https://github.com/mattiasgustavsson/libs) | Reading and writing `settings.conf` | MIT **or** public domain |
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 or the render backends Reaktor never selects. Its tray is built: on
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 the Text module rasterizes with Nuklear's
stb_truetype.
`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.
[hamza](https://github.com/saidwho12/hamza) was the first choice of shaper
and is not used: its sources still carry the LGPL headers its MIT license file
replaced, its tables stop short of the Indic scripts, and MSVC cannot compile
it (an empty struct, GNU range designators).
Portions of this software are copyright © 2026 The FreeType Project
(https://freetype.org). All rights reserved.
## The one dependency that is not a submodule
@@ -48,10 +49,10 @@ as on a desktop with no accessibility bus.
| --- | --- |
| [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 a permissive license with an attribution requirement, which this
table meets, and a patent-termination clause. It is not GPL-compatible, which
matters to a GPL downstream, not to an MIT project. The alternative was ATK:
LGPL, and being retired in favor of speaking AT-SPI directly.
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
@@ -60,15 +61,28 @@ LGPL, and being retired in favor of speaking AT-SPI directly.
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, `tex_null` repointed after every
bake, a key-up dropped for a key Nuklear does not hold, text input of any
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 because the first change is inside
`nk_sdl_font_stash_end`, and submodules are not edited. The cost: when
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.
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
`src/dynapi/SDL_dynapi.h`, with `SDL_DYNAMIC_API` 0. No SDL file is edited.
CMake stops if that header ever opens with another guard.
## Fonts
Fonts are the exception to the submodule rule, for a license's sake: the old
@@ -84,7 +98,7 @@ 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
stb_truetype reads.
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
@@ -112,9 +126,9 @@ attribution, and the page prints it under the story.
## The mark
`assets/icons/` is original work under this project's MIT license, as SVG, PNG
and `.ico`. Its colors are USWDS system tokens, public domain as a U.S.
Government work.
`assets/icons/`, the Reaktor mark, is original work under this project's MIT
license, as SVG, PNG and `.ico`. Its colors are USWDS system tokens, public
domain as a U.S. Government work.
## Benchmarks
@@ -124,10 +138,10 @@ each toolchain fetches its own framework, and none is part of a Reaktor build.
## What is redistributed
A native build links SDL, libcss, yutil, plutosvg and plutovg statically, plus
mojibake and kb_text_shape with the Text module, and compiles in Nuklear,
NukAnim, Onlay and ini.h, and PDFGen with the print module, so it carries the
zlib, MIT and Unlicense terms above. Each license
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.
@@ -140,6 +154,7 @@ 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. The
WebAssembly build packs the ones it uses into its `.data` bundle.
embedded (the catalogs are with `-DREAKTOR_LOCALE_EMBED=ON`); a build that
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.
+70 -65
View File
@@ -1,16 +1,18 @@
# Performance
**Every pixel is drawn by the CPU.** Nuklear turns the widgets into shapes and
SDL's software rasterizer fills them in; no GPU is required anywhere, for the
reasons in [the renderer](DOCUMENTATION.md#the-renderer).
**By default, every pixel is drawn by the CPU.** Nuklear turns the widgets into
shapes and SDL's software rasterizer fills them in; no GPU is required
anywhere, for the reasons in [the renderer](DOCUMENTATION.md#the-renderer).
`--renderer` hands the drawing to the GPU instead, through Direct3D, OpenGL or
Metal; [Against the others](#against-the-others) measures both.
**Nothing is drawn until something changes.** The app sleeps on the event
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.
On Windows today, `showcase.exe` is 3,473,408 bytes, `notepad.exe` 2,491,392,
`simple.exe` 2,456,064 and `bench.exe` 2,447,360. The showcase links all three
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
@@ -20,41 +22,46 @@ the one all four programs share.
## Against the others
![Two bar charts of drawing 64 rotating boxes at 60 fps in an 800x600 window.
Memory: Reaktor 10.0 MB, the same binary on D3D11 60.7 MB and on OpenGL
90.2 MB, Flutter 92.2 MB, Electron 158.3 MB, Kotlin Multiplatform 669.8 MB.
CPU as a percent of one core: Reaktor 16.4%, D3D11 14.4%, OpenGL 14.1%,
Flutter 16.6%, Electron 39.0%, Kotlin Multiplatform 56.1%](benchmark.svg)
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, run on one machine by one procedure;
[`benchmarks/`](../benchmarks/BENCHMARKS.md) has the projects and the runner.
Reaktor appears three times because `--renderer` changes what it is. 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, one core |
| --- | --- | --- |
| **Reaktor**, `software` | **10.0 MB** | **16.4%** |
| **Reaktor**, `direct3d11` | 60.7 MB | 14.4% |
| **Reaktor**, `opengl` | 90.2 MB | 14.1% |
| Flutter | 92.2 MB | 16.6% |
| Electron | 158.3 MB | 39.0% |
| Kotlin Multiplatform | 669.8 MB | 56.1% |
| 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% |
- **A ninth of Flutter's memory**, a sixty-seventh of Compose's, and the
cheapest arm on CPU after Reaktor's own GPU backends.
- **The GPU backends buy about two points of CPU for six to nine times the
memory**, which is why the default stays software. On a GPU driver Reaktor
costs what the GPU frameworks do: `opengl` is 90.2 MB against Flutter's
92.2, and the three GPU arms fall within 2.5 points on CPU. At that size the
number is the GL context and its buffers, not the framework.
- **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: 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. These runs had the GeForce RTX 2060 idle.
**The top row used to read 67.3%**, and not from rasterizing. `nk_convert`
turns every shape into triangles, so a panel background reached SDL as two
textured, blended triangles over the window: **16.38 ms**, against **6.95 ms**
untextured and **0.12 ms** as a fill. The renderer now fills an axis-aligned
quad of one color, unblended when opaque. A frame of this benchmark went from
**11.48 ms to 2.12 ms** and an empty window from 8.06 to 0.54 ms, with pixels
within one least significant bit. Only measuring the present found it.
`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
@@ -62,14 +69,15 @@ within one least significant bit. Only measuring the present found it.
./benchmarks/run.ps1 -Seconds 6 -Fps 60 -Runs 10
```
Every arm is held to 60 fps and sleeps out each frame, so it is charged for
drawing, not waiting. Each figure is the median of ten 6-second runs; across
three passes CPU moved by up to three points and memory by under a megabyte.
Memory is peak summed private bytes across the process tree; the JVM has no
heap flags. The sampler, not the apps' own counters, sets the bars: those miss
driver threads and presentation — for `direct3d11`, `bench` extrapolated 2.5%
of a core where the sampler charged 16.5%. `direct3d12` and `vulkan` fall back
to D3D11 in this SDL build.
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
@@ -145,9 +153,9 @@ in RAM, shared library pages included.
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) in one SysV segment shared with the X server. Its figures are
swap-backed resident from `ps` and `procstat -v`, macOS's from `vmmap`;
`reaktor_process_memory` reads only Windows and Linux.
(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
@@ -170,35 +178,32 @@ Redrawing continuously at 960×680, p10–p90 of 31 samples:
| 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 pays an extra pass, uploading the
software bitmap to a Metal texture to present it. On GhostBSD most of a frame
is the present — 6.7 ms of Login's 7.1 ms median, 11.1 ms of Buttons' 14.8 —
a software blit into VMware's SVGA II framebuffer.
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). And the
number that made software the default: on the GPU-less VM, `direct3d11` falls
back to WARP and a frame goes from 4.7 ms to **20.3 ms** (before the fill
fix). With a real GPU that reverses — see **Against the others**.
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 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 by walking up to the `.reaktor-root`
marker. The web build packs those into its `.data` and needs an HTTP server,
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** — 11 Pro (26200), x64, MSVC Release, in a VirtualBox VM with no
Direct3D 11 adapter. Everything from **Size** down, and today's sizes, with
MSVC 14.44 (Visual Studio 2022 Build Tools) and emscripten 6.0.9 for those
and **Modules**.
- **Windows, with a GPU** — 11 Pro (26200), x64, MSVC Release, Ryzen 5 4600H
(6 cores, 12 threads), GeForce RTX 2060, 1920×1080 at 120 Hz, no scaling.
Everything in **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.
- **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`.
+38 -32
View File
@@ -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.446" width="46" height="3.55356" fill="#56c7ff"/>
<text x="122.5" y="418.446" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="21" font-weight="600" fill="#ffffff">10.0 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-15.5701 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v15.5701 z" fill="#56c7ff"/>
<text x="228.5" y="400.43" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="21" font-weight="600" fill="#ffffff">60.7 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">D3D11</text>
<path d="M311.5 452 v-26.0354 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v26.0354 z" fill="#56c7ff"/>
<text x="334.5" y="389.965" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="21" font-weight="600" fill="#ffffff">90.2 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-26.7461 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v26.7461 z" fill="#6e7a82"/>
<text x="440.5" y="389.254" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="21" font-weight="600" fill="#ffffff">92.2 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-50.2352 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v50.2352 z" fill="#6e7a82"/>
<text x="546.5" y="365.765" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="21" font-weight="600" fill="#ffffff">158.3 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="21" font-weight="600" fill="#ffffff">669.8 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</text>
<path d="M824.5 452 v-63.3636 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v63.3636 z" fill="#56c7ff"/>
<text x="847.5" y="352.636" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="21" font-weight="600" fill="#ffffff">16.4%</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-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-54.8788 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v54.8788 z" fill="#56c7ff"/>
<text x="953.5" y="361.121" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="21" font-weight="600" fill="#ffffff">14.4%</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">D3D11</text>
<path d="M1036.5 452 v-53.8182 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v53.8182 z" fill="#56c7ff"/>
<text x="1059.5" y="362.182" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="21" font-weight="600" fill="#ffffff">14.1%</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-64.2121 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v64.2121 z" fill="#6e7a82"/>
<text x="1165.5" y="351.788" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="21" font-weight="600" fill="#ffffff">16.6%</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-159.242 a6 6 0 0 1 6 -6 h34 a6 6 0 0 1 6 6 v159.242 z" fill="#6e7a82"/>
<text x="1271.5" y="256.758" text-anchor="middle" font-family="Segoe UI, -apple-system, Helvetica Neue, Arial, sans-serif" font-size="21" font-weight="600" fill="#ffffff">39.0%</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="21" font-weight="600" fill="#ffffff">56.1%</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 configurations against the alternatives from other tech stacks, 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.0 KiB

After

Width:  |  Height:  |  Size: 7.9 KiB

Vendored Submodule
+1
Submodule external/freetype added at 37515cf56b
+1 -1
-1
Submodule external/pdfgen deleted from b3413daead
+1
View File
@@ -103,6 +103,7 @@ typedef struct reaktor_launch {
void *user;
int remember_window;
int single_instance;
int skip_same_frames;
reaktor_save save_settings;
int save_ms;
} reaktor_launch;
-2
View File
@@ -7,8 +7,6 @@
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_COMMAND_USERDATA
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_DEFAULT_FONT
/* A browser delivers press and release in one task. */
#define NK_BUTTON_TRIGGER_ON_RELEASE
+1
View File
@@ -8,6 +8,7 @@
#include "reaktor/a11y.h"
#include "reaktor/ui.h"
#include "reaktor/anim.h"
#include "reaktor/test.h"
#include "reaktor/locale.h"
#include "reaktor/style.h"
#include "reaktor/text.h"
+23
View File
@@ -0,0 +1,23 @@
#ifndef REAKTOR_TEST_H
#define REAKTOR_TEST_H
#include "reaktor/launch.h"
typedef struct reaktor_test reaktor_test;
typedef void (*reaktor_test_script)(reaktor_test *t, void *user);
int reaktor_test_app(int argc, char **argv, const reaktor_launch *launch,
reaktor_test_script script, void *user);
int reaktor_test_find(reaktor_test *t, const char *target);
int reaktor_test_click(reaktor_test *t, const char *target);
int reaktor_test_type(reaktor_test *t, const char *target, const char *text);
int reaktor_test_key(reaktor_test *t, const char *chord);
int reaktor_test_value(reaktor_test *t, const char *target, char *out, int cap);
unsigned reaktor_test_state(reaktor_test *t, const char *target);
void reaktor_test_settle(reaktor_test *t);
int reaktor_test_check(reaktor_test *t, int ok, const char *what);
App *reaktor_test_app_of(reaktor_test *t);
#endif
+9
View File
@@ -5,6 +5,7 @@
#include "reaktor/nuklear.h"
#include "reaktor/a11y.h"
#include "reaktor/widgets.h"
#ifndef REAKTOR_APP_FWD
#define REAKTOR_APP_FWD
@@ -18,6 +19,7 @@ enum {
REAKTOR_RSS_ICON,
REAKTOR_RSS_NUKLEAR,
REAKTOR_RSS_FONT,
REAKTOR_RSS_START,
REAKTOR_RSS_STYLE,
REAKTOR_RSS_STEPS
};
@@ -68,6 +70,12 @@ int reaktor_button_label(App *app, struct reaktor_context *ctx,
const char *label);
int reaktor_button_icon(App *app, struct reaktor_context *ctx,
const char *ionicon, const char *label);
int reaktor_button_accent_icon(App *app, struct reaktor_context *ctx,
const char *ionicon, const char *label);
float reaktor_button_width(App *app, struct reaktor_context *ctx,
const char *ionicon, const char *label);
int reaktor_button_custom(App *app, struct reaktor_context *ctx, const char *name,
reaktor_button_paint paint, void *user);
reaktor_flags reaktor_field_text(App *app, struct reaktor_context *ctx,
reaktor_flags flags,
char *buf, int *len, int cap, const char *hint,
@@ -233,6 +241,7 @@ typedef struct reaktor_diag {
float frame_gap_ms;
float cpu_ms_per_frame;
int hover_gap_ms;
unsigned long frames_drawn, frames_skipped;
unsigned long nk_bytes, nk_used, icon_bytes;
unsigned long rss_bytes, private_bytes;
int icons;
+8
View File
@@ -33,6 +33,7 @@ typedef struct reaktor_box {
float gap;
float ml, mt, mr, mb;
unsigned flags;
const char *mark;
} reaktor_box;
void reaktor_box_open(unsigned char dir, const reaktor_box *b);
@@ -66,6 +67,10 @@ typedef struct reaktor_handler {
enum { REAKTOR_LEFT = 0, REAKTOR_CENTER, REAKTOR_RIGHT };
typedef void (*reaktor_button_paint)(App *app, struct reaktor_command_buffer *cv,
struct reaktor_rect content,
struct reaktor_color ink, void *user);
typedef struct reaktor_button_spec {
const char *label;
const char *icon;
@@ -80,6 +85,8 @@ typedef struct reaktor_button_spec {
unsigned char repeat;
unsigned char fit_content;
unsigned char flat;
reaktor_button_paint paint;
void *paint_user;
} reaktor_button_spec;
int reaktor_button(const reaktor_button_spec *s);
@@ -286,6 +293,7 @@ void reaktor_color_pick(const reaktor_color_spec *s);
typedef struct reaktor_link_spec {
const char *text;
const char *url;
const char *schemes;
const char *name;
const char *style;
reaktor_box box;
+3 -1
View File
@@ -3,6 +3,8 @@
#include <string.h>
#include <SDL3/SDL.h>
#include "util.h"
typedef struct snap_node {
unsigned id, parent;
unsigned char role, level;
@@ -204,7 +206,7 @@ copy_text(const reaktor_snap *s, int at, char **buf, size_t *left)
if (at < 0 || *left < 2) return NULL;
/* libdbus aborts on invalid UTF-8. */
n = SDL_utf8strlcpy(*buf, s->str + at, *left);
n = reaktor_utf8_clean(*buf, s->str + at, *left);
{
const char *out = *buf;
*buf += n + 1;
+17 -6
View File
@@ -104,20 +104,28 @@ notify_os(App *app, const char *title, const char *body)
const char *name = reaktor_app_ident(), *icon = "";
dbus_uint32_t replaces = 0;
dbus_int32_t expire = -1;
int ok;
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 (!(c = dbus_bus_get(DBUS_BUS_SESSION, NULL))) return 0;
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) return 0;
if (!m) {
dbus_connection_unref(c);
goto done;
}
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, &title);
dbus_message_iter_append_basic(&it, DBUS_TYPE_STRING, &body);
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);
@@ -127,7 +135,10 @@ notify_os(App *app, const char *title, const char *body)
dbus_connection_flush(c);
dbus_message_unref(m);
dbus_connection_unref(c);
return ok ? 1 : 0;
done:
SDL_free(t);
SDL_free(b);
return ok;
}
#elif defined(__APPLE__)
+1 -1
View File
@@ -184,7 +184,7 @@ int reaktor_window_set_dark(SDL_Window *win, int dark)
if (!native_window) return 0;
if (!looked_up) {
void *dll = (void *)LoadLibraryA("dwmapi.dll");
void *dll = (void *)LoadLibraryExA("dwmapi.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (dll)
set_attr = (set_attr_fn)(void *)GetProcAddress(
(HMODULE)dll, "DwmSetWindowAttribute");
+171 -12
View File
@@ -22,6 +22,7 @@ effective_dark(const App *app)
size_t reaktor_rss[REAKTOR_RSS_STEPS];
size_t reaktor_priv[REAKTOR_RSS_STEPS];
void (*reaktor_test_hook)(App *app);
static reaktor_launch g_launch;
static App *g_app;
static int g_started, g_stopped;
@@ -825,7 +826,9 @@ app_init(void **appstate, int argc, char *argv[])
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_strcmp(app->renderer_pref, "auto") != 0)
if (SDL_strcasecmp(app->renderer_pref, "directx") == 0)
reaktor_hint(SDL_HINT_RENDER_DRIVER, "direct3d12,direct3d11");
else if (SDL_strcmp(app->renderer_pref, "auto") != 0)
reaktor_hint(SDL_HINT_RENDER_DRIVER, app->renderer_pref);
} else {
SDL_strlcpy(app->render_mode, "auto: software",
@@ -950,6 +953,7 @@ app_init(void **appstate, int argc, char *argv[])
return SDL_APP_FAILURE;
}
}
reaktor_rss_mark(REAKTOR_RSS_START);
take_pending(app);
load_theme(app);
@@ -1010,6 +1014,23 @@ 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:
case SDL_EVENT_RENDER_TARGETS_RESET:
case SDL_EVENT_RENDER_DEVICE_RESET:
app->must_draw = 1;
break;
default:
break;
}
switch (event->type) {
case SDL_EVENT_MOUSE_MOTION:
if (app->dragging) { app->drag_moved = 1; app->dirty = 1; }
@@ -1301,6 +1322,137 @@ 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.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);
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;
}
static int
take_shot(App *app)
{
@@ -1449,6 +1601,7 @@ reaktor_app_frame(App *app, int win_w, int win_h, const char *title,
if (is_main) {
reaktor_a11y_platform_push(&app->a11y, app->focus_id);
a11y_dump_once(app);
if (reaktor_test_hook) reaktor_test_hook(app);
reaktor_inspector_frame(app);
} else {
reaktor_a11y_platform_window_push(app->win, &app->a11y, app->focus_id,
@@ -1473,16 +1626,22 @@ reaktor_app_frame(App *app, int win_w, int win_h, const char *title,
f = SDL_GetPerformanceFrequency();
t_render0 = SDL_GetPerformanceCounter();
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) {
app->capture = SDL_RenderReadPixels(app->ren, NULL);
app->want_capture = 0;
if (same_frame(app, ctx)) {
t_present0 = t_end = t_render0;
app->frames_skipped++;
} else {
app->frames_drawn++;
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) {
app->capture = SDL_RenderReadPixels(app->ren, NULL);
app->want_capture = 0;
}
SDL_RenderPresent(app->ren);
t_end = SDL_GetPerformanceCounter();
}
SDL_RenderPresent(app->ren);
t_end = SDL_GetPerformanceCounter();
app->last_draw_ms = SDL_GetTicks();
if (is_main && app->first_frame_done) calibrate_hover_gap(app);
@@ -1602,12 +1761,12 @@ app_quit(void *appstate, SDL_AppResult result)
}
if (app->ren) img_cache_free(app);
if (app->ctx) nk_sdl_shutdown(app->ctx);
reaktor_fontset_free(&app->fonts);
if (app->ren) SDL_DestroyRenderer(app->ren);
if (app->win) SDL_DestroyWindow(app->win);
reaktor_anim_destroy(app->anim);
app->anim = NULL;
/* The picker's thread still writes into it. */
if (!app->file_pending) SDL_free(app);
reaktor_app_free(app);
g_app = NULL;
reaktor_signal_unwatch();
reaktor_process_end();
+141 -40
View File
@@ -6,6 +6,7 @@
#ifndef __EMSCRIPTEN__
#define INSTANCE_PATH_MAX 4096
#define INSTANCE_PATHS_MAX 64
#define INSTANCE_READ_MS 2000
static void (*g_opened)(App *app, const char *path);
@@ -34,17 +35,17 @@ receive(App *app, instance_read rd, void *conn)
Uint32 count = 0, i, len;
char *path;
if (rd(conn, &count, sizeof count) && count <= INSTANCE_PATHS_MAX) {
for (i = 0; i < count; i++) {
if (!rd(conn, &len, sizeof len) || len == 0 || len >= INSTANCE_PATH_MAX) break;
if (!(path = (char *)SDL_malloc(len + 1))) break;
if (!rd(conn, path, len)) {
SDL_free(path);
break;
}
path[len] = 0;
reaktor_post(app, deliver_path, path);
if (!rd(conn, &count, sizeof count)) return;
if (count > INSTANCE_PATHS_MAX) count = 0;
for (i = 0; i < count; i++) {
if (!rd(conn, &len, sizeof len) || len == 0 || len >= INSTANCE_PATH_MAX) break;
if (!(path = (char *)SDL_malloc(len + 1))) break;
if (!rd(conn, path, len)) {
SDL_free(path);
break;
}
path[len] = 0;
reaktor_post(app, deliver_path, path);
}
reaktor_post(app, deliver_raise, NULL);
}
@@ -98,16 +99,52 @@ message(int argc, char **argv, char **out, Uint32 *out_len)
static HANDLE g_mutex;
static char g_pipe[256];
static SDL_Thread *g_thread;
static SDL_AtomicInt g_stop;
static HANDLE g_stop;
typedef struct pipe_conn { HANDLE pipe, event; } pipe_conn;
union token_user_buf {
TOKEN_USER user;
BYTE raw[sizeof(TOKEN_USER) + SECURITY_MAX_SID_SIZE];
};
static void
pipe_arm(OVERLAPPED *o, HANDLE event)
{
SDL_zero(*o);
o->hEvent = event;
ResetEvent(event);
}
static int
pipe_wait(HANDLE pipe, OVERLAPPED *o, DWORD ms, DWORD *got)
{
HANDLE wait[2];
wait[0] = o->hEvent;
wait[1] = g_stop;
if (WaitForMultipleObjects(2, wait, FALSE, ms) == WAIT_OBJECT_0 &&
GetOverlappedResult(pipe, o, got, FALSE))
return 1;
CancelIoEx(pipe, o);
GetOverlappedResult(pipe, o, got, TRUE);
return 0;
}
static int
pipe_read(void *conn, void *buf, Uint32 n)
{
DWORD got = 0;
char *p = (char *)buf;
pipe_conn *c = (pipe_conn *)conn;
char *p = (char *)buf;
while (n) {
if (!ReadFile((HANDLE)conn, p, n, &got, NULL) || !got) return 0;
OVERLAPPED o;
DWORD got = 0;
pipe_arm(&o, c->event);
if (!ReadFile(c->pipe, p, n, NULL, &o) && GetLastError() != ERROR_IO_PENDING)
return 0;
if (!pipe_wait(c->pipe, &o, INSTANCE_READ_MS, &got) || !got) return 0;
p += got;
n -= got;
}
@@ -124,6 +161,33 @@ names(void)
SDL_snprintf(g_pipe, sizeof g_pipe, "\\\\.\\pipe\\reaktor.%lu.%08x", (unsigned long)session, h);
}
static int
token_user(HANDLE process, union token_user_buf *out)
{
HANDLE token;
DWORD len = 0;
int ok;
if (!OpenProcessToken(process, TOKEN_QUERY, &token)) return 0;
ok = GetTokenInformation(token, TokenUser, out, sizeof *out, &len);
CloseHandle(token);
return ok;
}
static int
same_user(ULONG pid)
{
union token_user_buf mine, theirs;
HANDLE process = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);
int ok;
if (!process) return 0;
ok = token_user(process, &theirs) && token_user(GetCurrentProcess(), &mine) &&
EqualSid(mine.user.User.Sid, theirs.user.User.Sid);
CloseHandle(process);
return ok;
}
int
reaktor_instance_claim(int argc, char **argv)
{
@@ -144,7 +208,8 @@ reaktor_instance_claim(int argc, char **argv)
/* 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, 0, NULL);
pipe = CreateFileA(g_pipe, GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION, NULL);
if (pipe != INVALID_HANDLE_VALUE) break;
if (GetLastError() == ERROR_PIPE_BUSY) WaitNamedPipeA(g_pipe, 200);
else Sleep(100);
@@ -153,7 +218,12 @@ reaktor_instance_claim(int argc, char **argv)
SDL_Log("single instance: the running copy did not answer; starting another");
return 1;
}
if (GetNamedPipeServerProcessId(pipe, &server)) AllowSetForegroundWindow(server);
if (!GetNamedPipeServerProcessId(pipe, &server) || !same_user(server)) {
SDL_Log("single instance: %s belongs to another user; starting another", g_pipe);
CloseHandle(pipe);
return 1;
}
AllowSetForegroundWindow(server);
if (message(argc, argv, &msg, &len)) WriteFile(pipe, msg, len, &wrote, NULL);
SDL_free(msg);
CloseHandle(pipe);
@@ -163,21 +233,35 @@ reaktor_instance_claim(int argc, char **argv)
static int SDLCALL
listen_thread(void *data)
{
App *app = (App *)data;
App *app = (App *)data;
pipe_conn c;
while (!SDL_GetAtomicInt(&g_stop)) {
HANDLE p = CreateNamedPipeA(g_pipe, PIPE_ACCESS_INBOUND,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT |
PIPE_REJECT_REMOTE_CLIENTS,
PIPE_UNLIMITED_INSTANCES, 0, 64 * 1024, 0, NULL);
c.event = CreateEventA(NULL, TRUE, FALSE, NULL);
if (!c.event) return 0;
while (WaitForSingleObject(g_stop, 0) != WAIT_OBJECT_0) {
OVERLAPPED o;
DWORD none = 0;
int connected;
if (p == INVALID_HANDLE_VALUE) return 0;
if (ConnectNamedPipe(p, NULL) || GetLastError() == ERROR_PIPE_CONNECTED) {
if (!SDL_GetAtomicInt(&g_stop)) receive(app, pipe_read, p);
c.pipe = CreateNamedPipeA(g_pipe, PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED |
FILE_FLAG_FIRST_PIPE_INSTANCE,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT |
PIPE_REJECT_REMOTE_CLIENTS,
PIPE_UNLIMITED_INSTANCES, 0, 64 * 1024, 0, NULL);
if (c.pipe == INVALID_HANDLE_VALUE) {
SDL_Log("single instance: %s is held by another process; not listening", g_pipe);
break;
}
DisconnectNamedPipe(p);
CloseHandle(p);
pipe_arm(&o, c.event);
connected = ConnectNamedPipe(c.pipe, &o) ||
GetLastError() == ERROR_PIPE_CONNECTED ||
(GetLastError() == ERROR_IO_PENDING &&
pipe_wait(c.pipe, &o, INFINITE, &none));
if (connected) receive(app, pipe_read, &c);
DisconnectNamedPipe(c.pipe);
CloseHandle(c.pipe);
}
CloseHandle(c.event);
return 0;
}
@@ -186,6 +270,7 @@ reaktor_instance_listen(App *app, void (*opened)(App *app, const char *path))
{
g_opened = opened;
if (!g_mutex || g_thread) return;
if (!g_stop && !(g_stop = CreateEventA(NULL, TRUE, FALSE, NULL))) return;
g_thread = SDL_CreateThread(listen_thread, "reaktor-instance", app);
}
@@ -193,15 +278,14 @@ void
reaktor_instance_stop(void)
{
if (g_thread) {
HANDLE p;
SDL_SetAtomicInt(&g_stop, 1);
/* The listener waits in ConnectNamedPipe; one connection releases it. */
p = CreateFileA(g_pipe, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (p != INVALID_HANDLE_VALUE) CloseHandle(p);
SetEvent(g_stop);
SDL_WaitThread(g_thread, NULL);
g_thread = NULL;
}
if (g_stop) {
CloseHandle(g_stop);
g_stop = NULL;
}
if (g_mutex) {
ReleaseMutex(g_mutex);
CloseHandle(g_mutex);
@@ -212,6 +296,8 @@ reaktor_instance_stop(void)
#elif !defined(__EMSCRIPTEN__)
#include <errno.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/un.h>
#include <unistd.h>
@@ -236,18 +322,29 @@ sock_read(void *conn, void *buf, Uint32 n)
return 1;
}
/* Beside the app's settings when that fits a socket's path, in /tmp by user otherwise. */
/* 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)
{
char *dir = SDL_GetPrefPath(NULL, reaktor_app_ident());
int n = -1;
char *dir = SDL_GetPrefPath(NULL, reaktor_app_ident());
char own[64];
struct stat st;
int n = -1;
if (dir) n = SDL_snprintf(g_sock, sizeof g_sock, "%sinstance.sock", dir);
SDL_free(dir);
if (n < 0 || (size_t)n >= sizeof g_sock)
n = SDL_snprintf(g_sock, sizeof g_sock, "/tmp/reaktor.%lu.%08x.sock",
(unsigned long)getuid(), reaktor_fnv(REAKTOR_FNV, reaktor_app_ident()));
if (n > 0 && (size_t)n < sizeof g_sock) return 1;
SDL_snprintf(own, sizeof own, "/tmp/reaktor-%lu", (unsigned long)getuid());
if (mkdir(own, 0700) != 0 && errno != EEXIST) return 0;
if (lstat(own, &st) != 0 || !S_ISDIR(st.st_mode) || st.st_uid != getuid() ||
(st.st_mode & 077)) {
SDL_Log("single instance: %s is not this user's own; not listening", own);
return 0;
}
n = SDL_snprintf(g_sock, sizeof g_sock, "%s/%08x.sock", own,
reaktor_fnv(REAKTOR_FNV, reaktor_app_ident()));
return n > 0 && (size_t)n < sizeof g_sock;
}
@@ -307,8 +404,11 @@ reaktor_instance_claim(int argc, char **argv)
static int SDLCALL
listen_thread(void *data)
{
App *app = (App *)data;
App *app = (App *)data;
struct timeval tv;
tv.tv_sec = INSTANCE_READ_MS / 1000;
tv.tv_usec = (INSTANCE_READ_MS % 1000) * 1000;
while (!SDL_GetAtomicInt(&g_stop)) {
int c = accept(g_listen, NULL, NULL);
@@ -316,6 +416,7 @@ listen_thread(void *data)
if (errno == EINTR) continue;
break;
}
setsockopt(c, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof tv);
if (!SDL_GetAtomicInt(&g_stop)) receive(app, sock_read, &c);
close(c);
}
-8
View File
@@ -1,8 +0,0 @@
/* PDFGen as it ships, minus one clash: NetBSD's <sys/types.h> declares a
bswap32 and wraps it in a macro, and PDFGen defines a static function of
that name. PDFGen's is renamed; the header's guard keeps it from coming back. */
#include <sys/types.h>
#undef bswap32
#define bswap32 pdfgen_bswap32
#include "pdfgen.c"
+125 -31
View File
@@ -1,7 +1,6 @@
#include "internal.h"
#include "reaktor/launch.h"
#include "declare.h"
#include "pdfgen.h"
#include "plutovg.h"
#define REAKTOR_PRINT_PAGES 64
@@ -17,10 +16,11 @@ typedef struct print_job {
int index, to_printer;
} print_job;
typedef struct jpeg_buf {
typedef struct buffer {
unsigned char *bytes;
size_t len, cap;
} jpeg_buf;
int failed;
} buffer;
static void
print_page(App *app, struct nk_context *ctx, int w, int h, void *user)
@@ -31,15 +31,19 @@ print_page(App *app, struct nk_context *ctx, int w, int h, void *user)
}
static void
jpeg_put(void *closure, void *data, int size)
put_bytes(void *closure, void *data, int size)
{
jpeg_buf *b = (jpeg_buf *)closure;
buffer *b = (buffer *)closure;
if (b->failed || size <= 0) return;
if (b->len + (size_t)size > b->cap) {
size_t cap = (b->len + (size_t)size) * 2;
unsigned char *more = (unsigned char *)SDL_realloc(b->bytes, cap);
if (!more) return;
if (!more) {
b->failed = 1;
return;
}
b->bytes = more;
b->cap = cap;
}
@@ -47,6 +51,118 @@ jpeg_put(void *closure, void *data, int size)
b->len += (size_t)size;
}
static void
put(buffer *b, const char *fmt, ...)
{
char line[256];
va_list ap;
int n;
va_start(ap, fmt);
n = SDL_vsnprintf(line, sizeof line, fmt, ap);
va_end(ap);
if (n < 0 || n >= (int)sizeof line) b->failed = 1;
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)
{
size_t left = SDL_strlen(s);
const char *p;
for (p = s; *p; p++)
if ((unsigned char)*p < 0x20 || (unsigned char)*p > 0x7E ||
*p == '(' || *p == ')' || *p == '\\')
break;
if (!*p) {
put(b, "(");
put_bytes(b, (void *)s, (int)left);
put(b, ")");
return;
}
put(b, "<FEFF");
while (left) {
Uint32 c = SDL_StepUTF8(&s, &left);
if (c > 0xFFFF) put(b, "%04X%04X", 0xD800 + ((c - 0x10000) >> 10), 0xDC00 + (c & 0x3FF));
else if (c) put(b, "%04X", c);
}
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)
{
buffer pdf = { NULL, 0, 0, 0 };
size_t at[4 + 3 * REAKTOR_PRINT_PAGES], xref, k;
SDL_Time now;
SDL_DateTime t;
Uint64 id = 0xcbf29ce484222325u;
int objects = 3 + 3 * n, i, ok;
put(&pdf, "%%PDF-1.3\n%%\xE2\xE3\xCF\xD3\n");
at[1] = pdf.len;
put(&pdf, "1 0 obj\n<< /Creator (Reaktor)");
if (title && *title) {
put(&pdf, " /Title ");
put_text(&pdf, title);
}
if (SDL_GetCurrentTime(&now) && SDL_TimeToDateTime(now, &t, false))
put(&pdf, " /CreationDate (D:%04d%02d%02d%02d%02d%02dZ)", t.year, t.month, t.day,
t.hour, t.minute, t.second);
put(&pdf, " >>\nendobj\n");
at[2] = pdf.len;
put(&pdf, "2 0 obj\n<< /Type /Pages /Count %d /Kids [", n);
for (i = 0; i < n; i++) put(&pdf, " %d 0 R", 4 + 3 * i);
put(&pdf, " ] >>\nendobj\n");
at[3] = pdf.len;
put(&pdf, "3 0 obj\n<< /Type /Catalog /Pages 2 0 R >>\nendobj\n");
for (i = 0; i < n && !pdf.failed; i++) {
plutovg_surface_t *s = plutovg_surface_create_for_data(page[i]->pixels, page[i]->w,
page[i]->h, page[i]->pitch);
buffer jpg = { NULL, 0, 0, 0 };
char draw[96];
int o = 4 + 3 * i, len;
if (s) plutovg_surface_write_to_jpg_stream(s, put_bytes, &jpg, 90);
plutovg_surface_destroy(s);
len = SDL_snprintf(draw, sizeof draw, "q %.4f 0 0 %.4f 0 0 cm /Im Do Q",
(double)pt_w, (double)pt_h);
if (!jpg.len || jpg.failed) pdf.failed = 1;
at[o] = pdf.len;
put(&pdf, "%d 0 obj\n<< /Type /Page /Parent 2 0 R /MediaBox [0 0 %.4f %.4f]", o,
(double)pt_w, (double)pt_h);
put(&pdf, " /Resources << /XObject << /Im %d 0 R >> >> /Contents %d 0 R >>\nendobj\n",
o + 1, o + 2);
at[o + 1] = pdf.len;
put(&pdf, "%d 0 obj\n<< /Type /XObject /Subtype /Image /Width %d /Height %d", o + 1,
page[i]->w, page[i]->h);
put(&pdf, " /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode"
" /Length %zu >>\nstream\n", jpg.len);
put_bytes(&pdf, jpg.bytes, (int)jpg.len);
put(&pdf, "\nendstream\nendobj\n");
at[o + 2] = pdf.len;
put(&pdf, "%d 0 obj\n<< /Length %d >>\nstream\n%s\nendstream\nendobj\n", o + 2, len, draw);
SDL_free(jpg.bytes);
}
xref = pdf.len;
put(&pdf, "xref\n0 %d\n0000000000 65535 f \n", objects + 1);
for (i = 1; i <= objects; i++) put(&pdf, "%010zu 00000 n \n", at[i]);
for (k = 0; k < pdf.len; k++) id = (id ^ pdf.bytes[k]) * 0x100000001b3u;
put(&pdf, "trailer\n<< /Size %d /Root 3 0 R /Info 1 0 R", objects + 1);
put(&pdf, " /ID [<%016" SDL_PRIx64 "> <%016" SDL_PRIx64 ">] >>\n", id, id);
put(&pdf, "startxref\n%zu\n%%%%EOF\n", xref);
ok = !pdf.failed && SDL_SaveFile(path, pdf.bytes, pdf.len);
SDL_free(pdf.bytes);
return ok;
}
#ifdef _WIN32
/* The system's print dialog, then each page stretched over the printable area. */
static int
@@ -105,7 +221,6 @@ print_run(App *app, void *user)
print_job *job = (print_job *)user;
float keep = reaktor_scale(), pt_w = job->spec.w, pt_h = job->spec.h;
SDL_Surface *page[REAKTOR_PRINT_PAGES];
struct pdf_doc *doc = NULL;
App *pa = NULL;
int id, i, n = 0, ok = 1;
@@ -138,32 +253,11 @@ print_run(App *app, void *user)
ok = print_win32(app, page, n, job->spec.title ? job->spec.title : "Reaktor");
else
#endif
if (ok) {
struct pdf_info info;
SDL_zero(info);
SDL_strlcpy(info.creator, "Reaktor", sizeof info.creator);
if (job->spec.title) SDL_strlcpy(info.title, job->spec.title, sizeof info.title);
doc = pdf_create(pt_w, pt_h, &info);
}
for (i = 0; doc && ok && i < n; i++) {
plutovg_surface_t *s = plutovg_surface_create_for_data(page[i]->pixels, page[i]->w,
page[i]->h, page[i]->pitch);
jpeg_buf b = { NULL, 0, 0 };
struct pdf_object *p = pdf_append_page(doc);
if (s) plutovg_surface_write_to_jpg_stream(s, jpeg_put, &b, 90);
plutovg_surface_destroy(s);
if (!p || !b.len ||
pdf_add_image_data(doc, p, 0, 0, pt_w, pt_h, b.bytes, b.len) < 0) ok = 0;
SDL_free(b.bytes);
}
if (doc && ok) ok = pdf_save(doc, job->path) >= 0;
if (doc) pdf_destroy(doc);
if (ok) ok = pdf_write(job->path, job->spec.title, page, n, pt_w, pt_h);
#if defined(__APPLE__)
if (doc && ok && job->to_printer) ok = reaktor_print_macos(job->path);
if (ok && job->to_printer) ok = reaktor_print_macos(job->path);
#elif !defined(_WIN32)
if (doc && ok && job->to_printer) {
if (ok && job->to_printer) {
char *url = NULL;
SDL_asprintf(&url, "file://%s", job->path);
+366
View File
@@ -0,0 +1,366 @@
/* 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"
#define TEST_WAIT_MS 5000
#define TEST_FIND_TRIES 20
struct reaktor_test {
App *app;
SDL_Semaphore *done;
char text[256];
int checks, fails, stuck;
};
typedef struct test_ask {
reaktor_test *t;
char target[256];
reaktor_a11y_node node;
char value[256];
int found;
Uint64 seq;
} test_ask;
static reaktor_test_script g_script;
static void *g_user;
static reaktor_test g_test;
static SDL_Thread *g_thread;
static void *g_settle;
static test_ask g_ask, g_settle_ask;
App *
reaktor_test_app_of(reaktor_test *t)
{
return t->app;
}
static int
wait_main(reaktor_test *t)
{
if (t->stuck) return 0;
if (SDL_WaitSemaphoreTimeout(t->done, TEST_WAIT_MS)) return 1;
SDL_Log("test: the window stopped answering");
t->stuck = 1;
return 0;
}
static int
matches(const reaktor_a11y_node *n, const char *target)
{
if (target[0] == '#') return n->id && reaktor_mark_has(n->id, target + 1);
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)
{
int hops, k;
for (hops = 0; hops < REAKTOR_A11Y_MAX_DEPTH && tree[i].parent; hops++) {
if (reaktor_mark_has(tree[i].parent, scope)) return 1;
for (k = i - 1; k >= 0 && tree[k].id != tree[i].parent; k--) {}
if (k < 0) return 0;
i = k;
}
return 0;
}
static void
look_main(App *app, void *user)
{
test_ask *q = (test_ask *)user;
const reaktor_a11y_node *tree;
int n = 0, i;
char scope[64];
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));
target = space + 1;
scoped = 1;
}
tree = reaktor_a11y_tree(&app->a11y, &n);
q->found = 0;
if (scoped && !reaktor_mark_has(0, scope)) {
SDL_SignalSemaphore(q->t->done);
return;
}
for (i = 0; i < n; i++)
if (matches(&tree[i], target) && (!scoped || within(tree, i, scope))) {
if (!q->found) {
q->node = tree[i];
SDL_strlcpy(q->value, tree[i].value ? tree[i].value : "", sizeof q->value);
}
q->found++;
}
if (q->found > 1)
SDL_Log("test: %d widgets match \"%s\"; the first is used", q->found, q->target);
SDL_SignalSemaphore(q->t->done);
}
void
reaktor_test_settle(reaktor_test *t)
{
if (t->stuck) return;
SDL_zero(g_settle_ask);
g_settle_ask.t = t;
SDL_SetAtomicPointer(&g_settle, &g_settle_ask);
reaktor_wake(t->app);
if (wait_main(t)) SDL_SetAtomicPointer(&g_settle, NULL);
}
static int
look(reaktor_test *t, const char *target, test_ask *q)
{
int tries;
SDL_zero(*q);
if (t->stuck) return 0;
for (tries = 0; tries < TEST_FIND_TRIES; tries++) {
SDL_zero(g_ask);
g_ask.t = t;
SDL_strlcpy(g_ask.target, target, sizeof g_ask.target);
reaktor_post(t->app, look_main, &g_ask);
if (!wait_main(t)) return 0;
*q = g_ask;
if (q->found) return 1;
reaktor_test_settle(t);
if (t->stuck) return 0;
}
return 0;
}
int
reaktor_test_find(reaktor_test *t, const char *target)
{
test_ask q;
return target && look(t, target, &q);
}
int
reaktor_test_value(reaktor_test *t, const char *target, char *out, int cap)
{
test_ask q;
if (!target || !look(t, target, &q)) return 0;
if (out && cap > 0) SDL_strlcpy(out, q.value, (size_t)cap);
return 1;
}
unsigned
reaktor_test_state(reaktor_test *t, const char *target)
{
test_ask q;
return target && look(t, target, &q) ? q.node.state : 0u;
}
static void
push(reaktor_test *t, SDL_Event *e)
{
e->common.timestamp = SDL_GetTicksNS();
SDL_PushEvent(e);
reaktor_wake(t->app);
}
static int
press_at(reaktor_test *t, float x, float y)
{
Uint32 win = SDL_GetWindowID(t->app->win);
SDL_Event e;
int down;
SDL_zero(e);
e.type = SDL_EVENT_MOUSE_MOTION;
e.motion.windowID = win;
e.motion.x = x;
e.motion.y = y;
push(t, &e);
reaktor_test_settle(t);
for (down = 1; down >= 0; down--) {
SDL_zero(e);
e.type = down ? SDL_EVENT_MOUSE_BUTTON_DOWN : SDL_EVENT_MOUSE_BUTTON_UP;
e.button.windowID = win;
e.button.button = SDL_BUTTON_LEFT;
e.button.down = down != 0;
e.button.clicks = 1;
e.button.x = x;
e.button.y = y;
push(t, &e);
reaktor_test_settle(t);
}
return !t->stuck;
}
int
reaktor_test_click(reaktor_test *t, const char *target)
{
test_ask q;
struct nk_rect r;
if (!target || !look(t, target, &q)) {
SDL_Log("test: no %s to click", target ? target : "(null)");
return 0;
}
if (q.node.state & REAKTOR_A11Y_OFFSCREEN) {
SDL_Log("test: %s is scrolled out of view", target);
return 0;
}
r = q.node.bounds;
return press_at(t, r.x + r.w * 0.5f, r.y + r.h * 0.5f);
}
int
reaktor_test_type(reaktor_test *t, const char *target, const char *text)
{
SDL_Event e;
if (target && !reaktor_test_click(t, target)) return 0;
SDL_strlcpy(t->text, text ? text : "", sizeof t->text);
SDL_zero(e);
e.type = SDL_EVENT_TEXT_INPUT;
e.text.windowID = SDL_GetWindowID(t->app->win);
e.text.text = t->text;
push(t, &e);
reaktor_test_settle(t);
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)
{
char part[64];
const char *p = chord, *plus;
SDL_Keymod mod = SDL_KMOD_NONE;
SDL_Keycode key = SDLK_UNKNOWN;
SDL_Event e;
int down;
while (p && *p) {
size_t n;
plus = SDL_strchr(p, '+');
n = plus && plus[1] ? (size_t)(plus - p) : SDL_strlen(p);
if (n >= sizeof part) return 0;
SDL_memcpy(part, p, n);
part[n] = 0;
p = plus && plus[1] ? plus + 1 : NULL;
if (!p) key = SDL_GetKeyFromName(part);
else if (SDL_strcasecmp(part, "Ctrl") == 0) mod |= SDL_KMOD_LCTRL;
else if (SDL_strcasecmp(part, "Shift") == 0) mod |= SDL_KMOD_LSHIFT;
else if (SDL_strcasecmp(part, "Alt") == 0) mod |= SDL_KMOD_LALT;
else if (SDL_strcasecmp(part, "Cmd") == 0 || SDL_strcasecmp(part, "Gui") == 0)
mod |= SDL_KMOD_LGUI;
else return 0;
}
if (key == SDLK_UNKNOWN) {
SDL_Log("test: no key called %s", chord ? chord : "(null)");
return 0;
}
for (down = 1; down >= 0; down--) {
SDL_zero(e);
e.type = down ? SDL_EVENT_KEY_DOWN : SDL_EVENT_KEY_UP;
e.key.windowID = SDL_GetWindowID(t->app->win);
e.key.key = key;
e.key.scancode = SDL_GetScancodeFromKey(key, NULL);
e.key.mod = mod;
e.key.down = down != 0;
push(t, &e);
reaktor_test_settle(t);
}
return !t->stuck;
}
int
reaktor_test_check(reaktor_test *t, int ok, const char *what)
{
t->checks++;
if (!ok) t->fails++;
SDL_Log("test: %-56s %s", what ? what : "", ok ? "ok" : "FAILED");
return ok;
}
static int SDLCALL
script_thread(void *data)
{
reaktor_test *t = (reaktor_test *)data;
g_script(t, g_user);
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);
/* 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)) {
SDL_SetAtomicPointer(&g_settle, NULL);
SDL_SignalSemaphore(q->t->done);
} else {
app->dirty = 1;
reaktor_wake(app);
}
return;
}
if (!g_script || g_thread) return;
if (!reaktor_frame_settled(app)) {
app->dirty = 1;
reaktor_wake(app);
return;
}
g_test.app = app;
g_test.done = SDL_CreateSemaphore(0);
if (g_test.done) g_thread = SDL_CreateThread(script_thread, "reaktor-test", &g_test);
if (!g_thread) {
SDL_Log("test: cannot start the script");
reaktor_quit(app, 1);
}
}
int
reaktor_test_app(int argc, char **argv, const reaktor_launch *launch,
reaktor_test_script script, void *user)
{
static char video[] = "--video", dummy[] = "dummy", fresh[] = "--new-instance";
char **args = (char **)SDL_calloc((size_t)argc + 4, sizeof *args);
int i, n = 0, own_video = 0, rc;
if (!args) return 1;
for (i = 1; i < argc; i++)
if (SDL_strcmp(argv[i], "--video") == 0) own_video = 1;
args[n++] = argc > 0 ? argv[0] : fresh;
if (!own_video) {
args[n++] = video;
args[n++] = dummy;
}
args[n++] = fresh;
for (i = 1; i < argc; i++) args[n++] = argv[i];
g_script = script;
g_user = user;
reaktor_test_hook = test_frame;
rc = reaktor_launch_app(n, args, launch);
if (g_thread) SDL_WaitThread(g_thread, NULL);
if (g_test.done) SDL_DestroySemaphore(g_test.done);
SDL_free(args);
return rc;
}
+13 -9
View File
@@ -59,13 +59,18 @@ unpark(int all)
int i;
for (i = g_parked_n - 1; i >= 0; i--)
if (all || SDL_GetAtomicInt(&g_parked[i]->file_done)) {
if (!all) {
SDL_free(g_parked[i]->file_list);
SDL_free(g_parked[i]);
}
if (all || reaktor_app_free(g_parked[i]))
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)
{
if (SDL_GetAtomicInt(&a->file_busy)) return 0;
SDL_free(a->file_list);
SDL_free(a);
return 1;
}
int
@@ -88,14 +93,13 @@ teardown(App *a)
if (a->ctx) nk_sdl_shutdown(a->ctx);
if (a->ren) SDL_DestroyRenderer(a->ren);
if (a->win) SDL_DestroyWindow(a->win);
SDL_free(a->glyphs);
reaktor_fontset_free(&a->fonts);
reaktor_anim_destroy(a->anim);
a->anim = NULL;
a->win = NULL;
a->ren = NULL;
a->ctx = NULL;
if (a->file_pending && g_parked_n < WINDOW_MAX) g_parked[g_parked_n++] = a;
else if (!a->file_pending) SDL_free(a);
if (!reaktor_app_free(a) && g_parked_n < WINDOW_MAX) g_parked[g_parked_n++] = a;
}
static void
+1 -1
View File
@@ -83,7 +83,7 @@ load(const char *path)
SDL_snprintf(g.status, sizeof(g.status), "Could not read %s", path);
return;
}
if (!room((int)n)) {
if (n > (size_t)SDL_MAX_SINT32 - 256 || !room((int)n)) {
SDL_snprintf(g.status, sizeof(g.status), "%s does not fit in memory", path);
SDL_free(body);
return;
+103 -24
View File
@@ -13,6 +13,47 @@ 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)
{
const struct reaktor_user_font *f = reaktor_style_font(app, "button", 14, 0);
const char *n = (const char *)user;
float nw = f->width(f->userdata, f->height, n, (int)SDL_strlen(n)) + 14.0f;
float lw = f->width(f->userdata, f->height, "Inbox", 5);
float x = c.x + (c.w - lw - 8.0f - nw) * 0.5f;
float y = c.y + (c.h - f->height) * 0.5f;
struct reaktor_color accent = reaktor_token("--links", reaktor_rgb(0, 118, 209));
reaktor_draw_text(cv, reaktor_rect(x, y, lw, f->height), "Inbox", 5, f,
reaktor_rgba(0, 0, 0, 0), ink);
reaktor_fill_round(app, cv, reaktor_rect(x + lw + 8.0f, y - 2.0f, nw, f->height + 4.0f),
(f->height + 4.0f) * 0.5f, accent);
reaktor_draw_text(cv, reaktor_rect(x + lw + 15.0f, y, nw, f->height), n,
(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)
{
const struct reaktor_user_font *f = reaktor_style_font(app, "button", 14, 1);
const struct reaktor_user_font *small = reaktor_style_font(app, "button", 12, 0);
struct reaktor_image im = reaktor_ionicon(app, "download-outline", 24);
float y = c.y + (c.h - f->height - small->height - 2.0f) * 0.5f;
(void)user;
reaktor_draw_image(cv, reaktor_rect(c.x, c.y + (c.h - 24.0f) * 0.5f, 24.0f, 24.0f), &im, ink);
reaktor_draw_text(cv, reaktor_rect(c.x + 36.0f, y, c.w - 36.0f, f->height),
"reaktor-0.7.1-web.zip", 21, f, reaktor_rgba(0, 0, 0, 0), ink);
reaktor_draw_text(cv, reaktor_rect(c.x + 36.0f, y + f->height + 2.0f, c.w - 36.0f,
small->height),
"4.2 MB of 9.8 MB", 16, small, reaktor_rgba(0, 0, 0, 0),
reaktor_token("--text-muted", ink));
}
void
page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
{
@@ -60,38 +101,76 @@ page_buttons(App *app, struct reaktor_context *ctx, showcase_state *s)
{ "chevron-forward-outline", "Forward" },
{ "menu-outline", "Menu" }
};
int row, col;
REAKTOR_ROW(.flags = REAKTOR_LAY_FILL_X | REAKTOR_LAY_WRAP,
.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,
.fit_content = 1 }))
s->presses++;
for (i = 0; i < 3; i++)
if (reaktor_button(&(reaktor_button_spec){
.label = nav[i].label, .icon = nav[i].icon,
.fit_content = 1 }))
s->presses++;
}
}
REAKTOR_COLUMN(.gap = ctx->style.window.spacing.y) {
for (row = 0; row * 4 < ICON_N; row++) {
REAKTOR_ROW(.h = 38.0f, .flags = REAKTOR_LAY_FILL_X,
.gap = ctx->style.window.spacing.x) {
for (col = 0; col < 4; col++) {
int k = row * 4 + col;
if (k >= ICON_N) break;
if (reaktor_button(&(reaktor_button_spec){
.label = g_icons[k].label,
.icon = g_icons[k].icon,
.box = { .flags = REAKTOR_LAY_FILL_X |
REAKTOR_LAY_FILL_Y } }))
s->presses++;
}
}
}
section(app, ctx, "Width",
"A button is as wide as its content with .fit_content, the way "
"GTK and Qt size one, and its icon and label are centered "
"together at any width. A .box.w with .fit_content is the least "
"it takes, so short labels line up while a long or translated one "
"still grows; .box.w alone is exact, and REAKTOR_LAY_FILL_X shares "
"the row out.");
api(app, ctx, ".fit_content / .box.w / REAKTOR_LAY_FILL_X / reaktor_button_width "
"/ reaktor_button_accent_icon");
{
static const char *const how[4] = { "Content", "At least 100", "Exactly 100",
"Shared" };
static const reaktor_box box[4] = {
{ 0 }, { .w = 100.0f }, { .w = 100.0f }, { .flags = REAKTOR_LAY_FILL_X } };
int m;
for (m = 0; m < 4; m++) {
REAKTOR_ROW(.h = 38.0f, .flags = REAKTOR_LAY_FILL_X,
.gap = ctx->style.window.spacing.x) {
for (i = 0; i < 3; i++)
if (reaktor_button(&(reaktor_button_spec){
.label = nav[i].label, .icon = nav[i].icon,
.box = { .flags = REAKTOR_LAY_FILL_X |
REAKTOR_LAY_FILL_Y } }))
s->presses++;
reaktor_label(&(reaktor_label_spec){ .text = how[m],
.box = { .w = 110.0f, .flags = REAKTOR_LAY_FILL_Y } });
if (reaktor_button(&(reaktor_button_spec){
.label = "Back", .icon = "chevron-back-outline",
.fit_content = m < 2, .box = box[m] }))
s->presses++;
if (reaktor_button(&(reaktor_button_spec){
.label = "Add folder", .icon = "folder-open-outline",
.fit_content = m < 2, .box = box[m] }))
s->presses++;
if (reaktor_button(&(reaktor_button_spec){
.label = "Wipe", .icon = "flame-outline", .accent = 1,
.fit_content = m < 2, .box = box[m] }))
s->presses++;
}
}
}
section(app, ctx, "Custom content",
"The sheet's button with nothing in it: its fill, edge, hover, "
"focus ring and click are the runtime's, and a callback paints "
"the inside, given the content box inside the padding and the "
"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 = 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 } }))
s->presses++;
if (reaktor_button(&(reaktor_button_spec){
.label = "reaktor-0.7.1-web.zip, 4.2 MB of 9.8 MB", .paint = paint_download,
.box = { .w = 280.0f, .flags = REAKTOR_LAY_FILL_Y } }))
s->presses++;
}
section(app, ctx, "Flat icons",
"An icon with no label and .flat set is a toolbar button: no "
"fill and no edge until the pointer is over it, then the sheet's "
+5 -1
View File
@@ -2,7 +2,8 @@
static const char *const rss_names[REAKTOR_RSS_STEPS] = {
"before any of it", "SDL_Init(VIDEO)", "window and renderer",
"window icon", "Nuklear context", "font atlas", "stylesheets"
"window icon", "Nuklear context", "font atlas", "the application's start",
"stylesheets"
};
static void
@@ -159,6 +160,9 @@ page_diagnostics(App *app, struct reaktor_context *ctx, showcase_state *st)
SDL_snprintf(v, sizeof(v), "one per %d ms while the pointer moves",
d.hover_gap_ms);
diag_row(app, ctx, "hover redraws", v);
SDL_snprintf(v, sizeof(v), "%lu drawn, %lu the same as the last and skipped",
d.frames_drawn, d.frames_skipped);
diag_row(app, ctx, "frames", v);
}
section(app, ctx, "Where a frame goes",
+5 -1
View File
@@ -119,7 +119,10 @@ splash_page(App *app, struct reaktor_context *ctx, int w, int h, void *user)
reaktor_timer(app, 350, 0, splash_tick, NULL);
reaktor_timer(app, 650, 0, splash_tick, NULL);
}
reaktor_fill_rect(cv, reaktor_rect(0, 0, (float)w, (float)h), 0, reaktor_page_color(app));
reaktor_fill_rect(cv, reaktor_rect(0, 0, (float)w, (float)h), 0,
reaktor_token("--background", reaktor_page_color(app)));
reaktor_edge_round(app, cv, reaktor_rect(0, 0, (float)w, (float)h), 0.0f, 1.0f,
reaktor_token("--border", muted));
reaktor_draw_image(cv, reaktor_rect(((float)w - px) * 0.5f, 52.0f + (96.0f - px) * 0.5f, px, px),
&im, reaktor_rgba(255, 255, 255, (reaktor_byte)(255.0f * mark)));
credit(cv, reaktor_font(app, 30, 1), "Reaktor", 164.0f, w, ink, name);
@@ -809,6 +812,7 @@ main(int argc, char **argv)
.font_fallbacks = { { .path = "assets/fonts/MPLUS1p-Regular.ttf" } },
.confirm_close = SC_CLOSE_QUESTION,
.single_instance = 1,
.skip_same_frames = 1,
.inspector = { .attach = 1 },
.page = page_shell,
.key = sample_key,
+12
View File
@@ -390,5 +390,17 @@ int main(int argc, char **argv)
check("overflow clamps at the arena size", n, REAKTOR_A11Y_MAX_NODES);
check("overflow is counted", a.overflow_nodes > 0, 1);
reaktor_a11y_begin(&a, "w", r(0, 0, 10, 10));
for (i = 0; i < REAKTOR_A11Y_SLOTS * 2; i++) {
char name[16];
snprintf(name, sizeof(name), "n%d", i);
reaktor_a11y_add(&a, REAKTOR_A11Y_NONE, name, NULL, 0, r(0, 0, 1, 1));
}
reaktor_a11y_add(&a, REAKTOR_A11Y_BUTTON, "after", NULL, 0, r(0, 0, 1, 1));
reaktor_a11y_end(&a);
reaktor_a11y_tree(&a, &n);
check("a full slot table still ends the frame", n >= 1, 1);
return test_done("a11y");
}
+53
View File
@@ -0,0 +1,53 @@
#include <string.h>
#include "util.h"
#include "test.h"
#define ok test_ok
int
main(void)
{
ok("http, https and mailto open",
reaktor_url_allowed("https://example.com", NULL) &&
reaktor_url_allowed("http://example.com", NULL) &&
reaktor_url_allowed("mailto:a@example.com", NULL));
ok(" in any case", reaktor_url_allowed("HTTPS://example.com", NULL));
ok("file, a drive path and a share do not",
!reaktor_url_allowed("file:///C:/Windows/System32/calc.exe", NULL) &&
!reaktor_url_allowed("C:\\Windows\\System32\\calc.exe", NULL) &&
!reaktor_url_allowed("\\\\server\\share\\x", NULL));
ok("nor a registered protocol, a blank start or no scheme at all",
!reaktor_url_allowed("ms-settings:", NULL) &&
!reaktor_url_allowed(" https://example.com", NULL) &&
!reaktor_url_allowed("example.com", NULL) && !reaktor_url_allowed("", NULL) &&
!reaktor_url_allowed(NULL, NULL));
ok("a link's own schemes are added, whole names only",
reaktor_url_allowed("file:///tmp/x", "file,ftp") &&
reaktor_url_allowed("ftp://x", "file,ftp") &&
!reaktor_url_allowed("fil:///tmp/x", "file,ftp") &&
!reaktor_url_allowed("ms-settings:", "file,ftp"));
{
static const char *const cases[][2] = {
{ "h\xC3\xA9llo \xE6\x97\xA5 \xF0\x9F\x98\x80", "h\xC3\xA9llo \xE6\x97\xA5 \xF0\x9F\x98\x80" },
{ "a\x80" "b", "a\xEF\xBF\xBD" "b" },
{ "a\xE2\x82", "a\xEF\xBF\xBD\xEF\xBF\xBD" },
{ "\xC0\xAF", "\xEF\xBF\xBD\xEF\xBF\xBD" },
{ "\xED\xA0\x80", "\xEF\xBF\xBD\xEF\xBF\xBD\xEF\xBF\xBD" },
{ "\xF4\x90\x80\x80", "\xEF\xBF\xBD" },
};
char out[64];
int k, bad = 0;
for (k = 0; k < (int)(sizeof cases / sizeof cases[0]); k++) {
reaktor_utf8_clean(out, cases[k][0], sizeof out);
if (strcmp(out, cases[k][1]) != 0) bad++;
}
ok("invalid UTF-8 becomes U+FFFD, valid text is kept", bad == 0);
reaktor_utf8_clean(out, "ab\xE6\x97\xA5", 4);
ok("a short buffer cuts at a whole character", strlen(out) == 2);
}
return test_done("base");
}
+123 -4
View File
@@ -26,7 +26,13 @@ static const char g_sheet[] =
"a.y { border-top: 2px dotted #0d0e0f !important; }\n"
"em { color: color-mix(in srgb, rgb(255 0 0 / 50%) 50%, red); "
"background-color: color-mix(in srgb, hsl(120, 100%, 50%), black); "
"border-top-color: color-mix(in srgb, #ff000080, rgba(0, 0, 255, 1)); }\n";
"border-top-color: color-mix(in srgb, #ff000080, rgba(0, 0, 255, 1)); }\n"
":root { --slash: /; }\n"
"dl { background: url(https://x/a.png); color: #111111; }\n"
"dt { b: x//y; color: #121212; }\n"
"dd { b: {}x; color: #131313; }\n"
"dfn { b: var(--slash)*x; color: #141414; }\n"
"a[href^=\"//\"], kbd { color: #151515; }\n";
static const char g_media[] =
"@media (prefers-color-scheme: dark) { h1 { color: #000001; } }\n"
@@ -38,12 +44,96 @@ static const char g_media[] =
"@media (prefers-contrast: more) and (max-width: 720px) { ol { color: #000007; } }\n"
"@media print { ul { color: #000008; } }\n";
static char *
repeat(char *s, const char *piece, int times)
{
size_t n = strlen(s), k = strlen(piece);
char *r = realloc(s, n + k * (size_t)times + 1);
int i;
if (!r) return s;
for (i = 0; i < times; i++) memcpy(r + n + k * (size_t)i, piece, k);
r[n + k * (size_t)times] = 0;
return r;
}
static char *
append(char *s, const char *piece)
{
return repeat(s, piece, 1);
}
static char *
generated(const char *name)
{
char *s = calloc(1, 1);
char piece[64];
int i;
if (!s) return NULL;
if (strcmp(name, "calc.css") == 0) {
s = append(s, "dir { width: calc(");
s = repeat(s, "(", 40);
s = append(s, "1px");
s = repeat(s, ")", 40);
s = append(s, "); color: #161616; }\n");
} else if (strcmp(name, "self.css") == 0) {
s = repeat(s, "@import \"self.css\";\n", 20);
s = append(s, "kbd { color: #171717; }\n");
} else if (strncmp(name, "fan", 3) == 0 && name[3] >= '0' && name[3] <= '8') {
if (name[3] < '8') {
snprintf(piece, sizeof(piece), "@import \"fan%c.css\";\n", name[3] + 1);
s = repeat(s, piece, 20);
}
s = append(s, "samp { color: #181818; }\n");
} else if (strcmp(name, "nest.css") == 0) {
s = append(s, "var { color: ");
s = repeat(s, "var(--u, ", 1000);
s = append(s, "red");
s = repeat(s, ")", 1000);
s = append(s, "; background-color: var(--u, var(--v, #191919)); }\n");
} else if (strcmp(name, "laughs.css") == 0) {
s = append(s, ":root { --a0: xxxxxxxxxx;");
for (i = 1; i < 10; i++) {
snprintf(piece, sizeof(piece), " --a%d:", i);
s = append(s, piece);
snprintf(piece, sizeof(piece), " var(--a%d)", i - 1);
s = repeat(s, piece, 10);
s = append(s, ";");
}
s = append(s, " }\nabbr { color: var(--a9); background-color: #1a1a1a; }\n");
} else {
free(s);
return NULL;
}
return s;
}
static char *
flat1(const char *name)
{
return reaktor_css_flatten(&name, 1, "light", 511, NULL);
}
static int
count(const char *s, const char *what)
{
int n = 0;
while ((s = strstr(s, what)) != NULL) { n++; s++; }
return n;
}
char *
reaktor_asset_load(const char *name, size_t *len)
{
char *out = NULL;
char *out = generated(name);
long n = 0;
if (out) {
if (len) *len = strlen(out);
return out;
}
if (strcmp(name, "test.css") == 0 || strcmp(name, "media.css") == 0) {
const char *s = name[0] == 't' ? g_sheet : g_media;
@@ -51,9 +141,11 @@ reaktor_asset_load(const char *name, size_t *len)
out = malloc((size_t)n + 1);
if (out) memcpy(out, s, (size_t)n + 1);
} else {
FILE *f = fopen(name, "rb");
char path[1024];
FILE *f;
if (!f) return NULL;
snprintf(path, sizeof path, "%s%s", CSSTEST_SOURCE, name);
if (!(f = fopen(path, "rb"))) return NULL;
fseek(f, 0, SEEK_END);
n = ftell(f);
fseek(f, 0, SEEK_SET);
@@ -113,6 +205,13 @@ main(void)
ok(" and brackets", strstr(out, "margin: 8px;") != NULL);
ok("calc() with a percentage is left", strstr(out, "width: calc(100% - 2 * 8px);") != NULL);
ok("a value with a ';' is dropped", !strstr(out, "base64") && strstr(out, "#010203"));
ok("a value with '//', '/*' or '}' is dropped",
strstr(out, "dl {") && !strstr(strstr(out, "dl {"), "/*") &&
!strstr(out, "//") && !strstr(out, "{}") &&
strstr(out, "#111111") && strstr(out, "#121212") &&
strstr(out, "#131313") && strstr(out, "#141414"));
ok("a selector with '//' is dropped, the rest of its list kept",
strstr(out, "kbd {") && strstr(out, "#151515"));
ok("a value past the token is dropped", !strstr(out, "longer") && strstr(out, "#040506"));
ok("a selector past the token is dropped", !strstr(out, "a-selector") && strstr(out, "u {"));
ok("border keyword widths become lengths",
@@ -161,5 +260,25 @@ main(void)
free(out);
}
out = flat1("calc.css");
ok("calc() nested past its depth is dropped, the rest of its rule kept",
out && !strstr(out, "width") && strstr(out, "#161616"));
free(out);
out = flat1("self.css");
ok("a sheet that imports itself is read once", out && count(out, "#171717") == 1);
free(out);
out = flat1("fan0.css");
ok("imports that fan out stop at the budget", out && strlen(out) < (16u << 20));
free(out);
out = flat1("nest.css");
ok("var() fallbacks nested past the limit are dropped",
out && !strstr(out, "red") && strstr(out, "background-color: #191919"));
free(out);
out = flat1("laughs.css");
ok("var() that would grow past the limit is dropped",
out && strlen(out) < (1u << 20) && !strstr(out, "var(") &&
strstr(out, "#1a1a1a"));
free(out);
return test_done("css");
}
+97
View File
@@ -0,0 +1,97 @@
#include <stdio.h>
#include "plutovg.h"
#include "test.h"
#define ok test_ok
static const unsigned char g_png[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0x15, 0xc4, 0x89, 0x00, 0x00, 0x00,
0x0d, 0x49, 0x44, 0x41, 0x54, 0x78, 0x9c, 0x63, 0xf8, 0xcf, 0xc0, 0xf0,
0x1f, 0x00, 0x05, 0x00, 0x01, 0xff, 0x89, 0x99, 0x3d, 0x1d, 0x00, 0x00,
0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
};
static const unsigned char g_jpeg[] = {
0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46, 0x49, 0x46, 0x00, 0x01,
0x01, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0xff, 0xdb, 0x00, 0x43,
0x00, 0x08, 0x06, 0x06, 0x07, 0x06, 0x05, 0x08, 0x07, 0x07, 0x07, 0x09,
0x09, 0x08, 0x0a, 0x0c, 0x14, 0x0d, 0x0c, 0x0b, 0x0b, 0x0c, 0x19, 0x12,
0x13, 0x0f, 0x14, 0x1d, 0x1a, 0x1f, 0x1e, 0x1d, 0x1a, 0x1c, 0x1c, 0x20,
0x24, 0x2e, 0x27, 0x20, 0x22, 0x2c, 0x23, 0x1c, 0x1c, 0x28, 0x37, 0x29,
0x2c, 0x30, 0x31, 0x34, 0x34, 0x34, 0x1f, 0x27, 0x39, 0x3d, 0x38, 0x32,
0x3c, 0x2e, 0x33, 0x34, 0x32, 0xff, 0xdb, 0x00, 0x43, 0x01, 0x09, 0x09,
0x09, 0x0c, 0x0b, 0x0c, 0x18, 0x0d, 0x0d, 0x18, 0x32, 0x21, 0x1c, 0x21,
0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32,
0x32, 0x32, 0xff, 0xc0, 0x00, 0x11, 0x08, 0x00, 0x01, 0x00, 0x01, 0x03,
0x01, 0x22, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff, 0xc4, 0x00,
0x1f, 0x00, 0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0xff, 0xc4, 0x00, 0xb5, 0x10, 0x00,
0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, 0x05, 0x05, 0x04, 0x04, 0x00,
0x00, 0x01, 0x7d, 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21,
0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, 0x81,
0x91, 0xa1, 0x08, 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, 0x24,
0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x25,
0x26, 0x27, 0x28, 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a,
0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56,
0x57, 0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a,
0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83, 0x84, 0x85, 0x86,
0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3,
0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6,
0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9,
0xda, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf1,
0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xff, 0xc4, 0x00,
0x1f, 0x01, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0xff, 0xc4, 0x00, 0xb5, 0x11, 0x00,
0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, 0x07, 0x05, 0x04, 0x04, 0x00,
0x01, 0x02, 0x77, 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31,
0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08,
0x14, 0x42, 0x91, 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, 0x15,
0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18,
0x19, 0x1a, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, 0x39,
0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55,
0x56, 0x57, 0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x82, 0x83, 0x84,
0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa,
0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4,
0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
0xd8, 0xd9, 0xda, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xff, 0xda, 0x00,
0x0c, 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00, 0xe2,
0xe8, 0xa2, 0x8a, 0xf9, 0x93, 0xf7, 0x13, 0xff, 0xd9,
};
static const unsigned char g_gif[] = {
0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x01, 0x00, 0x01, 0x00, 0x81, 0x00,
0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x08,
0x04, 0x00, 0x01, 0x04, 0x04, 0x00, 0x3b,
};
static int
decodes(const unsigned char *data, int len)
{
plutovg_surface_t *s = plutovg_surface_load_from_image_data(data, len);
if (!s) return 0;
plutovg_surface_destroy(s);
return 1;
}
int
main(void)
{
ok("a PNG decodes", decodes(g_png, (int)sizeof(g_png)));
ok("a JPEG decodes", decodes(g_jpeg, (int)sizeof(g_jpeg)));
ok("a GIF does not", !decodes(g_gif, (int)sizeof(g_gif)));
return test_done("image");
}
+21 -27
View File
@@ -4,6 +4,7 @@
#include <SDL3/SDL.h>
#include "nk_common.h"
#include "font.h"
#include "util.h"
#include "text.h"
#include "test.h"
@@ -58,7 +59,7 @@ directions(void)
}
static float
width(const struct nk_font *font, const char *s)
width(const struct reaktor_font *font, const char *s)
{
return font->handle.width(font->handle.userdata, font->handle.height, s,
(int)strlen(s));
@@ -114,16 +115,17 @@ same_vertices(struct nk_buffer *a, struct nk_buffer *b)
static void
drawing(void)
{
struct nk_font_atlas atlas;
struct nk_font_config cfg = nk_font_config(16.0f);
struct nk_context ctx;
struct nk_buffer rtl, ltr, wrong;
struct nk_font *font;
nk_text_width_f atlas_width;
SDL_Surface *surface;
SDL_Renderer *ren;
char path[1024], japanese[1024], line[200];
int w, h;
static const nk_rune latin[] = { 0x0020, 0x00FF, 0 };
struct reaktor_fontset set;
struct reaktor_face_src src;
struct nk_context ctx;
struct nk_buffer rtl, ltr, wrong;
struct reaktor_font *font;
nk_text_width_f atlas_width;
SDL_Surface *surface;
SDL_Renderer *ren;
char path[1024], japanese[1024], line[200];
int baked;
if (!reaktor_path(path, sizeof path, FONT_FILE) ||
!reaktor_path(japanese, sizeof japanese, JAPANESE_FILE)) {
@@ -140,25 +142,17 @@ drawing(void)
return;
}
cfg.oversample_h = cfg.oversample_v = 1;
cfg.pixel_snap = 1;
nk_font_atlas_init_default(&atlas);
nk_font_atlas_begin(&atlas);
{
size_t len = 0;
char *ttf = reaktor_read_file(path, &len);
/* The atlas copies bytes it does not own. */
font = ttf ? nk_font_atlas_add_from_memory(&atlas, ttf, len, 16.0f, &cfg)
: NULL;
reaktor_free(ttf);
}
if (!font || !nk_font_atlas_bake(&atlas, &w, &h, NK_FONT_ATLAS_ALPHA8)) {
src.ttf = reaktor_read_file(path, &src.size);
src.px = 16.0f;
baked = src.ttf && reaktor_fontset_bake(&set, &src, 1, latin);
reaktor_free((void *)src.ttf);
if (!baked || !set.fonts[0].glyph_count) {
printf("FAIL could not bake %s\n", path);
failures++;
return;
}
nk_font_atlas_end(&atlas, nk_handle_id(0), NULL);
reaktor_fontset_bind(&set, nk_handle_id(0));
font = &set.fonts[0];
nk_init_default(&ctx, &font->handle);
atlas_width = font->handle.width;
@@ -190,7 +184,7 @@ drawing(void)
reaktor_text_attach_font(NULL, NULL);
nk_free(&ctx);
nk_font_atlas_clear(&atlas);
reaktor_fontset_free(&set);
SDL_DestroyRenderer(ren);
SDL_DestroySurface(surface);
}
+121
View File
@@ -0,0 +1,121 @@
#include "reaktor/reaktor.h"
#include "reaktor/main.h"
static char g_name[64];
static int g_name_len;
static int g_count;
static reaktor_bool g_loud;
static char g_greeting[96] = "Nobody greeted yet";
static int g_rows[3] = { 1, 1, 1 };
static void
greet(void)
{
SDL_snprintf(g_greeting, sizeof g_greeting, g_loud ? "HELLO, %.*s!" : "Hello, %.*s",
g_name_len, g_name);
}
static void
page(App *app, struct reaktor_context *ctx, int win_w, int win_h)
{
char count[32];
(void)app; (void)ctx; (void)win_h;
SDL_snprintf(count, sizeof count, "%d", g_count);
REAKTOR_COLUMN(.w = (float)win_w, .gap = 8.0f) {
reaktor_field(&(reaktor_field_spec){
.buf = g_name, .len = &g_name_len, .cap = sizeof g_name, .name = "Name",
.box = { .w = 240.0f } });
reaktor_check(&(reaktor_check_spec){ .label = "Loud", .on = &g_loud });
if (reaktor_button(&(reaktor_button_spec){
.label = "Greet", .keys = "Ctrl+G", .fit_content = 1,
.box = { .mark = "greet button" } }))
greet();
if (reaktor_button(&(reaktor_button_spec){
.label = "Add one", .icon = "add-outline", .fit_content = 1,
.box = { .mark = "add" } }))
g_count++;
reaktor_label(&(reaktor_label_spec){ .text = g_greeting, .name = "Greeting",
.value = g_greeting });
reaktor_label(&(reaktor_label_spec){ .text = count, .name = "Count", .value = count,
.box = { .mark = "count" } });
{
static const char *const fruit[3] = { "Apple", "Banana", "Cherry" };
static const char *const marks[3] = { "row0", "row1", "row2" };
int i;
for (i = 0; i < 3; i++) {
if (!g_rows[i]) continue;
REAKTOR_ROW(.h = 30.0f, .gap = 8.0f, .mark = marks[i]) {
reaktor_label(&(reaktor_label_spec){ .text = fruit[i],
.box = { .w = 80.0f } });
if (reaktor_button(&(reaktor_button_spec){ .label = "Delete",
.name = "Delete",
.fit_content = 1,
.box = { .mark = "del" } }))
g_rows[i] = 0;
}
}
}
}
}
static int
on_key(App *app, const SDL_Event *e)
{
(void)app;
if (!reaktor_chord(e, REAKTOR_MOD_CTRL, SDLK_G)) return 0;
greet();
return 1;
}
static void
script(reaktor_test *t, void *user)
{
char v[96];
(void)user;
reaktor_test_check(t, reaktor_test_find(t, "Greet"), "a button is found by its name");
reaktor_test_check(t, reaktor_test_find(t, "#add"), " and by its mark");
reaktor_test_check(t, !reaktor_test_find(t, "Nothing like this"), " and a missing one is not");
reaktor_test_click(t, "#add");
reaktor_test_click(t, "Add one");
reaktor_test_check(t, reaktor_test_value(t, "#count", v, sizeof v) && SDL_strcmp(v, "2") == 0,
"two clicks count two");
reaktor_test_type(t, "Name", "Ada");
reaktor_test_click(t, "Greet");
reaktor_test_check(t, reaktor_test_value(t, "Greeting", v, sizeof v) &&
SDL_strcmp(v, "Hello, Ada") == 0,
"typed text reaches the field and the click reads it");
reaktor_test_click(t, "Loud");
reaktor_test_check(t, (reaktor_test_state(t, "Loud") & REAKTOR_A11Y_CHECKED) != 0,
"a click checks a box");
reaktor_test_key(t, "Ctrl+G");
reaktor_test_check(t, reaktor_test_value(t, "Greeting", v, sizeof v) &&
SDL_strcmp(v, "HELLO, Ada!") == 0,
"a shortcut reaches the key hook");
reaktor_test_check(t, reaktor_test_find(t, "Delete"), "a name three rows share is found, and the log says so");
reaktor_test_check(t, reaktor_test_find(t, "#row1 Delete"), "a mark on a row scopes a lookup");
reaktor_test_check(t, reaktor_test_find(t, "#greet button"), "a mark with a space is found whole");
reaktor_test_check(t, reaktor_test_find(t, "#del"), "a mark three buttons share is found, and the log says so");
reaktor_test_click(t, "#row1 #del");
reaktor_test_check(t, !reaktor_test_find(t, "Banana") && reaktor_test_find(t, "Apple") &&
reaktor_test_find(t, "Cherry"),
" and the click reaches that row's button, not the first");
reaktor_test_check(t, !reaktor_test_find(t, "#row1 Delete"), " and an absent scope finds nothing");
reaktor_test_click(t, "#row2 #del");
reaktor_test_check(t, !reaktor_test_find(t, "Cherry") && reaktor_test_find(t, "Apple"),
"a shared mark inside a scope reaches that row's widget");
}
int
main(int argc, char **argv)
{
return reaktor_test_app(argc, argv, &(reaktor_launch){
.name = "UI test", .window = { .w = 400, .h = 320 }, .page = page, .key = on_key },
script, NULL);
}
+23
View File
@@ -0,0 +1,23 @@
#!/bin/sh
# The scripted UI test: tests/uitest.c drives its own window through the
# accessibility tree and SDL's events, and exits 0 when every check passed.
# uitest.sh [-w WRAP] BUILD
set -u
wrap=""
while getopts w: opt; do
case $opt in
w) wrap=$OPTARG ;;
*) echo "usage: uitest.sh [-w WRAP] BUILD" >&2; exit 2 ;;
esac
done
shift $((OPTIND - 1))
build=$1
mkdir -p smoke
rm -f smoke/uitest.log
$wrap "$build/uitest" --log smoke/uitest.log </dev/null >/dev/null 2>&1
rc=$?
grep "test:" smoke/uitest.log 2>/dev/null || cat smoke/uitest.log 2>/dev/null || :
[ "$rc" = 0 ] || echo "uitest: exit status $rc"
exit "$rc"
+3 -39
View File
@@ -4,6 +4,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; object-src 'none'; base-uri 'none'; form-action 'none'">
<title>Reaktor</title>
<link rel="icon" type="image/svg+xml" href="reaktor-icon.svg">
<link rel="alternate icon" type="image/png" href="reaktor-icon.png">
@@ -105,46 +106,9 @@
<div class="bar"><div></div></div>
<div class="text">Loading&hellip;</div>
</div>
<canvas id="canvas" tabindex="-1" oncontextmenu="event.preventDefault()">
<canvas id="canvas" tabindex="-1">
</canvas>
<script>
var statusEl = document.getElementById('status');
var barEl = statusEl.querySelector('.bar');
var textEl = statusEl.querySelector('.text');
var Module = {
canvas: document.getElementById('canvas'),
print: function (text) { console.log(text); },
printErr: function (text) { console.error(text); },
setStatus: function (text) {
if (!statusEl) return;
if (text) {
var m = /\((\d+)\/(\d+)\)/.exec(text);
if (m && +m[2] > 0) {
barEl.classList.add('known');
barEl.firstChild.style.width = Math.min(100, 100 * m[1] / m[2]) + '%';
}
textEl.textContent = text.replace('...', '\u2026');
return;
}
var el = statusEl;
statusEl = null;
el.classList.add('done');
setTimeout(function () { el.remove(); }, 260);
}
};
Module.canvas.addEventListener('keydown', function (e) {
if (e.key === 'Tab') e.preventDefault();
});
if (new URLSearchParams(location.search).has('keylog')) {
var keylog = document.createElement('script');
keylog.src = 'keylog.js';
document.head.appendChild(keylog);
}
Module.onRuntimeInitialized = function () { Module.setStatus(''); };
</script>
<script src="shell.js"></script>
{{{ SCRIPT }}}
</body>
</html>
+37
View File
@@ -0,0 +1,37 @@
var statusEl = document.getElementById('status');
var barEl = statusEl.querySelector('.bar');
var textEl = statusEl.querySelector('.text');
var Module = {
canvas: document.getElementById('canvas'),
print: function (text) { console.log(text); },
printErr: function (text) { console.error(text); },
setStatus: function (text) {
if (!statusEl) return;
if (text) {
var m = /\((\d+)\/(\d+)\)/.exec(text);
if (m && +m[2] > 0) {
barEl.classList.add('known');
barEl.firstChild.style.width = Math.min(100, 100 * m[1] / m[2]) + '%';
}
textEl.textContent = text.replace('...', '…');
return;
}
var el = statusEl;
statusEl = null;
el.classList.add('done');
setTimeout(function () { el.remove(); }, 260);
}
};
Module.canvas.addEventListener('contextmenu', function (e) { e.preventDefault(); });
Module.canvas.addEventListener('keydown', function (e) {
if (e.key === 'Tab') e.preventDefault();
});
if (new URLSearchParams(location.search).has('keylog')) {
var keylog = document.createElement('script');
keylog.src = 'keylog.js';
document.head.appendChild(keylog);
}
Module.onRuntimeInitialized = function () { Module.setStatus(''); };