Vixen
02b45cc4
csharp
public readonly struct PlatformEvent

One thing that happened: a key, a click, a resize, a suspend.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Every platform event the engine understands is this one type, discriminated by Kind. That is deliberate and it is what SDL, Win32 and the browser all do: events arrive interleaved in a single stream, so any design that splits them into several typed streams has to buffer and re-order them, and loses the ordering between a key press and the resize that happened between it and the next one.

The payload slots are shared between kinds, so an accessor is only meaningful for the kinds its documentation names. In debug builds reading the wrong one trips an assert rather than returning a plausible number; in release the check is gone. Construct events through the factory methods, which is the only way the pairing can be got wrong once.

This is a with no allocation of its own except Text, which is null for every kind that does not carry text. Draining a frame's worth of input allocates nothing.

Fields and properties (21)

  • public PlatformEventKind Kind

    What happened.

  • public uint WindowId

    Which window it happened to, or 0 for events that belong to no window.

  • public long Timestamp

    When it happened, in Stopwatch ticks from a monotonic clock.

  • public KeyModifiers Modifiers

    The modifier keys held at the time.

  • public Key Key

    The key, for KeyDown and KeyUp.

  • public bool IsRepeat

    Whether a KeyDown is auto-repeat rather than a fresh press.

  • public MouseButton MouseButton

    The button, for MouseButtonDown and MouseButtonUp.

  • public int ClickCount

    How many clicks this one completes: 1 for a single click, 2 for the second click of a double-click, and so on for as far as the OS counts.

  • public GamepadButton GamepadButton

    The button, for GamepadButtonDown and GamepadButtonUp.

  • public GamepadAxis GamepadAxis

    The axis, for GamepadAxisMoved.

  • public float Value

    An analogue reading: an axis position, or a touch's pressure.

  • public int DeviceId

    Which device this came from: a gamepad's id, or a finger's id for the duration of its touch.

  • public Vector2 Position

    Where the pointer or finger is, relative to the window's top-left, in logical points.

  • public Vector2 Delta

    How far it moved since the previous event, in logical points — or in wheel notches for MouseWheel.

  • public Int2 WindowPosition

    The window's new top-left in desktop coordinates, for WindowMoved.

  • public Int2 Size

    The client area's new size in logical points, for WindowResized.

  • public Int2 PixelSize

    The framebuffer's new size in physical pixels, for WindowResized — which is what a swapchain is rebuilt from.

  • public float DpiScale

    The window's new scale factor, for WindowDpiChanged.

  • public string Text

    The text: committed input, a composition string, a dropped path, or dropped text.

  • public int SelectionStart

    Where the composition cursor sits within Text, for TextEditing.

  • public int SelectionLength

    How much of Text the composition has selected, for TextEditing.

Methods (17)

  • public static PlatformEvent Window(PlatformEventKind kind, uint windowId, long timestamp)

    A window event that carries nothing but its identity.

  • public static PlatformEvent WindowMoved(uint windowId, long timestamp, Int2 position)

    A window move.

  • public static PlatformEvent WindowResized(uint windowId, long timestamp, Int2 size, Int2 pixelSize)

    A window resize, carrying both the logical size and the framebuffer size.

  • public static PlatformEvent WindowDpiChanged(uint windowId, long timestamp, float dpiScale)

    A change of scale factor.

  • public static PlatformEvent Keyboard(PlatformEventKind kind, uint windowId, long timestamp, Key key, KeyModifiers modifiers, bool isRepeat = false)

    A key press or release.

  • public static PlatformEvent TextInput(uint windowId, long timestamp, string text)

    Committed text.

  • public static PlatformEvent TextEditing(uint windowId, long timestamp, string text, int selectionStart, int selectionLength)

    An in-progress IME composition.

  • public static PlatformEvent MouseMoved(uint windowId, long timestamp, Vector2 position, Vector2 delta, KeyModifiers modifiers = None)

    Pointer motion.

  • public static PlatformEvent MouseButtonChanged(PlatformEventKind kind, uint windowId, long timestamp, MouseButton button, Vector2 position, int clickCount = 1, KeyModifiers modifiers = None)

    A mouse button press or release.

  • public static PlatformEvent MouseWheel(uint windowId, long timestamp, Vector2 position, Vector2 delta, KeyModifiers modifiers = None)

    A wheel or trackpad scroll, in notches.

  • public static PlatformEvent Touch(PlatformEventKind kind, uint windowId, long timestamp, int fingerId, Vector2 position, Vector2 delta = default(Vector2), float pressure = 1)

    A touch down, move or up.

  • public static PlatformEvent GamepadConnection(PlatformEventKind kind, long timestamp, int deviceId)

    A gamepad arriving or leaving.

  • public static PlatformEvent GamepadButtonChanged(PlatformEventKind kind, long timestamp, int deviceId, GamepadButton button)

    A gamepad button press or release.

  • public static PlatformEvent GamepadAxisMoved(long timestamp, int deviceId, GamepadAxis axis, float position)

    A gamepad axis moving.

  • public static PlatformEvent Application(PlatformEventKind kind, long timestamp)

    An event that belongs to the application rather than to any window: a suspend, a resume, a memory warning, a quit, a display change.

  • public static PlatformEvent Drop(PlatformEventKind kind, uint windowId, long timestamp, string text, Vector2 position)

    Something dropped onto a window.

  • public override string ToString()

    Returns the fully qualified type name of this instance.

Used by (30)

  • PbrShowcaseGamePbrShowcase
  • TriangleGameHelloTriangle
  • UiHostHelloUi
  • VideoGameVideoPlayback
  • VirtualGeometryGameVirtualGeometry
  • DesktopLifecycleVixen.Platform.Desktop
  • DesktopPlatformVixen.Platform.Desktop
  • DesktopPlatformTestsVixen.Platform.Desktop.Tests
  • GameVixen.App.Hosting
  • HeadlessLifecycleVixen.Platform.Headless
  • HeadlessLifecycleTestsVixen.Platform.Headless.Tests
  • HeadlessPlatformVixen.Platform.Headless
  • HeadlessPlatformTestsVixen.Platform.Headless.Tests
  • HeadlessWindowVixen.Platform.Headless
  • IPlatformVixen.Platform
  • MobileLifecycleVixen.Platform
  • MobileLifecycleTestsVixen.Platform.Tests
  • PlatformEventBufferVixen.Platform
  • PlatformEventBufferTestsVixen.Platform.Tests
  • PlatformEventTestsVixen.Platform.Tests
  • PlatformInputVixen.App.Hosting
  • PlatformInputVixen.Platform.Ui
  • PlatformWindowHostVixen.Platform.Ui
  • PlatformWindowHostTestsVixen.Platform.Ui.Tests
  • VixenApplicationVixen.App.Hosting
  • EditorHostVixen.Editor.Host
  • InterceptingGameVixen.App.Tests
  • PlatformInputTestsVixen.App.Tests
  • PostingGameVixen.App.Tests
  • VixenApplicationTestsVixen.App.Tests