avyos.dev/pkg/graphics/core

package core

Package Overview

No package-level documentation is provided.

Export GroupCount
Constants0
Variables1
Functions0
Types5

Variables

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

Types

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.

Functions

func NewBuffer(width, height int) *Buffer

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

Methods

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

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

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

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

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 (b *Buffer) BlitRect(src *Buffer, srcRect Rect, x, y int)

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

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 (b *Buffer) Clear(c Color)

Clear fills the entire buffer with a color.

func (b *Buffer) ClearClip()

ClearClip removes any active drawing clip.

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

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

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

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

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

DrawRect draws a rectangle outline with a color.

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

DrawRoundedRect draws a rounded rectangle outline.

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

FillRect fills a rectangle with a color.

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

FillRoundedRect fills a rectangle with rounded corners.

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

GetPixel returns the color at the given coordinates.

func (b *Buffer) SetClip(r Rect)

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

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

SetPixel sets a pixel at the given coordinates.

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

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

Color

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

Color represents an RGBA color.

Functions

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

NewColor creates a new color from RGBA values.

func NewColorHex(hex uint32) Color

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

func NewColorRGB(r, g, b uint8) Color

NewColorRGB creates a new opaque color from RGB values.

Methods

func (c Color) BGRA() uint32

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

func (c Color) Blend(bg Color) Color

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

func (c Color) RGB565() uint16

RGB565 returns the color as 16-bit RGB565 value.

func (c Color) RGBA() uint32

RGBA returns the color as 32-bit RGBA value.

PixelFormat

type PixelFormat int

PixelFormat represents the pixel format of a buffer.

Constants

const (
	PixelFormatBGRA PixelFormat = iota
	PixelFormatRGBA
	PixelFormatRGB565
)

Point

type Point struct {
	X, Y int
}

Point represents a 2D point.

Rect

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

Rect represents a rectangle with position and size.

Functions

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

NewRect creates a new rectangle.

Methods

func (r Rect) Center() Point

Center returns the center point of the rectangle.

func (r Rect) Contains(p Point) bool

Contains returns true if the point is inside the rectangle.

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

ContainsXY returns true if the coordinates are inside the rectangle.

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

Inset returns a rectangle inset by the given amounts.

func (r Rect) InsetAll(amount int) Rect

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

func (r Rect) Intersection(other Rect) Rect

Intersection returns the intersection of two rectangles.

func (r Rect) Intersects(other Rect) bool

Intersects returns true if this rectangle intersects with another.

func (r Rect) IsEmpty() bool

IsEmpty returns true if the rectangle has zero area.

func (r Rect) Position() Point

Position returns the position of the rectangle as a Point.

func (r Rect) Size() Point

Size returns the size of the rectangle as a Point.

func (r Rect) Union(other Rect) Rect

Union returns the smallest rectangle containing both rectangles.