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

Pages: [1]
1
General / Re: Mouse Trouble
« on: July 13, 2024, 07:50:30 am »

Thanks eXpl0it3r. Your reply is much appreciated. I have dug in to this some more and perhaps come across a better method. Continuously checking the events to get a status is a really bad idea but found that the switch command enables me to discretely handle each event in turn. Code is:

        sf::Event event;
        while (window.pollEvent(event))
        {
            switch (event.type)
            {
                case sf::Event::Closed:
                    window.close();
                    break;

                case sf::Event::MouseWheelScrolled:
                    if (event.mouseWheelScroll.delta > 0)
                    {
      \\ Mouse Scroll Up
                    }
                    else
                    {
      \\ Mouse Scroll Down
                    }
                    break;

                case sf::Event::MouseButtonPressed:
                    if (event.mouseButton.button == sf::Mouse::Left)
                    {
      \\ Left mouse button pressed.
                    }
                    else
                    {
      \\ Right mouse button pressed.
                    }

                    break;

                case sf::Event::MouseButtonReleased:

      \\ Either Mouse Button Released

                    break;


                case sf::Event::Resized:

      \\ Resize Event

                    windowWidth = event.size.width;
                    windowHeight = event.size.height;

                    visibleArea = sf::FloatRect(0, 0, windowWidth, windowHeight);

                    break;

                default:
                    break;
            }
        }

I think switch is a much better way to do this and don't know why SFML don't suggest this in their tutorials. Also probably worth noting that I am a terrible coder and not great with instructions. Having to learn patience and get the ability to read and understand the docs.

Thanks once again.

2
General / Mouse Trouble
« on: July 10, 2024, 11:50:38 am »
Hi All

Hope this is the right place. Trying to trap mouse and window resize events. C++ in MS Visual Studio 2022 (Windows).  I got the code working before but without warning I cant get this working now. The problem is when I click the left click, I get a scroll wheel down event.

Relevant code is.

Quote

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                windowHeight = 0;
                windowWidth = 0;
                window.close();
            }
            else if (event.type == sf::Event::Resized)
            {
                std::cout << "Resize " << std::endl;
                windowWidth = event.size.width;
                windowHeight = event.size.height;
                sf::FloatRect visibleArea(0, 0, windowWidth, windowHeight);
                window.setView(sf::View(visibleArea));
            }
            else if (event.mouseWheelScroll.wheel == sf::Mouse::VerticalWheel)
            {
                if (event.mouseWheelScroll.delta > 0) {
                    std::cout << "Wheel in " << std::endl;
                }
                else
                {
                   std::cout << "Wheel out " << std::endl;
                }
            }
            else if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
            {
                std::cout << "Left Mouse Button" << std::endl;
            }




        }

It's probably something stupid I have done but I just cant see it. Any help would be appreciated. Thanks.

Moon.


3
General discussions / Scroll Wheel
« on: May 22, 2024, 05:23:19 pm »
Hi All,

Apologies, as I am fairly new to this game.  I have been programming in C++ / SFML for a while now (months) but got stuck on mouse wheels. How do I use SFML to detect which way a vertical mouse wheel has been scrolled? I am using a Logitech mouse that has a pile of buttons and wheels but the main vertical wheel is the one that I want to detect.

I have been playing Forge of Empires and this scroll wheel controls the zoom function of the map, which is great and so I know this is doable. Would very much appreciate any help.

Many thanks

Moon.

Pages: [1]
anything