sokol: small fixes to screenshot functions and docs (#13055)

pull/13058/head
Larpon 2022-01-06 13:11:40 +01:00 committed by GitHub
parent ec91de3504
commit 214853c373
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 6 deletions

View File

@ -6,15 +6,27 @@ import stbi
// v_sapp_gl_read_rgba_pixels reads pixles from the OpenGL buffer into `pixels`. // v_sapp_gl_read_rgba_pixels reads pixles from the OpenGL buffer into `pixels`.
fn C.v_sapp_gl_read_rgba_pixels(x int, y int, width int, height int, pixels charptr) fn C.v_sapp_gl_read_rgba_pixels(x int, y int, width int, height int, pixels charptr)
// screenshot takes a screenshot of the current window. // screenshot takes a screenshot of the current window and
// saves it to `path`. The format is inferred from the extension
// of the file name in `path`.
//
// Supported formats are: `.png`, `.ppm`.
pub fn screenshot(path string) ? { pub fn screenshot(path string) ? {
if !path.ends_with('.ppm') { match os.file_ext(path) {
return error(@MOD + '.' + @FN + ' currently only supports .ppm files.') '.png' {
return screenshot_png(path)
}
'.ppm' {
return screenshot_ppm(path)
}
else {
return error(@MOD + '.' + @FN + ' currently only supports .png and .ppm files.')
}
} }
return screenshot_ppm(path)
} }
// screenshot_ppm takes a screenshot of the current window as a .ppm file // screenshot_ppm takes a screenshot of the current window and
// saves it to `path` as a .ppm file.
[manualfree] [manualfree]
pub fn screenshot_ppm(path string) ? { pub fn screenshot_ppm(path string) ? {
ss := screenshot_window() ss := screenshot_window()
@ -22,7 +34,8 @@ pub fn screenshot_ppm(path string) ? {
unsafe { ss.destroy() } unsafe { ss.destroy() }
} }
// screenshot_png takes a screenshot of the current window as a .png file // screenshot_png takes a screenshot of the current window and
// saves it to `path` as a .png file.
[manualfree] [manualfree]
pub fn screenshot_png(path string) ? { pub fn screenshot_png(path string) ? {
ss := screenshot_window() ss := screenshot_window()