Screens, panels and input (device 8)

In a system the host draws each machine's screen where the shell placed it, and routes the input to the machines. This article describes both. The calls that place machines (place, face, unface) are in The Machines device; a panel is a Screen command (0Dh) in the shell's own 3D list, described in The 3D vector display.

Pictures

A machine's picture is its screen scaled uniformly into its rectangle (x, y, w, h) and centred:

    if w*480 <= h*640: pw = w, ph = floor(w*480/640)
    else:              pw = floor(h*640/480), ph = h
    px = x + floor((w-pw)/2), py = y + floor((h-ph)/2)

If pw or ph is 0 nothing is shown. Running, paused, exited and faulted machines have a picture (exited and faulted ones show their last frame); loading and failed ones have none. Example: (0, 20, 640, 460) gives the picture (13, 20, 613, 460).

A machine is shown flat in the picture of its own rectangle, or, once the view of it (below) has finished moving towards the glass, in the picture of the view's rectangle. It is shown as a panel where the shell's 3D list has a Screen of it in effect, unless the view shows it flat. A Screen is in effect only in the shell's list, only the first one of its handle, and only if that machine has a picture and its own rectangle shows none.

What the host draws

With no Screen in effect, from the bottom: the shell's screen, then each flat picture in handle order (each a complete screen, with its own layers, style, afterglow and page, covering what is below), then the host's prompts. With at least one, the shell's scene, from the bottom:

1. the shell's screen without the lines, points and circles of its 3D list; 2. the panels, farthest first by the distance from the eye in use to each panel's centre (the mean of its corners), the lower handle first where two are as far; each covers what is below; 3. the lines, points and circles of the shell's 3D list, each panel hiding what is behind it as a face of its four corners does; 4. each flat picture, in handle order; 5. the host's prompts, naming the image title of the machine that asks.

A panel shows its machine's whole screen on its front, in perspective from the eye in use: the point a fraction u along its top edge from its top left corner and v down its left edge shows the point (640u, 480v) of the machine's screen. Seen from behind it is an opaque plate of a dark colour the host chooses. Panels are cut at the near plane (z = -800) and at the edges of the shell's screen. A host that cannot draw a picture in perspective may draw each panel's picture upright instead: scaled uniformly into the bounding rectangle of the panel's projection (its part in front of the near plane) and centred; the panel still hides what it would hide. (terse-host --panels flat makes its software renderer do this.) The resolution a panel's picture is drawn at, its filtering and the smoothing of its edges are presentation.

The view

face gives the system a view: a handle, a direction (towards the glass, or back after unface), a rectangle, a start progress, a start frame and a duration. Its progress is a number from 0 (the scene as listed) to 4,096 (the panel flat on the glass). After the shell's frame with counter f, with start progress p0, start frame s and duration d, it is

    k < d:  p0 + (e - p0) * k / d, rounded towards zero
    k >= d: e        (also for d = 0)

for k = f - s (32-bit unsigned), where e is 4,096 towards the glass and 0 back. The view moves while the progress is not e.

While there is a view whose machine has a Screen in effect, everything in steps 2 and 3 above (panels, lines, points, circles and the faces that hide them) is moved by the view's transform before it is seen from the eye; the caps are counted on the list as given. Let the view's panel as listed have the centre c0, the width w0 and the orientation R0 (the rotation whose columns are the unit vectors along its top edge, down its left edge and their cross product), and let the picture of the view's rectangle be (px, py, pw, ph), with centre c1 = (px + pw/2, py + ph/2, 0). At progress p let t = p/4,096 and e = t²(3 - 2t). Then

    c = c0 + (c1 - c0) e
    w = w0 (pw/w0)^e
    R = slerp(R0, identity, e), by the shorter arc
    q goes to c + (w/w0) R R0ᵀ (q - c0)

So at progress 0 the scene is as listed, and at 4,096 the view's panel lies on the glass over the picture, upright, centred on it and as wide. The eye stays where it is, so what is not on the glass still moves with it. When the view has finished moving towards the glass its machine is shown flat, pixel for pixel as place would show it. A host that cannot animate may show every view at its end at once.

At the end of each of the shell's frames, if the view's machine is not in use, has no picture, has a rectangle that shows a picture, or has no Screen in the shell's list, the view becomes none: the scene is shown as listed at once. The view is part of the shell's state (18 bytes at the end of the machines section of the state; see State, replay and conformance).

Input

Input arrives in the shell's screen units and is routed before the shell runs, by the focus, the flat pictures and the panels as shown after the shell's last frame, seen from the eye the host draws from:

InputGoes to
Key down, key up, text, wheelthe focused machine if running; the shell if focus is 0; else nobody
Pointer over a flat picturethat machine (highest handle on overlap), mapped, if running; else nobody
Pointer over a panel's front, no flat picturenobody while the view moves; else that machine, mapped, if running; else nobody
Pointer over nothing elsethe shell, unchanged
Controllersthe focused machine (the shell if focus is 0); others read them as not connected
Content, feeds, page eventseach machine its own
Any other host inputthe shell, unchanged

The focus that routes a frame's input, the controllers included, is the one at routing: a home key changes it for the events after it, a focus call from the next frame.

A position over picture (px, py, pw, ph) maps to

    x' = floor((2(x-px)+1) * 640 / (2pw))
    y' = floor((2(y-py)+1) * 480 / (2ph))

The pointer at (x, y) is over a panel if the ray from the eye in use through the point (x + 1/2, y + 1/2, 0) meets the panel in front of the near plane (z > -800), at a fraction u along its top edge and v down its left edge (0 <= u < 1, 0 <= v < 1); of several, the one it meets nearest the eye counts. If that panel is seen from behind, the pointer is over nothing; otherwise it maps to x' = floor(640u), y' = floor(480v). The eye is an input of the shell's system, as the pointer is.

A pointer event that sets a button bit clear in the previous pointer event (wherever that went) over a flat picture, or over a panel while the view does not move, also gives the shell a machine pressed event, at the pointer event's place in the shell's input, whatever the machine's state.

The home key is one input the host reserves (F12 in terse-host, the home script line in terse run). It never reaches a machine as a key; it sets the focus to 0 and queues a home event for the shell. A single machine run alone has no home key. See events.