forked from jaildesigner-jailgames/jaildoctors_dilemma
Afegides guardes en Surface::render() per a no pintar fora del destí (no estava implementat en totes les versions de render)
This commit is contained in:
@@ -196,14 +196,15 @@ void Surface::drawLine(int x1, int y1, int x2, int y2, Uint8 color)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copia una región de la superficie de origen a la de destino
|
|
||||||
void Surface::render(int dx, int dy, int sx, int sy, int w, int h)
|
void Surface::render(int dx, int dy, int sx, int sy, int w, int h)
|
||||||
{
|
{
|
||||||
auto surface_data = Screen::get()->getRendererSurface()->getSurfaceData();
|
auto surface_data = Screen::get()->getRendererSurface()->getSurfaceData();
|
||||||
|
|
||||||
// Limitar la región para evitar accesos fuera de rango
|
// Limitar la región para evitar accesos fuera de rango en origen
|
||||||
w = std::min(w, surface_data_->width - sx);
|
w = std::min(w, surface_data_->width - sx);
|
||||||
h = std::min(h, surface_data_->height - sy);
|
h = std::min(h, surface_data_->height - sy);
|
||||||
|
|
||||||
|
// Limitar la región para evitar accesos fuera de rango en destino
|
||||||
w = std::min(w, surface_data->width - dx);
|
w = std::min(w, surface_data->width - dx);
|
||||||
h = std::min(h, surface_data->height - dy);
|
h = std::min(h, surface_data->height - dy);
|
||||||
|
|
||||||
@@ -211,16 +212,24 @@ void Surface::render(int dx, int dy, int sx, int sy, int w, int h)
|
|||||||
{
|
{
|
||||||
for (int ix = 0; ix < w; ++ix)
|
for (int ix = 0; ix < w; ++ix)
|
||||||
{
|
{
|
||||||
Uint8 color = surface_data_->data[(sx + ix) + (sy + iy) * surface_data_->width];
|
int src_x = sx + ix;
|
||||||
if (color != transparent_color_)
|
int src_y = sy + iy;
|
||||||
|
int dest_x = dx + ix;
|
||||||
|
int dest_y = dy + 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)
|
||||||
{
|
{
|
||||||
surface_data->data[(dx + ix) + (dy + iy) * surface_data->width] = color;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copia una región de la superficie de origen a la de destino
|
|
||||||
void Surface::render(int x, int y, SDL_Rect *srcRect, SDL_RendererFlip flip)
|
void Surface::render(int x, int y, SDL_Rect *srcRect, SDL_RendererFlip flip)
|
||||||
{
|
{
|
||||||
auto surface_data = Screen::get()->getRendererSurface()->getSurfaceData();
|
auto surface_data = Screen::get()->getRendererSurface()->getSurfaceData();
|
||||||
@@ -231,12 +240,16 @@ void Surface::render(int x, int y, SDL_Rect *srcRect, SDL_RendererFlip flip)
|
|||||||
int w = (srcRect) ? srcRect->w : surface_data_->width;
|
int w = (srcRect) ? srcRect->w : surface_data_->width;
|
||||||
int h = (srcRect) ? srcRect->h : surface_data_->height;
|
int h = (srcRect) ? srcRect->h : surface_data_->height;
|
||||||
|
|
||||||
// Limitar la región para evitar accesos fuera de rango
|
// Limitar la región para evitar accesos fuera de rango en origen
|
||||||
w = std::min(w, surface_data_->width - sx);
|
w = std::min(w, surface_data_->width - sx);
|
||||||
h = std::min(h, surface_data_->height - sy);
|
h = std::min(h, surface_data_->height - sy);
|
||||||
w = std::min(w, surface_data->width - x);
|
w = std::min(w, surface_data->width - x);
|
||||||
h = std::min(h, surface_data->height - y);
|
h = std::min(h, surface_data->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);
|
||||||
|
|
||||||
// Renderiza píxel por píxel aplicando el flip si es necesario
|
// Renderiza píxel por píxel aplicando el flip si es necesario
|
||||||
for (int iy = 0; iy < h; ++iy)
|
for (int iy = 0; iy < h; ++iy)
|
||||||
{
|
{
|
||||||
@@ -250,16 +263,21 @@ void Surface::render(int x, int y, SDL_Rect *srcRect, SDL_RendererFlip flip)
|
|||||||
int dest_x = x + ix;
|
int dest_x = x + ix;
|
||||||
int dest_y = y + iy;
|
int dest_y = y + iy;
|
||||||
|
|
||||||
// Copia el píxel si no es transparente
|
// Verificar que las coordenadas de destino están dentro de los límites
|
||||||
Uint8 color = surface_data_->data[src_x + src_y * surface_data_->width];
|
if (dest_x >= 0 && dest_x < surface_data->width && dest_y >= 0 && dest_y < surface_data->height)
|
||||||
if (color != transparent_color_)
|
|
||||||
{
|
{
|
||||||
surface_data->data[dest_x + dest_y * surface_data->width] = color;
|
// 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Copia una región de la superficie de origen a la de destino
|
// Copia una región de la superficie de origen a la de destino
|
||||||
void Surface::render(SDL_Rect *srcRect, SDL_Rect *dstRect, SDL_RendererFlip flip)
|
void Surface::render(SDL_Rect *srcRect, SDL_Rect *dstRect, SDL_RendererFlip flip)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user