Eliminada paleta.cpp i mig adaptada la surface que la gastava

This commit is contained in:
2025-03-07 14:12:24 +01:00
parent ce88596d35
commit 529bfb5e3a
6 changed files with 22 additions and 289 deletions

View File

@@ -55,7 +55,7 @@ Palette loadPalette(const std::string &file_path)
}
// Carga una paleta desde un archivo .pal
Palette readPalFile(const std::string& file_path)
Palette readPalFile(const std::string &file_path)
{
Palette palette{};
palette.fill(0); // Inicializar todo con 0 (transparente por defecto)
@@ -101,7 +101,6 @@ Palette readPalFile(const std::string& file_path)
return palette;
}
// Constructor
Surface::Surface(int w, int h)
: surface_data_(std::make_shared<SurfaceData>(w, h)),
@@ -186,10 +185,7 @@ void Surface::putPixel(int x, int y, Uint8 color)
}
// Obtiene el color de un pixel de la surface_data
Uint8 Surface::getPixel(int x, int y)
{
return surface_data_->data[x + y * surface_data_->width];
}
Uint8 Surface::getPixel(int x, int y) { return surface_data_->data[x + y * surface_data_->width]; }
// Dibuja un rectangulo relleno
void Surface::fillRect(SDL_Rect *rect, Uint8 color)
@@ -320,7 +316,7 @@ void Surface::render(int dx, int dy, int sx, int sy, int w, int h)
void Surface::render(int x, int y, SDL_Rect *srcRect, SDL_RendererFlip flip)
{
auto surface_data = Screen::get()->getRendererSurface()->getSurfaceData();
auto surface_data_dest = Screen::get()->getRendererSurface()->getSurfaceData();
// Determina la región de origen (clip) a renderizar
int sx = (srcRect) ? srcRect->x : 0;
@@ -331,12 +327,12 @@ void Surface::render(int x, int y, SDL_Rect *srcRect, SDL_RendererFlip flip)
// Limitar la región para evitar accesos fuera de rango en origen
w = std::min(w, surface_data_->width - sx);
h = std::min(h, surface_data_->height - sy);
w = std::min(w, surface_data->width - x);
h = std::min(h, surface_data->height - y);
w = std::min(w, surface_data_dest->width - x);
h = std::min(h, surface_data_dest->height - y);
// Limitar la región para evitar accesos fuera de rango en destino
w = std::min(w, surface_data->width - x);
h = std::min(h, surface_data->height - y);
w = std::min(w, surface_data_dest->width - x);
h = std::min(h, surface_data_dest->height - y);
// Renderiza píxel por píxel aplicando el flip si es necesario
for (int iy = 0; iy < h; ++iy)
@@ -352,13 +348,13 @@ void Surface::render(int x, int y, SDL_Rect *srcRect, SDL_RendererFlip flip)
int dest_y = y + iy;
// Verificar que las coordenadas de destino están dentro de los límites
if (dest_x >= 0 && dest_x < surface_data->width && dest_y >= 0 && dest_y < surface_data->height)
if (dest_x >= 0 && dest_x < surface_data_dest->width && dest_y >= 0 && dest_y < surface_data_dest->height)
{
// Copia el píxel si no es transparente
Uint8 color = surface_data_->data[src_x + src_y * surface_data_->width];
if (color != transparent_color_)
{
surface_data->data[dest_x + dest_y * surface_data->width] = color;
surface_data_dest->data[dest_x + dest_y * surface_data_dest->width] = color;
}
}
}