Created
February 14, 2020 22:20
-
-
Save ericoporto/69d6ee9f84d187600dc4935f37601a6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void RoomSettingsEditor_MouseWheel(object sender, MouseEventArgs e) | |
{ | |
int movement = e.Delta; | |
int previousZoomLevel = sldZoomLevel.Value; | |
if (movement > 0) | |
{ | |
if (sldZoomLevel.Value < sldZoomLevel.Maximum) | |
{ | |
sldZoomLevel.Value++; | |
} | |
} | |
else | |
{ | |
if (sldZoomLevel.Value > sldZoomLevel.Minimum) | |
{ | |
sldZoomLevel.Value--; | |
} | |
} | |
sldZoomLevel_Scroll(null, null); | |
// Makes scrolling follow the mouse when possible | |
if (bufferedPanel1.ClientRectangle.Contains(e.Location)) | |
{ | |
int step = previousZoomLevel - sldZoomLevel.Value; | |
if (step != 0) { // do nothing if there was no change | |
double factor = ((double) ZOOM_STEP_VALUE) * ((double)sldZoomLevel.Value) / 100.0; // each step is 25% | |
double dx = (e.X - bufferedPanel1.Location.X) * (factor - 1.0); | |
double dy = (e.Y - bufferedPanel1.Location.Y) * (factor - 1.0); | |
bufferedPanel1.AutoScrollPosition = new Point( | |
(int) (bufferedPanel1.Location.X - dx), | |
(int) (bufferedPanel1.Location.Y - dy)); | |
bufferedPanel1.Invalidate(); // this prevents the room image to look garbled when panning | |
} | |
} | |
// Ridiculous solution, found on stackoverflow.com | |
// TODO: check again later, how reliable this is?! | |
HandledMouseEventArgs ee = (HandledMouseEventArgs)e; | |
ee.Handled = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment