Fase 1d: rename del codi restant (effects, stage_system, locals)
Sweep final del naming a CamelCase/camelBack/lower_case:
Fitxers renombrats:
- effects/gestor_puntuacio_flotant.{hpp,cpp} -> floating_score_manager.{hpp,cpp}
- effects/puntuacio_flotant.hpp -> floating_score.hpp
Tipus (CamelCase):
- GestorPuntuacioFlotant -> FloatingScoreManager
- PuntuacioFlotant -> FloatingScore
- ConfigStage -> StageConfig
- ConfigSistemaStages -> StageSystemConfig
- NauTitol -> TitleShip
- EstatNau -> ShipState
Metodes publics (camelBack):
- obte_renderer -> getRenderer
- get_num_actius -> getActiveCount
- calcular_direccio_explosio -> computeExplosionDirection
- trobar_slot_lliure -> findFreeSlot
- explotar -> explode
- reiniciar -> reset
- es_valida -> isValid
- parsejar_fitxer -> parseFile
- carregar -> load
- crear_explosio -> createExplosion
- registrar_puntuacio -> registerScore
- construir_marcador -> buildScoreboard
- render_centered -> renderCentered
Camps struct publics (snake_case):
- actiu/actius -> active
- rotacio -> rotation, rotacio_visual -> visual_rotation
- acceleracio -> acceleration
- velocitat -> velocity
- escala/escala_inicial/objectiu/actual -> scale/initial_scale/...
- posicio/posicio_inicial/objectiu/actual -> position/initial_position/...
- fase_oscilacio -> oscillation_phase
- temps_estat -> state_time
- jugador_id -> player_id
- estat -> state
- brillantor -> brightness
- tipus -> type
Camps privats (sufix _):
- naus_ -> ships_, orni_ -> enemies_, bales_ -> bullets_
- gestor_puntuacio_ -> floating_score_manager_
- punt_mort_ -> death_position_, punt_spawn_ -> spawn_position_
- itocado_per_jugador_ -> hit_timer_per_player_
- vides_per_jugador_ -> lives_per_player_
- puntuacio_per_jugador_ -> score_per_player_
- estat_game_over_ -> game_over_state_
- continues_usados_ -> continues_used_
Constants:
- MARGE_ESQ/DRET/DALT/BAIX -> MARGIN_LEFT/RIGHT/TOP/BOTTOM
Variables locals i parametres comuns (snake_case):
- nau -> ship, enemic -> enemy, bala -> bullet
- forma -> shape, punt(s) -> point(s)
- jugador -> player, partida -> match
- temps -> time, missatge -> message
Diff: 59 fitxers, +1000/-1000 (simetric). Compila i enllaça.
Pendents per a futures fases (no bloquejants):
- Comentaris de capçalera en catala -> castella
- Variables locals/parametres minoritaris en catala
- Include guards (queden alguns #ifndef en lloc de #pragma once)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -14,10 +14,10 @@ Shape::Shape(const std::string& filepath)
|
||||
: center_({.x = 0.0F, .y = 0.0F}),
|
||||
escala_defecte_(1.0F),
|
||||
nom_("unnamed") {
|
||||
carregar(filepath);
|
||||
load(filepath);
|
||||
}
|
||||
|
||||
bool Shape::carregar(const std::string& filepath) {
|
||||
bool Shape::load(const std::string& filepath) {
|
||||
// Llegir fitxer
|
||||
std::ifstream file(filepath);
|
||||
if (!file.is_open()) {
|
||||
@@ -32,10 +32,10 @@ bool Shape::carregar(const std::string& filepath) {
|
||||
file.close();
|
||||
|
||||
// Parsejar
|
||||
return parsejar_fitxer(contingut);
|
||||
return parseFile(contingut);
|
||||
}
|
||||
|
||||
bool Shape::parsejar_fitxer(const std::string& contingut) {
|
||||
bool Shape::parseFile(const std::string& contingut) {
|
||||
std::istringstream iss(contingut);
|
||||
std::string line;
|
||||
|
||||
@@ -55,7 +55,7 @@ bool Shape::parsejar_fitxer(const std::string& contingut) {
|
||||
try {
|
||||
escala_defecte_ = std::stof(extract_value(line));
|
||||
} catch (...) {
|
||||
std::cerr << "[Shape] Warning: escala invàlida, usant 1.0" << '\n';
|
||||
std::cerr << "[Shape] Warning: scale invàlida, usant 1.0" << '\n';
|
||||
escala_defecte_ = 1.0F;
|
||||
}
|
||||
} else if (starts_with(line, "center:")) {
|
||||
@@ -65,7 +65,7 @@ bool Shape::parsejar_fitxer(const std::string& contingut) {
|
||||
if (points.size() >= 2) {
|
||||
primitives_.push_back({PrimitiveType::POLYLINE, points});
|
||||
} else {
|
||||
std::cerr << "[Shape] Warning: polyline amb menys de 2 punts ignorada"
|
||||
std::cerr << "[Shape] Warning: polyline amb menys de 2 points ignorada"
|
||||
<< '\n';
|
||||
}
|
||||
} else if (starts_with(line, "line:")) {
|
||||
@@ -73,7 +73,7 @@ bool Shape::parsejar_fitxer(const std::string& contingut) {
|
||||
if (points.size() == 2) {
|
||||
primitives_.push_back({PrimitiveType::LINE, points});
|
||||
} else {
|
||||
std::cerr << "[Shape] Warning: line ha de tenir exactament 2 punts"
|
||||
std::cerr << "[Shape] Warning: line ha de tenir exactament 2 points"
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
@@ -147,7 +147,7 @@ std::vector<Vec2> Shape::parse_points(const std::string& str) const {
|
||||
float y = std::stof(pair.substr(comma + 1));
|
||||
points.push_back({x, y});
|
||||
} catch (...) {
|
||||
std::cerr << "[Shape] Warning: punt invàlid ignorat: " << pair
|
||||
std::cerr << "[Shape] Warning: point invàlid ignorat: " << pair
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,30 +10,30 @@
|
||||
|
||||
namespace Graphics {
|
||||
|
||||
// Tipus de primitiva dins d'una forma
|
||||
// Tipus de primitiva dins d'una shape
|
||||
enum class PrimitiveType {
|
||||
POLYLINE, // Seqüència de punts connectats
|
||||
LINE // Línia individual (2 punts)
|
||||
POLYLINE, // Seqüència de points connectats
|
||||
LINE // Línia individual (2 points)
|
||||
};
|
||||
|
||||
// Primitiva individual (polyline o line)
|
||||
struct ShapePrimitive {
|
||||
PrimitiveType type;
|
||||
std::vector<Vec2> points; // 2+ punts per polyline, exactament 2 per line
|
||||
std::vector<Vec2> points; // 2+ points per polyline, exactament 2 per line
|
||||
};
|
||||
|
||||
// Classe Shape - representa una forma vectorial carregada des de .shp
|
||||
// Classe Shape - representa una shape vectorial carregada des de .shp
|
||||
class Shape {
|
||||
public:
|
||||
// Constructors
|
||||
Shape() = default;
|
||||
explicit Shape(const std::string& filepath);
|
||||
|
||||
// Carregar forma des de fitxer .shp
|
||||
bool carregar(const std::string& filepath);
|
||||
// Carregar shape des de fitxer .shp
|
||||
bool load(const std::string& filepath);
|
||||
|
||||
// Parsejar forma des de buffer de memòria (per al sistema de recursos)
|
||||
bool parsejar_fitxer(const std::string& contingut);
|
||||
// Parsejar shape des de buffer de memòria (per al sistema de recursos)
|
||||
bool parseFile(const std::string& contingut);
|
||||
|
||||
// Getters
|
||||
[[nodiscard]] const std::vector<ShapePrimitive>& get_primitives() const {
|
||||
@@ -41,7 +41,7 @@ class Shape {
|
||||
}
|
||||
[[nodiscard]] const Vec2& getCenter() const { return center_; }
|
||||
[[nodiscard]] float get_escala_defecte() const { return escala_defecte_; }
|
||||
[[nodiscard]] bool es_valida() const { return !primitives_.empty(); }
|
||||
[[nodiscard]] bool isValid() const { return !primitives_.empty(); }
|
||||
|
||||
// Info de depuració
|
||||
[[nodiscard]] std::string get_nom() const { return nom_; }
|
||||
@@ -49,9 +49,9 @@ class Shape {
|
||||
|
||||
private:
|
||||
std::vector<ShapePrimitive> primitives_;
|
||||
Vec2 center_; // Centre/origen de la forma
|
||||
Vec2 center_; // Centre/origen de la shape
|
||||
float escala_defecte_; // Escala per defecte (normalment 1.0)
|
||||
std::string nom_; // Nom de la forma (per depuració)
|
||||
std::string nom_; // Nom de la shape (per depuració)
|
||||
|
||||
// Helpers privats per parsejar
|
||||
[[nodiscard]] std::string trim(const std::string& str) const;
|
||||
|
||||
@@ -32,7 +32,7 @@ std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
|
||||
// Load from resource system
|
||||
std::vector<uint8_t> data = Resource::Helper::loadFile(normalized);
|
||||
if (data.empty()) {
|
||||
std::cerr << "[ShapeLoader] Error: no s'ha pogut carregar " << normalized
|
||||
std::cerr << "[ShapeLoader] Error: no s'ha pogut load " << normalized
|
||||
<< '\n';
|
||||
return nullptr;
|
||||
}
|
||||
@@ -40,15 +40,15 @@ std::shared_ptr<Shape> ShapeLoader::load(const std::string& filename) {
|
||||
// Convert bytes to string and parse
|
||||
std::string file_content(data.begin(), data.end());
|
||||
auto shape = std::make_shared<Shape>();
|
||||
if (!shape->parsejar_fitxer(file_content)) {
|
||||
if (!shape->parseFile(file_content)) {
|
||||
std::cerr << "[ShapeLoader] Error: no s'ha pogut parsejar " << normalized
|
||||
<< '\n';
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Verify shape is valid
|
||||
if (!shape->es_valida()) {
|
||||
std::cerr << "[ShapeLoader] Error: forma invàlida " << normalized << '\n';
|
||||
if (!shape->isValid()) {
|
||||
std::cerr << "[ShapeLoader] Error: shape invàlida " << normalized << '\n';
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ class ShapeLoader {
|
||||
// No instanciable (tot estàtic)
|
||||
ShapeLoader() = delete;
|
||||
|
||||
// Carregar forma des de fitxer (amb caché)
|
||||
// Carregar shape des de fitxer (amb caché)
|
||||
// Retorna punter compartit (nullptr si error)
|
||||
// Exemple: load("ship.shp") → busca a "data/shapes/ship.shp"
|
||||
static std::shared_ptr<Shape> load(const std::string& filename);
|
||||
|
||||
@@ -22,11 +22,11 @@ Starfield::Starfield(SDL_Renderer* renderer,
|
||||
punt_fuga_(punt_fuga),
|
||||
area_(area),
|
||||
densitat_(densitat) {
|
||||
// Carregar forma d'estrella amb ShapeLoader
|
||||
// Carregar shape d'estrella amb ShapeLoader
|
||||
shape_estrella_ = ShapeLoader::load("star.shp");
|
||||
|
||||
if (!shape_estrella_ || !shape_estrella_->es_valida()) {
|
||||
std::cerr << "ERROR: No s'ha pogut carregar star.shp" << '\n';
|
||||
if (!shape_estrella_ || !shape_estrella_->isValid()) {
|
||||
std::cerr << "ERROR: No s'ha pogut load star.shp" << '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ Starfield::Starfield(SDL_Renderer* renderer,
|
||||
|
||||
// Calcular posició des de la distància
|
||||
float radi = estrella.distancia_centre * radi_max_;
|
||||
estrella.posicio.x = punt_fuga_.x + (radi * std::cos(estrella.angle));
|
||||
estrella.posicio.y = punt_fuga_.y + (radi * std::sin(estrella.angle));
|
||||
estrella.position.x = punt_fuga_.x + (radi * std::cos(estrella.angle));
|
||||
estrella.position.y = punt_fuga_.y + (radi * std::sin(estrella.angle));
|
||||
|
||||
estrelles_.push_back(estrella);
|
||||
}
|
||||
@@ -70,27 +70,27 @@ Starfield::Starfield(SDL_Renderer* renderer,
|
||||
|
||||
// Inicialitzar una estrella (nova o regenerada)
|
||||
void Starfield::inicialitzar_estrella(Estrella& estrella) const {
|
||||
// Angle aleatori des del punt de fuga cap a fora
|
||||
// Angle aleatori des del point de fuga cap a fora
|
||||
estrella.angle = (static_cast<float>(rand()) / RAND_MAX) * 2.0F * Defaults::Math::PI;
|
||||
|
||||
// Distància inicial petita (5% del radi màxim) - neix prop del centre
|
||||
estrella.distancia_centre = 0.05F;
|
||||
|
||||
// Posició inicial: molt prop del punt de fuga
|
||||
// Posició inicial: molt prop del point de fuga
|
||||
float radi = estrella.distancia_centre * radi_max_;
|
||||
estrella.posicio.x = punt_fuga_.x + (radi * std::cos(estrella.angle));
|
||||
estrella.posicio.y = punt_fuga_.y + (radi * std::sin(estrella.angle));
|
||||
estrella.position.x = punt_fuga_.x + (radi * std::cos(estrella.angle));
|
||||
estrella.position.y = punt_fuga_.y + (radi * std::sin(estrella.angle));
|
||||
}
|
||||
|
||||
// Verificar si una estrella està fora de l'àrea
|
||||
bool Starfield::fora_area(const Estrella& estrella) const {
|
||||
return (estrella.posicio.x < area_.x ||
|
||||
estrella.posicio.x > area_.x + area_.w ||
|
||||
estrella.posicio.y < area_.y ||
|
||||
estrella.posicio.y > area_.y + area_.h);
|
||||
return (estrella.position.x < area_.x ||
|
||||
estrella.position.x > area_.x + area_.w ||
|
||||
estrella.position.y < area_.y ||
|
||||
estrella.position.y > area_.y + area_.h);
|
||||
}
|
||||
|
||||
// Calcular escala dinàmica segons distància del centre
|
||||
// Calcular scale dinàmica segons distància del centre
|
||||
float Starfield::calcular_escala(const Estrella& estrella) const {
|
||||
const CapaConfig& capa = capes_[estrella.capa];
|
||||
|
||||
@@ -119,16 +119,16 @@ void Starfield::update(float delta_time) {
|
||||
const CapaConfig& capa = capes_[estrella.capa];
|
||||
|
||||
// Moure cap a fora des del centre
|
||||
float velocitat = capa.velocitat_base;
|
||||
float dx = velocitat * std::cos(estrella.angle) * delta_time;
|
||||
float dy = velocitat * std::sin(estrella.angle) * delta_time;
|
||||
float velocity = capa.velocitat_base;
|
||||
float dx = velocity * std::cos(estrella.angle) * delta_time;
|
||||
float dy = velocity * std::sin(estrella.angle) * delta_time;
|
||||
|
||||
estrella.posicio.x += dx;
|
||||
estrella.posicio.y += dy;
|
||||
estrella.position.x += dx;
|
||||
estrella.position.y += dy;
|
||||
|
||||
// Actualitzar distància del centre
|
||||
float dx_centre = estrella.posicio.x - punt_fuga_.x;
|
||||
float dy_centre = estrella.posicio.y - punt_fuga_.y;
|
||||
float dx_centre = estrella.position.x - punt_fuga_.x;
|
||||
float dy_centre = estrella.position.y - punt_fuga_.y;
|
||||
float dist_px = std::sqrt((dx_centre * dx_centre) + (dy_centre * dy_centre));
|
||||
estrella.distancia_centre = dist_px / radi_max_;
|
||||
|
||||
@@ -146,22 +146,22 @@ void Starfield::set_brightness(float multiplier) {
|
||||
|
||||
// Dibuixar totes les estrelles
|
||||
void Starfield::draw() {
|
||||
if (!shape_estrella_->es_valida()) {
|
||||
if (!shape_estrella_->isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& estrella : estrelles_) {
|
||||
// Calcular escala i brightness dinàmicament
|
||||
float escala = calcular_escala(estrella);
|
||||
// Calcular scale i brightness dinàmicament
|
||||
float scale = calcular_escala(estrella);
|
||||
float brightness = calcular_brightness(estrella);
|
||||
|
||||
// Renderitzar estrella sense rotació
|
||||
Rendering::render_shape(
|
||||
renderer_,
|
||||
shape_estrella_,
|
||||
estrella.posicio,
|
||||
estrella.position,
|
||||
0.0F, // angle (les estrelles no giren)
|
||||
escala, // escala dinàmica
|
||||
scale, // scale dinàmica
|
||||
1.0F, // progress (sempre visible)
|
||||
brightness // brightness dinàmica
|
||||
);
|
||||
|
||||
@@ -26,7 +26,7 @@ class Starfield {
|
||||
public:
|
||||
// Constructor
|
||||
// - renderer: SDL renderer
|
||||
// - punt_fuga: punt d'origen/fuga des d'on surten les estrelles
|
||||
// - punt_fuga: point d'origen/fuga des d'on surten les estrelles
|
||||
// - area: rectangle on actuen les estrelles (SDL_FRect)
|
||||
// - densitat: nombre total d'estrelles (es divideix entre capes)
|
||||
Starfield(SDL_Renderer* renderer,
|
||||
@@ -40,14 +40,14 @@ class Starfield {
|
||||
// Dibuixar totes les estrelles
|
||||
void draw();
|
||||
|
||||
// Setters per ajustar paràmetres en temps real
|
||||
void set_punt_fuga(const Vec2& punt) { punt_fuga_ = punt; }
|
||||
// Setters per ajustar paràmetres en time real
|
||||
void set_punt_fuga(const Vec2& point) { punt_fuga_ = point; }
|
||||
void set_brightness(float multiplier);
|
||||
|
||||
private:
|
||||
// Estructura interna per cada estrella
|
||||
struct Estrella {
|
||||
Vec2 posicio; // Posició actual
|
||||
Vec2 position; // Posició actual
|
||||
float angle; // Angle de moviment (radians)
|
||||
float distancia_centre; // Distància normalitzada del centre (0.0-1.0)
|
||||
int capa; // Índex de capa (0=lluny, 1=mitjà, 2=prop)
|
||||
@@ -59,7 +59,7 @@ class Starfield {
|
||||
// Verificar si una estrella està fora de l'àrea
|
||||
[[nodiscard]] bool fora_area(const Estrella& estrella) const;
|
||||
|
||||
// Calcular escala dinàmica segons distància del centre
|
||||
// Calcular scale dinàmica segons distància del centre
|
||||
[[nodiscard]] float calcular_escala(const Estrella& estrella) const;
|
||||
|
||||
// Calcular brightness dinàmica segons distància del centre
|
||||
@@ -76,7 +76,7 @@ class Starfield {
|
||||
SDL_FRect area_; // Àrea activa
|
||||
float radi_max_; // Distància màxima del centre al límit de pantalla
|
||||
int densitat_; // Nombre total d'estrelles
|
||||
float multiplicador_brightness_{1.0F}; // Multiplicador de brillantor (1.0 = default)
|
||||
float multiplicador_brightness_{1.0F}; // Multiplicador de brightness (1.0 = default)
|
||||
};
|
||||
|
||||
} // namespace Graphics
|
||||
|
||||
@@ -26,10 +26,10 @@ void VectorText::load_charset() {
|
||||
std::string filename = get_shape_filename(c);
|
||||
auto shape = ShapeLoader::load(filename);
|
||||
|
||||
if (shape && shape->es_valida()) {
|
||||
if (shape && shape->isValid()) {
|
||||
chars_[c] = shape;
|
||||
} else {
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut load " << filename
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
@@ -39,10 +39,10 @@ void VectorText::load_charset() {
|
||||
std::string filename = get_shape_filename(c);
|
||||
auto shape = ShapeLoader::load(filename);
|
||||
|
||||
if (shape && shape->es_valida()) {
|
||||
if (shape && shape->isValid()) {
|
||||
chars_[c] = shape;
|
||||
} else {
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut load " << filename
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
@@ -54,10 +54,10 @@ void VectorText::load_charset() {
|
||||
std::string filename = get_shape_filename(c);
|
||||
auto shape = ShapeLoader::load(filename);
|
||||
|
||||
if (shape && shape->es_valida()) {
|
||||
if (shape && shape->isValid()) {
|
||||
chars_[c] = shape;
|
||||
} else {
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut load " << filename
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
@@ -69,10 +69,10 @@ void VectorText::load_charset() {
|
||||
std::string filename = "font/char_copyright.shp";
|
||||
auto shape = ShapeLoader::load(filename);
|
||||
|
||||
if (shape && shape->es_valida()) {
|
||||
if (shape && shape->isValid()) {
|
||||
chars_[c] = shape;
|
||||
} else {
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut carregar " << filename
|
||||
std::cerr << "[VectorText] Warning: no s'ha pogut load " << filename
|
||||
<< '\n';
|
||||
}
|
||||
}
|
||||
@@ -168,7 +168,7 @@ std::string VectorText::get_shape_filename(char c) const {
|
||||
case '?':
|
||||
return "font/char_question.shp";
|
||||
case ' ':
|
||||
return ""; // Espai es maneja sense carregar shape
|
||||
return ""; // Espai es maneja sense load shape
|
||||
|
||||
case '\xA9': // Copyright symbol (©) - UTF-8 U+00A9
|
||||
return "font/char_copyright.shp";
|
||||
@@ -182,23 +182,23 @@ bool VectorText::is_supported(char c) const {
|
||||
return chars_.contains(c);
|
||||
}
|
||||
|
||||
void VectorText::render(const std::string& text, const Vec2& posicio, float escala, float spacing, float brightness) const {
|
||||
void VectorText::render(const std::string& text, const Vec2& position, float scale, float spacing, float brightness) const {
|
||||
if (renderer_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ancho de un carácter base (20 px a escala 1.0)
|
||||
const float char_width_scaled = char_width * escala;
|
||||
// Ancho de un carácter base (20 px a scale 1.0)
|
||||
const float char_width_scaled = char_width * scale;
|
||||
|
||||
// Spacing escalado
|
||||
const float spacing_scaled = spacing * escala;
|
||||
const float spacing_scaled = spacing * scale;
|
||||
|
||||
// Altura de un carácter escalado (necesario para ajustar Y)
|
||||
const float char_height_scaled = char_height * escala;
|
||||
const float char_height_scaled = char_height * scale;
|
||||
|
||||
// Posición X del borde izquierdo del carácter actual
|
||||
// (se ajustará +char_width/2 para obtener el centro al renderizar)
|
||||
float current_x = posicio.x;
|
||||
float current_x = position.x;
|
||||
|
||||
// Iterar sobre cada byte del string (con detecció UTF-8)
|
||||
for (size_t i = 0; i < text.length(); i++) {
|
||||
@@ -221,10 +221,10 @@ void VectorText::render(const std::string& text, const Vec2& posicio, float esca
|
||||
auto it = chars_.find(c);
|
||||
if (it != chars_.end()) {
|
||||
// Renderizar carácter
|
||||
// Ajustar X e Y para que posicio represente esquina superior izquierda
|
||||
// Ajustar X e Y para que position represente esquina superior izquierda
|
||||
// (render_shape espera el centro, así que sumamos la mitad de ancho y altura)
|
||||
Vec2 char_pos = {.x = current_x + (char_width_scaled / 2.0F), .y = posicio.y + (char_height_scaled / 2.0F)};
|
||||
Rendering::render_shape(renderer_, it->second, char_pos, 0.0F, escala, 1.0F, brightness);
|
||||
Vec2 char_pos = {.x = current_x + (char_width_scaled / 2.0F), .y = position.y + (char_height_scaled / 2.0F)};
|
||||
Rendering::render_shape(renderer_, it->second, char_pos, 0.0F, scale, 1.0F, brightness);
|
||||
|
||||
// Avanzar posición
|
||||
current_x += char_width_scaled + spacing_scaled;
|
||||
@@ -237,28 +237,28 @@ void VectorText::render(const std::string& text, const Vec2& posicio, float esca
|
||||
}
|
||||
}
|
||||
|
||||
void VectorText::render_centered(const std::string& text, const Vec2& centre_punt, float escala, float spacing, float brightness) const {
|
||||
void VectorText::renderCentered(const std::string& text, const Vec2& centre_punt, float scale, float spacing, float brightness) const {
|
||||
// Calcular dimensions del text
|
||||
float text_width = get_text_width(text, escala, spacing);
|
||||
float text_height = get_text_height(escala);
|
||||
float text_width = get_text_width(text, scale, spacing);
|
||||
float text_height = get_text_height(scale);
|
||||
|
||||
// Calcular posició de l'esquina superior esquerra
|
||||
// restant la meitat de les dimensions del punt central
|
||||
// restant la meitat de les dimensions del point central
|
||||
Vec2 posicio_esquerra = {
|
||||
.x = centre_punt.x - (text_width / 2.0F),
|
||||
.y = centre_punt.y - (text_height / 2.0F)};
|
||||
|
||||
// Delegar al mètode render() existent
|
||||
render(text, posicio_esquerra, escala, spacing, brightness);
|
||||
render(text, posicio_esquerra, scale, spacing, brightness);
|
||||
}
|
||||
|
||||
float VectorText::get_text_width(const std::string& text, float escala, float spacing) const {
|
||||
float VectorText::get_text_width(const std::string& text, float scale, float spacing) const {
|
||||
if (text.empty()) {
|
||||
return 0.0F;
|
||||
}
|
||||
|
||||
const float char_width_scaled = char_width * escala;
|
||||
const float spacing_scaled = spacing * escala;
|
||||
const float char_width_scaled = char_width * scale;
|
||||
const float spacing_scaled = spacing * scale;
|
||||
|
||||
// Contar caracteres visuals (no bytes) - manejar UTF-8
|
||||
size_t visual_chars = 0;
|
||||
@@ -279,8 +279,8 @@ float VectorText::get_text_width(const std::string& text, float escala, float sp
|
||||
return (visual_chars * char_width_scaled) + ((visual_chars - 1) * spacing_scaled);
|
||||
}
|
||||
|
||||
float VectorText::get_text_height(float escala) const {
|
||||
return char_height * escala;
|
||||
float VectorText::get_text_height(float scale) const {
|
||||
return char_height * scale;
|
||||
}
|
||||
|
||||
} // namespace Graphics
|
||||
|
||||
@@ -21,25 +21,25 @@ class VectorText {
|
||||
// Renderizar string completo
|
||||
// - text: cadena a renderizar (soporta: A-Z, a-z, 0-9, '.', ',', '-', ':',
|
||||
// '!', '?', ' ')
|
||||
// - posicio: posición inicial (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(const std::string& text, const Vec2& posicio, float escala = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const;
|
||||
// - position: posición inicial (esquina superior izquierda)
|
||||
// - scale: factor de scale (1.0 = 20×40 px por carácter)
|
||||
// - spacing: espacio entre caracteres en píxeles (a scale 1.0)
|
||||
// - brightness: factor de brightness (0.0-1.0, default 1.0 = màxima brightness)
|
||||
void render(const std::string& text, const Vec2& position, float scale = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const;
|
||||
|
||||
// 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 Vec2& centre_punt, float escala = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const;
|
||||
// - scale: factor de scale (1.0 = 20×40 px por carácter)
|
||||
// - spacing: espacio entre caracteres en píxeles (a scale 1.0)
|
||||
// - brightness: factor de brightness (0.0-1.0, default 1.0 = màxima brightness)
|
||||
void renderCentered(const std::string& text, const Vec2& centre_punt, float scale = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const;
|
||||
|
||||
// Calcular ancho total de un string (útil para centrado)
|
||||
[[nodiscard]] float get_text_width(const std::string& text, float escala = 1.0F, float spacing = 2.0F) const;
|
||||
[[nodiscard]] float get_text_width(const std::string& text, float scale = 1.0F, float spacing = 2.0F) const;
|
||||
|
||||
// Calcular altura del texto (útil para centrado vertical)
|
||||
[[nodiscard]] float get_text_height(float escala = 1.0F) const;
|
||||
[[nodiscard]] float get_text_height(float scale = 1.0F) const;
|
||||
|
||||
// Verificar si un carácter está soportado
|
||||
[[nodiscard]] bool is_supported(char c) const;
|
||||
|
||||
Reference in New Issue
Block a user