|
|
@ -43,7 +43,7 @@ SFMLRender::SFMLRender() : |
|
|
|
$ui_text.setPosition(0,0); |
|
|
|
$ui_text.setPosition(0,0); |
|
|
|
$ui_text.setCharacterSize(UI_FONT_SIZE); |
|
|
|
$ui_text.setCharacterSize(UI_FONT_SIZE); |
|
|
|
$ui_text.setFillColor(color(Value::LIGHT_MID)); |
|
|
|
$ui_text.setFillColor(color(Value::LIGHT_MID)); |
|
|
|
sf::Glyph glyph = $font.getGlyph(L'█', UI_FONT_SIZE, false); |
|
|
|
sf::Glyph glyph = $font.getGlyph(UI_BASE_CHAR, UI_FONT_SIZE, false); |
|
|
|
$ui_bounds = glyph.bounds; |
|
|
|
$ui_bounds = glyph.bounds; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -148,11 +148,22 @@ void SFMLRender::render_grid(const std::wstring &text, float x, float y) { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
inline sf::FloatRect draw_chunk(sf::RenderWindow& window, sf::Text& text, float x, float y, std::wstring &out) { |
|
|
|
inline sf::FloatRect draw_chunk(sf::RenderWindow& window, |
|
|
|
|
|
|
|
sf::FloatRect ui_bounds, sf::Text& text, |
|
|
|
|
|
|
|
sf::Color bgcolor, float x, float y, std::wstring &out) |
|
|
|
|
|
|
|
{ |
|
|
|
text.setString(out); |
|
|
|
text.setString(out); |
|
|
|
text.setPosition(x, y); |
|
|
|
text.setPosition({x, y}); |
|
|
|
sf::FloatRect bounds = text.getLocalBounds(); |
|
|
|
// get a base character for the cell size
|
|
|
|
// need left,top,width,height for box to be accurate
|
|
|
|
sf::FloatRect bounds(x, y, ui_bounds.width * out.size(), ui_bounds.height); |
|
|
|
|
|
|
|
sf::RectangleShape backing({bounds.width, bounds.height}); |
|
|
|
|
|
|
|
backing.setFillColor(bgcolor); |
|
|
|
|
|
|
|
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(text); |
|
|
|
window.draw(text); |
|
|
|
out.clear(); |
|
|
|
out.clear(); |
|
|
|
return bounds; |
|
|
|
return bounds; |
|
|
@ -162,10 +173,7 @@ void SFMLRender::render_text(const std::wstring &text, float start_x, float star |
|
|
|
std::wstring out; |
|
|
|
std::wstring out; |
|
|
|
float x = start_x; |
|
|
|
float x = start_x; |
|
|
|
float y = start_y; |
|
|
|
float y = start_y; |
|
|
|
enum State { START=1, BUILDING=2 }; |
|
|
|
sf::Color bgcolor = $default_bg; |
|
|
|
enum Event { NL=1, CHAR=3, SKIP=5 }; |
|
|
|
|
|
|
|
State state = START; |
|
|
|
|
|
|
|
Event event = CHAR; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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); |
|
|
@ -173,26 +181,20 @@ 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_text, x, y, out); |
|
|
|
auto bounds = draw_chunk($window, $ui_bounds, $ui_text, bgcolor, x, y, out); |
|
|
|
x += bounds.width; |
|
|
|
x += bounds.width; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
bgcolor = bg; |
|
|
|
$ui_text.setFillColor(fg); |
|
|
|
$ui_text.setFillColor(fg); |
|
|
|
}, |
|
|
|
}, |
|
|
|
[&](wchar_t tile) { |
|
|
|
[&](wchar_t tile) { |
|
|
|
if(tile == '\r') event = SKIP; |
|
|
|
switch(tile) { |
|
|
|
else if(tile == '\n') event = NL; |
|
|
|
case '\r': break; // ignore it
|
|
|
|
else event = CHAR; |
|
|
|
case '\n': { |
|
|
|
|
|
|
|
|
|
|
|
switch(event) { |
|
|
|
|
|
|
|
case SKIP: break; // ignore it
|
|
|
|
|
|
|
|
case NL: { |
|
|
|
|
|
|
|
if(state == START) { |
|
|
|
|
|
|
|
state = BUILDING; |
|
|
|
|
|
|
|
} else if(state == BUILDING) { |
|
|
|
|
|
|
|
sf::FloatRect bounds; |
|
|
|
sf::FloatRect bounds; |
|
|
|
|
|
|
|
|
|
|
|
if(out.size() > 0) { |
|
|
|
if(out.size() > 0) { |
|
|
|
bounds = draw_chunk($window, $ui_text, x, y, out); |
|
|
|
bounds = draw_chunk($window, $ui_bounds, $ui_text, bgcolor, x, y, out); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
bounds = $ui_text.getLocalBounds(); |
|
|
|
bounds = $ui_text.getLocalBounds(); |
|
|
|
} |
|
|
|
} |
|
|
@ -200,15 +202,17 @@ void SFMLRender::render_text(const std::wstring &text, float start_x, float star |
|
|
|
y += bounds.height; |
|
|
|
y += bounds.height; |
|
|
|
x = start_x; // reset to the original position
|
|
|
|
x = start_x; // reset to the original position
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case CHAR: |
|
|
|
default: |
|
|
|
state = BUILDING; |
|
|
|
|
|
|
|
out += tile; |
|
|
|
out += tile; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(out.size() > 0) { |
|
|
|
|
|
|
|
draw_chunk($window, $ui_bounds, $ui_text, bgcolor, x, y, out); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SFMLRender::draw_text(Panel &panel, bool with_border) { |
|
|
|
void SFMLRender::draw_text(Panel &panel, bool with_border) { |
|
|
|