mirror of
https://github.com/osukey/osukey.git
synced 2025-08-06 08:03:52 +09:00
Further logic simplification
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -142,20 +143,60 @@ namespace osu.Game.Screens.Edit.Screens.Compose
|
|||||||
graph.Beatmap.BindTo(Beatmap);
|
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)
|
protected override bool OnWheel(InputState state)
|
||||||
{
|
{
|
||||||
if (!state.Keyboard.ControlPressed)
|
if (!state.Keyboard.ControlPressed)
|
||||||
return base.OnWheel(state);
|
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);
|
Zoom += state.Mouse.WheelDelta;
|
||||||
float newAbsoluteTarget = relativeTarget * newSize * Content.DrawSize.X / Content.Size.X;
|
|
||||||
|
|
||||||
float mousePos = MathHelper.Clamp(ToLocalSpace(state.Mouse.NativeState.Position).X, 0, DrawSize.X);
|
float scrollPos = Content.DrawSize.X * relativeContentPosition - position;
|
||||||
float scrollPos = newAbsoluteTarget - mousePos;
|
|
||||||
|
|
||||||
Content.ResizeWidthTo(newSize);
|
|
||||||
ScrollTo(scrollPos, false);
|
ScrollTo(scrollPos, false);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user