- Reactivat relleno de patró (fillp)

- [New] bcolor() per a especificar el color de fons del patró, si no es transparent.
- [New] subpal() per a fer intercanvis de color de la paleta
This commit is contained in:
2023-08-04 16:26:57 +02:00
parent 040697fcbd
commit d16f0fef07
5 changed files with 80 additions and 15 deletions

View File

@@ -48,14 +48,18 @@ bool file_ignore_comma=true;
#define TILES(x, y) map_surface->p[x+y*map_surface->w]
#define CURRENT(x, y) surfaces[i].p[(x)+(y)*surfaces[i].w]
void (*do_pset)(int,int);
namespace ds {
uint8_t pen_color = 6;
uint8_t back_color = 0;
int cam[2] = {0, 0};
int clip[4] = {0, 0, screen_width, screen_height};
int clp[4] = {0, 0, screen_width-1, screen_height-1};
uint8_t trans = 0;
uint16_t fill_pattern = 0b1111111111111111;
bool fill_trans = false;
uint8_t draw_palette[256];
}
bool turbo_mode = true;
@@ -128,8 +132,24 @@ void read_ini() {
fclose(f);
}
void pset_fast(int x, int y) {
if (ds::trans != ds::pen_color) DEST(x, y) = ds::draw_palette[ds::pen_color];
}
void pset_pattern(int x, int y) {
int pbx = x % 4, pby = y % 4;
int pb = pbx+pby*4;
if (ds::fill_pattern & (1 << pb)) {
if (ds::trans != ds::pen_color) DEST(x, y) = ds::draw_palette[ds::pen_color];
} else {
if (!ds::fill_trans) DEST(x, y) = ds::draw_palette[ds::back_color];
}
}
void reinit() {
do_pset = pset_fast;
ds::pen_color = 6;
ds::back_color = 0;
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;
@@ -140,6 +160,7 @@ void reinit() {
if (surfaces[i].p != NULL) free(surfaces[i].p);
surfaces[i].p = NULL;
}
for (int i=0;i<256;++i) ds::draw_palette[i]=i;
if (file!=NULL) fclose(file);
file = NULL;
}
@@ -386,9 +407,10 @@ void simple_pset(int x, int y, uint8_t color) {
}
void cls(uint8_t color) {
const uint8_t col = ds::draw_palette[color];
for (int y=ds::clip[1]+ds::cam[1]; y<ds::clip[3]+ds::cam[1];++y) {
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,col);
}
}
//SDL_memset(dest_surface->p, color, dest_surface->size);
@@ -398,6 +420,10 @@ void color(uint8_t color) {
ds::pen_color=color;
}
void bcolor(uint8_t color) {
ds::back_color=color;
}
uint32_t *loadpal(const char* filename) {
int size;
uint8_t *buffer = (uint8_t*)file_getfilebuffer(filename, size);
@@ -442,6 +468,14 @@ uint8_t gettrans() {
return ds::trans;
}
void subpal(uint8_t index, uint8_t color) {
ds::draw_palette[index] = color;
}
void reset_subpal() {
for (int i=0;i<256;++i) ds::draw_palette[i]=i;
}
/*void pal() {
for (int i=0; i<16; ++i) {
ds::draw_palette[i] = i;
@@ -471,21 +505,9 @@ void palt(uint8_t col, bool t) {
void pset(int x, int y) {
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;
if (ds::trans != ds::pen_color) DEST(x, y) = ds::pen_color;
do_pset(x,y);
}
/*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;
int pbx = x % 4, pby = y % 4;
int pb = pbx+pby*4;
if (ds::fill_pattern & (1 << pb)) {
if (!ds::trans[ds::pen_color & 0xf]) DEST(x, y) = ds::draw_palette[ds::pen_color & 0xf];
} else {
if (!ds::fill_trans) DEST(x, y) = ds::draw_palette[ds::pen_color >> 4];
}
}*/
void pset(int x, int y, uint8_t color) {
ds::pen_color = color;
pset(x, y);
@@ -586,6 +608,7 @@ void rectfill(int x0, int y0, int x1, int y1, uint8_t color) {
void fillp(uint16_t pat, bool transparent) {
ds::fill_trans = transparent;
ds::fill_pattern = pat;
do_pset=(pat==0xffff?pset_fast:pset_pattern);
}
void print_symbol(char sym, int x, int y) {