Font 8bithud, classe Text i overlay RenderInfo (F3, persistit a config.yaml) (v0.7.0)

This commit is contained in:
JailDesigner committed 2026-04-19 00:31:02 +02:00
1 parent ce5bec1b34
commit e6f3c888e6
19 files changed
+712 -6

No files matched your search

+30
View File
@@ -113,3 +113,33 @@ void Surface::render(int x, int y, const SDL_FRect* src_rect, SDL_FlipMode flip)
}
}
}
void Surface::renderWithColorReplace(int x, int y, Uint8 source_color, Uint8 target_color, const SDL_FRect* src_rect, SDL_FlipMode flip) const {
Uint32* dst = Screen::get().getCanvasArgb();
const int DST_W = Screen::get().getCanvasWidth();
const int DST_H = Screen::get().getCanvasHeight();
const int SX = (src_rect != nullptr) ? static_cast<int>(src_rect->x) : 0;
const int SY = (src_rect != nullptr) ? static_cast<int>(src_rect->y) : 0;
int sw = (src_rect != nullptr) ? static_cast<int>(src_rect->w) : surface_data_->width;
int sh = (src_rect != nullptr) ? static_cast<int>(src_rect->h) : surface_data_->height;
sw = std::min(sw, surface_data_->width - SX);
sh = std::min(sh, surface_data_->height - SY);
const Uint8* src = surface_data_->data.get();
for (int iy = 0; iy < sh; ++iy) {
for (int ix = 0; ix < sw; ++ix) {
const int SRC_X = (flip == SDL_FLIP_HORIZONTAL) ? (SX + sw - 1 - ix) : (SX + ix);
const int SRC_Y = (flip == SDL_FLIP_VERTICAL) ? (SY + sh - 1 - iy) : (SY + iy);
const int DST_X = x + ix;
const int DST_Y = y + iy;
if (DST_X < 0 || DST_X >= DST_W || DST_Y < 0 || DST_Y >= DST_H) { continue; }
const Uint8 COLOR = src[SRC_X + (SRC_Y * surface_data_->width)];
if (COLOR == transparent_color_) { continue; }
const Uint8 REMAPPED = (COLOR == source_color) ? target_color : sub_palette_[COLOR];
dst[DST_X + (DST_Y * DST_W)] = palette_[REMAPPED];
}
}
}