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

Author Topic: Issue with Mouse Scroll Wheel Event  (Read 5056 times)

0 Members and 1 Guest are viewing this topic.

EBrown8534

  • Newbie
  • *
  • Posts: 4
    • View Profile
Issue with Mouse Scroll Wheel Event
« on: December 20, 2012, 08:25:33 am »
Hello Everyone,
So I seem to be having an issue with my Mouse Scroll Wheel Event in SFML version 1.6. I am using the static libraries, in the C++ language.

In my debug version, the scroll event fires as would be completely expected. When one would move the scroll wheel up or down it fires an event corresponding to the movement. However when I build a release version, it does not work as expected, and I'm not exactly sure why.

Here's the problem: When I move my scroll wheel in the release build, there is NO event fired, until I left or right click. Now I did not write my code to do this, so it's completely unexpected. And the issue is not prevalent in the Debug Version, so I assume it's a linker problem.

                                // Process events
                                sf::Event Event;
                                while (App.GetEvent(Event))
                                {
                                        std::cout << totalMenus << ", " << rMenus[0].GetTotalItems() << ", " << rMenus[1].GetTotalItems() << ", " << rMenus[2].GetTotalItems() << ", " << delay << ", " << menu << std::endl;
                                        // Close window : exit
                                        if (Event.Type == sf::Event::Closed)
                                                App.Close();

                                        // Escape key : exit
                                        if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                                                App.Close();

                                        // If we moved the wheel within the delay.
                                        if ((Event.Type == sf::Event::MouseWheelMoved) && delay == 0)
                                        {
                                                std::cout << menu << ": " << rMenus[menu].GetSelectedIndex() << std::endl;
                                                // Setup the delta. (Only needed for positive/negative)
                                                bool delta = Event.MouseWheel.Delta > 0 ? true : false;
                                               
                                                // Check what menu we are in.
                                                if (menu == -1)
                                                {
                                                        // No menu. Join the main menu.
                                                        menu = 0;
                                                }
                                                else
                                                {
                                                        rMenus[menu].MouseScroll(delta);
                                                }

                                                // Setup the delay so that it slows how many scrolls per second.
                                                delay = 4;

                                        }
                                       
                                        if (Event.Type == sf::Event::MouseButtonPressed && delay == 0)
                                        {
                                                // Check what button was clicked.
                                                if (Event.MouseButton.Button == sf::Mouse::Button::Right)
                                                {
                                                        if (menu > -1)
                                                        {
                                                                menu = rMenus[menu].UnSelect();
                                                                rMenus[menu].UnSelect();
                                                        }
                                                }
                                                else if (Event.MouseButton.Button == sf::Mouse::Button::Left)
                                                {
                                                        if (menu > -1)
                                                        {
                                                                menu = rMenus[menu].Select();
                                                        }
                                                }

                                                // Setup the delay so nothing is processed too quickly.
                                                delay = 4;
                                        }
                                       
                                        if (Event.Type == sf::Event::Resized)
                                        {
                                                WindowView = sf::View(sf::FloatRect(0, 0, Event.Size.Width, Event.Size.Height));
                                                rMenus[0].SetView(Event.Size.Width, Event.Size.Height);
                                                rMenus[1].SetView(Event.Size.Width, Event.Size.Height);
                                                rMenus[2].SetView(Event.Size.Width, Event.Size.Height);
                                                sprites[0].SetPosition(Event.Size.Width / 2 + 16, Event.Size.Height / 2 + 16);
                                                sprites[1].SetPosition(Event.Size.Width / 2 + 16, Event.Size.Height / 2 + 16);
                                        }
                                }

                                // Decrement the Delay as needed.
                                if (delay > 0)
                                        delay--;

The above is my event handler code. I am using Microsoft Visual Studio 2010 Ultimate, and yes, I did rebuild the SFML libraries in Visual Studio 2010 Ultimate.

If anyone has any ideas about what would cause this, and how I could possibly resolve this, I would be greatly obliged.

Edit: Forgot to mention, when I run my release build in the debugger it works as expected, it's only when run outside Visual Studio 2010 Ultimate that it fails, and fairly miserably I might add.

Thanks,
EBrown8534
« Last Edit: December 20, 2012, 08:37:51 am by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Issue with Mouse Scroll Wheel Event
« Reply #1 on: December 20, 2012, 08:40:06 am »
Quote
 && delay == 0
I don't know what the delay variable is, but have you tried to remove it from the condition, ie. to test the MouseWheelMoved event alone?
Laurent Gomila - SFML developer

EBrown8534

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Issue with Mouse Scroll Wheel Event
« Reply #2 on: December 20, 2012, 08:43:51 am »
Quote
 && delay == 0
I don't know what delay is, but have you tried to remove it from the condition?
Yes, and it had no effect. Actually, I added this line:

std::cout << totalMenus << ", " << rMenus[0].GetTotalItems() << ", " << rMenus[1].GetTotalItems() << ", " << rMenus[2].GetTotalItems() << ", " << delay << ", " << menu << std::endl;

Because I wanted to know where exactly the issue was, and the event is not even being fired. I only get events on movement of the mouse, or for some reason what appears to be a keep-alive from the mouse. I never get one upon scrolling when the issue is active.

When I right click, then I start getting scrolling events. But it doesn't appear like they're backlogged or anything, I just get the typical ones. So I am not sure what exactly is happening, and it only happens OUTSIDE the debugger, and on the release build.

Edit: It seems the issue arise when outside the debugger in the debug build as well, so I am assuming it has something to do with Visual Studio's debugger.

Edit 2: I think I suspect why it works in the debugger and not outside of it. I modified that line to tell me what event was fired when it received it, and it seems for some reason the Visual Studio debugger is firing a KeyReleased Event to it, as I get an event with that code when the window launches.

Thanks,
EBrown8534
« Last Edit: December 20, 2012, 08:56:17 am by EBrown8534 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Issue with Mouse Scroll Wheel Event
« Reply #3 on: December 20, 2012, 09:10:40 am »
You should do your tests on a minimal example rather than in your original code. This way you can quickly find if the problem is:
- SFML
- your code
- your environment
Laurent Gomila - SFML developer

EBrown8534

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Issue with Mouse Scroll Wheel Event
« Reply #4 on: December 20, 2012, 09:17:09 am »
You should do your tests on a minimal example rather than in your original code. This way you can quickly find if the problem is:
- SFML
- your code
- your environment
I heavily suspect it is my code somewhere, as I am not as good at this as I should be, so I probably made some mistake somewhere that created this issue.

I created myself somewhat a workaround, in that instead of just assuming that the person is in the window, force them to click inside it at least once in order to make things start working. This seems to grab the Mouse Scroll Wheel appropriately, and all my events work as expected.

I do greatly appreciate the attempt to assist me, as bad as I am at C++ and SFML, and I appreciate the fact that you took some time to respond to my questionnaire. It shows that you actually care whether or not people are able to successfully use the product that you have developed, and for that, I thank you.

Thanks,
EBrown8534

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Issue with Mouse Scroll Wheel Event
« Reply #5 on: December 20, 2012, 09:32:54 am »
Quote
I created myself somewhat a workaround, in that instead of just assuming that the person is in the window, force them to click inside it at least once in order to make things start working. This seems to grab the Mouse Scroll Wheel appropriately, and all my events work as expected.
Oh, so it's just a focus issue. Sometimes your window doesn't have the mouse focus, and in this case, it doesn't receive the mouse wheel events (it's the standard behaviour of your OS, it's not specific to SFML). Clicking the window gives it the focus.

Quote
It shows that you actually care whether or not people are able to successfully use the product that you have developed
I really do, yes. That's why SFML 2.0 is still not released: I spend too much time on the forum ;D
Laurent Gomila - SFML developer

EBrown8534

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Issue with Mouse Scroll Wheel Event
« Reply #6 on: December 20, 2012, 09:35:00 am »
Quote
I created myself somewhat a workaround, in that instead of just assuming that the person is in the window, force them to click inside it at least once in order to make things start working. This seems to grab the Mouse Scroll Wheel appropriately, and all my events work as expected.
Oh, so it's just a focus issue. Sometimes your window doesn't have the mouse focus, and in this case, it doesn't receive the mouse wheel events (it's the standard behaviour of your OS, it's not specific to SFML). Clicking the window gives it the focus.
That is what I assumed. From the fact that I could find no information on this from a search, I assumed it was something extremely unique, or something extremely trivial. It turns out it was something extremely trivial.

Again, I thank you greatly for trying to help. At the very least it helps me to learn a little more about the systems in operation, and to prevent me from making the same mistake again.

Thanks,
EBrown8534

 

anything