vglyph

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Foreground / Background ratio in RED channel. Alpha channel is alpha
	RED = ColorIndex(0)
	// Foreground / Background ratio in GREEN channel. Alpha channel is alpha
	GREEN = ColorIndex(1)
	// Foreground / Background ratio in BLUE channel. Alpha channel is alpha
	BLUE = ColorIndex(2)
	// Foreground / Background ratio in RED channel. RED channel is also alpha.
	GRAY = ColorIndex(3)
	// Foreground / Background ratio in RED channel. GREEN channel controls alpha. If GREEN > 0.5 then alpha = 0 else alpha = 1
	RED_GREENA = ColorIndex(4)
)
View Source
const (
	SETDepthField = SetKind(0)
	SETGrayScale  = SetKind(1)
	SETRGBA       = SetKind(2)
)
View Source
const (
	MAXGlyphSets = 16
)
View Source
const MAXImageWidth = 32768
View Source
const NOMINALFontSize = 32
View Source
const (
	NullSet = GlyphSetIndex(-1)
)

Variables

This section is empty.

Functions

func DefaultAdvance

func DefaultAdvance(height int, from, to rune) float32

func GetPalletteSampler

func GetPalletteSampler(ctx vk.APIContext, dev *vk.Device) *vk.Sampler

Sampler used in gyph shader. Clamps samping to edge

Types

type Appearance

type Appearance struct {
	GlyphSet  GlyphSetIndex
	GlyphName string
	ForeColor mgl32.Vec4
	BackColor mgl32.Vec4
	FgMask    MaskIndex
	BgMask    MaskIndex
	Edges     image.Rectangle
}

type ColorIndex

type ColorIndex uint32

type Glyph

type Glyph struct {
	Name       string
	Location   image.Rectangle
	CharOffset image.Point
	// Edges from 3 or 9 part glyph. left, top, right, bottom
	Edges image.Rectangle
}

Glyph is individual glyph in glyph set.

type GlyphBuilder

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

type GlyphSet

type GlyphSet struct {
	Desc    vk.ImageDescription
	Advance func(height int, from, to rune) float32
	// contains filtered or unexported fields
}

GlyphSet is set of prerendered glyph. GlyphSet can be either SETDepthField - All glyphs are rendered as signed depth fields. These allows more accurate sampling of glyph edges when sizing them. This is ideal for font's and other single colored glyphs SETGrayScale - Grays scale glyph mixes blending between font color and back color based on image grayness. Alpha channel is used to control glyphs alpha factor.

func (*GlyphSet) Dispose

func (set *GlyphSet) Dispose()

func (*GlyphSet) Get

func (set *GlyphSet) Get(name string) Glyph

Get glyph from set

func (*GlyphSet) MeasureString

func (gs *GlyphSet) MeasureString(text string, fontHeight int) int

If glyph set is made from font, measure string will calculate length of text using given font height

type GlyphSetIndex

type GlyphSetIndex int

type MaskIndex

type MaskIndex int

type Palette

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

Palette is set of glyph sets and masks. Palette, when built maps to single descriptor that can be bound to glyph shader.

func NewPalette

func NewPalette(ctx vk.APIContext, dev *vk.Device, noMasks int, maskSize int) *Palette

NewPalette initialized new palette and allocates room for mask image. Mask image is single multilayered image that glyph shader can use to amplify forecolor or backcolor. Masks can be used to create gradient effects to rendered glyph

func (*Palette) AddGlyphSet

func (th *Palette) AddGlyphSet(ctx vk.APIContext, gs *GlyphSet) GlyphSetIndex

Add glyph set to palette. You should add all glyph sets to palette before using it.

func (*Palette) ComputeMask

func (th *Palette) ComputeMask(ctx vk.APIContext, dev *vk.Device, compute func(x, y, maskSize int) color.RGBA) MaskIndex

ComputeMask fills one mask using given function.

func (*Palette) Dispose

func (pl *Palette) Dispose()

func (*Palette) Draw

func (pl *Palette) Draw(dc *vmodel.DrawContext, position Position, appearance Appearance) bool

func (*Palette) DrawString

func (pl *Palette) DrawString(dc *vmodel.DrawContext, fontSize int, text string,
	position Position, appearance Appearance) bool

func (*Palette) GetSet

func (th *Palette) GetSet(index GlyphSetIndex) *GlyphSet

GetSet retrieves glyph set from palette.

func (*Palette) MeasureString

func (pl *Palette) MeasureString(gsIndex GlyphSetIndex, text string, fontHeight int) int

type Position

type Position struct {
	// Clip left, top, right, bottom
	Clip      image.Rectangle
	ImageSize image.Point
	GlyphArea image.Rectangle
	Rotate    float32
}

func (Position) AddClip

func (pos Position) AddClip(clip image.Rectangle) Position

func (Position) Inset

func (pos Position) Inset(min image.Point, max image.Point) Position

func (Position) MouseArea

func (pos Position) MouseArea() image.Rectangle

type Range

type Range struct {
	From rune
	To   rune
}

Range of unicode points, ranges characters including

type SetBuilder

type SetBuilder struct {
	Ctx vk.APIContext
	// contains filtered or unexported fields
}

func NewSetBuilder

func NewSetBuilder(ctx vk.APIContext, kind SetKind) *SetBuilder

NewSetBuilder initialize new build that can build glyphset using images. Images can have foreground / background ratio (SETGrayScale) or full rgba image (SETRGBA) All images in one glyph set must have same kind

func (*SetBuilder) AddComputedGray

func (sb *SetBuilder) AddComputedGray(name string, size image.Point, edges image.Rectangle,
	intensity func(x, y int) (color float32, alpha float32))

Add computed glyph. Function will panic it set is not SETGrayScale

func (*SetBuilder) AddEdgedGlyph

func (sb *SetBuilder) AddEdgedGlyph(name string, mainColor ColorIndex, kind string, content []byte, edges image.Rectangle) *GlyphBuilder

Add edged glyph. See docs/vui.md) for more info

func (*SetBuilder) AddGlyph

func (sb *SetBuilder) AddGlyph(name string, mainColor ColorIndex, kind string, content []byte)

Add glyph to glyph set

func (*SetBuilder) Build

func (sb *SetBuilder) Build(dev *vk.Device) *GlyphSet

Build will create actual GlyphSet and load glyph images to GPU

type SetKind

type SetKind int

type VectorBuilder

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

func (*VectorBuilder) AddCorner

func (vb *VectorBuilder) AddCorner(from mgl32.Vec2, mid mgl32.Vec2, to mgl32.Vec2)

func (*VectorBuilder) AddCornerRect

func (vb *VectorBuilder) AddCornerRect(outside bool, left mgl32.Vec2, size mgl32.Vec2, corners mgl32.Vec4) *VectorBuilder

func (*VectorBuilder) AddLine

func (vb *VectorBuilder) AddLine(p1, p2 mgl32.Vec2) *VectorBuilder

func (*VectorBuilder) AddPoint

func (vb *VectorBuilder) AddPoint(p1 mgl32.Vec2) *VectorBuilder

func (*VectorBuilder) AddQuadratic

func (vb *VectorBuilder) AddQuadratic(p1, p2, p3 mgl32.Vec2) *VectorBuilder

func (*VectorBuilder) AddRect

func (vb *VectorBuilder) AddRect(outside bool, left mgl32.Vec2, size mgl32.Vec2) *VectorBuilder

func (*VectorBuilder) AddRoundedRect

func (vb *VectorBuilder) AddRoundedRect(outside bool, left mgl32.Vec2, size mgl32.Vec2, corners mgl32.Vec4) *VectorBuilder

type VectorSetBuilder

type VectorSetBuilder struct {
	Ctx         vk.APIContext
	MaxDistance float32
	// contains filtered or unexported fields
}

VectorSetBuilder converts vector based images (fonts and drawn) to glyph set

func (*VectorSetBuilder) AddChar

func (vsb *VectorSetBuilder) AddChar(font *sfnt.Font, pixelSize int, r rune) *VectorBuilder

Add individual character from font to vector builder

func (*VectorSetBuilder) AddEdgedGlyph

func (vsb *VectorSetBuilder) AddEdgedGlyph(name string, margin int, edges image.Rectangle) *VectorBuilder

Add glyph that have 3 sides: top, center, bottom or left, center, right. 9 side glyphs have left, top, right, bottom, center and all corners.

func (*VectorSetBuilder) AddFont

func (vsb *VectorSetBuilder) AddFont(ctx vk.APIContext, fontContent []byte, ranges ...Range)

Add font to vector set builder. Glyph names will be directly font character converted as string Currently only fonts containing lines and quadratics bezier lines are support (this should include all ttf fonts) Cubic bezier lines are not

func (*VectorSetBuilder) AddGlyph

func (vsb *VectorSetBuilder) AddGlyph(name string, margin int) *VectorBuilder

Add glyph using Vector builder. Margin will be added to final glyph. You must have few pixel around edges to separate glyph inside from outside

func (*VectorSetBuilder) Build

func (vsb *VectorSetBuilder) Build(ctx vk.APIContext, dev *vk.Device) *GlyphSet

Convert added vector sets to glyph set. This glyph set will be signed depth field

Jump to

Keyboard shortcuts

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