diff --git a/Examples/SpriteHandler_examples.h b/Examples/SpriteHandler_examples.h index 9caa0c3..47b1633 100644 --- a/Examples/SpriteHandler_examples.h +++ b/Examples/SpriteHandler_examples.h @@ -16,7 +16,6 @@ namespace sprite_handler void example1() { ScreenHandler<20, 40> sh; - Text tt; SpriteHandler sprh; keyboard::KeyPressData kpd; auto keyboard = std::make_unique(); @@ -184,7 +183,7 @@ namespace sprite_handler return_cursor(); sh.clear(); sprh.draw(sh, anim_frame); - sh.print_screen_buffer(tt, Color::Black); + sh.print_screen_buffer(Color::Black); Delay::sleep(0'200'000); kpd = keyboard->readKey(); @@ -196,7 +195,7 @@ namespace sprite_handler } quit: - end_screen(sh, tt); + end_screen(sh); } } diff --git a/GameEngine.h b/GameEngine.h index 493123c..2d6ae4d 100644 --- a/GameEngine.h +++ b/GameEngine.h @@ -146,7 +146,6 @@ class GameEngine std::chrono::time_point real_start_time_s; OneShot time_inited; - Text t; ScreenHandler sh; Color bg_color = Color::Default; @@ -261,7 +260,7 @@ class GameEngine private: void pre_quit() { - end_screen(sh, t); + end_screen(sh); if (m_params.enable_terminal_window_resize) if (term_win_rows > 0 && term_win_cols > 0) resize_terminal_window(term_win_rows, term_win_cols); @@ -445,7 +444,7 @@ class GameEngine update(); } - sh.print_screen_buffer(t, bg_color); + sh.print_screen_buffer(bg_color); //sh.print_screen_buffer_chars(); //sh.print_screen_buffer_fg_colors(); //sh.print_screen_buffer_bg_colors(); diff --git a/ScreenHandler.h b/ScreenHandler.h index b8710d4..098eb17 100644 --- a/ScreenHandler.h +++ b/ScreenHandler.h @@ -39,6 +39,8 @@ RGBA clamp(const RGBA& t) { return RGBA { math::clamp(t.r, 0., 1.), math::clamp( template class ScreenHandler { + std::unique_ptr m_text; + // Draw from top to bottom. std::array, NR> screen_buffer; std::array, NR> fg_color_buffer; @@ -75,6 +77,10 @@ class ScreenHandler std::vector ordered_texts; public: + ScreenHandler() + : m_text(std::make_unique()) + {} + void clear() { for (auto& row : screen_buffer) @@ -269,7 +275,7 @@ class ScreenHandler } } - void print_screen_buffer(Text& t, Color bg_color) const + void print_screen_buffer(Color bg_color) const { std::vector> colored_str; colored_str.resize(NR*(NC + 1)); @@ -285,7 +291,7 @@ class ScreenHandler } colored_str[i++] = { '\n', Color::Default, Color::Default }; } - t.print_complex(colored_str); + m_text->print_complex(colored_str); } void print_screen_buffer_chars() const diff --git a/ScreenUtils.h b/ScreenUtils.h index 6995022..76f0f89 100644 --- a/ScreenUtils.h +++ b/ScreenUtils.h @@ -232,14 +232,14 @@ void begin_screen() } template -void end_screen(ScreenHandler& sh, Text& t) +void end_screen(ScreenHandler& sh) { auto orig_colors [[maybe_unused]] = restore_terminal_colors(); #ifndef __APPLE__ sh.clear(); sh.replace_fg_color(orig_colors.fg_color); sh.replace_bg_color(orig_colors.bg_color); - sh.print_screen_buffer(t, orig_colors.bg_color); + sh.print_screen_buffer(orig_colors.bg_color); #endif restore_cursor(); show_cursor();