- [FIX] clip(x,y,w,h) works as expected.

- [NEW] clip() with no arguments resets clipping region.
- [FIX] cls() respects clipping region (but now it's slower)
- [FIX] pset's and pget now respect clipping region correctly
This commit is contained in:
2023-07-04 19:50:13 +02:00
parent 38e209fa76
commit 58f4845746
3 changed files with 30 additions and 14 deletions

14
lua.cpp
View File

@@ -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;
}

View File

@@ -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]; y<ds::clip[3];++y) {
for (int x=ds::clip[0]; x<ds::clip[2];++x) {
simple_pset(x,y,color);
}
}
//SDL_memset(dest_surface->p, 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;

1
mini.h
View File

@@ -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);