mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-12 22:17:26 +01:00
ui: Protect uiContext.scaleForWindow by mutex
This commit is contained in:
parent
bda11b0e17
commit
12a13892cd
4
run.go
4
run.go
@ -225,8 +225,6 @@ func SetScreenSize(width, height int) {
|
|||||||
panic("ebiten: SetScreenSize can't be called before the main loop starts")
|
panic("ebiten: SetScreenSize can't be called before the main loop starts")
|
||||||
}
|
}
|
||||||
theUIContext.SetScreenSize(width, height)
|
theUIContext.SetScreenSize(width, height)
|
||||||
s := theUIContext.getScaleForWindow()
|
|
||||||
uiDriver().SetWindowSize(int(float64(width)*s), int(float64(height)*s))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetScreenScale changes the scale of the screen on desktops.
|
// SetScreenScale changes the scale of the screen on desktops.
|
||||||
@ -258,8 +256,6 @@ func SetScreenScale(scale float64) {
|
|||||||
panic("ebiten: SetScreenScale can't be called before the main loop starts")
|
panic("ebiten: SetScreenScale can't be called before the main loop starts")
|
||||||
}
|
}
|
||||||
theUIContext.setScaleForWindow(scale)
|
theUIContext.setScaleForWindow(scale)
|
||||||
w, h := theUIContext.size()
|
|
||||||
uiDriver().SetWindowSize(int(float64(w)*scale), int(float64(h)*scale))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScreenScale returns the current screen scale.
|
// ScreenScale returns the current screen scale.
|
||||||
|
17
uicontext.go
17
uicontext.go
@ -80,26 +80,29 @@ func (c *uiContext) resolveSize() (int, int) {
|
|||||||
return c.screenWidth, c.screenHeight
|
return c.screenWidth, c.screenHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *uiContext) size() (int, int) {
|
|
||||||
return c.resolveSize()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *uiContext) setScaleForWindow(scale float64) {
|
func (c *uiContext) setScaleForWindow(scale float64) {
|
||||||
|
w, h := c.resolveSize()
|
||||||
|
c.m.Lock()
|
||||||
c.scaleForWindow = scale
|
c.scaleForWindow = scale
|
||||||
|
uiDriver().SetWindowSize(int(float64(w)*scale), int(float64(h)*scale))
|
||||||
|
c.m.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *uiContext) getScaleForWindow() float64 {
|
func (c *uiContext) getScaleForWindow() float64 {
|
||||||
return c.scaleForWindow
|
c.m.Lock()
|
||||||
|
s := c.scaleForWindow
|
||||||
|
c.m.Unlock()
|
||||||
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *uiContext) SetScreenSize(width, height int) {
|
func (c *uiContext) SetScreenSize(width, height int) {
|
||||||
c.m.Lock()
|
c.m.Lock()
|
||||||
defer c.m.Unlock()
|
defer c.m.Unlock()
|
||||||
|
|
||||||
// TODO: Use the interface Game's Layout and then update screenWidth and screenHeight, then this function
|
|
||||||
// is no longer needed.
|
|
||||||
c.reqWidth = width
|
c.reqWidth = width
|
||||||
c.reqHeight = height
|
c.reqHeight = height
|
||||||
|
s := c.scaleForWindow
|
||||||
|
uiDriver().SetWindowSize(int(float64(width)*s), int(float64(height)*s))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *uiContext) Layout(outsideWidth, outsideHeight float64) {
|
func (c *uiContext) Layout(outsideWidth, outsideHeight float64) {
|
||||||
|
Loading…
Reference in New Issue
Block a user