Hey, I got a button class like this:
#include "Button.h"
Button::Button(std::string content,int x, int y,GameObject* gameO,GameWindow* wI): xPos(x), yPos(y),game(gameO), windowIn(wI)
{
sprLeft=game->getSpriteManager()->getSprite(3);
sprLeft->setPosition(xPos-content.length()/2,yPos);
sprRight=game->getSpriteManager()->getSprite(4);
sprRight->setPosition(xPos+(content.length()*content.length()*1.9),yPos);
contentT=sf::Text(content,*game->getGuiFont());
contentT.setColor(sf::Color::Black);
contentT.setCharacterSize(18);
contentT.setPosition(xPos-content.length()/2, yPos-2);
}
Button::~Button(void)
{
}
void Button::draw()
{
windowIn->getWindow()->draw(*sprLeft);
windowIn->getWindow()->draw(contentT);
windowIn->getWindow()->draw(*sprRight);
}
Button::Button(void)
{}
and it is made and drawin in a class like this:
#include "MainMenuWindow.h"
MainMenuWindow::MainMenuWindow(GameObject* gameO, sf::RenderWindow *rW)
{
game=gameO;
window=rW;
newGameButton=Button("New Game",window->getSize().x/2-50,window->getSize().y/2-60,game,this);
}
MainMenuWindow::~MainMenuWindow(void)
{
}
void MainMenuWindow::draw(void)
{
newGameButton.draw();
}
what I would like to do, is get mouse click coords in my Main.cpp event loop(standard one) and do something if newGameButton was clicked, how could I do so? Bare in mind that the Button class is meant to create multiple buttons, all with different actions.