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

Author Topic: [SOLVED] SFML 2.5.1 THOR and MOUSE BUTTON CLICK issues  (Read 12604 times)

0 Members and 1 Guest are viewing this topic.

thunem

  • Newbie
  • *
  • Posts: 15
    • View Profile
[SOLVED] SFML 2.5.1 THOR and MOUSE BUTTON CLICK issues
« on: June 19, 2020, 09:36:06 pm »
Hi, I am using SFML2.5.1 and Thor, and I am not able to get a getGlobalBounds().contains to have the mouse button click over a sprite, someone can tell me why :-( ?


THE OBJECTS THAT I TRIED
//RECTANGLE
        //sf::RectangleShape closeButton;
        //closeButton.setSize(sf::Vector2f(200.0f, 80.0f));
        //closeButton.setPosition(300.0f, 260.0f);
        //closeButton.setFillColor(sf::Color::Red);

A FLOAT RECT
sf::FloatRect area1(550,0, 50, 20);

THE SAMPLE ROUNDEDRECT FROM THOR LIB
sf::ConvexShape roundedRect = thor::Shapes::roundedRect(sf::Vector2f(200.f, 100.f), 30.f, sf::Color(200, 190, 120), 3.f, sf::Color(150, 140, 80));

if (event.type == sf::Event::MouseButtonPressed )
{
        if (event.mouseButton.button == sf::Mouse::Left) {                                     

//THIS IS NOT WORKING Thats is the supposed way to operate but is not working for me
//if (closeButton.getGlobalBounds().contains(window.mapPixelToCoords(sf::Vector2i(event.mouseButton.x, event.mouseButton.y)))) {

//THIS WORK but is not precise, is not using the shape surface
//if ( sf::Mouse::getPosition(window).x > 550 && sf::Mouse::getPosition(window).y < 20 ) {                                     

                                // Mouse is inside the sprite.
                                std::cout << "Button pressed" << std::endl;
                                               
                        }

                }                              
                               
}
 

COMPILER ERRORS:

Error(active)   E0864   Rect is not  a model    Shapes  C:\Users\pc\Documents\Visual Studio 2017\Resources\SFML-2.5.1-win32\include\SFML\Graphics\Rect.inl      52     


Errore (attivo) E0864   Vector2 is not  a model Shapes  C:\Users\pc\Documents\Visual Studio 2017\Resources\SFML-2.5.1-win32\include\SFML\Graphics\Rect.inl      52     


Errore (attivo) E1670   qualificator not permitted in a non member function     Shapes  C:\Users\pc\Documents\Visual Studio 2017\Resources\SFML-2.5.1-win32\include\SFML\Graphics\Rect.inl      76     
 
« Last Edit: June 22, 2020, 02:44:47 pm by thunem »

thunem

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: SFML 2.5.1 THOR and MOUSE BUTTON CLICK issues
« Reply #1 on: June 19, 2020, 11:43:41 pm »
I found a source from another game that uses closeButton.getGlobalBounds().contains(mouse.x,mouse.y)
and the library that I used to compile is 2.4.2 (from config.hpp MAJOR MINOR etc )
So maybe something has changed and I cannot use contains (breaking the item mouse clicking workflow)?

It's this new behavior a change in 2.5.1?

This is one, I have still to find the one from a user that wanted to fix the engine because the rect gave the same error as mine, I was wondering tho if I can overcome in 2.5.1 without recompiling that part etc...
https://stackoverflow.com/questions/51630900/how-do-i-do-collision-between-two-rectangleshapes-in-sfml-2-5-0-c

Thanks for your help !

thunem

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: SFML 2.5.1 THOR and MOUSE BUTTON CLICK issues
« Reply #2 on: June 20, 2020, 02:51:50 pm »
Solved!
As reported there :
https://en.sfml-dev.org/forums/index.php?topic=21182.0

If someone stomp in this issue It's probably because you have <windows.h> before the SFML includes.

But since I haven't been able to move because the Selbaward library start to output errors, I had to try the preprocessor second solution from Laurent: NOMINMAX for both Release and Debug.

So, after that was added, when clicking compile no issues anymore :-) !

Perfect!

Since @Laurent replied in the other thread, can you please tell me what NOMINMAX remove/add/change? What can be the other face to do that preprocessor instruction?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: SFML 2.5.1 THOR and MOUSE BUTTON CLICK issues
« Reply #3 on: June 20, 2020, 05:39:39 pm »
Quote
Since @Laurent replied in the other thread, can you please tell me what NOMINMAX remove/add/change?
Prevents windows.h from #defining the min and max macros, which conflict with the std::min and std::max template functions when included first.
Laurent Gomila - SFML developer

thunem

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: SFML 2.5.1 THOR and MOUSE BUTTON CLICK issues
« Reply #4 on: June 21, 2020, 09:39:17 pm »
Thanks! For errors like those, what are your techniques if I may ask? I am interested to understand better those errors, I mean I have solved this error only because I have luckily found this topic in the link above, I was about to install an older version (2.4.2) just afterward to find that probably was totally another thing.

Best advices?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: SFML 2.5.1 THOR and MOUSE BUTTON CLICK issues
« Reply #5 on: June 22, 2020, 08:00:56 am »
There's no technique. It is important to understand what the compilers says, investigate, search on internet, etc. And personal experience, of course.
Laurent Gomila - SFML developer

thunem

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: SFML 2.5.1 THOR and MOUSE BUTTON CLICK issues
« Reply #6 on: June 22, 2020, 10:41:00 am »
Thanks!
This user in that topic says:
//Ok, I'm getting 8 errors and I have no clue why...
//Here is the line of code that I've narrowed it down too:
if (exitRect.getGlobalBounds().contains(window.mapPixelToCoords(sf::Mouse::getPosition(window))))
 

I mean how do you reach / or how to arrive to that solution?
You most likely include (something that includes) <windows.h> before SFML headers. Several possible solutions:
- get rid of that include if you don't need it
- define the preprocessor symbol NOMINMAX in your project settings
- #undef "min" and "max" symbols immediatly after including windows.h
- do not include any SFML header after windows.h, if possible

solution #2 is the cleanest (or #1 if you have windows.h included just for fun).

It's that based on your experience like damning the screen, or invoke mistic creatures, cursing the lamp etc ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: SFML 2.5.1 THOR and MOUSE BUTTON CLICK issues
« Reply #7 on: June 22, 2020, 01:39:45 pm »
As I said, the compiler message should be read carefully. It is full of useful stuff, and people often overlook that.

Quote
rect.inl(81): error C2589: '(': illegal token on right side of '::'
The error is located in rect.inl, line 81. And it's about something that is between :: and (. The same error repeats for lines 82, 83 and 84. So it can't be anything but the min and max symbols.

The next step is to know why the compiler complains about them being "illegal tokens". I don't remember how I did, but there are two solutions:
- F12 in Visual Studio ("go to declaration"), if the IDE is smart enough, this puts you into windows.h, at a line that looks like "#define min ...".
- search the error on Google, which often ends on stackoverflow with a meaningful answer. Especially for errors like this one, that almost any Windows programer has encountered.

In both cases, the solution is immediate:
- in windows.h, #define min ... is inside a #ifndef NOMINMAX bloc
- if found on stackoverflow, the solution is probably given directly

The experience also takes an important part: this kind of silly error (illegal token on something that looks really harmful) is often caused by included headers that define macros with common names, which makes the preprocessor put a big mess in the following code.

I hope this answers your question.
Laurent Gomila - SFML developer

thunem

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: SFML 2.5.1 THOR and MOUSE BUTTON CLICK issues
« Reply #8 on: June 22, 2020, 02:44:31 pm »
Yes, this is a perfect answer :-)

I will mark solved then, and yes so in conclusion you have the method as mine, and we are all in the same boat XD

Experience is a big jump in speed that's for sure tho

This video is pretty much what happen to all us :-) :

https://www.youtube.com/watch?v=HluANRwPyNo

« Last Edit: June 22, 2020, 03:20:38 pm by thunem »

 

anything