From 584b65041ccb4f54c4da3fd8fda7cf655d3b1da5 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Tue, 4 Jul 2023 23:03:19 +0200 Subject: [PATCH] - [NEW] view(x,y,w,h) Creates a clipped viewport that also translates origin. -[NEW] view() Resets the viewport to all the window. --- data/game.lua | 5 +++++ lua.cpp | 14 ++++++++++++++ mini.cpp | 17 +++++++++++++++-- mini.h | 2 ++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/data/game.lua b/data/game.lua index 607a15a..701e050 100644 --- a/data/game.lua +++ b/data/game.lua @@ -11,7 +11,12 @@ function _update() end function normal_update() + view() + cls(20) + view(10,10,140,100) + cls(3) + prnt("HOLA",0,0) prnt(text,x,60) if btnp(keyRight) then x=x+1 end if btnp(keyLeft) then x=x-1 end diff --git a/lua.cpp b/lua.cpp index 003f2e0..4a70e1b 100644 --- a/lua.cpp +++ b/lua.cpp @@ -278,6 +278,19 @@ extern "C" { return 0; } + static int cpp_view(lua_State *L) { + if (lua_gettop(L) == 0) { + view(); + } else { + int x = luaL_checknumber(L, 1); + int y = luaL_checknumber(L, 2); + int w = luaL_checknumber(L, 3); + int h = luaL_checknumber(L, 4); + view(x, y, w, h); + } + return 0; + } + static int cpp_circ(lua_State *L) { int x = luaL_checknumber(L, 1); int y = luaL_checknumber(L, 2); @@ -831,6 +844,7 @@ void push_lua_funcs() { lua_pushcfunction(L,cpp_print); lua_setglobal(L, "prnt"); lua_pushcfunction(L,cpp_clip); lua_setglobal(L, "clip"); lua_pushcfunction(L,cpp_camera); lua_setglobal(L, "camera"); + lua_pushcfunction(L,cpp_view); lua_setglobal(L, "view"); lua_pushcfunction(L,cpp_circ); lua_setglobal(L, "circ"); lua_pushcfunction(L,cpp_circfill); lua_setglobal(L, "circfill"); lua_pushcfunction(L,cpp_oval); lua_setglobal(L, "oval"); diff --git a/mini.cpp b/mini.cpp index cf477f2..195920e 100644 --- a/mini.cpp +++ b/mini.cpp @@ -382,8 +382,8 @@ void simple_pset(int x, int y, uint8_t color) { } void cls(uint8_t color) { - for (int y=ds::clip[1]; y