draw

package
v0.0.0-...-f3d8a94 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2018 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package draw provides basic graphics and drawing primitives, in the style of the Plan 9 graphics library (see http://plan9.bell-labs.com/magic/man2html/2/draw) and the X Render extension.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Border

func Border(dst Image, r Rectangle, w int, src image.Image, sp Point)

Border aligns r.Min in dst with sp in src and then replaces pixels in a w-pixel border around r in dst with the result of the Porter-Duff compositing operation “src over dst.” If w is positive, the border extends w pixels inside r. If w is negative, the border extends w pixels outside r.

func Draw

func Draw(dst Image, r Rectangle, src image.Image, sp Point)

Draw calls DrawMask with a nil mask and an Over op.

func DrawMask

func DrawMask(dst Image, r Rectangle, src image.Image, sp Point, mask image.Image, mp Point, op Op)

DrawMask aligns r.Min in dst with sp in src and mp in mask and then replaces the rectangle r in dst with the result of a Porter-Duff composition. A nil mask is treated as opaque. The implementation is simple and slow. TODO(nigeltao): Optimize this.

Types

type Color

type Color uint32

A Color represents a color with 8-bit R, G, B, and A values, packed into a uint32—0xRRGGBBAA—so that comparison is defined on colors. Color implements image.Color. Color also implements image.Image: it is a 10⁹x10⁹-pixel image of uniform color.

var (
	Opaque        Color = 0xFFFFFFFF
	Transparent   Color = 0x00000000
	Black         Color = 0x000000FF
	White         Color = 0xFFFFFFFF
	Red           Color = 0xFF0000FF
	Green         Color = 0x00FF00FF
	Blue          Color = 0x0000FFFF
	Cyan          Color = 0x00FFFFFF
	Magenta       Color = 0xFF00FFFF
	Yellow        Color = 0xFFFF00FF
	PaleYellow    Color = 0xFFFFAAFF
	DarkYellow    Color = 0xEEEE9EFF
	DarkGreen     Color = 0x448844FF
	PaleGreen     Color = 0xAAFFAAFF
	MedGreen      Color = 0x88CC88FF
	DarkBlue      Color = 0x000055FF
	PaleBlueGreen Color = 0xAAFFFFFF
	PaleBlue      Color = 0x0000BBFF
	BlueGreen     Color = 0x008888FF
	GreyGreen     Color = 0x55AAAAFF
	PaleGreyGreen Color = 0x9EEEEEFF
	YellowGreen   Color = 0x99994CFF
	MedBlue       Color = 0x000099FF
	GreyBlue      Color = 0x005DBBFF
	PaleGreyBlue  Color = 0x4993DDFF
	PurpleBlue    Color = 0x8888CCFF
)

func (Color) At

func (c Color) At(x, y int) color.Color

func (Color) ColorModel

func (c Color) ColorModel() color.Model

func (Color) Height

func (c Color) Height() int

func (Color) RGBA

func (c Color) RGBA() (r, g, b, a uint32)

func (Color) SetAlpha

func (c Color) SetAlpha(a uint8) Color

SetAlpha returns the color obtained by changing c's alpha value to a and scaling r, g, and b appropriately.

func (Color) Width

func (c Color) Width() int

type Context

type Context interface {
	// Screen returns an editable Image of window.
	Screen() Image

	// FlushImage flushes changes made to Screen() back to screen.
	FlushImage()

	// KeyboardChan returns a channel carrying keystrokes.
	// An event is sent each time a key is pressed or released.
	// The value k represents key k being pressed.
	// The value -k represents key k being released.
	// The specific set of key values is not specified,
	// but ordinary character represent themselves.
	KeyboardChan() <-chan int

	// MouseChan returns a channel carrying mouse events.
	// A new event is sent each time the mouse moves or a
	// button is pressed or released.
	MouseChan() <-chan Mouse

	// ResizeChan returns a channel carrying resize events.
	// An event is sent each time the window is resized;
	// the client should respond by calling Screen() to obtain
	// the new screen image.
	// The value sent on the channel is always “true” and can be ignored.
	ResizeChan() <-chan bool

	// QuitChan returns a channel carrying quit requests.
	// After reading a value from the quit channel, the application
	// should exit.
	QuitChan() <-chan bool
}

A Context represents a single graphics window.

type DrawMasker

type DrawMasker interface {
	DrawMask(r Rectangle, src image.Image, sp Point, mask image.Image, mp Point, op Op) bool
}

If an Image implements the DrawMasker interface, then its DrawMask method will be called when it is the destination of a Draw operation. DrawMask should return true if the operation has been performed.

type Image

type Image interface {
	image.Image
	Set(x, y int, c color.Color)
}

A draw.Image is an image.Image with a Set method to change a single pixel.

type Mouse

type Mouse struct {
	Buttons int   // bit mask of buttons: 1<<0 is left, 1<<1 middle, 1<<2 right
	Point         // location of cursor
	Nsec    int64 // time stamp
}

A Mouse represents the state of the mouse.

type Op

type Op int

A Porter-Duff compositing operator.

const (
	// Over specifies “(src in mask) over dst”.
	Over Op = iota
	// Src specifies “src in mask”.
	Src
)

type Point

type Point struct {
	X, Y int
}

A Point is an X, Y coordinate pair.

var ZP Point

ZP is the zero Point.

func Pt

func Pt(X, Y int) Point

Pt is shorthand for Point{X, Y}.

func (Point) Add

func (p Point) Add(q Point) Point

Add returns the sum of p and q: Pt(p.X+q.X, p.Y+q.Y).

func (Point) Div

func (p Point) Div(k int) Point

Div returns p divided by k: Pt(p.X/k, p.Y/k).

func (Point) Eq

func (p Point) Eq(q Point) bool

Eq returns true if p and q are equal.

func (Point) In

func (p Point) In(r Rectangle) bool

In returns true if p is within r.

func (Point) Mul

func (p Point) Mul(k int) Point

Mul returns p scaled by k: Pt(p.X*k p.Y*k).

func (Point) Sub

func (p Point) Sub(q Point) Point

Sub returns the difference of p and q: Pt(p.X-q.X, p.Y-q.Y).

type Rectangle

type Rectangle struct {
	Min, Max Point
}

A Rectangle contains the Points with Min.X <= X < Max.X, Min.Y <= Y < Max.Y.

var ZR Rectangle

ZR is the zero Rectangle.

func Rect

func Rect(x0, y0, x1, y1 int) Rectangle

Rect is shorthand for Rectangle{Pt(x0, y0), Pt(x1, y1)}.

func Rpt

func Rpt(min, max Point) Rectangle

Rpt is shorthand for Rectangle{min, max}.

func (Rectangle) Add

func (r Rectangle) Add(p Point) Rectangle

Add returns the rectangle r translated by p: Rpt(r.Min.Add(p), r.Max.Add(p)).

func (Rectangle) Canon

func (r Rectangle) Canon() Rectangle

Canon returns a canonical version of r: the returned rectangle has Min.X <= Max.X and Min.Y <= Max.Y.

func (Rectangle) Clip

func (r Rectangle) Clip(r1 Rectangle) Rectangle

Clip returns the largest rectangle containing only points shared by r and r1.

func (Rectangle) Combine

func (r Rectangle) Combine(r1 Rectangle) Rectangle

Combine returns the smallest rectangle containing all points from r and from r1.

func (Rectangle) Dx

func (r Rectangle) Dx() int

Dx returns the width of the rectangle r: r.Max.X - r.Min.X.

func (Rectangle) Dy

func (r Rectangle) Dy() int

Dy returns the width of the rectangle r: r.Max.Y - r.Min.Y.

func (Rectangle) Empty

func (r Rectangle) Empty() bool

Empty retruns true if r contains no points.

func (Rectangle) Eq

func (r Rectangle) Eq(r1 Rectangle) bool

Eq returns true if r and r1 are equal.

func (Rectangle) In

func (r Rectangle) In(r1 Rectangle) bool

InRect returns true if all the points in r are also in r1.

func (Rectangle) Inset

func (r Rectangle) Inset(n int) Rectangle

Inset returns the rectangle r inset by n: Rect(r.Min.X+n, r.Min.Y+n, r.Max.X-n, r.Max.Y-n).

func (Rectangle) Overlaps

func (r Rectangle) Overlaps(r1 Rectangle) bool

Overlaps returns true if r and r1 cross; that is, it returns true if they share any point.

func (Rectangle) Sub

func (r Rectangle) Sub(p Point) Rectangle

Sub returns the rectangle r translated by -p: Rpt(r.Min.Sub(p), r.Max.Sub(p)).

Notes

Bugs

  • This is a toy library and not ready for production use.

Jump to

Keyboard shortcuts

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