# HG changeset patch # User Sam # Date 1682779132 -25200 # Node ID bf2f4a9cd962ce77858f9173c6eceaae42205c8e # Parent c48ceb622b27ac9c7eef735e0d2d75791b952224 add: option to show/hide cursor diff -r c48ceb622b27 -r bf2f4a9cd962 examples/E10_pong.nim --- a/examples/E10_pong.nim Sat Apr 29 05:40:11 2023 -0700 +++ b/examples/E10_pong.nim Sat Apr 29 21:38:52 2023 +0700 @@ -66,7 +66,15 @@ height = float32(winsize[1]) / float32(winsize[0]) width = 1'f currentTime = cpuTime() + showSystemCursor = true while myengine.updateInputs() == Running and not myengine.keyWasPressed(Escape): + if myengine.keyWasPressed(C): + if showSystemCursor: + myengine.hideSystemCursor() + else: + myengine.showSystemCursor() + showSystemCursor = not showSystemCursor + let dt: float32 = cpuTime() - currentTime currentTime = cpuTime() if myengine.windowWasResized(): diff -r c48ceb622b27 -r bf2f4a9cd962 semicongine.nimble --- a/semicongine.nimble Sat Apr 29 05:40:11 2023 -0700 +++ b/semicongine.nimble Sat Apr 29 21:38:52 2023 +0700 @@ -11,3 +11,5 @@ requires "nim >= 1.6.10" requires "winim" +requires "xlib" +requires "alsa" diff -r c48ceb622b27 -r bf2f4a9cd962 src/semicongine/engine.nim --- a/src/semicongine/engine.nim Sat Apr 29 05:40:11 2023 -0700 +++ b/src/semicongine/engine.nim Sat Apr 29 21:38:52 2023 +0700 @@ -152,6 +152,7 @@ engine.resizeHandler(engine) return engine.state +# wrappers for internal things func keyIsDown*(engine: Engine, key: Key): auto = key in engine.input.keyIsDown func keyWasPressed*(engine: Engine, key: Key): auto = key in engine.input.keyWasPressed func keyWasReleased*(engine: Engine, key: Key): auto = key in engine.input.keyWasReleased @@ -164,3 +165,5 @@ func gpuDevice*(engine: Engine): Device = engine.device func getWindow*(engine: Engine): auto = engine.window func windowWasResized*(engine: Engine): auto = engine.input.windowWasResized +func showSystemCursor*(engine: Engine) = engine.window.showSystemCursor() +func hideSystemCursor*(engine: Engine) = engine.window.hideSystemCursor() diff -r c48ceb622b27 -r bf2f4a9cd962 src/semicongine/platform/linux/window.nim --- a/src/semicongine/platform/linux/window.nim Sat Apr 29 05:40:11 2023 -0700 +++ b/src/semicongine/platform/linux/window.nim Sat Apr 29 21:38:52 2023 +0700 @@ -54,13 +54,15 @@ var data = "\0".cstring var pixmap = XCreateBitmapFromData(display, window, data, 1, 1) var color: XColor - var empty_cursor = XCreatePixmapCursor(display, pixmap, pixmap, addr(color), - addr(color), 0, 0) + var empty_cursor = XCreatePixmapCursor(display, pixmap, pixmap, addr(color), addr(color), 0, 0) checkXlibResult XFreePixmap(display, pixmap) - checkXlibResult XDefineCursor(display, window, empty_cursor) + return NativeWindow(display: display, window: window, emptyCursor: empty_cursor) - return NativeWindow(display: display, window: window, - emptyCursor: empty_cursor) +proc hideSystemCursor*(window: NativeWindow) = + checkXlibResult XDefineCursor(window.display, window.window, window.emptyCursor) + +proc showSystemCursor*(window: NativeWindow) = + checkXlibResult XUndefineCursor(window.display, window.window) proc destroy*(window: NativeWindow) = checkXlibResult window.display.XFreeCursor(window.emptyCursor) diff -r c48ceb622b27 -r bf2f4a9cd962 src/semicongine/platform/windows/window.nim --- a/src/semicongine/platform/windows/window.nim Sat Apr 29 05:40:11 2023 -0700 +++ b/src/semicongine/platform/windows/window.nim Sat Apr 29 21:38:52 2023 +0700 @@ -86,8 +86,13 @@ ) discard ShowWindow(result.hwnd, SW_SHOW) + +proc hideSystemCursor*(window: NativeWindow) = discard ShowCursor(false) +proc showSystemCursor*(window: NativeWindow) = + discard ShowCursor(true) + proc destroy*(window: NativeWindow) = discard