gg/context.go

49 lines
911 B
Go

package gg
import "fmt"
// The type is used to provide
// custom behaviour for drawing and updating etc.
type Context struct {
events Events
engine *Engine
image *Image
}
// Get the current engine.
func (c Context) Engine() *Engine {
return c.engine
}
func (c Context) Camera() Camera {
if c.engine == nil {
return nil
}
return c.engine.camera
}
// Get the image to draw to.
// Can be accessed only in the
// Draw(...) call.
func (c Context) Image() *Image {
return c.image
}
// Get the events.
// Available only in the Update(...) call.
func (c Context) Events() Events {
return c.events
}
func (c Context) Dprint(v ...any) {
c.Engine().DebugPrint(c.Image(), fmt.Sprint(v...))
}
func (c Context) Dprintln(v ...any) {
c.Engine().DebugPrint(c.Image(), fmt.Sprintln(v...))
}
func (c Context) Dprintf(format string, v ...any) {
c.Engine().DebugPrint(c.Image(), fmt.Sprintf(format, v...))
}