# `Cauldron2D.Wx.View`
[🔗](https://github.com/jaman/cauldron/blob/v0.1.3/cauldron_2d_wx/lib/cauldron_2d/wx/view.ex#L1)

A wx panel that shows a world: the canvas drawn from the sheet around the focus, the
hud beside or below it if the game sends one, the keys and the pointer as input, the
sound through the speaker.

    view = Cauldron2D.Wx.View.new(parent, keymap: keymap, steering: [:left, :right], on_over: fn over -> ... end)
    Cauldron2D.Wx.View.join(view, {:socket, url: url, token: token, topic: "world:main", params: %{}})
    Cauldron2D.Wx.View.join(view, {:local, game: MyGame.Web, world: pid, name: "alice", props: %{}})
    Cauldron2D.Wx.View.leave(view)

## Options

  * `:keymap` — wx key codes and `{:mouse, button}` to actions, as `Cauldron2D.Wx.Input.new/2` takes
  * `:steering` — the actions the pointer also drives
  * `:size` — the least the canvas is, in pixels, default `{800, 600}`; it grows with the window
  * `:scale` — pixels per sheet pixel, default `1`
  * `:hud` — where the hud rows go: `:right` (default), `:bottom`, or `:none` for no hud panel
  * `:hud_size` — the hud panel's width (right) or height (bottom) in pixels, default `300`
  * `:hud_colours` — `%{background: rgb, text: rgb}` for the hud panel, default a dark panel with light text
  * `:font` — the hud's font in points, default `12`
  * `:on_over` — called with the outcome when the round is over for this player; the
    game draws what it likes then, the canvas draws nothing of its own
  * `:on_closed` — called with the reason when the link ends
  * `:on_refused` — called with the reason when the join is refused
  * `:on_key` — called with the wx key code of a key that went down and means no action
  * `:sound` — `false` for no sound
  * `:input_every` — milliseconds between input messages, default `100`
  * `:pointer` — whether the pointer aims, default `true`; `pointer/2` changes it later
  * `:zoom` — `true` lets the player zoom: `+`/`=` in, `-` out, `0` back to the
    game's scale, the wheel either way, from a tile of 2 pixels (or the whole map in
    view, whichever is larger) to 64; `zoom/2` sets a tile size from outside.
    Default `false`. A whole map that fits in 4096 pixels a side is drawn from one
    bitmap of it at the current size, so zooming out to see all of it costs nothing
    a frame; the sheet at each size is kept for the view's life, its bitmaps in one
    table the painter reads, so a zoom never takes a sheet from under a paint in
    progress. Watching — joined with `spectate` among the link's props or params —
    the view can also be panned: the arrows and a drag with the left button move
    it, the wheel zooms about the pointer, `0` recentres it as well, and a frame
    whose subject is not the one the pan was taken on drops the pan
  * `:on_stats` — called once a second with `%{frames: n, draws: n}`, the frames
    received and the times the canvas was painted in that second
  * `:show_stats` — draw those numbers in the canvas's top left corner, default
    `false`; `show_stats/2` changes it later

The canvas is cleared to the sheet's void colour. Input goes to the link on every
change and every `:input_every` ms.

# `focus`

```elixir
@spec focus(term()) :: :ok
```

Give the canvas the keyboard.

# `join`

```elixir
@spec join(term(), {:socket | :local, keyword()}) :: :ok
```

Join a world through a link: `{:socket, opts}` or `{:local, opts}`, the options of the link module less `:owner`.

# `keymap`

```elixir
@spec keymap(term(), map()) :: :ok
```

Read keys by another keymap from now on, as `new/2`'s `:keymap`; what was held is let go.

# `leave`

```elixir
@spec leave(term()) :: :ok
```

Leave the world.

# `levels`

```elixir
@spec levels(term(), number(), number()) :: :ok
```

The effects and music levels, 0.0 to 1.0.

# `new`

```elixir
@spec new(term(), keyword()) :: term()
```

The arena panel under `parent`.

# `pause`

```elixir
@spec pause(term()) :: :ok
```

Pause or resume a world of the player's own, through the link.

# `pointer`

```elixir
@spec pointer(term(), boolean()) :: :ok
```

Whether the pointer aims from now on.

# `show_stats`

```elixir
@spec show_stats(term(), boolean()) :: :ok
```

Whether the frames and draws a second are drawn on the canvas from now on.

# `window`

```elixir
@spec window(term()) :: term()
```

The panel's wx window.

# `zoom`

```elixir
@spec zoom(term(), pos_integer()) :: :ok
```

Draw tiles `pixels` wide from now on, within the zoom's limits.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
