aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/compat/GuiScreenUtils.kt
blob: 0cec5aeb22ae15a6caee91f808a5553b5658033b (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
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

    val globalMouseX get() = Mouse.getX()
    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
        }

}