package com.mojang.blaze3d.platform; import com.google.common.collect.Lists; import java.util.List; import java.util.Locale; import java.util.Optional; import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFWVidMode; import org.lwjgl.glfw.GLFWVidMode.Buffer; public final class Monitor { private final long monitor; private final List videoModes; private VideoMode currentMode; private int x; private int y; public Monitor(long l) { this.monitor = l; this.videoModes = Lists.newArrayList(); this.refreshVideoModes(); } public void refreshVideoModes() { this.videoModes.clear(); Buffer buffer = GLFW.glfwGetVideoModes(this.monitor); for (int i = buffer.limit() - 1; i >= 0; i--) { buffer.position(i); VideoMode videoMode = new VideoMode(buffer); if (videoMode.getRedBits() >= 8 && videoMode.getGreenBits() >= 8 && videoMode.getBlueBits() >= 8) { this.videoModes.add(videoMode); } } int[] j = new int[1]; int[] k = new int[1]; GLFW.glfwGetMonitorPos(this.monitor, j, k); this.x = j[0]; this.y = k[0]; GLFWVidMode gLFWVidMode = GLFW.glfwGetVideoMode(this.monitor); this.currentMode = new VideoMode(gLFWVidMode); } public VideoMode getPreferredVidMode(Optional optional) { if (optional.isPresent()) { VideoMode videoMode = (VideoMode)optional.get(); for (VideoMode videoMode1 : this.videoModes) { if (videoMode1.equals(videoMode)) { return videoMode1; } } } return this.getCurrentMode(); } public int getVideoModeIndex(VideoMode videoMode) { return this.videoModes.indexOf(videoMode); } public VideoMode getCurrentMode() { return this.currentMode; } public int getX() { return this.x; } public int getY() { return this.y; } public VideoMode getMode(int i) { return this.videoModes.get(i); } public int getModeCount() { return this.videoModes.size(); } public long getMonitor() { return this.monitor; } @Override public String toString() { return String.format(Locale.ROOT, "Monitor[%s %sx%s %s]", this.monitor, this.x, this.y, this.currentMode); } }