mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 21:47:25 +08:00
Further logic simplification
This commit is contained in:
parent
074a1db4a1
commit
166194e6b6
@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using OpenTK;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
@ -142,20 +143,60 @@ namespace osu.Game.Screens.Edit.Screens.Compose
|
||||
graph.Beatmap.BindTo(Beatmap);
|
||||
}
|
||||
|
||||
private float minZoom = 1;
|
||||
public float MinZoom
|
||||
{
|
||||
get { return minZoom; }
|
||||
set
|
||||
{
|
||||
if (value <= 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(value));
|
||||
if (minZoom == value)
|
||||
return;
|
||||
minZoom = value;
|
||||
}
|
||||
}
|
||||
|
||||
private float maxZoom = 30;
|
||||
public float MaxZoom
|
||||
{
|
||||
get { return maxZoom; }
|
||||
set
|
||||
{
|
||||
if (value <= 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(value));
|
||||
if (maxZoom == value)
|
||||
return;
|
||||
maxZoom = value;
|
||||
}
|
||||
}
|
||||
|
||||
private float zoom = 1;
|
||||
public float Zoom
|
||||
{
|
||||
get { return zoom; }
|
||||
set
|
||||
{
|
||||
value = MathHelper.Clamp(value, MinZoom, MaxZoom);
|
||||
if (zoom == value)
|
||||
return;
|
||||
zoom = value;
|
||||
|
||||
Content.ResizeWidthTo(Zoom);
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool OnWheel(InputState state)
|
||||
{
|
||||
if (!state.Keyboard.ControlPressed)
|
||||
return base.OnWheel(state);
|
||||
|
||||
float newSize = MathHelper.Clamp(Content.Size.X + state.Mouse.WheelDelta, 1, 30);
|
||||
float relativeContentPosition = Content.ToLocalSpace(state.Mouse.NativeState.Position).X / Content.DrawSize.X;
|
||||
float position = ToLocalSpace(state.Mouse.NativeState.Position).X;
|
||||
|
||||
float relativeTarget = MathHelper.Clamp(Content.ToLocalSpace(state.Mouse.NativeState.Position).X / Content.DrawSize.X, 0, 1);
|
||||
float newAbsoluteTarget = relativeTarget * newSize * Content.DrawSize.X / Content.Size.X;
|
||||
Zoom += state.Mouse.WheelDelta;
|
||||
|
||||
float mousePos = MathHelper.Clamp(ToLocalSpace(state.Mouse.NativeState.Position).X, 0, DrawSize.X);
|
||||
float scrollPos = newAbsoluteTarget - mousePos;
|
||||
|
||||
Content.ResizeWidthTo(newSize);
|
||||
float scrollPos = Content.DrawSize.X * relativeContentPosition - position;
|
||||
ScrollTo(scrollPos, false);
|
||||
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user