From 8514bd87ecb25def553b1474a8633229e47c516d Mon Sep 17 00:00:00 2001 From: Rasmus Anthin Date: Wed, 20 Nov 2024 13:23:32 +0100 Subject: [PATCH] ScreenHandler.h: * Now added a separate overload to print_screen_buffer() that takes a OffscreenBuffer object as a reference argument and outputs to that instead. Very useful for reflection effects and stuff like that. See Christmas_Demo for example of usage. --- ScreenHandler.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/ScreenHandler.h b/ScreenHandler.h index f4867f4..73daa6b 100644 --- a/ScreenHandler.h +++ b/ScreenHandler.h @@ -307,6 +307,45 @@ class ScreenHandler } m_text->print_complex(colored_str); } + + void print_screen_buffer(Color bg_color, const OffscreenBuffer& offscreen_buffer) + { + auto* texture = offscreen_buffer.buffer_texture; + if (texture == nullptr) + return; + + auto pos = offscreen_buffer.buffer_screen_pos; + + for (int r = 0; r < NR; ++r) + { + auto rl = r - pos.r; + for (int c = 0; c < NC; ++c) + { + auto cl = c - pos.c; + + auto textel = texture->operator()(rl, cl); + if (!stlutils::contains(offscreen_buffer.dst_fill_bg_colors, textel.bg_color)) + continue; + + textel.ch = screen_buffer[r][c]; + textel.fg_color = fg_color_buffer[r][c]; + textel.bg_color = bg_color_buffer[r][c]; + + if (stlutils::contains(offscreen_buffer.exclude_src_chars, textel.ch)) + continue; + if (stlutils::contains(offscreen_buffer.exclude_src_fg_colors, textel.fg_color)) + continue; + if (stlutils::contains(offscreen_buffer.exclude_src_bg_colors, textel.bg_color)) + continue; + + for (const auto& rp : offscreen_buffer.replace_src_dst_bg_colors) + if (textel.bg_color == rp.first) + textel.bg_color = rp.second; + + texture->set_textel(rl, cl, textel); + } + } + } void print_screen_buffer_chars() const {