- [NEW] draw::fadein()

- retocat draw::fadeout()
This commit is contained in:
2023-10-12 09:48:36 +02:00
parent d33db04d3b
commit eb5e2abf75

View File

@@ -22,6 +22,7 @@ namespace draw
surface *pushedSource = nullptr; // Punter a la superficie d'oritge que s'ha pushat surface *pushedSource = nullptr; // Punter a la superficie d'oritge que s'ha pushat
uint32_t palette[256]; // La paleta de colors uint32_t palette[256]; // La paleta de colors
uint32_t aux_palette[256]; // La paleta de colors
uint8_t color_indices[256]; // Indices dels colors per defecte uint8_t color_indices[256]; // Indices dels colors per defecte
uint8_t sel_color = 0; // Color seleccionat per defecte uint8_t sel_color = 0; // Color seleccionat per defecte
uint8_t transparent = 0; // El color transparent uint8_t transparent = 0; // El color transparent
@@ -353,24 +354,57 @@ namespace draw
vline(x+w-1,y,h); vline(x+w-1,y,h);
} }
bool decPalEntry(const uint8_t index, const uint8_t val)
{
const uint32_t entry = palette[index];
uint8_t r = (entry >> 16) & 0xff;
uint8_t g = (entry >> 8) & 0xff;
uint8_t b = entry & 0xff;
r = r>=val ? r-val : 0;
g = g>=val ? g-val : 0;
b = b>=val ? b-val : 0;
palette[index] = (r << 16) + (g << 8) + b;
return palette[index] != 0;
}
bool incPalEntry(const uint8_t index, const uint8_t val)
{
const uint32_t entry = palette[index];
uint8_t r = (entry >> 16) & 0xff;
uint8_t g = (entry >> 8) & 0xff;
uint8_t b = entry & 0xff;
const uint32_t dest_entry = aux_palette[index];
const uint8_t dr = (dest_entry >> 16) & 0xff;
const uint8_t dg = (dest_entry >> 8) & 0xff;
const uint8_t db = dest_entry & 0xff;
r = (r+val > dr) ? dr : r+val;
g = (g+val > dg) ? dg : g+val;
b = (b+val > db) ? db : b+val;
palette[index] = (r << 16) + (g << 8) + b;
return palette[index] != aux_palette[index];
}
void fadein() void fadein()
{ {
if (!fading_in) {
for (int i=0;i<256;++i) {
aux_palette[i] = palette[i];
palette[i] = 0;
}
}
fading_in = false;
for (int i=0; i<256; ++i) if (incPalEntry(i, 16)) fading_in = true;
} }
void fadeout() void fadeout()
{ {
fading_out = false; fading_out = false;
for (int i=0; i<256; ++i) for (int i=0; i<256; ++i) if (decPalEntry(i, 16)) fading_out = true;
{
// [TODO] ARREGLAR, les entrades en la paleta son uint32_t, hi ha que separar en rgba i decrementar cada canal per separat
if (palette[i] > 16) {
palette[i] = palette[i]-16;
fading_out = true;
} else {
palette[i] = 0;
}
}
} }
void print(const char* text, const int x, const int y, const Uint8 color, const Uint8 borde) void print(const char* text, const int x, const int y, const Uint8 color, const Uint8 borde)