A rendering engine library for Go supporting both SDL2 and WebAssembly (HTML Canvas) targets.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.4 KiB

  1. package canvas
  2. import (
  3. "time"
  4. "git.kirsle.net/apps/doodle/lib/events"
  5. "git.kirsle.net/apps/doodle/lib/render"
  6. )
  7. // Engine implements a rendering engine targeting an HTML canvas for
  8. // WebAssembly targets.
  9. type Engine struct {
  10. canvas Canvas
  11. startTime time.Time
  12. width int
  13. height int
  14. ticks uint32
  15. // Private fields.
  16. events *events.State
  17. running bool
  18. }
  19. // New creates the Canvas Engine.
  20. func New(canvasID string) (*Engine, error) {
  21. canvas := GetCanvas(canvasID)
  22. engine := &Engine{
  23. canvas: canvas,
  24. startTime: time.Now(),
  25. events: events.New(),
  26. width: canvas.ClientW(),
  27. height: canvas.ClientH(),
  28. }
  29. return engine, nil
  30. }
  31. // WindowSize returns the size of the canvas window.
  32. func (e *Engine) WindowSize() (w, h int) {
  33. return e.canvas.ClientW(), e.canvas.ClientH()
  34. }
  35. // GetTicks returns the current tick count.
  36. func (e *Engine) GetTicks() uint32 {
  37. return e.ticks
  38. }
  39. // TO BE IMPLEMENTED...
  40. func (e *Engine) Setup() error {
  41. return nil
  42. }
  43. func (e *Engine) Present() error {
  44. return nil
  45. }
  46. func (e *Engine) NewBitmap(filename string) (render.Texturer, error) {
  47. return nil, nil
  48. }
  49. func (e *Engine) Copy(t render.Texturer, src, dist render.Rect) {
  50. }
  51. // Delay for a moment.
  52. func (e *Engine) Delay(delay uint32) {
  53. time.Sleep(time.Duration(delay) * time.Millisecond)
  54. }
  55. // Teardown tasks.
  56. func (e *Engine) Teardown() {}
  57. func (e *Engine) Loop() error {
  58. return nil
  59. }