Aplicar formato automático con clang-format a todo el código fuente

- Reformatear archivos .cpp y .h según configuración Google personalizada
- Mejorar consistencia en indentación y espaciado
- Reorganizar includes y declaraciones de clases
- Mantener funcionalidad existente sin cambios

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-15 13:57:01 +02:00
parent 230046152c
commit 79c27dad6a
9 changed files with 494 additions and 585 deletions
+31 -43
View File
@@ -1,55 +1,55 @@
#define STB_IMAGE_IMPLEMENTATION
#include "texture.h"
#include <SDL3/SDL_error.h> // Para SDL_GetError
#include <SDL3/SDL_log.h> // Para SDL_Log
#include <SDL3/SDL_pixels.h> // Para SDL_PixelFormat
#include <SDL3/SDL_surface.h> // Para SDL_CreateSurfaceFrom, SDL_DestroySurface
#include <stdio.h> // Para NULL
#include <stdlib.h> // Para exit
#include <iostream> // Para basic_ostream, char_traits, operator<<
#include <string> // Para operator<<, string
#include "stb_image.h" // Para stbi_failure_reason, stbi_image_free
#include <iostream> // Para basic_ostream, char_traits, operator<<
#include <string> // Para operator<<, string
#include "stb_image.h" // Para stbi_failure_reason, stbi_image_free
Texture::Texture(SDL_Renderer *renderer)
: renderer_(renderer), texture_(nullptr), width_(0), height_(0) {}
: renderer_(renderer),
texture_(nullptr),
width_(0),
height_(0) {}
Texture::Texture(SDL_Renderer *renderer, const std::string &file_path)
: renderer_(renderer), texture_(nullptr), width_(0), height_(0)
{
: renderer_(renderer),
texture_(nullptr),
width_(0),
height_(0) {
loadFromFile(file_path);
}
Texture::~Texture()
{
Texture::~Texture() {
free();
}
// Carga la imagen desde una ruta especificada
bool Texture::loadFromFile(const std::string &file_path)
{
bool Texture::loadFromFile(const std::string &file_path) {
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
int req_format = STBI_rgb_alpha;
int width, height, orig_format;
unsigned char *data = stbi_load(file_path.c_str(), &width, &height, &orig_format, req_format);
if (data == nullptr)
{
if (data == nullptr) {
SDL_Log("Error al cargar la imagen: %s", stbi_failure_reason());
exit(1);
}
else
{
} else {
std::cout << "Imagen cargada: " << filename.c_str() << std::endl;
}
int pitch;
SDL_PixelFormat pixel_format;
if (req_format == STBI_rgb)
{
pitch = 3 * width; // 3 bytes por pixel * pixels por línea
if (req_format == STBI_rgb) {
pitch = 3 * width; // 3 bytes por pixel * pixels por línea
pixel_format = SDL_PIXELFORMAT_RGB24;
}
else
{ // STBI_rgb_alpha (RGBA)
} else { // STBI_rgb_alpha (RGBA)
pitch = 4 * width;
pixel_format = SDL_PIXELFORMAT_RGBA32;
}
@@ -62,20 +62,14 @@ bool Texture::loadFromFile(const std::string &file_path)
// Crea la superficie de la imagen desde los datos cargados
SDL_Surface *loaded_surface = SDL_CreateSurfaceFrom(width, height, pixel_format, (void *)data, pitch);
if (loaded_surface == nullptr)
{
if (loaded_surface == nullptr) {
std::cout << "No se pudo cargar la imagen " << file_path << std::endl;
}
else
{
} else {
// Crea la textura desde los píxeles de la superficie
new_texture = SDL_CreateTextureFromSurface(renderer_, loaded_surface);
if (new_texture == nullptr)
{
if (new_texture == nullptr) {
std::cout << "No se pudo crear la textura desde " << file_path << "! Error de SDL: " << SDL_GetError() << std::endl;
}
else
{
} else {
// Obtiene las dimensiones de la imagen
width_ = loaded_surface->w;
height_ = loaded_surface->h;
@@ -95,10 +89,8 @@ bool Texture::loadFromFile(const std::string &file_path)
}
// Libera la textura si existe
void Texture::free()
{
if (texture_ != nullptr)
{
void Texture::free() {
if (texture_ != nullptr) {
SDL_DestroyTexture(texture_);
texture_ = nullptr;
width_ = 0;
@@ -107,25 +99,21 @@ void Texture::free()
}
// Renderiza la textura en pantalla
void Texture::render(SDL_FRect *src, SDL_FRect *dst)
{
void Texture::render(SDL_FRect *src, SDL_FRect *dst) {
SDL_RenderTexture(renderer_, texture_, src, dst);
}
// Obtiene el ancho de la imagen
int Texture::getWidth()
{
int Texture::getWidth() {
return width_;
}
// Obtiene la altura de la imagen
int Texture::getHeight()
{
int Texture::getHeight() {
return height_;
}
// Modula el color de la textura
void Texture::setColor(int r, int g, int b)
{
void Texture::setColor(int r, int g, int b) {
SDL_SetTextureColorMod(texture_, r, g, b);
}