nous sons
This commit is contained in:
@@ -236,6 +236,22 @@ void VectorText::render(const std::string& text, const Punt& posicio, float esca
|
||||
}
|
||||
}
|
||||
|
||||
void VectorText::render_centered(const std::string& text, const Punt& centre_punt, float escala, float spacing, float brightness) {
|
||||
// Calcular dimensions del text
|
||||
float text_width = get_text_width(text, escala, spacing);
|
||||
float text_height = get_text_height(escala);
|
||||
|
||||
// Calcular posició de l'esquina superior esquerra
|
||||
// restant la meitat de les dimensions del punt central
|
||||
Punt posicio_esquerra = {
|
||||
centre_punt.x - (text_width / 2.0f),
|
||||
centre_punt.y - (text_height / 2.0f)
|
||||
};
|
||||
|
||||
// Delegar al mètode render() existent
|
||||
render(text, posicio_esquerra, escala, spacing, brightness);
|
||||
}
|
||||
|
||||
float VectorText::get_text_width(const std::string& text, float escala, float spacing) const {
|
||||
if (text.empty()) {
|
||||
return 0.0f;
|
||||
|
||||
@@ -27,6 +27,14 @@ class VectorText {
|
||||
// - brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor)
|
||||
void render(const std::string& text, const Punt& posicio, float escala = 1.0f, float spacing = 2.0f, float brightness = 1.0f);
|
||||
|
||||
// Renderizar string centrado en un punto
|
||||
// - text: cadena a renderizar
|
||||
// - centre_punt: punto central del texto (no esquina superior izquierda)
|
||||
// - escala: factor de escala (1.0 = 20×40 px por carácter)
|
||||
// - spacing: espacio entre caracteres en píxeles (a escala 1.0)
|
||||
// - brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor)
|
||||
void render_centered(const std::string& text, const Punt& centre_punt, float escala = 1.0f, float spacing = 2.0f, float brightness = 1.0f);
|
||||
|
||||
// Calcular ancho total de un string (útil para centrado)
|
||||
float get_text_width(const std::string& text, float escala = 1.0f, float spacing = 2.0f) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user