internal/ui: refactoring: remove some exposed functions

This commit is contained in:
Hajime Hoshi 2022-02-13 20:08:59 +09:00
parent 08defeeded
commit 29382b424b
3 changed files with 7 additions and 17 deletions

View File

@ -23,6 +23,7 @@ import (
"github.com/hajimehoshi/ebiten/v2/internal/clock"
"github.com/hajimehoshi/ebiten/v2/internal/debug"
graphicspkg "github.com/hajimehoshi/ebiten/v2/internal/graphics"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
"github.com/hajimehoshi/ebiten/v2/internal/hooks"
)
@ -31,7 +32,7 @@ const DefaultTPS = 60
type Context interface {
UpdateOffscreen(outsideWidth, outsideHeight float64, deviceScaleFactor float64) (int, int)
UpdateGame() error
DrawGame(screenScale float64, offsetX, offsetY float64) error
DrawGame(screenScale float64, offsetX, offsetY float64, needsClearingScreen bool, framebufferYDirection graphicsdriver.YDirection) error
}
type contextImpl struct {
@ -99,7 +100,7 @@ func (c *contextImpl) updateFrameImpl(updateCount int, deviceScaleFactor float64
// Draw the game.
screenScale, offsetX, offsetY := c.screenScaleAndOffsets(deviceScaleFactor)
if err := c.context.DrawGame(screenScale, offsetX, offsetY); err != nil {
if err := c.context.DrawGame(screenScale, offsetX, offsetY, graphics().NeedsClearingScreen(), graphics().FramebufferYDirection()); err != nil {
return err
}

View File

@ -16,8 +16,6 @@ package ui
import (
"errors"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
)
type MouseButton int
@ -69,11 +67,3 @@ const (
WindowResizingModeOnlyFullscreenEnabled
WindowResizingModeEnabled
)
func NeedsClearingScreen() bool {
return graphics().NeedsClearingScreen()
}
func FramebufferYDirection() graphicsdriver.YDirection {
return graphics().FramebufferYDirection()
}

View File

@ -19,7 +19,6 @@ import (
"sync"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
"github.com/hajimehoshi/ebiten/v2/internal/ui"
)
type uiContext struct {
@ -88,7 +87,7 @@ func (c *uiContext) UpdateGame() error {
return c.game.Update()
}
func (c *uiContext) DrawGame(screenScale float64, offsetX, offsetY float64) error {
func (c *uiContext) DrawGame(screenScale float64, offsetX, offsetY float64, needsClearingScreen bool, framebufferYDirection graphicsdriver.YDirection) error {
// Even though updateCount == 0, the offscreen is cleared and Draw is called.
// Draw should not update the game state and then the screen should not be updated without Update, but
// users might want to process something at Draw with the time intervals of FPS.
@ -97,7 +96,7 @@ func (c *uiContext) DrawGame(screenScale float64, offsetX, offsetY float64) erro
}
c.game.Draw(c.offscreen)
if ui.NeedsClearingScreen() {
if needsClearingScreen {
// This clear is needed for fullscreen mode or some mobile platforms (#622).
c.screen.Clear()
}
@ -105,7 +104,7 @@ func (c *uiContext) DrawGame(screenScale float64, offsetX, offsetY float64) erro
op := &DrawImageOptions{}
s := screenScale
switch vd := ui.FramebufferYDirection(); vd {
switch framebufferYDirection {
case graphicsdriver.Upward:
op.GeoM.Scale(s, -s)
_, h := c.offscreen.Size()
@ -113,7 +112,7 @@ func (c *uiContext) DrawGame(screenScale float64, offsetX, offsetY float64) erro
case graphicsdriver.Downward:
op.GeoM.Scale(s, s)
default:
panic(fmt.Sprintf("ebiten: invalid v-direction: %d", vd))
panic(fmt.Sprintf("ebiten: invalid v-direction: %d", framebufferYDirection))
}
op.GeoM.Translate(offsetX, offsetY)