Documentation
¶
Overview ¶
Package g2d is a framework to create 2D graphic applications.
Index ¶
- Variables
- func BytesFromImage(img image.Image) []byte
- func ImageFromFile(path string) (image.Image, error)
- type Configuration
- type Framebuffer
- type Graphics
- type Layer
- type Properties
- type Rectangle
- type RectanglesLayer
- type Stats
- type Texture
- type Window
- type WindowImpl
- func (wnd *WindowImpl) Close()
- func (wnd *WindowImpl) Custom(obj interface{})
- func (wnd *WindowImpl) OnButtonDown(buttonCode int, doubleClicked bool) error
- func (wnd *WindowImpl) OnButtonUp(buttonCode int, doubleClicked bool) error
- func (wnd *WindowImpl) OnClose() (bool, error)
- func (wnd *WindowImpl) OnConfig(config *Configuration) error
- func (wnd *WindowImpl) OnCreate() error
- func (wnd *WindowImpl) OnCustom(obj interface{}) error
- func (wnd *WindowImpl) OnDestroy(err error) error
- func (wnd *WindowImpl) OnFocus(focus bool) error
- func (wnd *WindowImpl) OnFramebufferCreated(texture Framebuffer) error
- func (wnd *WindowImpl) OnKeyDown(keyCode int, repeated uint) error
- func (wnd *WindowImpl) OnKeyUp(keyCode int) error
- func (wnd *WindowImpl) OnMinimize() error
- func (wnd *WindowImpl) OnMouseMove() error
- func (wnd *WindowImpl) OnMove() error
- func (wnd *WindowImpl) OnResize() error
- func (wnd *WindowImpl) OnRestore() error
- func (wnd *WindowImpl) OnShow() error
- func (wnd *WindowImpl) OnTextureLoaded(texture Texture) error
- func (wnd *WindowImpl) OnUpdate() error
- func (wnd *WindowImpl) OnWheel(rotation float32) error
- func (wnd *WindowImpl) Quit()
- func (wnd *WindowImpl) Show(window Window)
- func (wnd *WindowImpl) Update()
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func BytesFromImage ¶
BytesFromImage returns bytes from image. (This is for test purposes.)
Types ¶
type Configuration ¶
type Configuration struct {
ClientX, ClientY int
ClientWidth, ClientHeight int
ClientWidthMin, ClientHeightMin int
ClientWidthMax, ClientHeightMax int
MouseLocked, Borderless, Dragable bool
Resizable, Fullscreen, Centered bool
Title string
}
Configuration is the initial setting of window.
type Graphics ¶
type Graphics struct {
BgR, BgG, BgB float32
VSync, AVSync bool
Layers []Layer
// contains filtered or unexported fields
}
Graphics draws graphics.
func (*Graphics) CreateFramebuffer ¶
CreateFramebuffer creates a buffer to draw to. [not implemented]
func (*Graphics) LoadTexture ¶
LoadTexture loads a texture into video memory. This is asynchronous. After the texture has been loaded OnTextureLoaded is called. (Loading a new texture with same id as a previous one will release the previous texture.)
type Properties ¶
type Properties struct {
MouseX, MouseY int
ClientX, ClientY int
ClientWidth, ClientHeight int
ClientWidthMin, ClientHeightMin int
ClientWidthMax, ClientHeightMax int
MouseLocked, Borderless, Dragable bool
Resizable, Fullscreen bool
Title string
}
Properties are the current window properties.
type Rectangle ¶
type Rectangle struct {
X, Y, Width, Height float32
R, G, B, A float32
RotX, RotY, RotAlpha float32
TexRef, TexX, TexY int
TexWidth, TexHeight int
Enabled bool
// contains filtered or unexported fields
}
Rectangle is an entity from a RectanglesLayer.
type RectanglesLayer ¶
type RectanglesLayer struct {
Enabled bool
// contains filtered or unexported fields
}
RectanglesLayer is a layer holding rectangles.
func (*RectanglesLayer) NewEntity ¶
func (layer *RectanglesLayer) NewEntity() *Rectangle
NewEntity returns a new instance of Rectangle.
func (*RectanglesLayer) Release ¶
func (layer *RectanglesLayer) Release(r *Rectangle) *Rectangle
Release releases the entity. This entity may be reused when calling NewEntity.
func (*RectanglesLayer) UseTexture ¶
func (layer *RectanglesLayer) UseTexture(ref, textureId int)
UseTexture associates a reference with a texture. Reference must be in range of [0, 15].
type Texture ¶
type Texture interface {
Id() int
RGBABytes() ([]byte, error)
Dimensions() (int, int)
GenMipMap() bool
IsMipMap() bool
FilterLinear() bool
}
Texture provides a texture.
type Window ¶
type Window interface {
OnConfig(config *Configuration) error
OnCreate() error
OnShow() error
OnResize() error
OnMove() error
OnKeyDown(keyCode int, repeated uint) error
OnKeyUp(keyCode int) error
OnMouseMove() error
OnButtonDown(buttonCode int, doubleClicked bool) error
OnButtonUp(buttonCode int, doubleClicked bool) error
OnWheel(rotation float32) error
OnCustom(obj interface{}) error
OnTextureLoaded(texture Texture) error
OnFramebufferCreated(buffer Framebuffer) error
OnUpdate() error
OnClose() (bool, error)
OnDestroy(error) error
OnMinimize() error
OnRestore() error
OnFocus(focus bool) error
Custom(obj interface{})
Update()
Close()
Quit()
Show(window Window)
// contains filtered or unexported methods
}
Window is callback for window handling.
type WindowImpl ¶
type WindowImpl struct {
Props Properties
Stats Stats
Gfx Graphics
// contains filtered or unexported fields
}
WindowImpl is the obligatory struct to embed, when using interface Window.
func (*WindowImpl) Custom ¶
func (wnd *WindowImpl) Custom(obj interface{})
Custom triggers OnCustom event.
func (*WindowImpl) OnButtonDown ¶
func (wnd *WindowImpl) OnButtonDown(buttonCode int, doubleClicked bool) error
OnButtonDown is called when mouse button has been pressed.
func (*WindowImpl) OnButtonUp ¶
func (wnd *WindowImpl) OnButtonUp(buttonCode int, doubleClicked bool) error
OnButtonUp is called when mouse button has been released.
func (*WindowImpl) OnClose ¶
func (wnd *WindowImpl) OnClose() (bool, error)
OnClose is called after close button of window has been pressed. If function returns true, window will be destroyed.
func (*WindowImpl) OnConfig ¶
func (wnd *WindowImpl) OnConfig(config *Configuration) error
OnConfig is called before creating the window. Configuration is used to create a window.
func (*WindowImpl) OnCreate ¶
func (wnd *WindowImpl) OnCreate() error
OnCreate is called after window has been created. This event could be used to allocate ressources and set graphics.
func (*WindowImpl) OnCustom ¶
func (wnd *WindowImpl) OnCustom(obj interface{}) error
OnCustom is called after calling Custom().
func (*WindowImpl) OnDestroy ¶
func (wnd *WindowImpl) OnDestroy(err error) error
OnDestroy is called before window gets destroyed.
func (*WindowImpl) OnFocus ¶
func (wnd *WindowImpl) OnFocus(focus bool) error
OnFocus is called when window gets or loses focus.
func (*WindowImpl) OnFramebufferCreated ¶
func (wnd *WindowImpl) OnFramebufferCreated(texture Framebuffer) error
OnFramebufferCreated is called after texture has been created.
func (*WindowImpl) OnKeyDown ¶
func (wnd *WindowImpl) OnKeyDown(keyCode int, repeated uint) error
OnKeyDown is called when a key has been pressed. If key stayes pressed, parameter repeated is != 0.
func (*WindowImpl) OnKeyUp ¶
func (wnd *WindowImpl) OnKeyUp(keyCode int) error
OnKeyUp is called when a key has been released.
func (*WindowImpl) OnMinimize ¶
func (wnd *WindowImpl) OnMinimize() error
OnMinimize is called after window has been minimized.
func (*WindowImpl) OnMouseMove ¶
func (wnd *WindowImpl) OnMouseMove() error
OnMouseMove is called when mouse is moved. New properties are in wnd.Props.
func (*WindowImpl) OnMove ¶
func (wnd *WindowImpl) OnMove() error
OnMove is called when Window is moved. New properties are in wnd.Props.
func (*WindowImpl) OnResize ¶
func (wnd *WindowImpl) OnResize() error
OnResize is called when Window is resized. New properties are in wnd.Props.
func (*WindowImpl) OnRestore ¶
func (wnd *WindowImpl) OnRestore() error
OnRestore is called after window has returned from minimized state.
func (*WindowImpl) OnShow ¶
func (wnd *WindowImpl) OnShow() error
OnShow is called after window has been set visible. This event culd be used to start animations.
func (*WindowImpl) OnTextureLoaded ¶
func (wnd *WindowImpl) OnTextureLoaded(texture Texture) error
OnTextureLoaded is called after texture has been loaded to video memory.
func (*WindowImpl) OnUpdate ¶
func (wnd *WindowImpl) OnUpdate() error
OnCustom is called after calling Update(). After OnUpdate graphis is redrawn.
func (*WindowImpl) OnWheel ¶
func (wnd *WindowImpl) OnWheel(rotation float32) error
OnWheel is called when mouse wheel has been moved.