summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-11-27 00:24:43 +0100
committerNao Pross <naopross@thearcway.org>2018-11-27 00:24:43 +0100
commit52f8505f5c665280b48b2e80beefb254e6ac1bd0 (patch)
tree027599f7d0c60a878f8cead99da8383da742d0c4
parentDeleted Game.start() content, add check for state change (diff)
downloadSubconscious-java-52f8505f5c665280b48b2e80beefb254e6ac1bd0.tar.gz
Subconscious-java-52f8505f5c665280b48b2e80beefb254e6ac1bd0.zip
Add unscii-16 as default font in Scene
There is also CamingoCode-Regular.ttf that can be used in the future for dev stuff in the UI.
-rw-r--r--src/subconscious/graphics/Scene.java22
-rw-r--r--src/subconscious/graphics/widget/PerfView.java20
-rw-r--r--src/subconscious/res/fonts/CamingoCode-Regular.ttfbin0 -> 93500 bytes
-rw-r--r--src/subconscious/res/fonts/unscii-16.ttfbin0 -> 188204 bytes
4 files changed, 34 insertions, 8 deletions
diff --git a/src/subconscious/graphics/Scene.java b/src/subconscious/graphics/Scene.java
index 74330ff..3849c24 100644
--- a/src/subconscious/graphics/Scene.java
+++ b/src/subconscious/graphics/Scene.java
@@ -10,12 +10,17 @@ import subconscious.graphics.widget.PerfView;
import java.util.ArrayList;
import java.util.Map;
+import java.io.InputStream;
+import java.io.IOException;
+
import java.awt.Canvas;
import java.awt.Graphics2D;
import java.awt.Dimension;
import java.awt.BorderLayout;
import java.awt.Panel;
import java.awt.RenderingHints;
+import java.awt.Font;
+import java.awt.FontFormatException;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
@@ -77,6 +82,9 @@ public abstract class Scene extends Panel
protected Canvas canvas = new Canvas();
protected BufferStrategy buffer;
+ protected Font font;
+ protected final float defaultFontSize = 10.0f;
+
// TODO: make accessible from user settings
protected int guiSize = 2;
@@ -88,6 +96,19 @@ public abstract class Scene extends Panel
this.UNIQUE_NAME = uniqueName + " (" + label + ")";
this.game = game;
+ // set default scene font unscii
+ InputStream fontStream = Scene.class.getResourceAsStream("/subconscious/res/fonts/unscii-16.ttf");
+
+ assert fontStream != null;
+
+ try {
+ this.font = Font.createFont(Font.TRUETYPE_FONT, fontStream);
+ } catch (FontFormatException ex) {
+ ex.printStackTrace();
+ } catch (IOException ioex) {
+ ioex.printStackTrace();
+ }
+
// watch for resize
this.addComponentListener(this);
@@ -211,6 +232,7 @@ public abstract class Scene extends Panel
do {
Graphics2D g = (Graphics2D) this.buffer.getDrawGraphics();
g.addRenderingHints(this.RENDERING_HINTS);
+ g.setFont(this.font.deriveFont(this.defaultFontSize));
this.render(g);
this.renderWidgets(g);
g.dispose();
diff --git a/src/subconscious/graphics/widget/PerfView.java b/src/subconscious/graphics/widget/PerfView.java
index d5de3cb..c7c9356 100644
--- a/src/subconscious/graphics/widget/PerfView.java
+++ b/src/subconscious/graphics/widget/PerfView.java
@@ -11,22 +11,26 @@ import java.awt.Graphics2D;
* final game.
*/
public class PerfView extends Widget implements Dynamic {
-
- public static final int WIDTH = 120;
- public static final int HEIGHT = 30;
-
protected long lastDeltaNanoTime = 0;
-
public PerfView(String uniqueName, int x, int y) {
- super(uniqueName, x, y, PerfView.WIDTH, PerfView.HEIGHT);
+ // the size depends on the font
+ super(uniqueName, x, y, 0, 0);
}
@Override
public void render(Graphics2D g) {
+ String text = "DeltaTime (us): "
+ + Long.toString(this.lastDeltaNanoTime/1000);
+
+ this.width = g.getFontMetrics().stringWidth(text);
+ this.height = g.getFontMetrics().getHeight() + 10;
+
g.setColor(Palette.BLACK);
- g.drawString("DeltaTime (us): ", 0, HEIGHT/2);
- g.drawString(Long.toString(this.lastDeltaNanoTime/1000), 0, HEIGHT);
+ g.fillRect(0, 0, this.width, this.height);
+
+ g.setColor(Palette.WHITE);
+ g.drawString(text, 0, this.height - 10);
}
@Override
diff --git a/src/subconscious/res/fonts/CamingoCode-Regular.ttf b/src/subconscious/res/fonts/CamingoCode-Regular.ttf
new file mode 100644
index 0000000..04b8860
--- /dev/null
+++ b/src/subconscious/res/fonts/CamingoCode-Regular.ttf
Binary files differ
diff --git a/src/subconscious/res/fonts/unscii-16.ttf b/src/subconscious/res/fonts/unscii-16.ttf
new file mode 100644
index 0000000..050ce76
--- /dev/null
+++ b/src/subconscious/res/fonts/unscii-16.ttf
Binary files differ