Fixed the overflows and make the render handle SFML's weird window coordinates not matching world coordinates.

This commit is contained in:
Zed A. Shaw 2024-12-11 16:57:18 -05:00
parent cb2e766305
commit f05f652c26
3 changed files with 18 additions and 12 deletions

View file

@ -92,7 +92,6 @@ void SFMLRender::render_grid(const std::wstring &text, sf::Color default_fg, sf:
sf::Color cur_fg = default_fg;
sf::Color cur_bg = default_bg;
// make a copy so we don't modify the cached one
$ansi.parse(text, [&](auto fg, auto bg) {
cur_fg = fg;
cur_bg = bg;
@ -235,9 +234,14 @@ void SFMLRender::draw(Panel &panel, float x_offset, float y_offset) {
}
bool SFMLRender::mouse_position(Panel &panel, Point &out) {
sf::Vector2i pos = sf::Mouse::getPosition($window);
// yes, you have to do this in sfml
sf::Vector2f pos = $window.mapPixelToCoords(sf::Mouse::getPosition($window));
auto bounds = panel.grid ? $grid_bounds : $text_bounds;
println("mouse position pos={},{} panel.pos={},{} panel.size={},{}",
pos.x, pos.y, panel.x, panel.y, panel.width, panel.height);
if(pos.x >= panel.x && pos.y >= panel.y
&& pos.x <= (panel.x + panel.width * bounds.width)
&& pos.y <= (panel.y + panel.height * bounds.height))