Did a full code review to identify things to fix and either fixed them or noted BUG where I should come back.

This commit is contained in:
Zed A. Shaw 2024-12-04 21:43:59 -05:00
parent ae43dad499
commit 9abb39a3bf
14 changed files with 72 additions and 35 deletions

View file

@ -6,6 +6,7 @@
#include "map.hpp"
#include <iostream>
#include "color.hpp"
#if defined(_WIN64) || defined(_WIN32)
#include <stdio.h>
#include <fcntl.h>
@ -65,7 +66,8 @@ void SFMLRender::resize_grid(int new_size, Panel &panel_out) {
panel_out.resize(view_x, view_y);
}
inline void configure_tile(const sf::Sprite &sprite, sf::FloatRect &sp_bounds, sf::FloatRect bg_bounds, float &width_delta, float &height_delta) {
inline void configure_tile(const sf::Sprite &sprite, sf::FloatRect &sp_bounds, sf::FloatRect bg_bounds, float &width_delta, float &height_delta) {
// BUG: I think I could create a struct that kept this info for all sprites loaded
// should look into caching all this instead of calcing it each time
sp_bounds = sprite.getLocalBounds();
@ -75,7 +77,7 @@ inline void configure_tile(const sf::Sprite &sprite, sf::FloatRect &sp_bounds,
}
void SFMLRender::render_grid(const std::wstring &text, sf::Color default_fg, sf::Color default_bg, float x, float y) {
wchar_t last_tile = '#';
wchar_t last_tile = $config.bg_tile;
sf::FloatRect sp_bounds;
float width_delta = 0;
float height_delta = 0;
@ -86,7 +88,7 @@ void SFMLRender::render_grid(const std::wstring &text, sf::Color default_fg, sf:
sf::Color cur_bg = default_bg;
// make a copy so we don't modify the cached one
$ansi.parse(text, [&](sf::Color fg, sf::Color bg) {
$ansi.parse(text, [&](auto fg, auto bg) {
cur_fg = fg;
cur_bg = bg;
},
@ -104,9 +106,9 @@ void SFMLRender::render_grid(const std::wstring &text, sf::Color default_fg, sf:
// only get a new sprite if the tile changed
if(last_tile != tile) {
last_tile = tile; // update last tile seen
sprite = get_text_sprite(tile);
configure_tile(sprite, sp_bounds, $bg_bounds, width_delta, height_delta);
last_tile = tile; // update last tile seen
}
sprite.setPosition({x+width_delta, y+height_delta});
@ -135,6 +137,7 @@ inline sf::FloatRect draw_chunk(sf::RenderWindow& window,
text.setPosition({x, y});
// get a base character for the cell size
sf::FloatRect bounds(x, y, ui_bounds.width * out.size(), ui_bounds.height);
if(default_bg != bgcolor) {
sf::RectangleShape backing({bounds.width, bounds.height});
backing.setFillColor(bgcolor);
@ -157,7 +160,7 @@ void SFMLRender::render_text(const std::wstring &text, sf::Color default_fg, sf:
$ui_text.setFillColor(default_fg);
$ansi.parse(text,
[&](sf::Color fg, sf::Color bg) {
[&](auto fg, auto bg) {
if(out.size() > 0 ) {
auto bounds = draw_chunk($window,
$ui_bounds, $ui_text,
@ -232,6 +235,5 @@ void SFMLRender::init_terminal() {
_setmode(_fileno(stdout), _O_U16TEXT);
#endif
// the parser only handles full color so force it
ftxui::Terminal::SetColorSupport(ftxui::Terminal::Color::TrueColor);
}