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
This commit is contained in:
parent
5a22c0d9de
commit
cb079b48c0
@ -35,8 +35,13 @@ import com.jme3.app.state.AbstractAppState;
|
|||||||
import com.jme3.app.state.AppStateManager;
|
import com.jme3.app.state.AppStateManager;
|
||||||
import com.jme3.font.BitmapFont;
|
import com.jme3.font.BitmapFont;
|
||||||
import com.jme3.font.BitmapText;
|
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.Node;
|
||||||
import com.jme3.scene.Spatial.CullHint;
|
import com.jme3.scene.Spatial.CullHint;
|
||||||
|
import com.jme3.scene.shape.Quad;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,14 +55,17 @@ public class StatsAppState extends AbstractAppState {
|
|||||||
private Application app;
|
private Application app;
|
||||||
protected StatsView statsView;
|
protected StatsView statsView;
|
||||||
protected boolean showSettings = true;
|
protected boolean showSettings = true;
|
||||||
private boolean showFps = true;
|
private boolean showFps = true;
|
||||||
private boolean showStats = true;
|
private boolean showStats = true;
|
||||||
|
private boolean darkenBehind = true;
|
||||||
|
|
||||||
protected Node guiNode;
|
protected Node guiNode;
|
||||||
protected float secondCounter = 0.0f;
|
protected float secondCounter = 0.0f;
|
||||||
protected int frameCounter = 0;
|
protected int frameCounter = 0;
|
||||||
protected BitmapText fpsText;
|
protected BitmapText fpsText;
|
||||||
protected BitmapFont guiFont;
|
protected BitmapFont guiFont;
|
||||||
|
protected Geometry darkenFps;
|
||||||
|
protected Geometry darkenStats;
|
||||||
|
|
||||||
public StatsAppState() {
|
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
|
@Override
|
||||||
public void initialize(AppStateManager stateManager, Application app) {
|
public void initialize(AppStateManager stateManager, Application app) {
|
||||||
super.initialize(stateManager, app);
|
super.initialize(stateManager, app);
|
||||||
@ -133,6 +150,7 @@ public class StatsAppState extends AbstractAppState {
|
|||||||
|
|
||||||
loadFpsText();
|
loadFpsText();
|
||||||
loadStatsView();
|
loadStatsView();
|
||||||
|
loadDarken();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -148,6 +166,7 @@ public class StatsAppState extends AbstractAppState {
|
|||||||
fpsText.setText("Frames per second");
|
fpsText.setText("Frames per second");
|
||||||
fpsText.setCullHint(showFps ? CullHint.Never : CullHint.Always);
|
fpsText.setCullHint(showFps ? CullHint.Never : CullHint.Always);
|
||||||
guiNode.attachChild(fpsText);
|
guiNode.attachChild(fpsText);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -166,18 +185,40 @@ public class StatsAppState extends AbstractAppState {
|
|||||||
guiNode.attachChild(statsView);
|
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
|
@Override
|
||||||
public void setEnabled(boolean enabled) {
|
public void setEnabled(boolean enabled) {
|
||||||
super.setEnabled(enabled);
|
super.setEnabled(enabled);
|
||||||
|
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
fpsText.setCullHint(showFps ? CullHint.Never : CullHint.Always);
|
fpsText.setCullHint(showFps ? CullHint.Never : CullHint.Always);
|
||||||
|
darkenFps.setCullHint(showFps && darkenBehind ? CullHint.Never : CullHint.Always);
|
||||||
statsView.setEnabled(showStats);
|
statsView.setEnabled(showStats);
|
||||||
statsView.setCullHint(showStats ? CullHint.Never : CullHint.Always);
|
statsView.setCullHint(showStats ? CullHint.Never : CullHint.Always);
|
||||||
|
darkenStats.setCullHint(showStats && darkenBehind ? CullHint.Never : CullHint.Always);
|
||||||
} else {
|
} else {
|
||||||
fpsText.setCullHint(CullHint.Always);
|
fpsText.setCullHint(CullHint.Always);
|
||||||
|
darkenFps.setCullHint(CullHint.Always);
|
||||||
statsView.setEnabled(false);
|
statsView.setEnabled(false);
|
||||||
statsView.setCullHint(CullHint.Always);
|
statsView.setCullHint(CullHint.Always);
|
||||||
|
darkenStats.setCullHint(CullHint.Always);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,6 +242,8 @@ public class StatsAppState extends AbstractAppState {
|
|||||||
|
|
||||||
guiNode.detachChild(statsView);
|
guiNode.detachChild(statsView);
|
||||||
guiNode.detachChild(fpsText);
|
guiNode.detachChild(fpsText);
|
||||||
|
guiNode.detachChild(darkenFps);
|
||||||
|
guiNode.detachChild(darkenStats);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,6 +92,10 @@ public class StatsView extends Node implements Control {
|
|||||||
addControl(this);
|
addControl(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getHeight() {
|
||||||
|
return labels[0].getLineHeight() * statLabels.length;
|
||||||
|
}
|
||||||
|
|
||||||
public void update(float tpf) {
|
public void update(float tpf) {
|
||||||
|
|
||||||
if (!isEnabled())
|
if (!isEnabled())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user