- [NEW] view(x,y,w,h) Creates a clipped viewport that also translates origin.

-[NEW] view() Resets the viewport to all the window.
This commit is contained in:
2023-07-04 23:03:19 +02:00
parent 0a92e29aa3
commit 584b65041c
4 changed files with 36 additions and 2 deletions

View File

@@ -11,7 +11,12 @@ function _update()
end end
function normal_update() function normal_update()
view()
cls(20) cls(20)
view(10,10,140,100)
cls(3)
prnt("HOLA",0,0)
prnt(text,x,60) prnt(text,x,60)
if btnp(keyRight) then x=x+1 end if btnp(keyRight) then x=x+1 end
if btnp(keyLeft) then x=x-1 end if btnp(keyLeft) then x=x-1 end

14
lua.cpp
View File

@@ -278,6 +278,19 @@ extern "C" {
return 0; 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) { static int cpp_circ(lua_State *L) {
int x = luaL_checknumber(L, 1); int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2); 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_print); lua_setglobal(L, "prnt");
lua_pushcfunction(L,cpp_clip); lua_setglobal(L, "clip"); lua_pushcfunction(L,cpp_clip); lua_setglobal(L, "clip");
lua_pushcfunction(L,cpp_camera); lua_setglobal(L, "camera"); 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_circ); lua_setglobal(L, "circ");
lua_pushcfunction(L,cpp_circfill); lua_setglobal(L, "circfill"); lua_pushcfunction(L,cpp_circfill); lua_setglobal(L, "circfill");
lua_pushcfunction(L,cpp_oval); lua_setglobal(L, "oval"); lua_pushcfunction(L,cpp_oval); lua_setglobal(L, "oval");

View File

@@ -382,8 +382,8 @@ void simple_pset(int x, int y, uint8_t color) {
} }
void cls(uint8_t color) { void cls(uint8_t color) {
for (int y=ds::clip[1]; y<ds::clip[3];++y) { for (int y=ds::clip[1]+ds::cam[1]; y<ds::clip[3]+ds::cam[1];++y) {
for (int x=ds::clip[0]; x<ds::clip[2];++x) { for (int x=ds::clip[0]+ds::cam[0]; x<ds::clip[2]+ds::cam[0];++x) {
simple_pset(x,y,color); simple_pset(x,y,color);
} }
} }
@@ -656,6 +656,19 @@ void camera(int x, int y) {
ds::cam[1] = y; ds::cam[1] = y;
} }
void view(int x, int y, int w, int h) {
ds::cam[0] = -x;
ds::cam[1] = -y;
ds::clip[0] = x; ds::clip[1] = y; ds::clip[2] = w+x; ds::clip[3] = h+y;
ds::clp[0] = x; ds::clp[1] = y; ds::clp[2] = w-1; ds::clp[3] = h-1;
}
void view() {
ds::cam[0] = ds::cam[1] = 0;
ds::clip[0] = ds::clip[1] = 0; ds::clip[2] = screen_width; ds::clip[3] = screen_height;
ds::clp[0] = ds::clp[1] = 0; ds::clp[2] = screen_width-1; ds::clp[3] = screen_height-1;
}
void _drawcirc(int xc, int yc, int x, int y) { void _drawcirc(int xc, int yc, int x, int y) {
pset(xc+x, yc+y); pset(xc+x, yc+y);
pset(xc-x, yc+y); pset(xc-x, yc+y);

2
mini.h
View File

@@ -168,6 +168,8 @@ void print(const char *str, int x, int y, uint8_t color);
void clip(int x, int y, int w, int h); void clip(int x, int y, int w, int h);
void clip(); void clip();
void camera(int x, int y); void camera(int x, int y);
void view(int x, int y, int w, int h);
void view();
void circ(int x, int y, uint8_t r = 4); void circ(int x, int y, uint8_t r = 4);
void circ(int x, int y, uint8_t r, uint8_t color); void circ(int x, int y, uint8_t r, uint8_t color);