Remove ui.ActualScale()

This commit is contained in:
Hajime Hoshi 2015-01-02 03:28:43 +09:00
parent 3d01084a2a
commit c4e104a5d2
2 changed files with 13 additions and 18 deletions

View File

@ -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() {

6
run.go
View File

@ -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