core

package
v0.0.0-...-ba0b20d Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ColorBlack       = Color{0, 0, 0, 255}
	ColorWhite       = Color{255, 255, 255, 255}
	ColorRed         = Color{255, 0, 0, 255}
	ColorGreen       = Color{0, 255, 0, 255}
	ColorBlue        = Color{0, 0, 255, 255}
	ColorGray        = Color{128, 128, 128, 255}
	ColorLightGray   = Color{200, 200, 200, 255}
	ColorDarkGray    = Color{64, 64, 64, 255}
	ColorTransparent = Color{0, 0, 0, 0}
)

Common colors

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	Width  int
	Height int
	Stride int
	Format PixelFormat
	Data   []byte
	// contains filtered or unexported fields
}

Buffer represents a pixel buffer for drawing.

func NewBuffer

func NewBuffer(width, height int) *Buffer

NewBuffer creates a new buffer with the given dimensions (BGRA format).

func (*Buffer) Blit

func (b *Buffer) Blit(src *Buffer, x, y int)

Blit copies a source buffer onto this buffer at the given position.

func (*Buffer) BlitOpaque

func (b *Buffer) BlitOpaque(src *Buffer, x, y int)

BlitOpaque copies a source buffer onto this buffer, treating all pixels as fully opaque.

func (*Buffer) BlitOpaqueRect

func (b *Buffer) BlitOpaqueRect(src *Buffer, srcRect Rect, x, y int)

BlitOpaqueRect copies a region of a source buffer onto this buffer, treating all source pixels as fully opaque.

func (*Buffer) BlitRect

func (b *Buffer) BlitRect(src *Buffer, srcRect Rect, x, y int)

BlitRect copies a region of a source buffer onto this buffer.

func (*Buffer) BlitScaled

func (b *Buffer) BlitScaled(src *Buffer, srcRect, dstRect Rect)

BlitScaled copies a rectangular region of a source buffer onto this buffer, scaling to fit the destination rectangle using bilinear sampling.

func (*Buffer) Clear

func (b *Buffer) Clear(c Color)

Clear fills the entire buffer with a color.

func (*Buffer) ClearClip

func (b *Buffer) ClearClip()

ClearClip removes any active drawing clip.

func (*Buffer) Clip

func (b *Buffer) Clip() (Rect, bool)

Clip returns the active clip rectangle and whether clipping is enabled.

func (*Buffer) DrawLine

func (b *Buffer) DrawLine(x0, y0, x1, y1 int, c Color)

DrawLine draws a line between two points using Bresenham's algorithm.

func (*Buffer) DrawRect

func (b *Buffer) DrawRect(r Rect, c Color)

DrawRect draws a rectangle outline with a color.

func (*Buffer) DrawRoundedRect

func (b *Buffer) DrawRoundedRect(r Rect, radius int, c Color)

DrawRoundedRect draws a rounded rectangle outline.

func (*Buffer) FillRect

func (b *Buffer) FillRect(r Rect, c Color)

FillRect fills a rectangle with a color.

func (*Buffer) FillRoundedRect

func (b *Buffer) FillRoundedRect(r Rect, radius int, c Color)

FillRoundedRect fills a rectangle with rounded corners.

func (*Buffer) GetPixel

func (b *Buffer) GetPixel(x, y int) Color

GetPixel returns the color at the given coordinates.

func (*Buffer) Resize

func (b *Buffer) Resize(width, height int)

Resize resizes the buffer, reusing the backing memory when capacity allows.

func (*Buffer) SetClip

func (b *Buffer) SetClip(r Rect)

SetClip restricts subsequent drawing operations to the given rectangle. The clip is intersected with the buffer bounds.

func (*Buffer) SetPixel

func (b *Buffer) SetPixel(x, y int, c Color)

SetPixel sets a pixel at the given coordinates.

func (*Buffer) SubBuffer

func (b *Buffer) SubBuffer(r Rect) *Buffer

SubBuffer returns a new buffer that is a copy of a region of this buffer.

type Color

type Color struct {
	R, G, B, A uint8
}

Color represents an RGBA color.

func NewColor

func NewColor(r, g, b, a uint8) Color

NewColor creates a new color from RGBA values.

func NewColorHex

func NewColorHex(hex uint32) Color

NewColorHex creates a color from a hex value (0xRRGGBB or 0xRRGGBBAA).

func NewColorRGB

func NewColorRGB(r, g, b uint8) Color

NewColorRGB creates a new opaque color from RGB values.

func (Color) BGRA

func (c Color) BGRA() uint32

BGRA returns the color as 32-bit BGRA value (common framebuffer format).

func (Color) Blend

func (c Color) Blend(bg Color) Color

Blend blends this color over a background color using alpha compositing.

func (Color) RGB565

func (c Color) RGB565() uint16

RGB565 returns the color as 16-bit RGB565 value.

func (Color) RGBA

func (c Color) RGBA() uint32

RGBA returns the color as 32-bit RGBA value.

type PixelFormat

type PixelFormat int

PixelFormat represents the pixel format of a buffer.

const (
	PixelFormatBGRA PixelFormat = iota
	PixelFormatRGBA
	PixelFormatRGB565
)

type Point

type Point struct {
	X, Y int
}

Point represents a 2D point.

type Rect

type Rect struct {
	X, Y int
	W, H int
}

Rect represents a rectangle with position and size.

func NewRect

func NewRect(x, y, w, h int) Rect

NewRect creates a new rectangle.

func (Rect) Center

func (r Rect) Center() Point

Center returns the center point of the rectangle.

func (Rect) Contains

func (r Rect) Contains(p Point) bool

Contains returns true if the point is inside the rectangle.

func (Rect) ContainsXY

func (r Rect) ContainsXY(x, y int) bool

ContainsXY returns true if the coordinates are inside the rectangle.

func (Rect) Inset

func (r Rect) Inset(top, right, bottom, left int) Rect

Inset returns a rectangle inset by the given amounts.

func (Rect) InsetAll

func (r Rect) InsetAll(amount int) Rect

InsetAll returns a rectangle inset by the same amount on all sides.

func (Rect) Intersection

func (r Rect) Intersection(other Rect) Rect

Intersection returns the intersection of two rectangles.

func (Rect) Intersects

func (r Rect) Intersects(other Rect) bool

Intersects returns true if this rectangle intersects with another.

func (Rect) IsEmpty

func (r Rect) IsEmpty() bool

IsEmpty returns true if the rectangle has zero area.

func (Rect) Position

func (r Rect) Position() Point

Position returns the position of the rectangle as a Point.

func (Rect) Size

func (r Rect) Size() Point

Size returns the size of the rectangle as a Point.

func (Rect) Union

func (r Rect) Union(other Rect) Rect

Union returns the smallest rectangle containing both rectangles.

Jump to

Keyboard shortcuts

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