Documentation ¶
Index ¶
- type Canvas
- type Directions
- type HAlign
- type Image
- type Rectangle
- func (r Rectangle) Carve(edge Directions, length int32) (carved Rectangle, rest Rectangle)
- func (r Rectangle) Fill(renderer Renderer, color api.RGBA)
- func (r Rectangle) Move(dx, dy int32) Rectangle
- func (r Rectangle) Position(width, height int32, horiz HAlign, vert VAlign) Rectangle
- func (r Rectangle) Scale(factor float32) Rectangle
- func (r Rectangle) Shrink(dw, dh int32) Rectangle
- func (r Rectangle) Transformation() Transform
- func (r Rectangle) Translation() Transform
- type Renderer
- type Transform
- type TransitionCurve
- type VAlign
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Canvas ¶
type Canvas interface { // Finish resets the target of the underlying renderer and returns the // rendered image. Finish() Image // Close resets the target of the underlying renderer and deletes the // underlying texture if it was not yet finished. // It is idempotent and does nothing if Finish() was called before. Close() }
Canvas is a facility to render content into a rectangular canvas. use it to pre-render content into a texture you can later copy to the renderer when rendering a scene.
Creation of a Canvas sets the target of the underlying Renderer to the texture of this Canvas. Ensure that you either Close or Finish a Canvas object after creating it to reset the renderer's target. It is recommended to use `defer canvas.Close()` right after creation, which will do nothing if you explicitly call Finish() in the following code.
To draw into the canvas, simply use the Renderer API.
type Directions ¶
type Directions uint8
Directions is a bitset of directions.
const ( // Nowhere contains no direction at all. Nowhere Directions = 0 // North is the northern direction North Directions = 1 << iota // East is the eastern direction East // South is the southern direction South // West is the western direction West // Everywhere contains all directions. Everywhere = North | East | South | West )
type Image ¶
type Image struct { TextureID uint32 Width, Height int32 // Flipped describes the row order in the image data. // true -> first datapoint in image data is lower left corner. // false -> first datapoint in image data is upper left corner. // This is used because loading image files returns the top row first, // while internally OpenGL places the bottom row first (e.g. when rendering // to a texture). Flipped bool // true iff the texture has an alpha channel. HasAlpha bool }
Image is a rectangular image stored as OpenGL texture `id` is the name of an OpenGL texture iff width!=0. any Image width width==0 is considered the empty image.
In the context of this API, this type should be considered opaque with only Width and Height being read-accessible. The fields are public so that plugins can use the data for custom OpenGL processing.
func EmptyImage ¶
func EmptyImage() Image
EmptyImage returns an image that has no linked OpenGL texture.
type Rectangle ¶
Rectangle describes a rectangle positioned on the screen.
The screen coordinates are (0,0) at the lower left corner and (width, height) at the upper right corner.
Rectangle is the high-level API for positioning stuff on the screen. It provides functionality to position one rectangle in another one and so on. You can use it in conjunction with the lower-level Transform API which can do rotations by using Rectangle's Translation() / Transformation() funcs.
func (Rectangle) Carve ¶
func (r Rectangle) Carve(edge Directions, length int32) (carved Rectangle, rest Rectangle)
Carve removes a rectangle of the given length starting at the given edge from the current rectangle.
edge must be North, East, South or West. The carved rectangle is returned as `carved`, the remaining rectangle as `rest`
func (Rectangle) Position ¶
Position returns a rectangle with the given width and height, which is position in the current rectangle according to the given flags.
giving HStretch and VStretch will override the given width and height respectively, the other positioning flags will only set the position.
func (Rectangle) Scale ¶
Scale scales the rectangle's width and height by the given factor, repositioning it so that the center stays the same.
func (Rectangle) Shrink ¶
Shrink removes dw from the rectangles width and dh from its height, repositioning it so that the center stays the same.
func (Rectangle) Transformation ¶
Transformation returns the transformation needed to transform a square with edge length of 1.0 centered around the origin to the subject rectangle.
func (Rectangle) Translation ¶
Translation returns the transformation needed to move an object centered on the origin to the center of the rectangle.
type Renderer ¶
type Renderer interface { // OutputSize returns a rectangle that describes the dimensions in pixels // of the current rendering area. X and Y are always 0. // // This rectangle will be the whole OpenGL surface by default, but if a Canvas // is active, it returns the Canvas' size. OutputSize() Rectangle // Unit is the scaled smallest unit in pixels. It is defined as being // 1/144 of the screen's width or height, whichever is smaller. // Borders typically have the size of one Unit. // // Use this value as base for calculating sizes to make your renderer output // scale depending on the target display size. Not using lengths smaller than // Unit avoids making stuff too small for your users to see. // // Font sizes depend directly on this size. Unit() int32 // FillRect fills a rectangle with the specified color. // The rectangle is a square with edge length of 1.0 centered around the // origin, transformed with the given transformation. // // For the high-level API, use Rectangle's Fill() instead. FillRect(t Transform, color api.RGBA) // DrawImage renders the given image if it is not empty on a square with // edge length of 1.0 centered around the origin, transformed with the given // transformation. alpha modifies the image's opacity. // // For the high-level API, use Image's Draw() instead. DrawImage(image Image, t Transform, alpha uint8) // RenderText renders the given text with the given font into an image with // transparent background. // Returns an empty image if it wasn't able to create the texture. RenderText(text string, font api.Font) Image // CreateCanvas creates a canvas to draw content into, and fills it with the // given background. The returned content rectangle is the canvas area minus // the borders. // // Borders are added in each given direction. Border width/height is added to // the given innerWidth / innerHeight values. // // The texture created by the canvas will have an alpha channel only if the // primary color has an alpha value other than 255, or if a mask is set and // the secondary color has an alpha value other than 255. CreateCanvas(innerWidth, innerHeight int32, bg api.Background, borders Directions) (canvas Canvas, content Rectangle) // LoadImageFile loads an image file from the specified URL. // if an error is returned, the returned image is empty. // // if scaleDownToOutput is true, the image is scaled down to the output // context's dimensions so that it completely fits into the display while // preserving aspect ratio. // // The image will always be scaled down to GL_MAX_TEXTURE_SIZE if its // dimensions exceed it. LoadImageFile(path *url.URL, scaleDownToOutput bool) (Image, error) // LoadImageMem loads an image from data in memory. // if an error is returned, the returned image is empty. // // scaleDownToOutput work like for LoadImageFile. LoadImageMem(data []byte, scaleDownToOutput bool) (Image, error) // FreeImage destroys the texture associated with the image (if one exists) // and sets i to be the empty image. Does nothing on empty images. FreeImage(i *Image) }
Renderer describes an object providing functions for rendering objects.
type Transform ¶
type Transform [6]float32
Transform encodes a 2D affine transformation matrix
func (Transform) Rotate ¶
Rotate adds a rotation to the transformation. The given angle is in radian.
type TransitionCurve ¶
type TransitionCurve struct { // Duration sets the length of the transition Duration time.Duration }
TransitionCurve provides various curves useful for smooth transitions. All its methods return a float between 0.0 and 1.0 calculated from the given elapsed time in relation to the total duration.