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.

main
Zed A. Shaw 1 month ago
parent fe5f7673ea
commit 08d71f9bdc
  1. 48
      gui.cpp

@ -14,6 +14,7 @@
#include <SFML/Window.hpp> #include <SFML/Window.hpp>
#include <SFML/System.hpp> #include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <fmt/core.h> #include <fmt/core.h>
#include "dbc.hpp" #include "dbc.hpp"
@ -148,9 +149,42 @@ void GUI::burn() {
void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) { void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) {
if(clear) $window.clear(); 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); $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(); $window.display();
} }
@ -198,20 +232,13 @@ void GUI::render_scene() {
Render($map_screen, $map_view->Render()); Render($map_screen, $map_view->Render());
Render($screen, $document->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(); draw_screen();
} }
int GUI::main() { int GUI::main() {
configure_world(); configure_world();
create_renderer(); create_renderer();
run_systems();
while($window.isOpen()) { while($window.isOpen()) {
render_scene(); render_scene();
@ -219,7 +246,6 @@ int GUI::main() {
if(handle_events()) { if(handle_events()) {
run_systems(); run_systems();
} }
std::this_thread::sleep_for(10ms); std::this_thread::sleep_for(10ms);
} }

Loading…
Cancel
Save