corregida la llista de inicialització en clang-format
creat Balloon::Config per a inicialitzar globos
This commit is contained in:
@@ -8,12 +8,12 @@
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include <string_view> // Para string_view
|
||||
|
||||
#include "color.h" // Para Color
|
||||
#include "screen.h" // Para Screen
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "texture.h" // Para Texture
|
||||
#include "utils.h" // Para getFileName, printWithDots
|
||||
#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
|
||||
|
||||
// Constructor
|
||||
Text::Text(const std::shared_ptr<Texture> &texture, const std::string &text_file) {
|
||||
@@ -157,7 +157,7 @@ auto Text::writeToTexture(const std::string &text, int zoom, int kerning, int le
|
||||
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
|
||||
auto base_width = Text::length(text, kerning);
|
||||
auto base_height = box_height_;
|
||||
@@ -165,10 +165,10 @@ auto Text::writeDXToTexture(Uint8 flags, const std::string &text, int kerning, C
|
||||
auto height = base_height;
|
||||
auto offset_x = 0;
|
||||
auto offset_y = 0;
|
||||
|
||||
|
||||
const auto STROKED = ((flags & Text::STROKE) == Text::STROKE);
|
||||
const auto SHADOWED = ((flags & Text::SHADOW) == Text::SHADOW);
|
||||
|
||||
|
||||
if (STROKED) {
|
||||
// Para stroke, el texto se expande en todas las direcciones por shadow_distance
|
||||
width = base_width + (shadow_distance * 2);
|
||||
@@ -180,7 +180,7 @@ auto Text::writeDXToTexture(Uint8 flags, const std::string &text, int kerning, C
|
||||
width = base_width + shadow_distance;
|
||||
height = base_height + shadow_distance;
|
||||
}
|
||||
|
||||
|
||||
auto *temp = SDL_GetRenderTarget(renderer);
|
||||
|
||||
texture->createBlank(width, height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||
@@ -200,18 +200,18 @@ void Text::writeColored(int x, int y, const std::string &text, Color color, int
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
|
||||
// Guarda el alpha original y aplica el nuevo
|
||||
Uint8 original_alpha;
|
||||
SDL_GetTextureAlphaMod(texture->getSDLTexture(), &original_alpha);
|
||||
texture->setAlpha(color.a);
|
||||
texture->setColor(color.r, color.g, color.b);
|
||||
|
||||
|
||||
sprite->setY(y);
|
||||
for (const auto CH : VISIBLE_TEXT) {
|
||||
const auto INDEX = static_cast<unsigned char>(CH);
|
||||
@@ -223,7 +223,7 @@ void Text::writeColoredWithSprite(Sprite* sprite, int x, int y, const std::strin
|
||||
shift += offset_[INDEX].w + kerning;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Restaura los valores originales
|
||||
texture->setColor(255, 255, 255);
|
||||
texture->setAlpha(255);
|
||||
@@ -233,26 +233,26 @@ void Text::writeColoredWithSprite(Sprite* sprite, int x, int y, const std::strin
|
||||
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);
|
||||
auto text_height = box_height_;
|
||||
auto temp_width = text_width + (shadow_distance * 2);
|
||||
auto temp_height = text_height + (shadow_distance * 2);
|
||||
|
||||
|
||||
// Crea textura temporal
|
||||
auto temp_texture = std::make_shared<Texture>(renderer);
|
||||
temp_texture->createBlank(temp_width, temp_height, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET);
|
||||
temp_texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
|
||||
|
||||
// Renderiza el stroke en la textura temporal
|
||||
temp_texture->setAsRenderTarget(renderer);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
|
||||
// Selecciona el sprite apropiado para el stroke
|
||||
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);
|
||||
for (int dist = 1; dist <= shadow_distance; ++dist) {
|
||||
@@ -262,10 +262,10 @@ void Text::writeStrokeWithAlpha(int x, int y, const std::string &text, int kerni
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Restaura render target original
|
||||
SDL_SetRenderTarget(renderer, original_target);
|
||||
|
||||
|
||||
// Renderiza la textura temporal con el alpha deseado
|
||||
temp_texture->setAlpha(stroke_color.a);
|
||||
temp_texture->render(x - shadow_distance, y - shadow_distance);
|
||||
@@ -378,20 +378,20 @@ auto Text::loadFile(const std::string &file_path) -> std::shared_ptr<Text::File>
|
||||
auto resource_data = ResourceHelper::loadFile(file_path);
|
||||
std::istringstream stream;
|
||||
bool using_resource_data = false;
|
||||
|
||||
|
||||
if (!resource_data.empty()) {
|
||||
std::string content(resource_data.begin(), resource_data.end());
|
||||
stream.str(content);
|
||||
using_resource_data = true;
|
||||
}
|
||||
|
||||
|
||||
// Fallback a archivo directo
|
||||
std::ifstream file;
|
||||
if (!using_resource_data) {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user