canvas

package module
v0.0.0-...-e17b121 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2018 License: BSD-3-Clause Imports: 13 Imported by: 1

README

canvas

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// Surface
	ErrorUnknownDriver = errors.New("Unknown driver")
	ErrorAllocation    = errors.New("Allocation fail")
	ErrorNotAllowNil   = errors.New("nil is not allow")
	ErrorTooBusy       = errors.New("Currently, Query queue is too busy to handle this")
	ErrorUnsupported   = errors.New("Unsupported Option")
	ErrorClosed        = errors.New("This is closed Surface, Do not use this")
)

Predefined Errors for implement Surface. They are not used in the package, but are designed for surface implementation in other packages.

View Source
var (
	FetalSetup = errors.New("Fetal error, Setup check fail")
)

Fetal is a very serious error. They are passed through the panic(), not the return value.

Functions

func Capture

func Capture(path string, surface Surface) (err error)

func IsFail

func IsFail(o Option) bool

func Setup

func Setup(name Driver, driver func(w, h int, options ...Option) (Surface, error))

Setup new driver for surface Once setup driver, that driver can be use by NewSurface

func Vec

func Vec(x, y float32) mgl32.Vec2

Types

type Clear

type Clear color.RGBA

Clear with color.RGBA Clear{} for using this empty all pixels

= Write | Init

func (Clear) OptionType

func (Clear) OptionType() OptionType

type CloseQueryBuffer

type CloseQueryBuffer struct{}

Close buffer

= Send

func (CloseQueryBuffer) OptionType

func (CloseQueryBuffer) OptionType() OptionType

type ColorShader

type ColorShader color.RGBA

func (*ColorShader) At

func (s *ColorShader) At(x, y int) color.RGBA

func (*ColorShader) Size

func (s *ColorShader) Size(w, h int)

type Driver

type Driver string

Get DriverName

= Read

func (Driver) OptionType

func (Driver) OptionType() OptionType

type FixedShader

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

func (*FixedShader) At

func (s *FixedShader) At(x, y int) color.RGBA

func (*FixedShader) Size

func (s *FixedShader) Size(w, h int)

type FlushQueryBuffer

type FlushQueryBuffer struct{}

Flush all buffer for Data

= Send

func (FlushQueryBuffer) OptionType

func (FlushQueryBuffer) OptionType() OptionType

type Font

type Font struct {
}

TODO

type FrameBuffer

type FrameBuffer image.RGBA

GetResult image

= Read | Write

func (FrameBuffer) Convert

func (s FrameBuffer) Convert() *image.RGBA

func (FrameBuffer) OptionType

func (FrameBuffer) OptionType() OptionType

type Height

type Height int

Get Height

= Read | Write

func (Height) OptionType

func (Height) OptionType() OptionType

type InnerPath

type InnerPath interface {
	MoveTo(to mgl32.Vec2)
	LineTo(to mgl32.Vec2)
	QuadTo(p0, to mgl32.Vec2)
	CubeTo(p0, p1, to mgl32.Vec2)
	CloseTo()

	Query(qtype QueryType, reader io.Reader) error
}

type KernalShader

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

type MixOperation

type MixOperation draw.Op

GetResult image

= Read | Write | Init

func (MixOperation) OptionType

func (MixOperation) OptionType() OptionType

type Option

type Option interface {
	// They do not do anything, but they tell us that they are implementations of the Option interface.
	// It exists for a structure that can be utilized in IDE.
	OptionType() OptionType
}

Option is an interface used for various synchronization, value transfer and acquisition on the surface. Each option allows you to pass in, receive, or synchronize values that match your name (structure name). All options except Essensial are optional implementations and do not necessarily exist. This can be checked with the .Support method of the Surface interface.

type OptionType

type OptionType uint8

OptionType is the type that exists for the return of the .OptionType() method of the Option interface,

which tells you roughly what the implementation of the Option interface has.
const (
	// Read 는
	Read  OptionType = 0x01
	Write OptionType = 0x02
	Init  OptionType = 0x04
	Send  OptionType = 0x08
	Error OptionType = 0x80
)

type Path

type Path struct {
	Data []mgl32.Vec3
	Rect image.Rectangle
}

func NewPath

func NewPath() *Path

func (*Path) Fill

func (s *Path) Fill(fn func(i InnerPath)) *Path

func (*Path) RectValidate

func (s *Path) RectValidate(w, h int)

func (*Path) SetFont

func (s *Path) SetFont(f *Font)

func (*Path) SetLineCap

func (s *Path) SetLineCap(width float32)

func (*Path) SetLineJoint

func (s *Path) SetLineJoint(width float32)

func (*Path) SetLineWidth

func (s *Path) SetLineWidth(width float32)

type QueryBufferLength

type QueryBufferLength int

GetCurrent Buffer Query Count

= Read

func (QueryBufferLength) OptionType

func (QueryBufferLength) OptionType() OptionType

type QueryType

type QueryType uint32
const (
	SVGQuery QueryType = iota
)

type RepeatShader

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

type ResultFail

type ResultFail struct {
	Cause error
}

There is two type Fail, one is .Option(...) return error wrap by ResultFail Other is return nil, which is so obious, no need to explain

func (ResultFail) Error

func (s ResultFail) Error() string

func (ResultFail) OptionType

func (ResultFail) OptionType() OptionType

type Shader

type Shader interface {
	Size(w, h int)
	At(x, y int) color.RGBA
}

func NewColorShader

func NewColorShader(c color.Color) Shader

type Size

type Size image.Point

Get Size(Width, Height)

= Read | Write

func (Size) OptionType

func (Size) OptionType() OptionType

type Surface

type Surface interface {
	// Check Support options
	// Returns true if all the given options are satisfied
	Support(opt ...Option) bool
	// It is highly affected by the Linux ioctl function.
	// You can pass Option pointer or value(pointer is normally use for get, value normally used for set)
	//
	// return can be error
	// If there is error, it return nil or ResultFail struct(not pointer of ResultFail)
	Option(opt Option) Option
	// Query send Path, Shader, Transform for Path Rendering
	// Always it MUST BE thread-safe
	// You can use Goroutine
	//
	// throw > ErrorTooBusy : Literally, it is too busy to handle this
	// throw > ErrorClosed 	: .Close() method called, do not use this Surface
	// throw > * : any other errors
	//
	// query 		: It is points for path render
	//				:
	//				: nil not allowed, you must pass valid path data
	//				throw > ErrorNotAllowNil
	//
	// shader		: It is filling data for rendering area
	// 				: This will determine how to fill given space
	//				:
	//				: nil can be use, it MUST parsed as NewColorShader(colors.HTML.Black)
	//				throw > _
	//
	// transform 	: It is 3x3 matrix for homogeneous vector points(in query)
	//				: Every points in query is handle by this for transfomation
	//				: You can use directly apply this by handling Path.Data
	//				: But query build is CPU-dependent work
	//				: Surface can be accelerate by GPU
	//				: So if you can, pass transformation by using this
	//				:
	//				: nil can be use, it assume Identity matrix
	//				throw > _
	Query(query *Path, shader Shader, transform *Transform) error
	// This make free every resource for surface
	// It destroy Surface
	// Even if Surface call this, it is possible to use Surface in some case(not using external resource like GPU)
	// But not recommanded for safety reason
	io.Closer
}

func NewSurface

func NewSurface(driver Driver, width, height int, options ...Option) (Surface, error)

Make new Surface given driver If you don't care any driver set driver as "." "." mean any driver

type TextPath

type TextPath interface {
	Follow(text string, pathfn func(i InnerPath))
	Draw(text string, pos mgl32.Vec2, align align.Align)
}

type Transform

type Transform mgl32.Mat3

Transform is matrix for transforming homogeneous vector You can easyly build transform matrix by using this

It can use method chaining [https://en.wikipedia.org/wiki/Method_chaining]

func NewTransform

func NewTransform() *Transform
Example
package main

import (
	"fmt"
	"github.com/go-gl/mathgl/mgl32"
	"github.com/iamGreedy/canvas"
)

func main() {
	// Identity matrix
	fmt.Println(canvas.NewTransform())

	// translation matrix (+5, +5)
	fmt.Println(canvas.NewTransform().Translate(mgl32.Vec2{5, 5}))

	// Scale (16x, 16x)
	fmt.Println(canvas.NewTransform().Scale(mgl32.Vec2{16, 16}))

	// Scale and Translate
	fmt.Println(canvas.NewTransform().Scale(mgl32.Vec2{16, 16}).Translate(mgl32.Vec2{5, 5}))

	// Make (15, 15) to origin Scale (3x, 3x)
	fmt.Println(canvas.NewTransform().Pivot(mgl32.Vec2{15, 15}, func(t *canvas.Transform) {
		t.Scale(mgl32.Vec2{3, 3})
	}))
}

func (*Transform) Mul

func (s *Transform) Mul(v mgl32.Vec2) mgl32.Vec2

func (*Transform) Pivot

func (s *Transform) Pivot(at mgl32.Vec2, do func(t *Transform)) *Transform

func (*Transform) RawMul

func (s *Transform) RawMul(v mgl32.Vec3) mgl32.Vec3

func (*Transform) Reflection

func (s *Transform) Reflection(a axis.Axis) *Transform

func (*Transform) Rotate

func (s *Transform) Rotate(degree float32) *Transform

func (*Transform) Scale

func (s *Transform) Scale(scale mgl32.Vec2) *Transform

func (*Transform) Shear

func (s *Transform) Shear(shear float32, ea axis.ExculsiveAxis) *Transform

func (*Transform) String

func (s *Transform) String() string

func (*Transform) Translate

func (s *Transform) Translate(delta mgl32.Vec2) *Transform

type UseQueryBuffer

type UseQueryBuffer struct{}

Use Flush buffer for performance

= Send

func (UseQueryBuffer) OptionType

func (UseQueryBuffer) OptionType() OptionType

type WaitFlush

type WaitFlush struct{}

Lock until every flushing success

= Send

func (WaitFlush) OptionType

func (WaitFlush) OptionType() OptionType

type Width

type Width int

Get Width

= Read | Write

func (Width) OptionType

func (Width) OptionType() OptionType

Directories

Path Synopsis
glcanvas

Jump to

Keyboard shortcuts

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