Skip to content

Commit

Permalink
fix: properly handle scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
Zxnii committed Oct 18, 2024
1 parent 6120c8d commit 6183357
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions modules/lwjgl/src/main/kotlin/org/lwjgl/input/Mouse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ object Mouse {
@JvmStatic fun getY(): Int = implementation.getY()
@JvmStatic fun getDX(): Int = implementation.getDX()
@JvmStatic fun getDY(): Int = implementation.getDY()
@JvmStatic fun getDWheel(): Int = implementation.getDWheel()

@JvmStatic fun getEventButton(): Int = implementation.getEventButton()
@JvmStatic fun getEventButtonState(): Boolean = implementation.getEventButtonState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface IMouse {

fun getDX(): Int
fun getDY(): Int
fun getDWheel(): Int

fun getEventButton(): Int
fun getEventButtonState(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MouseImpl(private val window: GLFWwindow, private val display: IDisplay) :
}

fun setRawInput(raw: Boolean) {
glfwSetInputMode(window, GLFW_RAW_MOUSE_MOTION, raw.toInt());
glfwSetInputMode(window, GLFW_RAW_MOUSE_MOTION, raw.toInt())
}

override fun destroy() {}
Expand All @@ -61,6 +61,7 @@ class MouseImpl(private val window: GLFWwindow, private val display: IDisplay) :
override fun getY(): Int = display.getHeight() - y
override fun getDX(): Int = xDelta.toInt()
override fun getDY(): Int = yDelta.toInt()
override fun getDWheel(): Int = scrollDelta

override fun getEventButton(): Int = currentEvent?.button ?: -1
override fun getEventButtonState(): Boolean = currentEvent?.buttonState ?: false
Expand All @@ -87,6 +88,7 @@ class MouseImpl(private val window: GLFWwindow, private val display: IDisplay) :
override fun poll() {
xDelta = 0.0
yDelta = 0.0
scrollDelta = 0
}

override fun getButtonCount(): Int = size
Expand All @@ -113,6 +115,8 @@ class MouseImpl(private val window: GLFWwindow, private val display: IDisplay) :

@Suppress("UNUSED_PARAMETER")
private fun mouseButtonHandler(window: Long, button: Int, action: Int, mods: Int) {
buttonStates[button] = action == GLFW_PRESS

events.addLast(
createEvent(
button,
Expand Down Expand Up @@ -154,7 +158,7 @@ class MouseImpl(private val window: GLFWwindow, private val display: IDisplay) :

@Suppress("UNUSED_PARAMETER")
private fun mouseScrollHandler(window: Long, x: Double, y: Double) {
scrollDelta = y.toInt()
scrollDelta += y.toInt()

events.addLast(
createEvent(
Expand Down

0 comments on commit 6183357

Please sign in to comment.