By default the Stats/FPS window is in the bottom left and up to now this didn’t really bother me, but I’m at the point where I want to implement a text notification area that I plan to place in that corner. Since I intend to have both available at the same time, at least during development, It’s really not optimal to have those overlapping. Readability would be awful.
The change I’m proposing is to have two new methods in SimpleApplication and several in StatsAppState.java.
Succinctly, you can call either
setStatsWindowLocation(x, y);
or
setStatsWindowLocation(intConstant);
The first is to position the stats at an arbitrary position. The second is for each of the corner of the screen being top-left, top-right, bottom-left and bottom-right. Values would be 0, 1, 2 and 3 respectively.
Here are the proposed changes.
SimpleApplication:
[java]
— Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -265,6 +265,42 @@
}
}
-
/**
-
* Sets the location of the Stats window at a specific position on
-
* the screen.
-
*
-
* Notes:
-
*
-
* The coordinate system is the same as the OpenGL
-
* screen coordinate (0, 0 is bottom left).
-
*
-
* You are also responsible to check the validity of the values.
-
*
-
*
-
* @param x The X position on the screen.
-
* @param y The Y position on the screen.
-
*/
-
public void setStatsWindowLocation(int x, int y) {
-
stateManager.getState(StatsAppState.class).setStatsWindowLocation(x, y);
-
}
-
/**
-
* Sets the location of the Stats window at one of the predefined
-
* positions on the screen.
-
*
-
* @param locType The screen corner location constant.
-
*
-
* 0 = Top left.
-
* 1 = Top right.
-
* 2 = Bottom left (default).
-
* 3 = Bottom right.
-
*
-
*
-
*/
-
public void setStatsWindowLocation(int locType) {
-
stateManager.getState(StatsAppState.class).setStatsWindowLocation(locType);
-
}
-
public abstract void simpleInitApp();
public void simpleUpdate(float tpf) {
[/java]
StatsAppState
[java]
— Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -58,6 +58,10 @@
private boolean showFps = true;
private boolean showStats = true;
private boolean darkenBehind = true;
-
private boolean locationChanged = true;
-
private int statsScreenLocation = -1;
-
private int screenPosX = -1;
-
private int screenPosY = -1;
protected Node guiNode;
protected float secondCounter = 0.0f;
@@ -171,7 +175,7 @@
fpsText = new BitmapText(guiFont, false);
}
-
fpsText.setLocalTranslation(0, fpsText.getLineHeight(), 0);
+// fpsText.setLocalTranslation(0, fpsText.getLineHeight(), 0);
fpsText.setText(“Frames per second”);
fpsText.setCullHint(showFps ? CullHint.Never : CullHint.Always);
guiNode.attachChild(fpsText);
@@ -188,7 +192,7 @@
app.getAssetManager(),
app.getRenderer().getStatistics());
// move it up so it appears above fps text
-
statsView.setLocalTranslation(0, fpsText.getLineHeight(), 0);
+// statsView.setLocalTranslation(0, fpsText.getLineHeight(), 0);
statsView.setEnabled(showStats);
statsView.setCullHint(showStats ? CullHint.Never : CullHint.Always);
guiNode.attachChild(statsView);
@@ -201,17 +205,113 @@
darkenFps = new Geometry("StatsDarken", new Quad(200, fpsText.getLineHeight()));
darkenFps.setMaterial(mat);
-
darkenFps.setLocalTranslation(0, 0, -1);
+// darkenFps.setLocalTranslation(0, 0, -1);
darkenFps.setCullHint(showFps && darkenBehind ? CullHint.Never : CullHint.Always);
guiNode.attachChild(darkenFps);
darkenStats = new Geometry("StatsDarken", new Quad(200, statsView.getHeight()));
darkenStats.setMaterial(mat);
-
darkenStats.setLocalTranslation(0, fpsText.getHeight(), -1);
+// darkenStats.setLocalTranslation(0, fpsText.getHeight(), -1);
darkenStats.setCullHint(showStats && darkenBehind ? CullHint.Never : CullHint.Always);
guiNode.attachChild(darkenStats);
}
-
/**
-
* Set the StatsWindow location at an arbitrary location on the screen.
-
*
-
* NOTE: The coordinate system is the OpenGL system.
-
*
-
* @param x The X coordinate on the screen where to put the StatsWindow.
-
* @param y The Y coordinate on the screen where to put the StatsWindow.
-
*/
-
public void setStatsWindowLocation(float x, float y) {
-
statsScreenLocation = 4;
-
screenPosX = (int) x;
-
screenPosY = (int) y;
-
locationChanged = true;
-
}
-
/**
-
* Set the StatsWindow location to one of the predefined location
-
* on the screen.
-
*
-
* @param screenCorner The screen corner location constant.
-
* 0 = Top left.
-
* 1 = Top right.
-
* 2 = Bottom left (default).
-
* 3 = Bottom right.
-
*/
-
public void setStatsWindowLocation(int screenCorner) {
-
statsScreenLocation = screenCorner;
-
locationChanged = true;
-
}
-
private void statsWindowLocation(int screenCorner) {
-
int x;
-
int yStats;
-
int yFps;
-
if (screenCorner 4) {
-
screenCorner = 2;
-
}
-
int width = app.getGuiViewPort().getCamera().getWidth();
-
int height = app.getGuiViewPort().getCamera().getHeight();
-
int textWidth = 200;
-
int statsHeight = (int) statsView.getHeight();
-
int fpsHeight = (int) fpsText.getHeight();
-
if (screenCorner == 0) {
-
x = 0;
-
if (showStats) {
-
yStats = height - statsHeight;
-
yFps = yStats - fpsHeight;
-
} else {
-
yStats = height - (int) statsView.getHeight();
-
yFps = height - fpsHeight;
-
}
-
} else if (screenCorner == 1) {
-
x = width - textWidth;
-
if (showStats) {
-
yStats = height - statsHeight;
-
yFps = yStats - fpsHeight;
-
} else {
-
yStats = height - (int) statsView.getHeight();
-
yFps = height - fpsHeight;
-
}
-
} else if (screenCorner == 2) {
-
x = 0;
-
yStats = (int) fpsText.getLineHeight();
-
yFps = 0;
-
} else if (screenCorner == 3) {
-
x = width - textWidth;
-
yStats = (int) fpsText.getLineHeight();
-
yFps = 0;
-
} else {
-
x = screenPosX;
-
yStats = screenPosY;
-
yFps = screenPosY - fpsHeight;
-
}
-
setDarkenStats(x, yStats);
-
setDarkenFPS(x, yFps);
-
setStatsLocation(x, yStats);
-
setFPSLocation(x, yFps + fpsHeight);
-
locationChanged = false;
-
}
-
private void setDarkenStats(float x, float y) {
-
darkenStats.setLocalTranslation(x, y, -1);
-
}
-
private void setStatsLocation(float x, float y) {
-
statsView.setLocalTranslation(x, y, 0);
-
}
-
private void setDarkenFPS(float x, float y) {
-
darkenFps.setLocalTranslation(x, y, -1);
-
}
-
private void setFPSLocation(float x, float y) {
-
fpsText.setLocalTranslation(x, y, 0);
-
}
-
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
@@ -233,6 +333,9 @@@Override
public void update(float tpf) { -
if (locationChanged) {
-
statsWindowLocation(statsScreenLocation);
-
} if (showFps) { secondCounter += app.getTimer().getTimePerFrame(); frameCounter ++;
[/java]