context.go 911 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package gg
  2. import "fmt"
  3. // The type is used to provide
  4. // custom behaviour for drawing and updating etc.
  5. type Context struct {
  6. events Events
  7. engine *Engine
  8. image *Image
  9. }
  10. // Get the current engine.
  11. func (c Context) Engine() *Engine {
  12. return c.engine
  13. }
  14. func (c Context) Camera() Camera {
  15. if c.engine == nil {
  16. return nil
  17. }
  18. return c.engine.camera
  19. }
  20. // Get the image to draw to.
  21. // Can be accessed only in the
  22. // Draw(...) call.
  23. func (c Context) Image() *Image {
  24. return c.image
  25. }
  26. // Get the events.
  27. // Available only in the Update(...) call.
  28. func (c Context) Events() Events {
  29. return c.events
  30. }
  31. func (c Context) Dprint(v ...any) {
  32. c.Engine().DebugPrint(c.Image(), fmt.Sprint(v...))
  33. }
  34. func (c Context) Dprintln(v ...any) {
  35. c.Engine().DebugPrint(c.Image(), fmt.Sprintln(v...))
  36. }
  37. func (c Context) Dprintf(format string, v ...any) {
  38. c.Engine().DebugPrint(c.Image(), fmt.Sprintf(format, v...))
  39. }