- afegida carpeta release

- jitter en renderInfo
This commit is contained in:
2026-04-05 09:39:05 +02:00
parent 3aa6078054
commit c0553c6d37
104 changed files with 78786 additions and 63 deletions

View File

@@ -266,6 +266,137 @@ 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;
const char* ptr = text;
int cursor_x = x;
while (*ptr) {
uint32_t cp = nextCodepoint(ptr);
if (cp == 0) break;
auto it = glyphs_.find(cp);
if (it == glyphs_.end()) {
it = glyphs_.find('?');
if (it == glyphs_.end()) {
cursor_x += cell_w;
continue;
}
}
const auto& glyph = it->second;
// Centra el glif dins la cel·la
int glyph_x = cursor_x + (cell_w - glyph.w) / 2;
for (int gy = 0; gy < box_height_; gy++) {
int dst_y = y + gy;
if (dst_y < 0 || dst_y >= SCREEN_HEIGHT) continue;
for (int gx = 0; gx < glyph.w; gx++) {
int dst_x = glyph_x + gx;
if (dst_x < 0 || dst_x >= SCREEN_WIDTH) continue;
int src_x = glyph.x + gx;
int src_y = glyph.y + gy;
if (src_x >= bitmap_width_ || src_y >= bitmap_height_) continue;
Uint8 pixel = bitmap_[src_x + src_y * bitmap_width_];
if (pixel != 0) {
pixel_data[dst_x + dst_y * SCREEN_WIDTH] = color;
}
}
}
cursor_x += cell_w;
}
}
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;
const char* ptr = text;
int cursor_x = x;
bool first = true;
while (*ptr) {
uint32_t cp = nextCodepoint(ptr);
if (cp == 0) break;
auto it = glyphs_.find(cp);
if (it == glyphs_.end()) {
it = glyphs_.find('?');
if (it == glyphs_.end()) {
if (!first) cursor_x += 1;
cursor_x += box_width_;
first = false;
continue;
}
}
const auto& glyph = it->second;
bool is_digit = (cp >= '0' && cp <= '9');
if (!first) cursor_x += 1; // kerning
int glyph_x = is_digit ? cursor_x + (digit_cell_w - glyph.w) / 2 : cursor_x;
for (int gy = 0; gy < box_height_; gy++) {
int dst_y = y + gy;
if (dst_y < 0 || dst_y >= SCREEN_HEIGHT) continue;
for (int gx = 0; gx < glyph.w; gx++) {
int dst_x = glyph_x + gx;
if (dst_x < 0 || dst_x >= SCREEN_WIDTH) continue;
int src_x = glyph.x + gx;
int src_y = glyph.y + gy;
if (src_x >= bitmap_width_ || src_y >= bitmap_height_) continue;
Uint8 pixel = bitmap_[src_x + src_y * bitmap_width_];
if (pixel != 0) {
pixel_data[dst_x + dst_y * SCREEN_WIDTH] = color;
}
}
}
cursor_x += is_digit ? digit_cell_w : glyph.w;
first = false;
}
}
auto Text::widthMonoDigits(const char* text, int digit_cell_w) const -> int {
const char* ptr = text;
int w = 0;
bool first = true;
while (*ptr) {
uint32_t cp = nextCodepoint(ptr);
if (cp == 0) break;
if (!first) w += 1; // kerning
first = false;
bool is_digit = (cp >= '0' && cp <= '9');
if (is_digit) {
w += digit_cell_w;
} else {
auto it = glyphs_.find(cp);
if (it == glyphs_.end()) it = glyphs_.find('?');
if (it != glyphs_.end())
w += it->second.w;
else
w += box_width_;
}
}
return w;
}
auto Text::widthMono(const char* text, int cell_w) const -> int {
const char* ptr = text;
int count = 0;
while (*ptr) {
uint32_t cp = nextCodepoint(ptr);
if (cp == 0) break;
count++;
}
return count * cell_w;
}
auto Text::width(const char* text) const -> int {
const char* ptr = text;
int w = 0;