diff --git a/lua/core/screen.lua b/lua/core/screen.lua index d4de20c32..b2633a21e 100644 --- a/lua/core/screen.lua +++ b/lua/core/screen.lua @@ -309,9 +309,9 @@ _norns.screen_circle = function(x, y, r) _norns.screen_arc(x, y, r, 0, math.pi*2) end ---- export png +--- export screenshot -- @param filename: saved to dust/data/(script)/(filename).png -Screen.export_png = function(filename) _norns.screen_export_png(norns.state.data..filename..'.png') end +Screen.export_screenshot = function(filename) _norns.screen_export_screenshot(norns.state.data..filename..'.png') end --- display png -- @param filename diff --git a/matron/src/hardware/screen.c b/matron/src/hardware/screen.c index 6eaf43d15..e56176e56 100644 --- a/matron/src/hardware/screen.c +++ b/matron/src/hardware/screen.c @@ -395,6 +395,11 @@ double *screen_text_extents(const char *s) { } extern void screen_export_png(const char *s) { + CHECK_CR + cairo_surface_write_to_png(surface, s); +} + +extern void screen_export_screenshot(const char *s) { CHECK_CR static cairo_surface_t *png; static cairo_t *temp; // for bg fill diff --git a/matron/src/hardware/screen.h b/matron/src/hardware/screen.h index cdc91fed6..623c37bc6 100644 --- a/matron/src/hardware/screen.h +++ b/matron/src/hardware/screen.h @@ -32,6 +32,7 @@ extern void screen_clear(void); extern void screen_close_path(void); extern double *screen_text_extents(const char *s); extern void screen_export_png(const char *s); +extern void screen_export_screenshot(const char *s); extern void screen_display_png(const char *filename, double x, double y); extern char *screen_peek(int x, int y, int *w, int *h); extern void screen_poke(int x, int y, int w, int h, unsigned char *buf); diff --git a/matron/src/weaver.c b/matron/src/weaver.c index 0c83169b3..170ce2f25 100644 --- a/matron/src/weaver.c +++ b/matron/src/weaver.c @@ -115,6 +115,7 @@ static int _screen_clear(lua_State *l); static int _screen_close(lua_State *l); static int _screen_text_extents(lua_State *l); static int _screen_export_png(lua_State *l); +static int _screen_export_screenshot(lua_State *l); static int _screen_display_png(lua_State *l); static int _screen_peek(lua_State *l); static int _screen_poke(lua_State *l); @@ -463,6 +464,7 @@ void w_init(void) { lua_register_norns("screen_close", &_screen_close); lua_register_norns("screen_text_extents", &_screen_text_extents); lua_register_norns("screen_export_png", &_screen_export_png); + lua_register_norns("screen_export_screenshot", &_screen_export_screenshot); lua_register_norns("screen_display_png", &_screen_display_png); lua_register_norns("screen_peek", &_screen_peek); lua_register_norns("screen_poke", &_screen_poke); @@ -956,6 +958,19 @@ int _screen_export_png(lua_State *l) { return 0; } +/*** + * screen: export_screenshot + * @function s_export_screenshot + * @tparam string filename + */ +int _screen_export_screenshot(lua_State *l) { + lua_check_num_args(1); + const char *s = luaL_checkstring(l, 1); + screen_export_screenshot(s); + lua_settop(l, 0); + return 0; +} + /*** * screen: display_png * @function s_display_png