mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
mobile: Handle touch events
This commit is contained in:
parent
c5163e89f4
commit
f251ae8b49
@ -37,3 +37,17 @@ func Start() error {
|
||||
func Render() error {
|
||||
return mobile.Render()
|
||||
}
|
||||
|
||||
// TODO: So many glue codes: Can I reduce those?
|
||||
|
||||
func TouchDown(x, y int) {
|
||||
mobile.TouchDown(x, y)
|
||||
}
|
||||
|
||||
func TouchUp(x, y int) {
|
||||
mobile.TouchUp(x, y)
|
||||
}
|
||||
|
||||
func TouchMove(x, y int) {
|
||||
mobile.TouchMove(x, y)
|
||||
}
|
||||
|
@ -15,10 +15,12 @@
|
||||
package mobile
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/examples/common"
|
||||
)
|
||||
|
||||
@ -50,5 +52,11 @@ func Update(screen *ebiten.Image) error {
|
||||
if err := screen.DrawImage(gophersImage, op); err != nil {
|
||||
return err
|
||||
}
|
||||
msg := ""
|
||||
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
|
||||
x, y := ebiten.CursorPosition()
|
||||
msg = fmt.Sprintf("(%d, %d)", x, y)
|
||||
}
|
||||
ebitenutil.DebugPrint(screen, msg)
|
||||
return nil
|
||||
}
|
||||
|
@ -18,8 +18,9 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
glfw "github.com/go-gl/glfw/v3.1/glfw"
|
||||
"math"
|
||||
|
||||
glfw "github.com/go-gl/glfw/v3.1/glfw"
|
||||
)
|
||||
|
||||
var glfwMouseButtonToMouseButton = map[glfw.MouseButton]MouseButton{
|
||||
|
@ -15,3 +15,23 @@
|
||||
// +build android
|
||||
|
||||
package ui
|
||||
|
||||
func (i *input) touchDown(x, y int) {
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
i.mouseButtonPressed[MouseButtonLeft] = true
|
||||
i.cursorX, i.cursorY = x, y
|
||||
}
|
||||
|
||||
func (i *input) touchUp(x, y int) {
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
i.mouseButtonPressed[MouseButtonLeft] = false
|
||||
i.cursorX, i.cursorY = x, y
|
||||
}
|
||||
|
||||
func (i *input) touchMove(x, y int) {
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
i.cursorX, i.cursorY = x, y
|
||||
}
|
||||
|
@ -130,3 +130,18 @@ func (u *userInterface) ScreenScale() int {
|
||||
func (u *userInterface) actualScreenScale() int {
|
||||
return u.scale
|
||||
}
|
||||
|
||||
func TouchDown(x, y int) {
|
||||
s := currentUI.actualScreenScale()
|
||||
currentInput.touchDown(x/s, y/s)
|
||||
}
|
||||
|
||||
func TouchUp(x, y int) {
|
||||
s := currentUI.actualScreenScale()
|
||||
currentInput.touchUp(x/s, y/s)
|
||||
}
|
||||
|
||||
func TouchMove(x, y int) {
|
||||
s := currentUI.actualScreenScale()
|
||||
currentInput.touchMove(x/s, y/s)
|
||||
}
|
||||
|
@ -50,3 +50,15 @@ func Render() error {
|
||||
}
|
||||
return ui.Render(chError)
|
||||
}
|
||||
|
||||
func TouchDown(x, y int) {
|
||||
ui.TouchDown(x, y)
|
||||
}
|
||||
|
||||
func TouchUp(x, y int) {
|
||||
ui.TouchUp(x, y)
|
||||
}
|
||||
|
||||
func TouchMove(x, y int) {
|
||||
ui.TouchMove(x, y)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user