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 - Kalicliq

Pages: [1]
1
Window / Re: mouse position relative to window
« on: February 16, 2021, 02:58:22 pm »
Code works for me(Windows), I think it's bug so should be reported - https://github.com/SFML/SFML/issues
Hi, ok thx for testing.
I'm on Fedora 33.

If you deal in screen resolution, everything will be relative to the top left corner of the screen. What you want to do is, calculate the position relative to the window position.
As such take the window position, calculate the wanted offset to your window and set the mouse cursor position to that.
As Kvaz1r said my code works on windows so its not a code problem its an OS problem since i'm on fedora 33.

2
Window / Re: mouse position relative to window
« on: February 10, 2021, 03:53:18 pm »
this is what i approximately do:

#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Window/Mouse.hpp>
#include <SFML/Window/Event.hpp>

class _window
{
    public:
        void create(std::string windowName, const sf::VideoMode resolution, const bool fullScreen)
        {
            sf::VideoMode screenSize = sf::VideoMode::getDesktopMode();

            _rw.create(resolution, windowName, fullScreen ? 8 : 7);
            _rw.setVerticalSyncEnabled(true);
            if (!fullScreen)
                _rw.setPosition(sf::Vector2i((screenSize.width / 2) - (resolution.width / 2), (screenSize.height / 2) - (resolution.height / 2)));

            sf::Mouse::setPosition(sf::Vector2i(_rw.getSize().x / 2, _rw.getSize().y / 2), _rw);
        }

        sf::RenderWindow& get_rw()
        {
            return _rw;
        }

        sf::Event& get_event()
        {
            return _event;
        }

    private:
        sf::RenderWindow _rw;
        sf::Event _event;
};

int main()
{
    _window w;

    w.create("test", sf::VideoMode(800, 600, 32), false);

    while (w.get_rw().isOpen()) {
        while (w.get_rw().pollEvent(w.get_event()))
            switch (w.get_event().type)
            {
                case sf::Event::Closed:
                    w.get_rw().close();
                    break;
                default:
                    break;
            }
        w.get_rw().display();
        w.get_rw().clear();
    }
    return 0;
}

3
Window / mouse position relative to window
« on: February 06, 2021, 10:50:50 pm »
Hi i want to center the mouse on the previously created window. But something went wrong and i dont know why.
you can see where the mouse is positioned on the screenshot.

Edit: Im on Fedora 33.

void Window::create(const std::string windowName, const sf::VideoMode resolution, const bool fullScreen)
{
    sf::VideoMode screenSize = sf::VideoMode::getDesktopMode();

    _window.create(resolution, windowName, fullScreen ? 8 : 7);
    _window.setVerticalSyncEnabled(true);
    if (!fullScreen)
        _window.setPosition(sf::Vector2i((screenSize.width / 2) - (resolution.width / 2), (screenSize.height / 2) - (resolution.height / 2)));

    sf::Mouse::setPosition(sf::Vector2i(_window.getSize().x / 2, _window.getSize().y / 2), _window);
}
 

Pages: [1]