From 577dc3bcb6b4ee6ff1e97bf5e43b2d4b1e1cbabe Mon Sep 17 00:00:00 2001 From: David Krause Date: Sun, 12 Feb 2023 19:56:31 +0100 Subject: [PATCH] added getClipboardText added "PASTE CODE" to Nicosynth Signed-off-by: David Krause --- nico.nim | 15 ++++++++------- nico/backends/sdl2.nim | 13 ++++++++----- nicosynth.nim | 7 +++++++ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/nico.nim b/nico.nim index 27455e2..f12cdee 100644 --- a/nico.nim +++ b/nico.nim @@ -39,6 +39,7 @@ export profileHistory export errorPopup export setClipboardText +export getClipboardText # Audio export joinPath @@ -738,7 +739,7 @@ proc ditherADitherXor*(v: float32, a = 149,b = 1234, c = 511) = proc ditherPass(x,y: int): bool {.inline.} = if gDitherMode == DitherNone: return true - + let x = floorMod(x + gDitherOffsetX, screenWidth) let y = floorMod(y + gDitherOffsetY, screenHeight) @@ -2532,12 +2533,12 @@ proc spr*(drawer: SpriteDraw, x,y:Pint)= proc sprOverlap*(a,b : SpriteDraw): bool= ##Will return true if the sprites overlap setSpritesheet(a.spriteSheet) - let + let aSprRect = getSprRect(a.spriteIndex,a.w,a.h) aRect: Rect = (a.x, a.y, aSprRect.w, aSprRect.h) if(a.spritesheet != b.spritesheet): setSpritesheet(b.spriteSheet) - let + let bSprRect = getSprRect(b.spriteIndex,b.w,b.h) bRect: Rect = (b.x, b.y, bSprRect.w, bSprRect.h) @@ -2552,7 +2553,7 @@ proc sprOverlap*(a,b : SpriteDraw): bool= bXRelative = xOverlap - b.x bYRelative = yOverlap - b.y - var + var surfA = spritesheets[a.spriteSheet] surfB = spritesheets[b.spriteSheet] indA = 0 @@ -2561,7 +2562,7 @@ proc sprOverlap*(a,b : SpriteDraw): bool= #Foreach pixel in the overlap check the colour there for xSamp in 0.. 0 and surfB.data[indB] > 0): #Using 0 as of now for alpha check - return true + return true return false diff --git a/nico/backends/sdl2.nim b/nico/backends/sdl2.nim index 62c4985..a34e948 100644 --- a/nico/backends/sdl2.nim +++ b/nico/backends/sdl2.nim @@ -496,7 +496,7 @@ proc createWindow*(title: string, w,h: int, scale: int = 2, fullscreen: bool = f window = createWindow(title.cstring, r.x, r.y, r.w, r.h, (WINDOW_RESIZABLE or WINDOW_OPENGL).uint32) else: - window = createWindow(title.cstring, WINDOWPOS_CENTERED, WINDOWPOS_CENTERED, (w * scale).cint, (h * scale).cint, + window = createWindow(title.cstring, WINDOWPOS_CENTERED, WINDOWPOS_CENTERED, (w * scale).cint, (h * scale).cint, (WINDOW_RESIZABLE or (if fullscreen: WINDOW_FULLSCREEN_DESKTOP else: 0) or WINDOW_OPENGL.cint).uint32) discard glSetAttribute(GLattr.GL_CONTEXT_PROFILE_MASK, GL_CONTEXT_PROFILE_ES) @@ -630,7 +630,7 @@ void main() { window = createWindow(title.cstring, r.x, r.y, r.w, r.h, (WINDOW_RESIZABLE).uint32) else: - window = createWindow(title.cstring, WINDOWPOS_CENTERED, WINDOWPOS_CENTERED, (w * scale).cint, (h * scale).cint, + window = createWindow(title.cstring, WINDOWPOS_CENTERED, WINDOWPOS_CENTERED, (w * scale).cint, (h * scale).cint, (WINDOW_RESIZABLE or (if fullscreen: WINDOW_FULLSCREEN_DESKTOP else: 0)).uint32) if window == nil: @@ -1392,7 +1392,7 @@ when defined(emscripten): {.emit:""" EM_ASM( //create your directory where we keep our persistent data - FS.mkdir('/IDBFS'); + FS.mkdir('/IDBFS'); //mount persistent directory as IDBFS FS.mount(IDBFS,{},'/IDBFS'); @@ -1401,9 +1401,9 @@ when defined(emscripten): //flag to check when data are synchronized Module.syncdone = 0; - //populate persistent_data directory with existing persistent source data + //populate persistent_data directory with existing persistent source data //stored with Indexed Db - //first parameter = "true" mean synchronize from Indexed Db to + //first parameter = "true" mean synchronize from Indexed Db to //Emscripten file system, // "false" mean synchronize from Emscripten file system to Indexed Db //second parameter = function called when data are synchronized @@ -2139,6 +2139,9 @@ proc showMouse*() = proc setClipboardText*(text: string) = discard sdl.setClipboardText(text) +proc getClipboardText*(): string = + return $sdl.getClipboardText() + proc setLinearFilter*(on: bool) = linearFilter = on resize() diff --git a/nicosynth.nim b/nicosynth.nim index 23f9bde..989e101 100644 --- a/nicosynth.nim +++ b/nicosynth.nim @@ -180,6 +180,13 @@ proc gameGui() = if G.button("COPY CODE"): echo fmt("synth(channel, \"{outputStr}\")") setClipboardText(outputStr) + if G.button("PASTE CODE"): + try: + data = synthDataFromString(getClipboardText()) + gameInit() + except: + echo "Could not parse code: ", getClipboardText() + data = initData G.endArea() proc gameUpdate(dt: float32) =