mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
internal/ui: refactoring: remove sizeChanged
It is safe to call Layout every frame.
This commit is contained in:
parent
fcd4453e4f
commit
e2f0878a4c
@ -58,7 +58,6 @@ var (
|
|||||||
// Give a default outside size so that the game can start without initializing them.
|
// Give a default outside size so that the game can start without initializing them.
|
||||||
outsideWidth: 640,
|
outsideWidth: 640,
|
||||||
outsideHeight: 480,
|
outsideHeight: 480,
|
||||||
sizeChanged: true,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -99,7 +98,6 @@ type UserInterface struct {
|
|||||||
outsideWidth float64
|
outsideWidth float64
|
||||||
outsideHeight float64
|
outsideHeight float64
|
||||||
|
|
||||||
sizeChanged bool
|
|
||||||
foreground int32
|
foreground int32
|
||||||
errCh chan error
|
errCh chan error
|
||||||
|
|
||||||
@ -273,10 +271,6 @@ func (u *UserInterface) run(game Game, mainloop bool) (err error) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
u.m.Lock()
|
|
||||||
u.sizeChanged = true
|
|
||||||
u.m.Unlock()
|
|
||||||
|
|
||||||
u.context = newContextImpl(game)
|
u.context = newContextImpl(game)
|
||||||
|
|
||||||
if mainloop {
|
if mainloop {
|
||||||
@ -306,8 +300,6 @@ func (u *UserInterface) layoutIfNeeded() {
|
|||||||
var outsideWidth, outsideHeight float64
|
var outsideWidth, outsideHeight float64
|
||||||
|
|
||||||
u.m.RLock()
|
u.m.RLock()
|
||||||
sizeChanged := u.sizeChanged
|
|
||||||
if sizeChanged {
|
|
||||||
if u.gbuildWidthPx == 0 || u.gbuildHeightPx == 0 {
|
if u.gbuildWidthPx == 0 || u.gbuildHeightPx == 0 {
|
||||||
outsideWidth = u.outsideWidth
|
outsideWidth = u.outsideWidth
|
||||||
outsideHeight = u.outsideHeight
|
outsideHeight = u.outsideHeight
|
||||||
@ -317,14 +309,10 @@ func (u *UserInterface) layoutIfNeeded() {
|
|||||||
outsideWidth = float64(u.gbuildWidthPx) / d
|
outsideWidth = float64(u.gbuildWidthPx) / d
|
||||||
outsideHeight = float64(u.gbuildHeightPx) / d
|
outsideHeight = float64(u.gbuildHeightPx) / d
|
||||||
}
|
}
|
||||||
}
|
|
||||||
u.sizeChanged = false
|
|
||||||
u.m.RUnlock()
|
u.m.RUnlock()
|
||||||
|
|
||||||
if sizeChanged {
|
|
||||||
u.context.layout(outsideWidth, outsideHeight)
|
u.context.layout(outsideWidth, outsideHeight)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (u *UserInterface) update() error {
|
func (u *UserInterface) update() error {
|
||||||
<-renderCh
|
<-renderCh
|
||||||
@ -353,7 +341,6 @@ func (u *UserInterface) SetOutsideSize(outsideWidth, outsideHeight float64) {
|
|||||||
if u.outsideWidth != outsideWidth || u.outsideHeight != outsideHeight {
|
if u.outsideWidth != outsideWidth || u.outsideHeight != outsideHeight {
|
||||||
u.outsideWidth = outsideWidth
|
u.outsideWidth = outsideWidth
|
||||||
u.outsideHeight = outsideHeight
|
u.outsideHeight = outsideHeight
|
||||||
u.sizeChanged = true
|
|
||||||
}
|
}
|
||||||
u.m.Unlock()
|
u.m.Unlock()
|
||||||
}
|
}
|
||||||
@ -362,7 +349,6 @@ func (u *UserInterface) setGBuildSize(widthPx, heightPx int) {
|
|||||||
u.m.Lock()
|
u.m.Lock()
|
||||||
u.gbuildWidthPx = widthPx
|
u.gbuildWidthPx = widthPx
|
||||||
u.gbuildHeightPx = heightPx
|
u.gbuildHeightPx = heightPx
|
||||||
u.sizeChanged = true
|
|
||||||
u.m.Unlock()
|
u.m.Unlock()
|
||||||
|
|
||||||
u.once.Do(func() {
|
u.once.Do(func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user