ui: Refactoring: Remove unneeded error handlings

This commit is contained in:
Hajime Hoshi 2017-05-31 10:47:52 +09:00
parent 7d181e3182
commit 1d59938295
7 changed files with 19 additions and 43 deletions

View File

@ -45,49 +45,31 @@ func (c *graphicsContext) Invalidate() {
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 err := c.screen.Dispose(); err != nil {
return err
}
_ = c.screen.Dispose()
}
if c.offscreen != nil {
if err := c.offscreen.Dispose(); err != nil {
return err
}
_ = c.offscreen.Dispose()
}
if c.offscreen2 != nil {
if err := c.offscreen2.Dispose(); err != nil {
return err
}
}
offscreen, err := newVolatileImage(screenWidth, screenHeight, FilterNearest)
if err != nil {
return err
_ = c.offscreen2.Dispose()
}
offscreen := newVolatileImage(screenWidth, screenHeight, FilterNearest)
intScreenScale := int(math.Ceil(screenScale))
w := screenWidth * intScreenScale
h := screenHeight * intScreenScale
offscreen2, err := newVolatileImage(w, h, FilterLinear)
if err != nil {
return err
}
offscreen2 := newVolatileImage(w, h, FilterLinear)
w = int(float64(screenWidth) * screenScale)
h = int(float64(screenHeight) * screenScale)
c.screen, err = newImageWithScreenFramebuffer(w, h)
if err != nil {
return err
}
if err := c.screen.Clear(); err != nil {
return err
}
c.screen = newImageWithScreenFramebuffer(w, h)
_ = c.screen.Clear()
c.offscreen = offscreen
c.offscreen2 = offscreen2
c.screenScale = screenScale
return nil
}
func (c *graphicsContext) initializeIfNeeded() error {

View File

@ -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.
//
// 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)
r := restorable.NewImage(width, height, glFilter(filter), true)
r.Fill(color.RGBA{})
i := &Image{r}
runtime.SetFinalizer(i, (*Image).Dispose)
return i, nil
return i
}
// 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
}
func newImageWithScreenFramebuffer(width, height int) (*Image, error) {
func newImageWithScreenFramebuffer(width, height int) *Image {
checkSize(width, height)
r := restorable.NewScreenFramebufferImage(width, height)
i := &Image{r}
runtime.SetFinalizer(i, (*Image).Dispose)
return i, nil
return i
}
const MaxImageSize = graphics.MaxImageSize

View File

@ -74,7 +74,7 @@ func (c *runContext) updateFPS(fps float64) {
}
type GraphicsContext interface {
SetSize(width, height int, scale float64) error
SetSize(width, height int, scale float64)
UpdateAndDraw(updateCount int) error
Invalidate()
}
@ -84,8 +84,8 @@ type loopGraphicsContext struct {
graphicsContext GraphicsContext
}
func (g *loopGraphicsContext) SetSize(width, height int, scale float64) error {
return g.graphicsContext.SetSize(width, height, scale)
func (g *loopGraphicsContext) SetSize(width, height int, scale float64) {
g.graphicsContext.SetSize(width, height, scale)
}
func (g *loopGraphicsContext) Update() error {

View File

@ -15,7 +15,7 @@
package ui
type GraphicsContext interface {
SetSize(width, height int, scale float64) error
SetSize(width, height int, scale float64)
Update() error
Invalidate()
}

View File

@ -236,9 +236,7 @@ func (u *userInterface) update(g GraphicsContext) error {
return nil
})
if 0 < actualScale {
if err := g.SetSize(u.width, u.height, actualScale); err != nil {
return err
}
g.SetSize(u.width, u.height, actualScale)
}
_ = u.runOnMainThread(func() error {

View File

@ -80,9 +80,7 @@ func (u *userInterface) update(g GraphicsContext) error {
if u.sizeChanged {
u.sizeChanged = false
w, h := u.size()
if err := g.SetSize(w, h, u.actualScreenScale()); err != nil {
return err
}
g.SetSize(w, h, u.actualScreenScale())
return nil
}
if err := g.Update(); err != nil {

View File

@ -83,9 +83,7 @@ func (u *userInterface) update(g GraphicsContext) error {
if u.sizeChanged {
// Sizing also calls GL functions
u.sizeChanged = false
if err := g.SetSize(u.width, u.height, u.actualScreenScale()); err != nil {
return err
}
g.SetSize(u.width, u.height, u.actualScreenScale())
return nil
}
if err := g.Update(); err != nil {