|
|
@ -133,31 +133,30 @@ void SFMLRender::render_grid(const std::wstring &text, float x, float y) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
inline sf::FloatRect draw_chunk(sf::RenderWindow& window, |
|
|
|
inline sf::FloatRect draw_chunk(sf::RenderWindow& window, |
|
|
|
sf::FloatRect ui_bounds, sf::Text& text, |
|
|
|
sf::FloatRect ui_bounds, sf::Text& text, sf::Color default_bg, |
|
|
|
sf::Color bgcolor, float x, float y, std::wstring &out) |
|
|
|
sf::Color bgcolor, float x, float y, std::wstring &out) |
|
|
|
{ |
|
|
|
{ |
|
|
|
text.setString(out); |
|
|
|
text.setString(out); |
|
|
|
text.setPosition({x, y}); |
|
|
|
text.setPosition({x, y}); |
|
|
|
// get a base character for the cell size
|
|
|
|
// get a base character for the cell size
|
|
|
|
sf::FloatRect bounds(x, y, ui_bounds.width * out.size(), ui_bounds.height); |
|
|
|
sf::FloatRect bounds(x, y, ui_bounds.width * out.size(), ui_bounds.height); |
|
|
|
|
|
|
|
if(default_bg != bgcolor) { |
|
|
|
sf::RectangleShape backing({bounds.width, bounds.height}); |
|
|
|
sf::RectangleShape backing({bounds.width, bounds.height}); |
|
|
|
backing.setFillColor(bgcolor); |
|
|
|
backing.setFillColor(bgcolor); |
|
|
|
backing.setPosition({bounds.left, bounds.top + BG_BOX_OFFSET}); |
|
|
|
backing.setPosition({bounds.left, bounds.top + BG_BOX_OFFSET}); |
|
|
|
#ifdef DEBUG |
|
|
|
|
|
|
|
backing.setOutlineColor(int(y) % 4 ? sf::Color::Red : sf::Color::Yellow); |
|
|
|
|
|
|
|
backing.setOutlineThickness(1); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
window.draw(backing); |
|
|
|
window.draw(backing); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
window.draw(text); |
|
|
|
window.draw(text); |
|
|
|
out.clear(); |
|
|
|
out.clear(); |
|
|
|
return bounds; |
|
|
|
return bounds; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SFMLRender::render_text(const std::wstring &text, float start_x, float start_y) { |
|
|
|
void SFMLRender::render_text(const std::wstring &text, 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 bgcolor = $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); |
|
|
@ -165,10 +164,12 @@ void SFMLRender::render_text(const std::wstring &text, float start_x, float star |
|
|
|
$ansi.parse(text, |
|
|
|
$ansi.parse(text, |
|
|
|
[&](sf::Color fg, sf::Color bg) { |
|
|
|
[&](sf::Color fg, sf::Color bg) { |
|
|
|
if(out.size() > 0 ) { |
|
|
|
if(out.size() > 0 ) { |
|
|
|
auto bounds = draw_chunk($window, $ui_bounds, $ui_text, bgcolor, x, y, out); |
|
|
|
auto bounds = draw_chunk($window, |
|
|
|
|
|
|
|
$ui_bounds, $ui_text, |
|
|
|
|
|
|
|
default_bg, cur_bg, x, y, out); |
|
|
|
x += bounds.width; |
|
|
|
x += bounds.width; |
|
|
|
} |
|
|
|
} |
|
|
|
bgcolor = bg; |
|
|
|
cur_bg = bg; |
|
|
|
$ui_text.setFillColor(fg); |
|
|
|
$ui_text.setFillColor(fg); |
|
|
|
}, |
|
|
|
}, |
|
|
|
[&](wchar_t tile) { |
|
|
|
[&](wchar_t tile) { |
|
|
@ -178,7 +179,8 @@ void SFMLRender::render_text(const std::wstring &text, float start_x, float star |
|
|
|
sf::FloatRect bounds; |
|
|
|
sf::FloatRect bounds; |
|
|
|
|
|
|
|
|
|
|
|
if(out.size() > 0) { |
|
|
|
if(out.size() > 0) { |
|
|
|
bounds = draw_chunk($window, $ui_bounds, $ui_text, bgcolor, x, y, out); |
|
|
|
bounds = draw_chunk($window, $ui_bounds, |
|
|
|
|
|
|
|
$ui_text, default_bg, cur_bg, x, y, out); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
bounds = $ui_text.getLocalBounds(); |
|
|
|
bounds = $ui_text.getLocalBounds(); |
|
|
|
} |
|
|
|
} |
|
|
@ -195,7 +197,7 @@ void SFMLRender::render_text(const std::wstring &text, float start_x, float star |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if(out.size() > 0) { |
|
|
|
if(out.size() > 0) { |
|
|
|
draw_chunk($window, $ui_bounds, $ui_text, bgcolor, x, y, out); |
|
|
|
draw_chunk($window, $ui_bounds, $ui_text, default_bg, cur_bg, x, y, out); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -219,6 +221,6 @@ void SFMLRender::draw(Panel &panel, float x_offset, float y_offset) { |
|
|
|
|
|
|
|
|
|
|
|
backing.setPosition(panel.x + x_offset, panel.y + y_offset); |
|
|
|
backing.setPosition(panel.x + x_offset, panel.y + y_offset); |
|
|
|
$window.draw(backing); |
|
|
|
$window.draw(backing); |
|
|
|
render_text(panelout, panel.x, panel.y); |
|
|
|
render_text(panelout, panel.default_bg, panel.x, panel.y); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|