avyos.dev/pkg/graphics/core
package core
Package Overview
No package-level documentation is provided.
| Export Group | Count |
|---|---|
| Constants | 0 |
| Variables | 1 |
| Functions | 0 |
| Types | 5 |
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) *BufferNewBuffer 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) ColorGetPixel 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) *BufferSubBuffer 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) ColorNewColor creates a new color from RGBA values.
func NewColorHex(hex uint32) ColorNewColorHex creates a color from a hex value (0xRRGGBB or 0xRRGGBBAA).
func NewColorRGB(r, g, b uint8) ColorNewColorRGB creates a new opaque color from RGB values.
Methods
func (c Color) BGRA() uint32BGRA returns the color as 32-bit BGRA value (common framebuffer format).
func (c Color) Blend(bg Color) ColorBlend blends this color over a background color using alpha compositing.
func (c Color) RGB565() uint16RGB565 returns the color as 16-bit RGB565 value.
func (c Color) RGBA() uint32RGBA returns the color as 32-bit RGBA value.
PixelFormat
type PixelFormat intPixelFormat 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) RectNewRect creates a new rectangle.
Methods
func (r Rect) Center() PointCenter returns the center point of the rectangle.
func (r Rect) Contains(p Point) boolContains returns true if the point is inside the rectangle.
func (r Rect) ContainsXY(x, y int) boolContainsXY returns true if the coordinates are inside the rectangle.
func (r Rect) Inset(top, right, bottom, left int) RectInset returns a rectangle inset by the given amounts.
func (r Rect) InsetAll(amount int) RectInsetAll returns a rectangle inset by the same amount on all sides.
func (r Rect) Intersection(other Rect) RectIntersection returns the intersection of two rectangles.
func (r Rect) Intersects(other Rect) boolIntersects returns true if this rectangle intersects with another.
func (r Rect) IsEmpty() boolIsEmpty returns true if the rectangle has zero area.
func (r Rect) Position() PointPosition returns the position of the rectangle as a Point.
func (r Rect) Size() PointSize returns the size of the rectangle as a Point.
func (r Rect) Union(other Rect) RectUnion returns the smallest rectangle containing both rectangles.