Documentation ¶
Overview ¶
Package tilegraphics implements a graphics rendering using small tiles. This is especially useful for devices with a slow bus to the display, like screens driven over SPI.
Instantiate an Engine object using NewEngine and draw objects on it. The objects can be changed and moved after creation. These changes are recorded, but not directly sent to the screen. They're only sent on the next call to Display(). It is therefore recommended to only call Display() when the display should really be updated, to send all the updates in a single batch for improved performance.
Index ¶
- Constants
- func ApplyAlpha(c color.RGBA, alpha uint8) color.RGBA
- func Blend(bottom, top color.RGBA) color.RGBA
- type Displayer
- type Engine
- func (e *Engine) Display()
- func (e *Engine) NewLayer(x, y, width, height int16, background color.RGBA) *Layer
- func (e *Engine) NewLine(x1, y1, x2, y2 int16, stroke color.RGBA) *Line
- func (e *Engine) NewRectangle(x, y, width, height int16, c color.RGBA) *Rectangle
- func (e *Engine) SetBackgroundColor(background color.RGBA)
- type Layer
- func (l *Layer) Move(x, y, width, height int16)
- func (l *Layer) NewLayer(x, y, width, height int16, background color.RGBA) *Layer
- func (l *Layer) NewLine(x1, y1, x2, y2 int16, stroke color.RGBA) *Line
- func (l *Layer) NewRectangle(x, y, width, height int16, c color.RGBA) *Rectangle
- func (l *Layer) SetBackgroundColor(background color.RGBA)
- type Line
- type Rectangle
Constants ¶
const TileSize = 8
TileSize is the size (width and height) of a tile. A tile will take up TileSize*TileSize*4 bytes of memory during rendering.
Variables ¶
This section is empty.
Functions ¶
func ApplyAlpha ¶
ApplyAlpha takes a color (that may be semi-transparent) and applies the given alpha to it, making it even more transparent. It does so while taking gamma into account, see Blend.
func Blend ¶
Blend takes a fully opaque background color and a foreground color that may be semi-transparent and blends them together.
Color blending uses a gamma of 2.0, which is close to the commonly used gamma of ~2.2 but is much easier to calculate efficiently. It is slightly off the ideal gamma curve, but in practice it looks almost identical.
For more information on why blending isn't trivial in sRGB color space: https://www.youtube.com/watch?v=LKnqECcg6Gw https://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-about-gamma/ https://ninedegreesbelow.com/photography/linear-gamma-blur-normal-blend.html
Types ¶
type Displayer ¶
type Displayer interface { // Size returns the display size in pixels. It must never change. Size() (int16, int16) // Display sends the last updates to the screen, if needed. // The display might be updated directly or only after this method has been // called, depending on the implementation. Display() error // FillRectangle fills the given rectangle with the given color, and returns // an error if something went wrong. FillRectangle(x, y, width, height int16, c color.RGBA) error // FillRectangleWithBuffer fills the given rectangle with a slice of colors. // The buffer is stored in row major order. FillRectangleWithBuffer(x, y, width, height int16, buffer []color.RGBA) error }
Displayer is the display interface required by the rendering engine.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the actual rendering engine. Use NewEngine to construct a new rendering engine.
func (*Engine) Display ¶
func (e *Engine) Display()
Display updates the display with all the changes that have been done since the last update.
func (*Engine) NewLayer ¶
NewLayer creates a new layer to the display with the given background color.
func (*Engine) NewLine ¶
NewLine creates a new line with the two given coordinates and the given stroke color.
func (*Engine) NewRectangle ¶
NewRectangle adds a new rectangle to the display with the given color.
func (*Engine) SetBackgroundColor ¶
SetBackgroundColor updates the background color of the display. Note that the alpha channel should be 100% (255) and will be ignored.
type Layer ¶
type Layer struct {
// contains filtered or unexported fields
}
Layer contains other objects, but makes sure no containing objects will draw outside of its boundaries. This object provides some encapsulation and improves performance when rendering many objects on a screen.
func (*Layer) NewLayer ¶
NewLayer returns a new layer inside this layer, with the given coordinates (relative to the parent layer) and the given background color.
func (*Layer) NewLine ¶
NewLine creates a new line with the given coordinates and line color. There is no restriction on the order of coordinates. Note that x2, y2 is inclusive, not exlusive, meaning that those pixels will get painted as well.
func (*Layer) NewRectangle ¶
NewRectangle adds a new rectangle to the layer with the given color.
func (*Layer) SetBackgroundColor ¶
SetBackgroundColor updates the background color of this layer.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
bounce
This is a small example (and test) how to use tilegraphics.
|
This is a small example (and test) how to use tilegraphics. |
layers
This is a small example (and test) how to use tilegraphics.
|
This is a small example (and test) how to use tilegraphics. |
reveal
Example to show fast show/hide of a layer, by "rolling" it up and down.
|
Example to show fast show/hide of a layer, by "rolling" it up and down. |
Package imagescreen implements a fake screen (actually, an image) that can be used for testing the tilegraphics package.
|
Package imagescreen implements a fake screen (actually, an image) that can be used for testing the tilegraphics package. |
Package sdlscreen implements a Displayer interface as required by tilegraphics and outputs using SDL2.
|
Package sdlscreen implements a Displayer interface as required by tilegraphics and outputs using SDL2. |
Package testscreen provides a demo screen for small examples.
|
Package testscreen provides a demo screen for small examples. |