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
}
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
// GLContext must be created before setting the screen size, which requires
// swapping buffers.

View File

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