afegides shapes per a fonts

This commit is contained in:
2025-11-29 10:06:33 +01:00
parent 89302a2ee3
commit 983f42814f
69 changed files with 530 additions and 258 deletions

View File

@@ -92,8 +92,8 @@ void EscenaLogo::inicialitzar_lletres() {
// Llista de fitxers .shp (A repetida per a les dues A's)
std::vector<std::string> fitxers = {
"letra_j.shp", "letra_a.shp", "letra_i.shp", "letra_l.shp",
"letra_g.shp", "letra_a.shp", "letra_m.shp", "letra_e.shp", "letra_s.shp"
"logo/letra_j.shp", "logo/letra_a.shp", "logo/letra_i.shp", "logo/letra_l.shp",
"logo/letra_g.shp", "logo/letra_a.shp", "logo/letra_m.shp", "logo/letra_e.shp", "logo/letra_s.shp"
};
// Pas 1: Carregar totes les formes i calcular amplades

View File

@@ -0,0 +1,60 @@
// text_renderer.cpp - Implementació del renderitzador de text
// © 2025 Port a C++20 amb SDL3
#include "text_renderer.hpp"
#include "../core/graphics/shape_loader.hpp"
#include "../core/rendering/shape_renderer.hpp"
#include <iostream>
namespace Utils {
void TextRenderer::render(SDL_Renderer* renderer,
const std::string& text,
int x, int y,
int spacing) {
int current_x = x;
for (char c : text) {
std::string filename = get_char_filename(c);
auto shape = Graphics::ShapeLoader::load("font/" + filename);
if (shape && shape->es_valida()) {
Punt pos = {current_x, y};
Rendering::render_shape(renderer, shape, pos, 0.0f, 1.0f, true, 1.0f);
}
current_x += spacing;
}
}
int TextRenderer::calculate_width(const std::string& text, int spacing) {
return static_cast<int>(text.length()) * spacing;
}
std::string TextRenderer::get_char_filename(char c) {
// Números 0-9
if (c >= '0' && c <= '9')
return std::string("char_") + c + ".shp";
// Letras A-Z (mayúsculas)
if (c >= 'A' && c <= 'Z')
return std::string("char_") + c + ".shp";
// Convertir minúsculas a mayúsculas
if (c >= 'a' && c <= 'z')
return std::string("char_") + char(c - 32) + ".shp";
// Caracteres especiales
switch (c) {
case ':': return "char_colon.shp";
case '.': return "char_dot.shp";
case '-': return "char_minus.shp";
case ',': return "char_comma.shp";
case '!': return "char_exclamation.shp";
case '?': return "char_question.shp";
case ' ': return "char_space.shp";
default: return "char_question.shp"; // Fallback
}
}
} // namespace Utils

View File

@@ -0,0 +1,30 @@
// text_renderer.hpp - Renderitzador de text amb formes .shp
// © 2025 Port a C++20 amb SDL3
#pragma once
#include <string>
#include "../core/types.hpp"
// Forward declarations
struct SDL_Renderer;
namespace Graphics { class Shape; }
namespace Utils {
class TextRenderer {
public:
// Renderitza un string en la posició especificada
static void render(SDL_Renderer* renderer,
const std::string& text,
int x, int y,
int spacing = 22);
// Calcula el ancho total de un string
static int calculate_width(const std::string& text, int spacing = 22);
private:
// Mapea un caràcter a su nombre de archivo .shp
static std::string get_char_filename(char c);
};
} // namespace Utils