refactor: fase 3 — Text::bitmap_ a std::vector<Uint8>
- bitmap_: Uint8* (owning, free'd al destructor) → std::vector<Uint8> - loadBitmap copia des del buffer de LoadGif i fa free(pixels) de l'intermedi (gif.h usa malloc internament) - ~Text() eliminat: regla 0 aplicada (vector es destrueix sol) - Les 4 comprovacions !bitmap_ → bitmap_.empty() Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -19,10 +19,6 @@ Text::Text(const char* fnt_file, const char* gif_file) {
|
||||
loadFont(fnt_file);
|
||||
}
|
||||
|
||||
Text::~Text() {
|
||||
if (bitmap_) free(bitmap_);
|
||||
}
|
||||
|
||||
// --- UTF-8 ---
|
||||
|
||||
auto Text::nextCodepoint(const char*& ptr) -> uint32_t {
|
||||
@@ -146,7 +142,8 @@ void Text::loadBitmap(const char* gif_file) {
|
||||
|
||||
bitmap_width_ = w;
|
||||
bitmap_height_ = h;
|
||||
bitmap_ = pixels;
|
||||
bitmap_.assign(pixels, pixels + (static_cast<size_t>(w) * h));
|
||||
free(pixels); // LoadGif usa malloc internament
|
||||
|
||||
std::cout << "Text: bitmap loaded " << w << "x" << h << '\n';
|
||||
}
|
||||
@@ -154,7 +151,7 @@ void Text::loadBitmap(const char* gif_file) {
|
||||
// --- Renderitzat ---
|
||||
|
||||
void Text::draw(Uint32* pixel_data, int x, int y, const char* text, Uint32 color) const {
|
||||
if (!bitmap_ || !pixel_data) return;
|
||||
if (bitmap_.empty() || !pixel_data) return;
|
||||
|
||||
const char* ptr = text;
|
||||
int cursor_x = x;
|
||||
@@ -207,7 +204,7 @@ void Text::drawCentered(Uint32* pixel_data, int y, const char* text, Uint32 colo
|
||||
}
|
||||
|
||||
void Text::drawClipped(Uint32* pixel_data, int x, int y, const char* text, Uint32 color, int clip_x_min, int clip_x_max, int clip_y_min, int clip_y_max) const {
|
||||
if (!bitmap_ || !pixel_data) return;
|
||||
if (bitmap_.empty() || !pixel_data) return;
|
||||
|
||||
// Descart ràpid si el glifo sencer cau fora verticalment
|
||||
if (y + box_height_ <= clip_y_min || y >= clip_y_max) return;
|
||||
@@ -262,7 +259,7 @@ void Text::drawClipped(Uint32* pixel_data, int x, int y, const char* text, Uint3
|
||||
}
|
||||
|
||||
void Text::drawMono(Uint32* pixel_data, int x, int y, const char* text, Uint32 color, int cell_w) const {
|
||||
if (!bitmap_ || !pixel_data) return;
|
||||
if (bitmap_.empty() || !pixel_data) return;
|
||||
|
||||
const char* ptr = text;
|
||||
int cursor_x = x;
|
||||
@@ -308,7 +305,7 @@ void Text::drawMono(Uint32* pixel_data, int x, int y, const char* text, Uint32 c
|
||||
}
|
||||
|
||||
void Text::drawMonoDigits(Uint32* pixel_data, int x, int y, const char* text, Uint32 color, int digit_cell_w) const {
|
||||
if (!bitmap_ || !pixel_data) return;
|
||||
if (bitmap_.empty() || !pixel_data) return;
|
||||
|
||||
const char* ptr = text;
|
||||
int cursor_x = x;
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
class Text {
|
||||
public:
|
||||
Text(const char* fnt_file, const char* gif_file);
|
||||
~Text();
|
||||
|
||||
// Pinta texto sobre un buffer ARGB de 320x200
|
||||
void draw(Uint32* pixel_data, int x, int y, const char* text, Uint32 color) const;
|
||||
@@ -46,7 +46,7 @@ class Text {
|
||||
int cell_spacing_{0};
|
||||
int row_spacing_{0};
|
||||
|
||||
Uint8* bitmap_{nullptr}; // píxels 8-bit del GIF de la font
|
||||
std::vector<Uint8> bitmap_; // píxels 8-bit del GIF de la font
|
||||
int bitmap_width_{0};
|
||||
int bitmap_height_{0};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user