mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
parent
90dba581e2
commit
bb04fc8a29
@ -58,6 +58,7 @@ var (
|
||||
flagWindowPosition = flag.String("windowposition", "", "window position (e.g., 100,200)")
|
||||
flagScreenTransparent = flag.Bool("screentransparent", false, "screen transparent")
|
||||
flagAutoAdjusting = flag.Bool("autoadjusting", false, "make the game screen auto-adjusting")
|
||||
flagInitFocused = flag.Bool("initfocused", true, "whether the window is focused on start")
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -370,6 +371,11 @@ func main() {
|
||||
ebiten.SetWindowResizable(true)
|
||||
}
|
||||
|
||||
ebiten.SetInitFocused(*flagInitFocused)
|
||||
if !*flagInitFocused {
|
||||
ebiten.SetRunnableInBackground(true)
|
||||
}
|
||||
|
||||
const title = "Window Size (Ebiten Demo)"
|
||||
if *flagLegacy {
|
||||
if err := ebiten.Run(g.Update, g.width, g.height, initScreenScale, title); err != nil {
|
||||
|
@ -49,6 +49,7 @@ type UI interface {
|
||||
SetRunnableInBackground(runnableInBackground bool)
|
||||
SetVsyncEnabled(enabled bool)
|
||||
SetScreenTransparent(transparent bool)
|
||||
SetInitFocused(focused bool)
|
||||
|
||||
Input() Input
|
||||
Window() Window
|
||||
|
@ -78,6 +78,7 @@ const (
|
||||
ContextVersionMinor = Hint(0x00022003)
|
||||
Decorated = Hint(0x00020005)
|
||||
Focused = Hint(0x00020001)
|
||||
FocusOnShow = Hint(0x0002000C)
|
||||
Resizable = Hint(0x00020003)
|
||||
TransparentFramebuffer = Hint(0x0002000A)
|
||||
Visible = Hint(0x00020004)
|
||||
|
@ -68,6 +68,7 @@ type UserInterface struct {
|
||||
initWindowHeightInDP int
|
||||
initScreenTransparent bool
|
||||
initIconImages []image.Image
|
||||
initFocused bool
|
||||
|
||||
reqWidth int
|
||||
reqHeight int
|
||||
@ -95,6 +96,7 @@ var (
|
||||
initWindowPositionYInDP: invalidPos,
|
||||
initWindowWidthInDP: 640,
|
||||
initWindowHeightInDP: 480,
|
||||
initFocused: true,
|
||||
vsync: true,
|
||||
}
|
||||
)
|
||||
@ -334,6 +336,19 @@ func (u *UserInterface) setInitWindowSize(width, height int) {
|
||||
u.m.Unlock()
|
||||
}
|
||||
|
||||
func (u *UserInterface) isInitFocused() bool {
|
||||
u.m.Lock()
|
||||
v := u.initFocused
|
||||
u.m.Unlock()
|
||||
return v
|
||||
}
|
||||
|
||||
func (u *UserInterface) setInitFocused(focused bool) {
|
||||
u.m.Lock()
|
||||
u.initFocused = focused
|
||||
u.m.Unlock()
|
||||
}
|
||||
|
||||
// toDeviceIndependentPixel must be called from the main thread.
|
||||
func (u *UserInterface) toDeviceIndependentPixel(x float64) float64 {
|
||||
return x / u.glfwScale()
|
||||
@ -628,6 +643,12 @@ func (u *UserInterface) run(context driver.UIContext) error {
|
||||
}
|
||||
glfw.WindowHint(glfw.Resizable, resizable)
|
||||
|
||||
focused := glfw.False
|
||||
if u.isInitFocused() {
|
||||
focused = glfw.True
|
||||
}
|
||||
glfw.WindowHint(glfw.FocusOnShow, focused)
|
||||
|
||||
// Set the window visible explicitly or the application freezes on Wayland (#974).
|
||||
if os.Getenv("WAYLAND_DISPLAY") != "" {
|
||||
glfw.WindowHint(glfw.Visible, glfw.True)
|
||||
@ -1015,6 +1036,13 @@ func (u *UserInterface) MonitorPosition() (int, int) {
|
||||
return mx, my
|
||||
}
|
||||
|
||||
func (u *UserInterface) SetInitFocused(focused bool) {
|
||||
if u.isRunning() {
|
||||
panic("ui: SetInitFocused must be called before the main loop")
|
||||
}
|
||||
u.setInitFocused(focused)
|
||||
}
|
||||
|
||||
func (u *UserInterface) monitorPosition() (int, int) {
|
||||
// TODO: toDeviceIndependentPixel might be required.
|
||||
return u.currentMonitor().GetPos()
|
||||
|
@ -33,6 +33,7 @@ type UserInterface struct {
|
||||
runnableInBackground bool
|
||||
vsync bool
|
||||
running bool
|
||||
initFocused bool
|
||||
|
||||
sizeChanged bool
|
||||
contextLost bool
|
||||
@ -46,6 +47,7 @@ type UserInterface struct {
|
||||
var theUI = &UserInterface{
|
||||
sizeChanged: true,
|
||||
vsync: true,
|
||||
initFocused: true,
|
||||
}
|
||||
|
||||
func init() {
|
||||
@ -405,7 +407,9 @@ func init() {
|
||||
}
|
||||
|
||||
func (u *UserInterface) Run(context driver.UIContext) error {
|
||||
canvas.Call("focus")
|
||||
if u.initFocused {
|
||||
canvas.Call("focus")
|
||||
}
|
||||
u.running = true
|
||||
ch := u.loop(context)
|
||||
if runtime.GOARCH == "wasm" {
|
||||
@ -460,6 +464,13 @@ func (u *UserInterface) MonitorPosition() (int, int) {
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
func (u *UserInterface) SetInitFocused(focused bool) {
|
||||
if u.running {
|
||||
panic("ui: SetInitFocused must be called before the main loop")
|
||||
}
|
||||
u.initFocused = focused
|
||||
}
|
||||
|
||||
func (u *UserInterface) Input() driver.Input {
|
||||
return &u.input
|
||||
}
|
||||
|
@ -420,6 +420,10 @@ func (u *UserInterface) MonitorPosition() (int, int) {
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
func (u *UserInterface) SetInitFocused(focused bool) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
func (u *UserInterface) Input() driver.Input {
|
||||
return &u.input
|
||||
}
|
||||
|
14
run.go
14
run.go
@ -486,3 +486,17 @@ func IsScreenTransparent() bool {
|
||||
func SetScreenTransparent(transparent bool) {
|
||||
uiDriver().SetScreenTransparent(transparent)
|
||||
}
|
||||
|
||||
// SetInitFocused sets whether the application is focused on show.
|
||||
// The default value is true, i.e., the application is focused.
|
||||
// Note that the application does not proceed if this is not focused by default.
|
||||
// This behavior can be changed by SetRunnableInBackground.
|
||||
//
|
||||
// SetInitFocused does nothing on mobile.
|
||||
//
|
||||
// SetInitFocused panics if this is called after the main loop.
|
||||
//
|
||||
// SetInitFocused is cuncurrent-safe.
|
||||
func SetInitFocused(focused bool) {
|
||||
uiDriver().SetInitFocused(focused)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user