SFML community forums

Help => General => Topic started by: DecoratorFawn82 on January 06, 2014, 09:54:23 am

Title: Mouse Input: X, Y Values of the Mouse
Post by: DecoratorFawn82 on January 06, 2014, 09:54:23 am
Hi! I'm wondering if I have for example a SFML window with a image of a start button or something. How can I do so that when I click that button it happens something. I just want to know how to do if I want to click in a special area within the window. In if the mouse wheren't in the special area it shouldn't happen anything. Here is my code to make it clearer what I want to achieve.

Code: [Select]
#include <iostream>
#include <SFML/Window.hpp>

using namespace std;

int main()
{
    sf::Window window;
    window.create(sf::VideoMode(640, 480), "Window");
    sf::Event event;

    window.setKeyRepeatEnabled(false);
    while (window.isOpen())
    {
        while (window.pollEvent(event))
        {
            switch (event.type)
            {
                case sf::Event::Closed: window.close(); break;
                case sf::Event::MouseMoved:
                    cout << "X: " << event.mouseMove.x << endl;
                    cout << "Y: " << event.mouseMove.y << endl;
                    break;
                default: break;
            }
                if (event.type == sf::Event::MouseMoved)
                {
                    cout << "Mouse Moved";
                    if (event.type == sf::Event::MouseButtonPressed)
                    {
                        cout << "Mouse Button Pressed";
                    }
                }
        }
    }

    return 0;
}
Title: Re: Mouse Input: X, Y Values of the Mouse
Post by: DecoratorFawn82 on January 06, 2014, 10:09:39 am
Or maybe just keep on reading the tutorials to get the mouse like that. I didn't think before I wrote :)