Explorar o código

Use the Adwaita symbolic icons for ngui

ngui's icons (browser back/forward/reload/home, the files and gallery
icons) are now GNOME Adwaita symbolic icons instead of line drawings.

The unchanged *-symbolic.svg files live in assets/icons/adwaita/
(LGPL-3 / CC-BY-SA-3.0).  ICON_LIST in include/icon_abi.h names them and
generates enum ngui_icon and ngui_icon_name(); the order is the bundle
order, so append only.  STOP, CLOSE, SEARCH and MENU are new.

The host tool mkicons rasterizes each SVG with the browser's svg_raster.c
into a 16x16 coverage mask and writes one NBICO1 bundle,
/ramfs/icons/adwaita16.icn (3.3 KB, ~0.8 KB gzip).  Its XML reader only
accepts what symbolic icons use and fails the build on transforms,
strokes or unknown elements; -v prints an ASCII preview.

ngui_icon() reads the bundle once per process into BSS (safe across the
browser's heap_reset()), capped at the ids it knows, and blends the mask
tinted with the caller's colour.  The procedural fallback is gone: it
cost ~2 KB of code per app, and dropping it lets both packs carry the
bundle while the floppy lite pack still shrinks.  browser-host symlinks
icons/ into its /ramfs like fonts/.
Johannes Zellner hai 3 días
pai
achega
d00a58bec0

+ 2 - 0
.gitignore

@@ -36,3 +36,5 @@ host/build/
 browser-host
 browser-host
 host-curl
 host-curl
 firmware/
 firmware/
+/mkicons
+/icons/

+ 29 - 5
AGENTS.md

@@ -16,7 +16,8 @@ Targets i586 (first-gen Pentium); runs under QEMU or on real hardware.
 | `user/` | `ucmd_lib.h` (the ring-3 syscall wrappers) and `ucmd.ld` |
 | `user/` | `ucmd_lib.h` (the ring-3 syscall wrappers) and `ucmd.ld` |
 | `user/apps/<name>/` | One ring-3 program per directory: entry file `ucmd_<name>.c` plus private modules (`browser/` holds `browser.c`, `browser_html.c`, `js_*.c`, `svg_raster.c`; `chat/` holds `chat_login.c`; `gallery/` holds the real `gallery.c` behind the `ucmd_gallery.c` launcher; `hello/` has its own `hello.ld`) |
 | `user/apps/<name>/` | One ring-3 program per directory: entry file `ucmd_<name>.c` plus private modules (`browser/` holds `browser.c`, `browser_html.c`, `js_*.c`, `svg_raster.c`; `chat/` holds `chat_login.c`; `gallery/` holds the real `gallery.c` behind the `ucmd_gallery.c` launcher; `hello/` has its own `hello.ld`) |
 | `user/lib/<lib>/` | Ring-3 libraries: `libc`, `ngui`, `ufont`, `img`, `tls` (crypto incl. `wpa_crypto.c`), `uhttp`, `ujson`, `uwm` (`uwm_lib.c`), `wifi` (`wifi_store.c`, `wpa.c`); host tests live next to their library |
 | `user/lib/<lib>/` | Ring-3 libraries: `libc`, `ngui`, `ufont`, `img`, `tls` (crypto incl. `wpa_crypto.c`), `uhttp`, `ujson`, `uwm` (`uwm_lib.c`), `wifi` (`wifi_store.c`, `wpa.c`); host tests live next to their library |
-| `tools/` | Host tools (`mkpack.c`, `mkrootfs.c`, `mkrtwtbl.c`, `kexec_send.c`, `netkexec_send.c`, `netmonitor.c`, `flash.sh`) and the QMP test scripts |
+| `tools/` | Host tools (`mkpack.c`, `mkrootfs.c`, `mkrtwtbl.c`, `mkicons.c`, `kexec_send.c`, `netkexec_send.c`, `netmonitor.c`, `flash.sh`) and the QMP test scripts |
+| `assets/` | Imported assets: `assets/icons/adwaita/` (the Adwaita symbolic SVGs used as UI icons, LGPL-3 / CC-BY-SA-3.0, with README and licences) |
 | `host/` | Linux SDL3 browser harness |
 | `host/` | Linux SDL3 browser harness |
 
 
 The top-level `Makefile` builds everything.  Objects go to `build/`
 The top-level `Makefile` builds everything.  Objects go to `build/`
@@ -489,7 +490,7 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   press/release edges with a capture window, so a click that starts in a
   press/release edges with a capture window, so a click that starts in a
   window still gets its release after the pointer leaves.  The userland
   window still gets its release after the pointer leaves.  The userland
   `ngui.c/h` immediate-mode toolkit builds on those: clipped RGB565
   `ngui.c/h` immediate-mode toolkit builds on those: clipped RGB565
-  primitives, buttons, text input, procedural icons and scrolling panes
+  primitives, buttons, text input, the Adwaita symbolic icons and scrolling panes
   (`ngui_scroll`; `hide_bar` keeps wheel/key scrolling without drawing a
   (`ngui_scroll`; `hide_bar` keeps wheel/key scrolling without drawing a
   scrollbar).
   scrollbar).
   `files` (`ucmd_files.c`) is its first user; `gallery` (`gallery.c`) is the
   `files` (`ucmd_files.c`) is its first user; `gallery` (`gallery.c`) is the
@@ -1004,6 +1005,28 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `wifi.c` reloads on the next use.  Tested by QEMU `usb-host` passthrough
   `wifi.c` reloads on the next use.  Tested by QEMU `usb-host` passthrough
   on xHCI (C-cut chip, firmware 42.4): 2.4 + 5 GHz scan, WPA2-PSK connect
   on xHCI (C-cut chip, firmware 42.4): 2.4 + 5 GHz scan, WPA2-PSK connect
   and DHCP through the control panel.
   and DHCP through the control panel.
+- **UI icons**: ngui's icons are GNOME Adwaita symbolic icons
+  (adwaita-icon-theme 51, LGPL-3 or CC-BY-SA-3.0).  `assets/icons/adwaita/`
+  holds the unchanged `*-symbolic.svg` files; `ICON_LIST` (an X-macro in
+  `include/icon_abi.h`: enum suffix, short name, theme file) is the icon id
+  order and the bundle order, so append only, and it generates
+  `enum ngui_icon` (`NGUI_ICON_FOLDER` .. `NGUI_ICON_MENU`,
+  `NGUI_ICON_COUNT`) and `ngui_icon_name()`.  `tools/mkicons.c` rasterizes
+  each SVG with the browser's `svg_raster.c` into a 16x16 8-bit coverage
+  mask and writes one `NBICO1` bundle (16-byte header + masks, ~3.3 KB,
+  ~0.8 KB gzip) packed as `icons/adwaita16.icn` in **both** packs.  Its XML
+  reader handles only what symbolic icons use (`<svg viewBox>`, `<g>`,
+  `<path>`, `<rect>`, `<circle>`, `<ellipse>`, fill/fill-rule/opacity) and
+  fails the build on transforms, strokes, `style` or unknown elements.
+  `ngui_icon()` reads the bundle once per process into a BSS buffer (not
+  the libc heap, so the browser's `heap_reset()` cannot free it; the read is
+  capped at the ids this build knows, so a newer bundle with appended icons
+  still works) and blends the mask tinted with the caller's colour, centred
+  in the rectangle and clipped.  There is no line-drawn fallback: without
+  the bundle an icon is left blank (the old procedural drawings cost ~2 KB
+  of code per app and the floppy has a few hundred bytes to spare).
+  `browser-host` symlinks the repository's `icons/` into its `/ramfs` like
+  `fonts/`.
 - **Mouse**: `mouse.c/h` — cursor move/draw shared by the PS/2 path
 - **Mouse**: `mouse.c/h` — cursor move/draw shared by the PS/2 path
   (IntelliMouse including the 4th-byte wheel, Cirrus/Radeon hardware
   (IntelliMouse including the 4th-byte wheel, Cirrus/Radeon hardware
   cursor) and the USB backend.  Scroll from every backend accumulates in
   cursor) and the USB backend.  Scroll from every backend accumulates in
@@ -1268,8 +1291,8 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   is the variant that runs the bookkeeping without publishing the canvas, for
   is the variant that runs the bookkeeping without publishing the canvas, for
   apps that poll input without redrawing.
   apps that poll input without redrawing.
 - **Gallery**: `gallery.c` is the ngui widget gallery: typography and
 - **Gallery**: `gallery.c` is the ngui widget gallery: typography and
-  truncation, the drawing primitives and clip stack, the theme palette, all
-  nine icons, live buttons/icon buttons, text fields (including a disabled,
+  truncation, the drawing primitives and clip stack, the theme palette, every
+  icon in `ICON_LIST`, live buttons/icon buttons, text fields (including a disabled,
   read-only field) with event feedback, a nested draggable scroll pane and the
   read-only field) with event feedback, a nested draggable scroll pane and the
   `ngui_cut_*` layout helpers.  The real
   `ngui_cut_*` layout helpers.  The real
   ELF ships in the pack as `bin/gallery.app`; `ucmd_gallery.c` is the tiny
   ELF ships in the pack as `bin/gallery.app`; `ucmd_gallery.c` is the tiny
@@ -1898,7 +1921,8 @@ inflates it into page-allocated memory and mounts it read-only at `/ramfs`.
 The kernel image no longer contains it, so the pack no longer moves `_end`;
 The kernel image no longer contains it, so the pack no longer moves `_end`;
 the high-memory legacy path supports up to 2 MB (known issue 8).  The UI
 the high-memory legacy path supports up to 2 MB (known issue 8).  The UI
 font subsets live in the pack under `fonts/`, the WiFi firmware under
 font subsets live in the pack under `fonts/`, the WiFi firmware under
-`firmware/`, and the flat kernel at `install/kernel.bin` (full pack only;
+`firmware/`, the UI icons at `icons/adwaita16.icn` (both packs) and the
+flat kernel at `install/kernel.bin` (full pack only;
 `install self` reads it).  The floppy images use `cmds-lite.pack` (no
 `install self` reads it).  The floppy images use `cmds-lite.pack` (no
 firmware and no `install/kernel.bin`, to stay inside 1.44 MB).
 firmware and no `install/kernel.bin`, to stay inside 1.44 MB).
 
 

+ 21 - 5
Makefile

@@ -567,7 +567,7 @@ $(HOST_BUILD)/js_prelude.o: user/apps/browser/js_prelude.S user/apps/browser/js_
 $(HOST_BUILD)/user/apps/browser/browser.o: HOST_EXTRA = -D_start=browser_start
 $(HOST_BUILD)/user/apps/browser/browser.o: HOST_EXTRA = -D_start=browser_start
 $(HOST_BUILD)/user/apps/curl/ucmd_curl.o: HOST_EXTRA = -D_start=curl_start
 $(HOST_BUILD)/user/apps/curl/ucmd_curl.o: HOST_EXTRA = -D_start=curl_start
 
 
-browser-host: host-curl $(HOST_BROWSER_OBJS)
+browser-host: host-curl $(HOST_BROWSER_OBJS) | icons/adwaita16.icn
 	$(HOST_CC) $(HOST_LDFLAGS) -o $@ $(filter-out host-curl,$^) $(HOST_LDLIBS)
 	$(HOST_CC) $(HOST_LDFLAGS) -o $@ $(filter-out host-curl,$^) $(HOST_LDLIBS)
 
 
 host-curl: $(HOST_CURL_OBJS)
 host-curl: $(HOST_CURL_OBJS)
@@ -754,6 +754,9 @@ netkexec_send: tools/netkexec_send.c
 netmonitor: tools/netmonitor.c
 netmonitor: tools/netmonitor.c
 	gcc -O2 -o $@ $<
 	gcc -O2 -o $@ $<
 
 
+mkicons: tools/mkicons.c include/icon_abi.h user/apps/browser/svg_raster.c user/apps/browser/svg_raster.h
+	gcc -O2 -Wall -Wextra -Iinclude -o $@ tools/mkicons.c user/apps/browser/svg_raster.c -lm
+
 # ---- Command pack (the system rootfs) ---------------------------------------
 # ---- Command pack (the system rootfs) ---------------------------------------
 #
 #
 # The ring-3 command ELFs plus hello and the browser/gallery apps, packed
 # The ring-3 command ELFs plus hello and the browser/gallery apps, packed
@@ -761,13 +764,26 @@ netmonitor: tools/netmonitor.c
 FONT_FILES = fonts/sans.ttf fonts/sans-b.ttf fonts/sans-i.ttf \
 FONT_FILES = fonts/sans.ttf fonts/sans-b.ttf fonts/sans-i.ttf \
              fonts/sans-bi.ttf fonts/mono.ttf fonts/emoji.ttf
              fonts/sans-bi.ttf fonts/mono.ttf fonts/emoji.ttf
 
 
+# UI icons: the Adwaita symbolic SVGs (assets/icons/adwaita/, LGPL-3 /
+# CC-BY-SA-3.0) rasterized by mkicons (with the browser's svg_raster.c) into
+# one NBICO1 bundle of 16 px coverage masks (include/icon_abi.h) that ngui
+# loads from /ramfs/icons/adwaita16.icn and tints.  ~3.3 KB (~0.8 KB gzip),
+# so the floppy lite pack carries it as well.
+ICON_THEME = assets/icons/adwaita
+ICON_FILE = icons/adwaita16.icn
+$(ICON_FILE): mkicons $(wildcard $(ICON_THEME)/*.svg)
+	@mkdir -p icons
+	./mkicons $(ICON_THEME) 16 $@
+
 HELLO_ELF = $(U)/apps/hello/hello.elf
 HELLO_ELF = $(U)/apps/hello/hello.elf
 PACK_FILES = $(foreach a,$(UCMDS),bin/$(a)=$(call app,$(a)).elf) \
 PACK_FILES = $(foreach a,$(UCMDS),bin/$(a)=$(call app,$(a)).elf) \
              bin/hello=$(HELLO_ELF) \
              bin/hello=$(HELLO_ELF) \
              bin/browser.app=browser.elf \
              bin/browser.app=browser.elf \
              bin/gallery.app=gallery.elf \
              bin/gallery.app=gallery.elf \
-             $(foreach f,$(FONT_FILES),$(f)=$(f))
-PACK_DEPS = $(UCMD_ELFS) $(HELLO_ELF) browser.elf gallery.elf $(FONT_FILES) mkpack
+             $(foreach f,$(FONT_FILES),$(f)=$(f)) \
+             $(ICON_FILE)=$(ICON_FILE)
+PACK_DEPS = $(UCMD_ELFS) $(HELLO_ELF) browser.elf gallery.elf $(FONT_FILES) \
+            $(ICON_FILE) mkpack
 
 
 # `install self` reads the flat kernel from the full pack.  The lite/floppy
 # `install self` reads the flat kernel from the full pack.  The lite/floppy
 # pack deliberately omits it (no room on a 1.44 MB disk).
 # pack deliberately omits it (no room on a 1.44 MB disk).
@@ -1184,8 +1200,8 @@ clean:
 	      BOOTX64.EFI browser.elf gallery.elf *.boot.tmp \
 	      BOOTX64.EFI browser.elf gallery.elf *.boot.tmp \
 	      cmds.pack cmds-lite.pack cmds_pack_gz.bin cmds_lite_gz.bin \
 	      cmds.pack cmds-lite.pack cmds_pack_gz.bin cmds_lite_gz.bin \
 	      rootfs.bin rootfs-full.bin cmds.img \
 	      rootfs.bin rootfs-full.bin cmds.img \
-	      firmware/*.ucode firmware/*.tbl firmware/*.bin \
-	      mkpack mkrootfs mkrtwtbl kexec_send netkexec_send netmonitor \
+	      firmware/*.ucode firmware/*.tbl firmware/*.bin icons/*.icn \
+	      mkpack mkrootfs mkrtwtbl mkicons kexec_send netkexec_send netmonitor \
 	      browser-host host-curl \
 	      browser-host host-curl \
 	      ufont_test ufont_test_asan svg_test touchpad_gesture_test \
 	      ufont_test ufont_test_asan svg_test touchpad_gesture_test \
 	      ujson_test uhttp_cookie_test chat_login_test tls_test wpa_test \
 	      ujson_test uhttp_cookie_test chat_login_test tls_test wpa_test \

+ 10 - 0
assets/icons/adwaita/COPYING

@@ -0,0 +1,10 @@
+This work is licenced under the terms of either the GNU LGPL v3 or
+Creative Commons Attribution-Share Alike 3.0 United States License.
+
+To view a copy of the CC-BY-SA licence, visit
+http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
+Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA.
+
+When attributing the artwork, using "GNOME Project" is enough.
+Please link to http://www.gnome.org where available.
+

+ 7 - 0
assets/icons/adwaita/COPYING_CCBYSA3

@@ -0,0 +1,7 @@
+This work is licenced under the Creative Commons Attribution-Share Alike 3.0
+United States License. To view a copy of this licence, visit
+http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
+Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA.
+
+When attributing the artwork, using "GNOME Project" is enough. 
+Please link to http://www.gnome.org where available.

+ 165 - 0
assets/icons/adwaita/COPYING_LGPL

@@ -0,0 +1,165 @@
+                   GNU LESSER GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+  This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+  0. Additional Definitions.
+
+  As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+  "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+  An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+  A "Combined Work" is a work produced by combining or linking an
+Application with the Library.  The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+  The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+  The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+  1. Exception to Section 3 of the GNU GPL.
+
+  You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+  2. Conveying Modified Versions.
+
+  If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+   a) under this License, provided that you make a good faith effort to
+   ensure that, in the event an Application does not supply the
+   function or data, the facility still operates, and performs
+   whatever part of its purpose remains meaningful, or
+
+   b) under the GNU GPL, with none of the additional permissions of
+   this License applicable to that copy.
+
+  3. Object Code Incorporating Material from Library Header Files.
+
+  The object code form of an Application may incorporate material from
+a header file that is part of the Library.  You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+   a) Give prominent notice with each copy of the object code that the
+   Library is used in it and that the Library and its use are
+   covered by this License.
+
+   b) Accompany the object code with a copy of the GNU GPL and this license
+   document.
+
+  4. Combined Works.
+
+  You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+   a) Give prominent notice with each copy of the Combined Work that
+   the Library is used in it and that the Library and its use are
+   covered by this License.
+
+   b) Accompany the Combined Work with a copy of the GNU GPL and this license
+   document.
+
+   c) For a Combined Work that displays copyright notices during
+   execution, include the copyright notice for the Library among
+   these notices, as well as a reference directing the user to the
+   copies of the GNU GPL and this license document.
+
+   d) Do one of the following:
+
+       0) Convey the Minimal Corresponding Source under the terms of this
+       License, and the Corresponding Application Code in a form
+       suitable for, and under terms that permit, the user to
+       recombine or relink the Application with a modified version of
+       the Linked Version to produce a modified Combined Work, in the
+       manner specified by section 6 of the GNU GPL for conveying
+       Corresponding Source.
+
+       1) Use a suitable shared library mechanism for linking with the
+       Library.  A suitable mechanism is one that (a) uses at run time
+       a copy of the Library already present on the user's computer
+       system, and (b) will operate properly with a modified version
+       of the Library that is interface-compatible with the Linked
+       Version.
+
+   e) Provide Installation Information, but only if you would otherwise
+   be required to provide such information under section 6 of the
+   GNU GPL, and only to the extent that such information is
+   necessary to install and execute a modified version of the
+   Combined Work produced by recombining or relinking the
+   Application with a modified version of the Linked Version. (If
+   you use option 4d0, the Installation Information must accompany
+   the Minimal Corresponding Source and Corresponding Application
+   Code. If you use option 4d1, you must provide the Installation
+   Information in the manner specified by section 6 of the GNU GPL
+   for conveying Corresponding Source.)
+
+  5. Combined Libraries.
+
+  You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+   a) Accompany the combined library with a copy of the same work based
+   on the Library, uncombined with any other library facilities,
+   conveyed under the terms of this License.
+
+   b) Give prominent notice with the combined library that part of it
+   is a work based on the Library, and explaining where to find the
+   accompanying uncombined form of the same work.
+
+  6. Revised Versions of the GNU Lesser General Public License.
+
+  The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+  Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+  If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.

+ 21 - 0
assets/icons/adwaita/README

@@ -0,0 +1,21 @@
+Adwaita symbolic icons (16 px)
+
+Source:  the Arch Linux package adwaita-icon-theme 51.0
+         (/usr/share/icons/Adwaita/symbolic), upstream
+         https://gitlab.gnome.org/GNOME/adwaita-icon-theme
+Licence: GNU LGPL v3 or Creative Commons Attribution-Share Alike 3.0
+         (see COPYING, COPYING_LGPL, COPYING_CCBYSA3).  Attribution:
+         "GNOME Project", https://www.gnome.org
+
+The SVG files are copied unchanged from the symbolic/<context>/ folders
+(the context folder is dropped).  tools/mkicons.c rasterizes them with the
+browser's svg_raster.c into the NBICO1 bundle (include/icon_abi.h), one
+8-bit coverage mask per icon, packed as /ramfs/icons/adwaita16.icn.  ngui
+tints the masks with the theme colour.  ICON_LIST in include/icon_abi.h
+names the file for every icon; to add one, copy its -symbolic.svg here and
+append an ICON_LIST entry.
+
+mkicons understands what these files use: <path d>, <rect>, <circle>,
+<ellipse>, fill / fill-rule / opacity / fill-opacity on the element or an
+enclosing <g>.  It refuses transforms, strokes and anything else instead of
+drawing the icon wrong.

+ 1 - 0
assets/icons/adwaita/drive-harddisk-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M4 0C2.355469 0 1 1.355469 1 3v10c0 1.644531 1.355469 3 3 3h8c1.644531 0 3-1.355469 3-3V3c0-1.644531-1.355469-3-3-3zm0 2h8c.570312 0 1 .429688 1 1v9c0 .570312-.429688 1-1 1H4c-.554688 0-1-.445312-1-1V3c0-.554688.445312-1 1-1m4 1C5.789062 3 4 4.789062 4 7v4h4c2.5 0 4-1.789062 4-4s-1.789062-4-4-4m0 2c1.105469 0 2 .894531 2 2s-.894531 2-2 2-2-.894531-2-2 .894531-2 2-2m0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/folder-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M2.96875 1.003906c-1.644531 0-3 1.355469-3 3v8c0 1.644532 1.355469 3 3 3h10c1.644531 0 3-1.355468 3-3v-6c0-1.644531-1.355469-3-3-3H9.382812L7.675781 1.296875c-.1875-.1875-.441406-.292969-.707031-.292969zm0 2h3.585938l1 1H1.96875c0-.5625.4375-1 1-1m-1 2h11c.5625 0 1 .4375 1 1v6c0 .5625-.4375 1-1 1h-10c-.5625 0-1-.4375-1-1zm0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/go-home-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M8 .363281c-.5 0-1 .167969-1.40625.507813L2.128906 4.59375C1.414062 5.1875 1 6.070312 1 7v6c0 1.65625 1.34375 3 3 3h8c1.65625 0 3-1.34375 3-3V7c0-.929688-.414062-1.8125-1.128906-2.40625L9.40625.871094C9 .53125 8.5.363281 8 .363281m-.015625 1.996094c.050781-.003906.101563.011719.144531.046875l4.464844 3.722656C12.851562 6.34375 13 6.664062 13 7v6c0 .5625-.4375 1-1 1h-2V9c0-.554688-.445312-1-1-1H7c-.554688 0-1 .445312-1 1v5H4c-.5625 0-1-.4375-1-1V7c0-.335938.148438-.65625.40625-.871094L7.871094 2.40625c.035156-.027344.074218-.042969.113281-.046875m0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/go-next-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M4 2c0-.265625.105469-.519531.292969-.707031.390625-.390625 1.023437-.390625 1.414062 0l6 6C11.894531 7.480469 12 7.734375 12 8s-.105469.519531-.292969.707031l-6 6c-.390625.390625-1.023437.390625-1.414062 0C4.105469 14.519531 4 14.265625 4 14s.105469-.519531.292969-.707031L9.585938 8 4.292969 2.707031C4.105469 2.519531 4 2.265625 4 2m0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/go-previous-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M12 2c0-.265625-.105469-.519531-.292969-.707031-.390625-.390625-1.023437-.390625-1.414062 0l-6 6C4.105469 7.480469 4 7.734375 4 8s.105469.519531.292969.707031l6 6c.390625.390625 1.023437.390625 1.414062 0C11.894531 14.519531 12 14.265625 12 14s-.105469-.519531-.292969-.707031L6.414062 8l5.292969-5.292969C11.894531 2.519531 12 2.265625 12 2m0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/go-up-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M1 11c0-.265625.105469-.519531.292969-.707031l6-6c.390625-.390625 1.023437-.390625 1.414062 0l6 6c.1875.1875.292969.441406.292969.707031s-.105469.519531-.292969.707031c-.390625.390625-1.023437.390625-1.414062 0L8 6.414062l-5.292969 5.292969c-.390625.390625-1.023437.390625-1.414062 0C1.105469 11.519531 1 11.265625 1 11m0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/list-add-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M7 1v6H1v2h6v6h2V9h6V7H9V1zm0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/open-menu-symbolic.svg

@@ -0,0 +1 @@
+<svg width="16px" height="16px" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><g fill="#2e3436"><path d="m1 2h14v2h-14z"/><path d="m1 7h14v2h-14z"/><path d="m1 12h14v2h-14z"/></g></svg>

+ 1 - 0
assets/icons/adwaita/process-stop-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M3 2c-.265625 0-.519531.105469-.707031.292969-.390625.390625-.390625 1.023437 0 1.414062L6.585938 8l-4.292969 4.292969c-.390625.390625-.390625 1.023437 0 1.414062s1.023437.390625 1.414062 0L8 9.414062l4.292969 4.292969c.390625.390625 1.023437.390625 1.414062 0s.390625-1.023437 0-1.414062L9.414062 8l4.292969-4.292969c.390625-.390625.390625-1.023437 0-1.414062C13.519531 2.105469 13.265625 2 13 2s-.519531.105469-.707031.292969L8 6.585938 3.707031 2.292969C3.519531 2.105469 3.265625 2 3 2m0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/system-search-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M6.5 0C2.921875 0 0 2.921875 0 6.5s2.921875 6.496094 6.5 6.496094c1.429688 0 2.753906-.464844 3.828125-1.253906l2.945313 2.945312c.957031.9375 2.363281-.5 1.40625-1.4375L11.75 10.320312C12.535156 9.246094 13 7.925781 13 6.5 13 2.921875 10.078125 0 6.5 0m0 2C8.996094 2 11 4.003906 11 6.5s-2.003906 4.496094-4.5 4.496094S2 8.996094 2 6.5 4.003906 2 6.5 2m0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/text-x-generic-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M4.96875 1.003906c-1.644531 0-3 1.355469-3 3v9c0 1.644532 1.355469 3 3 3h6c1.644531 0 3-1.355468 3-3v-7.5c0-.265625-.105469-.519531-.292969-.707031l-3.5-3.5c-.1875-.1875-.441406-.292969-.707031-.292969zm0 2h4v1.5q0 1.5 1.5 1.5h1.5v7c0 .570313-.429688 1-1 1h-6c-.570312 0-1-.429687-1-1v-9c0-.570312.429688-1 1-1m0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/view-refresh-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M7.40625 1c-.613281.007812-1.234375.089844-1.847656.253906C2.285156 2.132812 0 5.109375 0 8.5s2.285156 6.367188 5.558594 7.242188c3.273437.878906 6.742187-.558594 8.4375-3.492188.277344-.480469.109375-1.089844-.367188-1.367188-.476562-.273437-1.089844-.109374-1.367187.367188-1.246094 2.160156-3.777344 3.207031-6.1875 2.5625C3.667969 13.167969 2 10.992188 2 8.5c0-2.496094 1.667969-4.667969 4.074219-5.3125 2.410156-.644531 4.941406.402344 6.1875 2.5625.058593.085938.125.164062.203125.226562l-.019532.015626L12.4375 6H11c-.550781 0-1 .449219-1 1 0 0 0 1 1 1h5V3s.003906-1-1-1c-.550781 0-1 .449219-1 1v1.6875l-.015625.011719-.011719.011719c-1.277344-2.179688-3.53125-3.519532-5.953125-3.691407C7.816406 1.003906 7.613281 1 7.40625 1m0 0"/></svg>

+ 1 - 0
assets/icons/adwaita/window-close-symbolic.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 16 16"><path fill="#2e3436" d="M4 4h1.03125c.253906.011719.511719.128906.6875.3125L8 6.59375l2.3125-2.28125c.265625-.230469.445312-.304688.6875-.3125h1v1c0 .285156-.035156.550781-.25.75L9.46875 8.03125l2.25 2.25c.1875.1875.28125.453125.28125.71875v1h-1c-.265625 0-.53125-.09375-.71875-.28125L8 9.4375l-2.28125 2.28125C5.53125 11.90625 5.265625 12 5 12H4v-1c0-.265625.09375-.53125.28125-.71875l2.28125-2.25L4.28125 5.75C4.070312 5.554688 3.976562 5.28125 4 5zm0 0"/></svg>

+ 29 - 2
docs/graphics.html

@@ -60,6 +60,7 @@
 			<li><a href="#ngui">ngui toolkit</a></li>
 			<li><a href="#ngui">ngui toolkit</a></li>
 			<li><a href="#apps">Applications</a></li>
 			<li><a href="#apps">Applications</a></li>
 			<li><a href="#images">Image library</a></li>
 			<li><a href="#images">Image library</a></li>
+			<li><a href="#icons">UI icons</a></li>
 			<li><a href="#gpu">GPU quirks</a></li>
 			<li><a href="#gpu">GPU quirks</a></li>
 			<li><a href="#backlight">Panel backlight</a></li>
 			<li><a href="#backlight">Panel backlight</a></li>
 			<li><a href="#sources">Source map</a></li>
 			<li><a href="#sources">Source map</a></li>
@@ -350,8 +351,8 @@
 		<p>
 		<p>
 			<span class="file">ngui.c</span>/<span class="file">ngui.h</span> is an
 			<span class="file">ngui.c</span>/<span class="file">ngui.h</span> is an
 			immediate-mode GUI toolkit shared by the ring-3 apps. It provides
 			immediate-mode GUI toolkit shared by the ring-3 apps. It provides
-			clipped RGB565 primitives, buttons, menu items, text fields, nine
-			procedural icons, a theme palette, layout cut helpers and scrolling
+			clipped RGB565 primitives, buttons, menu items, text fields, the
+			Adwaita symbolic icons (see <a href="#icons">UI icons</a>), a theme palette, layout cut helpers and scrolling
 			panes. It is linked into <code>files</code>, <code>mines</code>,
 			panes. It is linked into <code>files</code>, <code>mines</code>,
 			<code>solitaire</code>, <code>chat</code>, the control panel and
 			<code>solitaire</code>, <code>chat</code>, the control panel and
 			the real <code>gallery.elf</code>.
 			the real <code>gallery.elf</code>.
@@ -441,6 +442,31 @@
 		</ul>
 		</ul>
 	</section>
 	</section>
 
 
+	<section id="icons">
+		<h2>UI icons</h2>
+		<p>
+			ngui's icons (<code>ngui_icon()</code>, <code>ngui_icon_button()</code>:
+			back/forward, reload and home in the browser toolbar, folder/file/drive
+			in <code>files</code>) are GNOME Adwaita symbolic icons
+			(adwaita-icon-theme 51, LGPL-3 or CC-BY-SA-3.0).  The unchanged
+			<code>*-symbolic.svg</code> files live in
+			<span class="file">assets/icons/adwaita/</span>; the host tool
+			<span class="file">tools/mkicons.c</span> rasterizes each one with the
+			browser's <span class="file">svg_raster.c</span> into a 16&times;16
+			8-bit coverage mask and writes one <code>NBICO1</code> bundle,
+			<code>/ramfs/icons/adwaita16.icn</code> (layout in
+			<span class="file">include/icon_abi.h</span>): a 16-byte header and
+			13 masks, ~3.3&nbsp;KB raw and ~0.8&nbsp;KB gzip, so both the USB
+			and the floppy pack carry it.
+		</p>
+		<ul>
+			<li><strong>Icon list.</strong> <code>ICON_LIST</code> is an X-macro of enum suffix, short name and theme file.  Its order is the icon id and the bundle order (append only); it generates <code>enum ngui_icon</code> and <code>ngui_icon_name()</code>, and the gallery shows every entry.</li>
+			<li><strong>Tinting.</strong> Symbolic icons are one colour, so only coverage is stored.  <code>ngui_icon()</code> blends the mask in the caller's colour (the theme text colour on buttons, <code>icon_folder</code>/<code>icon_disk</code>/<code>icon_file</code> in <code>files</code>), centred and clipped.</li>
+			<li><strong>Loading.</strong> Each process reads the bundle once into a BSS buffer, so the browser's <code>heap_reset()</code> cannot free it.  The read is capped at the ids the app was built with, so an older app still works with a newer bundle.  Without the bundle the icon is left blank; there is no line-drawn fallback, because it cost ~2&nbsp;KB of code in each app.</li>
+			<li><strong>Strict converter.</strong> mkicons reads only what symbolic icons use (<code>&lt;svg viewBox&gt;</code>, <code>&lt;g&gt;</code>, <code>&lt;path&gt;</code>, <code>&lt;rect&gt;</code>, <code>&lt;circle&gt;</code>, <code>&lt;ellipse&gt;</code>, fill, fill-rule, opacity) and fails the build on transforms, strokes, <code>style</code> or unknown elements instead of drawing a wrong icon.  <code>./mkicons assets/icons/adwaita 16 out.icn -v</code> prints an ASCII preview of every mask.</li>
+		</ul>
+	</section>
+
 	<section id="gpu">
 	<section id="gpu">
 		<h2>GPU quirks</h2>
 		<h2>GPU quirks</h2>
 		<ul>
 		<ul>
@@ -492,6 +518,7 @@
 			<li><code>user/lib/img/img*.c</code> — image codecs</li>
 			<li><code>user/lib/img/img*.c</code> — image codecs</li>
 			<li><code>kernel/ati.c</code>, <code>kernel/nvidia.c</code>, <code>kernel/intel.c</code>, <code>kernel/nv50.c</code></li>
 			<li><code>kernel/ati.c</code>, <code>kernel/nvidia.c</code>, <code>kernel/intel.c</code>, <code>kernel/nv50.c</code></li>
 			<li><code>kernel/backlight.c</code>, <code>kernel/backlight.h</code> — Cherryview/VLV panel PWM</li>
 			<li><code>kernel/backlight.c</code>, <code>kernel/backlight.h</code> — Cherryview/VLV panel PWM</li>
+			<li><code>include/icon_abi.h</code>, <code>tools/mkicons.c</code>, <code>assets/icons/adwaita/</code> — UI icon list, the NBICO1 bundle and the Adwaita symbolic SVGs</li>
 		</ul>
 		</ul>
 	</section>
 	</section>
 </main>
 </main>

+ 1 - 1
docs/index.html

@@ -212,7 +212,7 @@
 			</a>
 			</a>
 			<a class="card" href="graphics.html">
 			<a class="card" href="graphics.html">
 				<h3>Graphics &amp; UI</h3>
 				<h3>Graphics &amp; UI</h3>
-				<p>VBE framebuffer, shadow buffer, damage rectangles, compositor, canvas ABI, ngui, the fixed-point TrueType text engine and image codecs.</p>
+				<p>VBE framebuffer, shadow buffer, damage rectangles, compositor, canvas ABI, ngui, the Adwaita UI icons, the fixed-point TrueType text engine and image codecs.</p>
 				<span class="card-tag">graphics.html</span>
 				<span class="card-tag">graphics.html</span>
 			</a>
 			</a>
 			<a class="card" href="network.html">
 			<a class="card" href="network.html">

+ 22 - 16
host/fs.c

@@ -67,11 +67,29 @@ int host_guest_to_host(const char *guest, char *out, size_t cap)
 	return 0;
 	return 0;
 }
 }
 
 
+/* Expose <repo>/<dir> (or <cwd>/<dir>) as <root>/ramfs/<dir>, the way the
+ * pack mounts the UI fonts and icons on the target. */
+static void link_repo_dir(const char *root, const char *dir)
+{
+	char src[HOST_PATH_MAX];
+	char link[HOST_PATH_MAX];
+	struct stat st;
+
+	snprintf(src, sizeof(src), "%s/%s", host_repo, dir);
+	if (access(src, R_OK) != 0) {
+		char cwd[HOST_PATH_MAX];
+
+		if (getcwd(cwd, sizeof(cwd)))
+			snprintf(src, sizeof(src), "%s/%s", cwd, dir);
+	}
+	snprintf(link, sizeof(link), "%s/ramfs/%s", root, dir);
+	if (access(src, R_OK) == 0 && lstat(link, &st) != 0)
+		symlink(src, link);
+}
+
 int host_fs_init(const char *root)
 int host_fs_init(const char *root)
 {
 {
 	char path[HOST_PATH_MAX];
 	char path[HOST_PATH_MAX];
-	char fonts[HOST_PATH_MAX];
-	char link[HOST_PATH_MAX];
 
 
 	if (mkdir_p(root) != 0)
 	if (mkdir_p(root) != 0)
 		return -1;
 		return -1;
@@ -85,20 +103,8 @@ int host_fs_init(const char *root)
 	if (mkdir_p(path) != 0)
 	if (mkdir_p(path) != 0)
 		return -1;
 		return -1;
 
 
-	snprintf(fonts, sizeof(fonts), "%s/fonts", host_repo);
-	if (access(fonts, R_OK) != 0) {
-		char cwd[HOST_PATH_MAX];
-
-		if (getcwd(cwd, sizeof(cwd)))
-			snprintf(fonts, sizeof(fonts), "%s/fonts", cwd);
-	}
-	snprintf(link, sizeof(link), "%s/ramfs/fonts", root);
-	if (access(fonts, R_OK) == 0) {
-		struct stat st;
-
-		if (lstat(link, &st) != 0)
-			symlink(fonts, link);
-	}
+	link_repo_dir(root, "fonts");
+	link_repo_dir(root, "icons");   /* built by `make icons/adwaita16.icn` */
 	return 0;
 	return 0;
 }
 }
 
 

+ 42 - 0
include/icon_abi.h

@@ -0,0 +1,42 @@
+/* UI icons and the NBICO1 icon bundle.
+ *
+ * Shared by ngui (user/lib/ngui: enum ngui_icon, ngui_icon()) and the host
+ * tool tools/mkicons.c, which rasterizes the Adwaita symbolic SVGs in
+ * assets/icons/adwaita/ into /ramfs/icons/adwaita16.icn.
+ *
+ * ICON_LIST is an X-macro: X(ENUM_SUFFIX, "short name", "theme file").  The
+ * order is the icon id and the order of the masks in the bundle, so append
+ * only. */
+#ifndef ICON_ABI_H
+#define ICON_ABI_H
+
+#define ICON_LIST(X) \
+	X(FOLDER,        "folder",  "folder-symbolic")         \
+	X(FILE,          "file",    "text-x-generic-symbolic") \
+	X(DISK,          "disk",    "drive-harddisk-symbolic") \
+	X(UP,            "up",      "go-up-symbolic")          \
+	X(HOME,          "home",    "go-home-symbolic")        \
+	X(REFRESH,       "refresh", "view-refresh-symbolic")   \
+	X(PLUS,          "plus",    "list-add-symbolic")       \
+	X(CHEVRON_LEFT,  "back",    "go-previous-symbolic")    \
+	X(CHEVRON_RIGHT, "forward", "go-next-symbolic")        \
+	X(STOP,          "stop",    "process-stop-symbolic")   \
+	X(CLOSE,         "close",   "window-close-symbolic")   \
+	X(SEARCH,        "search",  "system-search-symbolic")  \
+	X(MENU,          "menu",    "open-menu-symbolic")
+
+/* ---- NBICO1 bundle ------------------------------------------------------
+ * [struct icon_file_hdr][count x size*size coverage bytes]
+ * One 8-bit coverage mask per icon (0 = transparent, 255 = opaque), rows
+ * top to bottom, in ICON_LIST order.  Symbolic icons are single-colour, so
+ * the drawing side tints the mask with the theme colour.  Little-endian. */
+#define ICON_FILE_MAGIC "NBICO1\0\0"
+
+struct icon_file_hdr {
+	char magic[8];
+	unsigned short count;    /* number of masks */
+	unsigned short size;     /* mask edge in px, e.g. 16 */
+	unsigned int reserved;
+};
+
+#endif

+ 463 - 0
tools/mkicons.c

@@ -0,0 +1,463 @@
+/* mkicons: rasterize Adwaita symbolic SVGs into an NBICO1 icon bundle.
+ *
+ *   ./mkicons <theme-dir> <size> <out.icn> [-v]
+ *
+ * Every ICON_LIST entry (include/icon_abi.h) names <theme-dir>/<file>.svg.
+ * The SVG is drawn with the browser's svg_raster.c (the same antialiased
+ * rasterizer the browser uses for inline SVG) into a size x size coverage
+ * mask.  Symbolic icons are single-colour, so only coverage is kept; ngui
+ * tints it at draw time.  -v prints an ASCII preview of every mask.
+ *
+ * The XML reader is deliberately tiny: it handles what the symbolic theme
+ * uses (<svg viewBox>, <g>, <path>, <rect>, <circle>, <ellipse>, fill,
+ * fill-rule, opacity, fill-opacity) and fails loudly on anything else
+ * (transforms, strokes, style attributes, unknown elements) rather than
+ * producing a wrong icon. */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "icon_abi.h"
+#include "../user/apps/browser/svg_raster.h"
+
+#define ICON_MAX_SIZE 64
+#define PT_CAP        16384
+#define ATTR_MAX      16384
+#define GROUP_MAX     16
+
+struct icon_def {
+	const char *name;
+	const char *file;
+};
+
+#define ICON_DEF_(e, name, file) { name, file },
+static const struct icon_def icons[] = { ICON_LIST(ICON_DEF_) };
+#undef ICON_DEF_
+#define NICONS ((int)(sizeof(icons) / sizeof(icons[0])))
+
+static const char *cur_file;
+
+static void die(const char *msg, const char *detail)
+{
+	fprintf(stderr, "mkicons: %s: %s%s%s\n", cur_file ? cur_file : "-",
+		msg, detail ? ": " : "", detail ? detail : "");
+	exit(1);
+}
+
+static char *read_file(const char *path)
+{
+	FILE *f = fopen(path, "rb");
+	long n;
+	char *buf;
+
+	if (!f)
+		return NULL;
+	fseek(f, 0, SEEK_END);
+	n = ftell(f);
+	fseek(f, 0, SEEK_SET);
+	buf = malloc((size_t)n + 1);
+	if (!buf || fread(buf, 1, (size_t)n, f) != (size_t)n) {
+		fclose(f);
+		free(buf);
+		return NULL;
+	}
+	buf[n] = 0;
+	fclose(f);
+	return buf;
+}
+
+/* One start tag: name and the raw attribute text up to '>' or '/>'. */
+struct tag {
+	char name[32];
+	const char *attrs, *attrs_end;
+	int closing;            /* </name> */
+	int self_closing;       /* <name ... /> */
+};
+
+static int is_space(char c)
+{
+	return c == ' ' || c == '\t' || c == '\n' || c == '\r';
+}
+
+/* Advance to the next tag; returns 0 at the end of the document. */
+static int next_tag(const char **pp, struct tag *t)
+{
+	const char *p = *pp, *e;
+	unsigned int n = 0;
+
+	for (;;) {
+		p = strchr(p, '<');
+		if (!p)
+			return 0;
+		if (!strncmp(p, "<!--", 4)) {
+			e = strstr(p, "-->");
+			if (!e)
+				die("unterminated comment", NULL);
+			p = e + 3;
+			continue;
+		}
+		if (p[1] == '?' || p[1] == '!') {
+			e = strchr(p, '>');
+			if (!e)
+				die("unterminated declaration", NULL);
+			p = e + 1;
+			continue;
+		}
+		break;
+	}
+	p++;
+	memset(t, 0, sizeof(*t));
+	if (*p == '/') {
+		t->closing = 1;
+		p++;
+	}
+	while (*p && !is_space(*p) && *p != '>' && *p != '/') {
+		if (n + 1 < sizeof(t->name))
+			t->name[n++] = *p;
+		p++;
+	}
+	t->name[n] = 0;
+	t->attrs = p;
+	e = p;
+	while (*e && *e != '>') {
+		if (*e == '"' || *e == '\'') {
+			char q = *e++;
+
+			while (*e && *e != q)
+				e++;
+			if (!*e)
+				die("unterminated attribute", t->name);
+		}
+		e++;
+	}
+	if (!*e)
+		die("unterminated tag", t->name);
+	t->attrs_end = e;
+	if (e > p && e[-1] == '/') {
+		t->self_closing = 1;
+		t->attrs_end = e - 1;
+	}
+	*pp = e + 1;
+	return 1;
+}
+
+/* Copy attribute `name` into out; returns 1 when present. */
+static int attr(const struct tag *t, const char *name, char *out,
+		unsigned int outsz)
+{
+	const char *p = t->attrs;
+	size_t nl = strlen(name);
+
+	while (p < t->attrs_end) {
+		const char *ns, *ne, *vs;
+		char q;
+		unsigned int n = 0;
+
+		while (p < t->attrs_end && is_space(*p))
+			p++;
+		ns = p;
+		while (p < t->attrs_end && *p != '=' && !is_space(*p))
+			p++;
+		if (p >= t->attrs_end)
+			break;
+		ne = p;
+		vs = p;
+		while (vs < t->attrs_end && (is_space(*vs) || *vs == '='))
+			vs++;
+		if (vs >= t->attrs_end || (*vs != '"' && *vs != '\''))
+			die("malformed attribute", t->name);
+		q = *vs++;
+		p = vs;
+		while (p < t->attrs_end && *p != q)
+			p++;
+		if ((size_t)(ne - ns) == nl && !strncmp(ns, name, nl)) {
+			if ((size_t)(p - vs) + 1 > outsz)
+				die("attribute too long", name);
+			while (vs + n < p) {
+				out[n] = vs[n];
+				n++;
+			}
+			out[n] = 0;
+			return 1;
+		}
+		p++;
+	}
+	return 0;
+}
+
+/* Reject attributes the renderer would silently ignore. */
+static void check_attrs(const struct tag *t)
+{
+	static const char *const known[] = {
+		"xmlns", "xmlns:xlink", "width", "height", "viewBox", "version",
+		"id", "class", "fill", "fill-rule", "clip-rule", "opacity",
+		"fill-opacity", "d", "x", "y", "rx", "ry", "cx", "cy", "r",
+		"color", NULL
+	};
+	const char *p = t->attrs;
+
+	while (p < t->attrs_end) {
+		const char *ns;
+		char q;
+		int i, ok = 0;
+
+		while (p < t->attrs_end && is_space(*p))
+			p++;
+		ns = p;
+		while (p < t->attrs_end && *p != '=' && !is_space(*p))
+			p++;
+		if (p >= t->attrs_end)
+			break;
+		for (i = 0; known[i]; i++)
+			if ((size_t)(p - ns) == strlen(known[i]) &&
+			    !strncmp(ns, known[i], (size_t)(p - ns)))
+				ok = 1;
+		if (!ok) {
+			char nm[64];
+			size_t l = (size_t)(p - ns);
+
+			if (l >= sizeof(nm))
+				l = sizeof(nm) - 1;
+			memcpy(nm, ns, l);
+			nm[l] = 0;
+			/* stroke="none" is harmless; any real stroke is not. */
+			if (!strcmp(nm, "stroke")) {
+				char v[32];
+
+				if (attr(t, "stroke", v, sizeof(v)) &&
+				    !strcmp(v, "none"))
+					ok = 1;
+			}
+			if (!ok)
+				die("unsupported attribute", nm);
+		}
+		while (p < t->attrs_end && *p != '"' && *p != '\'')
+			p++;
+		q = *p++;
+		while (p < t->attrs_end && *p != q)
+			p++;
+		p++;
+	}
+}
+
+static double num_attr(const struct tag *t, const char *name, double def)
+{
+	char v[64];
+
+	if (!attr(t, name, v, sizeof(v)))
+		return def;
+	return strtod(v, NULL);
+}
+
+struct paint {
+	double opacity;         /* opacity * fill-opacity, inherited */
+	int none;               /* fill="none" */
+	int evenodd;
+};
+
+static void apply_paint(const struct tag *t, struct paint *p)
+{
+	char v[64];
+
+	if (attr(t, "fill", v, sizeof(v)))
+		p->none = !strcmp(v, "none");
+	if (attr(t, "fill-rule", v, sizeof(v)))
+		p->evenodd = !strcmp(v, "evenodd");
+	p->opacity *= num_attr(t, "opacity", 1.0);
+	p->opacity *= num_attr(t, "fill-opacity", 1.0);
+}
+
+static void render(const char *svg, int size, unsigned char *mask)
+{
+	static unsigned char ptbuf[PT_CAP * (2 * sizeof(float) + 1)];
+	static unsigned short px[ICON_MAX_SIZE * ICON_MAX_SIZE];
+	static char d[ATTR_MAX];
+	struct paint stack[GROUP_MAX];
+	struct svgr r;
+	struct svgr_layer L = { px, mask, size, size };
+	struct tag t;
+	const char *p = svg;
+	double m[6] = { 1, 0, 0, 1, 0, 0 };
+	int depth = 0, seen_svg = 0, shapes = 0;
+
+	memset(mask, 0, (size_t)size * (size_t)size);
+	memset(px, 0, sizeof(px));
+	svgr_init(&r, ptbuf, PT_CAP);
+	stack[0].opacity = 1.0;
+	stack[0].none = 0;
+	stack[0].evenodd = 0;
+
+	while (next_tag(&p, &t)) {
+		struct paint pt;
+
+		if (t.closing) {
+			if (!strcmp(t.name, "g") || !strcmp(t.name, "svg")) {
+				if (depth == 0)
+					die("unbalanced </g>", NULL);
+				depth--;
+			}
+			continue;
+		}
+		if (!strcmp(t.name, "title") || !strcmp(t.name, "desc") ||
+		    !strcmp(t.name, "metadata")) {
+			/* Skip the element's text; nested tags are not used. */
+			continue;
+		}
+		check_attrs(&t);
+		pt = stack[depth];
+		apply_paint(&t, &pt);
+
+		if (!strcmp(t.name, "svg")) {
+			char vb[128];
+			double vx = 0, vy = 0, vw = 16, vh = 16;
+
+			if (seen_svg++)
+				die("nested <svg>", NULL);
+			if (attr(&t, "viewBox", vb, sizeof(vb))) {
+				char *q = vb;
+
+				vx = strtod(q, &q);
+				while (*q == ',' || is_space(*q))
+					q++;
+				vy = strtod(q, &q);
+				while (*q == ',' || is_space(*q))
+					q++;
+				vw = strtod(q, &q);
+				while (*q == ',' || is_space(*q))
+					q++;
+				vh = strtod(q, &q);
+			}
+			if (vw <= 0 || vh <= 0 || vw != vh)
+				die("viewBox must be square", vb);
+			m[0] = m[3] = size / vw;
+			m[4] = -vx * m[0];
+			m[5] = -vy * m[3];
+		} else if (!strcmp(t.name, "g")) {
+			/* group: paint state only */
+		} else if (!strcmp(t.name, "path") || !strcmp(t.name, "rect") ||
+			   !strcmp(t.name, "circle") ||
+			   !strcmp(t.name, "ellipse")) {
+			if (!seen_svg)
+				die("shape outside <svg>", t.name);
+			svgr_reset(&r, m);
+			if (!strcmp(t.name, "path")) {
+				if (!attr(&t, "d", d, sizeof(d)))
+					die("<path> without d", NULL);
+				if (svgr_path(&r, d) != 0)
+					die("bad path data", NULL);
+			} else if (!strcmp(t.name, "rect")) {
+				double rx = num_attr(&t, "rx", -1);
+				double ry = num_attr(&t, "ry", -1);
+
+				if (rx < 0)
+					rx = ry < 0 ? 0 : ry;
+				if (ry < 0)
+					ry = rx;
+				svgr_rect(&r, num_attr(&t, "x", 0),
+					  num_attr(&t, "y", 0),
+					  num_attr(&t, "width", 0),
+					  num_attr(&t, "height", 0), rx, ry);
+			} else if (!strcmp(t.name, "circle")) {
+				double rr = num_attr(&t, "r", 0);
+
+				svgr_ellipse(&r, num_attr(&t, "cx", 0),
+					     num_attr(&t, "cy", 0), rr, rr);
+			} else {
+				svgr_ellipse(&r, num_attr(&t, "cx", 0),
+					     num_attr(&t, "cy", 0),
+					     num_attr(&t, "rx", 0),
+					     num_attr(&t, "ry", 0));
+			}
+			if (r.overflow)
+				die("path too complex", NULL);
+			if (!pt.none && pt.opacity > 0) {
+				unsigned int a = (unsigned int)(pt.opacity * 255.0 + 0.5);
+
+				svgr_fill(&r, &L, 0xFFFF, a > 255 ? 255 : a,
+					  pt.evenodd);
+				shapes++;
+			}
+		} else {
+			die("unsupported element", t.name);
+		}
+
+		if (!t.self_closing &&
+		    (!strcmp(t.name, "g") || !strcmp(t.name, "svg"))) {
+			if (++depth >= GROUP_MAX)
+				die("groups nested too deep", NULL);
+			stack[depth] = pt;
+		}
+	}
+	if (!shapes)
+		die("no filled shape", NULL);
+}
+
+static void preview(const char *name, const unsigned char *mask, int size)
+{
+	static const char ramp[] = " .:-=+*#%@";
+	int x, y;
+
+	fprintf(stderr, "%s\n", name);
+	for (y = 0; y < size; y++) {
+		for (x = 0; x < size; x++) {
+			int v = mask[y * size + x] * 9 / 255;
+
+			fputc(ramp[v], stderr);
+			fputc(ramp[v], stderr);
+		}
+		fputc('\n', stderr);
+	}
+}
+
+int main(int argc, char **argv)
+{
+	static unsigned char mask[ICON_MAX_SIZE * ICON_MAX_SIZE];
+	struct icon_file_hdr h;
+	char path[1024];
+	int size, verbose, i;
+	FILE *out;
+
+	if (argc < 4) {
+		fprintf(stderr, "usage: %s <theme-dir> <size> <out.icn> [-v]\n",
+			argv[0]);
+		return 2;
+	}
+	size = atoi(argv[2]);
+	verbose = argc > 4 && !strcmp(argv[4], "-v");
+	if (size < 8 || size > ICON_MAX_SIZE) {
+		fprintf(stderr, "mkicons: size must be 8..%d\n", ICON_MAX_SIZE);
+		return 2;
+	}
+	out = fopen(argv[3], "wb");
+	if (!out) {
+		perror(argv[3]);
+		return 1;
+	}
+	memset(&h, 0, sizeof(h));
+	memcpy(h.magic, ICON_FILE_MAGIC, 8);
+	h.count = (unsigned short)NICONS;
+	h.size = (unsigned short)size;
+	fwrite(&h, sizeof(h), 1, out);
+
+	for (i = 0; i < NICONS; i++) {
+		char *svg;
+
+		snprintf(path, sizeof(path), "%s/%s.svg", argv[1],
+			 icons[i].file);
+		cur_file = path;
+		svg = read_file(path);
+		if (!svg)
+			die("cannot read", NULL);
+		render(svg, size, mask);
+		free(svg);
+		if (verbose)
+			preview(icons[i].name, mask, size);
+		fwrite(mask, 1, (size_t)size * (size_t)size, out);
+	}
+	if (fclose(out) != 0) {
+		perror(argv[3]);
+		remove(argv[3]);
+		return 1;
+	}
+	return 0;
+}

+ 10 - 18
user/apps/gallery/gallery.c

@@ -82,7 +82,7 @@ static const char *const sec_descs[SEC_COUNT] = {
 	"styles, truncation and measurement",
 	"styles, truncation and measurement",
 	"rectangles, frames, lines and clipping",
 	"rectangles, frames, lines and clipping",
 	"the ngui_theme_dark palette",
 	"the ngui_theme_dark palette",
-	"all nine procedural icons",
+	"every Adwaita symbolic icon",
 	"buttons and icon buttons",
 	"buttons and icon buttons",
 	"single-line text fields",
 	"single-line text fields",
 	"a nested draggable scroll pane",
 	"a nested draggable scroll pane",
@@ -95,17 +95,6 @@ static const char *const color_names[15] = {
 	"button_down", "icon_folder", "icon_file", "icon_disk", "error"
 	"button_down", "icon_folder", "icon_file", "icon_disk", "error"
 };
 };
 
 
-static const enum ngui_icon icon_list[9] = {
-	NGUI_ICON_FOLDER, NGUI_ICON_FILE, NGUI_ICON_DISK,
-	NGUI_ICON_UP, NGUI_ICON_HOME, NGUI_ICON_REFRESH,
-	NGUI_ICON_PLUS, NGUI_ICON_CHEVRON_LEFT, NGUI_ICON_CHEVRON_RIGHT
-};
-
-static const char *const icon_names[9] = {
-	"folder", "file", "disk", "up", "home",
-	"refresh", "plus", "left", "right"
-};
-
 static const char *const list_items[LIST_ROWS] = {
 static const char *const list_items[LIST_ROWS] = {
 	"ngui_fill_rect", "ngui_frame", "ngui_line", "ngui_text",
 	"ngui_fill_rect", "ngui_frame", "ngui_line", "ngui_text",
 	"ngui_text_styled", "ngui_icon", "ngui_button",
 	"ngui_text_styled", "ngui_icon", "ngui_button",
@@ -638,7 +627,7 @@ static void draw_theme(struct ngui *g, struct ngui_rect card)
 
 
 static void draw_icons(struct ngui *g, struct ngui_rect card)
 static void draw_icons(struct ngui *g, struct ngui_rect card)
 {
 {
-	int cell = (card.w - 2 * CARD_PAD) / 9;
+	int cell = (card.w - 2 * CARD_PAD) / NGUI_ICON_COUNT;
 	int bs = cell >= 56 ? 40 : 30;
 	int bs = cell >= 56 ? 40 : 30;
 	int y = card.y + 12;
 	int y = card.y + 12;
 	int i;
 	int i;
@@ -647,7 +636,10 @@ static void draw_icons(struct ngui *g, struct ngui_rect card)
 
 
 	if (cell < 20)
 	if (cell < 20)
 		return;
 		return;
-	for (i = 0; i < 9; i++) {
+	if (bs > cell - 4)
+		bs = cell - 4;
+	for (i = 0; i < NGUI_ICON_COUNT; i++) {
+		const char *name = ngui_icon_name((enum ngui_icon)i);
 		int cx = card.x + CARD_PAD + i * cell;
 		int cx = card.x + CARD_PAD + i * cell;
 		int bx = cx + (cell - bs) / 2;
 		int bx = cx + (cell - bs) / 2;
 		int tw, tx, ly = y + bs + 4;
 		int tw, tx, ly = y + bs + 4;
@@ -655,13 +647,13 @@ static void draw_icons(struct ngui *g, struct ngui_rect card)
 
 
 		if (gallery_icon_button(g, ID_ICON_BASE + (unsigned int)i,
 		if (gallery_icon_button(g, ID_ICON_BASE + (unsigned int)i,
 					rect_make(bx, y, bs, bs),
 					rect_make(bx, y, bs, bs),
-					icon_list[i])) {
+					(enum ngui_icon)i)) {
 			char b[64];
 			char b[64];
 			unsigned int m = 0;
 			unsigned int m = 0;
 
 
 			icon_clicks++;
 			icon_clicks++;
 			s_append(b, &m, "icon '", sizeof(b));
 			s_append(b, &m, "icon '", sizeof(b));
-			s_append(b, &m, icon_names[i], sizeof(b));
+			s_append(b, &m, name, sizeof(b));
 			s_append(b, &m, "' - ", sizeof(b));
 			s_append(b, &m, "' - ", sizeof(b));
 			s_append_uint(b, &m, (unsigned int)icon_clicks,
 			s_append_uint(b, &m, (unsigned int)icon_clicks,
 				      sizeof(b));
 				      sizeof(b));
@@ -671,12 +663,12 @@ static void draw_icons(struct ngui *g, struct ngui_rect card)
 			ngui_invalidate(g);
 			ngui_invalidate(g);
 		}
 		}
 
 
-		tw = (int)ngui_text_width_ui(g, icon_names[i]);
+		tw = (int)ngui_text_width_ui(g, name);
 		tx = cx + (cell - tw) / 2;
 		tx = cx + (cell - tw) / 2;
 		lr = rect_make(cx + 2, ly, cell - 4, 16);
 		lr = rect_make(cx + 2, ly, cell - 4, 16);
 		if (tx < lr.x)
 		if (tx < lr.x)
 			tx = lr.x;
 			tx = lr.x;
-		ngui_text_ellipsis(g, lr, tx, ly, icon_names[i],
+		ngui_text_ellipsis(g, lr, tx, ly, name,
 				   g->theme.text_dim);
 				   g->theme.text_dim);
 	}
 	}
 
 

+ 109 - 49
user/lib/ngui/ngui.c

@@ -1212,61 +1212,121 @@ void ngui_text_ellipsis(struct ngui *ui, struct ngui_rect r, int x, int y,
 	}
 	}
 }
 }
 
 
+/* ---- Icons ------------------------------------------------------------
+ * The Adwaita symbolic masks are read once per process into BSS (not the
+ * libc heap, so the browser's heap_reset() cannot free them).  The read is
+ * capped at the icons this build knows: a newer bundle with appended icons
+ * still works, an older one leaves the missing ids blank. */
+#define NGUI_ICON_PX 16
+#define NGUI_ICON_BYTES (NGUI_ICON_PX * NGUI_ICON_PX)
+
+static unsigned char icon_data[sizeof(struct icon_file_hdr) +
+			       NGUI_ICON_COUNT * NGUI_ICON_BYTES + 512];
+static int icon_state;          /* 0 untried, 1 loaded, -1 unavailable */
+static unsigned int icon_count;
+
+#define NGUI_ICON_NAME_(e, name, file) name,
+static const char *const icon_names[NGUI_ICON_COUNT] = {
+	ICON_LIST(NGUI_ICON_NAME_)
+};
+#undef NGUI_ICON_NAME_
+
+const char *ngui_icon_name(enum ngui_icon icon)
+{
+	if ((unsigned int)icon >= NGUI_ICON_COUNT)
+		return "?";
+	return icon_names[icon];
+}
+
+static void icon_load(void)
+{
+	const struct icon_file_hdr *h = (const struct icon_file_hdr *)icon_data;
+	unsigned int max = sizeof(icon_data) - 512, have;
+	int n, i;
+
+	icon_state = -1;
+	/* The FAT path may write a final partial sector past `max`; the
+	 * buffer keeps 512 bytes of slack for it. */
+	n = u_syscall3(SYS_READ_FILE, (int)NGUI_ICON_PATH, (int)icon_data,
+		       (int)max);
+	if (n < (int)sizeof(*h))
+		return;
+	for (i = 0; i < 8; i++)
+		if (h->magic[i] != ICON_FILE_MAGIC[i])
+			return;
+	if (h->size != NGUI_ICON_PX)
+		return;
+	have = ((unsigned int)n - sizeof(*h)) / NGUI_ICON_BYTES;
+	if (have > h->count)
+		have = h->count;
+	if (have > NGUI_ICON_COUNT)
+		have = NGUI_ICON_COUNT;
+	icon_count = have;
+	icon_state = 1;
+}
+
+static const unsigned char *icon_mask(enum ngui_icon icon)
+{
+	if (icon_state == 0)
+		icon_load();
+	if (icon_state != 1 || (unsigned int)icon >= icon_count)
+		return 0;
+	return icon_data + sizeof(struct icon_file_hdr) +
+		(unsigned int)icon * NGUI_ICON_BYTES;
+}
+
+/* Tint a coverage mask with `color` and blend it over the canvas. */
+static void icon_blit(struct ngui *ui, int x, int y,
+		      const unsigned char *m, unsigned short color)
+{
+	int cx, cy, cw, ch, i, j;
+	int sr = color >> 11, sg = (color >> 5) & 63, sb = color & 31;
+
+	ngui_clip_bounds(ui, &cx, &cy, &cw, &ch);
+	for (j = 0; j < NGUI_ICON_PX; j++) {
+		int py = y + j;
+		unsigned short *row;
+
+		if (py < cy || py >= cy + ch)
+			continue;
+		row = ui->px + py * ui->w;
+		for (i = 0; i < NGUI_ICON_PX; i++) {
+			int px = x + i, a = m[j * NGUI_ICON_PX + i];
+			unsigned short d;
+			int dr, dg, db;
+
+			if (!a || px < cx || px >= cx + cw)
+				continue;
+			if (a == 255) {
+				row[px] = color;
+				continue;
+			}
+			d = row[px];
+			dr = d >> 11;
+			dg = (d >> 5) & 63;
+			db = d & 31;
+			dr += ((sr - dr) * a + 127) / 255;
+			dg += ((sg - dg) * a + 127) / 255;
+			db += ((sb - db) * a + 127) / 255;
+			row[px] = (unsigned short)((dr << 11) | (dg << 5) | db);
+		}
+	}
+}
+
 void ngui_icon(struct ngui *ui, struct ngui_rect r, enum ngui_icon icon,
 void ngui_icon(struct ngui *ui, struct ngui_rect r, enum ngui_icon icon,
 	       unsigned short color)
 	       unsigned short color)
 {
 {
 	int x = r.x + r.w / 2 - 8;
 	int x = r.x + r.w / 2 - 8;
 	int y = r.y + r.h / 2 - 8;
 	int y = r.y + r.h / 2 - 8;
+	const unsigned char *m;
 
 
-	switch (icon) {
-	case NGUI_ICON_FOLDER:
-		ngui_fill_rect(ui, rect_make(x + 1, y + 3, 7, 4), color);
-		ngui_fill_rect(ui, rect_make(x, y + 6, 16, 9), color);
-		break;
-	case NGUI_ICON_FILE:
-		ngui_frame(ui, rect_make(x + 2, y, 12, 16), color);
-		ngui_line(ui, x + 10, y, x + 13, y + 3, color);
-		ngui_fill_rect(ui, rect_make(x + 4, y + 7, 8, 1), color);
-		ngui_fill_rect(ui, rect_make(x + 4, y + 10, 8, 1), color);
-		break;
-	case NGUI_ICON_DISK:
-		ngui_frame(ui, rect_make(x, y + 2, 16, 12), color);
-		ngui_fill_rect(ui, rect_make(x + 2, y + 5, 12, 2), color);
-		ngui_fill_rect(ui, rect_make(x + 11, y + 9, 3, 3), color);
-		break;
-	case NGUI_ICON_UP:
-		ngui_line(ui, x + 8, y + 2, x + 3, y + 8, color);
-		ngui_line(ui, x + 8, y + 2, x + 13, y + 8, color);
-		ngui_fill_rect(ui, rect_make(x + 6, y + 7, 5, 7), color);
-		break;
-	case NGUI_ICON_HOME:
-		ngui_line(ui, x + 2, y + 8, x + 8, y + 2, color);
-		ngui_line(ui, x + 8, y + 2, x + 14, y + 8, color);
-		ngui_frame(ui, rect_make(x + 3, y + 8, 10, 7), color);
-		ngui_fill_rect(ui, rect_make(x + 7, y + 11, 3, 4), color);
-		break;
-	case NGUI_ICON_REFRESH:
-		ngui_line(ui, x + 3, y + 8, x + 6, y + 4, color);
-		ngui_line(ui, x + 6, y + 4, x + 10, y + 3, color);
-		ngui_line(ui, x + 10, y + 3, x + 13, y + 6, color);
-		ngui_line(ui, x + 13, y + 6, x + 13, y + 9, color);
-		ngui_fill_rect(ui, rect_make(x + 11, y + 1, 4, 4), color);
-		break;
-	case NGUI_ICON_PLUS:
-		ngui_fill_rect(ui, rect_make(x + 7, y + 3, 2, 10), color);
-		ngui_fill_rect(ui, rect_make(x + 3, y + 7, 10, 2), color);
-		break;
-	case NGUI_ICON_CHEVRON_LEFT:
-		ngui_line(ui, x + 10, y + 3, x + 6, y + 8, color);
-		ngui_line(ui, x + 6, y + 8, x + 10, y + 13, color);
-		break;
-	case NGUI_ICON_CHEVRON_RIGHT:
-		ngui_line(ui, x + 6, y + 3, x + 10, y + 8, color);
-		ngui_line(ui, x + 10, y + 8, x + 6, y + 13, color);
-		break;
-	default:
-		break;
-	}
+	if (!ui || !ui->px)
+		return;
+	/* Without the bundle (a stale /ramfs or a host run without
+	 * icons/) the icon is simply left out. */
+	m = icon_mask(icon);
+	if (m)
+		icon_blit(ui, x, y, m, color);
 }
 }
 
 
 int ngui_button(struct ngui *ui, unsigned int id, struct ngui_rect r,
 int ngui_button(struct ngui *ui, unsigned int id, struct ngui_rect r,

+ 14 - 9
user/lib/ngui/ngui.h

@@ -8,6 +8,7 @@
 
 
 #include "syscall.h"
 #include "syscall.h"
 #include "wm_abi.h"
 #include "wm_abi.h"
+#include "icon_abi.h"
 
 
 #define NGUI_INPUT_MAX 512
 #define NGUI_INPUT_MAX 512
 #define NGUI_MOTION_REDRAW_MS 33
 #define NGUI_MOTION_REDRAW_MS 33
@@ -67,17 +68,21 @@ struct ngui_theme {
 
 
 extern const struct ngui_theme ngui_theme_dark;
 extern const struct ngui_theme ngui_theme_dark;
 
 
+/* Icons come from the Adwaita symbolic set (include/icon_abi.h): ngui loads
+ * /ramfs/icons/adwaita16.icn on first use and tints the 16 px masks with the
+ * colour passed to ngui_icon().  Both packs carry the bundle; without it
+ * ngui_icon() draws nothing. */
+#define NGUI_ICON_ENUM_(e, name, file) NGUI_ICON_##e,
 enum ngui_icon {
 enum ngui_icon {
-	NGUI_ICON_FOLDER,
-	NGUI_ICON_FILE,
-	NGUI_ICON_DISK,
-	NGUI_ICON_UP,
-	NGUI_ICON_HOME,
-	NGUI_ICON_REFRESH,
-	NGUI_ICON_PLUS,
-	NGUI_ICON_CHEVRON_LEFT,
-	NGUI_ICON_CHEVRON_RIGHT
+	ICON_LIST(NGUI_ICON_ENUM_)
+	NGUI_ICON_COUNT
 };
 };
+#undef NGUI_ICON_ENUM_
+
+#define NGUI_ICON_PATH "/ramfs/icons/adwaita16.icn"
+
+/* Short display name of an icon ("folder", "back", ...). */
+const char *ngui_icon_name(enum ngui_icon icon);
 
 
 struct ngui_input {
 struct ngui_input {
 	char text[NGUI_INPUT_MAX];
 	char text[NGUI_INPUT_MAX];