2020-07-22 06:23:34 +01:00
|
|
|
package com.mojang.blaze3d.platform;
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Optional;
|
|
|
|
import org.lwjgl.glfw.GLFWVidMode;
|
|
|
|
import org.lwjgl.glfw.GLFW;
|
2020-07-22 06:25:47 +01:00
|
|
|
import com.mojang.blaze3d.systems.RenderSystem;
|
2020-07-22 06:23:34 +01:00
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public final class Monitor {
|
|
|
|
private final long monitor;
|
|
|
|
private final List<VideoMode> videoModes;
|
|
|
|
private VideoMode currentMode;
|
|
|
|
private int x;
|
|
|
|
private int y;
|
|
|
|
|
|
|
|
public Monitor(final long long1) {
|
|
|
|
this.monitor = long1;
|
|
|
|
this.videoModes = Lists.newArrayList();
|
|
|
|
this.refreshVideoModes();
|
|
|
|
}
|
|
|
|
|
2020-07-22 06:25:47 +01:00
|
|
|
public void refreshVideoModes() {
|
|
|
|
RenderSystem.assertThread(RenderSystem::isInInitPhase);
|
2020-07-22 06:23:34 +01:00
|
|
|
this.videoModes.clear();
|
|
|
|
final GLFWVidMode.Buffer buffer2 = GLFW.glfwGetVideoModes(this.monitor);
|
|
|
|
for (int integer3 = buffer2.limit() - 1; integer3 >= 0; --integer3) {
|
|
|
|
buffer2.position(integer3);
|
2020-07-22 06:25:47 +01:00
|
|
|
final VideoMode cxt4 = new VideoMode(buffer2);
|
|
|
|
if (cxt4.getRedBits() >= 8 && cxt4.getGreenBits() >= 8 && cxt4.getBlueBits() >= 8) {
|
|
|
|
this.videoModes.add(cxt4);
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
final int[] arr3 = { 0 };
|
|
|
|
final int[] arr4 = { 0 };
|
|
|
|
GLFW.glfwGetMonitorPos(this.monitor, arr3, arr4);
|
|
|
|
this.x = arr3[0];
|
|
|
|
this.y = arr4[0];
|
|
|
|
final GLFWVidMode gLFWVidMode5 = GLFW.glfwGetVideoMode(this.monitor);
|
|
|
|
this.currentMode = new VideoMode(gLFWVidMode5);
|
|
|
|
}
|
|
|
|
|
|
|
|
public VideoMode getPreferredVidMode(final Optional<VideoMode> optional) {
|
2020-07-22 06:25:47 +01:00
|
|
|
RenderSystem.assertThread(RenderSystem::isInInitPhase);
|
2020-07-22 06:23:34 +01:00
|
|
|
if (optional.isPresent()) {
|
2020-07-22 06:25:47 +01:00
|
|
|
final VideoMode cxt3 = optional.get();
|
|
|
|
for (final VideoMode cxt4 : this.videoModes) {
|
|
|
|
if (cxt4.equals(cxt3)) {
|
|
|
|
return cxt4;
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.getCurrentMode();
|
|
|
|
}
|
|
|
|
|
2020-07-22 06:25:47 +01:00
|
|
|
public int getVideoModeIndex(final VideoMode cxt) {
|
|
|
|
RenderSystem.assertThread(RenderSystem::isInInitPhase);
|
|
|
|
return this.videoModes.indexOf(cxt);
|
2020-07-22 06:23:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public VideoMode getCurrentMode() {
|
|
|
|
return this.currentMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getX() {
|
|
|
|
return this.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getY() {
|
|
|
|
return this.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
public VideoMode getMode(final int integer) {
|
|
|
|
return this.videoModes.get(integer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getModeCount() {
|
|
|
|
return this.videoModes.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getMonitor() {
|
|
|
|
return this.monitor;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return String.format("Monitor[%s %sx%s %s]", this.monitor, this.x, this.y, this.currentMode);
|
|
|
|
}
|
|
|
|
}
|