From df755c6fd26ad9f8ef0fe86bc95c3c9b7137fdb5 Mon Sep 17 00:00:00 2001 From: Rasmus Anthin Date: Tue, 3 Dec 2024 18:48:53 +0100 Subject: [PATCH] SpriteHandler.h: * Added private function BitmapSprite::fill_sprite_data() to be used later. --- SpriteHandler.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/SpriteHandler.h b/SpriteHandler.h index 53db098..77b9761 100644 --- a/SpriteHandler.h +++ b/SpriteHandler.h @@ -101,6 +101,32 @@ class BitmapSprite : public Sprite return true; } + + template + void fill_sprite_data(std::vector& target, const ttl::Rectangle& bb, T arg) + { + int nr = std::min(bb.r_len, size.r); + int nc = std::min(bb.c_len, size.c); + + auto N_trg = target.size(); + + for (int i = 0; i < nr; ++i) + { + for (int j = 0; j < nc; ++j) + { + // Map bounding box (i, j) to the target sprite data + int trg_row = bb.r + i; + int trg_col = bb.c + j; + + // Calculate linear index into the target vector and src_data + int trg_index = trg_row * size.c + trg_col; + + // Assign data to the target vector + if (trg_index < N_trg) + target[trg_index] = arg; + } + } + } RC size { 0, 0 }; int area = 0;