Vixen
02b45cc4
csharp
public sealed class Viewport

A rectangle of the interface that something else renders into.

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

Remarks

Three jobs, and none of them is drawing a scene. It says where and how big in render pixels; it says when that changed, which is when a render target has to be recreated; and it takes the input that happens inside it and reports it in the coordinates a camera controller wants. What goes in the rectangle belongs to Vixen.Rendering, and this assembly is deliberately unaware of it.

⚠ The size is reported in render pixels, not layout pixels. A layout is in device-independent units and a render target is in real ones, so the two differ by the display scale on every machine anybody actually uses. A viewport that handed a renderer its layout size would produce a soft image on every retina display and nowhere else, which is the bug nobody sees until somebody complains about a screenshot.

It draws RenderTarget when there is one, through the draw list's image command — so a renderer hands the interface a texture rather than compositing over it, and the viewport is an ordinary element that other elements can be drawn on top of. With no target it fills a placeholder colour, which is what a viewport nothing has rendered into yet should look like: empty rather than broken.

⚠ Capture does not lock the pointer and cannot: a pointer lock is a platform request, and this assembly has no platform. PointerLockRequested is what an app head subscribes to, and until something does, capture is "every move comes here" and nothing more.

Fields and properties (16)

  • protected override string TagName

    The element name this type answers to when a caller does not choose one.

  • protected override bool AcceptsFocus

    Whether the focus can rest on this kind of control at all.

  • public UiElement Overlay

    Where gizmos, overlays and heads-up text go.

  • public ViewportGizmo Gizmo

    The axis cross in the corner.

  • public float RenderScale
  • public bool ShowGizmo
  • public ulong RenderTarget

    The renderer's handle for whatever is being drawn here.

  • public bool FlipVertically
  • public int RenderWidth

    How wide the render target should be, in render pixels.

  • public int RenderHeight

    How tall it should be.

  • public float AspectRatio

    The shape of it, for a projection matrix.

  • public bool IsCapturing

    Whether every pointer event is coming here.

  • public Matrix4x4 ViewRotation

    The camera's orientation, which is what the gizmo shows.

  • public static readonly UiPropertyKey RenderScaleProperty

    Identity for RenderScale.

  • public static readonly UiPropertyKey ShowGizmoProperty

    Identity for ShowGizmo.

  • public static readonly UiPropertyKey FlipVerticallyProperty

    Identity for FlipVertically.

Events (5)

  • public Action<Viewport>? Resized

    Raised when the render size changes, which is when a target has to be recreated.

  • public Action<Viewport, ViewportDrag>? Dragged

    Raised for every pointer move with a button down inside the viewport.

  • public Action<Viewport, float>? Zoomed

    Raised for the wheel, carrying its vertical delta unchanged.

  • public Action<Viewport, bool>? CaptureChanged

    Raised when the viewport takes or gives up the pointer.

  • public Action<Viewport, bool>? PointerLockRequested

    Raised when the viewport would like the platform to lock the pointer, or unlock it.

Methods (11)

  • public bool IsOverlayEvent(UiElement? source)

    Whether an event came from the chrome over the pane rather than from the pane.

  • protected override void OnCreated()

    Builds whatever this element is made of, once, as it joins a document.

  • public bool Refresh()

    Brings the render size up to date and raises Resized if it moved.

  • public void Capture(bool lockPointer = false)

    Sends every pointer event here until it is released.

  • public void ReleaseCapture()

    Stops.

  • public Vector2 ToRender(float x, float y)

    Where a point in the viewport is, in render pixels from its top-left.

  • public Color4 AxisColor(int axis)

    The colour of one of the gizmo's arms.

  • protected override void OnDraw(DrawContext context)

    Draws whatever this element is, beyond what a stylesheet can describe.

  • public void ClearRenderScale()

    Unsets RenderScale, so it takes its default or its ancestor's value again.

  • public void ClearShowGizmo()

    Unsets ShowGizmo, so it takes its default or its ancestor's value again.

  • public void ClearFlipVertically()

    Unsets FlipVertically, so it takes its default or its ancestor's value again.

Used by (20)

  • ResizeTestsVixen.Ui.Controls.Advanced.Tests
  • ViewportGizmoVixen.Ui.Controls.Advanced
  • ViewportTestsVixen.Ui.Controls.Advanced.Tests
  • BlockoutModeVixen.Editor.Blockout
  • ChromeFixtureVixen.Editor.Ui.Tests
  • EditorAffordanceTestsVixen.Editor.App.Tests
  • EditorApplicationVixen.Editor.App
  • EditorModeTestsVixen.Editor.App.Tests
  • FoliageModeVixen.Editor.Terrain
  • ManipulationTestsVixen.Editor.SceneView.Tests
  • MarqueeOverlayVixen.Editor.SceneView
  • PaneVixen.Editor.SceneView.Tests
  • ProxyShapeViewVixen.Editor.AssetEditors
  • ScenePresenterVixen.Editor.App
  • SceneViewportVixen.Editor.SceneView
  • TerrainModeVixen.Editor.Terrain
  • ViewportChromeVixen.Editor.App
  • ViewportInputTestsVixen.Editor.SceneView.Tests
  • ViewportLayoutVixen.Editor.SceneView
  • WorkPlaneCommandTestsVixen.Editor.App.Tests