using System;
using System.Collections.Generic;
using Azimuth;
using Blacklight.Core;
using Blacklight.Core.Cameras;
using Clave;
using Glass;
namespace Konis.Testbed
{
///
/// Something the testbed does, and the keys that do it.
///
public class Command
{
private readonly Action run;
public Command(string name, Action run, params Chord[] chords)
{
Name = name;
this.run = run;
Bindings = chords;
Chords = ChordSet.Of(chords);
}
public string Name { get; }
public IReadOnlyList Bindings { get; }
public ChordSet Chords { get; }
public void Run()
{
run();
}
///
/// Returns the text for the keys that run this command, such as "Backspace", or null if none do.
///
public string ShortcutText()
{
return Clave.ShortcutText.Of(Chords);
}
}
///
/// Runs commands when their keys are pressed, unless the UI has a stronger claim on the keys.
///
public class CommandKeys : IInputConsumer
{
private readonly KeyboardManager keyboardManager;
private readonly List commands = new List();
public CommandKeys(KeyboardManager keyboardManager)
{
this.keyboardManager = keyboardManager;
}
///
/// Registers the command's chords as shortcuts and returns it.
///
public Command Add(Command command)
{
foreach (Chord chord in command.Bindings)
{
keyboardManager.AddShortcut(chord);
}
commands.Add(command);
return command;
}
public bool KeyDown(KeyboardSnapshot keyboard)
{
foreach (Command command in commands)
{
foreach (Chord chord in command.Bindings)
{
if (keyboardManager.ShouldFire(chord, keyboard))
{
command.Run();
return true;
}
}
}
return false;
}
public bool KeyUp(KeyboardSnapshot keyboard)
{
return false;
}
public void SyncKeys(KeyboardSnapshot keyboard)
{
}
public void CancelKeys()
{
}
public bool PointerDown(PointerInput input)
{
return false;
}
public bool PointerMove(PointerInput input)
{
return false;
}
public bool PointerUp(PointerInput input)
{
return false;
}
public bool Wheel(Scalar ticks, Vector pixelPos)
{
return false;
}
}
}