Java Code Examples for com.jme3.font.BitmapText#setColor()

The following examples show how to use com.jme3.font.BitmapText#setColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DetailedProfilerState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public boolean setColor(BitmapText t, double value, double totalTime, boolean isParent, boolean expended) {

        boolean dimmed = isParent && expended;
        boolean insignificant = false;

        if (value > 1000000000.0 / 30.0) {
            t.setColor(dimmed ? dimmedRed : ColorRGBA.Red);
        } else if (value > 1000000000.0 / 60.0) {
            t.setColor(dimmed ? dimmedOrange : ColorRGBA.Orange);
        } else if (value > totalTime / 3) {
            t.setColor(dimmed ? dimmedGreen : ColorRGBA.Green);
        } else if (value < 30000) {
            t.setColor(ColorRGBA.DarkGray);
            insignificant = true;
        } else {
            t.setColor(dimmed ? dimmedWhite : ColorRGBA.White);
        }
        return insignificant;
    }
 
Example 2
Source File: RenderDeviceJme.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
    public void renderFont(RenderFont font, String str, int x, int y, Color color, float sizeX, float sizeY) {
        if (str.length() == 0) {
            return;
        }

        RenderFontJme jmeFont = (RenderFontJme) font;

        ColorRGBA colorRgba = convertColor(color, tempColor);
        CachedTextKey key = new CachedTextKey(jmeFont.getFont(), str/*, colorRgba*/);
        BitmapText text = textCacheLastFrame.get(key);
        if (text == null) {
            text = jmeFont.createText();
            text.setText(str);
            text.updateLogicalState(0);
        }
        textCacheCurrentFrame.put(key, text);

//        float width = text.getLineWidth();
//        float height = text.getLineHeight();
        float x0 = x; //+ 0.5f * width * (1f - sizeX);
        float y0 = y; // + 0.5f * height * (1f - sizeY);

        tempMat.loadIdentity();
        tempMat.setTranslation(x0, getHeight() - y0, 0);
        tempMat.setScale(sizeX, sizeY, 0);

        rm.setWorldMatrix(tempMat);
        rm.setForcedRenderState(renderState);
        text.setColor(colorRgba);
        text.updateLogicalState(0);
        text.render(rm, colorRgba);

//        System.out.format("renderFont(%s, %s, %d, %d, %s, %f, %f)\n", jmeFont.getFont(), str, x, y, color.toString(), sizeX, sizeY);
    }
 
Example 3
Source File: TestBitmapFontLayout.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void setupInstructionsNote() {
    // Add some instructional text
    String instructions = "WASD/Cursor Keys = scroll\n"
                        + "+/- = zoom\n"
                        + "space = reset view\n"
                        + "0 = reset zoom\n";
    BitmapText note = new BitmapText(guiFont);
    note.setText(instructions);
    note.setColor(new ColorRGBA(0, 0.3f, 0, 1));
    note.updateLogicalState(0.1f);
    
    BoundingBox bb = (BoundingBox)note.getWorldBound();        
    
    note.setLocalTranslation(cam.getWidth() - bb.getXExtent() * 2 - 20, 
                             cam.getHeight() - 20, 10);                
    
    guiNode.attachChild(note);
    
    BitmapText note2 = note.clone();
    note2.setColor(ColorRGBA.Black);
    note2.move(1, -1, -2);
    guiNode.attachChild(note2);

    BitmapText note3 = note.clone();
    note3.setColor(ColorRGBA.White);
    note3.move(-1, 1, -1);
    guiNode.attachChild(note3);
    
}
 
Example 4
Source File: TestComboMoves.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    setDisplayFps(false);
    setDisplayStatView(false);

    // Create debug text
    BitmapText helpText = new BitmapText(guiFont);
    helpText.setLocalTranslation(0, settings.getHeight(), 0);
    helpText.setText("Moves:\n" +
                     "Fireball: Down, Down+Right, Right\n"+
                     "Shuriken: Left, Down, Attack1(Z)\n"+
                     "Jab: Attack1(Z)\n"+
                     "Punch: Attack1(Z), Attack1(Z)\n");
    guiNode.attachChild(helpText);

    fireballText = new BitmapText(guiFont);
    fireballText.setColor(ColorRGBA.Orange);
    fireballText.setLocalTranslation(0, fireballText.getLineHeight(), 0);
    guiNode.attachChild(fireballText);

    shurikenText = new BitmapText(guiFont);
    shurikenText.setColor(ColorRGBA.Cyan);
    shurikenText.setLocalTranslation(0, shurikenText.getLineHeight()*2f, 0);
    guiNode.attachChild(shurikenText);

    jabText = new BitmapText(guiFont);
    jabText.setColor(ColorRGBA.Red);
    jabText.setLocalTranslation(0, jabText.getLineHeight()*3f, 0);
    guiNode.attachChild(jabText);

    punchText = new BitmapText(guiFont);
    punchText.setColor(ColorRGBA.Green);
    punchText.setLocalTranslation(0, punchText.getLineHeight()*4f, 0);
    guiNode.attachChild(punchText);

    inputManager.addMapping("Left",    new KeyTrigger(KeyInput.KEY_LEFT));
    inputManager.addMapping("Right",   new KeyTrigger(KeyInput.KEY_RIGHT));
    inputManager.addMapping("Up",      new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping("Down",    new KeyTrigger(KeyInput.KEY_DOWN));
    inputManager.addMapping("Attack1", new KeyTrigger(KeyInput.KEY_Z));
    inputManager.addListener(this, "Left", "Right", "Up", "Down", "Attack1");

    fireball = new ComboMove("Fireball");
    fireball.press("Down").notPress("Right").done();
    fireball.press("Right", "Down").done();
    fireball.press("Right").notPress("Down").done();
    fireball.notPress("Right", "Down").done();
    fireball.setUseFinalState(false); // no waiting on final state

    shuriken = new ComboMove("Shuriken");
    shuriken.press("Left").notPress("Down", "Attack1").done();
    shuriken.press("Down").notPress("Attack1").timeElapsed(0.11f).done();
    shuriken.press("Attack1").notPress("Left").timeElapsed(0.11f).done();
    shuriken.notPress("Left", "Down", "Attack1").done();

    jab = new ComboMove("Jab");
    jab.setPriority(0.5f); // make jab less important than other moves
    jab.press("Attack1").done();

    punch = new ComboMove("Punch");
    punch.press("Attack1").done();
    punch.notPress("Attack1").done();
    punch.press("Attack1").done();

    fireballExec = new ComboMoveExecution(fireball);
    shurikenExec = new ComboMoveExecution(shuriken);
    jabExec = new ComboMoveExecution(jab);
    punchExec = new ComboMoveExecution(punch);
}
 
Example 5
Source File: DetailedProfilerState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected void initialize(Application app) {
    Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", new ColorRGBA(0, 0, 0, 0.5f));
    mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
    Geometry darkenStats = new Geometry("StatsDarken", new Quad(PANEL_WIDTH, app.getCamera().getHeight()));
    darkenStats.setMaterial(mat);
    darkenStats.setLocalTranslation(0, -app.getCamera().getHeight(), -1);

    ui.attachChild(darkenStats);
    ui.setLocalTranslation(app.getCamera().getWidth() - PANEL_WIDTH, app.getCamera().getHeight(), 0);
    font = app.getAssetManager().loadFont("Interface/Fonts/Console.fnt");
    bigFont = app.getAssetManager().loadFont("Interface/Fonts/Default.fnt");
    prof.setRenderer(app.getRenderer());
    rootLine = new StatLineView("Frame");
    rootLine.attachTo(ui);

    BitmapText frameLabel = new BitmapText(bigFont);
    frameLabel.setText("Total Frame Time: ");
    ui.attachChild(frameLabel);
    frameLabel.setLocalTranslation(new Vector3f(PANEL_WIDTH / 2 - bigFont.getLineWidth(frameLabel.getText()), -PADDING, 0));

    BitmapText cpuLabel = new BitmapText(bigFont);
    cpuLabel.setText("CPU");
    ui.attachChild(cpuLabel);
    cpuLabel.setLocalTranslation(PANEL_WIDTH / 4 - bigFont.getLineWidth(cpuLabel.getText()) / 2, -PADDING - 30, 0);

    BitmapText gpuLabel = new BitmapText(bigFont);
    gpuLabel.setText("GPU");
    ui.attachChild(gpuLabel);
    gpuLabel.setLocalTranslation(3 * PANEL_WIDTH / 4 - bigFont.getLineWidth(gpuLabel.getText()) / 2, -PADDING - 30, 0);

    frameTimeValue = new BitmapText(bigFont);
    frameCpuTimeValue = new BitmapText(bigFont);
    frameGpuTimeValue = new BitmapText(bigFont);

    selectedField = new BitmapText(font);
    selectedField.setText("Selected: ");
    selectedField.setLocalTranslation(PANEL_WIDTH / 2, -PADDING - 75, 0);
    selectedField.setColor(ColorRGBA.Yellow);


    ui.attachChild(frameTimeValue);
    ui.attachChild(frameCpuTimeValue);
    ui.attachChild(frameGpuTimeValue);
    ui.attachChild(selectedField);

    hideInsignificantField = new BitmapText(font);
    hideInsignificantField.setText("O " + INSIGNIFICANT);
    hideInsignificantField.setLocalTranslation(PADDING, -PADDING - 75, 0);
    ui.attachChild(hideInsignificantField);

    final InputManager inputManager = app.getInputManager();
    if (inputManager != null) {
        inputManager.addMapping(TOGGLE_KEY, new KeyTrigger(KeyInput.KEY_F6));
        inputManager.addMapping(CLICK_KEY, new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
        inputManager.addListener(inputListener, TOGGLE_KEY, CLICK_KEY);
    }
}
 
Example 6
Source File: TestComboMoves.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    fpsText.setCullHint(CullHint.Always);
    statsView.setCullHint(CullHint.Always);

    // Create debug text
    BitmapText helpText = new BitmapText(guiFont);
    helpText.setLocalTranslation(0, settings.getHeight(), 0);
    helpText.setText("Moves:\n" +
                     "Fireball: Down, Down+Right, Right\n"+
                     "Shuriken: Left, Down, Attack1(Z)\n"+
                     "Jab: Attack1(Z)\n"+
                     "Punch: Attack1(Z), Attack1(Z)\n");
    guiNode.attachChild(helpText);

    fireballText = new BitmapText(guiFont);
    fireballText.setColor(ColorRGBA.Orange);
    fireballText.setLocalTranslation(0, fireballText.getLineHeight(), 0);
    guiNode.attachChild(fireballText);

    shurikenText = new BitmapText(guiFont);
    shurikenText.setColor(ColorRGBA.Cyan);
    shurikenText.setLocalTranslation(0, shurikenText.getLineHeight()*2f, 0);
    guiNode.attachChild(shurikenText);

    jabText = new BitmapText(guiFont);
    jabText.setColor(ColorRGBA.Red);
    jabText.setLocalTranslation(0, jabText.getLineHeight()*3f, 0);
    guiNode.attachChild(jabText);

    punchText = new BitmapText(guiFont);
    punchText.setColor(ColorRGBA.Green);
    punchText.setLocalTranslation(0, punchText.getLineHeight()*4f, 0);
    guiNode.attachChild(punchText);

    inputManager.addMapping("Left",    new KeyTrigger(KeyInput.KEY_LEFT));
    inputManager.addMapping("Right",   new KeyTrigger(KeyInput.KEY_RIGHT));
    inputManager.addMapping("Up",      new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping("Down",    new KeyTrigger(KeyInput.KEY_DOWN));
    inputManager.addMapping("Attack1", new KeyTrigger(KeyInput.KEY_Z));
    inputManager.addListener(this, "Left", "Right", "Up", "Down", "Attack1");

    fireball = new ComboMove("Fireball");
    fireball.press("Down").notPress("Right").done();
    fireball.press("Right", "Down").done();
    fireball.press("Right").notPress("Down").done();
    fireball.notPress("Right", "Down").done();
    fireball.setUseFinalState(false); // no waiting on final state

    shuriken = new ComboMove("Shuriken");
    shuriken.press("Left").notPress("Down", "Attack1").done();
    shuriken.press("Down").notPress("Attack1").timeElapsed(0.11f).done();
    shuriken.press("Attack1").notPress("Left").timeElapsed(0.11f).done();
    shuriken.notPress("Left", "Down", "Attack1").done();

    jab = new ComboMove("Jab");
    jab.setPriority(0.5f); // make jab less important than other moves
    jab.press("Attack1").done();

    punch = new ComboMove("Punch");
    punch.press("Attack1").done();
    punch.notPress("Attack1").done();
    punch.press("Attack1").done();

    fireballExec = new ComboMoveExecution(fireball);
    shurikenExec = new ComboMoveExecution(shuriken);
    jabExec = new ComboMoveExecution(jab);
    punchExec = new ComboMoveExecution(punch);
}