Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - rycode

Pages: [1]
1
Window / Re: Title bar, mouse position, and mapPixelToCoords
« on: October 15, 2017, 07:05:33 am »

A bit of an update. I tried the exact same exe on a different computer (Nvidia drivers) and it worked as expected -- the rectangle stuck to the mouse cursor, even with the title bar.

My primary dev machine is a Dell laptop with both Intel integrated graphics and an Nvidia chip. I forced it to use the Nvidia chip and everything works well. Switch back to Intel integrated and the scaling offset is there again.

There must be some sort of bug / oddity in the Intel drivers where things don't work well for some funky reason. I've been building SFML from source and tracing through the code when the app is behaving oddly and can't see anything in there that seems to relate to the behavior.

Am going to try to update my Intel drivers and see if that helps.

And, just for specifics, in this case the values returned by mapPixelToCoords are (as expected) the same as the values passed in, since I'm using the default view. There's no odd values coming back from there, the oddness seems to be in the final image generation on the window.







2
Window / Title bar, mouse position, and mapPixelToCoords
« on: October 12, 2017, 07:45:33 am »
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();
 
  }
}


 


Pages: [1]