ui: Rename MonitorSize -> ScreenSizeInFullscreen (#708)

This commit is contained in:
Hajime Hoshi 2018-10-09 23:27:29 +09:00
parent 0a54ce48fd
commit c758a1f8c6
6 changed files with 19 additions and 18 deletions

View File

@ -97,10 +97,10 @@ func update(screen *ebiten.Image) error {
op.Filter = ebiten.FilterLinear op.Filter = ebiten.FilterLinear
screen.DrawImage(gophersImage, op) screen.DrawImage(gophersImage, op)
mw, mh := ebiten.MonitorSize() fw, fh := ebiten.ScreenSizeInFullscreen()
msgs := []string{ msgs := []string{
"This is an example of the finest fullscreen. Press Q to quit.", "This is an example of the finest fullscreen. Press Q to quit.",
fmt.Sprintf("Monitor size: %d, %d", mw, mh), fmt.Sprintf("Screen size in fullscreen: %d, %d", fw, fh),
fmt.Sprintf("Game's screen size: %d, %d", sw, sh), fmt.Sprintf("Game's screen size: %d, %d", sw, sh),
fmt.Sprintf("Device scale factor: %0.2f", scale), fmt.Sprintf("Device scale factor: %0.2f", scale),
} }
@ -118,7 +118,7 @@ func main() {
ebiten.SetFullscreen(true) ebiten.SetFullscreen(true)
w, h := ebiten.MonitorSize() w, h := ebiten.ScreenSizeInFullscreen()
// On mobiles, ebiten.MonitorSize is not available so far. // On mobiles, ebiten.MonitorSize is not available so far.
// Use arbitrary values. // Use arbitrary values.
if w == 0 || h == 0 { if w == 0 || h == 0 {

View File

@ -199,8 +199,8 @@ func main() {
flag.Parse() flag.Parse()
fmt.Printf("Device scale factor: %0.2f\n", ebiten.DeviceScaleFactor()) fmt.Printf("Device scale factor: %0.2f\n", ebiten.DeviceScaleFactor())
w, h := ebiten.MonitorSize() w, h := ebiten.ScreenSizeInFullscreen()
fmt.Printf("Monitor size: %d, %d\n", w, h) fmt.Printf("Screen size in fullscreen: %d, %d\n", w, h)
// Decode image from a byte slice instead of a file so that // Decode image from a byte slice instead of a file so that
// this example works in any working directory. // this example works in any working directory.

View File

@ -232,7 +232,7 @@ func (u *userInterface) runOnMainThread(f func() error) error {
return err return err
} }
func MonitorSize() (int, int) { func ScreenSizeInFullscreen() (int, int) {
var v *glfw.VidMode var v *glfw.VidMode
if currentUI.isRunning() { if currentUI.isRunning() {
_ = currentUI.runOnMainThread(func() error { _ = currentUI.runOnMainThread(func() error {

View File

@ -59,7 +59,7 @@ var (
setTimeout = window.Get("setTimeout") setTimeout = window.Get("setTimeout")
) )
func MonitorSize() (int, int) { func ScreenSizeInFullscreen() (int, int) {
return window.Get("innerWidth").Int(), window.Get("innerHeight").Int() return window.Get("innerWidth").Int(), window.Get("innerHeight").Int()
} }

View File

@ -253,7 +253,7 @@ func (u *userInterface) screenSize() (int, int) {
return w, h return w, h
} }
func MonitorSize() (int, int) { func ScreenSizeInFullscreen() (int, int) {
// TODO: This function should return fullscreenWidthPx, fullscreenHeightPx, // TODO: This function should return fullscreenWidthPx, fullscreenHeightPx,
// 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

21
run.go
View File

@ -315,19 +315,20 @@ func RunWithoutMainLoop(f func(*Image) error, width, height int, scale float64,
return ch return ch
} }
// MonitorSize returns the monitor size in device-independent pixels. // ScreenSizeInFullscreen returns the size in device-independent pixels when the game is fullscreen.
// The adopted monitor is the 'current' monitor that includes the biggest area of the window. // The adopted monitor is the 'current' monitor which the window belongs to.
// The returned value can be given to Run or SetSize function if the perfectly fit fullscreen is needed.
// //
// On browsers, MonitorSize returns the 'window' size, not 'screen' size since an Ebiten game // On browsers, ScreenSizeInFullscreen returns the 'window' (global object) size, not 'screen' size since an Ebiten game
// should not know the outside of the window object. // should not know the outside of the window object.
// For more detials, see SetFullscreen API comment. // For more detials, see SetFullscreen API comment.
// //
// On mobiles, MonitorSize returns (0, 0) so far. // On mobiles, ScreenSizeInFullscreen returns (0, 0) so far.
// //
// If you use this for screen size with SetFullscreen(true), you can get the fullscreen mode // If you use this for screen size with SetFullscreen(true), you can get the fullscreen mode
// which size is well adjusted with the monitor. // which size is well adjusted with the monitor.
// //
// w, h := MonitorSize() // w, h := ScreenSizeInFullscreen()
// ebiten.SetFullscreen(true) // ebiten.SetFullscreen(true)
// ebiten.Run(update, w, h, 1, "title") // ebiten.Run(update, w, h, 1, "title")
// //
@ -335,15 +336,15 @@ func RunWithoutMainLoop(f func(*Image) error, width, height int, scale float64,
// fullscreen mode. // fullscreen mode.
// //
// s := ebiten.DeviceScaleFactor() // s := ebiten.DeviceScaleFactor()
// w, h := MonitorSize() // w, h := ScreenSizeInFullscreen()
// ebiten.SetFullscreen(true) // ebiten.SetFullscreen(true)
// ebiten.Run(update, int(float64(w) * s), int(float64(h) * s), 1/s, "title") // ebiten.Run(update, int(float64(w) * s), int(float64(h) * s), 1/s, "title")
// //
// For actual example, see examples/fullscreen // For actual example, see examples/fullscreen
// //
// MonitorSize is concurrent-safe. // ScreenSizeInFullscreen is concurrent-safe.
func MonitorSize() (int, int) { func ScreenSizeInFullscreen() (int, int) {
return ui.MonitorSize() return ui.ScreenSizeInFullscreen()
} }
// SetScreenSize changes the (logical) size of the screen. // SetScreenSize changes the (logical) size of the screen.
@ -515,7 +516,7 @@ func SetWindowIcon(iconImages []image.Image) {
ui.SetWindowIcon(iconImages) ui.SetWindowIcon(iconImages)
} }
// DeviceScaleFactor returns a device scale factor value. // DeviceScaleFactor returns a device scale factor value of the current monitor which the window belongs to.
// //
// DeviceScaleFactor returns a meaningful value on high-DPI display environment, // DeviceScaleFactor returns a meaningful value on high-DPI display environment,
// otherwise DeviceScaleFactor returns 1. // otherwise DeviceScaleFactor returns 1.