clang-tidy readability
This commit is contained in:
@@ -55,18 +55,20 @@ Texture::~Texture() {
|
||||
|
||||
// Carga una imagen desde un fichero
|
||||
auto Texture::loadFromFile(const std::string &file_path) -> bool {
|
||||
if (file_path.empty())
|
||||
if (file_path.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int req_format = STBI_rgb_alpha;
|
||||
int width, height, orig_format;
|
||||
int width;
|
||||
int height;
|
||||
int orig_format;
|
||||
unsigned char *data = stbi_load(file_path.c_str(), &width, &height, &orig_format, req_format);
|
||||
if (!data) {
|
||||
if (data == nullptr) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", getFileName(file_path).c_str());
|
||||
throw std::runtime_error("Fichero no encontrado: " + getFileName(file_path));
|
||||
} else {
|
||||
printWithDots("Texture : ", getFileName(file_path), "[ LOADED ]");
|
||||
}
|
||||
printWithDots("Texture : ", getFileName(file_path), "[ LOADED ]");
|
||||
|
||||
int pitch;
|
||||
SDL_PixelFormat pixel_format;
|
||||
@@ -82,7 +84,7 @@ auto Texture::loadFromFile(const std::string &file_path) -> bool {
|
||||
SDL_Texture *new_texture = nullptr;
|
||||
|
||||
// Carga la imagen desde una ruta específica
|
||||
auto loaded_surface = SDL_CreateSurfaceFrom(width, height, pixel_format, static_cast<void *>(data), pitch);
|
||||
auto *loaded_surface = SDL_CreateSurfaceFrom(width, height, pixel_format, static_cast<void *>(data), pitch);
|
||||
if (loaded_surface == nullptr) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to load image %s", file_path.c_str());
|
||||
} else {
|
||||
@@ -110,7 +112,7 @@ auto Texture::loadFromFile(const std::string &file_path) -> bool {
|
||||
auto Texture::createBlank(int width, int height, SDL_PixelFormat format, SDL_TextureAccess access) -> bool {
|
||||
// Crea una textura sin inicializar
|
||||
texture_ = SDL_CreateTexture(renderer_, format, access, width, height);
|
||||
if (!texture_) {
|
||||
if (texture_ == nullptr) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create blank texture! SDL Error: %s", SDL_GetError());
|
||||
} else {
|
||||
width_ = width;
|
||||
@@ -123,7 +125,7 @@ auto Texture::createBlank(int width, int height, SDL_PixelFormat format, SDL_Tex
|
||||
// Libera la memoria de la textura
|
||||
void Texture::unloadTexture() {
|
||||
// Libera la textura
|
||||
if (texture_) {
|
||||
if (texture_ != nullptr) {
|
||||
SDL_DestroyTexture(texture_);
|
||||
texture_ = nullptr;
|
||||
width_ = 0;
|
||||
@@ -161,7 +163,7 @@ void Texture::render(int x, int y, SDL_FRect *clip, float zoom_w, float zoom_h,
|
||||
}
|
||||
|
||||
// Calcula el zoom y las coordenadas
|
||||
if (zoom_h != 1.0f || zoom_w != 1.0f) {
|
||||
if (zoom_h != 1.0F || zoom_w != 1.0F) {
|
||||
render_quad.x = render_quad.x + (render_quad.w / 2);
|
||||
render_quad.y = render_quad.y + (render_quad.h / 2);
|
||||
render_quad.w = render_quad.w * zoom_w;
|
||||
@@ -180,12 +182,12 @@ void Texture::setAsRenderTarget(SDL_Renderer *renderer) {
|
||||
}
|
||||
|
||||
// Obtiene el ancho de la imagen
|
||||
auto Texture::getWidth() -> int {
|
||||
auto Texture::getWidth() const -> int {
|
||||
return width_;
|
||||
}
|
||||
|
||||
// Obtiene el alto de la imagen
|
||||
auto Texture::getHeight() -> int {
|
||||
auto Texture::getHeight() const -> int {
|
||||
return height_;
|
||||
}
|
||||
|
||||
@@ -231,7 +233,8 @@ auto Texture::loadSurface(const std::string &file_path) -> std::shared_ptr<Surfa
|
||||
|
||||
// Crear un objeto Gif y llamar a la función loadGif
|
||||
GIF::Gif gif;
|
||||
Uint16 w = 0, h = 0;
|
||||
Uint16 w = 0;
|
||||
Uint16 h = 0;
|
||||
std::vector<Uint8> raw_pixels = gif.loadGif(buffer.data(), w, h);
|
||||
if (raw_pixels.empty()) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: No se pudo cargar el GIF %s", file_path.c_str());
|
||||
@@ -256,7 +259,7 @@ auto Texture::loadSurface(const std::string &file_path) -> std::shared_ptr<Surfa
|
||||
// Vuelca la surface en la textura
|
||||
void Texture::flipSurface() {
|
||||
// Limpia la textura
|
||||
auto temp = SDL_GetRenderTarget(renderer_);
|
||||
auto *temp = SDL_GetRenderTarget(renderer_);
|
||||
SDL_SetRenderTarget(renderer_, texture_);
|
||||
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
|
||||
SDL_RenderClear(renderer_);
|
||||
@@ -286,9 +289,8 @@ auto Texture::loadPaletteFromFile(const std::string &file_path) -> Palette {
|
||||
if (!file) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", file_path.c_str());
|
||||
throw std::runtime_error("Fichero no encontrado: " + file_path);
|
||||
} else {
|
||||
printWithDots("Palette : ", getFileName(file_path), "[ LOADED ]");
|
||||
}
|
||||
printWithDots("Palette : ", getFileName(file_path), "[ LOADED ]");
|
||||
|
||||
// Obtener el tamaño del archivo y leerlo en un buffer
|
||||
std::streamsize size = file.tellg();
|
||||
@@ -364,7 +366,9 @@ auto Texture::readPalFile(const std::string &file_path) -> Palette {
|
||||
|
||||
// Procesar las líneas restantes con valores RGB
|
||||
std::istringstream ss(line);
|
||||
int r, g, b;
|
||||
int r;
|
||||
int g;
|
||||
int b;
|
||||
if (ss >> r >> g >> b) {
|
||||
// Construir el color RGBA (A = 255 por defecto)
|
||||
Uint32 color = (r << 24) | (g << 16) | (b << 8) | 255;
|
||||
|
||||
Reference in New Issue
Block a user