2018-09-22 10:29:40 +02:00
|
|
|
package it.cavallium.warppi.gui.graphicengine.impl.jogl;
|
2017-01-31 22:29:49 +01:00
|
|
|
|
|
|
|
import java.io.IOException;
|
2017-11-19 22:58:37 +01:00
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Paths;
|
2017-05-16 22:02:44 +02:00
|
|
|
|
2017-01-31 22:29:49 +01:00
|
|
|
import com.jogamp.opengl.GLException;
|
|
|
|
import com.jogamp.opengl.util.texture.Texture;
|
|
|
|
|
2018-09-02 13:36:49 +02:00
|
|
|
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
|
|
|
import it.cavallium.warppi.gui.graphicengine.Skin;
|
2018-09-22 10:29:40 +02:00
|
|
|
import it.cavallium.warppi.gui.graphicengine.impl.jogl.JOGLRenderer.OpenedTextureData;
|
2018-09-02 13:36:49 +02:00
|
|
|
|
2018-09-22 10:29:40 +02:00
|
|
|
public class JOGLSkin implements Skin {
|
2017-01-31 22:29:49 +01:00
|
|
|
|
|
|
|
public Texture t;
|
|
|
|
public int w;
|
|
|
|
public int h;
|
|
|
|
|
|
|
|
private String texturePath;
|
|
|
|
private boolean initialized = false;
|
2017-12-09 23:00:04 +01:00
|
|
|
private boolean isResource;
|
2018-05-12 21:18:29 +02:00
|
|
|
|
2018-09-22 11:17:30 +02:00
|
|
|
JOGLSkin(final GraphicEngine d, final String file) throws IOException {
|
2017-01-31 22:29:49 +01:00
|
|
|
load(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-09-22 11:17:30 +02:00
|
|
|
public void load(final String file) throws IOException {
|
2018-05-12 21:18:29 +02:00
|
|
|
final boolean isResource = !Files.exists(Paths.get(file));
|
2018-09-22 11:17:30 +02:00
|
|
|
if (isResource && this.getClass().getClassLoader().getResource(file) == null)
|
2017-01-31 22:29:49 +01:00
|
|
|
throw new IOException("File '" + file + "' not found!");
|
|
|
|
texturePath = file;
|
2017-12-09 23:00:04 +01:00
|
|
|
this.isResource = isResource;
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-09-22 11:17:30 +02:00
|
|
|
public void initialize(final GraphicEngine d) {
|
2017-01-31 22:29:49 +01:00
|
|
|
try {
|
2018-09-22 10:29:40 +02:00
|
|
|
final OpenedTextureData i = JOGLRenderer.openTexture(texturePath, isResource);
|
|
|
|
t = JOGLRenderer.importTexture(i.f, i.deleteOnExit);
|
2017-11-19 22:58:37 +01:00
|
|
|
w = i.w;
|
|
|
|
h = i.h;
|
2018-09-22 10:29:40 +02:00
|
|
|
((JOGLEngine) d).registerTexture(t);
|
2017-01-31 22:29:49 +01:00
|
|
|
initialized = true;
|
|
|
|
} catch (GLException | IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
System.exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-09-22 11:17:30 +02:00
|
|
|
public void use(final GraphicEngine d) {
|
|
|
|
if (!initialized)
|
2017-01-31 22:29:49 +01:00
|
|
|
initialize(d);
|
2018-09-22 10:29:40 +02:00
|
|
|
final JOGLRenderer r = (JOGLRenderer) d.getRenderer();
|
2017-04-10 22:50:43 +02:00
|
|
|
r.useTexture(t, w, h);
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
|
|
|
|
2017-09-15 23:24:12 +02:00
|
|
|
@Override
|
|
|
|
public boolean isInitialized() {
|
|
|
|
return initialized;
|
|
|
|
}
|
|
|
|
|
2018-04-02 00:47:33 +02:00
|
|
|
@Override
|
|
|
|
public int getSkinWidth() {
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSkinHeight() {
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|