canvas

package
v0.0.0-...-c624cc0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FontFilenameToName

func FontFilenameToName(filename string) string

FontFilenameToName converts a FontFilename to its CSS font name.

The CSS font name is set to the base of the filename, without the .ttf file extension. For example, "fonts/DejaVuSans.ttf" uses the CSS font family name "DejaVuSans" and that's what this function returns.

Fonts must be defined in the index.html style sheet when serving the wasm build of Doodle.

If filename is "", returns "serif" as a sensible default.

func RGBA

func RGBA(c render.Color) string

RGBA turns a color into CSS RGBA string.

Types

type Canvas

type Canvas struct {
	Value js.Value
	// contains filtered or unexported fields
}

Canvas represents an HTML5 Canvas object.

func GetCanvas

func GetCanvas(id string) Canvas

GetCanvas gets an HTML5 Canvas object from the DOM.

func (Canvas) ClientH

func (c Canvas) ClientH() int

ClientH returns the client height.

func (Canvas) ClientW

func (c Canvas) ClientW() int

ClientW returns the client width.

type Engine

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

Engine implements a rendering engine targeting an HTML canvas for WebAssembly targets.

func New

func New(canvasID string) (*Engine, error)

New creates the Canvas Engine.

func (*Engine) AddEventListeners

func (e *Engine) AddEventListeners()

AddEventListeners sets up bindings to collect events from the browser.

func (*Engine) Clear

func (e *Engine) Clear(color render.Color)

Clear the canvas to a certain color.

func (*Engine) ComputeTextRect

func (e *Engine) ComputeTextRect(text render.Text) (render.Rect, error)

ComputeTextRect computes and returns a Rect for how large the text would appear if rendered.

func (*Engine) Copy

func (e *Engine) Copy(t render.Texturer, src, dist render.Rect)

Copy a texturer bitmap onto the canvas.

func (*Engine) Delay

func (e *Engine) Delay(delay uint32)

Delay for a moment.

func (*Engine) DrawBox

func (e *Engine) DrawBox(color render.Color, rect render.Rect)

DrawBox draws a filled rectangle.

func (*Engine) DrawLine

func (e *Engine) DrawLine(color render.Color, a, b render.Point)

DrawLine draws a line between two points.

func (*Engine) DrawPoint

func (e *Engine) DrawPoint(color render.Color, point render.Point)

DrawPoint draws a pixel.

func (*Engine) DrawRect

func (e *Engine) DrawRect(color render.Color, rect render.Rect)

DrawRect draws a rectangle.

func (*Engine) DrawText

func (e *Engine) DrawText(text render.Text, point render.Point) error

DrawText draws text on the canvas.

func (*Engine) FreeTextures

func (e *Engine) FreeTextures() int

FreeTextures flushes the texture cache.

func (*Engine) GetTicks

func (e *Engine) GetTicks() uint32

GetTicks returns the number of milliseconds since the engine started.

func (*Engine) LoadTexture

func (e *Engine) LoadTexture(name string) (render.Texturer, error)

LoadTexture recalls a cached texture image.

func (*Engine) Loop

func (e *Engine) Loop() error

func (*Engine) Poll

func (e *Engine) Poll() (*event.State, error)

Poll for events.

func (*Engine) PollEvent

func (e *Engine) PollEvent() *Event

PollEvent returns the next event in the queue, or null.

func (*Engine) Present

func (e *Engine) Present() error

func (*Engine) SetTitle

func (e *Engine) SetTitle(title string)

SetTitle sets the window title.

func (*Engine) Setup

func (e *Engine) Setup() error

func (*Engine) StoreTexture

func (e *Engine) StoreTexture(name string, img image.Image) (render.Texturer, error)

StoreTexture caches a texture from a bitmap.

func (*Engine) Teardown

func (e *Engine) Teardown()

Teardown tasks.

func (*Engine) WindowSize

func (e *Engine) WindowSize() (w, h int)

WindowSize returns the size of the canvas window.

type Event

type Event struct {
	Name  string // mouseup, keydown, etc.
	Class EventClass

	// Mouse events.
	X          int
	Y          int
	LeftClick  bool
	RightClick bool

	// Key events.
	KeyName string
	State   bool
	Repeat  bool
}

Event object queues up asynchronous JavaScript events to be processed linearly.

type EventClass

type EventClass int

EventClass to categorize JavaScript events.

const (
	MouseEvent EventClass = iota
	ClickEvent
	KeyEvent
	ResizeEvent
	WindowEvent
)

EventClass values.

type Texture

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

Texture can hold on to cached image textures.

func (*Texture) Free

func (t *Texture) Free() error

Free the texture. Doesn't do anything in the Canvas engine currently.

func (*Texture) Image

func (t *Texture) Image() image.Image

Image returns the underlying image.

func (*Texture) Size

func (t *Texture) Size() render.Rect

Size returns the dimensions of the texture.

Jump to

Keyboard shortcuts

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