From b5b8f08100c5617efc25ff16097648d4cc1eec92 Mon Sep 17 00:00:00 2001 From: treeform Date: Wed, 28 Oct 2026 09:48:40 -0700 Subject: [PATCH] add custom cursors to web backend --- src/windy/platforms/emscripten/platform.nim | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/windy/platforms/emscripten/platform.nim b/src/windy/platforms/emscripten/platform.nim index cfd36f3..efc0387 100644 --- a/src/windy/platforms/emscripten/platform.nim +++ b/src/windy/platforms/emscripten/platform.nim @@ -1,5 +1,5 @@ import - std/[tables, strutils, unicode, times], + std/[base64, tables, strutils, unicode, times], ../../common, ../../internal, vmath, pixie # include for EMSCRIPTEN_KEEPALIVE @@ -395,6 +395,7 @@ proc cursor*(window: Window): Cursor = window.state.cursor proc `cursor=`*(window: Window, cursor: Cursor) = + ## Sets the cursor displayed over the canvas. window.state.cursor = cursor case cursor.kind: of ArrowCursor: @@ -426,8 +427,22 @@ proc `cursor=`*(window: Window, cursor: Cursor) = of WaitCursor: set_cursor("wait") of CustomCursor: - # TODO base64 encode Image? - set_cursor("auto") + if cursor.image == nil: + set_cursor("auto") + else: + let + data = + try: + base64.encode(cursor.image.encodeImage(PngFormat)) + except PixieError as error: + raise newException( + WindyError, + "Unable to encode cursor image: " & error.msg, + error + ) + value = "url(\"data:image/png;base64," & data & "\") " & + $cursor.hotspot.x & " " & $cursor.hotspot.y & ", crosshair" + set_cursor(value.cstring) # Style functions proc style*(window: Window): WindowStyle =