mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
internal/processtest: add a test for capturing cursor and fullscreen
Updates #2475
This commit is contained in:
parent
02fd8cfb07
commit
fd689467c5
75
internal/processtest/testdata/issue2475.go
vendored
Normal file
75
internal/processtest/testdata/issue2475.go
vendored
Normal file
@ -0,0 +1,75 @@
|
||||
// Copyright 2023 The Ebitengine Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
||||
)
|
||||
|
||||
type Game struct {
|
||||
count int
|
||||
x int
|
||||
y int
|
||||
}
|
||||
|
||||
func (g *Game) Update() error {
|
||||
switch g.count {
|
||||
case 0:
|
||||
g.x, g.y = ebiten.CursorPosition()
|
||||
case 20:
|
||||
ebiten.SetFullscreen(true)
|
||||
case 40:
|
||||
ebiten.SetFullscreen(false)
|
||||
case 60:
|
||||
return ebiten.Termination
|
||||
default:
|
||||
if x, y := ebiten.CursorPosition(); g.x != x || g.y != y {
|
||||
return fmt.Errorf("cursor position changed: got: (%d, %d), want: (%d, %d)", x, y, g.x, g.y)
|
||||
}
|
||||
}
|
||||
g.count++
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *Game) Draw(screen *ebiten.Image) {
|
||||
x, y := ebiten.CursorPosition()
|
||||
ebitenutil.DebugPrint(screen, fmt.Sprintf("%d, %d", x, y))
|
||||
}
|
||||
|
||||
func (g *Game) Layout(width, height int) (int, int) {
|
||||
// Using a fixed size matters.
|
||||
// If a window size is changed or fullscreened, the cursor position calculation considers the current screen scale.
|
||||
return 320, 240
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Mouse is not supported on mobiles.
|
||||
// Capturing a cursor requires a user gesture on browsers.
|
||||
// Skip the test in these environments.
|
||||
if runtime.GOOS == "android" || runtime.GOOS == "ios" || runtime.GOOS == "js" {
|
||||
return
|
||||
}
|
||||
|
||||
ebiten.SetCursorMode(ebiten.CursorModeCaptured)
|
||||
if err := ebiten.RunGame(&Game{}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user