using Annulus;
using Azimuth;
using System.Collections.Generic;
namespace Glass.Testbed
{
///
/// Switches who draws the mouse cursor, so the three answers can be compared against each other live.
///
public class CursorTestCase : TestCase
{
private static readonly Vector ButtonSize = new Vector(200, 56);
private readonly World world;
private readonly Dictionary buttons = new Dictionary();
public CursorTestCase(string name, World world) : base(name)
{
this.world = world;
}
///
/// Stands in for a radio group the same way the tab strip does: the chosen mode wears yellow.
///
private void ShowChoice()
{
foreach (KeyValuePair button in buttons)
{
button.Value.ButtonMaterial = button.Key == world.CursorMode
? UiPacksheetMaterials.YellowButton
: UiPacksheetMaterials.Button;
}
}
// The row is consumed a column at a time, so it has to be the caller's rect rather than a copy of it.
private void AddChoice(ref Rect row, CursorMode mode, string label)
{
CursorMode chooseMe = mode;
Button choice = new Panel { Material = Widgets.ButtonLabel(label) }.FillParent(new Button
{
DebugName = $"{mode} cursor",
ButtonMaterial = UiPacksheetMaterials.Button,
Bounds = row.NewCol(ButtonSize.X, margin: Gutter),
});
choice.OnClick += delegate (in MouseState _, MouseButtonFlags __)
{
world.CursorMode = chooseMe;
ShowChoice();
};
Add(choice);
buttons[mode] = choice;
}
protected override void Populate()
{
AddCaption("System leaves the pointer alone; hardware hands the art to the OS; software draws it here");
AddCaption("Software lands last in the frame, so nothing can cover it, but it trails by a tick");
Rect row = ContentAggregator.NewRow(ButtonSize.Y);
AddChoice(ref row, CursorMode.System, "System");
AddChoice(ref row, CursorMode.Hardware, "Hardware");
AddChoice(ref row, CursorMode.Software, "Software");
}
///
/// The mode outlives the case being hidden, so the buttons are re-marked rather than reset.
///
protected override void Setup()
{
ShowChoice();
}
}
}