1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 20:47:30 +08:00
osu-lazer/osu.Game/Graphics/Cursor/OsuCursorContainer.cs
Andrey Zavadskiy 16dc1460ad Cursor scale
2017-02-02 14:44:56 +03:00

75 lines
2.4 KiB
C#

//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Framework.Graphics.Transformations;
using osu.Framework.Input;
using osu.Game.Configuration;
using System;
namespace osu.Game.Graphics.Cursor
{
class OsuCursorContainer : CursorContainer
{
protected override Drawable CreateCursor() => new OsuCursor();
public OsuCursorContainer()
{
Add(new CursorTrail { Depth = 1 });
}
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
ActiveCursor.Scale = new Vector2(1);
ActiveCursor.ScaleTo(1.2f, 100, EasingTypes.OutQuad);
return base.OnMouseDown(state, args);
}
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
{
if (!state.Mouse.HasMainButtonPressed)
ActiveCursor.ScaleTo(1, 200, EasingTypes.OutQuad);
return base.OnMouseUp(state, args);
}
class OsuCursor : Container
{
private BindableDouble cursorScale;
private Sprite sprite;
public OsuCursor()
{
Origin = Anchor.Centre;
AutoSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load(TextureStore textures, OsuConfigManager config)
{
cursorScale = (BindableDouble)config.GetBindable<double>(OsuConfig.CursorSize);
Children = new Drawable[]
{
sprite = new Sprite
{
Scale = new Vector2((float)cursorScale),
Texture = textures.Get(@"Cursor/cursor")
}
};
cursorScale.ValueChanged += scaleChanged;
}
private void scaleChanged(object sender, EventArgs e)
{
sprite.Scale = new Vector2((float)cursorScale);
}
}
}
}