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

Author Topic: [SOLVED]How to use MouseButton?  (Read 2459 times)

0 Members and 1 Guest are viewing this topic.

Chuckleluck

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
[SOLVED]How to use MouseButton?
« on: November 15, 2011, 06:24:19 pm »
I'm having trouble with a function that passes Event.MouseButton.Button as an argument:
Declaration:
Code: [Select]
void HandleMouseClick(Button click, int x, int y);
Called in the main program loop:
Code: [Select]
if(Event.Type == sf::Event::MouseButtonPressed)
HandleMouseClick(Event.MouseButton.Button, Event.MouseMove.X, Event.MouseMove.Y);

Definition:
Code: [Select]
void HandleMouseClick(Button button, int x, int y)
{
    if(button == Left && g_Mode == MAINMENU)
    {
        if(x >= 264 && x < 800 && y >= 300 && y < 325)
        {
            g_Mode = LOBBY;
        }
        else if(x >= 264 && x < 800 && y >= 326 && y < 367)
        {
            g_Mode = OPTIONS;
        }
        else if(x >= 264 && x < 800 && y >= 368 && y < 409)
        {
            ExitGame = true; // calls MainWindow.Close() to end the program
        }
    }
}

The objective of this code is to make it so that when the mouse is over a certain menu item (the x and y values), and the left mouse button is clicked (button == Left), it will execute the correct action.
However, I get the following errors on the definition:
Quote
Error: Variable or field HandleMouseClick declared void
error: `Button' not declared in this scope
error: expected primary-expression before "int"
error: expected primary-expression before "int"
error: initializer expression list treated as compound expression
etc. etc.

I'm guessing I used "Button" incorrectly.  Can someone point out what I did wrong here?

P@u1

  • Jr. Member
  • **
  • Posts: 83
    • View Profile
[SOLVED]How to use MouseButton?
« Reply #1 on: November 15, 2011, 06:34:57 pm »
replace "Button" with "sf::Mouse::Button". Don't forget the namespace and the enclosing class.

Chuckleluck

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
[SOLVED]How to use MouseButton?
« Reply #2 on: November 15, 2011, 07:00:40 pm »
Ok thank you.  :D