mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
internal/ui: separate 'vibrate' part to internal/vibrate
This commit is contained in:
parent
d2d3673bd2
commit
9c8b4db81f
@ -124,9 +124,6 @@ func (*UserInterface) SetScreenTransparent(transparent bool) {
|
|||||||
func (*UserInterface) SetInitFocused(focused bool) {
|
func (*UserInterface) SetInitFocused(focused bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*UserInterface) Vibrate(duration time.Duration, magnitude float64) {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*UserInterface) Input() *Input {
|
func (*UserInterface) Input() *Input {
|
||||||
return &theUserInterface.input
|
return &theUserInterface.input
|
||||||
}
|
}
|
||||||
|
@ -1620,7 +1620,3 @@ func (u *UserInterface) setOrigPos(x, y int) {
|
|||||||
u.origPosX = x
|
u.origPosX = x
|
||||||
u.origPosY = y
|
u.origPosY = y
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) Vibrate(duration time.Duration, magnitude float64) {
|
|
||||||
// Do nothing.
|
|
||||||
}
|
|
||||||
|
@ -652,14 +652,6 @@ func (u *UserInterface) SetInitFocused(focused bool) {
|
|||||||
u.initFocused = focused
|
u.initFocused = focused
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) Vibrate(duration time.Duration, magnitude float64) {
|
|
||||||
// magnitude is ignored.
|
|
||||||
|
|
||||||
if js.Global().Get("navigator").Get("vibrate").Truthy() {
|
|
||||||
js.Global().Get("navigator").Call("vibrate", float64(duration/time.Millisecond))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u *UserInterface) Input() *Input {
|
func (u *UserInterface) Input() *Input {
|
||||||
return &u.input
|
return &u.input
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
//go:build !ebitencbackend
|
//go:build !ebitencbackend
|
||||||
// +build !ebitencbackend
|
// +build !ebitencbackend
|
||||||
|
|
||||||
package ui
|
package vibrate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
@ -107,7 +107,7 @@ static void vibrateOneShot(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx,
|
|||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
func (u *UserInterface) Vibrate(duration time.Duration, magnitude float64) {
|
func Vibrate(duration time.Duration, magnitude float64) {
|
||||||
go func() {
|
go func() {
|
||||||
_ = app.RunOnJVM(func(vm, env, ctx uintptr) error {
|
_ = app.RunOnJVM(func(vm, env, ctx uintptr) error {
|
||||||
// TODO: This might be crash when this is called from init(). How can we detect this?
|
// TODO: This might be crash when this is called from init(). How can we detect this?
|
@ -15,7 +15,7 @@
|
|||||||
//go:build ios && !ebitencbackend
|
//go:build ios && !ebitencbackend
|
||||||
// +build ios,!ebitencbackend
|
// +build ios,!ebitencbackend
|
||||||
|
|
||||||
package ui
|
package vibrate
|
||||||
|
|
||||||
// #cgo CFLAGS: -x objective-c
|
// #cgo CFLAGS: -x objective-c
|
||||||
// #cgo LDFLAGS: -framework AVFoundation -framework CoreHaptics -framework Foundation
|
// #cgo LDFLAGS: -framework AVFoundation -framework CoreHaptics -framework Foundation
|
||||||
@ -114,7 +114,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (u *UserInterface) Vibrate(duration time.Duration, magnitude float64) {
|
func Vibrate(duration time.Duration, magnitude float64) {
|
||||||
go func() {
|
go func() {
|
||||||
C.vibrate(C.double(float64(duration)/float64(time.Second)), C.double(magnitude))
|
C.vibrate(C.double(float64(duration)/float64(time.Second)), C.double(magnitude))
|
||||||
}()
|
}()
|
28
internal/vibrate/vibrate_js.go
Normal file
28
internal/vibrate/vibrate_js.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright 2022 The Ebiten 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.
|
||||||
|
|
||||||
|
package vibrate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall/js"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Vibrate(duration time.Duration, magnitude float64) {
|
||||||
|
// magnitude is ignored.
|
||||||
|
|
||||||
|
if js.Global().Get("navigator").Get("vibrate").Truthy() {
|
||||||
|
js.Global().Get("navigator").Call("vibrate", float64(duration/time.Millisecond))
|
||||||
|
}
|
||||||
|
}
|
26
internal/vibrate/vibrate_null.go
Normal file
26
internal/vibrate/vibrate_null.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
// Copyright 2022 The Ebiten 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 (!android && !ios && !js) || ebitencbackend
|
||||||
|
// +build !android,!ios,!js ebitencbackend
|
||||||
|
|
||||||
|
package vibrate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Vibrate(duration time.Duration, magnitude float64) {
|
||||||
|
// Do nothing.
|
||||||
|
}
|
@ -18,7 +18,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/gamepad"
|
"github.com/hajimehoshi/ebiten/v2/internal/gamepad"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/ui"
|
"github.com/hajimehoshi/ebiten/v2/internal/vibrate"
|
||||||
)
|
)
|
||||||
|
|
||||||
// VibrateOptions represents the options for device vibration.
|
// VibrateOptions represents the options for device vibration.
|
||||||
@ -51,7 +51,7 @@ type VibrateOptions struct {
|
|||||||
//
|
//
|
||||||
// Vibrate is concurrent-safe.
|
// Vibrate is concurrent-safe.
|
||||||
func Vibrate(options *VibrateOptions) {
|
func Vibrate(options *VibrateOptions) {
|
||||||
ui.Get().Vibrate(options.Duration, options.Magnitude)
|
vibrate.Vibrate(options.Duration, options.Magnitude)
|
||||||
}
|
}
|
||||||
|
|
||||||
// VibrateGamepadOptions represents the options for gamepad vibration.
|
// VibrateGamepadOptions represents the options for gamepad vibration.
|
||||||
|
Loading…
Reference in New Issue
Block a user