Created
August 14, 2018 22:52
-
-
Save rewinfrey/e96196beb1d8a4042eb0434ada276c61 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package VoltIJ.gui.layers; | |
import VoltIJ.core.Font; | |
import com.sun.opengl.util.texture.Texture; | |
import com.sun.opengl.util.texture.TextureIO; | |
import java.io.File; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
import java.util.List; | |
import javax.media.opengl.GL; | |
import javax.media.opengl.glu.GLU; | |
public class SkinFactory { | |
private static Texture arrowdoubleTex; | |
private static Texture arrowdownTex; | |
private static Texture arrowrightTex; | |
private static Texture checkboxTex; | |
private static Texture checkedTex; | |
private static Texture colorTex; | |
private static Texture settingsTex; | |
private static Texture settingsupTex; | |
private static Texture slidercursorTex; | |
private static Texture slidermidTex; | |
private static Texture sliderstartTex; | |
private static Texture sliderendTex; | |
private static Texture scrollbarbkgtopTex; | |
private static Texture scrollbarbkgbtmTex; | |
private static Texture scrollbarbkgmidTex; | |
private static Texture scrollbarbuttondownTex; | |
private static Texture scrollbarbuttonupTex; | |
private static Texture scrollbarstartTex; | |
private static Texture scrollbarmidTex; | |
private static Texture scrollbarendTex; | |
private static Texture defaultTex; | |
private static Texture fontTex; | |
private static HashMap<String, Texture> textureTable = new HashMap<String, Texture>(); | |
private static Font font = new Font("plugins/3D/VoltIJSkins/VoltIJFont.fnt"); | |
private static String path; | |
public static String skinPath = "plugins/3D/VoltIJSkins/"; | |
public static String defaultSkinPath = "default/"; | |
private static ArrayList<String> skinList = new ArrayList<String>(); | |
public SkinFactory() { | |
} | |
public static ArrayList<String> getSkinList() { | |
File rep = new File(skinPath); | |
if (rep.exists()) { | |
String liste[]; | |
liste = rep.list(); | |
for (int i = 0; i < liste.length; i++) { | |
File entree = new File(skinPath + liste[i]); | |
if (entree.isDirectory()) { | |
skinList.add(liste[i]); | |
} | |
} | |
} | |
return skinList; | |
} | |
public static Font getFont() { | |
return font; | |
} | |
public static void loadSkin() { | |
path = skinPath + defaultSkinPath; | |
loadTextures(); | |
} | |
public static void loadSkin(String skin) { | |
path = skinPath + skin + "/"; | |
loadTextures(); | |
} | |
public static void loadTextures() { | |
fontTex = loadTexture("VoltIJFont.png"); | |
arrowdoubleTex = loadTexture("arrow_double.png"); | |
arrowdownTex = loadTexture("arrow_down.png"); | |
arrowrightTex = loadTexture("arrow_right.png"); | |
checkboxTex = loadTexture("checkbox.png"); | |
checkedTex = loadTexture("checked.png"); | |
colorTex = loadTexture("color.png"); | |
settingsTex = loadTexture("settings.png"); | |
settingsupTex = loadTexture("settings_up.png"); | |
slidercursorTex = loadTexture("slider_cursor.png"); | |
slidermidTex = loadTexture("slider_mid.png"); | |
slidermidTex.setTexParameteri(GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT); | |
slidermidTex.setTexParameteri(GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT); | |
sliderstartTex = loadTexture("slider_start.png"); | |
sliderendTex = loadTexture("slider_end.png"); | |
scrollbarbkgtopTex = loadTexture("scrollbar_bkg_top.png"); | |
scrollbarbkgbtmTex = loadTexture("scrollbar_bkg_btm.png"); | |
scrollbarbkgmidTex = loadTexture("scrollbar_bkg_mid.png"); | |
scrollbarbuttondownTex = loadTexture("scrollbar_button_down.png"); | |
scrollbarbuttonupTex = loadTexture("scrollbar_button_up.png"); | |
scrollbarstartTex = loadTexture("scrollbar_start.png"); | |
scrollbarmidTex = loadTexture("scrollbar_mid.png"); | |
scrollbarmidTex.setTexParameteri(GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT); | |
scrollbarmidTex.setTexParameteri(GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT); | |
scrollbarendTex = loadTexture("scrollbar_end.png"); | |
defaultTex = loadTexture("default.png"); | |
textureTable.put("font", fontTex); | |
textureTable.put("arrow_double", arrowdoubleTex); | |
textureTable.put("arrow_down", arrowdownTex); | |
textureTable.put("arrow_right", arrowrightTex); | |
textureTable.put("checkbox", checkboxTex); | |
textureTable.put("checked", checkedTex); | |
textureTable.put("color", colorTex); | |
textureTable.put("settings", settingsTex); | |
textureTable.put("settings_up", settingsupTex); | |
textureTable.put("slider_cursor", slidercursorTex); | |
textureTable.put("slider_mid", slidermidTex); | |
textureTable.put("slider_start", sliderstartTex); | |
textureTable.put("slider_end", sliderendTex); | |
textureTable.put("scrollbar_bkg_top", scrollbarbkgtopTex); | |
textureTable.put("scrollbar_bkg_btm", scrollbarbkgbtmTex); | |
textureTable.put("scrollbar_bkg_mid", scrollbarbkgmidTex); | |
textureTable.put("scrollbar_button_down", scrollbarbuttondownTex); | |
textureTable.put("scrollbar_button_up", scrollbarbuttonupTex); | |
textureTable.put("scrollbar_start", scrollbarstartTex); | |
textureTable.put("scrollbar_mid", scrollbarmidTex); | |
textureTable.put("scrollbar_end", scrollbarendTex); | |
textureTable.put("default", defaultTex); | |
} | |
private static Texture loadTexture(String fnm) { | |
String fileName = path + fnm; | |
Texture tex = null; | |
try { | |
tex = TextureIO.newTexture(new File(fileName), false); | |
tex.setTexParameteri(GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); | |
tex.setTexParameteri(GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST); | |
} catch (Exception e) { | |
System.out.println("Error loading texture " + fileName + " / Exception : " + e); | |
} | |
return tex; | |
} | |
public static Texture getTexture(String type) { | |
if (textureTable.containsKey(type)) { | |
return textureTable.get(type); | |
} | |
return textureTable.get("default"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment