Documentation
¶
Overview ¶
Package viewkit holds what the wpix-editor tools that show a texture share: the texture sprite kept on screen (Texture), the frames over it with hover, selection, labels and a list to pick from (Frames), and the overlay text in window pixels (Labels). The previewers of package viewer and the sheet tool use it, so a sheet and an atlas draw their frames the same way. See doc/design/tool-shell.md#tools.
Index ¶
- Constants
- Variables
- func DrawBorder(s *toolshell.Shell, screen ebiten.FinalScreen, r gfx.Rect, c color.RGBA)
- func DrawOutline(s *toolshell.Shell, screen ebiten.FinalScreen, r gfx.Rect, c color.RGBA)
- func FrameAt(frames []Frame, p gfx.Vec2) int
- func LabelFace(px float64) *text.GoTextFace
- func PointText(p gfx.Vec2) string
- func RectText(r gfx.Rect) string
- type Frame
- type Frames
- func (f *Frames) Draw(s *toolshell.Shell, screen ebiten.FinalScreen)
- func (f *Frames) Section() toolshell.Section
- func (f *Frames) Set(id string, val json.RawMessage) (ok bool, err error)
- func (f *Frames) SetList(list []Frame)
- func (f *Frames) Shown() (Frame, bool)
- func (f *Frames) Update(s *toolshell.Shell)
- type LabelMode
- type Labels
- type Texture
- func (t *Texture) Close(s *toolshell.Shell)
- func (t *Texture) Entity() ecs.Entity
- func (t *Texture) SetSprite(s *toolshell.Shell, h gfx.SpriteHandle)
- func (t *Texture) Size(s *toolshell.Shell) gfx.Vec2
- func (t *Texture) Spawn(s *toolshell.Shell, h gfx.SpriteHandle)
- func (t *Texture) Sync(s *toolshell.Shell)
Constants ¶
const FrameRows = 8
FrameRows is the rows the frame list shows before it scrolls.
const LabelSize = 13
LabelSize is the size of the overlay text in device-independent pixels; the cache multiplies it by the display's scale factor.
const MinLabelPx = 24
MinLabelPx is the least width, in device-independent pixels, of a box that gets its label without being hovered or selected; smaller boxes would only be covered by their labels.
Variables ¶
var DeviceScale = func() float64 { if m := ebiten.Monitor(); m != nil { return max(m.DeviceScaleFactor(), 1) } return 1 }
DeviceScale is the display's scale factor (devicePixelRatio in a browser), at least 1: window pixels are device pixels. It is a variable so tests can set it: the real lookup (ebiten.Monitor) initializes the windowing system, which a headless test has no display for.
var LabelModeNames = []string{"Index and name", "Index", "Name", "None"}
LabelModeNames are the entries of the Labels dropdown.
Functions ¶
func DrawBorder ¶
DrawBorder draws a one pixel border in c just outside the world rectangle r, in window pixels.
func DrawOutline ¶
DrawOutline draws a one pixel outline in c along the inside of the window rectangle r.
func FrameAt ¶
FrameAt returns the index in frames of the frame under texture point p, or -1. Where frames overlap (a packer may share pixels) the smallest wins, so a small frame inside a big one can still be picked.
func LabelFace ¶
func LabelFace(px float64) *text.GoTextFace
LabelFace is the face of the overlay text at size px: Go Regular, so it needs no file.
Types ¶
type Frame ¶
type Frame struct {
// Index is the position in the atlas's file order.
Index int
// Name is the key of the frame ("idle_0", "3").
Name string
// Rect is the frame's pixels in the texture.
Rect gfx.Rect
// Size is the untrimmed size, Offset where the trimmed image starts in
// it, and Pivot the default pivot in untrimmed pixels.
Size, Offset, Pivot gfx.Vec2
}
Frame is one frame of an atlas or a sheet as a tool shows it.
type Frames ¶
type Frames struct {
// Prefix starts the ids of the widgets ("atlas", "sheet").
Prefix string
// List is the frames in file order.
List []Frame
// Hover and Sel index List, -1 for none.
Hover, Sel int
// Mode is what each frame is labelled with.
Mode LabelMode
// MinPx is the narrowest frame, in window pixels, that Draw outlines
// (the hovered and the selected one always are); 0 means 3. Below it
// the outlines are only a smudge.
MinPx float32
// contains filtered or unexported fields
}
Frames is the frames over a texture as a tool shows them: every frame outlined and labelled, the one under the mouse and the selected one highlighted, and a left section with the label mode and a list to pick a frame from. Its widget ids are Prefix + ".labels" and Prefix + ".frame".
func NewFrames ¶
NewFrames returns frames with the widget id prefix and nothing hovered or selected.
func (*Frames) Draw ¶
func (f *Frames) Draw(s *toolshell.Shell, screen ebiten.FinalScreen)
Draw outlines the frames on screen and labels those wide enough, then highlights the hovered and the selected frame with their full label.
func (*Frames) Section ¶
Section is the left section to pick frames from: the label mode and the list of frames, "(none)" first (index 0 clears the selection).
func (*Frames) SetList ¶
SetList replaces the frames (a reload) and keeps the selection while it still exists.
type LabelMode ¶
type LabelMode int
LabelMode says what a tool writes on each frame.
The label modes, in the order of the panel's dropdown.
type Labels ¶
type Labels struct {
// contains filtered or unexported fields
}
Labels renders overlay text once; the zero value is ready to use. The shell draws overlays on a FinalScreen, which text.Draw cannot target, so each string becomes a small image drawn with DrawImage. The final screen is in device pixels, so on a HiDPI display (scale 2) text of LabelSize device pixels would show at half its size: the cache renders at LabelSize times the scale, and starts over when the scale changes (the window moved to another display).
func (*Labels) Draw ¶
func (c *Labels) Draw(screen ebiten.FinalScreen, s string, x, y float32)
Draw puts the label at window pixel (x, y), its top-left corner.
func (*Labels) Fits ¶
Fits reports whether the label for s fits in a box w window pixels wide that is also at least MinLabelPx device-independent pixels wide.
type Texture ¶
type Texture struct {
// Sprite is the texture shown, the zero handle for none.
Sprite gfx.SpriteHandle
// contains filtered or unexported fields
}
Texture is one texture shown as a sprite entity with its top-left corner at world (0, 0), so a world point is a texture pixel. The zero value shows nothing until Texture.Spawn.
func (*Texture) Entity ¶
Entity is the sprite entity, for tools that set more of its Sprite (a shader and its Params).
func (*Texture) SetSprite ¶
func (t *Texture) SetSprite(s *toolshell.Shell, h gfx.SpriteHandle)
SetSprite shows h instead of the current texture.
func (*Texture) Size ¶
Size reads the texture's size from the asset store, which a hot reload can change; zero without a texture.
func (*Texture) Spawn ¶
func (t *Texture) Spawn(s *toolshell.Shell, h gfx.SpriteHandle)
Spawn creates the sprite entity for h. Call it once; Texture.SetSprite changes the texture later.
func (*Texture) Sync ¶
Sync keeps the texture visible; call it from the tool's toolshell.Syncer. The engine culls a sprite by its position alone, so a texture whose top-left corner left the screen would vanish while most of it is still visible. The sprite is instead pinned at the center of the part of the texture that is on screen, with its pivot set so the texture stays where it is.