Added mousewheel zooming

This commit is contained in:
Philipp Schärer
2016-01-25 18:28:06 +01:00
committed by Oliver Brakmann
parent 386acdcfc9
commit ea74499ec2
10 changed files with 198 additions and 30 deletions

View File

@@ -189,8 +189,41 @@ namespace OpenRA.Mods.Common.Widgets
}
}
bool IsZoomAllowed(float zoom)
{
return world.IsGameOver || zoom >= 1.0f || world.IsReplay || world.LocalPlayer == null || world.LocalPlayer.Spectating;
}
void Zoom(int direction)
{
var zoomSteps = worldRenderer.Viewport.AvailableZoomSteps;
var currentZoom = worldRenderer.Viewport.Zoom;
var nextIndex = zoomSteps.IndexOf(currentZoom);
if (direction < 0)
nextIndex++;
else
nextIndex--;
if (nextIndex < 0 || nextIndex >= zoomSteps.Count())
return;
var zoom = zoomSteps.ElementAt(nextIndex);
if (!IsZoomAllowed(zoom))
return;
worldRenderer.Viewport.Zoom = zoom;
}
public override bool HandleMouseInput(MouseInput mi)
{
if (mi.Event == MouseInputEvent.Scroll &&
Game.Settings.Game.AllowZoom && mi.Modifiers.HasModifier(Game.Settings.Game.ZoomModifier))
{
Zoom(mi.ScrollDelta);
return true;
}
var scrolltype = Game.Settings.Game.MouseScroll;
if (scrolltype == MouseScrollType.Disabled)
return false;