blob: d2f22dc5768f31895e6e194480cece6ce6377c56 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
package at.hannibal2.skyhanni.utils.compat
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.ScaledResolution
import org.lwjgl.input.Mouse
object GuiScreenUtils {
private val mc get() = Minecraft.getMinecraft()
val scaledWindowHeight
get() =
//#if MC < 1.16
ScaledResolution(mc).scaledHeight
//#else
//$$ mc.window.guiScaledHeight
//#endif
val scaledWindowWidth
get() =
//#if MC < 1.16
ScaledResolution(mc).scaledWidth
//#else
//$$ mc.window.guiScaledWidth
//#endif
val displayWidth
get() =
//#if MC < 1.16
mc.displayWidth
//#else
//$$ mc.window.width
//#endif
val displayHeight
get() =
//#if MC < 1.16
mc.displayHeight
//#else
//$$ mc.window.height
//#endif
private val globalMouseX get() = Mouse.getX()
private val globalMouseY get() = Mouse.getY()
val mouseX get() = globalMouseX * scaledWindowWidth / displayWidth
val mouseY: Int
get() {
val height = this.scaledWindowHeight
// TODO: in later versions the height - factor is removed, i think
val y = globalMouseY * height / displayHeight
//#if MC < 1.16
return height - y - 1
//#else
//$$ return y
//#endif
}
val mousePos: Pair<Int, Int> get() = mouseX to mouseY
}
|