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
|
|
|
|
|
|
|
|
|
|
using System;
|
2017-02-01 08:00:54 +08:00
|
|
|
|
using System.Linq;
|
2017-01-11 06:43:00 +08:00
|
|
|
|
using OpenTK.Graphics;
|
2017-01-30 23:16:55 +08:00
|
|
|
|
using OpenTK.Input;
|
2017-01-11 06:43:00 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2017-01-30 23:16:55 +08:00
|
|
|
|
using osu.Framework.Input;
|
2017-01-11 06:43:00 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2017-02-08 10:19:58 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2017-01-11 06:43:00 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Select
|
|
|
|
|
{
|
2017-02-08 14:13:56 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// A textbox which holds focus eagerly.
|
|
|
|
|
/// </summary>
|
2017-02-08 10:19:58 +08:00
|
|
|
|
public class SearchTextBox : OsuTextBox
|
2017-01-11 06:43:00 +08:00
|
|
|
|
{
|
|
|
|
|
protected override Color4 BackgroundUnfocused => new Color4(10, 10, 10, 255);
|
|
|
|
|
protected override Color4 BackgroundFocused => new Color4(10, 10, 10, 255);
|
2017-02-01 08:00:54 +08:00
|
|
|
|
public Action Exit;
|
2017-02-03 18:12:57 +08:00
|
|
|
|
|
|
|
|
|
private bool focus;
|
|
|
|
|
public bool HoldFocus
|
|
|
|
|
{
|
|
|
|
|
get { return focus; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
focus = value;
|
|
|
|
|
if (!focus)
|
|
|
|
|
TriggerFocusLost();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-08 14:13:56 +08:00
|
|
|
|
public override bool RequestingFocus => HoldFocus;
|
|
|
|
|
|
2017-01-11 06:43:00 +08:00
|
|
|
|
public SearchTextBox()
|
|
|
|
|
{
|
|
|
|
|
Height = 35;
|
|
|
|
|
Add(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new TextAwesome
|
|
|
|
|
{
|
|
|
|
|
Icon = FontAwesome.fa_search,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Margin = new MarginPadding { Right = 10 },
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-02-08 13:01:17 +08:00
|
|
|
|
|
|
|
|
|
PlaceholderText = "type to search";
|
2017-01-11 06:43:00 +08:00
|
|
|
|
}
|
2017-02-03 18:12:57 +08:00
|
|
|
|
|
2017-02-08 10:19:58 +08:00
|
|
|
|
protected override bool OnFocus(InputState state)
|
|
|
|
|
{
|
|
|
|
|
var result = base.OnFocus(state);
|
|
|
|
|
BorderThickness = 0;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-01 08:00:54 +08:00
|
|
|
|
protected override void OnFocusLost(InputState state)
|
|
|
|
|
{
|
|
|
|
|
if (state.Keyboard.Keys.Any(key => key == Key.Escape))
|
2017-02-08 14:14:15 +08:00
|
|
|
|
{
|
|
|
|
|
if (Text.Length > 0)
|
|
|
|
|
Text = string.Empty;
|
|
|
|
|
else
|
|
|
|
|
Exit?.Invoke();
|
|
|
|
|
}
|
2017-02-01 08:00:54 +08:00
|
|
|
|
base.OnFocusLost(state);
|
|
|
|
|
}
|
2017-02-03 18:12:57 +08:00
|
|
|
|
|
2017-01-30 23:16:55 +08:00
|
|
|
|
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
|
|
|
|
{
|
2017-02-09 11:33:24 +08:00
|
|
|
|
if (HandlePendingText(state)) return true;
|
|
|
|
|
|
2017-02-08 14:30:20 +08:00
|
|
|
|
if (!state.Keyboard.ControlPressed && !state.Keyboard.ShiftPressed)
|
|
|
|
|
{
|
|
|
|
|
switch (args.Key)
|
|
|
|
|
{
|
|
|
|
|
case Key.Left:
|
|
|
|
|
case Key.Right:
|
|
|
|
|
case Key.Up:
|
|
|
|
|
case Key.Down:
|
|
|
|
|
case Key.Enter:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-30 23:16:55 +08:00
|
|
|
|
return base.OnKeyDown(state, args);
|
|
|
|
|
}
|
2017-01-11 06:43:00 +08:00
|
|
|
|
}
|
|
|
|
|
}
|