ui: Refactoring

This commit is contained in:
Hajime Hoshi 2016-09-03 01:06:16 +09:00
parent db782ff0d9
commit ec70ea3be5
2 changed files with 6 additions and 10 deletions

View File

@ -142,7 +142,7 @@ func ScreenScale() float64 {
return s return s
} }
func Run(width, height int, scale float64, title string, g GraphicsContext) error { func Run(width, height int, scale float64, title string, g GraphicsContext, glContext opengl.Context) error {
u := currentUI u := currentUI
// GLContext must be created before setting the screen size, which requires // GLContext must be created before setting the screen size, which requires
// swapping buffers. // swapping buffers.

View File

@ -57,7 +57,7 @@ func ScreenScale() float64 {
return currentUI.scale return currentUI.scale
} }
func (u *userInterface) ActualScreenScale() float64 { func (u *userInterface) actualScreenScale() float64 {
return u.scale * u.deviceScale return u.scale * u.deviceScale
} }
@ -72,7 +72,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 { if err := g.SetSize(w, h, u.actualScreenScale()); err != nil {
return err return err
} }
return nil return nil
@ -98,10 +98,6 @@ func (u *userInterface) loop(g GraphicsContext) error {
return <-ch return <-ch
} }
func (u *userInterface) FinishRendering() error {
return nil
}
func touchEventToTouches(e *js.Object) []touch { func touchEventToTouches(e *js.Object) []touch {
scale := currentUI.scale scale := currentUI.scale
j := e.Get("targetTouches") j := e.Get("targetTouches")
@ -273,7 +269,7 @@ func Run(width, height int, scale float64, title string, g GraphicsContext) erro
} }
func (u *userInterface) size() (width, height int) { func (u *userInterface) size() (width, height int) {
a := u.ActualScreenScale() a := u.actualScreenScale()
if a == 0 { if a == 0 {
// a == 0 only on the initial state. // a == 0 only on the initial state.
return return
@ -291,8 +287,8 @@ func (u *userInterface) setScreenSize(width, height int, scale float64) bool {
} }
u.scale = scale u.scale = scale
u.deviceScale = devicePixelRatio() u.deviceScale = devicePixelRatio()
canvas.Set("width", int(float64(width)*u.ActualScreenScale())) canvas.Set("width", int(float64(width)*u.actualScreenScale()))
canvas.Set("height", int(float64(height)*u.ActualScreenScale())) canvas.Set("height", int(float64(height)*u.actualScreenScale()))
canvasStyle := canvas.Get("style") canvasStyle := canvas.Get("style")
cssWidth := int(float64(width) * scale) cssWidth := int(float64(width) * scale)