2017-02-07 12:59:30 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-09-28 16:32:38 +08:00
|
|
|
|
|
2016-11-26 18:22:56 +08:00
|
|
|
|
using OpenTK;
|
2017-02-04 21:56:56 +08:00
|
|
|
|
using OpenTK.Graphics;
|
2016-11-09 07:13:20 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2017-02-02 19:44:56 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
2017-03-05 02:42:37 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2016-09-28 16:32:38 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2017-02-25 20:12:39 +08:00
|
|
|
|
using osu.Framework.Graphics.Transforms;
|
2016-09-28 16:32:38 +08:00
|
|
|
|
using osu.Framework.Input;
|
2017-02-02 19:44:56 +08:00
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
|
using System;
|
2016-09-28 16:32:38 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Cursor
|
|
|
|
|
{
|
2017-02-28 19:14:48 +08:00
|
|
|
|
public class OsuCursorContainer : CursorContainer
|
2016-09-28 16:32:38 +08:00
|
|
|
|
{
|
|
|
|
|
protected override Drawable CreateCursor() => new OsuCursor();
|
|
|
|
|
|
2016-11-26 18:22:56 +08:00
|
|
|
|
public OsuCursorContainer()
|
|
|
|
|
{
|
2016-11-30 03:50:12 +08:00
|
|
|
|
Add(new CursorTrail { Depth = 1 });
|
2016-11-26 18:22:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-28 16:32:38 +08:00
|
|
|
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
|
|
|
|
|
{
|
2016-11-26 18:22:56 +08:00
|
|
|
|
ActiveCursor.Scale = new Vector2(1);
|
2016-09-28 16:32:38 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-28 19:14:48 +08:00
|
|
|
|
public class OsuCursor : Container
|
2016-09-28 16:32:38 +08:00
|
|
|
|
{
|
2017-02-04 21:56:56 +08:00
|
|
|
|
private Container cursorContainer;
|
2017-02-26 21:08:21 +08:00
|
|
|
|
private Bindable<double> cursorScale;
|
2017-02-04 21:56:56 +08:00
|
|
|
|
|
2016-09-28 16:32:38 +08:00
|
|
|
|
public OsuCursor()
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre;
|
2017-02-04 21:56:56 +08:00
|
|
|
|
Size = new Vector2(42);
|
2016-09-28 16:32:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-12 18:44:16 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2017-02-27 22:32:32 +08:00
|
|
|
|
private void load(OsuConfigManager config)
|
2016-09-28 16:32:38 +08:00
|
|
|
|
{
|
2017-02-27 11:24:50 +08:00
|
|
|
|
cursorScale = config.GetBindable<double>(OsuConfig.CursorSize);
|
2017-02-02 19:44:56 +08:00
|
|
|
|
|
2016-09-28 16:32:38 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-02-04 21:56:56 +08:00
|
|
|
|
cursorContainer = new CircularContainer
|
2016-09-28 16:32:38 +08:00
|
|
|
|
{
|
2017-02-04 21:56:56 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-02-02 19:44:56 +08:00
|
|
|
|
Scale = new Vector2((float)cursorScale),
|
2017-02-04 21:56:56 +08:00
|
|
|
|
Masking = true,
|
|
|
|
|
BorderThickness = Size.X / 6,
|
|
|
|
|
BorderColour = Color4.White,
|
2017-02-10 10:19:13 +08:00
|
|
|
|
EdgeEffect = new EdgeEffect {
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Colour = Color4.Pink.Opacity(0.5f),
|
|
|
|
|
Radius = 5,
|
|
|
|
|
},
|
2017-02-04 21:56:56 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-02-05 16:40:58 +08:00
|
|
|
|
Alpha = 0,
|
|
|
|
|
AlwaysPresent = true,
|
2017-02-04 21:56:56 +08:00
|
|
|
|
},
|
|
|
|
|
new CircularContainer
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Masking = true,
|
|
|
|
|
BorderThickness = Size.X / 3,
|
|
|
|
|
BorderColour = Color4.White.Opacity(0.5f),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-02-05 16:40:58 +08:00
|
|
|
|
Alpha = 0,
|
|
|
|
|
AlwaysPresent = true,
|
2017-02-04 21:56:56 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
new CircularContainer
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Scale = new Vector2(0.1f),
|
|
|
|
|
Masking = true,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
2016-09-28 16:32:38 +08:00
|
|
|
|
};
|
2017-02-02 19:44:56 +08:00
|
|
|
|
cursorScale.ValueChanged += scaleChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void scaleChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-02-04 21:56:56 +08:00
|
|
|
|
cursorContainer.Scale = new Vector2((float)cursorScale);
|
2016-09-28 16:32:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|