1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 06:47:24 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/OsuTextBox.cs

76 lines
2.2 KiB
C#
Raw Normal View History

2018-04-13 17:19:50 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.Sprites;
2018-11-20 15:51:59 +08:00
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
using osu.Framework.Extensions.Color4Extensions;
2018-06-27 15:06:26 +08:00
using osu.Framework.Input.Bindings;
2018-10-02 11:02:47 +08:00
using osu.Framework.Input.Events;
2018-06-27 15:06:26 +08:00
using osu.Game.Input.Bindings;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Graphics.UserInterface
{
2018-06-27 15:06:26 +08:00
public class OsuTextBox : TextBox, IKeyBindingHandler<GlobalAction>
2018-04-13 17:19:50 +08:00
{
protected override Color4 BackgroundUnfocused => Color4.Black.Opacity(0.5f);
protected override Color4 BackgroundFocused => OsuColour.Gray(0.3f).Opacity(0.8f);
protected override Color4 BackgroundCommit => BorderColour;
protected override float LeftRightPadding => 10;
protected override SpriteText CreatePlaceholder() => new OsuSpriteText
{
Font = @"Exo2.0-MediumItalic",
Colour = new Color4(180, 180, 180, 255),
Margin = new MarginPadding { Left = 2 },
};
public OsuTextBox()
{
Height = 40;
TextContainer.Height = 0.5f;
CornerRadius = 5;
2018-06-27 15:06:26 +08:00
Current.DisabledChanged += disabled => { Alpha = disabled ? 0.3f : 1; };
2018-04-13 17:19:50 +08:00
}
[BackgroundDependencyLoader]
private void load(OsuColour colour)
{
BorderColour = colour.Yellow;
}
2018-10-02 11:02:47 +08:00
protected override void OnFocus(FocusEvent e)
2018-04-13 17:19:50 +08:00
{
BorderThickness = 3;
2018-10-02 11:02:47 +08:00
base.OnFocus(e);
2018-04-13 17:19:50 +08:00
}
2018-10-02 11:02:47 +08:00
protected override void OnFocusLost(FocusLostEvent e)
2018-04-13 17:19:50 +08:00
{
BorderThickness = 0;
2018-10-02 11:02:47 +08:00
base.OnFocusLost(e);
2018-04-13 17:19:50 +08:00
}
protected override Drawable GetDrawableCharacter(char c) => new OsuSpriteText { Text = c.ToString(), TextSize = CalculatedTextSize };
2018-06-27 15:06:26 +08:00
2018-06-29 22:28:15 +08:00
public virtual bool OnPressed(GlobalAction action)
2018-06-27 15:06:26 +08:00
{
if (action == GlobalAction.Back)
{
2018-06-29 22:28:15 +08:00
KillFocus();
2018-06-27 15:06:26 +08:00
return true;
}
2018-06-29 22:35:14 +08:00
return false;
2018-06-27 15:06:26 +08:00
}
public bool OnReleased(GlobalAction action) => false;
2018-04-13 17:19:50 +08:00
}
}