diff --git a/lua.cpp b/lua.cpp index cea7739..003f2e0 100644 --- a/lua.cpp +++ b/lua.cpp @@ -259,11 +259,15 @@ extern "C" { } static int cpp_clip(lua_State *L) { - int x = luaL_checknumber(L, 1); - int y = luaL_checknumber(L, 2); - int w = luaL_checknumber(L, 3); - int h = luaL_checknumber(L, 4); - clip(x, y, w, h); + if (lua_gettop(L) == 0) { + clip(); + } 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); + clip(x, y, w, h); + } return 0; } diff --git a/mini.cpp b/mini.cpp index 3e89a11..6aa0ff8 100644 --- a/mini.cpp +++ b/mini.cpp @@ -362,8 +362,19 @@ int main(int argc,char*argv[]){ return 0; } +void simple_pset(int x, int y, uint8_t color) { + x -= ds::cam[0]; y -= ds::cam[1]; + if (x < ds::clip[0] || x >= ds::clip[2] || y < ds::clip[1] || y >= ds::clip[3]) return; + DEST(x, y) = color; +} + void cls(uint8_t color) { - SDL_memset(dest_surface->p, color, dest_surface->size); + for (int y=ds::clip[1]; yp, color, dest_surface->size); } void color(uint8_t color) { @@ -440,15 +451,9 @@ void palt(uint8_t col, bool t) { } */ -void simple_pset(int x, int y, uint8_t color) { - x -= ds::cam[0]; y -= ds::cam[1]; - if (x < ds::clp[0] || x > ds::clp[2] || y < ds::clp[1] || y > ds::clp[3]) return; - DEST(x, y) = color; -} - void pset(int x, int y) { x -= ds::cam[0]; y -= ds::cam[1]; - if (x < ds::clp[0] || x > ds::clp[2] || y < ds::clp[1] || y > ds::clp[3]) return; + if (x < ds::clip[0] || x >= ds::clip[2] || y < ds::clip[1] || y >= ds::clip[3]) return; if (ds::trans != ds::pen_color) DEST(x, y) = ds::pen_color; } @@ -471,7 +476,8 @@ void pset(int x, int y, uint8_t color) { uint8_t pget(int x, int y) { x -= ds::cam[0]; y -= ds::cam[1]; - if (x < 0 || x > (dest_surface->w-1) || y < 0 || y > (dest_surface->h-1)) return 0; + //if (x < 0 || x > (dest_surface->w-1) || y < 0 || y > (dest_surface->h-1)) return 0; + if (x < ds::clip[0] || x >= ds::clip[2] || y < ds::clip[1] || y >= ds::clip[3]) return 0; return DEST(x, y); } @@ -627,6 +633,11 @@ void clip(int x, int y, int w, int h) { ds::clp[0] = x; ds::clp[1] = y; ds::clp[2] = w-x-1; ds::clp[3] = h-y-1; } +void clip() { + 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 camera(int x, int y) { ds::cam[0] = x; ds::cam[1] = y; diff --git a/mini.h b/mini.h index 95dc7cb..dc0ee37 100644 --- a/mini.h +++ b/mini.h @@ -166,6 +166,7 @@ void print(const char *str, int x, int y); void print(const char *str, int x, int y, uint8_t color); void clip(int x, int y, int w, int h); +void clip(); void camera(int x, int y); void circ(int x, int y, uint8_t r = 4);