firefly

package
v0.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 5 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// The screen width in pixels.
	Width = 240

	// The screen height in pixels.
	Height = 160
)
View Source
const (
	// The lowest possible value for [Pad.X].
	PadMinX = -1000

	// The lowest possible value for [Pad.Y].
	PadMinY = -1000

	// The highest possible value for [Pad.X].
	PadMaxX = 1000

	// The highest possible value for [Pad.Y].
	PadMaxY = 1000
)

Variables

View Source
var (
	// Callback to be called once when the app starts.
	//
	// Called after memory is initialized and host functions are registered
	// but before any other callback.
	Boot func()

	// Callback to be called on every update.
	//
	// Don't use it to draw on the screen, use [Render] instead.
	Update func()

	// Callback to be called before rendering the frame.
	//
	// Don't use it to update the state, use [Update] instead.
	Render func()

	// Callback to be called before exiting the app.
	BeforeExit func()

	// Callback to be called when a cheat code is sent from firefly CLI.
	//
	// Accepts the command index and value and returns a response to show in CLI.
	Cheat func(int, int) int
)
View Source
var Combined = Peer{0xFF}

A combination of all connected peers.

Can be passed in functions like ReadPad and ReadButtons to get the combined input of all peers.

Useful for single-player games that want in multiplayer to handle inputs from all devices as one input.

Functions

func AddScore added in v0.7.0

func AddScore(p Peer, b Board, v int16) int16

Add the given score to the board.

May be negative if you want the lower scores to rank higher. Zero value is not added to the board.

If the Peer is Combined, the score is added for every peer and the returned value is the lowest of their best scores.

func ClearScreen

func ClearScreen(c Color)

Fill the whole frame with the given color.

func DrawArc

func DrawArc(p Point, d int, start, sweep Angle, s Style)

Draw an arc.

func DrawCircle

func DrawCircle(p Point, d int, s Style)

Draw a circle with the given diameter.

func DrawEllipse

func DrawEllipse(p Point, b Size, s Style)

Draw an ellipse (oval).

func DrawImage

func DrawImage(i Image, p Point)

Render an image at the given point.

func DrawLine

func DrawLine(a, b Point, s LineStyle)

Draw a straight line from point a to point b.

func DrawPoint

func DrawPoint(p Point, c Color)

Set a single point (1 pixel is scaling is 1) on the frame.

func DrawQR added in v0.9.0

func DrawQR(t string, p Point, black, white Color)

Render a QR code for the given text.

func DrawQRBytes added in v0.11.0

func DrawQRBytes(t []byte, p Point, black, white Color)

Render a QR code for the given text byte slice.

Input slice must be valid UTF-8 formatted (without BOM).

Useful when you are building strings in a byte array or slice, such as via a bytes.Buffer. This function allows you to use such content without allocating a new string.

It is allowed to modify the byte slice after the function call.

func DrawRect

func DrawRect(p Point, b Size, s Style)

Draw a rectangle filling the given bounding box.

func DrawRoundedRect

func DrawRoundedRect(p Point, b, c Size, s Style)

Draw a rectangle with rounded corners.

func DrawSector

func DrawSector(p Point, d int, start, sweep Angle, s Style)

Draw a sector.

func DrawSubImage

func DrawSubImage(i SubImage, p Point)

Draw a subregion of an image.

Most often used to draw a sprite from a sprite atlas.

func DrawText

func DrawText(t string, f Font, p Point, c Color)

Render text using the given font.

Unlike in the other drawing functions, here Point points not to the top-left corner but to the baseline start position.

func DrawTextBytes added in v0.11.0

func DrawTextBytes(t []byte, f Font, p Point, c Color)

Render text using the given font.

Unlike in the other drawing functions, here Point points not to the top-left corner but to the baseline start position.

Input slice must be valid UTF-8 formatted (without BOM).

Useful when you are building strings in a byte array or slice, such as via a bytes.Buffer. This function allows you to use such content without allocating a new string.

It is allowed to modify the byte slice after the function call.

func DrawTriangle

func DrawTriangle(a, b, c Point, s Style)

Draw a triangle.

The order of points doesn't matter.

func DumpFile added in v0.6.0

func DumpFile(path string, raw []byte)

Write a file into the app data dir.

func FileExists added in v0.9.2

func FileExists(path string) bool

Check if the given file exists.

func GetFileSize added in v0.9.5

func GetFileSize(path string) int

Get size (in bytes) of the given file.

func GetName added in v0.8.1

func GetName(p Peer) string

Get human-readable name of the given peer.

func GetRandom

func GetRandom() uint32

Get a random value.

func GetScore added in v0.7.0

func GetScore(p Peer, b Board) int16

Get the personal best of the player.

func LogDebug

func LogDebug(t string)

Log a debug message.

func LogDebugBytes added in v0.11.0

func LogDebugBytes(t []byte)

Log a debug message from byte slice.

Input slice must be valid UTF-8 formatted (without BOM).

Useful when you are building strings in a byte array or slice, such as via a bytes.Buffer. This function allows you to use such content without allocating a new string.

It is allowed to modify the byte slice after the function call.

func LogError

func LogError(t string)

Log an error message.

func LogErrorBytes added in v0.11.0

func LogErrorBytes(t []byte)

Log an error message from byte slice.

Input slice must be valid UTF-8 formatted (without BOM).

Useful when you are building strings in a byte array or slice, such as via a bytes.Buffer. This function allows you to use such content without allocating a new string.

It is allowed to modify the byte slice after the function call.

func Quit

func Quit()

Exit the app after the current update is finished.

func RemoveFile added in v0.6.0

func RemoveFile(path string)

Remove a file from the app data dir.

func Restart added in v0.3.0

func Restart()

Restart the app.

func SaveStash added in v0.8.0

func SaveStash(p Peer, b Stash)

Save the given Stash.

When called, the stash for the given peer will be stored in RAM. Calling LoadStash for the same peer will return that stash. On exit, the runtime will persist the stash in FS. Next time the app starts, calling LoadStash will restore the stash saved earlier.

func SetCanvas added in v0.6.0

func SetCanvas(c Canvas)

Set the target image for all subsequent drawing operations.

func SetColor

func SetColor(c Color, v RGB)

Set a color value in the palette.

func SetPalette added in v0.9.4

func SetPalette(colors [16]RGB)

Set all colors in the color palette.

func SetSeed

func SetSeed(seed uint32)

Set the seed used to generate random values.

func UnsetCanvas added in v0.6.0

func UnsetCanvas()

Make all subsequent drawing operations target the screen instead of a canvas.

Cancels the effect of SetCanvas.

Types

type Angle

type Angle struct {
	// contains filtered or unexported fields
}

An angle between two vectors.

Used by DrawArc and DrawSector. Constructed by [Dagrees] and Radians.

func Degrees

func Degrees(a float32) Angle

Define an angle in radians where 360.0 is the full circle.

func Radians

func Radians(a float32) Angle

Define an angle in radians where Tau (doubled Pi) is the full circle.

func (Angle) Add added in v0.9.4

func (a Angle) Add(r Angle) Angle

func (Angle) Degrees

func (a Angle) Degrees() float32

Get the angle value in degrees.

func (Angle) Neg added in v0.9.4

func (a Angle) Neg() Angle

func (Angle) Normalize added in v0.9.4

func (a Angle) Normalize() Angle

Ensure the angle is on the 0°-360° range.

func (Angle) Radians

func (a Angle) Radians() float32

Get the angle value in radians.

func (Angle) Sub added in v0.9.4

func (a Angle) Sub(r Angle) Angle

type AnyPeer added in v0.12.0

type AnyPeer interface {
	// contains filtered or unexported methods
}

A peer obtained either from Peers (GetPeers) or from GetMe.

type Atlas added in v0.11.0

type Atlas struct {
	// contains filtered or unexported fields
}

Helper for working with spritesheets.

Constructed by NewAtlas.

func NewAtlas added in v0.11.0

func NewAtlas(spriteW, spriteH int) Atlas

Create a new Atlas with the given sprite dimensions.

func (*Atlas) Load added in v0.11.0

func (a *Atlas) Load(path string)

Set the underlying spritesheet image for the atlas.

Should be called before any Sprite.Draw. The best is to call it once from Boot.

func (*Atlas) Sprite added in v0.11.0

func (a *Atlas) Sprite(row, col int) Sprite

Create a reference to a sprite within the atlas.

type Badge added in v0.7.0

type Badge uint8

A badge (aka achievement) ID.

type Board added in v0.7.0

type Board uint8

A board (aka score board / leader board) ID.

type Buttons

type Buttons struct {
	// South. The bottom button, like A on the X-Box controller.
	//
	// Typically used for confirmation, main action, jump, etc.
	S bool

	// East. The right button, like B on the X-Box controller.
	//
	// Typically used for cancellation, going to previous screen, etc.
	E bool

	// West. The left button, like X on the X-Box controller.
	//
	// Typically used for attack.
	W bool

	// North. The top button, like Y on the X-Box controller.
	//
	// Typically used for a secondary action, like charged attack.
	N bool

	// The menu button, almost always handled by the runtime.
	Menu bool
}

State of the buttons.

func ReadButtons

func ReadButtons(p Peer) Buttons

Get the currently pressed buttons.

The peer can be Combined or one of the GetPeers.

func (Buttons) Any added in v0.10.0

func (p Buttons) Any() bool

Check if any button is currently pressed.

func (Buttons) Held

func (p Buttons) Held(old Buttons) Buttons

Given the old state, get buttons that were pressed and are still pressed now.

func (Buttons) JustPressed

func (p Buttons) JustPressed(old Buttons) Buttons

Given the old state, get buttons that were not pressed but are pressed now.

func (Buttons) JustReleased

func (p Buttons) JustReleased(old Buttons) Buttons

Given the old state, get buttons that were pressed but aren't pressed now.

type Canvas added in v0.6.0

type Canvas struct {
	// contains filtered or unexported fields
}

Canvas is an Image that can be drawn upon.

Constructed by NewCanvas.

func NewCanvas added in v0.6.0

func NewCanvas(s Size) Canvas

func (Canvas) Image added in v0.6.0

func (c Canvas) Image() Image

Represent the canvas as an Image.

func (Canvas) Set added in v0.9.2

func (c Canvas) Set()

Set this canvas as the target for all subsequent draw operations.

type Color

type Color uint8

A pointer to a color in the color palette.

const (
	// No color (100% transparency). Default.
	ColorNone Color = 0
	// Black color: #1A1C2C.
	ColorBlack Color = 1
	// Purple color: #5D275D.
	ColorPurple Color = 2
	// Red color: #B13E53.
	ColorRed Color = 3
	// Orange color: #EF7D57.
	ColorOrange Color = 4
	// Yellow color: #FFCD75.
	ColorYellow Color = 5
	// Light green color: #A7F070.
	ColorLightGreen Color = 6
	// Green color: #38B764.
	ColorGreen Color = 7
	// Dark green color: #257179.
	ColorDarkGreen Color = 8
	// Dark blue color: #29366F.
	ColorDarkBlue Color = 9
	// Blue color: #3B5DC9.
	ColorBlue Color = 10
	// Light blue color: #41A6F6.
	ColorLightBlue Color = 11
	// Cyan color: #73EFF7.
	ColorCyan Color = 12
	// White color: #F4F4F4.
	ColorWhite Color = 13
	// Light gray color: #94B0C2.
	ColorLightGray Color = 14
	// Gray color: #566C86.
	ColorGray Color = 15
	// Dark gray color: #333C57.
	ColorDarkGray Color = 16
)

func (Color) String added in v0.11.0

func (color Color) String() string

Get the color name in the default palette (SWEETIE-16).

Implements fmt.Stringer.

type DPad4 added in v0.10.0

type DPad4 uint8

4-directional DPad-like representation of the Pad.

Constructed with Pad.DPad4. Useful for simple games and ports. The middle of the pad is a "dead zone" pressing which will not activate any direction.

Implements all the same methods as DPad8.

const (
	DPad4None  DPad4 = 0
	DPad4Right DPad4 = 1
	DPad4Up    DPad4 = 2
	DPad4Left  DPad4 = 3
	DPad4Down  DPad4 = 4
)

Possible directions for DPad4.

func (DPad4) Any added in v0.10.0

func (p DPad4) Any() bool

func (DPad4) Held added in v0.10.0

func (p DPad4) Held(old DPad4) DPad4

func (DPad4) JustPressed added in v0.10.0

func (p DPad4) JustPressed(old DPad4) DPad4

func (DPad4) JustReleased added in v0.10.0

func (p DPad4) JustReleased(old DPad4) DPad4

type DPad8 added in v0.10.0

type DPad8 struct {
	Left  bool
	Right bool
	Up    bool
	Down  bool
}

8-directional DPad-like representation of the Pad.

Constructed with Pad.DPad8. Useful for simple games and ports. The middle of the pad is a "dead zone" pressing which will not activate any direction.

Invariant: it's not possible for opposite directions (left and right, or down and up) to be active at the same time. However, it's possible for neighboring directions (like up and right) to be active at the same time if the player presses a diagonal.

Implements all the same methods as DPad4.

func (DPad8) Any added in v0.10.0

func (p DPad8) Any() bool

func (DPad8) Held added in v0.10.0

func (p DPad8) Held(old DPad8) DPad8

Given the old state, get directions that were pressed and are still pressed now.

func (DPad8) JustPressed added in v0.10.0

func (p DPad8) JustPressed(old DPad8) DPad8

Given the old state, get directions that were not pressed but are pressed now.

func (DPad8) JustReleased added in v0.10.0

func (p DPad8) JustReleased(old DPad8) DPad8

Given the old state, get directions that were pressed but aren't pressed now.

type File

type File []byte

A file loaded from the filesystem.

func LoadFile added in v0.6.0

func LoadFile(path string, buf []byte) File

Read a file.

It will first lookup file in the app's ROM directory and then check the app writable data directory.

If the file does not exist, the Raw value of the returned File will be nil.

The second argument is the buffer in which the file should be loaded. If the buffer is smaller than the file content, it gets cut. If the buffer is nil, a new buffer of sufficient size will be allocated.

func (File) Bytes added in v0.11.0

func (f File) Bytes() []byte

func (File) Exists added in v0.9.2

func (f File) Exists() bool

Check if the file was loaded.

func (File) Font

func (f File) Font() Font

Convert the File to a Font.

func (File) Image

func (f File) Image() Image

Convert the File to an Image.

func (File) Must added in v0.8.0

func (f File) Must() File

Ensure that the loaded file exists.

type Font

type Font struct {
	// contains filtered or unexported fields
}

A loaded font file.

Can be loaded using LoadFile.

func LoadFont added in v0.9.2

func LoadFont(path string, buf []byte) Font

Load the given file as a font.

func (Font) CharHeight added in v0.9.3

func (f Font) CharHeight() int

Character height.

func (Font) CharWidth added in v0.9.3

func (f Font) CharWidth() int

Character width.

func (Font) Draw added in v0.9.2

func (f Font) Draw(t string, p Point, c Color)

Render the given text.

func (Font) DrawBytes added in v0.11.0

func (f Font) DrawBytes(t []byte, p Point, c Color)

Render the given text bytes.

Input slice must be valid UTF-8 formatted (without BOM).

Useful when you are building strings in a byte array or slice, such as via a bytes.Buffer. This function allows you to use such content without allocating a new string.

It is allowed to modify the byte slice after the function call.

func (Font) IsASCII added in v0.9.3

func (f Font) IsASCII() bool

If the font is for ASCII encoding (English alphabet).

func (Font) LineWidth added in v0.9.3

func (f Font) LineWidth(t string) int

Calculate width (in pixels) of the given text.

This function does not account for newlines.

type Image

type Image struct {
	// contains filtered or unexported fields
}

A loaded image file.

Can be loaded using LoadFile.

func LoadImage added in v0.9.2

func LoadImage(path string, buf []byte) Image

Load the given file as an image.

func (Image) Draw added in v0.9.2

func (i Image) Draw(p Point)

Render the image.

func (Image) GetPixel added in v0.11.0

func (i Image) GetPixel(point Point) Color

Get color of a pixel in the image.

Returns ColorNone if out of bounds.

func (Image) Height added in v0.6.0

func (i Image) Height() int

The image height in pixels.

func (Image) Pixels added in v0.6.0

func (i Image) Pixels() int

The number of pixels the image has.

func (Image) SetTransparency added in v0.6.0

func (i Image) SetTransparency(c Color)

Set the color that should represent transparency.

Pass ColorNone to disable transparency.

func (Image) Size added in v0.6.0

func (i Image) Size() Size

The image size in pixels.

func (Image) Sub

func (i Image) Sub(p Point, s Size) SubImage

Get a rectangle subregion of the image.

func (Image) Transparency added in v0.6.0

func (i Image) Transparency() Color

The color used for transparency. If no transparency, returns ColorNone.

func (Image) Width added in v0.6.0

func (i Image) Width() int

The image width in pixels.

type Language added in v0.11.0

type Language uint16
const (
	English   Language = 0x656e // en 🇬🇧 💂
	Dutch     Language = 0x6e6c // nl 🇳🇱 🧀
	French    Language = 0x6672 // fr 🇫🇷 🥐
	German    Language = 0x6465 // de 🇩🇪 🥨
	Italian   Language = 0x6974 // it 🇮🇹 🍕
	Polish    Language = 0x706c // pl 🇵🇱 🥟
	Romanian  Language = 0x726f // ro 🇷🇴 🧛
	Russian   Language = 0x7275 // ru 🇷🇺 🪆
	Spanish   Language = 0x6573 // es 🇪🇸 🐂
	Swedish   Language = 0x7376 // sv 🇸🇪 ❄️
	Turkish   Language = 0x7472 // tr 🇹🇷 🕌
	Ukrainian Language = 0x756b // uk 🇺🇦 ✊
	TokiPona  Language = 0x7470 // tp 🇨🇦 🙂
)

func (Language) Code added in v0.11.0

func (lang Language) Code() string

func (Language) Encoding added in v0.11.0

func (lang Language) Encoding() string

func (Language) NameEnglish added in v0.11.0

func (lang Language) NameEnglish() string

func (Language) NameNative added in v0.11.0

func (lang Language) NameNative() string

type LineStyle

type LineStyle struct {
	Color Color
	Width int
}

The same as Style but without a fill color (only stroke color and width).

func L added in v0.9.4

func L(c Color, w int) LineStyle

A shortcut for creating a new LineStyle.

func (LineStyle) Draw added in v0.9.2

func (s LineStyle) Draw(a, b Point)

Draw a line from a to b.

type Me added in v0.12.0

type Me struct {
	// contains filtered or unexported fields
}

The peer representing the current device.

Can be compared to Peer (using Me.Eq) or used to GetSettings.

**IMPORTANT:** Using this type may cause state drift between device in multiplayer. See the docs for more info.

func GetMe added in v0.3.0

func GetMe() Me

Get the peer corresponding to the local device.

func (Me) Eq added in v0.12.0

func (me Me) Eq(peer Peer) bool

Check if the given Peer represents the current device.

type Pad

type Pad struct {
	X int
	Y int
}

A finger position on the touch pad.

Both X and Y are somewhere the range between -1000 and 1000 (both ends included). The 1000 X is on the right, the 1000 Y is on the top.

func ReadPad

func ReadPad(p Peer) (Pad, bool)

Get the current touch pad state.

The peer can be Combined or one of the GetPeers.

func (Pad) Azimuth

func (p Pad) Azimuth() Angle

The angle of the polar coordinate of the touch point.

  • (Pad{X: 1, Y: 0}).Azimuth() == Degrees(0)
  • (Pad{X: 0, Y: 1}).Azimuth() == Degrees(90)
  • (Pad{X: -1, Y: 0}).Azimuth() == Degrees(180)
  • (Pad{X: 0, Y: -1}).Azimuth() == Degrees(270)

func (Pad) DPad4 added in v0.10.0

func (p Pad) DPad4() DPad4

Convert the Pad into DPad4.

func (Pad) DPad8 added in v0.10.0

func (p Pad) DPad8() DPad8

Convert the Pad into DPad8.

func (Pad) Point

func (p Pad) Point() Point

Convert the Pad into Point.

func (Pad) Radius

func (p Pad) Radius() float32

The distance from the pad center to the touch point.

func (Pad) RadiusSquared added in v0.11.0

func (p Pad) RadiusSquared() int

Radius returns the squared distance from the pad center to the touch point, which is simpler to calculate, and guarantees that the return value is an integer.

func (Pad) Size

func (p Pad) Size() Size

Convert the Pad into Size.

type Peer added in v0.3.0

type Peer struct {
	// contains filtered or unexported fields
}

The peer ID.

Can be obtained by getting the list of Peers using GetPeers and then iterating over it.

func (Peer) Eq added in v0.12.0

func (peer Peer) Eq(other Peer) bool

Check if the given peers represent the same device.

type Peers added in v0.3.0

type Peers uint32

The list of peers online.

Can be obtained using GetPeers.

func GetPeers added in v0.3.0

func GetPeers() Peers

Get the list of peers that are currently online.

Includes the local device.

It can be used to detect if multiplayer is active: if there is more than 1 peer, you're playing with friends.

func (Peers) Contains added in v0.9.5

func (peers Peers) Contains(peer Peer) bool

Check if the given Peer is online.

func (Peers) Iter added in v0.8.1

func (peers Peers) Iter() iter.Seq[Peer]

Iterate over all peers that are online.

Uses the iterators API introduced in Go 1.23.

func (Peers) Len added in v0.3.0

func (peers Peers) Len() int

Get how many peers are online.

func (Peers) Slice added in v0.3.0

func (peers Peers) Slice() []Peer

Get the slice of all peers that are online.

type Point

type Point struct {
	X int
	Y int
}

A point on the screen.

Typically, the upper-left corner of a bounding box of a shape.

func P added in v0.9.2

func P(x, y int) Point

Shortcut for creating a Point.

func (Point) Abs

func (p Point) Abs() Point

Set X and Y to their absolute (non-negative) value.

func (Point) Add

func (p Point) Add(r Point) Point

Add together two points.

func (Point) ComponentMax

func (p Point) ComponentMax(r Point) Point

Set both X and Y to their maximum in the two given points.

func (Point) ComponentMin

func (p Point) ComponentMin(r Point) Point

Set both X and Y to their minimum in the two given points.

func (Point) Draw added in v0.9.2

func (p Point) Draw(c Color)

Render a single pixel.

func (Point) InBounds added in v0.9.2

func (p Point) InBounds() bool

Check if the point is within the screen boundaries.

func (Point) Pad

func (p Point) Pad() Pad

Convert the Point to a Pad.

func (Point) Size

func (p Point) Size() Size

Convert the Point to a Size.

func (Point) Sub

func (p Point) Sub(r Point) Point

Subtract the given point from the current one.

type Progress added in v0.7.0

type Progress struct {
	// How many points the player already has.
	Done uint16
	// How many points the player needs to earn the badge.
	Goal uint16
}

func AddProgress added in v0.7.0

func AddProgress(p Peer, b Badge, v int16) Progress

Add the given value to the progress for the badge.

May be negative if you want to decrease the progress. If zero, does not change the progress.

If the Peer is Combined, the progress is added to every peer and the returned value is the lowest progress.

func GetProgress added in v0.7.0

func GetProgress(p Peer, b Badge) Progress

Get the progress of earning the badge.

func (Progress) Earned added in v0.7.0

func (p Progress) Earned() bool

True if the player got enough points to unlock the badge.

type RGB

type RGB struct {
	// Red component
	R uint8
	// Green component
	G uint8
	// Blue component
	B uint8
}

The RGB value of a color in the palette.

func NewRGB added in v0.9.5

func NewRGB(r, g, b uint8) RGB

type Settings added in v0.11.0

type Settings struct {
	// The preferred color scheme of the player.
	Theme Theme

	// The configured interface language.
	Language Language

	// If true, the screen is rotated 180 degrees.
	//
	// In other words, the player holds the device upside-down.
	// The touchpad is now on the right and the buttons are on the left.
	RotateScreen bool

	// The player has photosensitivity. The app should avoid any rapid flashes.
	ReduceFlashing bool

	// The player wants increased contrast for colors.
	//
	// If set, the black and white colors in the default
	// palette are adjusted automatically. All other colors
	// in the default palette or all colors in a custom palette
	// should be adjusted by the app.
	Contrast bool

	// If true, the player wants to see easter eggs, holiday effects, and weird jokes.
	EasterEggs bool
}

func GetSettings added in v0.11.0

func GetSettings(p AnyPeer) Settings

Get the peer's system settings.

IMPORTANT: This is the only function that accepts as input not only Peer but also Me, which might lead to a state drift if used incorrectly. See the docs for more info.

type Size

type Size struct {
	// W is the width of the bounding box.
	W int
	// H is the height of the bounding box.
	H int
}

Size of a bounding box for a shape.

The width and height must be positive.

func S added in v0.9.2

func S(w, h int) Size

Shortcut for creating a Size.

func (Size) Abs

func (s Size) Abs() Size

Set W and H to their absolute (non-negative) value.

func (Size) Add

func (s Size) Add(r Size) Size

Add two sizes.

func (Size) ComponentMax

func (s Size) ComponentMax(r Size) Size

Set both W and H to their maximum in the two given sizes.

func (Size) ComponentMin

func (s Size) ComponentMin(r Size) Size

Set both W and H to their minimum in the two given sizes.

func (Size) Pad

func (s Size) Pad() Pad

Convert the Size to a Pad.

func (Size) Point

func (s Size) Point() Point

Convert the Size to a Point.

func (Size) Sub

func (s Size) Sub(r Size) Size

Subtract the given size from the current one.

type Sprite added in v0.11.0

type Sprite struct {
	// contains filtered or unexported fields
}

func (Sprite) Draw added in v0.11.0

func (s Sprite) Draw(p Point)

Render the sprite at the given position.

Make sure to call Atlas.Load first.

type Stash added in v0.8.0

type Stash = []byte

Stash is a serialized binary state of the app that you want to persist between app runs and to be available in multiplayer.

For single-player purposes, you can save data in a regular file using DumpFile. File saved that way can be bigger (and you can create lots of them) but it cannot be accessed in multiplayer.

It's your job to serialize data into a binary stash and later parse it. Stash can be saved using SaveStash and later read using LoadStash.

func LoadStash added in v0.8.0

func LoadStash(p Peer, buf []byte) Stash

Load Stash saved earlier (in this or previous run) by SaveStash.

The buffer should be big enough to fit the stash. If it's not, the stash will be truncated. If there is no stash or it's empty, nil is returned.

If the given buffer is nil, a new buffer will be allocated big enough to fit the biggest allowed stash. At the moment, it is 80 bytes.

type Style

type Style struct {
	// The color to use to fill the shape.
	FillColor Color

	// The color to use for the shape stroke.
	StrokeColor Color

	// The width of the shape stroke.
	//
	// If zero, a solid shape without a stroke will be drawn.
	StrokeWidth int
}

Style of a shape.

func Outlined added in v0.9.2

func Outlined(c Color, width int) Style

Make Style for an outlined shape (without fill).

func Solid added in v0.9.2

func Solid(c Color) Style

Make Style for a solid shape (without stroke).

func (Style) LineStyle

func (s Style) LineStyle() LineStyle

Convert the Style to a LineStyle.

LineStyle is the same as Style except it doesn't have a fill color.

type SubImage

type SubImage struct {
	// contains filtered or unexported fields
}

A subregion of an image. Constructed using Image.Sub.

func (SubImage) Draw added in v0.9.2

func (i SubImage) Draw(p Point)

Render the sub image at the given point.

func (SubImage) Height added in v0.11.0

func (i SubImage) Height() int

Height returns the height of this sub-image.

func (SubImage) Image added in v0.11.0

func (i SubImage) Image() Image

Image returns back the original parent Image from which this sub-image was created from.

func (SubImage) Point added in v0.11.0

func (i SubImage) Point() Point

Point returns the offset of this sub-image in the parent Image.

func (SubImage) Size added in v0.11.0

func (i SubImage) Size() Size

Size returns the size of this sub-image.

func (SubImage) Width added in v0.11.0

func (i SubImage) Width() int

Width returns the width of this sub-image.

type Theme added in v0.11.0

type Theme struct {
	ID uint8
	// The main color of text and boxes.
	Primary Color
	// The color of disable options, muted text, etc.
	Secondary Color
	// The color of important elements, active options, etc.
	Accent Color
	// The background color, the most contrast color to primary.
	BG Color
}

Directories

Path Synopsis
Structs for working with shapes as values.
Structs for working with shapes as values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL