Vixen
02b45cc4
csharp
public sealed class SpriteSheetView

A texture with the sprites cut out of it drawn on top, and the controls that cut them.

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

Remarks

The panel a sprite sheet is sliced in. Three ways to cut — a grid by cell size, a grid by cell count, and one sprite per island of opaque texels — then the rects as boxes over the picture, a list beside it, and the selected rect's numbers underneath. What it does not have is a mode of its own: slicing writes rects onto the texture's own import settings, so this is a second view over TextureImportDocument rather than a second document over the same file. Two documents over one .meta would be two undo histories over one set of bytes, and whichever saved last would win.

⚠ It shows the picture and does not draw it, exactly as TextureImportView does and for the same reason: nothing in this assembly has a graphics device, so a texture reaches the interface as a number a UiRenderer handed out for one it uploaded. The view decodes the file — CPU work, and what the slicer needs anyway — and the application puts the number in Preview.

⚠ Every rect on the overlay is positioned inline in texels times Zoom, not by layout. A stylesheet cannot express "this box is at texel 96 of that picture", and computing it here rather than reading it back out of the layout is what lets the overlay be asserted in a test without a frame having been drawn.

⚠ Slicing is a suggestion. What it produces goes into the document as rects an author then drags, renames and deletes — the sidecar records the answer rather than the question. SpriteSlicer's own remarks say why: an automatic slice depends on the pixels, so a re-export with one frame nudged would renumber the sheet and quietly repoint every reference into it.

Fields and properties (36)

  • 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 Image Preview

    Where the texture is drawn once something has uploaded it.

  • public UiElement Canvas

    The picture and the boxes over it, sized to the texture times Zoom.

  • public IReadOnlyList<UiElement> Rects

    The boxes, one per sprite, in the document's order.

  • public UiElement List

    The sprite names, one row each.

  • public UiElement Fields

    The selected sprite's numbers.

  • public Select Method

    How the texture is cut.

  • public NumericInput CellWidth

    The cell's width, or the column count — whichever the method reads.

  • public NumericInput CellHeight

    The cell's height, or the row count.

  • public NumericInput GridOffsetX

    Where the grid starts, horizontally.

  • public NumericInput GridOffsetY

    Where the grid starts, vertically.

  • public NumericInput PaddingX

    The gap between cells, horizontally.

  • public NumericInput PaddingY

    The gap between cells, vertically.

  • public ToggleButton TrimToggle

    Whether each rect is shrunk to what is drawn inside it.

  • public ToggleButton KeepEmptyToggle

    Whether a grid keeps cells with nothing in them.

  • public Button SliceButton

    Cuts the texture with the options as they stand.

  • public Button ClearButton

    Throws every sprite away.

  • public Button AddButton

    Adds one sprite covering the whole texture, for a sheet cut by hand.

  • public Button RemoveButton

    Removes the selected sprite.

  • public Alert Unavailable

    Shown when there are no pixels to slice.

  • public TextureData? Source

    The decoded source, or if nothing could decode it.

  • public int Selected

    Which sprite is selected, or -1 for none.

  • public float Zoom

    How many screen pixels one texel takes.

  • public SpriteSliceOptions Options

    The options the toolbar is asking for.

  • public TextBox Name

    The selected sprite's name.

  • public NumericInput RectX

    Its left edge, in texels.

  • public NumericInput RectY

    Its top edge.

  • public NumericInput RectWidth

    Its width.

  • public NumericInput RectHeight

    Its height.

  • public NumericInput PivotX

    Its pivot, horizontally.

  • public NumericInput PivotY

    Its pivot, vertically.

  • public NumericInput BorderLeft

    Its nine-slice border, from the left.

  • public NumericInput BorderTop

    From the top.

  • public NumericInput BorderRight

    From the right.

  • public NumericInput BorderBottom

    From the bottom.

Events (1)

  • public Action<SpriteSheetView>? SelectionChanged

    Raised when a different sprite is selected.

Methods (6)

  • protected override void OnCreated()

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

  • public void Show(TextureImportDocument texture)

    Shows a texture's sprites.

  • public int Slice()

    Cuts the texture with the options the toolbar is asking for.

  • public void Select(int index)

    Selects a sprite, or nothing.

  • public void FitTo(float width, float height)

    Sets the zoom so that the whole texture fits inside a box.

  • public void Restate()

    Rebuilds the overlay, the list and the fields from the document as it stands.

Used by (2)

  • SpriteViewTestsVixen.Editor.AssetEditors.Tests
  • TextureImportViewVixen.Editor.AssetEditors