mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
parent
bb68ebfcad
commit
d31b0189a2
@ -431,7 +431,6 @@ func main() {
|
||||
ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
|
||||
}
|
||||
|
||||
ebiten.SetInitFocused(*flagInitFocused)
|
||||
if !*flagInitFocused {
|
||||
ebiten.SetRunnableOnUnfocused(true)
|
||||
}
|
||||
@ -464,6 +463,7 @@ func main() {
|
||||
default:
|
||||
log.Fatalf("unexpected graphics library: %s", *flagGraphicsLibrary)
|
||||
}
|
||||
op.InitUnfocused = !*flagInitFocused
|
||||
|
||||
const title = "Window Size (Ebitengine Demo)"
|
||||
ww := int(float64(g.width) * initScreenScale)
|
||||
|
@ -98,4 +98,5 @@ func (u *UserInterface) dumpImages(dir string) (string, error) {
|
||||
|
||||
type RunOptions struct {
|
||||
GraphicsLibrary GraphicsLibrary
|
||||
InitUnfocused bool
|
||||
}
|
||||
|
@ -93,7 +93,6 @@ type userInterfaceImpl struct {
|
||||
initWindowFloating bool
|
||||
initWindowMaximized bool
|
||||
initScreenTransparent bool
|
||||
initFocused bool
|
||||
|
||||
origWindowPosX int
|
||||
origWindowPosY int
|
||||
@ -135,7 +134,6 @@ func init() {
|
||||
initWindowPositionYInDIP: invalidPos,
|
||||
initWindowWidthInDIP: 640,
|
||||
initWindowHeightInDIP: 480,
|
||||
initFocused: true,
|
||||
fpsMode: FPSModeVsyncOn,
|
||||
origWindowPosX: invalidPos,
|
||||
origWindowPosY: invalidPos,
|
||||
@ -490,27 +488,6 @@ func (u *userInterfaceImpl) isWindowBeingClosed() bool {
|
||||
return v
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) isInitFocused() bool {
|
||||
if microsoftgdk.IsXbox() {
|
||||
return true
|
||||
}
|
||||
|
||||
u.m.RLock()
|
||||
v := u.initFocused
|
||||
u.m.RUnlock()
|
||||
return v
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) setInitFocused(focused bool) {
|
||||
if microsoftgdk.IsXbox() {
|
||||
return
|
||||
}
|
||||
|
||||
u.m.Lock()
|
||||
u.initFocused = focused
|
||||
u.m.Unlock()
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) ScreenSizeInFullscreen() (int, int) {
|
||||
if !u.isRunning() {
|
||||
return u.initFullscreenWidthInDIP, u.initFullscreenHeightInDIP
|
||||
@ -933,9 +910,9 @@ func (u *userInterfaceImpl) init(options *RunOptions) error {
|
||||
}
|
||||
glfw.WindowHint(glfw.Floating, floating)
|
||||
|
||||
focused := glfw.False
|
||||
if u.isInitFocused() {
|
||||
focused = glfw.True
|
||||
focused := glfw.True
|
||||
if options.InitUnfocused {
|
||||
focused = glfw.False
|
||||
}
|
||||
glfw.WindowHint(glfw.FocusOnShow, focused)
|
||||
|
||||
@ -1467,13 +1444,6 @@ func (u *userInterfaceImpl) resetForTick() {
|
||||
u.m.Unlock()
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) SetInitFocused(focused bool) {
|
||||
if u.isRunning() {
|
||||
panic("ui: SetInitFocused must be called before the main loop")
|
||||
}
|
||||
u.setInitFocused(focused)
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) Input() *Input {
|
||||
return &u.input
|
||||
}
|
||||
|
@ -77,7 +77,6 @@ type userInterfaceImpl struct {
|
||||
fpsMode FPSModeType
|
||||
renderingScheduled bool
|
||||
running bool
|
||||
initFocused bool
|
||||
cursorMode CursorMode
|
||||
cursorPrevMode CursorMode
|
||||
cursorShape CursorShape
|
||||
@ -96,7 +95,6 @@ type userInterfaceImpl struct {
|
||||
func init() {
|
||||
theUI.userInterfaceImpl = userInterfaceImpl{
|
||||
runnableOnUnfocused: true,
|
||||
initFocused: true,
|
||||
}
|
||||
theUI.input.ui = &theUI.userInterfaceImpl
|
||||
}
|
||||
@ -638,7 +636,7 @@ func (u *userInterfaceImpl) forceUpdateOnMinimumFPSMode() {
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) Run(game Game, options *RunOptions) error {
|
||||
if u.initFocused && window.Truthy() {
|
||||
if !options.InitUnfocused && window.Truthy() {
|
||||
// Do not focus the canvas when the current document is in an iframe.
|
||||
// Otherwise, the parent page tries to focus the iframe on every loading, which is annoying (#1373).
|
||||
isInIframe := !window.Get("location").Equal(window.Get("parent").Get("location"))
|
||||
@ -689,13 +687,6 @@ func (u *userInterfaceImpl) resetForTick() {
|
||||
u.input.resetForTick()
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) SetInitFocused(focused bool) {
|
||||
if u.running {
|
||||
panic("ui: SetInitFocused must be called before the main loop")
|
||||
}
|
||||
u.initFocused = focused
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) Input() *Input {
|
||||
return &u.input
|
||||
}
|
||||
|
@ -433,10 +433,6 @@ func (u *userInterfaceImpl) resetForTick() {
|
||||
u.input.resetForTick()
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) SetInitFocused(focused bool) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
func (u *userInterfaceImpl) Input() *Input {
|
||||
return &u.input
|
||||
}
|
||||
|
@ -133,9 +133,6 @@ func (*userInterfaceImpl) IsScreenTransparent() bool {
|
||||
func (*userInterfaceImpl) SetScreenTransparent(transparent bool) {
|
||||
}
|
||||
|
||||
func (*userInterfaceImpl) SetInitFocused(focused bool) {
|
||||
}
|
||||
|
||||
func (*userInterfaceImpl) Input() *Input {
|
||||
return &theUI.input
|
||||
}
|
||||
|
22
run.go
22
run.go
@ -232,8 +232,15 @@ func RunGame(game Game) error {
|
||||
// RungameOptions represents options for RunGameWithOptions.
|
||||
type RunGameOptions struct {
|
||||
// GraphicsLibrary is a graphics library Ebitengine will use.
|
||||
//
|
||||
// The default (zero) value is GraphicsLibraryAuto, which lets Ebitengine choose the graphics library.
|
||||
GraphicsLibrary GraphicsLibrary
|
||||
|
||||
// InitUnfocused represents whether the window is unfocused or not on launching.
|
||||
// InitUnfocused is valid on desktops and browsers.
|
||||
//
|
||||
// The default (zero) value is false, which means that the window is focused.
|
||||
InitUnfocused bool
|
||||
}
|
||||
|
||||
// RunGameWithOptions starts the main loop and runs the game with the specified options.
|
||||
@ -598,15 +605,26 @@ func SetScreenTransparent(transparent bool) {
|
||||
// SetInitFocused panics if this is called after the main loop.
|
||||
//
|
||||
// SetInitFocused is cuncurrent-safe.
|
||||
//
|
||||
// Deprecated: as of v2.5. Use RunGameWithOptions instead.
|
||||
func SetInitFocused(focused bool) {
|
||||
ui.Get().SetInitFocused(focused)
|
||||
if focused {
|
||||
atomic.StoreInt32(&initUnfocused, 0)
|
||||
} else {
|
||||
atomic.StoreInt32(&initUnfocused, 1)
|
||||
}
|
||||
}
|
||||
|
||||
var initUnfocused int32 = 0
|
||||
|
||||
func toUIRunOptions(options *RunGameOptions) *ui.RunOptions {
|
||||
if options == nil {
|
||||
return &ui.RunOptions{}
|
||||
return &ui.RunOptions{
|
||||
InitUnfocused: atomic.LoadInt32(&initUnfocused) != 0,
|
||||
}
|
||||
}
|
||||
return &ui.RunOptions{
|
||||
GraphicsLibrary: ui.GraphicsLibrary(options.GraphicsLibrary),
|
||||
InitUnfocused: options.InitUnfocused,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user