Skip to content

Commit

Permalink
Made mouse move happen in drawScreen, as handleMouseInput triggers on…
Browse files Browse the repository at this point in the history
… tick
  • Loading branch information
Stivais committed Apr 28, 2024
1 parent 3938e07 commit a4bd7bf
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions odinmain/src/main/kotlin/com/github/stivais/ui/UIScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ class UIScreen(val ui: UI) : GuiScreen() {
}

override fun drawScreen(mouseX: Int, mouseY: Int, partialTicks: Float) {
ui.eventManager?.apply {
val mx = Mouse.getX().toFloat()
val my = mc.displayHeight - Mouse.getY() - 1f

if (this.mouseX != mx || this.mouseY != my) {
onMouseMove(mx, my)
}

val scroll = Mouse.getEventDWheel()
if (scroll != 0) {
onMouseScroll(scroll.toFloat())
}
}
val w = mc.framebuffer.framebufferWidth
val h = mc.framebuffer.framebufferHeight
if (w != previousWidth || h != previousHeight) {
Expand All @@ -32,27 +45,6 @@ class UIScreen(val ui: UI) : GuiScreen() {
ui.eventManager?.onMouseRelease(button)
}

fun mouseMoved(mx: Float, my: Float) {
ui.eventManager?.onMouseMove(mx, my)
}

override fun handleMouseInput() {
ui.eventManager?.apply {
val mx = Mouse.getX().toFloat()
val my = mc.displayHeight - Mouse.getY() - 1f

if (mouseX != mx || mouseY != my) {
onMouseMove(mx, my)
}

val scroll = Mouse.getEventDWheel()
if (scroll != 0) {
onMouseScroll(scroll.toFloat())
}
}
super.handleMouseInput()
}

override fun keyTyped(typedChar: Char, keyCode: Int) {
if (ui.eventManager?.onKeyType(typedChar) == true) return
if (ui.eventManager?.onKeycodePressed(keyCode) == true) return
Expand Down

0 comments on commit a4bd7bf

Please sign in to comment.