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

attempt to fix screenshotting #61 but causes issue with nimpng / too nested template #72

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
18 changes: 9 additions & 9 deletions nico/backends/sdl2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import std/json
import std/tables
import std/hashes
import std/strutils
import std/strformat
import std/sequtils
import std/times
import std/math
Expand All @@ -13,8 +14,6 @@ import std/os
import std/osproc
import std/parsecfg

when defined(android):
import std/strformat
when defined(opengl):
import std/opengl

Expand Down Expand Up @@ -797,13 +796,13 @@ proc flip*() =
recordFrame = newSurface(swCanvas.w, swCanvas.h)

proc saveScreenshot*() =
echo "saveScreenshot"
createDir(writePath & "/screenshots")
var frame = recordFrames[recordFrames.size-1]
var abgr = newSeq[uint8](screenWidth*screenHeight*4)
# convert RGBA to BGRA
convertToRGBA(frame, abgr[0].addr, screenWidth*4, screenWidth, screenHeight)
let filename = joinPath(writePath, joinPath("screenshots", "screenshot-$1T$2.png".format(getDateStr(), getClockStr())))
debug "saved screenshot to: ", filename
let filename = joinPath(writePath, joinPath("screenshots", &"screenshot-{getDateStr()}{getClockStr()}.png"))
var data = newSeq[uint8](swCanvas32.w * swCanvas32.h * 4)
copyMem(data[0].addr, swCanvas32.pixels, swCanvas32.w * swCanvas32.h * 4)
var res = savePNG(filename, data, LCT_RGBA, 32, swCanvas32.w, swCanvas32.h)
echo "saved screenshot to: ", filename

proc saveRecording*() =
# TODO: do this in another thread?
Expand Down Expand Up @@ -1168,8 +1167,9 @@ proc appHandleEvent(evt: sdl.Event) =
elif sym == (sdl.Keycode.K_F9) and down:
saveRecording()

elif sym == (sdl.Keycode.K_F10) and down:
elif (sym == sdl.Keycode.K_F10 or sym == sdl.Keycode.K_PRINTSCREEN) and down:
saveScreenshot()
return

elif sym == (sdl.Keycode.K_F11) and down:
when system.hostOS == "windows":
Expand Down