From c4e104a5d27163ad81cb72a29ef2f92b88aa5c5e Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 2 Jan 2015 03:28:43 +0900 Subject: [PATCH] Remove ui.ActualScale() --- internal/ui/ui.go | 25 ++++++++++--------------- run.go | 6 +++--- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/internal/ui/ui.go b/internal/ui/ui.go index 02c84b797..46f3512f0 100644 --- a/internal/ui/ui.go +++ b/internal/ui/ui.go @@ -32,10 +32,6 @@ func Use(f func(*opengl.Context)) { <-ch } -func ActualScale() int { - return current.actualScale -} - func DoEvents() { current.doEvents() } @@ -86,22 +82,21 @@ func init() { } type ui struct { - window *glfw.Window - scale int - actualScale int - glContext *opengl.Context - input input - funcs chan func() + window *glfw.Window + scale int + glContext *opengl.Context + input input + funcs chan func() } -func Start(width, height, scale int, title string) error { +func Start(width, height, scale int, title string) (actualScale int, err error) { monitor, err := glfw.GetPrimaryMonitor() if err != nil { - return err + return 0, err } videoMode, err := monitor.GetVideoMode() if err != nil { - return err + return 0, err } x := (videoMode.Width - width*scale) / 2 y := (videoMode.Height - height*scale) / 3 @@ -134,9 +129,9 @@ func Start(width, height, scale int, title string) error { // For retina displays, recalculate the scale with the framebuffer size. windowWidth, _ := window.GetFramebufferSize() - ui.actualScale = windowWidth / width + actualScale = windowWidth / width - return err + return actualScale, nil } func (u *ui) doEvents() { diff --git a/run.go b/run.go index f9fceaead..543606179 100644 --- a/run.go +++ b/run.go @@ -30,15 +30,15 @@ import ( // but this is not strictly guaranteed. // If you need to care about time, you need to check current time every time f is called. func Run(f func(*Image) error, width, height, scale int, title string) error { - if err := ui.Start(width, height, scale, title); err != nil { + actualScale, err := ui.Start(width, height, scale, title) + if err != nil { return err } defer ui.Terminate() var graphicsContext *graphicsContext - var err error ui.Use(func(c *opengl.Context) { - graphicsContext, err = newGraphicsContext(c, width, height, ui.ActualScale()) + graphicsContext, err = newGraphicsContext(c, width, height, actualScale) }) if err != nil { return err