renombrades extensions .h a .hpp

This commit is contained in:
2025-10-17 21:45:19 +02:00
parent 50ccb2ccc2
commit 46974ef2eb
144 changed files with 1758 additions and 1783 deletions

View File

@@ -1,5 +1,5 @@
#define STB_IMAGE_IMPLEMENTATION
#include "texture.h"
#include "texture.hpp"
#include <SDL3/SDL.h> // Para SDL_LogError, SDL_LogCategory, Uint8, SDL_...
@@ -12,14 +12,14 @@
#include <utility>
#include <vector> // Para vector
#include "color.h" // Para getFileName, Color, printWithDots
#include "external/gif.h" // Para Gif
#include "resource_helper.h" // Para ResourceHelper
#include "stb_image.h" // Para stbi_image_free, stbi_load, STBI_rgb_alpha
#include "utils.h"
#include "color.hpp" // Para getFileName, Color, printWithDots
#include "external/gif.hpp" // Para Gif
#include "resource_helper.hpp" // Para ResourceHelper
#include "stb_image.h" // Para stbi_image_free, stbi_load, STBI_rgb_alpha
#include "utils.hpp"
// Constructor
Texture::Texture(SDL_Renderer *renderer, std::string path)
Texture::Texture(SDL_Renderer* renderer, std::string path)
: renderer_(renderer),
path_(std::move(path)) {
// Carga el fichero en la textura
@@ -56,7 +56,7 @@ Texture::~Texture() {
}
// Carga una imagen desde un fichero
auto Texture::loadFromFile(const std::string &file_path) -> bool {
auto Texture::loadFromFile(const std::string& file_path) -> bool {
if (file_path.empty()) {
return false;
}
@@ -65,7 +65,7 @@ auto Texture::loadFromFile(const std::string &file_path) -> bool {
int width;
int height;
int orig_format;
unsigned char *data = nullptr;
unsigned char* data = nullptr;
// Intentar cargar desde ResourceHelper primero
auto resource_data = ResourceHelper::loadFile(file_path);
@@ -93,10 +93,10 @@ auto Texture::loadFromFile(const std::string &file_path) -> bool {
unloadTexture();
// La textura final
SDL_Texture *new_texture = nullptr;
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 {
@@ -164,7 +164,7 @@ void Texture::setAlpha(Uint8 alpha) {
}
// Renderiza la textura en un punto específico
void Texture::render(int x, int y, SDL_FRect *clip, float horizontal_zoom, float vertical_zoom, double angle, SDL_FPoint *center, SDL_FlipMode flip) {
void Texture::render(int x, int y, SDL_FRect* clip, float horizontal_zoom, float vertical_zoom, double angle, SDL_FPoint* center, SDL_FlipMode flip) {
// Establece el destino de renderizado en la pantalla
SDL_FRect render_quad = {static_cast<float>(x), static_cast<float>(y), static_cast<float>(width_), static_cast<float>(height_)};
@@ -189,7 +189,7 @@ void Texture::render(int x, int y, SDL_FRect *clip, float horizontal_zoom, float
}
// Establece la textura como objetivo de renderizado
void Texture::setAsRenderTarget(SDL_Renderer *renderer) {
void Texture::setAsRenderTarget(SDL_Renderer* renderer) {
SDL_SetRenderTarget(renderer, texture_);
}
@@ -209,7 +209,7 @@ auto Texture::reLoad() -> bool {
}
// Obtiene la textura
auto Texture::getSDLTexture() -> SDL_Texture * {
auto Texture::getSDLTexture() -> SDL_Texture* {
return texture_;
}
@@ -221,7 +221,7 @@ void Texture::unloadSurface() {
}
// Crea una surface desde un fichero .gif
auto Texture::loadSurface(const std::string &file_path) -> std::shared_ptr<Surface> {
auto Texture::loadSurface(const std::string& file_path) -> std::shared_ptr<Surface> {
// Libera la superficie actual
unloadSurface();
@@ -245,7 +245,7 @@ auto Texture::loadSurface(const std::string &file_path) -> std::shared_ptr<Surfa
// Leer el contenido del archivo en un buffer
buffer.resize(size);
if (!file.read(reinterpret_cast<char *>(buffer.data()), size)) {
if (!file.read(reinterpret_cast<char*>(buffer.data()), size)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error al leer el fichero %s", file_path.c_str());
throw std::runtime_error("Error al leer el fichero: " + file_path);
}
@@ -279,16 +279,16 @@ 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_);
SDL_SetRenderTarget(renderer_, temp);
// Vuelca los datos
Uint32 *pixels;
Uint32* pixels;
int pitch;
SDL_LockTexture(texture_, nullptr, reinterpret_cast<void **>(&pixels), &pitch);
SDL_LockTexture(texture_, nullptr, reinterpret_cast<void**>(&pixels), &pitch);
for (int i = 0; i < width_ * height_; ++i) {
pixels[i] = palettes_[current_palette_][surface_->data[i]];
}
@@ -301,7 +301,7 @@ void Texture::setPaletteColor(int palette, int index, Uint32 color) {
}
// Carga una paleta desde un fichero
auto Texture::loadPaletteFromFile(const std::string &file_path, bool quiet) -> Palette {
auto Texture::loadPaletteFromFile(const std::string& file_path, bool quiet) -> Palette {
Palette palette;
std::vector<Uint8> buffer;
@@ -323,7 +323,7 @@ auto Texture::loadPaletteFromFile(const std::string &file_path, bool quiet) -> P
file.seekg(0, std::ios::beg);
buffer.resize(size);
if (!file.read(reinterpret_cast<char *>(buffer.data()), size)) {
if (!file.read(reinterpret_cast<char*>(buffer.data()), size)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: No se pudo leer completamente el fichero %s", file_path.c_str());
throw std::runtime_error("Error al leer el fichero: " + file_path);
}
@@ -351,13 +351,13 @@ auto Texture::loadPaletteFromFile(const std::string &file_path, bool quiet) -> P
}
// Añade una paleta a la lista
void Texture::addPaletteFromGifFile(const std::string &path, bool quiet) {
void Texture::addPaletteFromGifFile(const std::string& path, bool quiet) {
palettes_.emplace_back(loadPaletteFromFile(path, quiet));
setPaletteColor(palettes_.size() - 1, 0, 0x00000000);
}
// Añade una paleta a la lista
void Texture::addPaletteFromPalFile(const std::string &path) {
void Texture::addPaletteFromPalFile(const std::string& path) {
palettes_.emplace_back(readPalFile(path, true)); // Usar modo silencioso
setPaletteColor(palettes_.size() - 1, 0, 0x00000000);
}
@@ -371,10 +371,10 @@ void Texture::setPalette(size_t palette) {
}
// Obtiene el renderizador
auto Texture::getRenderer() -> SDL_Renderer * { return renderer_; }
auto Texture::getRenderer() -> SDL_Renderer* { return renderer_; }
// Carga una paleta desde un archivo .pal
auto Texture::readPalFile(const std::string &file_path, bool quiet) -> Palette {
auto Texture::readPalFile(const std::string& file_path, bool quiet) -> Palette {
Palette palette{};
palette.fill(0); // Inicializar todo con 0 (transparente por defecto)
@@ -398,7 +398,7 @@ auto Texture::readPalFile(const std::string &file_path, bool quiet) -> Palette {
}
}
std::istream &input_stream = using_resource_data ? stream : static_cast<std::istream &>(file);
std::istream& input_stream = using_resource_data ? stream : static_cast<std::istream&>(file);
std::string line;
int line_number = 0;