From 08d71f9bdceb1ce99906c9b7b7a6f1eee0e401c0 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Fri, 18 Oct 2024 16:00:13 -0400 Subject: [PATCH] Super duper slow but this renders the text glyphs directly as sprites so I can do special colorization. Probalby then need to process the ftxui color ansi codes. --- gui.cpp | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/gui.cpp b/gui.cpp index fba98a0..334900b 100644 --- a/gui.cpp +++ b/gui.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include "dbc.hpp" @@ -148,9 +149,42 @@ void GUI::burn() { void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) { if(clear) $window.clear(); + std::string screenout = $screen.ToString(); + std::string map_screenout = $map_screen.ToString(); + std::wstring main_screen_utf8 = $converter.from_bytes(screenout); + $ui_text.setString(main_screen_utf8); $window.draw($ui_text); - $map_text.setPosition(GAME_MAP_POS+map_off_x, map_off_y); - $window.draw($map_text); + + std::wstring map_screen_utf8 = $converter.from_bytes(map_screenout); + $map_text.setString(map_screen_utf8); + + sf::Texture ftext = $font.getTexture(MAP_FONT_SIZE); + + for(size_t i = 0; i < map_screen_utf8.size(); i++) { + wchar_t tile = map_screen_utf8[i]; + sf::Glyph glyph = $font.getGlyph(tile, MAP_FONT_SIZE, false); + sf::Sprite sprite(ftext); + sprite.setTextureRect(glyph.textureRect); + auto pos = $map_text.findCharacterPos(i); + sprite.setPosition(pos); + if(tile == L'█') { + sprite.setColor(sf::Color(100,100,100)); + } else if(tile == L'☺') { + sprite.setColor(sf::Color::Blue); + } else if(tile == L'Ω') { + sprite.setColor(sf::Color::Red); + } else if(tile == L'·') { + sprite.setColor(color(Value::DARK_MID)); + } else if(tile == L'\n' || tile == L'\r') { + // skip newlines + continue; + } else { + sprite.setColor(color(Value::MID)); + } + + $window.draw(sprite); + } + $window.display(); } @@ -198,20 +232,13 @@ void GUI::render_scene() { Render($map_screen, $map_view->Render()); Render($screen, $document->Render()); - std::string $screenout = $screen.ToString(); - std::wstring main_screen_utf8 = $converter.from_bytes($screenout); - $ui_text.setString(main_screen_utf8); - - std::string $map_screenout = $map_screen.ToString(); - std::wstring map_screen_utf8 = $converter.from_bytes($map_screenout); - $map_text.setString(map_screen_utf8); - draw_screen(); } int GUI::main() { configure_world(); create_renderer(); + run_systems(); while($window.isOpen()) { render_scene(); @@ -219,7 +246,6 @@ int GUI::main() { if(handle_events()) { run_systems(); } - std::this_thread::sleep_for(10ms); }