-
Notifications
You must be signed in to change notification settings - Fork 3
/
ebiten.go
48 lines (43 loc) · 1.32 KB
/
ebiten.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package ui
import (
"github.com/deadsy/sdfx/vec/v2i"
"github.com/hajimehoshi/ebiten"
)
// rendererEbitenGame hides the private ebiten implementation while behaving like a *Renderer internally
type rendererEbitenGame struct {
*Renderer
}
func (r rendererEbitenGame) Update(_ *ebiten.Image) error {
var err error
r.cachedRenderLock.RLock()
firstFrame := r.cachedRender == nil
if firstFrame { // This always runs before the first frame
r.cachedRender, err = ebiten.NewImage(1, 1, ebiten.FilterDefault)
if err != nil {
return err
}
r.cachedPartialRender = r.cachedRender
}
r.cachedRenderLock.RUnlock()
r.onUpdateInputs()
return nil
}
func (r rendererEbitenGame) Draw(screen *ebiten.Image) {
r.drawSDF(screen)
r.drawUI(screen)
}
func (r rendererEbitenGame) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
r.cachedRenderLock.RLock()
firstFrame := r.cachedRender == nil
r.cachedRenderLock.RUnlock()
r.implStateLock.RLock()
defer r.implStateLock.RUnlock()
if !firstFrame { // Layout is called before Update(), but don't render in this case
newScreenSize := v2i.Vec{X: outsideWidth, Y: outsideHeight}
if r.screenSize != newScreenSize {
r.screenSize = newScreenSize
r.rerender()
}
}
return outsideWidth, outsideHeight // Use all available pixels, no re-scaling (unless ResInv is modified)
}