uidriver/mobile: Refactoring: Rename variables

This commit is contained in:
Hajime Hoshi 2019-12-13 02:50:57 +09:00
parent 7f88732cc5
commit ba0e8ef13f

View File

@ -100,9 +100,9 @@ type UserInterface struct {
sizeChanged bool sizeChanged bool
// Used for gomobile-build // Used for gomobile-build
fullscreenScale float64 gbuildScale float64
fullscreenWidthPx int gbuildWidthPx int
fullscreenHeightPx int gbuildHeightPx int
graphics driver.Graphics graphics driver.Graphics
@ -139,7 +139,7 @@ func (u *UserInterface) appMain(a app.App) {
glctx = nil glctx = nil
} }
case size.Event: case size.Event:
u.setFullscreenImpl(e.WidthPx, e.HeightPx) u.setGBuildImpl(e.WidthPx, e.HeightPx)
case paint.Event: case paint.Event:
if glctx == nil || e.External { if glctx == nil || e.External {
continue continue
@ -264,8 +264,8 @@ func (u *UserInterface) ActualScale() float64 {
func (u *UserInterface) scaleImpl() float64 { func (u *UserInterface) scaleImpl() float64 {
scale := u.scale scale := u.scale
if u.fullscreenScale != 0 { if u.gbuildScale != 0 {
scale = u.fullscreenScale scale = u.gbuildScale
} }
return scale return scale
} }
@ -303,7 +303,7 @@ func (u *UserInterface) ScreenSize() (int, int) {
} }
func (u *UserInterface) ScreenSizeInFullscreen() (int, int) { func (u *UserInterface) ScreenSizeInFullscreen() (int, int) {
// TODO: This function should return fullscreenWidthPx, fullscreenHeightPx, // TODO: This function should return gbuildWidthPx, gbuildHeightPx,
// but these values are not initialized until the main loop starts. // but these values are not initialized until the main loop starts.
return 0, 0 return 0, 0
} }
@ -313,7 +313,7 @@ func (u *UserInterface) SetScreenSize(width, height int) {
if u.width != width || u.height != height { if u.width != width || u.height != height {
u.width = width u.width = width
u.height = height u.height = height
u.updateFullscreenScaleIfNeeded() u.updateGBuildScaleIfNeeded()
u.sizeChanged = true u.sizeChanged = true
} }
u.m.Unlock() u.m.Unlock()
@ -335,28 +335,27 @@ func (u *UserInterface) ScreenScale() float64 {
return s return s
} }
func (u *UserInterface) setFullscreenImpl(widthPx, heightPx int) { func (u *UserInterface) setGBuildImpl(widthPx, heightPx int) {
// This implementation is only for gomobile-build so far.
u.m.Lock() u.m.Lock()
u.fullscreenWidthPx = widthPx u.gbuildWidthPx = widthPx
u.fullscreenHeightPx = heightPx u.gbuildHeightPx = heightPx
u.updateFullscreenScaleIfNeeded() u.updateGBuildScaleIfNeeded()
u.sizeChanged = true u.sizeChanged = true
u.m.Unlock() u.m.Unlock()
} }
func (u *UserInterface) updateFullscreenScaleIfNeeded() { func (u *UserInterface) updateGBuildScaleIfNeeded() {
if u.fullscreenWidthPx == 0 || u.fullscreenHeightPx == 0 { if u.gbuildWidthPx == 0 || u.gbuildHeightPx == 0 {
return return
} }
w, h := u.width, u.height w, h := u.width, u.height
scaleX := float64(u.fullscreenWidthPx) / float64(w) scaleX := float64(u.gbuildWidthPx) / float64(w)
scaleY := float64(u.fullscreenHeightPx) / float64(h) scaleY := float64(u.gbuildHeightPx) / float64(h)
scale := scaleX scale := scaleX
if scale > scaleY { if scale > scaleY {
scale = scaleY scale = scaleY
} }
u.fullscreenScale = scale / deviceScale() u.gbuildScale = scale / deviceScale()
u.sizeChanged = true u.sizeChanged = true
} }
@ -368,12 +367,12 @@ func (u *UserInterface) ScreenPadding() (x0, y0, x1, y1 float64) {
} }
func (u *UserInterface) screenPaddingImpl() (x0, y0, x1, y1 float64) { func (u *UserInterface) screenPaddingImpl() (x0, y0, x1, y1 float64) {
if u.fullscreenScale == 0 { if u.gbuildScale == 0 {
return 0, 0, 0, 0 return 0, 0, 0, 0
} }
s := u.fullscreenScale * deviceScale() s := u.gbuildScale * deviceScale()
ox := (float64(u.fullscreenWidthPx) - float64(u.width)*s) / 2 ox := (float64(u.gbuildWidthPx) - float64(u.width)*s) / 2
oy := (float64(u.fullscreenHeightPx) - float64(u.height)*s) / 2 oy := (float64(u.gbuildHeightPx) - float64(u.height)*s) / 2
return ox, oy, ox, oy return ox, oy, ox, oy
} }