Documentation ¶
Overview ¶
Package pix provides set of drawing functions for simple pixmap based displays. Such displays, unlike the vector or display-list based ones, require data in the form of ready-made array of pixels.
Only one drawing operation is required from the display driver: drawing an image on a selected rectangle. This basic drawing primitive is supported in hardware by many simple LCD and OLED display controlers like ILI9341, ILI948x, ST7796S, HX8357, SSD1351 and can be also easily implemented in software for other displays.
Index ¶
- Constants
- func IsConvex(vertices ...image.Point) bool
- func StringWidth(s string, f font.Face) int
- func Width(s []byte, f font.Face) int
- type Area
- func (a *Area) Arc(p image.Point, mina, minb, maxa, maxb int, th0, th1 int32, fill bool)
- func (a *Area) Bounds() image.Rectangle
- func (a *Area) Color() color.Color
- func (a *Area) Draw(r image.Rectangle, src image.Image, sp image.Point, mask image.Image, ...)
- func (a *Area) Err(clear bool) error
- func (a *Area) Fill(r image.Rectangle)
- func (a *Area) FillQuad(p0, p1, p2, p3 image.Point)
- func (a *Area) Flush()
- func (a *Area) Line(p0, p1 image.Point)
- func (a *Area) Mirror() int
- func (a *Area) NewTextWriter(f font.Face) *TextWriter
- func (a *Area) Origin() image.Point
- func (a *Area) Point(x, y int)
- func (a *Area) Quad(p0, p1, p2, p3 image.Point, fill bool)
- func (a *Area) Rect() image.Rectangle
- func (a *Area) RoundRect(p0, p1 image.Point, ra, rb int, fill bool)
- func (a *Area) SetColor(c color.Color)
- func (a *Area) SetColorRGBA(r, g, b, alpha uint8)
- func (a *Area) SetMirror(mvxy int)
- func (a *Area) SetOrigin(origin image.Point)
- func (a *Area) SetRect(r image.Rectangle)
- type Display
- func (d *Display) Bounds() image.Rectangle
- func (d *Display) Driver() Driver
- func (d *Display) Err(clear bool) error
- func (d *Display) Flush()
- func (d *Display) NewArea(r image.Rectangle) *Area
- func (d *Display) Rect() image.Rectangle
- func (d *Display) SetDir(dir int)
- func (d *Display) SetOrigin(origin image.Point)
- func (d *Display) SetRect(r image.Rectangle)
- type Driver
- type TextWriter
Constants ¶
const ( MI = images.MI // identity (no operation) MV = images.MV // swap X with Y MX = images.MX // mirror X axis MY = images.MY // mirror Y axis )
const ( NoWrap byte = iota WrapNewLine WrapSameLine )
Wrapping modes determine what TextWriter does if the string does not fit in the drawing area.
const ( BreakAny byte = iota // break at any rune BreakSpace // break at unicode White Space )
Line breaking mode.
Variables ¶
This section is empty.
Functions ¶
func StringWidth ¶
StringWidth returns the number of horizontal pixels that would be occupied by the string if it were drawn using the given font face and NoWrap mode.
Types ¶
type Area ¶
type Area struct {
// contains filtered or unexported fields
}
Area is the drawing area on the display. It has its own coordinates independent of its position on the display. Only one goroutine can use an area at the same time.
func (*Area) Arc ¶
Arc draws an arc with the center at p. The mina, minb, maxa, maxb represent the minimal and maximal radiuses in x and y direction. The th0 and th1 represent the starting and ending angle of the arc.
func (*Area) Draw ¶
func (a *Area) Draw(r image.Rectangle, src image.Image, sp image.Point, mask image.Image, mp image.Point, op draw.Op)
Draw works like draw.DrawMask with dst set to the image representing the whole area.
func (*Area) Err ¶
Err runs through all the displays covered by a and calls thier Err methods until it encounters non-nil error.
func (*Area) FillQuad ¶
FillQuad draws a filled convex quadrilateral or triangle described by the given vertices. It obeys the filling rules so can be used to draw filled polygons composed of adjacent quadrilaterals/triangles ensuring that the common edges are drawn once. FillQuad draws a triangle if two adjacent vertices are identical.
func (*Area) Flush ¶
func (a *Area) Flush()
Flush runs through all the displays covered by a and calls thier Flush methods.
func (*Area) NewTextWriter ¶
func (a *Area) NewTextWriter(f font.Face) *TextWriter
NewTextWriter provides a conveniet way to create new TextWriter. It can be used in place of the following set of statements:
w := new(TextWriter) w.Area = a w.Color = &image.Uniform{a.Color()} w.Face = f w.Wrap = WrapNewLine w.Pos = a.Bounds().Min _, w.Offset.Y = f.Size() // ascent
func (*Area) Origin ¶
Returns the coordinate of the upper left corner of the area in the area's own coordinate system. The origin equals to a.Bounds().Min in MI mirror mode.
func (*Area) Quad ¶
Quad draws a quadrilateral or triangle described by the given vertices. If fill is true the quadrilateral must be convex. Quad draws a triangle if two adjacent vertices are identical.
func (*Area) RoundRect ¶
RoundRect can draw rectangles, ellipses and circles. If ra = rb = 0 it draws an empty or filled rectangle with a given diagonal (p0, p1). Non-zero ra enlarges the rectangle horizontally, non-zero rb enlarges it vertically. The enlarged rectangle has rounded corners with eliptic shape. If p0 = p1 RoundRect draws an ellipse with a given minor and major radius.
func (*Area) SetColorRGBA ¶
SetColorRGBA is equivalent of SetColor(color.RGBA{r, g, b, alpha}). Notice that r, g, b must be alpha-premultiplied, e.g. they must be less than or equal to alpha.
func (*Area) SetMirror ¶
SetMirror sets mirror drawing mode. It affects all drawing methods and Bounds. Other Area's methods are unaffected.
type Display ¶
type Display struct {
// contains filtered or unexported fields
}
Display represents a pixmap based display.
func (*Display) Flush ¶
func (d *Display) Flush()
Flush ensures that everything drawn so far has been sent to the display controller. Using it is not required if the driver draws directly to the display without any buffering. Even then it is worth using Flush for code portability.
func (*Display) NewArea ¶
NewArea provides a convenient way to create a drawing area on the display. Use NewArea for areas that occupy more than one display.
func (*Display) SetDir ¶
SetDir sets the display direction by rotate its default coordinate system by dir*90 degrees. The positive number means clockwise rotation, the negative one means counterclockwise rotation.
After SetDir the coordinates of all areas that use this display must be re-set (usng SetRect method) and their content should be redrawn. Use a.SetRect(a.Rect()) if the coordinates should remain the same.
type Driver ¶
type Driver interface { // SetDir sets the display direction rotating its default coordinate system // by dir*90 degrees. It returns the bounds of the frame memory for the new // direction. NewDisplay calls SetDir(0) before any other Driver method is // called so this is a good place for initialization code if required. SetDir(dir int) image.Rectangle // Draw works like draw.DrawMask with dst set to the image representing the // whole frame memory. // // The draw.Over operator may be implemented in a limited way but it must // at least support 1-bit transparency. // // Draw may assume the r is a non-empty rectangle that fits entirely on the // display and is entirely covered by src and mask. // // Draw is actually the only drawing operation required from a display // controller. The Fill operation below can be easily implemented by drawing // an uniform image. Draw(r image.Rectangle, src image.Image, sp image.Point, mask image.Image, mp image.Point, op draw.Op) // SetColor sets the color used by Fill method. SetColor(c color.Color) // Fill helps to increase prformance when drawing filled rectangles. Any // other geometric shape is drawn as a set of filed rectangles. // // Fill(r) is intended to be a faster counterpart of // // Draw(r, image.Uniform{c}, image.Point{}, nil, image.Point{}, draw.Over) // // where c is the color set by SetColor. Fill(r image.Rectangle) // Flush allows to flush the drivers internal buffers. Drivers are allowed // to implement any kind of buffering if the direct drawing to the frame // memory is problematic or inefficient. Flush() // Err returns the saved error and clears it if clear is true. If an error // has occured the driver should avoid any actions that may cause further // errors until the recorded error is cleared. Err(clear bool) error }
Driver defines the interface to be implemented by display controller drivers or anything else that wants to use drawing functions of pix package.
type TextWriter ¶
type TextWriter struct { Area *Area // drawing area Face font.Face // source of glyphs Color image.Image // glyph color (foreground image) Pos image.Point // position of the next glyph Offset image.Point // offset from the Pos to the glyph origin Wrap byte // wrapping mode Break byte // line breaking mode // contains filtered or unexported fields }
TextWriter allows to write a text on an area. At least the Area, Face and Color fields must be set before use it.
Notice that the Color field type is image.Image, not color.Color. Set it to &image.Uniform{color} for traditional uniform color of glyphs.
func (*TextWriter) SetColor ¶
func (w *TextWriter) SetColor(c color.Color)
SetColor provides a convenient way to set drawing color. If the w.Color contains value of type *image.Uniform it modifies the color of the current image. Otherwise it sets w.Color to &image.Uniform{c}.
func (*TextWriter) SetFace ¶
func (w *TextWriter) SetFace(f font.Face)
SetFace provides a convenient way to set w.Face and at the same time modify w.Offset in such a way that the current baseline is unaffected.
func (*TextWriter) WriteString ¶
func (w *TextWriter) WriteString(s string) (int, error)
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package displays contains initialization functions for the most popular displays.
|
Package displays contains initialization functions for the most popular displays. |
driver
|
|
dummydrv
Package dummydrv provides a dummy implementation of pix.Driver.
|
Package dummydrv provides a dummy implementation of pix.Driver. |
fbdrv
Package fbdrv provides frame-buffer based drivers for pix graphics library.
|
Package fbdrv provides frame-buffer based drivers for pix graphics library. |
fbdrv/ssd1306
Package ssd1306 provides driver to SSD1306 based displays.
|
Package ssd1306 provides driver to SSD1306 based displays. |
imgdrv
Package imgdrv provides a minimal driver based on Go image/draw package.
|
Package imgdrv provides a minimal driver based on Go image/draw package. |
tftdrv
Package tftdrv defines the Display Controller Interface (DCI) and provides generic drivers to the graphics controllers that can be found in a wide variety of LCD and OLED displays.
|
Package tftdrv defines the Display Controller Interface (DCI) and provides generic drivers to the graphics controllers that can be found in a wide variety of LCD and OLED displays. |
tftdrv/ili9341
Package ili9341 provides driver to ILI9341 based displays.
|
Package ili9341 provides driver to ILI9341 based displays. |
tftdrv/ili9486
Package ili9486 provides driver to ILI9486 based displays.
|
Package ili9486 provides driver to ILI9486 based displays. |
tftdrv/ssd1351
Package ssd1351 provides driver to SSD1351 based displays.
|
Package ssd1351 provides driver to SSD1351 based displays. |
tftdrv/st7789
Package st7789 provides driver to ST7789 based displays.
|
Package st7789 provides driver to ST7789 based displays. |