|
|
@ -69,19 +69,21 @@ inline void configure_tile(const sf::Sprite &sprite, sf::FloatRect &sp_bounds, |
|
|
|
height_delta = bg_bounds.height > sp_bounds.width ? (bg_bounds.height - sp_bounds.height) / 2 : 0; |
|
|
|
height_delta = bg_bounds.height > sp_bounds.width ? (bg_bounds.height - sp_bounds.height) / 2 : 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SFMLRender::render_grid(const std::wstring &text, float x, float y) { |
|
|
|
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 = '#'; |
|
|
|
sf::FloatRect sp_bounds; |
|
|
|
sf::FloatRect sp_bounds; |
|
|
|
float width_delta = 0; |
|
|
|
float width_delta = 0; |
|
|
|
float height_delta = 0; |
|
|
|
float height_delta = 0; |
|
|
|
sf::Sprite &sprite = get_text_sprite(last_tile); |
|
|
|
sf::Sprite &sprite = get_text_sprite(last_tile); |
|
|
|
const float start_x = x; |
|
|
|
const float start_x = x; |
|
|
|
sf::Color cur_fg = $default_fg; |
|
|
|
// BUG: get default_fg from panel too
|
|
|
|
|
|
|
|
sf::Color cur_fg = default_fg; |
|
|
|
|
|
|
|
sf::Color cur_bg = default_bg; |
|
|
|
|
|
|
|
|
|
|
|
// make a copy so we don't modify the cached one
|
|
|
|
// make a copy so we don't modify the cached one
|
|
|
|
$ansi.parse(text, [&](sf::Color fg, sf::Color bg) { |
|
|
|
$ansi.parse(text, [&](sf::Color fg, sf::Color bg) { |
|
|
|
cur_fg = fg; |
|
|
|
cur_fg = fg; |
|
|
|
$bg_sprite.setColor(bg); |
|
|
|
cur_bg = bg; |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
[&](wchar_t tile) { |
|
|
|
[&](wchar_t tile) { |
|
|
@ -94,7 +96,6 @@ void SFMLRender::render_grid(const std::wstring &text, float x, float y) { |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: { |
|
|
|
default: { |
|
|
|
$bg_sprite.setPosition({x, y}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// only get a new sprite if the tile changed
|
|
|
|
// only get a new sprite if the tile changed
|
|
|
|
if(last_tile != tile) { |
|
|
|
if(last_tile != tile) { |
|
|
@ -106,7 +107,13 @@ void SFMLRender::render_grid(const std::wstring &text, float x, float y) { |
|
|
|
sprite.setPosition({x+width_delta, y+height_delta}); |
|
|
|
sprite.setPosition({x+width_delta, y+height_delta}); |
|
|
|
sprite.setColor(cur_fg); |
|
|
|
sprite.setColor(cur_fg); |
|
|
|
|
|
|
|
|
|
|
|
$window.draw($bg_sprite); |
|
|
|
// only draw background char if it's different from default
|
|
|
|
|
|
|
|
if(cur_bg != default_bg) { |
|
|
|
|
|
|
|
$bg_sprite.setPosition({x, y}); |
|
|
|
|
|
|
|
$bg_sprite.setColor(cur_bg); |
|
|
|
|
|
|
|
$window.draw($bg_sprite); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$window.draw(sprite); |
|
|
|
$window.draw(sprite); |
|
|
|
// next cell
|
|
|
|
// next cell
|
|
|
|
x += $base_glyph.advance; |
|
|
|
x += $base_glyph.advance; |
|
|
@ -135,14 +142,14 @@ inline sf::FloatRect draw_chunk(sf::RenderWindow& window, |
|
|
|
return bounds; |
|
|
|
return bounds; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SFMLRender::render_text(const std::wstring &text, sf::Color default_bg, float start_x, float start_y) { |
|
|
|
void SFMLRender::render_text(const std::wstring &text, sf::Color default_fg, sf::Color default_bg, float start_x, float start_y) { |
|
|
|
std::wstring out; |
|
|
|
std::wstring out; |
|
|
|
float x = start_x; |
|
|
|
float x = start_x; |
|
|
|
float y = start_y; |
|
|
|
float y = start_y; |
|
|
|
sf::Color cur_bg = default_bg; |
|
|
|
sf::Color cur_bg = default_bg; |
|
|
|
|
|
|
|
|
|
|
|
// start with the default_fg until it's changed
|
|
|
|
// start with the default_fg until it's changed
|
|
|
|
$ui_text.setFillColor($default_fg); |
|
|
|
$ui_text.setFillColor(default_fg); |
|
|
|
|
|
|
|
|
|
|
|
$ansi.parse(text, |
|
|
|
$ansi.parse(text, |
|
|
|
[&](sf::Color fg, sf::Color bg) { |
|
|
|
[&](sf::Color fg, sf::Color bg) { |
|
|
@ -184,26 +191,33 @@ void SFMLRender::render_text(const std::wstring &text, sf::Color default_bg, flo |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Does not render the panel, you have to do that so you can control |
|
|
|
|
|
|
|
* when things render. |
|
|
|
|
|
|
|
*/ |
|
|
|
void SFMLRender::draw(Panel &panel, float x_offset, float y_offset) { |
|
|
|
void SFMLRender::draw(Panel &panel, float x_offset, float y_offset) { |
|
|
|
panel.render(); |
|
|
|
|
|
|
|
const std::wstring &panelout = panel.to_string(); |
|
|
|
const std::wstring &panelout = panel.to_string(); |
|
|
|
|
|
|
|
|
|
|
|
if(panel.grid) { |
|
|
|
// BUG: ui vs bg doesn't make sense. maybe grid vs. text?
|
|
|
|
render_grid(panelout, panel.x + x_offset, panel.y + y_offset); |
|
|
|
auto bounds = panel.grid ? $bg_bounds : $ui_bounds; |
|
|
|
} else { |
|
|
|
|
|
|
|
sf::RectangleShape backing( |
|
|
|
|
|
|
|
sf::Vector2f($ui_bounds.width * panel.width + panel.border_px, |
|
|
|
|
|
|
|
$ui_bounds.height * panel.height + panel.border_px)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
backing.setFillColor(panel.default_bg); |
|
|
|
sf::RectangleShape backing( |
|
|
|
|
|
|
|
sf::Vector2f(bounds.width * panel.width + panel.border_px, |
|
|
|
|
|
|
|
bounds.height * panel.height + panel.border_px)); |
|
|
|
|
|
|
|
|
|
|
|
if(panel.has_border) { |
|
|
|
backing.setFillColor(panel.default_bg); |
|
|
|
backing.setOutlineColor(panel.border_color); |
|
|
|
|
|
|
|
backing.setOutlineThickness(panel.border_px); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
backing.setPosition(panel.x + x_offset, panel.y + y_offset); |
|
|
|
if(panel.has_border) { |
|
|
|
$window.draw(backing); |
|
|
|
backing.setOutlineColor(panel.border_color); |
|
|
|
render_text(panelout, panel.default_bg, panel.x, panel.y); |
|
|
|
backing.setOutlineThickness(panel.border_px); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
backing.setPosition(panel.x + x_offset, panel.y + y_offset); |
|
|
|
|
|
|
|
$window.draw(backing); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(panel.grid) { |
|
|
|
|
|
|
|
render_grid(panelout, panel.default_fg, panel.default_bg, panel.x + x_offset, panel.y + y_offset); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
render_text(panelout, panel.default_fg, panel.default_bg, panel.x + x_offset, panel.y + y_offset); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|