feat(menu): primera versió del menú de servei
This commit is contained in:
1 parent
e4a8b4cd3e
commit
350625dec0
21 files changed
+1477
-16
No files matched your search
@@ -220,17 +220,61 @@ void Screen::clear(std::uint8_t r, std::uint8_t g, std::uint8_t b) {
|
||||
}
|
||||
|
||||
void Screen::fillRect(int x, int y, int w, int h, std::uint32_t argb) {
|
||||
const int X0 = std::max(x, 0);
|
||||
const int Y0 = std::max(y, 0);
|
||||
const int X1 = std::min(x + w, canvas_width_);
|
||||
const int Y1 = std::min(y + h, canvas_height_);
|
||||
const auto CLIP = Rendering::activeClip();
|
||||
const int X0 = std::max(x, CLIP.x);
|
||||
const int Y0 = std::max(y, CLIP.y);
|
||||
const int X1 = std::min(x + w, CLIP.x + CLIP.w);
|
||||
const int Y1 = std::min(y + h, CLIP.y + CLIP.h);
|
||||
for (int iy = Y0; iy < Y1; ++iy) {
|
||||
std::uint32_t* row = canvas_.data() + (static_cast<std::ptrdiff_t>(iy) * canvas_width_);
|
||||
std::fill(row + X0, row + X1, argb);
|
||||
}
|
||||
}
|
||||
|
||||
void Screen::blendRect(int x, int y, int w, int h, std::uint32_t argb, std::uint8_t alpha) {
|
||||
if (alpha == 0) { return; }
|
||||
if (alpha == 0xFF) {
|
||||
fillRect(x, y, w, h, argb);
|
||||
return;
|
||||
}
|
||||
// Mescla linealment src (argb, alpha) sobre dst (el canvas). El canvas
|
||||
// és ARGB amb R/G/B als bytes baixos i A fix a 0xFF; fem la mescla per
|
||||
// canal i deixem A intacte perquè el backend espera opacitat total.
|
||||
const std::uint8_t SA = alpha;
|
||||
const std::uint8_t INV = 255 - alpha;
|
||||
const std::uint8_t SR = (argb >> 16) & 0xFF;
|
||||
const std::uint8_t SG = (argb >> 8) & 0xFF;
|
||||
const std::uint8_t SB = argb & 0xFF;
|
||||
const auto CLIP = Rendering::activeClip();
|
||||
const int X0 = std::max(x, CLIP.x);
|
||||
const int Y0 = std::max(y, CLIP.y);
|
||||
const int X1 = std::min(x + w, CLIP.x + CLIP.w);
|
||||
const int Y1 = std::min(y + h, CLIP.y + CLIP.h);
|
||||
for (int iy = Y0; iy < Y1; ++iy) {
|
||||
std::uint32_t* row = canvas_.data() + (static_cast<std::ptrdiff_t>(iy) * canvas_width_);
|
||||
for (int ix = X0; ix < X1; ++ix) {
|
||||
const std::uint32_t DST = row[ix];
|
||||
const std::uint8_t DR = (DST >> 16) & 0xFF;
|
||||
const std::uint8_t DG = (DST >> 8) & 0xFF;
|
||||
const std::uint8_t DB = DST & 0xFF;
|
||||
const std::uint8_t R = ((SR * SA) + (DR * INV)) / 255;
|
||||
const std::uint8_t G = ((SG * SA) + (DG * INV)) / 255;
|
||||
const std::uint8_t B = ((SB * SA) + (DB * INV)) / 255;
|
||||
row[ix] = 0xFF000000U | (static_cast<std::uint32_t>(R) << 16) | (static_cast<std::uint32_t>(G) << 8) | static_cast<std::uint32_t>(B);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Screen::setOverlayRenderer(std::function<void()> callback) {
|
||||
overlay_renderer_ = std::move(callback);
|
||||
}
|
||||
|
||||
void Screen::present() {
|
||||
// Overlays (menú de servei, etc.) s'han de pintar al canvas ABANS que
|
||||
// shader_backend llegisca els píxels per pujar-los a GPU; si no, queden
|
||||
// per sota del postprocés o no apareixen al frame presentat.
|
||||
if (overlay_renderer_) { overlay_renderer_(); }
|
||||
|
||||
fps_.increment();
|
||||
fps_.calculate(SDL_GetTicks());
|
||||
|
||||
|
||||
Reference in new issue
Block a user