mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 10:42:42 +01:00
examples/highdpi: Bug fix: doesn't work well on multiple monitors
This commit is contained in:
parent
7f291b7bb1
commit
0fb33e7c36
@ -29,6 +29,9 @@ var (
|
|||||||
count int
|
count int
|
||||||
highDPIImage *ebiten.Image
|
highDPIImage *ebiten.Image
|
||||||
highDPIImageCh = make(chan *ebiten.Image)
|
highDPIImageCh = make(chan *ebiten.Image)
|
||||||
|
|
||||||
|
// scale represents the device scale when the application starts.
|
||||||
|
scale = 1.0
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -48,6 +51,10 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func update(screen *ebiten.Image) error {
|
func update(screen *ebiten.Image) error {
|
||||||
|
// TODO: DeviceScaleFactor() might return different values for different monitors.
|
||||||
|
// Add a mode to adjust the screen size along with the current device scale (#705).
|
||||||
|
// Now this example uses the device scale initialized at the begining of this application.
|
||||||
|
|
||||||
if highDPIImage == nil {
|
if highDPIImage == nil {
|
||||||
// Use select and 'default' clause for non-blocking receiving.
|
// Use select and 'default' clause for non-blocking receiving.
|
||||||
select {
|
select {
|
||||||
@ -66,7 +73,6 @@ func update(screen *ebiten.Image) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
scale := ebiten.DeviceScaleFactor()
|
|
||||||
sw, sh := screen.Size()
|
sw, sh := screen.Size()
|
||||||
|
|
||||||
w, h := highDPIImage.Size()
|
w, h := highDPIImage.Size()
|
||||||
@ -88,7 +94,7 @@ func update(screen *ebiten.Image) error {
|
|||||||
op.Filter = ebiten.FilterLinear
|
op.Filter = ebiten.FilterLinear
|
||||||
screen.DrawImage(highDPIImage, op)
|
screen.DrawImage(highDPIImage, op)
|
||||||
|
|
||||||
ebitenutil.DebugPrint(screen, fmt.Sprintf("Device Scale Ratio: %0.2f", scale))
|
ebitenutil.DebugPrint(screen, fmt.Sprintf("(Init) Device Scale Ratio: %0.2f", scale))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +105,10 @@ func main() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Pass the invert of scale so that Ebiten's auto scaling by device scale is disabled.
|
// Pass the invert of scale so that Ebiten's auto scaling by device scale is disabled.
|
||||||
s := ebiten.DeviceScaleFactor()
|
//
|
||||||
|
// Note that DeviceScaleFactor cannot be called from init() functions on some environments.
|
||||||
|
scale = ebiten.DeviceScaleFactor()
|
||||||
|
s := scale
|
||||||
if err := ebiten.Run(update, int(screenWidth*s), int(screenHeight*s), 1/s, "High DPI (Ebiten Demo)"); err != nil {
|
if err := ebiten.Run(update, int(screenWidth*s), int(screenHeight*s), 1/s, "High DPI (Ebiten Demo)"); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user