Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added getClipboardText added "PASTE CODE" to Nicosynth #99

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions nico.nim
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export profileHistory
export errorPopup

export setClipboardText
export getClipboardText

# Audio
export joinPath
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -2561,7 +2562,7 @@ proc sprOverlap*(a,b : SpriteDraw): bool=
#Foreach pixel in the overlap check the colour there
for xSamp in 0..<wOverlap:
for ySamp in 0..<hOverlap:
var
var
aX = aSprRect.x + xSamp + aXRelative
aY = aSprRect.y + ySamp + aYRelative
bX = bSprRect.x + xSamp + bxRelative
Expand All @@ -2572,7 +2573,7 @@ proc sprOverlap*(a,b : SpriteDraw): bool=
if(a.flipX):
aX = aSprRect.x + (aSprRect.w - (xSamp + aXRelative)) - 1
if(a.flipY):
aY = aSprRect.y + (aSprRect.h - (ySamp + aYRelative)) - 1
aY = aSprRect.y + (aSprRect.h - (ySamp + aYRelative)) - 1

if(b.flipX):
bX = bSprRect.x + (aSprRect.w - (xSamp + bXRelative)) - 1
Expand All @@ -2584,7 +2585,7 @@ proc sprOverlap*(a,b : SpriteDraw): bool=
indB = bX + bY * surfB.w
if(indA < surfA.data.len and indB < surfB.data.len):#Shouldnt ever happen but errors must be checked
if(surfA.data[indA] > 0 and surfB.data[indB] > 0): #Using 0 as of now for alpha check
return true
return true

return false

Expand Down
13 changes: 8 additions & 5 deletions nico/backends/sdl2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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');
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions nicosynth.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down