Added code to darken the area behind the stats display so it can be read even over a light background. This can be turned off by calling setDarkenBehind(false) on the StatsAppState

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9975 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Zer..om 12 years ago
parent 5a22c0d9de
commit cb079b48c0
  1. 43
      engine/src/core/com/jme3/app/StatsAppState.java
  2. 4
      engine/src/core/com/jme3/app/StatsView.java

@ -35,8 +35,13 @@ import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.font.BitmapFont;
import com.jme3.font.BitmapText;
import com.jme3.material.Material;
import com.jme3.material.RenderState.BlendMode;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial.CullHint;
import com.jme3.scene.shape.Quad;
/**
@ -52,12 +57,15 @@ public class StatsAppState extends AbstractAppState {
protected boolean showSettings = true;
private boolean showFps = true;
private boolean showStats = true;
private boolean darkenBehind = true;
protected Node guiNode;
protected float secondCounter = 0.0f;
protected int frameCounter = 0;
protected BitmapText fpsText;
protected BitmapFont guiFont;
protected Geometry darkenFps;
protected Geometry darkenStats;
public StatsAppState() {
}
@ -110,6 +118,15 @@ public class StatsAppState extends AbstractAppState {
}
}
public void setDarkenBehind(boolean darkenBehind) {
this.darkenBehind = darkenBehind;
setEnabled(isEnabled());
}
public boolean isDarkenBehind() {
return darkenBehind;
}
@Override
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
@ -133,6 +150,7 @@ public class StatsAppState extends AbstractAppState {
loadFpsText();
loadStatsView();
loadDarken();
}
/**
@ -148,6 +166,7 @@ public class StatsAppState extends AbstractAppState {
fpsText.setText("Frames per second");
fpsText.setCullHint(showFps ? CullHint.Never : CullHint.Always);
guiNode.attachChild(fpsText);
}
/**
@ -166,18 +185,40 @@ public class StatsAppState extends AbstractAppState {
guiNode.attachChild(statsView);
}
public void loadDarken() {
Material mat = new Material(app.assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", new ColorRGBA(0,0,0,0.5f));
mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
darkenFps = new Geometry("StatsDarken", new Quad(200, fpsText.getLineHeight()));
darkenFps.setMaterial(mat);
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.setCullHint(showStats && darkenBehind ? CullHint.Never : CullHint.Always);
guiNode.attachChild(darkenStats);
}
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
if (enabled) {
fpsText.setCullHint(showFps ? CullHint.Never : CullHint.Always);
darkenFps.setCullHint(showFps && darkenBehind ? CullHint.Never : CullHint.Always);
statsView.setEnabled(showStats);
statsView.setCullHint(showStats ? CullHint.Never : CullHint.Always);
darkenStats.setCullHint(showStats && darkenBehind ? CullHint.Never : CullHint.Always);
} else {
fpsText.setCullHint(CullHint.Always);
darkenFps.setCullHint(CullHint.Always);
statsView.setEnabled(false);
statsView.setCullHint(CullHint.Always);
darkenStats.setCullHint(CullHint.Always);
}
}
@ -201,6 +242,8 @@ public class StatsAppState extends AbstractAppState {
guiNode.detachChild(statsView);
guiNode.detachChild(fpsText);
guiNode.detachChild(darkenFps);
guiNode.detachChild(darkenStats);
}

@ -92,6 +92,10 @@ public class StatsView extends Node implements Control {
addControl(this);
}
public float getHeight() {
return labels[0].getLineHeight() * statLabels.length;
}
public void update(float tpf) {
if (!isEnabled())

Loading…
Cancel
Save