diff --git a/core/src/cz/nic/tablexia/TablexiaApplication.java b/core/src/cz/nic/tablexia/TablexiaApplication.java index f3abd297caeb7548590e21550c8f2e9dae3e79e6..4c5b50f057f1b6ce032dca53371cdce02f738bb9 100644 --- a/core/src/cz/nic/tablexia/TablexiaApplication.java +++ b/core/src/cz/nic/tablexia/TablexiaApplication.java @@ -37,9 +37,9 @@ public abstract class TablexiaApplication implements ApplicationListener { private AbstractTablexiaScreen<?> lastScreen; private AbstractTablexiaScreen<?> screen; - private InputMultiplexer inputMultiplexer; - private DebugInfo debugInfo; - private Stage stage; + private InputMultiplexer inputMultiplexer; + private DebugInfo debugInfo; + private Stage stage; public Stage getStage() { @@ -108,6 +108,8 @@ public abstract class TablexiaApplication implements ApplicationListener { if (lastScreen != null) lastScreen.resize(width, height); if (screen != null) screen.resize(width, height); stage.getViewport().update(width, height, true); + // keep debug info on edges of the screen + debugInfo.onResize(); } @@ -115,7 +117,7 @@ public abstract class TablexiaApplication implements ApplicationListener { private void prepareDebugInfo() { if (TablexiaSettings.getInstance().isDebug()) { - debugInfo = new DebugInfo(getStage().getWidth(), getStage().getHeight()); + debugInfo = new DebugInfo(); // TODO probably deprecated creating specific size getStage().addActor(debugInfo); } } @@ -189,27 +191,27 @@ public abstract class TablexiaApplication implements ApplicationListener { screen = newScreen; screenTransaction.processTransaction(stage, lastScreen, newScreen, - new Runnable() { + new Runnable() { - @Override - public void run() { - processNewScreen(screen); - } - }, + @Override + public void run() { + processNewScreen(screen); + } + }, - new Runnable() { - @Override - public void run() { - processLastScreen(lastScreen); - } - }, + new Runnable() { + @Override + public void run() { + processLastScreen(lastScreen); + } + }, - new Runnable() { - @Override - public void run() { - newScreen.performScreenVisible(); - } - }); + new Runnable() { + @Override + public void run() { + newScreen.performScreenVisible(); + } + }); } } @@ -270,8 +272,8 @@ public abstract class TablexiaApplication implements ApplicationListener { private static class MoveRightAnimation implements cz.nic.tablexia.TablexiaApplication.ScreenTransaction.ScreenTransactionImplementation { protected float newScreenMoveFrom = -Gdx.graphics.getWidth(); - protected float newScreenMoveTo = 0; - protected float lastScreenMoveTo = Gdx.graphics.getWidth(); + protected float newScreenMoveTo = 0; + protected float lastScreenMoveTo = Gdx.graphics.getWidth(); @Override public void processTransaction(Stage stage, final AbstractTablexiaScreen<?> lastScreen, final AbstractTablexiaScreen<?> newScreen, Runnable newScreenHandler, final Runnable lastScreenHandler, final Runnable finishHandler) { diff --git a/core/src/cz/nic/tablexia/debug/DebugInfo.java b/core/src/cz/nic/tablexia/debug/DebugInfo.java index 2c6f1f8b946032356266b0ba541a12f32b1671d2..462f5c979dd03434f396ff6deda876e7d45bf5e0 100644 --- a/core/src/cz/nic/tablexia/debug/DebugInfo.java +++ b/core/src/cz/nic/tablexia/debug/DebugInfo.java @@ -29,41 +29,38 @@ import static com.badlogic.gdx.scenes.scene2d.actions.Actions.alpha; /** * Debug info container - * - * @author Matyáš Latner * + * @author Matyáš Latner */ public class DebugInfo extends Table implements Disposable { - private static class DebugInfoComponent extends Table { - - private Map<String, Label> infoLabelMap; - private LabelStyle labelStyle; - - public DebugInfoComponent(float width, float height) { - infoLabelMap = new HashMap<String, Label>(); - setBounds(0, 0, width, height); - setBackground(new TextureRegionDrawable(new TextureRegion(new ColorTexture(1, 1, BACKGROUND_COLOR)))); - addAction(alpha(BACKGROUND_ALPHA)); - - labelStyle = new LabelStyle(new BitmapFont(), FONT_COLOR); - } - - public synchronized void setInfoValue(String infoKey, String infoValue) { - Label label = infoLabelMap.get(infoKey); - if (label == null) { - createInfoLabel(infoKey, infoValue); - } else { - label.setText(infoKey + KEY_COLON + infoValue); - } - } - - private void clean() { - clearChildren(); - infoLabelMap.clear(); - } - - private void createInfoLabel(String infoKey, String infoValue) { + private static class DebugInfoComponent extends Table { + + private Map<String, Label> infoLabelMap; + private LabelStyle labelStyle; + + public DebugInfoComponent() { + infoLabelMap = new HashMap<String, Label>(); + setBackground(new TextureRegionDrawable(new TextureRegion(new ColorTexture(1, 1, BACKGROUND_COLOR)))); + addAction(alpha(BACKGROUND_ALPHA)); + labelStyle = new LabelStyle(new BitmapFont(), FONT_COLOR); + } + + public synchronized void setInfoValue(String infoKey, String infoValue) { + Label label = infoLabelMap.get(infoKey); + if (label == null) { + createInfoLabel(infoKey, infoValue); + } else { + label.setText(infoKey + KEY_COLON + infoValue); + } + } + + private void clean() { + clearChildren(); + infoLabelMap.clear(); + } + + private void createInfoLabel(String infoKey, String infoValue) { Label infoLabel = new Label(infoKey + KEY_COLON + infoValue, labelStyle); infoLabelMap.put(infoKey, infoLabel); clearChildren(); @@ -74,88 +71,90 @@ public class DebugInfo extends Table implements Disposable { cell.pad(0, INFO_PADDING, 0, 0); } } - } - - @Override - public void setSize(float width, float height) { - super.setSize(width, height); - } - - } - - - private static final String NATIVE_HEAP = "Native Heap"; - private static final String JAVA_HEAP = "Java Heap"; - private static final String FPS = "FPS"; - private static final String LOCALE = "Locale"; - private static final String VERSION = "Version"; - - private static final String SCREEN_NAME = "Screen Name"; - - private static final int INFO_PADDING = 20; - private static final int MB_SIZE = 1000000; - private static final String UNIT_MB = " MB"; - private static final String KEY_COLON = ": "; - - private static final Color FONT_COLOR = Color.WHITE; - private static final Color BACKGROUND_COLOR = Color.BLACK; - private static final float BACKGROUND_ALPHA = 0.5f; - - private DebugInfoComponent applicationDebugInfo; - private DebugInfoComponent screenNameInfo; - private DebugInfoComponent screenDebugInfo; - - private ConcurrentLinkedQueue<ScreenInfoEvent> screenDebugInfoQueue = new ConcurrentLinkedQueue<ScreenInfoEvent>(); - private ConcurrentLinkedQueue<ScreenChangedEvent> screenNameInfoQueue = new ConcurrentLinkedQueue<ScreenChangedEvent>(); - - public DebugInfo(float width, float height) { - setBounds(0, 0, width, height); - ApplicationBus.getInstance().subscribe(this); - - applicationDebugInfo = new DebugInfoComponent(width, height); - screenNameInfo = new DebugInfoComponent(width, height); - screenDebugInfo = new DebugInfoComponent(width, height); - - Table topTable = new Table(); - topTable.add(screenNameInfo).expandX(); - topTable.add(screenDebugInfo).pad(0, INFO_PADDING, 0, 0).expandX(); - add(topTable); - row(); - add(new Container<Actor>()).expand(); - row(); - add(applicationDebugInfo).expandX(); - } - - public void update() { + } + + @Override + public void setSize(float width, float height) { + super.setSize(width, height); + } + } + + + private static final String NATIVE_HEAP = "Native Heap"; + private static final String JAVA_HEAP = "Java Heap"; + private static final String FPS = "FPS"; + private static final String LOCALE = "Locale"; + private static final String VERSION = "Version"; + + private static final String SCREEN_NAME = "Screen Name"; + + private static final int INFO_PADDING = 20; + private static final int MB_SIZE = 1000000; + private static final String UNIT_MB = " MB"; + private static final String KEY_COLON = ": "; + + private static final Color FONT_COLOR = Color.WHITE; + private static final Color BACKGROUND_COLOR = Color.BLACK; + private static final float BACKGROUND_ALPHA = 0.5f; + + private DebugInfoComponent applicationDebugInfo; + private DebugInfoComponent screenNameInfo; + private DebugInfoComponent screenDebugInfo; + + private ConcurrentLinkedQueue<ScreenInfoEvent> screenDebugInfoQueue = new ConcurrentLinkedQueue<ScreenInfoEvent>(); + private ConcurrentLinkedQueue<ScreenChangedEvent> screenNameInfoQueue = new ConcurrentLinkedQueue<ScreenChangedEvent>(); + + public DebugInfo() { + ApplicationBus.getInstance().subscribe(this); + + applicationDebugInfo = new DebugInfoComponent(); + screenNameInfo = new DebugInfoComponent(); + screenDebugInfo = new DebugInfoComponent(); + + Table topTable = new Table(); + topTable.add(screenNameInfo).expandX(); + topTable.add(screenDebugInfo).pad(0, INFO_PADDING, 0, 0).expandX(); + add(topTable); + row(); + add(new Container<Actor>()).expand(); + row(); + add(applicationDebugInfo).expandX(); + } + + public void update() { applicationDebugInfo.setInfoValue(FPS, "" + Gdx.graphics.getFramesPerSecond()); applicationDebugInfo.setInfoValue(JAVA_HEAP, ("" + Gdx.app.getJavaHeap() / MB_SIZE) + UNIT_MB); applicationDebugInfo.setInfoValue(NATIVE_HEAP, ("" + Gdx.app.getNativeHeap() / MB_SIZE) + UNIT_MB); applicationDebugInfo.setInfoValue(LOCALE, "" + TablexiaSettings.getInstance().getLocale()); applicationDebugInfo.setInfoValue(VERSION, "" + TablexiaSettings.getInstance().getVersionName()); - while (!screenDebugInfoQueue.isEmpty()) { - ScreenInfoEvent screenInfoEvent = screenDebugInfoQueue.poll(); - screenDebugInfo.setInfoValue(screenInfoEvent.getInfoKey(), screenInfoEvent.getInfoValue()); - } - - while (!screenNameInfoQueue.isEmpty()) { - screenNameInfo.setInfoValue(SCREEN_NAME, "" + screenNameInfoQueue.poll().getScreenClass().getSimpleName()); - } - } - - @Handler - public void handleScreenChangedEvent(ScreenChangedEvent screenChangedEvent) { - screenDebugInfo.clean(); - screenNameInfoQueue.add(screenChangedEvent); - } - - @Handler - public void handleScreenInfoEvent(ScreenInfoEvent screenInfoEvent) { - screenDebugInfoQueue.add(screenInfoEvent); - } - - @Override - public void dispose() { - ApplicationBus.getInstance().unsubscribe(this); - } + while (!screenDebugInfoQueue.isEmpty()) { + ScreenInfoEvent screenInfoEvent = screenDebugInfoQueue.poll(); + screenDebugInfo.setInfoValue(screenInfoEvent.getInfoKey(), screenInfoEvent.getInfoValue()); + } + + while (!screenNameInfoQueue.isEmpty()) { + screenNameInfo.setInfoValue(SCREEN_NAME, "" + screenNameInfoQueue.poll().getScreenClass().getSimpleName()); + } + } + + public void onResize() { + setBounds(0,getStage().getCamera().position.y - getStage().getHeight() / 2,getStage().getWidth(), getStage().getHeight()); + } + + @Handler + public void handleScreenChangedEvent(ScreenChangedEvent screenChangedEvent) { + screenDebugInfo.clean(); + screenNameInfoQueue.add(screenChangedEvent); + } + + @Handler + public void handleScreenInfoEvent(ScreenInfoEvent screenInfoEvent) { + screenDebugInfoQueue.add(screenInfoEvent); + } + + @Override + public void dispose() { + ApplicationBus.getInstance().unsubscribe(this); + } }