1
General / Re: Mouse Wheel Scroll Zoom (C# / SFML.Net)
« on: April 26, 2014, 07:12:36 pm »
Thank you Laurent for your input. I got my mouse wheel zoom feature working beautifully. As there are zero examples on the subject in the past topics I'm going to go ahead and make this one a learning experience for everyone who are seeking for this kind zoom feature in the future.
Quote
public static class GameThis is a minimized code from my project. I have bolded the parts which are the key elements here. I hope this can provide help for people trying to figure out the magics of mouse wheel handling. I'm going to mark this topic as solved so it will stand out when searching the forums for this.
{
static float gameZoom = 1;
static void OnMouseScroll(object sender, EventArgs e)
{
RenderWindow window = (RenderWindow)sender;
MouseWheelEventArgs mouseEvent = (MouseWheelEventArgs)e;
gameZoom -= 0.05f * mouseEvent.Delta;
}
static void Main()
{
RenderWindow window = new RenderWindow(new VideoMode(1024, 768), "Mouse Wheel Zoom", Styles.Close);
window.MouseWheelMoved += new EventHandler<MouseWheelEventArgs>(OnMouseScroll);
View gameView = new View();
while (window.IsOpen())
{
window.DispatchEvents();
gameView.Zoom(gameZoom);
window.SetView(gameView);
window.Display();
window.Clear();
}
}
}