2019-04-10 00:35:44 +00:00
|
|
|
package render
|
|
|
|
|
|
|
|
import (
|
2019-06-27 18:57:26 +00:00
|
|
|
"image"
|
2019-04-10 00:35:44 +00:00
|
|
|
|
2019-12-22 23:53:52 +00:00
|
|
|
"git.kirsle.net/go/render/event"
|
2019-04-10 00:35:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Engine is the interface for the rendering engine, keeping SDL-specific stuff
|
|
|
|
// far away from the core of Doodle.
|
|
|
|
type Engine interface {
|
|
|
|
Setup() error
|
|
|
|
|
|
|
|
// Poll for events like keypresses and mouse clicks.
|
2019-12-22 22:11:01 +00:00
|
|
|
Poll() (*event.State, error)
|
2019-04-10 00:35:44 +00:00
|
|
|
GetTicks() uint32
|
|
|
|
WindowSize() (w, h int)
|
|
|
|
|
|
|
|
// Present presents the current state to the screen.
|
|
|
|
Present() error
|
|
|
|
|
|
|
|
// Clear the full canvas and set this color.
|
|
|
|
Clear(Color)
|
2019-06-25 21:57:11 +00:00
|
|
|
SetTitle(string)
|
2019-04-10 00:35:44 +00:00
|
|
|
DrawPoint(Color, Point)
|
|
|
|
DrawLine(Color, Point, Point)
|
|
|
|
DrawRect(Color, Rect)
|
|
|
|
DrawBox(Color, Rect)
|
|
|
|
DrawText(Text, Point) error
|
|
|
|
ComputeTextRect(Text) (Rect, error)
|
|
|
|
|
|
|
|
// Texture caching.
|
2019-06-27 20:01:01 +00:00
|
|
|
StoreTexture(name string, img image.Image) (Texturer, error)
|
|
|
|
LoadTexture(name string) (Texturer, error)
|
2019-04-10 00:35:44 +00:00
|
|
|
Copy(t Texturer, src, dst Rect)
|
|
|
|
|
2022-04-09 21:25:56 +00:00
|
|
|
// Teardown and free memory for all textures, returning the number
|
|
|
|
// of textures that were freed.
|
|
|
|
FreeTextures() int
|
|
|
|
|
2019-04-10 00:35:44 +00:00
|
|
|
// Delay for a moment using the render engine's delay method,
|
|
|
|
// implemented by sdl.Delay(uint32)
|
|
|
|
Delay(uint32)
|
|
|
|
|
|
|
|
// Tasks that the Setup function should defer until tear-down.
|
|
|
|
Teardown()
|
|
|
|
|
|
|
|
Loop() error // maybe?
|
|
|
|
}
|
|
|
|
|
|
|
|
// Texturer is a stored image texture used by the rendering engine while
|
|
|
|
// abstracting away its inner workings.
|
|
|
|
type Texturer interface {
|
|
|
|
Size() Rect
|
2021-06-14 02:59:54 +00:00
|
|
|
Image() image.Image
|
2022-04-09 21:25:56 +00:00
|
|
|
Free() error // teardown and free memory
|
2019-04-10 00:35:44 +00:00
|
|
|
}
|