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,4 +1,4 @@
#include "text.h"
#include "text.hpp"
#include <SDL3/SDL.h> // Para Uint8, SDL_GetRenderTarget, SDL_RenderClear, SDL_SetRenderDrawColor, SDL_SetRenderTarget, SDL_FRect, SDL_BLENDMODE_BLEND, SDL_PixelFormat, SDL_TextureAccess
@@ -8,15 +8,15 @@
#include <stdexcept> // Para runtime_error
#include <string_view> // Para string_view
#include "color.h" // Para Color
#include "resource_helper.h" // Para ResourceHelper
#include "screen.h" // Para Screen
#include "sprite.h" // Para Sprite
#include "texture.h" // Para Texture
#include "utils.h" // Para getFileName, printWithDots
#include "color.hpp" // Para Color
#include "resource_helper.hpp" // Para ResourceHelper
#include "screen.hpp" // Para Screen
#include "sprite.hpp" // Para Sprite
#include "texture.hpp" // Para Texture
#include "utils.hpp" // Para getFileName, printWithDots
// Constructor
Text::Text(const std::shared_ptr<Texture> &texture, const std::string &text_file) {
Text::Text(const std::shared_ptr<Texture>& texture, const std::string& text_file) {
// Carga los offsets desde el fichero
auto tf = loadFile(text_file);
@@ -37,7 +37,7 @@ Text::Text(const std::shared_ptr<Texture> &texture, const std::string &text_file
}
// Constructor
Text::Text(const std::shared_ptr<Texture> &texture, const std::shared_ptr<Text::File> &text_file) {
Text::Text(const std::shared_ptr<Texture>& texture, const std::shared_ptr<Text::File>& text_file) {
// Inicializa variables desde la estructura
box_height_ = text_file->box_height;
box_width_ = text_file->box_width;
@@ -55,7 +55,7 @@ Text::Text(const std::shared_ptr<Texture> &texture, const std::shared_ptr<Text::
}
// Constructor con textura blanca opcional
Text::Text(const std::shared_ptr<Texture> &texture, const std::shared_ptr<Texture> &white_texture, const std::string &text_file) {
Text::Text(const std::shared_ptr<Texture>& texture, const std::shared_ptr<Texture>& white_texture, const std::string& text_file) {
// Carga los offsets desde el fichero
auto tf = loadFile(text_file);
@@ -77,7 +77,7 @@ Text::Text(const std::shared_ptr<Texture> &texture, const std::shared_ptr<Textur
}
// Constructor con textura blanca opcional
Text::Text(const std::shared_ptr<Texture> &texture, const std::shared_ptr<Texture> &white_texture, const std::shared_ptr<Text::File> &text_file) {
Text::Text(const std::shared_ptr<Texture>& texture, const std::shared_ptr<Texture>& white_texture, const std::shared_ptr<Text::File>& text_file) {
// Inicializa variables desde la estructura
box_height_ = text_file->box_height;
box_width_ = text_file->box_width;
@@ -96,7 +96,7 @@ Text::Text(const std::shared_ptr<Texture> &texture, const std::shared_ptr<Textur
}
// Escribe texto en pantalla
void Text::write(int x, int y, const std::string &text, int kerning, int length) {
void Text::write(int x, int y, const std::string& text, int kerning, int length) {
int shift = 0;
const std::string_view VISIBLE_TEXT = (length == -1) ? std::string_view(text) : std::string_view(text).substr(0, length);
@@ -114,7 +114,7 @@ void Text::write(int x, int y, const std::string &text, int kerning, int length)
}
// Escribe el texto al doble de tamaño
void Text::write2X(int x, int y, const std::string &text, int kerning, int length) {
void Text::write2X(int x, int y, const std::string& text, int kerning, int length) {
int shift = 0;
const std::string_view VISIBLE_TEXT = (length == -1) ? std::string_view(text) : std::string_view(text).substr(0, length);
@@ -135,12 +135,12 @@ void Text::write2X(int x, int y, const std::string &text, int kerning, int lengt
}
// Escribe el texto en una textura
auto Text::writeToTexture(const std::string &text, int zoom, int kerning, int length) -> std::shared_ptr<Texture> {
auto *renderer = Screen::get()->getRenderer();
auto Text::writeToTexture(const std::string& text, int zoom, int kerning, int length) -> std::shared_ptr<Texture> {
auto* renderer = Screen::get()->getRenderer();
auto texture = std::make_shared<Texture>(renderer);
auto width = Text::length(text, kerning) * zoom;
auto height = box_height_ * zoom;
auto *temp = SDL_GetRenderTarget(renderer);
auto* temp = SDL_GetRenderTarget(renderer);
texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
texture->setBlendMode(SDL_BLENDMODE_BLEND);
@@ -154,8 +154,8 @@ auto Text::writeToTexture(const std::string &text, int zoom, int kerning, int le
}
// Escribe el texto con extras en una textura
auto Text::writeDXToTexture(Uint8 flags, const std::string &text, int kerning, Color text_color, Uint8 shadow_distance, Color shadow_color, int length) -> std::shared_ptr<Texture> {
auto *renderer = Screen::get()->getRenderer();
auto Text::writeDXToTexture(Uint8 flags, const std::string& text, int kerning, Color text_color, Uint8 shadow_distance, Color shadow_color, int length) -> std::shared_ptr<Texture> {
auto* renderer = Screen::get()->getRenderer();
auto texture = std::make_shared<Texture>(renderer);
// Calcula las dimensiones considerando los efectos
@@ -181,7 +181,7 @@ auto Text::writeDXToTexture(Uint8 flags, const std::string &text, int kerning, C
height = base_height + shadow_distance;
}
auto *temp = SDL_GetRenderTarget(renderer);
auto* temp = SDL_GetRenderTarget(renderer);
texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
texture->setBlendMode(SDL_BLENDMODE_BLEND);
@@ -195,16 +195,16 @@ auto Text::writeDXToTexture(Uint8 flags, const std::string &text, int kerning, C
}
// Escribe el texto con colores
void Text::writeColored(int x, int y, const std::string &text, Color color, int kerning, int length) {
void Text::writeColored(int x, int y, const std::string& text, Color color, int kerning, int length) {
writeColoredWithSprite(sprite_.get(), x, y, text, color, kerning, length);
}
// Escribe el texto con colores usando un sprite específico
void Text::writeColoredWithSprite(Sprite *sprite, int x, int y, const std::string &text, Color color, int kerning, int length) {
void Text::writeColoredWithSprite(Sprite* sprite, int x, int y, const std::string& text, Color color, int kerning, int length) {
int shift = 0;
const std::string_view VISIBLE_TEXT = (length == -1) ? std::string_view(text) : std::string_view(text).substr(0, length);
auto *texture = sprite->getTexture().get();
auto* texture = sprite->getTexture().get();
// Guarda el alpha original y aplica el nuevo
Uint8 original_alpha;
@@ -230,9 +230,9 @@ void Text::writeColoredWithSprite(Sprite *sprite, int x, int y, const std::strin
}
// Escribe stroke con alpha correcto usando textura temporal
void Text::writeStrokeWithAlpha(int x, int y, const std::string &text, int kerning, Color stroke_color, Uint8 shadow_distance, int length) {
auto *renderer = Screen::get()->getRenderer();
auto *original_target = SDL_GetRenderTarget(renderer);
void Text::writeStrokeWithAlpha(int x, int y, const std::string& text, int kerning, Color stroke_color, Uint8 shadow_distance, int length) {
auto* renderer = Screen::get()->getRenderer();
auto* original_target = SDL_GetRenderTarget(renderer);
// Calcula dimensiones de la textura temporal
auto text_width = Text::length(text, kerning);
@@ -251,7 +251,7 @@ void Text::writeStrokeWithAlpha(int x, int y, const std::string &text, int kerni
SDL_RenderClear(renderer);
// Selecciona el sprite apropiado para el stroke
auto *stroke_sprite = white_sprite_ ? white_sprite_.get() : sprite_.get();
auto* stroke_sprite = white_sprite_ ? white_sprite_.get() : sprite_.get();
// Renderiza stroke sin alpha (sólido) en textura temporal
Color solid_color = Color(stroke_color.r, stroke_color.g, stroke_color.b, 255);
@@ -272,19 +272,19 @@ void Text::writeStrokeWithAlpha(int x, int y, const std::string &text, int kerni
}
// Escribe el texto con sombra
void Text::writeShadowed(int x, int y, const std::string &text, Color color, Uint8 shadow_distance, int kerning, int length) {
void Text::writeShadowed(int x, int y, const std::string& text, Color color, Uint8 shadow_distance, int kerning, int length) {
writeDX(Text::SHADOW, x, y, text, kerning, color, shadow_distance, color, length);
write(x, y, text, kerning, length); // Dibuja el texto principal encima
}
// Escribe el texto centrado en un punto x
void Text::writeCentered(int x, int y, const std::string &text, int kerning, int length) {
void Text::writeCentered(int x, int y, const std::string& text, int kerning, int length) {
x -= (Text::length(text, kerning) / 2);
write(x, y, text, kerning, length);
}
// Escribe texto con extras
void Text::writeDX(Uint8 flags, int x, int y, const std::string &text, int kerning, Color text_color, Uint8 shadow_distance, Color shadow_color, int length) {
void Text::writeDX(Uint8 flags, int x, int y, const std::string& text, int kerning, Color text_color, Uint8 shadow_distance, Color shadow_color, int length) {
const auto CENTERED = ((flags & Text::CENTER) == Text::CENTER);
const auto SHADOWED = ((flags & Text::SHADOW) == Text::SHADOW);
const auto COLORED = ((flags & Text::COLOR) == Text::COLOR);
@@ -330,14 +330,14 @@ void Text::writeDX(Uint8 flags, int x, int y, const std::string &text, int kerni
}
// Escribe texto a partir de un TextStyle
void Text::writeStyle(int x, int y, const std::string &text, const Style &style, int length) {
void Text::writeStyle(int x, int y, const std::string& text, const Style& style, int length) {
writeDX(style.flags, x, y, text, style.kerning, style.text_color, style.shadow_distance, style.shadow_color);
}
// Obtiene la longitud en pixels de una cadena
auto Text::length(const std::string &text, int kerning) const -> int {
auto Text::length(const std::string& text, int kerning) const -> int {
int shift = 0;
for (const auto &ch : text) {
for (const auto& ch : text) {
// Convertimos a unsigned char para obtener el valor ASCII correcto (0-255)
const auto INDEX = static_cast<unsigned char>(ch);
@@ -362,11 +362,11 @@ void Text::setFixedWidth(bool value) {
}
// Llena una estructuta TextFile desde un fichero
auto Text::loadFile(const std::string &file_path) -> std::shared_ptr<Text::File> {
auto Text::loadFile(const std::string& file_path) -> std::shared_ptr<Text::File> {
auto tf = std::make_shared<Text::File>();
// Inicializa a cero el vector con las coordenadas
for (auto &i : tf->offset) {
for (auto& i : tf->offset) {
i.x = 0;
i.y = 0;
i.w = 0;
@@ -391,7 +391,7 @@ auto Text::loadFile(const std::string &file_path) -> std::shared_ptr<Text::File>
file.open(file_path);
}
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);
if ((using_resource_data && stream.good()) || (!using_resource_data && file.is_open() && file.good())) {
std::string buffer;