2017-01-09 22:42:59 +01:00
|
|
|
/*
|
|
|
|
* opsu!dance - fork of opsu! with cursordance auto
|
|
|
|
* Copyright (C) 2017 yugecin
|
|
|
|
*
|
|
|
|
* opsu!dance is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* opsu!dance is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with opsu!dance. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package yugecin.opsudance.utils;
|
|
|
|
|
2017-01-21 13:11:34 +01:00
|
|
|
import org.lwjgl.BufferUtils;
|
2017-01-09 22:42:59 +01:00
|
|
|
import org.lwjgl.LWJGLException;
|
2017-01-21 13:11:34 +01:00
|
|
|
import org.lwjgl.input.Cursor;
|
|
|
|
import org.lwjgl.input.Mouse;
|
2017-01-09 22:42:59 +01:00
|
|
|
import org.lwjgl.opengl.Display;
|
|
|
|
import org.lwjgl.opengl.DisplayMode;
|
2017-01-09 22:45:52 +01:00
|
|
|
import org.newdawn.slick.opengl.ImageIOImageData;
|
|
|
|
import org.newdawn.slick.opengl.LoadableImageData;
|
|
|
|
import org.newdawn.slick.opengl.TGAImageData;
|
|
|
|
import org.newdawn.slick.util.Log;
|
|
|
|
import org.newdawn.slick.util.ResourceLoader;
|
|
|
|
|
|
|
|
import java.nio.ByteBuffer;
|
2017-01-21 13:11:34 +01:00
|
|
|
import java.nio.IntBuffer;
|
2017-01-09 22:42:59 +01:00
|
|
|
|
2017-05-27 01:46:50 +02:00
|
|
|
import static yugecin.opsudance.core.errorhandling.ErrorHandler.*;
|
|
|
|
|
2017-01-09 22:42:59 +01:00
|
|
|
public class GLHelper {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* from org.newdawn.slick.AppGameContainer#setDisplayMode
|
|
|
|
*/
|
|
|
|
public static DisplayMode findFullscreenDisplayMode(int targetBPP, int targetFrequency, int width, int height) throws LWJGLException {
|
|
|
|
DisplayMode[] modes = Display.getAvailableDisplayModes();
|
|
|
|
DisplayMode foundMode = null;
|
|
|
|
int freq = 0;
|
|
|
|
int bpp = 0;
|
|
|
|
|
|
|
|
for (DisplayMode current : modes) {
|
|
|
|
if (current.getWidth() != width || current.getHeight() != height) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current.getBitsPerPixel() == targetBPP && current.getFrequency() == targetFrequency) {
|
|
|
|
return current;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current.getFrequency() >= freq && (foundMode == null || current.getBitsPerPixel() >= bpp)) {
|
|
|
|
foundMode = current;
|
|
|
|
freq = foundMode.getFrequency();
|
|
|
|
bpp = foundMode.getBitsPerPixel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return foundMode;
|
|
|
|
}
|
|
|
|
|
2017-01-09 22:45:52 +01:00
|
|
|
/**
|
|
|
|
* from org.newdawn.slick.AppGameContainer#setDisplayMode
|
|
|
|
*/
|
|
|
|
public static void setIcons(String[] refs) {
|
|
|
|
ByteBuffer[] bufs = new ByteBuffer[refs.length];
|
|
|
|
|
|
|
|
for (int i = 0; i < refs.length; i++) {
|
|
|
|
LoadableImageData data;
|
|
|
|
boolean flip = true;
|
|
|
|
|
|
|
|
if (refs[i].endsWith(".tga")) {
|
|
|
|
data = new TGAImageData();
|
|
|
|
} else {
|
|
|
|
flip = false;
|
|
|
|
data = new ImageIOImageData();
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
bufs[i] = data.loadImage(ResourceLoader.getResourceAsStream(refs[i]), flip, false, null);
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.error("failed to set the icon", e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Display.setIcon(bufs);
|
|
|
|
}
|
|
|
|
|
2017-01-21 13:11:34 +01:00
|
|
|
public static void hideNativeCursor() {
|
|
|
|
try {
|
|
|
|
int min = Cursor.getMinCursorSize();
|
|
|
|
IntBuffer tmp = BufferUtils.createIntBuffer(min * min);
|
|
|
|
Mouse.setNativeCursor(new Cursor(min, min, min / 2, min / 2, 1, tmp, null));
|
|
|
|
} catch (LWJGLException e) {
|
2017-05-27 01:46:50 +02:00
|
|
|
explode("Cannot hide native cursor", e, DEFAULT_OPTIONS);
|
2017-01-21 13:11:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void showNativeCursor() {
|
|
|
|
try {
|
|
|
|
Mouse.setNativeCursor(null);
|
|
|
|
} catch (LWJGLException e) {
|
2017-05-27 01:46:50 +02:00
|
|
|
explode("Cannot show native cursor", e, DEFAULT_OPTIONS);
|
2017-01-21 13:11:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-09 22:42:59 +01:00
|
|
|
}
|