mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-13 22:47:26 +01:00
ui: Refactoring: Remove unneeded error handlings
This commit is contained in:
parent
7d181e3182
commit
1d59938295
@ -45,49 +45,31 @@ func (c *graphicsContext) Invalidate() {
|
|||||||
c.invalidated = true
|
c.invalidated = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *graphicsContext) SetSize(screenWidth, screenHeight int, screenScale float64) error {
|
func (c *graphicsContext) SetSize(screenWidth, screenHeight int, screenScale float64) {
|
||||||
if c.screen != nil {
|
if c.screen != nil {
|
||||||
if err := c.screen.Dispose(); err != nil {
|
_ = c.screen.Dispose()
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if c.offscreen != nil {
|
if c.offscreen != nil {
|
||||||
if err := c.offscreen.Dispose(); err != nil {
|
_ = c.offscreen.Dispose()
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if c.offscreen2 != nil {
|
if c.offscreen2 != nil {
|
||||||
if err := c.offscreen2.Dispose(); err != nil {
|
_ = c.offscreen2.Dispose()
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
offscreen, err := newVolatileImage(screenWidth, screenHeight, FilterNearest)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
offscreen := newVolatileImage(screenWidth, screenHeight, FilterNearest)
|
||||||
|
|
||||||
intScreenScale := int(math.Ceil(screenScale))
|
intScreenScale := int(math.Ceil(screenScale))
|
||||||
w := screenWidth * intScreenScale
|
w := screenWidth * intScreenScale
|
||||||
h := screenHeight * intScreenScale
|
h := screenHeight * intScreenScale
|
||||||
offscreen2, err := newVolatileImage(w, h, FilterLinear)
|
offscreen2 := newVolatileImage(w, h, FilterLinear)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
w = int(float64(screenWidth) * screenScale)
|
w = int(float64(screenWidth) * screenScale)
|
||||||
h = int(float64(screenHeight) * screenScale)
|
h = int(float64(screenHeight) * screenScale)
|
||||||
c.screen, err = newImageWithScreenFramebuffer(w, h)
|
c.screen = newImageWithScreenFramebuffer(w, h)
|
||||||
if err != nil {
|
_ = c.screen.Clear()
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := c.screen.Clear(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
c.offscreen = offscreen
|
c.offscreen = offscreen
|
||||||
c.offscreen2 = offscreen2
|
c.offscreen2 = offscreen2
|
||||||
c.screenScale = screenScale
|
c.screenScale = screenScale
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *graphicsContext) initializeIfNeeded() error {
|
func (c *graphicsContext) initializeIfNeeded() error {
|
||||||
|
8
image.go
8
image.go
@ -250,13 +250,13 @@ func NewImage(width, height int, filter Filter) (*Image, error) {
|
|||||||
// If width or height is less than 1 or more than MaxImageSize, newVolatileImage panics.
|
// If width or height is less than 1 or more than MaxImageSize, newVolatileImage panics.
|
||||||
//
|
//
|
||||||
// Error returned by newVolatileImage is always nil as of 1.5.0-alpha.
|
// Error returned by newVolatileImage is always nil as of 1.5.0-alpha.
|
||||||
func newVolatileImage(width, height int, filter Filter) (*Image, error) {
|
func newVolatileImage(width, height int, filter Filter) *Image {
|
||||||
checkSize(width, height)
|
checkSize(width, height)
|
||||||
r := restorable.NewImage(width, height, glFilter(filter), true)
|
r := restorable.NewImage(width, height, glFilter(filter), true)
|
||||||
r.Fill(color.RGBA{})
|
r.Fill(color.RGBA{})
|
||||||
i := &Image{r}
|
i := &Image{r}
|
||||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||||
return i, nil
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewImageFromImage creates a new image with the given image (source).
|
// NewImageFromImage creates a new image with the given image (source).
|
||||||
@ -275,12 +275,12 @@ func NewImageFromImage(source image.Image, filter Filter) (*Image, error) {
|
|||||||
return i, nil
|
return i, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newImageWithScreenFramebuffer(width, height int) (*Image, error) {
|
func newImageWithScreenFramebuffer(width, height int) *Image {
|
||||||
checkSize(width, height)
|
checkSize(width, height)
|
||||||
r := restorable.NewScreenFramebufferImage(width, height)
|
r := restorable.NewScreenFramebufferImage(width, height)
|
||||||
i := &Image{r}
|
i := &Image{r}
|
||||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||||
return i, nil
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
const MaxImageSize = graphics.MaxImageSize
|
const MaxImageSize = graphics.MaxImageSize
|
||||||
|
@ -74,7 +74,7 @@ func (c *runContext) updateFPS(fps float64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GraphicsContext interface {
|
type GraphicsContext interface {
|
||||||
SetSize(width, height int, scale float64) error
|
SetSize(width, height int, scale float64)
|
||||||
UpdateAndDraw(updateCount int) error
|
UpdateAndDraw(updateCount int) error
|
||||||
Invalidate()
|
Invalidate()
|
||||||
}
|
}
|
||||||
@ -84,8 +84,8 @@ type loopGraphicsContext struct {
|
|||||||
graphicsContext GraphicsContext
|
graphicsContext GraphicsContext
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *loopGraphicsContext) SetSize(width, height int, scale float64) error {
|
func (g *loopGraphicsContext) SetSize(width, height int, scale float64) {
|
||||||
return g.graphicsContext.SetSize(width, height, scale)
|
g.graphicsContext.SetSize(width, height, scale)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *loopGraphicsContext) Update() error {
|
func (g *loopGraphicsContext) Update() error {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
type GraphicsContext interface {
|
type GraphicsContext interface {
|
||||||
SetSize(width, height int, scale float64) error
|
SetSize(width, height int, scale float64)
|
||||||
Update() error
|
Update() error
|
||||||
Invalidate()
|
Invalidate()
|
||||||
}
|
}
|
||||||
|
@ -236,9 +236,7 @@ func (u *userInterface) update(g GraphicsContext) error {
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if 0 < actualScale {
|
if 0 < actualScale {
|
||||||
if err := g.SetSize(u.width, u.height, actualScale); err != nil {
|
g.SetSize(u.width, u.height, actualScale)
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = u.runOnMainThread(func() error {
|
_ = u.runOnMainThread(func() error {
|
||||||
|
@ -80,9 +80,7 @@ func (u *userInterface) update(g GraphicsContext) error {
|
|||||||
if u.sizeChanged {
|
if u.sizeChanged {
|
||||||
u.sizeChanged = false
|
u.sizeChanged = false
|
||||||
w, h := u.size()
|
w, h := u.size()
|
||||||
if err := g.SetSize(w, h, u.actualScreenScale()); err != nil {
|
g.SetSize(w, h, u.actualScreenScale())
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := g.Update(); err != nil {
|
if err := g.Update(); err != nil {
|
||||||
|
@ -83,9 +83,7 @@ func (u *userInterface) update(g GraphicsContext) error {
|
|||||||
if u.sizeChanged {
|
if u.sizeChanged {
|
||||||
// Sizing also calls GL functions
|
// Sizing also calls GL functions
|
||||||
u.sizeChanged = false
|
u.sizeChanged = false
|
||||||
if err := g.SetSize(u.width, u.height, u.actualScreenScale()); err != nil {
|
g.SetSize(u.width, u.height, u.actualScreenScale())
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := g.Update(); err != nil {
|
if err := g.Update(); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user