mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 11:48:02 -04:00
Should fix incorrect coordinates in mouse scroll event in scaled GUIs, closing #1212.
This commit is contained in:
parent
6bf16b316e
commit
fdcdb2c7c5
@ -27,13 +27,11 @@ class Screen(val buffer: api.component.TextBuffer, val hasMouse: Boolean, val ha
|
|||||||
if (hasMouse && Mouse.hasWheel && Mouse.getEventDWheel != 0) {
|
if (hasMouse && Mouse.hasWheel && Mouse.getEventDWheel != 0) {
|
||||||
val mouseX = Mouse.getEventX * width / mc.displayWidth
|
val mouseX = Mouse.getEventX * width / mc.displayWidth
|
||||||
val mouseY = height - Mouse.getEventY * height / mc.displayHeight - 1
|
val mouseY = height - Mouse.getEventY * height / mc.displayHeight - 1
|
||||||
val bx = (mouseX - x - bufferMargin) / TextBufferRenderCache.renderer.charRenderWidth.toDouble
|
toBufferCoordinates(mouseX, mouseY) match {
|
||||||
val by = (mouseY - y - bufferMargin) / TextBufferRenderCache.renderer.charRenderHeight.toDouble
|
case Some((bx, by)) =>
|
||||||
val bw = buffer.getWidth
|
val scroll = math.signum(Mouse.getEventDWheel)
|
||||||
val bh = buffer.getHeight
|
buffer.mouseScroll(bx, by, scroll, null)
|
||||||
if (bx >= 0 && by >= 0 && bx < bw && by < bh) {
|
case _ => // Ignore when out of bounds.
|
||||||
val scroll = math.signum(Mouse.getEventDWheel)
|
|
||||||
buffer.mouseScroll(bx, by, scroll, null)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,15 +58,9 @@ class Screen(val buffer: api.component.TextBuffer, val hasMouse: Boolean, val ha
|
|||||||
super.mouseMovedOrUp(mouseX, mouseY, button)
|
super.mouseMovedOrUp(mouseX, mouseY, button)
|
||||||
if (hasMouse && button >= 0) {
|
if (hasMouse && button >= 0) {
|
||||||
if (didDrag) {
|
if (didDrag) {
|
||||||
val bx = (mouseX - x - bufferMargin) / scale / TextBufferRenderCache.renderer.charRenderWidth
|
toBufferCoordinates(mouseX, mouseY) match {
|
||||||
val by = (mouseY - y - bufferMargin) / scale / TextBufferRenderCache.renderer.charRenderHeight
|
case Some((bx, by)) => buffer.mouseUp(bx, by, button, null)
|
||||||
val bw = buffer.getWidth
|
case _ => buffer.mouseUp(-1.0, -1.0, button, null)
|
||||||
val bh = buffer.getHeight
|
|
||||||
if (bx >= 0 && by >= 0 && bx < bw && by < bh) {
|
|
||||||
buffer.mouseUp(bx, by, button, null)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
buffer.mouseUp(-1.0, -1.0, button, null)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
didDrag = false
|
didDrag = false
|
||||||
@ -77,6 +69,15 @@ class Screen(val buffer: api.component.TextBuffer, val hasMouse: Boolean, val ha
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def toBufferCoordinates(mouseX: Int, mouseY: Int): Option[(Double, Double)] = {
|
||||||
|
val bx = (mouseX - x - bufferMargin) / scale / TextBufferRenderCache.renderer.charRenderWidth
|
||||||
|
val by = (mouseY - y - bufferMargin) / scale / TextBufferRenderCache.renderer.charRenderHeight
|
||||||
|
val bw = buffer.getWidth
|
||||||
|
val bh = buffer.getHeight
|
||||||
|
if (bx >= 0 && by >= 0 && bx < bw && by < bh) Some((bx, by))
|
||||||
|
else None
|
||||||
|
}
|
||||||
|
|
||||||
private def clickOrDrag(mouseX: Int, mouseY: Int, button: Int) {
|
private def clickOrDrag(mouseX: Int, mouseY: Int, button: Int) {
|
||||||
val bx = (mouseX - x - bufferMargin) / scale / TextBufferRenderCache.renderer.charRenderWidth
|
val bx = (mouseX - x - bufferMargin) / scale / TextBufferRenderCache.renderer.charRenderWidth
|
||||||
val by = (mouseY - y - bufferMargin) / scale / TextBufferRenderCache.renderer.charRenderHeight
|
val by = (mouseY - y - bufferMargin) / scale / TextBufferRenderCache.renderer.charRenderHeight
|
||||||
|
Loading…
x
Reference in New Issue
Block a user