draw

package
Version: v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2021 License: MIT Imports: 17 Imported by: 24

Documentation

Overview

Package draw is a port of Plan 9's libdraw to Go. It connects to the 'devdraw' binary built as part of Plan 9 from User Space (http://swtch.com/plan9port/). All graphics operations are done in the remote server.

Displays

Graphics operations are mediated through a Display, obtained by calling Init. See the Display documentation for details.

Colors and Pixel Formats

This package represents colors as RGBA values, 8 bits per channel, packed into a uint32 type called Color. Color implements the image/color package's Color interface.

The images in this package store pixel values in more compact formats specified by a pixel format represented by the Pix type. (Plan 9 C calls this format a ‘chan’ but that name is already taken in Go.) The Pix details the sequence of image channels packed into each pixel. For example RGB24, defined as MakePix(CRed, 8, CGreen, 8, CBlue, 8), describes a 24-bit pixel format consisting of 8 bits each for red, green, and blue, with no explicit alpha channel.

The external representation of a Pix is a string, a sequence of two-character channel descriptions, each comprising a letter (r for red, g for green, b for blue, a for alpha, m for color-mapped, k for greyscale, and x for “don't care”) followed by a number of bits per pixel. The sum of the channel bits per pixel is the depth of the image, which must be either a divisor or a multiple of eight. It is an error to have more than one of any channel but x. An image must have either a greyscale channel; a color mapped channel; or red, green, and blue channels. If the alpha channel is present, it must be at least as deep as any other channel. For example, RGB24 is “r8g8b8”.

The packing of 1-, 2- or 4-bit pixels into bytes is big-endian, meaning that the first pixel in a 1-bit image is the 0x80 bit. But the packing of 16-, 24-, and 32-bit pixels into byte data is little-endian, meaning that the byte order for the RGB24 format is actually blue, green, red. This odd convention was chosen for compatibility with Plan 9, which in turn chose it for compatibility with VGA frame buffers, especially 16-bit pixel data like RGB16. Counterintuitively, then, the pixel formats corresponding to Go's image.RGBA are ABGR32 or XBGR32.

The color-mapped values, which now are only of historical interest, use a 4x4x4 subdivision with 4 shades in each subcube. See https://9fans.github.io/plan9port/man/man7/color.html for the details.

Image Format

Fonts and images as used by Image.Load, Image.Unload, Display.ReadImage, and so on are stored in a machine-independent format defined by Plan 9. See https://9fans.github.io/plan9port/man/man7/image.html for the details.

Fonts

External bitmap fonts are described by a plain text file that can be read using Display.OpenFont. See https://9fans.github.io/plan9port/man/man7/font.html for the details.

Font Names

Font names in this package (following Plan 9 from User Space) are a small language describing a font. The most basic form is the name of an existing bitmap font file, following the convention:

/lib/font/bit/name/range.size.font

where size is approximately the height in pixels of the lower case letters (without ascenders or descenders). Range gives some indication of which characters will be available: for example ascii, latin1, euro, or unicode. Euro includes most European languages, punctuation marks, the International Phonetic Alphabet, etc., but no Oriental languages. Unicode includes every character for which appropriate-sized images exist on the system.

In Plan 9 from User Space, the font files are rooted in $PLAN9/font instead of /lib/font/bit, but to keep old references working, paths beginning with /lib/font/bit are interpreted as references to the actual font directory.

Fonts need not be stored on disk in the Plan 9 format. If the font name has the form /mnt/font/name/size/font, fontsrv is invoked to synthesize a bitmap font from the operating system's installed vector fonts. The command ‘fontsrv -p .’ lists the available fonts. See https://9fans.github.io/plan9port/man/man4/fontsrv.html for more.

If the font name has the form scale*fontname, where scale is a small decimal integer, the fontname is loaded and then scaled by pixel repetition.

The Plan 9 bitmap fonts were designed for screens with pixel density around 100 DPI. When used on screens with pixel density above 200 DPI, the bitmap fonts are automatically pixel doubled. Similarly, fonts loaded from https://9fans.github.io/plan9port/man/man4/fontsrv.html are automatically doubled in size by varying the effective size path element. In both cases, the effect is that a single font name can be used on both low- and high-density displays (or even in a window moved between differing displays) while keeping roughly the same effective size.

For more control over the fonts used on low- and high-density displays, if the font name has the form ‘lowfont,highfont’, then lowfont is used on low-density displays and highfont on high-density displays. In effect, the behavior described above is that the font name

/lib/font/bit/lucsans/euro.8.font

really means

/lib/font/bit/lucsans/euro.8.font,2*/lib/font/bit/lucsans/euro.8.font

and similarly

/mnt/font/LucidaGrande/15a/font

really means

/mnt/font/LucidaGrande/15a/font,/mnt/font/LucidaGrande/30a/font

Using an explicit comma-separated font pair allows finer control, such as using a Plan 9 bitmap font on low-density displays but switching to a system-installed vector font on high-density displays:

/lib/font/bit/lucsans/euro.8.font,/mnt/font/LucidaGrande/30a/font

Libdraw Cheat Sheet

The mapping from the Plan 9 C libdraw names defined in <draw.h> to names in this package (omitting unchanged names) is:

ARROW → Arrow
Borderwidth → BorderWidth
CACHEAGE → unexported
CHAN1, CHAN2, CHAN3, CHAN4 → MakePix
Cachefont → unexported
Cacheinfo → unexported
Cachesubf → unexported
DBlack → Black
DBlue → Blue
DBluegreen → BlueGreen
DCyan → Cyan
DDarkYellow → DarkYellow
DDarkblue → DarkBlue
DDarkgreen → DarkGreen
DGreen → Green
DGreyblue → GreyBlue
DGreygreen → GreyGreen
DMagenta → Magenta
DMedGreen → MedGreen
DMedblue → MedBlue
DNofill → NoFill
DNotacolor → undefined
DOpaque → Opaque
DPaleYellow → PaleYellow
DPaleblue → PaleBlue
DPalebluegreen → PaleBlueGreen
DPalegreen → PaleGreen
DPalegreyblue → PaleGreyBlue
DPalegreygreen → PaleGreyGreen
DPurpleblue → PurpleBlue
DRed → Red
DSUBF → unexported
DTransparent → Transparent
DWhite → White
DYellow → Yellow
DYellowgreen → YellowGreen
Displaybufsize → unexported
Drawop → Op
Dx → Rectangle.Dx
Dy → Rectangle.Dy
Endarrow → EndArrow
Enddisc → EndDisc
Endmask → EndMask
Endsquare → EndSquare
Font → Font
Fontchar → Fontchar
Image → Image
LOG2NFCACHE → unexported
MAXFCACHE → unexported
MAXSUBF → unexported
NBITS, TYPE → Pix.Split
NFCACHE → unexported
NFLOOK → unexported
NFSUBF → unexported
NOREFRESH → not available
Pfmt → not implemented; use %v instead of %P
Point → Point (alias for image.Point)
Rectangle → Rectangle (alias for image.Rectangle)
Refbackup → RefBackup
Refmesg → RefMesg
Refnone → RefNone
Rfmt → not implemented; use %v instead of %P
SUBFAGE → unexported
_allocwindow → unexported
_screen → Display.Screen
_string → unexported; use String, Runes, etc.
addpt → Point.Add
agefont → unexported
allocimage → Display.AllocImage
allocimagemix → Display.AllocImageMix
allocscreen → Image.AllocScreen
allocsubfont → unexported
allocwindow → unexported
arc → Image.Arc
arcop → Image.ArcOp
bezier → Image.Bezier
bezierop → Image.BezierOp
bezspline → Image.BSpline
bezsplineop → Image.BSplineOp
bezsplinepts → unexported
border → Image.Border
borderop → Image.BorderOp
bottomnwindows → unexported
bottomwindow → unexported
bufimage → unexported
buildfont → Display.BuildFont
bytesperline → BytesPerLine
cachechars → unexported
canonrect → Rectangle.Canon
chantodepth → Pix.Depth
chantostr → Pix.String
cloadimage → Image.Cload
closedisplay → Display.Close
cmap2rgb → unexported
cmap2rgba → unexported
combinerect → CombineRect
creadimage → not available; use Display.ReadImage (readimage) with "compressed\n" prefix
cursorset → Display.MoveCursor
cursorswitch → Display.SwitchCursor
display → global variable removed; use result of Init
divpt → Point.Div
draw → Image.Draw
drawerror → not available
drawlsetrefresh → not available
drawop → Image.DrawOp
drawrepl → Repl
drawreplxy → ReplXY
drawresizewindow → Display.Resize
drawsetlabel → Display.SetLabel
drawtopwindow → Display.Top
ellipse → Image.Ellipse
ellipseop → Image.EllipseOp
eqpt → Point.Eq (or ==)
eqrect → Rectangle.Eq (but treats all empty rectangles equal)
fillarc → Image.FillArc
fillarcop → Image.FillArcOp
fillbezier, fillbezierop → not implemented
fillbezspline, fillbezsplineop → not implemented
fillellipse → Image.FillEllipse
fillellipseop → Image.FillEllipseOp
fillpoly → Image.FillPoly
fillpolyop → Image.FillPolyOp
flushimage → Display.Flush
font → Display.Font
freefont → Font.Free
freeimage → Image.Free
freescreen → Screen.Free
freesubfont → unexported
gendraw → Image.GenDraw
gendrawop → Image.GenDrawOp
gengetwindow → not available; use Display.Attach (getwindow)
geninitdraw → not available; use Init (initdraw)
getwindow → Display.Attach
icossin → IntCosSin
icossin2 → IntCosSin2
initdraw → Init
insetrect → Rectangle.Inset
installsubfont → unexported
line → Image.Line
lineop → Image.LineOp
loadchar → unexported
loadhidpi → unexported
loadimage → Image.Load
lockdisplay → unexported
lookupsubfont → unexported
mkfont → unexported
mulpt → Point.Mul
namedimage → not available
nameimage → not available
newwindow → not available
openfont → Display.OpenFont
originwindow → unexported
parsefontscale → unexported
poly → Image.Poly
polyop → Image.PolyOp
ptinrect → Point.In
publicscreen → unexported
readimage → Display.ReadImage
readsubfont → unexported
readsubfonti → unexported
rectXrect → RectXRect
rectaddpt → Rectangle.Add
rectclip → RectClip
rectinrect → RectInRect
rectsubpt → Rectangle.Sub
replclipr → Image.ReplClipr
rgb2cmap → unexported
runestring, runestringn → Image.Runes
runestringbg, runestringnbg → Image.RunesBg
runestringbgop, runestringnbgop → Image.RunesBgOp
runestringop, runestringnop → Image.RunesOp
runestringsize → Font.RunesSize
runestringwidth, runestringnwidth → Font.RunesWidth
scalecursor → ScaleCursor
scalesize → Display.Scale
screen → Display.ScreenImage
setalpha → Color.WithAlpha
string, stringn → Image.String
stringbg, stringnbg → Image.StringBg
stringbgop, stringnbgop → Image.StringBgOp
stringop, stringnop → Image.StringOp
stringsize → Font.StringSize
stringsubfont → not implemented
stringwidth, stringnwidth → Font.StringWidth
strsubfontwidth → not available
strtochan → ParsePix
subfontname → unexported
subpt → Point.Sub
swapfont → unexported
topnwindows → unexported
topwindow → unexported
uint32 as color type → Color
uint32 as image channel (format) type → Pix
uninstallsubfont → unexported
unloadimage → Image.Unload
unlockdisplay → unexported
wordsperline → WordsPerLine
writeimage → not implemented (TODO)
writesubfont → not available

Note that the %P and %R print formats are now simply %v, but since Point and Rectangle are aliases for the types in package image, the formats have changed: Points and Rectangles format as (1,2) and (1,2)-(3,4) instead of [1 2] and [[1 2] [3 4]].

Index

Constants

View Source
const (
	Clear Op = 0

	SinD  Op = 8
	DinS  Op = 4
	SoutD Op = 2
	DoutS Op = 1

	S      = SinD | SoutD
	SoverD = SinD | SoutD | DoutS
	SatopD = SinD | DoutS
	SxorD  = SoutD | DoutS

	D      = DinS | DoutS
	DoverS = DinS | DoutS | SoutD
	DatopS = DinS | SoutD
	DxorS  = DoutS | SoutD // == SxorD

	Ncomp = 12
)
View Source
const (
	RefBackup = 0
	RefNone   = 1
	RefMesg   = 2
)

Refresh algorithms to execute when a window is resized or uncovered. RefMesg is almost always the correct one to use.

View Source
const (
	KeyFn = '\uF000'

	KeyHome      = KeyFn | 0x0D
	KeyUp        = KeyFn | 0x0E
	KeyPageUp    = KeyFn | 0xF
	KeyPrint     = KeyFn | 0x10
	KeyLeft      = KeyFn | 0x11
	KeyRight     = KeyFn | 0x12
	KeyDown      = 0x80
	KeyView      = 0x80
	KeyPageDown  = KeyFn | 0x13
	KeyInsert    = KeyFn | 0x14
	KeyEnd       = KeyFn | 0x18
	KeyAlt       = KeyFn | 0x15
	KeyShift     = KeyFn | 0x16
	KeyCtl       = KeyFn | 0x17
	KeyBackspace = 0x08
	KeyDelete    = 0x7F
	KeyEscape    = 0x1b
	KeyEOF       = 0x04
	KeyCmd       = 0xF100
)
View Source
const (
	CRed = iota
	CGreen
	CBlue
	CGrey
	CAlpha
	CMap
	CIgnore
	NChan
)
View Source
const BorderWidth = 4
View Source
const DefaultDPI = 133

DefaultDPI is the DPI assumed when the actual display DPI is unknown. It is also the base DPI assumed for the Display.Scale method, which scales fixed-size pixel counts for higher-resolution displays. See the Display documentation for more information.

View Source
const ICOSSCALE = 1024

Variables

View Source
var (
	Gray1Model  color.Model = color.ModelFunc(gray1Model)
	Gray2Model  color.Model = color.ModelFunc(gray2Model)
	Gray4Model  color.Model = color.ModelFunc(gray4Model)
	CMap8Model  color.Model = color.ModelFunc(cmapModel)
	CRGB15Model color.Model = color.ModelFunc(crgb15Model)
	CRGB16Model color.Model = color.ModelFunc(crgb16Model)
)
View Source
var (
	GREY1  Pix = MakePix(CGrey, 1)
	GREY2  Pix = MakePix(CGrey, 2)
	GREY4  Pix = MakePix(CGrey, 4)
	GREY8  Pix = MakePix(CGrey, 8)
	CMAP8  Pix = MakePix(CMap, 8)
	RGB15  Pix = MakePix(CIgnore, 1, CRed, 5, CGreen, 5, CBlue, 5)
	RGB16      = MakePix(CRed, 5, CGreen, 6, CBlue, 5)
	RGB24      = MakePix(CRed, 8, CGreen, 8, CBlue, 8)
	BGR24      = MakePix(CBlue, 8, CGreen, 8, CRed, 8)
	RGBA32     = MakePix(CRed, 8, CGreen, 8, CBlue, 8, CAlpha, 8)
	ARGB32     = MakePix(CAlpha, 8, CRed, 8, CGreen, 8, CBlue, 8) // stupid VGAs
	ABGR32     = MakePix(CAlpha, 8, CBlue, 8, CGreen, 8, CRed, 8)
	XRGB32     = MakePix(CIgnore, 8, CRed, 8, CGreen, 8, CBlue, 8)
	XBGR32     = MakePix(CIgnore, 8, CBlue, 8, CGreen, 8, CRed, 8)
)

Functions

func BytesPerLine

func BytesPerLine(r Rectangle, depth int) int

BytesPerLine returns the number of 8-bit bytes touched by a scan line of the rectangle of specified depth.

func CombineRect

func CombineRect(r1 *Rectangle, r2 Rectangle)

CombineRect overwrites *r1 with the smallest rectangle enclosing both *r1 and r2. CombineRect(r1, r2) differs from *r1 = r1.Union(r2) in its handling of zero-width or zero-height rectangles.

func GenDrawOp

func GenDrawOp(dst *Image, r Rectangle, src *Image, p0 Point, mask *Image, p1 Point, op Op)

GenDrawOp is like GenDraw but specifies a Porter-Duff operator op to use in place of “S over D”.

func IntCosSin

func IntCosSin(deg int) (cos, sin int)

IntCosSin returns scaled integers representing the cosine and sine of the angle deg, measured in integer degrees. The values are scaled by ICOSSCALE (1024), so that cos(0) is 1024.

func IntCosSin2

func IntCosSin2(x, y int) (cos, sin int)

IntCosSin2 returns scaled integers representing the cosine and sine of the angle defined by the point (x, y). The values are scaled by ICOSSCALE (1024), so that cos(0) is 1024. IntCosSin2 is to IntCosSin what math.Atan2 is to math.Atan.

func MenuHit(but int, mc *Mousectl, me *Menu, scr *Screen) int

func MouseScrollSize

func MouseScrollSize(maxlines int) int

Mousescrollsize computes the number of lines of text that should be scrolled in response to a mouse scroll wheel click. Maxlines is the number of lines visible in the text window.

The default scroll increment is one line. This default can be overridden by setting the $mousescrollsize environment variable to an integer, which specifies a constant number of lines, or to a real number followed by a percent character, indicating that the scroll increment should be a percentage of the total number of lines in the window. For example, setting $mousescrollsize to 50% causes a half-window scroll increment.

func RectClip

func RectClip(rp *Rectangle, b Rectangle) bool

RectClip attempts to clip *rp to be within b. If any of *rp overlaps b, RectClip modifies *rp to denote the overlapping portion and returns true. Otherwise, when *rp and b do not overlap, RectClip leaves *rp unmodified and returns false.

func RectInRect

func RectInRect(r, s Rectangle) bool

RectInRect reports whether r is entirely contained in s. RectInRect(r, s) differs from r.In(s) in its handling of zero-width or zero-height rectangles.

func RectXRect

func RectXRect(r, s Rectangle) bool

RectXRect reports whether r and s cross, meaning they share any point or r is a zero-width or zero-height rectangle inside s. Note that the zero-sized cases make RectXRect(r, s) different from r.Overlaps(s).

func ReplXY

func ReplXY(min, max, x int) int

ReplXY clips x to be in the half-open interval [min, max) y adding or subtracking a multiple of max - min. That is, assuming [min, max) specify the base of an infinite tiling of the integer line, ReplXY returns the value of the image of x that appears in the interval.

func WordsPerLine

func WordsPerLine(r Rectangle, depth int) int

WordsPerLine returns the number of 32-bit words touched by a scan line of the rectangle of specified depth.

Types

type CMap8

type CMap8 struct {
	I uint8
}

CMap8 represents an 8-bit color-mapped color with the standard Plan 9 color map.

func (CMap8) RGBA

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

type CRGB15

type CRGB15 struct {
	// CIgnore, 1, CRed, 5, CGreen, 5, CBlue, 5
	V uint16
}

CRGB15 represents a 15-bit 5-5-5 RGB color.

func (CRGB15) RGBA

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

type CRGB16

type CRGB16 struct {
	// CRed, 5, CGreen, 6, CBlue, 5
	V uint16
}

CRGB16 represents a 16-bit 5-6-5 RGB color.

func (CRGB16) RGBA

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

type Color

type Color uint32

A Color represents an RGBA value, 8 bits per element: 0xRRGGBBAA.

The element values correspond to illumination, so 0x00000000 is transparent, 0x000000FF is opaque black, 0xFFFFFFFF is opaque white, 0xFF0000FF is opaque red, and so on.

The R, G, B values have been pre-multiplied by A (alpha). For example, a 50% red is 0x7F00007F not 0xFF00007F. See also the WithAlpha method.

const (
	Transparent   Color = 0x00000000
	Opaque        Color = 0xFFFFFFFF
	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

	// NoFill is a special value recognized by AllocImage.
	NoFill Color = 0xFFFFFF00
)

func (Color) RGBA

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

RGBA returns 16-bit r, g, b, a values for the color c, implementing the image/color package's Color interface.

func (Color) WithAlpha

func (c Color) WithAlpha(alpha uint8) Color

WithAlpha performs the alpha computation for a color, ignoring its initial alpha value and multiplying the components by the supplied alpha. For example, Red.WithAlpha(0x7F) is a 50% red color value.

type Cursor

type Cursor struct {
	Point
	White [2 * 16]uint8
	Black [2 * 16]uint8
}

A Cursor describes a single cursor.

The arrays White and Black are arranged in rows, two bytes per row, left to right in big-endian order, to give 16 rows of 16 bits each. A cursor is displayed on the screen by adding Point to the current mouse position, then using White as a mask to draw white at the pixels where White is 1, and then drawing black at the pixels where Black is 1.

type Cursor2

type Cursor2 struct {
	Point
	White [4 * 32]uint8
	Black [4 * 32]uint8
}

A Cursor2 describes a single high-DPI cursor, with twice the pixels in each direction as a Cursor (32 rows of 32 bits each).

func ScaleCursor

func ScaleCursor(c Cursor) Cursor2

ScaleCursor returns a high-DPI version of c.

type Display

type Display struct {
	Image       *Image
	Screen      *Screen
	ScreenImage *Image
	Windows     *Image
	DPI         int // display pixels-per-inch

	White       *Image // pre-allocated color
	Black       *Image // pre-allocated color
	Opaque      *Image // pre-allocated color
	Transparent *Image // pre-allocated color

	Font *Font // default font for UI
	// contains filtered or unexported fields
}

A Display represents a connection to a graphics display, holding all graphics resources associated with the connection, including in particular raster image data in use by the client program.

A Display d is created by calling Init. Each Display corresponds to a single host window system window. Multiple host windows can be created by calling Init multiple times, although each allocated Image and Font is only valid for use with the Display from which it was allocated.

Historically, Plan 9 graphics programs have used fixed-size graphics features that assume a narrow range of display densities, around 100 dpi: pixels (or dots) per inch. The new field DPI contains the display's actual density if known, or else DefaultDPI (133). The Display.Scale method scales a fixed pixel count n by DPI/DefaultDPI, rounding appropriately. Note that the display DPI can change during during Display.Attach.

The mouse cursor is always shown. The initial cursor is the system arrow. The SwitchCursor method changes the cursor image, and MoveCursor moves the cursor.

The various graphics operations are buffered and not guaranteed to be made visible until a call to the Flush method. Various routines flush automatically, notably Mousectl.Read. Programs that receive directly from Mousectl.C should typically Flush the display explicitly before the receive.

func Init

func Init(errch chan<- error, font, label, size string) (d *Display, err error)

Init connects to a display server and creates a single host window. The error channel is unused.

The font specifies the font name. If font is the empty string, Init uses the environment variable $font. If $font is not set, Init uses a built-in minimal default font. See the package documentation for a full discussion of font syntaxes.

The label and size specify the initial window title and diemnsions. The size takes the form "1000x500"; the units are pixels.

Unlike the Plan 9 C library's initdraw, Init does not establish any global variables. The C global variables display, font, and screen correspond to the returned value d, d.Font, and d.ScreenImage.

TODO: Use the error channel.

func (*Display) AllocImage

func (d *Display) AllocImage(r Rectangle, pix Pix, repl bool, color Color) (*Image, error)

AllocImage allocates a new Image on display d. It will have the rectangle, pixel format (RGBA32 etc), and replication flag given by its arguments.

All the new image's pixels will have the initial color (Black, White, Red, and so on). If color is NoFill, the pixels will be left uninitialized. (In Go, uninitialized means zeroed, so the pixels will be Transparent or Black depending on whether the pixel format includes an alpha channel.)

If repl is true, the result's Clipr rectangle is set to a very large region. Otherwise, the result's Clipr is set to r.

The result's Depth is computed from pix.

AllocImage returns an error if the display cannot allocate the image or is no longer available.

For example, to allocate a single-pixel replicated image that may be used to paint a region red:

red, err := display.AllocImage(draw.Rect(0, 0, 1, 1), draw.RGB24, true, draw.Red)

func (*Display) AllocImageMix

func (d *Display) AllocImageMix(color1, color3 Color) *Image

AllocImageMix is used to allocate background colors. It returns a 1×1 replicated image whose pixel is the result of mixing the two colors in a one to three ratio. On 8-bit color-mapped displays, it returns a 2×2 replicated image with one pixel colored the color one and the other three with three. (This simulates a wider range of tones than can be represented by a single pixel value on a color-mapped display.)

func (*Display) Attach

func (d *Display) Attach(ref int) error

Attach reattaches to a display, after a resize, updating the display's associated image, screen, and screen image data structures. The images d.Image and d.ScreenImage and the screen d.Screen are reallocated, so the caller must reinitialize any cached copies of those fields.

Any open Fonts associated with the Display may be updated in response to a DPI change, meaning the caller should expect that a Font's Height may be different after calling Attach as well. The Font pointers themselves do not change.

func (*Display) BuildFont

func (d *Display) BuildFont(buf []byte, name string) (*Font, error)

BuildFont builds a font of the given name using the description provided by the buffer, typically the contents of a font file.

func (*Display) Close

func (d *Display) Close() error

Close closes the Display.

func (*Display) Flush

func (d *Display) Flush() error

Flush flushes pending I/O to the server, making any drawing changes visible.

func (*Display) HiDPI

func (d *Display) HiDPI() bool

func (*Display) InitKeyboard

func (d *Display) InitKeyboard() *Keyboardctl

InitKeyboard connects to the keyboard and returns a Keyboardctl to listen to it.

func (*Display) InitMouse

func (d *Display) InitMouse() *Mousectl

InitMouse connects to the mouse and returns a Mousectl to interact with it.

func (*Display) MoveCursor

func (d *Display) MoveCursor(pt Point) error

MoveCursor moves the mouse cursor to the specified location.

func (*Display) OpenFont

func (d *Display) OpenFont(name string) (*Font, error)

OpenFont reads the named file and returns the font it defines. The name may be an absolute path, or it may identify a file in a standard font directory: /lib/font/bit, /usr/local/plan9, /mnt/font, etc.

In contrast to Plan 9, but matching Plan 9 from User Space, font names are a small language describing the desired font. See the package documentation for details.

func (*Display) ReadImage

func (d *Display) ReadImage(r io.Reader) (*Image, error)

ReadImage creates an image from data contained in r. (See the package documentation for the image file format.) The returned image is allocated using AllocImage.

func (*Display) ReadSnarf

func (d *Display) ReadSnarf(buf []byte) (int, int, error)

ReadSnarf reads the snarf buffer into buf, returning the number of bytes read, the total size of the snarf buffer (useful if buf is too short), and any error. No error is returned if there is no problem except for buf being too short.

func (*Display) Resize

func (d *Display) Resize(r Rectangle)

Resize resizes the host window.

func (*Display) Scale

func (d *Display) Scale(n int) int

Scale scales the fixed pixel count n by d.DPI / DefaultDPI, rounding appropriately. It can help programs that historically assumed fixed pixel counts (for example, a 4-pixel border) scale gracefully to high-resolution displays. See the Display documentation for more information.

func (*Display) ScaleSize

func (d *Display) ScaleSize(n int) int

func (*Display) SetDebug

func (d *Display) SetDebug(debug bool)

SetDebug enables debugging for the remote devdraw server.

func (*Display) SetLabel

func (d *Display) SetLabel(label string)

SetLabel sets the host window's title.

func (*Display) SwitchCursor

func (d *Display) SwitchCursor(c *Cursor) error

SwitchCursor sets the mouse cursor to the specified cursor image. SwitchCursor(nil) changes the cursor to the standard system cursor.

func (*Display) SwitchCursor2

func (d *Display) SwitchCursor2(c *Cursor, c2 *Cursor2) error

SwitchCursor2 sets the mouse cursor to the specified cursor images. SwitchCursor2(nil, nil) changes the cursor to the standard system cursor. If c2 is omitted, a scaled version of c is used instead.

func (*Display) Top

func (d *Display) Top()

Top moves the host window to the top of the host window pile.

func (*Display) WriteSnarf

func (d *Display) WriteSnarf(data []byte) error

WriteSnarf writes the data to the snarf buffer.

type End

type End int

An End specifies how to draw the end of a line.

const (
	// EndSquare terminates the line perpindicularly
	// to the direction of the line; a thick line with EndSquare
	// on both ends will be a rectangle.
	EndSquare End = 0

	// EndDisc terminates the line by drawing a disc of diameter 1+2*thick
	// centered on the end point.
	EndDisc End = 1

	// EndArrow terminates the line with an arrowhead whose tip
	// touches the endpoint.
	// Use the Arrow function for more control over the arrow shape.
	EndArrow End = 2
)

EndSquare terminates the line perpendicularly to the direction of the line; a thick line with EndSquare on both ends will be a rectangle. EndDisc terminates the line by drawing a disc of diameter 1+2*thick centered on the end point. EndArrow terminates the line with an arrowhead whose tip touches the endpoint. See the Arrow function for more control over arrow shapes.

func Arrow

func Arrow(a, b, c int) End

Arrow permits explicit control of the shape of a line-ending arrow. If all three parameters are zero, it produces the default arrowhead. Otherwise, a sets the distance along line from the end of the regular line to the tip, b sets the distance along line from the barb to the tip, and c sets the distance perpendicular to the line from the edge of the line to the tip of the barb, all in pixels.

type Font

type Font struct {
	Display *Display
	Name    string // name, typically from file.
	Height  int    // max height of image; interline spacing
	Ascent  int    // top of image to baseline
	Scale   int    // pixel scaling
	// contains filtered or unexported fields
}

A Font represents a font that may be used to draw on the display. A Font is constructed by reading a font file that describes how to create a full font from a collection of subfonts, each of which covers a section of the Unicode code space.

A Font is a set of character images, indexed by runes. The images are organized into Subfonts, each containing the images for a small, contiguous set of runes.

Font defines two important dimension fields: ‘Ascent’, the distance from the top of the highest character (actually the top of the image holding all the characters) to the baseline, and ‘Height’, the distance from the top of the highest character to the bottom of the lowest character (and hence, the interline spacing).

func (*Font) BytesSize

func (f *Font) BytesSize(b []byte) Point

ByteSize returns the number of horizontal and vertical pixels that would be occupied by the byte slice if it were drawn using the font.

func (*Font) BytesWidth

func (f *Font) BytesWidth(b []byte) int

ByteWidth returns the number of horizontal pixels that would be occupied by the byte slice if it were drawn using the font.

func (*Font) Free

func (f *Font) Free()

Free frees the server resources for the Font. Fonts have a finalizer that calls Free automatically, if necessary, for garbage collected Images, but it is more efficient to be explicit. TODO: Implement the Finalizer!

func (*Font) RunesSize

func (f *Font) RunesSize(r []rune) Point

RuneSize returns the number of horizontal and vertical pixels that would be occupied by the rune slice if it were drawn using the font.

func (*Font) RunesWidth

func (f *Font) RunesWidth(r []rune) int

RuneWidth returns the number of horizontal pixels that would be occupied by the rune slice if it were drawn using the font.

func (*Font) StringSize

func (f *Font) StringSize(s string) Point

StringSize returns the number of horizontal and vertical pixels that would be occupied by the string if it were drawn using the font.

func (*Font) StringWidth

func (f *Font) StringWidth(s string) int

StringWidth returns the number of horizontal pixels that would be occupied by the string if it were drawn using the font.

type Fontchar

type Fontchar struct {
	X      int   // x position in the image holding the glyphs.
	Top    uint8 // first non-zero scan line.
	Bottom uint8 // last non-zero scan line.
	Left   int8  // offset of baseline.
	Width  uint8 // width of baseline.
}

A Fontchar descibes one character glyph in a font (really a subfont).

type Gray1

type Gray1 struct {
	White bool
}

Gray1 represents a 1-bit black/white color.

func (Gray1) RGBA

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

type Gray2

type Gray2 struct {
	Y uint8
}

Gray2 represents a 2-bit grayscale color.

func (Gray2) RGBA

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

type Gray4

type Gray4 struct {
	Y uint8
}

Gray4 represents a 4-bit grayscale color.

func (Gray4) RGBA

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

type Image

type Image struct {
	// Display is the display the image belongs to.
	// All graphics operations must use images from a single display.
	Display *Display

	// R is the coordinates of the rectangle in the plane for
	// which the Image has defined pixel values.
	// It is read-only and should not be modified.
	R Rectangle

	// Clipr is the clipping rectangle: operations that read or write
	// the image will not access pixels outside clipr.
	// Frequently, clipr is the same as r, but it may differ.
	// See in particular the comment for Repl.
	// Clipr should not be modified directly; use the ReplClipr method instead.
	Clipr Rectangle

	// Pix is the pixel channel format descriptor.
	// See the package documentation for details about pixel formats.
	// It is read-only and should not be modified.
	Pix Pix

	// Depth is the number of bits per pixel in the picture.
	// It is identical to Pix.Depth() and is provided as a convenience.
	// It is read-only and should not be modified.
	Depth int

	// Repl is a boolean value specifying whether the image is tiled
	// to cover the plane when used as a source for a drawing operation.
	// If Repl is false, operations are restricted to the intersection of R and Clipr.
	// If Repl is true, R defines the tile to be replicated and Clipr defines the
	// portion of the plane covered by the tiling; in other words, R is replicated
	// to cover Clipr. In this case, R and Clipr are independent.
	//
	// For example, a replicated image with R set to (0,0)-(1,1)
	// and Clipr set to (0,0)-(100,100), with the single pixel of R set to blue,
	// behaves identically to an image with R and Clipr both set
	// to (0,0)-(100,100) and all pixels set to blue.
	// However, the first image requires far less memory and enables
	// more efficient operations.
	// Repl should not be modified directly; use the ReplClipr method instead.
	Repl bool // Whether the image is replicated (tiles the rectangle).

	Screen *Screen // If non-nil, the associated screen; this is a window.
	// contains filtered or unexported fields
}

An Image represents an image on the server, possibly visible on the display. It is a rectangular picture along with the methods to draw upon it. It is also the building block for higher-level objects such as windows and fonts. In particular, a window is represented as an Image; no special operators are needed to draw on a window.

Most of the graphics methods come in two forms: a basic form, and an extended form that takes an extra Op to specify a Porter-Duff compositing operator to use. The basic forms assume the operator is SoverD, which suffices for the vast majority of applications. The extended forms are named by adding an Op suffix to the basic form's name.

func (*Image) AllocScreen

func (i *Image) AllocScreen(fill *Image, public bool) (*Screen, error)

func (*Image) Arc

func (dst *Image) Arc(c Point, a, b, thick int, src *Image, sp Point, alpha, phi int)

Arc is like Ellipse but draws only that portion of the ellipse starting at angle alpha and extending through an angle of phi. The angles are measured in degrees counterclockwise from the positive x axis.

func (*Image) ArcOp

func (dst *Image) ArcOp(c Point, a, b, thick int, src *Image, sp Point, alpha, phi int, op Op)

ArcOp is like Arc but specifies an explicit Porter-Duff operator.

func (*Image) At

func (i *Image) At(x, y int) color.Color

At returns the standard Color value for the pixel at (x, y). If the location is outside the clipping rectangle, it returns color.Transparent. This operation does a round trip to the image server and can be expensive.

func (*Image) BSpline

func (dst *Image) BSpline(pt []Point, end0, end1 End, radius int, src *Image, sp Point)

BSpline takes the same arguments as Poly but draws a quadratic B-spline rather than a polygon. If the first and last points in p are equal, the spline has periodic end conditions.

func (*Image) BSplineOp

func (dst *Image) BSplineOp(pt []Point, end0, end1 End, radius int, src *Image, sp Point, op Op)

BSplineOp is like BSpline but specifies an explicit Porter-Duff operator.

func (*Image) Bezier

func (dst *Image) Bezier(a, b, c, d Point, end0, end1 End, radius int, src *Image, sp Point)

Bezier draws the cubic Bezier curve defined by Points a, b, c, and d. The end styles are determined by end0 and end1; the thickness of the curve is 1+2*thick. The source is aligned so sp in src corresponds to a in dst.

func (*Image) BezierOp

func (dst *Image) BezierOp(a, b, c, d Point, end0, end1 End, radius int, src *Image, sp Point, op Op)

BezierOp is like Bezier but specifies an explicit Porter-Duff operator.

func (*Image) Border

func (dst *Image) Border(r Rectangle, w int, color *Image, sp Point)

Border draws an outline of rectangle r in the specified color. The outline has width w; if w is positive, the border goes inside the rectangle; if negative, outside. The source is aligned so that sp corresponds to r.Min.

func (*Image) BorderOp

func (dst *Image) BorderOp(r Rectangle, n int, color *Image, sp Point, op Op)

BorderOp is like Border but specifies an explicit Porter-Duff operator.

func (*Image) Bounds

func (i *Image) Bounds() Rectangle

func (*Image) Bytes

func (dst *Image) Bytes(p Point, src *Image, sp Point, f *Font, b []byte) Point

Bytes is like String but accepts a UTF-8-encoded byte slice instead of a string.

func (*Image) BytesBg

func (dst *Image) BytesBg(p Point, src *Image, sp Point, f *Font, b []byte, bg *Image, bgp Point) Point

BytesBg is like StringBg but accepts a UTF-8-encoded byte slice instead of a string.

func (*Image) BytesBgOp

func (dst *Image) BytesBgOp(p Point, src *Image, sp Point, f *Font, b []byte, bg *Image, bgp Point, op Op) Point

BytesBgOp is like StringBgOp but accepts a UTF-8-encoded byte slice instead of a string.

func (*Image) BytesOp

func (dst *Image) BytesOp(p Point, src *Image, sp Point, f *Font, b []byte, op Op) Point

BytesOp is like StringOp but accepts a UTF-8-encoded byte slice instead of a string.

func (*Image) Cload

func (dst *Image) Cload(r Rectangle, data []byte) (int, error)

Cload replaces the specified rectangle in image i with the compressed data, returning the number of bytes copied from data. It is an error if data does not contain pixels for the entire rectangle.

See the package documentation for details about the compressed data format. Each call to Cload must pass data starting at the beginning of a compressed data block, specifically the y coordinate and data length for the block.

func (*Image) ColorModel

func (i *Image) ColorModel() color.Model

ColorModel returns the standard color model of the Image.

func (*Image) Draw

func (dst *Image) Draw(r Rectangle, src, mask *Image, p Point)

Draw is the standard drawing function. Only those pixels within the intersection of dst.R and dst.Clipr will be affected; draw ignores dst.Repl. The operation proceeds as follows (this is a description of the behavior, not the implementation):

1. If Repl is set in src or mask, replicate their contents to fill their clip rectangles.

2. Translate src and mask so p is aligned with r.Min.

3. Set r to the intersection of r and dst.R.

4. Intersect r with src.Clipr. If src.Repl is false, also intersect r with src.R.

5. Intersect r with mask.Clipr. If mask.Repl is false, also intersect r with mask.R

6. For each location in r, combine the dst pixel with the src pixel using the alpha value corresponding to the mask pixel. If the mask has an explicit alpha channel, the alpha value corresponding to the mask pixel is simply that pixel's alpha chan- nel. Otherwise, the alpha value is the NTSC greyscale equivalent of the color value, with white meaning opaque and black transparent. In terms of the Porter-Duff compositing algebra, draw replaces the dst pixels with (src in mask) over dst. (In the extended form provided by DrawOp, “over” is replaced by op).

The various pixel channel formats involved need not be identical. If the channels involved are smaller than 8-bits, they will be promoted before the calculation by replicating the extant bits; after the calculation, they will be truncated to their proper sizes.

Mask may be nil, in which case a fully opaque mask is assumed.

func (*Image) DrawOp

func (dst *Image) DrawOp(r Rectangle, src, mask *Image, p Point, op Op)

DrawOp is like Draw but specifies a Porter-Duff operator op to use in place of “S over D”. That is, dst.Draw(r, src, mask, p) is the same as dst.DrawOp(r, src, mask, p, SoverD).

func (*Image) Ellipse

func (dst *Image) Ellipse(c Point, a, b, thick int, src *Image, sp Point)

Ellipse draws in dst an ellipse centered on c with horizontal and vertical semiaxes a and b. The source is aligned so sp in src corresponds to c in dst. The ellipse is drawn with thickness 1+2*thick.

func (*Image) EllipseOp

func (dst *Image) EllipseOp(c Point, a, b, thick int, src *Image, sp Point, op Op)

EllipseOp is like Ellipse but specifies an explicit Porter-Duff operator.

func (*Image) FillArc

func (dst *Image) FillArc(c Point, a, b int, src *Image, sp Point, alpha, phi int)

FillArc is like Arc but fills the sector with the source color.

func (*Image) FillArcOp

func (dst *Image) FillArcOp(c Point, a, b int, src *Image, sp Point, alpha, phi int, op Op)

FillArcOp is like FillArc but specifies an explicit Porter-Duff operator.

func (*Image) FillBSpline

func (dst *Image) FillBSpline(pt []Point, wind int, src *Image, sp Point)

FillBSpline is like FillPoly but fills the quadratic B-spline defined by p, not the polygon defined by p. The spline is closed with a line if necessary.

func (*Image) FillBSplineOp

func (dst *Image) FillBSplineOp(pt []Point, wind int, src *Image, sp Point, op Op)

FillBSplineOp is like FillBSpline but specifies an explicit Porter-Duff operator.

func (*Image) FillBezier

func (dst *Image) FillBezier(a, b, c, d Point, wind int, src *Image, sp Point)

FillBezier is like FillPoly but fills the cubic Bezier curve defined by a, b, c, d.

func (*Image) FillBezierOp

func (dst *Image) FillBezierOp(a, b, c, d Point, wind int, src *Image, sp Point, op Op)

FillBezierOp is like FillBezier but specifies an explicit Porter-Duff operator.

func (*Image) FillEllipse

func (dst *Image) FillEllipse(c Point, a, b int, src *Image, sp Point)

FillEllipse is like Ellipse but fills the ellipse rather than outlining it.

func (*Image) FillEllipseOp

func (dst *Image) FillEllipseOp(c Point, a, b int, src *Image, sp Point, op Op)

FillEllipseOp is like FillEllipse but specifies an explicit Porter-Duff operator.

func (*Image) FillPoly

func (dst *Image) FillPoly(p []Point, wind int, src *Image, sp Point)

FillPoly is like Poly but fills in the resulting polygon rather than outlining it. The source is aligned so sp corresponds to p[0]. The winding rule parameter wind resolves ambiguities about what to fill if the polygon is self-intersecting. If wind is ^0, a pixel is inside the polygon if the polygon's winding number about the point is non-zero. If wind is 1, a pixel is inside if the winding number is odd. Complementary values (0 or ^1) cause outside pixels to be filled. The meaning of other values is undefined. The polygon is closed with a line if necessary.

func (*Image) FillPolyOp

func (dst *Image) FillPolyOp(p []Point, wind int, src *Image, sp Point, op Op)

FillPolyOp is like FillPoly but specifies an explicit Porter-Duff operator.

func (*Image) Free

func (i *Image) Free() error

Free frees the server resources for the image. Images have a finalizer that calls Free automatically, if necessary, when the Image is garbage collected, but it is more efficient to be explicit.

func (*Image) GenDraw

func (dst *Image) GenDraw(r Rectangle, src *Image, p0 Point, mask *Image, p1 Point)

GenDraw is like Draw except that it aligns the source and mask differently: src is aligned so p0 corresponds to r.Min, while mask is aligned so p1 corresponds to r.Min. GenDraw differs from Draw only when both of src or mask are non-trivial. For most purposes, Draw is sufficient.

func (*Image) Line

func (dst *Image) Line(p0, p1 Point, end0, end1 End, thick int, src *Image, sp Point)

Line draws in dst a line of width 1+2*thick pixels joining p0 and p1. The line is drawn using pixels from the src image aligned so sp in the source corresponds to p0 in the destination. The line touches both p0 and p1. End0 and end1 specify how the ends of the line are drawn; see the documentation for EndSquare and the Arrow function.

Line and the other geometrical operators are equivalent to calls to Draw using a mask produced by the geometric procedure.

func (*Image) LineOp

func (dst *Image) LineOp(p0, p1 Point, end0, end1 End, radius int, src *Image, sp Point, op Op)

LineOp draws a line in the source color from p0 to p1, of thickness 1+2*radius, with the specified ends. The source is aligned so sp corresponds to p0. See the Plan 9 documentation for more information.

func (*Image) Load

func (dst *Image) Load(r Rectangle, data []byte) (n int, err error)

Load replaces the specified rectangle in image dst with the data, returning the number of bytes copied from data. It is an error if data is too small to supply pixels for the entire rectangle.

In data, the pixels are presented one horizontal line at a time, starting with the top-left pixel of r. Each scan line starts with a new byte in the array, leaving the last byte of the previous line partially empty if necessary when i.Depth < 8. Pixels are packed as tightly as possible within a line, regardless of the rectangle being extracted. Bytes are filled from most to least significant bit order, as the x coordinate increases, aligned so that x = r.Min would appear as the leftmost pixel of its byte. Thus, for depth 1, the pixel at x offset 165 within the rectangle will be in a data byte at bit-position 0x04 regardless of the overall rectangle: 165 mod 8 equals 5, and 0x80 >> 5 equals 0x04.

func (*Image) Poly

func (dst *Image) Poly(p []Point, end0, end1 End, radius int, src *Image, sp Point)

Poly draws a general open polygon; it is conceptually equivalent to a series of calls to Line joining adjacent points in the array of points p. The ends end0 and end1 of the polygon are specified as in the Line method; see the EndSquare and Arrow documentation. Interior lines are terminated with EndDisc to make smooth joins. The source is aligned so that sp corresponds to p[0].

func (*Image) PolyOp

func (dst *Image) PolyOp(p []Point, end0, end1 End, radius int, src *Image, sp Point, op Op)

PolyOp is like Poly but specifies an explicit Porter-Duff operator.

func (*Image) ReplClipr

func (dst *Image) ReplClipr(repl bool, clipr Rectangle)

ReplClipr sets the replication boolean and clip rectangle for the specified image.

func (*Image) Runes

func (dst *Image) Runes(p Point, src *Image, sp Point, f *Font, r []rune) Point

Runes is like String but accepts a rune slice instead of a string.

func (*Image) RunesBg

func (dst *Image) RunesBg(p Point, src *Image, sp Point, f *Font, r []rune, bg *Image, bgp Point) Point

RunesBg is like StringBg but accepts a rune slice instead of a string.

func (*Image) RunesBgOp

func (dst *Image) RunesBgOp(p Point, src *Image, sp Point, f *Font, r []rune, bg *Image, bgp Point, op Op) Point

RunesBgOp is like StringBgOp but accepts a rune slice instead of a string.

func (*Image) RunesOp

func (dst *Image) RunesOp(p Point, src *Image, sp Point, f *Font, r []rune, op Op) Point

RunesOp is like StringOp but accepts a rune slice instead of a string.

func (*Image) String

func (dst *Image) String(p Point, src *Image, sp Point, f *Font, s string) Point

String draws the string in the specified font, placing the upper left corner at p. It draws the text using src, with sp aligned to p, using operation SoverD onto dst. String returns a Point that is the position of the next character that would be drawn if the string were longer.

For characters with undefined or zero-width images in the font, the character at font position 0 (NUL) is drawn instead.

func (*Image) StringBg

func (dst *Image) StringBg(p Point, src *Image, sp Point, f *Font, s string, bg *Image, bgp Point) Point

StringBg is like String but draws the background bg behind the characters, with bgp aligned to p, before drawing the text.

func (*Image) StringBgOp

func (dst *Image) StringBgOp(p Point, src *Image, sp Point, f *Font, s string, bg *Image, bgp Point, op Op) Point

StringBgOp is like StringBg but specifies an explicit Porter-Duff operator.

func (*Image) StringOp

func (dst *Image) StringOp(p Point, src *Image, sp Point, f *Font, s string, op Op) Point

StringOp is like String but specifies an explicit Porter-Duff operator.

func (*Image) Unload

func (i *Image) Unload(r Rectangle, data []byte) (n int, err error)

Unload reads a rectangle of pixels from image i into data, returning the number of bytes copied to data. It is an error if data does not contain pixels for the entire rectangle.

See the Load method's documentation for details about the data format.

type Keyboardctl

type Keyboardctl struct {
	C <-chan rune // Channel on which keyboard characters are delivered.
}

Keyboardctl is the source of keyboard events.

type Menu struct {
	Item    []string
	Gen     func(k int, buf []byte) (text []byte, ok bool)
	LastHit int
	// contains filtered or unexported fields
}

A Menu describes a menu of items.

The items are specified either in the static slice Item or by a function Gen that can be called to generate the k'th item (starting with k = 0). Gen should return text, true on success and "", false when k is beyond the end of the menu. LastHit records the previously selected menu item.

type Mouse

type Mouse struct {
	Point          // Location.
	Buttons int    // Buttons; bit 0 is button 1, bit 1 is button 2, etc.
	Msec    uint32 // Time stamp in milliseconds.
}

Mouse is the structure describing the current state of the mouse.

type Mousectl

type Mousectl struct {
	Mouse                // Store Mouse events here.
	C       <-chan Mouse // Channel of Mouse events.
	Resize  <-chan bool  // Each received value signals a window resize (see the display.Attach method).
	Display *Display     // The associated display.
}

Mousectl holds the interface to receive mouse events.

This Go library differs from the Plan 9 C library in its updating of Mouse. Updating the Mouse field is the duty of every receiver from C. The Read method does the update, but any use of C in a select needs to update the field as well, as in:

case mc.Mouse <- mc.C:

In the Plan 9 C library, the sender does the write after the send, but that write could not be relied upon due to scheduling delays, so receivers conventionally also did the write, as above. This write-write race, while harmless, impedes using the race detector to find more serious races, and it is easily avoided: the receiver is now in charge of updating Mouse.

func (*Mousectl) Read

func (mc *Mousectl) Read() Mouse

Read returns the next mouse event.

type Op

type Op int

An Op represents a Porter-Duff compositing operator.

See T. Porter, T. Duff. “Compositing Digital Images”, Computer Graphics (Proc. SIGGRAPH), 18:3, pp. 253-259, 1984.

type Pix

type Pix uint32

Pix represents a pixel format described simple notation: r8g8b8 for RGB24, m8 for color-mapped 8 bits, etc. The representation is 8 bits per channel, starting at the low end, with each byte represnted as a channel specifier (CRed etc.) in the high 4 bits and the number of pixels in the low 4 bits.

func MakePix

func MakePix(list ...int) Pix

MakePix returns a Pix by placing the successive integers into 4-bit nibbles.

func ParsePix

func ParsePix(s string) (Pix, error)

ParsePix is the reverse of String, turning a pixel string such as "r8g8b8" into a Pix value.

func (Pix) Depth

func (p Pix) Depth() int

func (Pix) Split

func (p Pix) Split() []int

Split returns the succesive integers making up p. That is, MakePix(p.Split()) == p. For example, RGB16.Split() is [CRed 5, CGreen, 6, CBlue, 5].

func (Pix) String

func (p Pix) String() string

String prints the pixel format as a string: "r8g8b8" for example.

type Point

type Point = image.Point

A Point is an X, Y coordinate pair, a location in an Image such as the display. The coordinate system has X increasing to the right and Y increasing down.

var ZP Point

ZP is the zero Point.

func Pt

func Pt(x, y int) Point

Pt is shorthand for Point{X: x, Y: y}.

func Repl

func Repl(r Rectangle, p Point) Point

Repl clips the point p to be within the rectangle r by translating p horizontally by an integer multiple of the rectangle width and vertically by an integer multiple of the rectangle height. That is, it returns the point corresponding to the image of p that appears inside the base rectangle r, which represents a tiling of the plane.

type Rectangle

type Rectangle = image.Rectangle

A Rectangle is a rectangular area in an image. By definition, Min.X ≤ Max.X and Min.Y ≤ Max.Y. By convention, the right (Max.X) and bottom (Max.Y) edges are excluded from the represented rectangle, so abutting rectangles have no points in common. Thus, max contains the coordinates of the first point beyond the rectangle. If Min.X > Max.X or Min.Y > Max.Y, the rectangle contains no points.

var ZR Rectangle

ZR is the zero Rectangle.

func Rect

func Rect(x1, y1, x2, y2 int) Rectangle

Rect is shorthand for Rectangle{Min: Pt(x0, y0), Max: Pt(x1, y1)}. Unlike image.Rect, Rect does not swap x1 ↔ x2 or y1 ↔ y2 to put them in canonical order. In this package, a Rectangle with x1 > x2 or y1 > y2 is an empty rectangle.

func Rpt

func Rpt(min, max Point) Rectangle

Rpt is shorthand for Rectangle{min, max}.

func SweepRect

func SweepRect(but int, mc *Mousectl) Rectangle

type Screen

type Screen struct {
	Display *Display // Display connected to the server.

	Fill *Image // Background image behind the windows.
	// contains filtered or unexported fields
}

A Screen is a collection of windows that are visible on an image.

func (*Screen) Free

func (s *Screen) Free() error

Free frees the server resources associated with the screen.

Directories

Path Synopsis
Package frame supports frames of editable text, such as in the Plan 9 text editors sam and acme.
Package frame supports frames of editable text, such as in the Plan 9 text editors sam and acme.

Jump to

Keyboard shortcuts

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