Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewritten proposal for Windowing 3.0 #2353

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions documentation/proposals/Proposal - Multi-Backend Input.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Cases where the **user** word is used without the **end** prefix can be assumed

# Usage Examples
```cs
IWindowHandlesSource someWindow = null!;
INativeWindow someWindow = null!;
var inputContext = someWindow.CreateInput();
inputContext.Update();
inputContext.Gamepads.ThumbstickMove += @event =>
Expand All @@ -43,27 +43,27 @@ inputContext.Gamepads.ThumbstickMove += @event =>
var isButtonDown = inputContext.Gamepads.Any(gamepadState => gamepadState.Buttons[JoystickButton.A]);
```
```cs
IWindowHandlesSource someWindow = null!;
INativeWindow someWindow = null!;
var inputContext = new InputContext();
inputContext.Update();
inputContext.Backends.Add(someWindow.CreateInputBackend());
// in future:
// inputContext.Backends.Add(new OpenXRInputBackend(...));
```
```cs
class MyThing
class Program : ISurfaceApplication
{
[SilkEntryPoint]
public static void Run(ISurface surface)
public static void Initialize<TSurface>(TSurface surface) where TSurface : Surface
{
var inputContext = surface.CreateInput();
surface.Update += _ => inputContext.Update();
inputContext.Gamepads.ThumbstickMove += @event =>
{
Console.WriteLine($"Thumbstick {@event.Index} moved from {@event.OldValue} to {@event.NewValue}");
};
surface.Run();
}

public static void Main() => ISurfaceApplication.Run<Program>();
}
```

Expand All @@ -74,18 +74,16 @@ Similar to Windowing 3.0, a reference implementation will be included in the mai
```cs
public static class InputWindowExtensions
{
public static IInputBackend CreateInputBackend(this WindowHandles window);
public static IInputBackend CreateInputBackend(this IWindowHandlesSource window);
public static InputContext CreateInput(this WindowHandles window);
public static InputContext CreateInput(this IWindowHandlesSource window);
public static IInputBackend CreateInputBackend(this INativeWindow window);
public static InputContext CreateInput(this INativeWindow window);
}
```

The `CreateInputBackend` will create an instance of the reference implementation for the given `WindowHandles`. The `IWindowHandlesSource` overloads just forward to the `WindowHandles` overload. This is because `ISurface` will implement `IWindowHandlesSource`, so the extension methods will be usable on an `ISurface` without having a hard reference between Windowing and Input.
The `CreateInputBackend` will create an instance of the reference implementation for the given `INativeWindow`. `Surface` will implement `INativeWindow`, so the extension methods will be usable on a `Surface` without having a hard reference between Windowing and Input.

The `CreateInput` methods simply return an `InputContext` preconfigured with the backend created by `CreateInputBackend` for ease of use.

Please see the Windowing 3.0 proposal for `IWindowHandlesSource` and `WindowHandles`.
Please see the Windowing 3.0 proposal for `INativeWindow`.

# Devices

Expand Down
Loading
Loading