hi --
I'm running into an issue where the using mapPixelToCoords is returning oddly offset/scaled values when being run in a window with a title bar.
It is as though the effective viewport for the drawing area extends under the title bar, but something in the rest of the code is not accounting for that and giving me odd results. I use sf::Mouse::getPosition(m_Window) and m_Window.mapPixelToCoords(mouse_pos) to draw a simple quad at the coords of the mouse cursor, but the quad drifts off the mouse position depending on where in the window it is.
I put together a very simple test program that works nicely with a borderless window (rect sticks to cursor) but changes behavior when you add the title bar to it.
I would expect the behavior to be consistent regardless of title bar presence. I am on Windows 10 and using SFML 2.4.2
Could someone advise me if I'm doing something wrong, or if this is indeed unexpected?
Gif is attached, hopefully that works.
Thanks!
test code is:
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window/Mouse.hpp>
#include <stdio.h>
int main(int argc, char** argv)
{
sf::VideoMode vm(200, 200);
sf::RenderWindow m_Window;
m_Window.create(vm, "title", sf::Style::Default);
while(m_Window.isOpen())
{
sf::Vector2i mouse_pos = sf::Mouse::getPosition(m_Window);
printf("%d %d\n", mouse_pos.x, mouse_pos.y);
m_Window.clear(sf::Color::Blue);
sf::Vector2f world_pos = m_Window.mapPixelToCoords(mouse_pos);
sf::RectangleShape shape;
shape.setFillColor(sf::Color::White);
shape.setPosition(world_pos.x, world_pos.y);
shape.setSize( sf::Vector2f(100, 100) );
m_Window.draw(shape);
m_Window.display();
}
}