The way that mine is set up is in my abstract Screen class I have a method called OnMouseClick. In the main program, after creating the window but before the game loop I register the OnMouseClick event with the Window.MouseButtonPressed event:
RenderWindow myWindow = new RenderWindow(new VideoMode(800, 600), "My Window"); myWindow.Closed += new EventHandler(OnClose); myWindow.MouseButtonPressed += new EventHandler<MouseButtonEventArgs>(currentGameScreen.OnMouseClick);
So for every screen that needs to accept mouse input, I have code parsing any input events that are passed to them. The event handler above accepts MouseButtonEventArgs which is descended from EventArgs:
public override void OnMouseClick(object sender, EventArgs e)
{
// Since it comes from a mouse click event, EventArgs argument e carries an enum indicating which mouse input was dispatched with that
// event. So we check what it is:
if (e.Code == SFML.Window.Mouse.Button.Left)
{
// Check if cursor is within the button's clickable region
if (SFML.Mouse.GetPosition(myWindowsName) == // Within myButton's borders)
{
// Execute myButton's left mouse click function
}
}
}
The thing to remember is that the SFML Window class is set up to receive keyboard and mouse input, so the window is where the listening happens. In my game screen's base class I have a public virtual method OnMouseClick, which is empty. That way any descendant can ignore mouse input by default but still pass it along to child elements. If an object gets the mouse button event argument and uses that particular input, it does whatever it's supposed to do.