Documentation
¶
Overview ¶
The canvas package provides some a facility for managing independently updating objects inside a graphics window.
The principal type is Canvas, which displays a z-ordered set of objects. New objects may be added, deleted and change their appearance: the Canvas manages any necessary re-drawing.
Any object that implements the Item interface may be placed onto a Canvas, including a Canvas itself, allowing more complex objects to be built relatively easily.
Index ¶
- Constants
- func BorderOp(dst draw.Image, r image.Rectangle, w int, src image.Image, sp image.Point, ...)
- func Box(width, height int, col image.Image, border int, borderCol image.Image) image.Image
- func DrawOp(dst draw.Image, r image.Rectangle, src image.Image, sp image.Point, op draw.Op)
- func ImageOf(it Item) *image.RGBA
- func NewPainter(dst draw.Image, src image.Image, op draw.Op) (p raster.Painter)
- func SliceImage(width, height int, r image.Rectangle, img draw.Image, p image.Point) draw.Image
- func SpanBbox(ss []raster.Span) image.Rectangle
- type Anchor
- type Background
- type Backing
- type Canvas
- func (c *Canvas) AddItem(item Item)
- func (c *Canvas) Atomically(f func(FlushFunc))
- func (c *Canvas) Bbox() image.Rectangle
- func (c *Canvas) Delete(it Item)
- func (c *Canvas) Draw(dst draw.Image, clipr image.Rectangle)
- func (c *Canvas) Flush()
- func (c *Canvas) HandleMouse(_ Flusher, m ui.MouseEvent, ec <-chan interface{}) bool
- func (c *Canvas) HitTest(p image.Point) (hit bool)
- func (c *Canvas) Opaque() bool
- func (c *Canvas) Raise(it, nextto Item, above bool)
- func (c *Canvas) Rect() image.Rectangle
- func (c *Canvas) Replace(it, it1 Item) (replaced bool)
- func (c *Canvas) SetContainer(b Backing)
- type Drawer
- type Ellipse
- type FlushFunc
- type Flusher
- type HandleMouser
- type HandlerItem
- type Image
- type ImageItem
- type Item
- type Line
- type MoveableItem
- type Polygon
- type RasterItem
- func (obj *RasterItem) Add1(p raster.Point)
- func (obj *RasterItem) Add2(p0, p1 raster.Point)
- func (obj *RasterItem) Add3(p0, p1, p2 raster.Point)
- func (obj *RasterItem) Bbox() image.Rectangle
- func (obj *RasterItem) CalcBbox()
- func (obj *RasterItem) Clear()
- func (obj *RasterItem) Draw(dst draw.Image, clipr image.Rectangle)
- func (obj *RasterItem) HitTest(p image.Point) bool
- func (obj *RasterItem) Opaque() bool
- func (obj *RasterItem) SetContainer(b Backing)
- func (obj *RasterItem) SetFill(fill image.Image)
- func (obj *RasterItem) Start(p raster.Point)
- type Slider
- type Text
- type TextItem
- func (d *TextItem) Bbox() image.Rectangle
- func (d *TextItem) CalcBbox()
- func (d *TextItem) Draw(dst draw.Image, clip image.Rectangle)
- func (d *TextItem) HitTest(p image.Point) bool
- func (d *TextItem) Init() *TextItem
- func (d *TextItem) Opaque() bool
- func (d *TextItem) SetContainer(_ Backing)
- func (d *TextItem) SetFill(fill image.Image)
Constants ¶
const ( N = Anchor(1 << iota) S E W Baseline )
Variables ¶
This section is empty.
Functions ¶
func BorderOp ¶
func BorderOp(dst draw.Image, r image.Rectangle, w int, src image.Image, sp image.Point, op draw.Op)
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 Box ¶
Box creates a rectangular image of the given size, filled with the given colour, with a border-size border of colour borderCol.
func NewPainter ¶
NewPainter returns a Painter that will draw from src onto dst using the Porter-Duff composition operator op.
func SliceImage ¶
SliceImage returns an image which is a view onto a portion of img. The returned image has the specified width and height, but all draw operations are clipped to r. The origin of img is aligned with p. Where img overlaps with r, it will be used for drawing operations.
Types ¶
type Background ¶
type Background struct {
// contains filtered or unexported fields
}
A Background is the base layer on which other objects can be layered. It implements the Backing interface and displays a single object only.
func NewBackground ¶
NewBackground creates a new Background object that draws to img, and draws the actual background with bg. The flush function, if non-nil, will be called to whenever changes are to be made visible externally (for example when Flush() is called.
Note that bg is drawn with the draw.Src operation, so it is possible to create images with a transparent background.
func (*Background) Atomically ¶
func (b *Background) Atomically(f func(FlushFunc))
func (*Background) Flush ¶
func (b *Background) Flush()
Flush flushes all pending changes, and makes them visible.
func (*Background) Rect ¶
func (b *Background) Rect() image.Rectangle
func (*Background) SetItem ¶
func (b *Background) SetItem(item Drawer)
SetItem sets the item to draw on top of the background.
type Backing ¶
A Backer represents a graphical area containing a number of Drawer objects. To change its appearance, one of those objects may call Atomically, passing it a function which will be called once to make the changes. The function will be passed a FlushFunc that can be used to inform the Backer of any changes that are made. Rect should return the rectangle that is available for items within the Backing to draw into.
func NullBacking ¶
func NullBacking() Backing
NullBacking returns an object that satisfies the Backing interface but has no actual image associated with it.
type Canvas ¶
type Canvas struct {
// contains filtered or unexported fields
}
A Canvas represents a z-ordered set of drawable Items. As a Canvas itself implements Item and Backing, Canvas's can be nested indefinitely.
func NewCanvas ¶
NewCanvas returns a new Canvas object that is inside backing. The background image, if non-nil, must be opaque, and will used to draw the background. r gives the extent of the canvas.
func (*Canvas) Atomically ¶
Atomically calls f, which can then make changes to the appearance of items in the canvas. See the Backing interface for details
func (*Canvas) HandleMouse ¶
func (c *Canvas) HandleMouse(_ Flusher, m ui.MouseEvent, ec <-chan interface{}) bool
HandleMouse delivers the mouse events to the top-most item that that is hit by the mouse point.
func (*Canvas) Raise ¶
Raise moves the Item it adjacent to nextto in the canvas z-ordering. If above is true, the item will be placed just above nextto, otherwise it will be placed just below. If nextto is nil, then the item will be placed at the very top (above==true) or the very bottom (above==false).
func (*Canvas) SetContainer ¶
type Drawer ¶
The Drawer interface represents the basic level of functionality for a drawn object. SetContainer is called when the object is placed inside another; b will be nil if the object is removed from its container. SetContainer can be called twice in a row with the same object if some ancestor has changed.
The Draw method should draw a representation of the object onto dst. No pixels outside clipr should be changed. It is legitimate for the Drawer object to retain the dst image until SetContainer is called (for instance, to perform its own direct manipulation of the image).
Neither method in Drawer should interact with any object outside its direct control (for example by modifying the appearance of another object using the same Backer)
type Ellipse ¶
type Ellipse struct { Item // contains filtered or unexported fields }
A ellipse object represents an ellipse centered in cr with radiuses ra and rb
func NewEllipse ¶
color, center, radius a radius b and width
func (*Ellipse) SetContainer ¶
type FlushFunc ¶
A FlushFunc can be used to inform a Backing object of a changed area of pixels. r specifies the rectangle that has changed; if drawn is non-nil, it indicates that the rectangle has already been redrawn (only appropriate if all pixels in the rectangle have been non-transparently overwritten); its value gives the item that has changed, which must be a direct child of the Backing object.
type Flusher ¶
type Flusher interface {
Flush()
}
The Flush method is used to flush any pending changes to the underlying image, usually the screen.
type HandleMouser ¶
type HandleMouser interface {
HandleMouse(f Flusher, m ui.MouseEvent, ec <-chan interface{}) bool
}
HandleMouse can be implemented by any object that might wish to handle mouse events. It is called with an initial mouse event, and a channel from which further events can be read. It returns true if the initial mouse event was absorbed. mc should not be used after HandleMouse returns.
type HandlerItem ¶
type HandlerItem interface { Item HandleMouser }
type Image ¶
type Image struct { Item // contains filtered or unexported fields }
An Image represents an rectangular (but possibly transparent) image.
func NewImage ¶
Image returns a new Image which will be drawn using img, with p giving the coordinate of the image's top left corner.
func (*Image) SetContainer ¶
type ImageItem ¶
An ImageItem is an Item that uses an image to draw itself. It is intended to be used as a building block for other Items.
func (*ImageItem) SetContainer ¶
type Item ¶
Values that implement the Item interface may be added to the canvas. They should adhere to the following rules: - No calls to the canvas should be made while in the Draw, Bbox or HitTest methods. - All changes to the appearance of the object should be made using the Atomically function.
type Line ¶
type Line struct { Item // contains filtered or unexported fields }
A line object represents a single straight line.
func (*Line) SetContainer ¶
func (*Line) SetEndPoints ¶
SetEndPoints changes the end coordinates of the Line.
type MoveableItem ¶
A MoveableItem is an item that may be moved by calling SetCentre, where the centre is the central point of the item's bounding box.
func Draggable ¶
func Draggable(it MoveableItem) MoveableItem
Draggable makes any MoveableItem into an object that may be dragged by the mouse.
func Moveable ¶
func Moveable(item Item) MoveableItem
type Polygon ¶
type Polygon struct { Item // contains filtered or unexported fields }
A Polygon represents a filled polygon.
func NewPolygon ¶
Polygon returns a new PolyObject, using col for its fill colour, and using points for its vertices.
func (*Polygon) SetContainer ¶
type RasterItem ¶
type RasterItem struct {
// contains filtered or unexported fields
}
A RasterItem is a low level canvas object that can be used to build higher level primitives. It implements Item, and will calculate (and remember) its bounding box on request.
Otherwise it can be used as a raster.Rasterizer.
func (*RasterItem) Add1 ¶
func (obj *RasterItem) Add1(p raster.Point)
func (*RasterItem) Add2 ¶
func (obj *RasterItem) Add2(p0, p1 raster.Point)
func (*RasterItem) Add3 ¶
func (obj *RasterItem) Add3(p0, p1, p2 raster.Point)
func (*RasterItem) Bbox ¶
func (obj *RasterItem) Bbox() image.Rectangle
func (*RasterItem) CalcBbox ¶
func (obj *RasterItem) CalcBbox()
CalcBbox calculates the current bounding box of all the pixels in the current path.
func (*RasterItem) Clear ¶
func (obj *RasterItem) Clear()
func (*RasterItem) Opaque ¶
func (obj *RasterItem) Opaque() bool
func (*RasterItem) SetContainer ¶
func (obj *RasterItem) SetContainer(b Backing)
func (*RasterItem) SetFill ¶
func (obj *RasterItem) SetFill(fill image.Image)
func (*RasterItem) Start ¶
func (obj *RasterItem) Start(p raster.Point)
type Slider ¶
type Slider struct { Item // contains filtered or unexported fields }
func NewSlider ¶
A Slider shows a mouse-adjustable slider bar. NewSlider returns the Slider item. The value is used to set and get the current slider value; its Type() should be float64; the slider's value is in the range [0, 1].
func (*Slider) HandleMouse ¶
func (obj *Slider) HandleMouse(f Flusher, m ui.MouseEvent, ec <-chan interface{}) bool
func (*Slider) SetContainer ¶
type Text ¶
type Text struct { Item // contains filtered or unexported fields }
func NewText ¶
func NewText(p image.Point, where Anchor, s string, font *truetype.Font, size float64, val values.Value) *Text
NewText creates a new item to display a line of text. If val is non-nil, it should be a string-typed Value, and the Value's text will be displayed instead of s.