diff --git a/The-Kurgan-Sword.png b/The-Kurgan-Sword.png new file mode 100644 index 0000000..7a04404 Binary files /dev/null and b/The-Kurgan-Sword.png differ diff --git a/kurgan/assets/hilt.png b/kurgan/assets/hilt.png new file mode 100644 index 0000000..5e49211 Binary files /dev/null and b/kurgan/assets/hilt.png differ diff --git a/kurgan/assets/kurgan.ico b/kurgan/assets/kurgan.ico new file mode 100644 index 0000000..aa9ea83 Binary files /dev/null and b/kurgan/assets/kurgan.ico differ diff --git a/kurgan/assets/make_assets.py b/kurgan/assets/make_assets.py new file mode 100644 index 0000000..a01f868 --- /dev/null +++ b/kurgan/assets/make_assets.py @@ -0,0 +1,127 @@ +"""Make The Kurgan's logo and icons from the source photo, The-Kurgan-Sword.png (repo root). + + .venv\\Scripts\\python.exe -m kurgan.assets.make_assets [source.png] + +Writes: + kurgan/assets/sword.png the whole sword, cleaned and trimmed (master copy) + kurgan/assets/hilt.png 512 px square: the crossguard centred and as large as it fits + kurgan/assets/kurgan.ico the tray icon (16-256 px), from the hilt + kurgan/web/static/logo.png the web UI's header logo: the whole sword, the cut-off blade faded out + kurgan/web/static/sword-vertical.png the web UI's backdrop: the whole sword, full size, turned 90° + clockwise (pommel up); the page's bottom edge cuts the blade off + kurgan/web/static/favicon.ico the browser tab icon, from the hilt + +Cleaning: the photo was cut out of a white background, leaving a pale one-pixel fringe and +stair-stepped edges. The outline is pulled in by a pixel, edge pixels take the colour of the +sword next to them instead of white, and the edge is smoothed to about a pixel wide. + +Small icons (32 px and under) have their metal brightened a little: at 16 px on a dark taskbar +the mid-grey crossguard otherwise reads as black. The black grip still disappears there; an +outline was tried and made the 16 px icon a blur. +""" + +from __future__ import annotations + +import os +import sys + +import numpy as np +from PIL import Image, ImageFilter + +HERE = os.path.dirname(os.path.abspath(__file__)) +ROOT = os.path.dirname(os.path.dirname(HERE)) +STATIC = os.path.join(ROOT, "kurgan", "web", "static") +SOURCE = os.path.join(ROOT, "The-Kurgan-Sword.png") + +ICON_SIZES = (16, 20, 24, 32, 40, 48, 64, 256) # tray: 16 at 100% scaling up to 32 at 200%; the rest for Windows +FAVICON_SIZES = (16, 32, 48) +LOGO_HEIGHT = 96 # shown 40 px high in the header: sharp up to about 240% scaling +SMALL_LIFT = 1.35 # gamma applied to icons of 32 px and under +BLADE_FADE = 0.18 # the last 18% of the header logo's width fades out (the photo cuts the blade off) + + +def _bleed(rgb: np.ndarray, known: np.ndarray, steps: int) -> np.ndarray: + """Give pixels outside `known` the average colour of their known neighbours, ring by ring.""" + rgb, known = rgb.copy(), known.copy() + for _ in range(steps): + acc = np.zeros_like(rgb) + count = np.zeros(known.shape, np.float32) + for dy in (-1, 0, 1): + for dx in (-1, 0, 1): + if dy or dx: + k = np.roll(known, (dy, dx), (0, 1)) + acc += np.roll(rgb, (dy, dx), (0, 1)) * k[..., None] + count += k + new = ~known & (count > 0) + rgb[new] = acc[new] / count[new][:, None] + known |= new + return rgb + + +def clean(path: str) -> Image.Image: + """The sword without its white fringe, with smooth edges, trimmed to its outline.""" + src = np.asarray(Image.open(path).convert("RGBA")).astype(np.float32) + solid = Image.fromarray(((src[..., 3] > 128) * 255).astype(np.uint8)) + core_img = solid.filter(ImageFilter.MinFilter(3)) # one pixel in: drops the fringe + core = np.asarray(core_img) > 0 + rgb = _bleed(src[..., :3], core, 8) # edges take the sword's colour, not white + soft = np.asarray(core_img.filter(ImageFilter.GaussianBlur(1.0))).astype(np.float32) / 255 + alpha = np.clip((soft - 0.5) * 2.0 + 0.5, 0, 1) # smooth, about a pixel wide + img = Image.fromarray(np.dstack([rgb, alpha * 255]).round().clip(0, 255).astype(np.uint8), "RGBA") + return img.crop(img.getchannel("A").point(lambda v: 255 if v > 8 else 0).getbbox()) + + +def hilt(sword: Image.Image) -> Image.Image: + """A square around the crossguard (the columns where the sword is tallest), as large as fits.""" + a = np.asarray(sword.getchannel("A")) > 128 + guard = np.nonzero(a.sum(0) > 0.6 * a.shape[0])[0] + rows = np.nonzero(a[:, guard].any(1))[0] + cx, cy = (guard.min() + guard.max()) / 2, (rows.min() + rows.max()) / 2 + side = round((rows.max() - rows.min() + 1) * 1.03) + left, top = round(cx - side / 2), round(cy - side / 2) + square = Image.new("RGBA", (side, side), (0, 0, 0, 0)) + piece = sword.crop((max(left, 0), max(top, 0), min(left + side, sword.width), min(top + side, sword.height))) + square.alpha_composite(piece, (max(-left, 0), max(-top, 0))) + return square + + +def icon_image(square: Image.Image, size: int) -> Image.Image: + small = square.resize((size, size), Image.LANCZOS) + if size > 32: + return small + small = small.filter(ImageFilter.UnsharpMask(0.6, 80, 0)) + r, g, b, a = small.split() + lift = [round(255 * (v / 255) ** (1 / SMALL_LIFT)) for v in range(256)] + return Image.merge("RGBA", (r.point(lift), g.point(lift), b.point(lift), a)) + + +def save_ico(square: Image.Image, path: str, sizes: tuple[int, ...]) -> None: + images = [icon_image(square, s) for s in sizes] + images[-1].save(path, format="ICO", sizes=[(s, s) for s in sizes], append_images=images[:-1]) + + +def header_logo(sword: Image.Image) -> Image.Image: + width = round(sword.width * LOGO_HEIGHT / sword.height) + logo = sword.resize((width, LOGO_HEIGHT), Image.LANCZOS) + x = np.linspace(0, 1, width) + t = np.clip((x - (1 - BLADE_FADE)) / BLADE_FADE, 0, 1) + fade = 1 - t * t * (3 - 2 * t) # smoothstep down to nothing at the tip + alpha = np.asarray(logo.getchannel("A")).astype(np.float32) * fade[None, :] + logo.putalpha(Image.fromarray(alpha.round().astype(np.uint8))) + return logo + + +def main(source: str = SOURCE) -> None: + sword = clean(source) + sword.save(os.path.join(HERE, "sword.png"), optimize=True) + square = hilt(sword) + square.resize((512, 512), Image.LANCZOS).save(os.path.join(HERE, "hilt.png"), optimize=True) + save_ico(square, os.path.join(HERE, "kurgan.ico"), ICON_SIZES) + header_logo(sword).save(os.path.join(STATIC, "logo.png"), optimize=True) + sword.transpose(Image.Transpose.ROTATE_270).save(os.path.join(STATIC, "sword-vertical.png"), optimize=True) + save_ico(square, os.path.join(STATIC, "favicon.ico"), FAVICON_SIZES) + print(f"sword {sword.size}, hilt {square.size} -> 512, icons {ICON_SIZES}, logo height {LOGO_HEIGHT}") + + +if __name__ == "__main__": + main(*sys.argv[1:2]) diff --git a/kurgan/assets/sword.png b/kurgan/assets/sword.png new file mode 100644 index 0000000..724f060 Binary files /dev/null and b/kurgan/assets/sword.png differ diff --git a/kurgan/theme.py b/kurgan/theme.py index d88841d..cca8a38 100644 --- a/kurgan/theme.py +++ b/kurgan/theme.py @@ -1,4 +1,4 @@ -"""Colours and thresholds shared by the LCD, the case/RAM lighting and the tray icon.""" +"""Colours and thresholds shared by the LCD and the case/RAM lighting.""" from __future__ import annotations diff --git a/kurgan/tray.py b/kurgan/tray.py index 2416b01..a2a6fcc 100644 --- a/kurgan/tray.py +++ b/kurgan/tray.py @@ -18,11 +18,14 @@ from __future__ import annotations import ctypes import ctypes.wintypes as wt import logging +import os import subprocess import threading log = logging.getLogger(__name__) +# The sword's hilt, 16-256 px (made by kurgan/assets/make_assets.py from The-Kurgan-Sword.png). +ICON_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets", "kurgan.ico") TASK_NAME = "The Kurgan" LEGACY_TASK_NAME = "TT LCD Dashboard" # until setup.ps1 re-registers the task @@ -84,37 +87,6 @@ def set_autostart(on: bool) -> None: _powershell(_SET.replace("%TASK%", name).replace("%ON%", "$true" if on else "$false")) -# ----------------------------------------------------------------------------- icon image - -def make_icon(path: str, layers: list[tuple[int, int, int]]) -> str: - """Draw a small version of the dashboard's power tank and save it as a .ico file. - - layers: colours from the bottom up (other, CPU, GPU). - """ - from PIL import Image, ImageDraw - - s = 256 - img = Image.new("RGBA", (s, s), (0, 0, 0, 0)) - d = ImageDraw.Draw(img) - chrome, dark = (206, 206, 212, 255), (20, 20, 24, 255) - x0, x1 = 52, 204 # glass - d.rectangle([x0, 30, x1, 226], fill=dark) - y = 226 - for h, c in zip((50, 42, 56), layers): # bottom up - d.rectangle([x0, y - h, x1, y], fill=c + (255,)) - y -= h - d.rectangle([x0, y - 3, x1, y + 3], fill=dark) - hl = Image.new("RGBA", (s, s), (0, 0, 0, 0)) - ImageDraw.Draw(hl).rectangle([x0 + 22, 36, x0 + 40, 222], fill=(255, 255, 255, 70)) - img.alpha_composite(hl) - d = ImageDraw.Draw(img) - for y0, y1 in ((4, 40), (216, 252)): # end caps - d.rounded_rectangle([28, y0, 228, y1], radius=12, fill=chrome) - d.rectangle([28, (y0 + y1) // 2 - 2, 228, (y0 + y1) // 2 + 2], fill=(120, 120, 128, 255)) - img.save(path, sizes=[(16, 16), (20, 20), (24, 24), (32, 32), (40, 40), (48, 48), (64, 64)]) - return path - - # ----------------------------------------------------------------------------- Win32 _u32 = ctypes.WinDLL("user32", use_last_error=True) @@ -418,16 +390,10 @@ class TrayIcon: if __name__ == "__main__": # Quick check: show the icon for 20 s with a test tooltip. - import os - import tempfile - import time - logging.basicConfig(level=logging.INFO, format="%(levelname)s %(message)s") print("Start with Windows:", autostart_enabled()) - path = make_icon(os.path.join(tempfile.gettempdir(), "kurgan_tray_test.ico"), - [(217, 89, 38), (57, 135, 229), (25, 158, 112)]) done = threading.Event() - tray = TrayIcon("The Kurgan (test)", path, on_exit=done.set, status_lines=lambda: ["Test run"]) + tray = TrayIcon("The Kurgan (test)", ICON_PATH, on_exit=done.set, status_lines=lambda: ["Test run"]) tray.start() for i in range(20): tray.set_tooltip(f"The Kurgan (test)\n{i} s") diff --git a/kurgan/web/static/favicon.ico b/kurgan/web/static/favicon.ico new file mode 100644 index 0000000..490dd2b Binary files /dev/null and b/kurgan/web/static/favicon.ico differ diff --git a/kurgan/web/static/favicon.svg b/kurgan/web/static/favicon.svg deleted file mode 100644 index ca54d5f..0000000 --- a/kurgan/web/static/favicon.svg +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/kurgan/web/static/logo.png b/kurgan/web/static/logo.png new file mode 100644 index 0000000..74741de Binary files /dev/null and b/kurgan/web/static/logo.png differ diff --git a/kurgan/web/static/style.css b/kurgan/web/static/style.css index ab1101e..1bf9f4a 100644 --- a/kurgan/web/static/style.css +++ b/kurgan/web/static/style.css @@ -73,9 +73,10 @@ button, select, input { font: inherit; color: inherit; } background: color-mix(in srgb, var(--page) 92%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid var(--border); + anchor-name: --masthead; } .brand { display: flex; align-items: center; gap: 10px; } -.brand svg { width: 22px; height: 22px; } +.brand img { display: block; width: auto; height: 40px; } .brand h1 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: 0.22em; color: var(--brand); } @@ -97,6 +98,20 @@ button, select, input { font: inherit; color: inherit; } } .banner .note { margin: 0; font-size: 14px; } +/* ---------------------------------------------------------------- the sword behind everything + Full size, pommel up, from just below the header to the bottom of the window, lined up with + the right edge of the tiles. Fixed: the page scrolls over it. The top follows the header's + height (it wraps on narrow windows); browsers without anchor positioning assume one row. */ +body::after { + content: ""; position: fixed; z-index: -1; pointer-events: none; + top: 71px; bottom: 0; left: 0; + right: calc(max(0px, (100% - 1480px) / 2) + 24px); /* main's max-width and padding */ + background: url("/static/sword-vertical.png") right top / auto 100% no-repeat; +} +@supports (top: anchor(--masthead bottom)) { + body::after { top: anchor(--masthead bottom); } +} + /* ---------------------------------------------------------------- layout */ main { padding: 8px 24px 40px; max-width: 1480px; margin: 0 auto; } section { margin-top: 28px; } @@ -107,7 +122,10 @@ section > h2 { .grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; margin-top: 16px; } .grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-top: 16px; } .card { - background: var(--surface); border: 1px solid var(--border); border-radius: 10px; + /* The sword shows through. 90% keeps the grey text at 4.5:1 or better over the brightest + metal (dark theme) and the black grip (light theme); 80% dropped it to 3.4:1. */ + background: color-mix(in srgb, var(--surface) 90%, transparent); + border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; margin: 0; min-width: 0; } .card h3 { margin: 0 0 2px; font-size: 15px; font-weight: 600; } @@ -264,6 +282,7 @@ footer { color: var(--text-2); font-size: 12.5px; padding: 0 24px 28px; max-widt @media (max-width: 720px) { .masthead { padding: 10px 14px; gap: 12px; } main { padding: 8px 14px 32px; } + body::after { right: 14px; } .hero-value { font-size: 36px; } .grid2 { grid-template-columns: 1fr; } } diff --git a/kurgan/web/static/sword-vertical.png b/kurgan/web/static/sword-vertical.png new file mode 100644 index 0000000..1424c29 Binary files /dev/null and b/kurgan/web/static/sword-vertical.png differ