mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-09 16:45:46 -07:00
add mousewheel relay
This commit is contained in:
parent
f2d4c17569
commit
52d07d5795
1 changed files with 15 additions and 0 deletions
|
|
@ -44,6 +44,10 @@ class AltCanvas : Canvas() {
|
|||
override fun keyReleased(e: KeyEvent) = relayKeyEvent(e) { it.keyReleased(e) }
|
||||
override fun keyTyped(e: KeyEvent) = relayKeyEvent(e) { it.keyTyped(e) }
|
||||
})
|
||||
|
||||
addMouseWheelListener(object : MouseWheelListener {
|
||||
override fun mouseWheelMoved(e: MouseWheelEvent) = relayMouseWheelEvent(e)
|
||||
})
|
||||
}
|
||||
|
||||
override fun update(g: Graphics) = paint(g)
|
||||
|
|
@ -115,6 +119,17 @@ class AltCanvas : Canvas() {
|
|||
for (listener in canvas.keyListeners) action(listener)
|
||||
}
|
||||
|
||||
private fun relayMouseWheelEvent(e: MouseWheelEvent) {
|
||||
val scale = minOf(width.toDouble() / gameImage!!.width, height.toDouble() / gameImage!!.height)
|
||||
val xOffset = ((width - gameImage!!.width * scale) / 2)
|
||||
val yOffset = ((height - gameImage!!.height * scale) / 2)
|
||||
|
||||
val adjustedX = ((e.x - xOffset) / scale).toInt().coerceIn(0, gameImage!!.width - 1)
|
||||
val adjustedY = ((e.y - yOffset) / scale).toInt().coerceIn(0, gameImage!!.height - 1)
|
||||
|
||||
canvas.dispatchEvent(MouseWheelEvent(this, e.id, e.`when`, e.modifiersEx, adjustedX, adjustedY, e.clickCount, e.isPopupTrigger, e.scrollType, e.scrollAmount, e.wheelRotation))
|
||||
}
|
||||
|
||||
fun updateGameImage() {
|
||||
if (IsHD()) renderGlRaster() else renderSoftwareRaster()
|
||||
repaint()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue