layout.setHorizontalGroup(layout.createParallelGroup().addWidgets(button, fpsCounter));\r
layout.setVerticalGroup(layout.createSequentialGroup().addWidget(button).addGap(5).addWidget(fpsCounter).addGap(5));\r
\r
- gui = TwlRenderer.createGUI(layout, Gdx.files.getFileHandle("data/widgets.xml", FileType.Internal));\r
+ gui = TwlRenderer.createGUI(layout, "data/widgets.xml", FileType.Internal);\r
}\r
\r
public void render () {\r
layout.setHorizontalGroup(layout.createParallelGroup().addWidgets(scrollPane, fpsCounter));\r
layout.setVerticalGroup(layout.createSequentialGroup().addWidget(scrollPane).addGap(5).addWidget(fpsCounter).addGap(5));\r
\r
- gui = TwlRenderer.createGUI(layout, Gdx.files.getFileHandle("data/widgets.xml", FileType.Internal));\r
+ gui = TwlRenderer.createGUI(layout, "data/widgets.xml", FileType.Internal);\r
\r
textArea.addCallback(new TextArea.Callback() {\r
Timer timer;\r
import com.badlogic.gdx.Files.FileType;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.GdxRuntimeException;
+import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.BitmapFont;
import de.matthiasmann.twl.renderer.CacheContext;
GdxTexture texture = textures.get(urlString);
if (texture == null) {
if (!valid) throw new IllegalStateException("CacheContext has been destroyed.");
- String path;
- try {
- path = new File(url.toURI()).getPath();
- } catch (Exception ex) {
- path = new File(url.getPath()).getPath();
- }
- if (path.startsWith(File.separator)) path = path.substring(1);
- int index = path.indexOf('!');
- if (index != -1) path = path.substring(index + 1);
- texture = new GdxTexture(renderer, path);
+ FileHandle textureFile = (FileHandle)url.getContent();
+ texture = new GdxTexture(renderer, textureFile);
textures.put(urlString, texture);
}
return texture;
String urlString = url.toExternalForm();
BitmapFont bitmapFont = fonts.get(urlString);
if (bitmapFont == null) {
- String fontFile;
- try {
- fontFile = new File(url.toURI().getPath()).toString();
- } catch (URISyntaxException ex) {
- throw new GdxRuntimeException(ex);
- }
- if (fontFile.startsWith(File.separator)) fontFile = fontFile.substring(1);
- String textureFile = fontFile.endsWith(".fnt") ? fontFile.substring(0, fontFile.length() - 3) + "png" : fontFile
- + ".png";
- bitmapFont = new BitmapFont(Gdx.files.getFileHandle(fontFile, FileType.Internal), Gdx.files.getFileHandle(textureFile,
- FileType.Internal), true);
+ FileHandle fontFile = (FileHandle)url.getContent();
+ FileHandle textureFile = (FileHandle)new URL(url, url.getPath().replace(".fnt", ".png")).getContent();
+ bitmapFont = new BitmapFont(fontFile, textureFile, true);
fonts.put(urlString, bitmapFont);
}
return bitmapFont;
valid = false;
}
}
+
+ private FileHandle urlToFileHandle (URL url) {
+ String relativePath;
+ try {
+ relativePath = new File(url.toURI()).getPath();
+ } catch (Exception ex) {
+ relativePath = new File(url.getPath()).getPath();
+ }
+ if (relativePath.startsWith(File.separator)) relativePath = relativePath.substring(1);
+ // BOZO - How to get the theme file to construct the full path?
+ return null;
+ }
}
import com.badlogic.gdx.Files.FileType;
import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.Texture.TextureWrap;
private final TwlRenderer renderer;
private final com.badlogic.gdx.graphics.Texture texture;
- public GdxTexture (TwlRenderer renderer, String path) {
+ public GdxTexture (TwlRenderer renderer, FileHandle textureFile) {
this.renderer = renderer;
- if (path.charAt(0) == '/') path = path.substring(1);
- texture = Gdx.graphics.newTexture(Gdx.files.getFileHandle(path, FileType.Internal), TextureFilter.Linear,
- TextureFilter.Linear, TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);
+ texture = Gdx.graphics.newTexture(textureFile, TextureFilter.Linear, TextureFilter.Linear, TextureWrap.ClampToEdge,
+ TextureWrap.ClampToEdge);
}
public Image getImage (int x, int y, int width, int height, Color tintColor, boolean tiled) {
\r
package com.badlogic.gdx.twl.renderer;\r
\r
+import java.io.File;\r
import java.io.FileNotFoundException;\r
import java.io.IOException;\r
import java.io.InputStream;\r
\r
import com.badlogic.gdx.Gdx;\r
import com.badlogic.gdx.GdxRuntimeException;\r
+import com.badlogic.gdx.Files.FileType;\r
import com.badlogic.gdx.files.FileHandle;\r
import com.badlogic.gdx.graphics.BitmapFont;\r
import com.badlogic.gdx.graphics.Color;\r
}\r
}\r
\r
- static public GUI createGUI (Widget root, final FileHandle themeFile) {\r
+ static public GUI createGUI (Widget root, String themeFile, final FileType fileType) {\r
TwlRenderer renderer = new TwlRenderer();\r
GUI gui = new GUI(root, renderer, null);\r
+ File file = new File(themeFile);\r
+ final String themeRoot = file.getParent() + "/";\r
+ String themeFileName = file.getName();\r
try {\r
- URL themeURL = new URL("testenv", "local", 80, themeFile.toString(), new URLStreamHandler() {\r
- protected URLConnection openConnection (URL url) throws IOException {\r
+ URL themeURL = new URL("gdx-twl", "local", 80, themeFileName, new URLStreamHandler() {\r
+ protected URLConnection openConnection (final URL url) throws IOException {\r
+ final FileHandle fileHandle = Gdx.files.getFileHandle(themeRoot + url.getPath(), fileType);\r
return new URLConnection(url) {\r
public void connect () throws IOException {\r
}\r
\r
+ public Object getContent () throws IOException {\r
+ return fileHandle;\r
+ }\r
+\r
public InputStream getInputStream () throws IOException {\r
- return themeFile.getInputStream();\r
+ return fileHandle.getInputStream();\r
}\r
};\r
}\r