2017-03-02 09:45:20 +00:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using OpenTK.Graphics;
|
2017-02-19 08:59:22 +00:00
|
|
|
|
using OpenTK.Input;
|
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
|
|
|
|
public class FocusedTextBox : OsuTextBox
|
|
|
|
|
{
|
|
|
|
|
protected override Color4 BackgroundUnfocused => new Color4(10, 10, 10, 255);
|
|
|
|
|
protected override Color4 BackgroundFocused => new Color4(10, 10, 10, 255);
|
|
|
|
|
|
|
|
|
|
public Action Exit;
|
|
|
|
|
|
|
|
|
|
private bool focus;
|
|
|
|
|
public bool HoldFocus
|
|
|
|
|
{
|
|
|
|
|
get { return focus; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
focus = value;
|
|
|
|
|
if (!focus)
|
|
|
|
|
TriggerFocusLost();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnFocus(InputState state)
|
|
|
|
|
{
|
|
|
|
|
var result = base.OnFocus(state);
|
|
|
|
|
BorderThickness = 0;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnFocusLost(InputState state)
|
|
|
|
|
{
|
|
|
|
|
if (state.Keyboard.Keys.Any(key => key == Key.Escape))
|
|
|
|
|
{
|
|
|
|
|
if (Text.Length > 0)
|
|
|
|
|
Text = string.Empty;
|
|
|
|
|
else
|
|
|
|
|
Exit?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
base.OnFocusLost(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool RequestingFocus => HoldFocus;
|
|
|
|
|
}
|
|
|
|
|
}
|