commonMain.korlibs.render.TouchEventHandler.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of korgw Show documentation
Show all versions of korgw Show documentation
Portable UI with accelerated graphics support for Kotlin
package korlibs.render
import korlibs.datastructure.*
import korlibs.datastructure.lock.*
import korlibs.event.*
class TouchEventHandler {
@PublishedApi
internal val lock = NonRecursiveLock()
@PublishedApi
internal val touchesEventPool = Pool { TouchEvent() }
@PublishedApi
internal var lastTouchEvent: TouchEvent = TouchEvent()
inline fun handleEvent(gameWindow: GameWindow, kind: TouchEvent.Type, emitter: (TouchEvent) -> Unit) {
val currentTouchEvent = lock {
val currentTouchEvent = touchesEventPool.alloc()
currentTouchEvent.copyFrom(lastTouchEvent)
currentTouchEvent.startFrame(kind)
emitter(currentTouchEvent)
currentTouchEvent.endFrame()
lastTouchEvent.copyFrom(currentTouchEvent)
currentTouchEvent
}
gameWindow.queue {
try {
gameWindow.dispatch(currentTouchEvent)
} finally {
lock { touchesEventPool.free(currentTouchEvent) }
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy