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

The following examples show how to use com.jme3.font.BitmapText#setText() . 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: TestBitmapFont.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    inputManager.addMapping("WordWrap", new KeyTrigger(KeyInput.KEY_TAB));
    inputManager.addListener(keyListener, "WordWrap");
    inputManager.addRawInputListener(textListener);

    BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
    txt = new BitmapText(fnt, false);
    txt.setBox(new Rectangle(0, 0, settings.getWidth(), settings.getHeight()));
    txt.setSize(fnt.getPreferredSize() * 2f);
    txt.setText(txtB);
    txt.setLocalTranslation(0, txt.getHeight(), 0);
    guiNode.attachChild(txt);

    txt2 = new BitmapText(fnt, false);
    txt2.setSize(fnt.getPreferredSize() * 1.2f);
    txt2.setText("Text without restriction. \nText without restriction. Text without restriction. Text without restriction");
    txt2.setLocalTranslation(0, txt2.getHeight(), 0);
    guiNode.attachChild(txt2);

    txt3 = new BitmapText(fnt, false);
    txt3.setBox(new Rectangle(0, 0, settings.getWidth(), 0));
    txt3.setText("Press Tab to toggle word-wrap. type text and enter to input text");
    txt3.setLocalTranslation(0, settings.getHeight()/2, 0);
    guiNode.attachChild(txt3);
}
 
Example 2
Source File: TestBitmapFont.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    inputManager.addMapping("WordWrap", new KeyTrigger(KeyInput.KEY_TAB));
    inputManager.addListener(keyListener, "WordWrap");
    inputManager.addRawInputListener(textListener);
    
    BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
    txt = new BitmapText(fnt, false);
    txt.setBox(new Rectangle(0, 0, settings.getWidth(), settings.getHeight()));
    txt.setSize(fnt.getPreferredSize() * 2f);
    txt.setText(txtB);
    txt.setLocalTranslation(0, txt.getHeight(), 0);
    guiNode.attachChild(txt);

    txt2 = new BitmapText(fnt, false);
    txt2.setSize(fnt.getPreferredSize() * 1.2f);
    txt2.setText("Text without restriction. \nText without restriction. Text without restriction. Text without restriction");
    txt2.setLocalTranslation(0, txt2.getHeight(), 0);
    guiNode.attachChild(txt2);
    
    txt3 = new BitmapText(fnt, false);
    txt3.setBox(new Rectangle(0, 0, settings.getWidth(), 0));
    txt3.setText("Press Tab to toggle word-wrap. type text and enter to input text");
    txt3.setLocalTranslation(0, settings.getHeight()/2, 0);
    guiNode.attachChild(txt3);
}
 
Example 3
Source File: HelloPhysics.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** A plus sign used as crosshairs to help the player with aiming.*/
protected void initCrossHairs() {
  setDisplayStatView(false);
  //guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
  BitmapText ch = new BitmapText(guiFont, false);
  ch.setSize(guiFont.getCharSet().getRenderedSize() * 2);
  ch.setText("+");        // fake crosshairs :)
  ch.setLocalTranslation( // center
    settings.getWidth() / 2,
    settings.getHeight() / 2, 0);
  guiNode.attachChild(ch);
}
 
Example 4
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 5
Source File: HelloOpenCL.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
    Context clContext = context.getOpenCLContext();
    if (clContext == null) {
        BitmapText txt = new BitmapText(fnt);
        txt.setText("No OpenCL Context created!\nSee output log for details.");
        txt.setLocalTranslation(5, settings.getHeight() - 5, 0);
        guiNode.attachChild(txt);
        return;
    }
    CommandQueue clQueue = clContext.createQueue();
    
    StringBuilder str = new StringBuilder();
    str.append("OpenCL Context created:\n  Platform: ")
            .append(clContext.getDevices().get(0).getPlatform().getName())
            .append("\n  Devices: ").append(clContext.getDevices());
    str.append("\nTests:");
    str.append("\n  Buffers: ").append(testBuffer(clContext, clQueue));
    str.append("\n  Kernel: ").append(testKernel(clContext, clQueue));
    str.append("\n  Images: ").append(testImages(clContext, clQueue));
    
    clQueue.release();
    
    BitmapText txt1 = new BitmapText(fnt);
    txt1.setText(str.toString());
    txt1.setLocalTranslation(5, settings.getHeight() - 5, 0);
    guiNode.attachChild(txt1);
    
    flyCam.setEnabled(false);
    inputManager.setCursorVisible(true);
}
 
Example 6
Source File: TerrainTestCollision.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void loadHintText() {
    hintText = new BitmapText(guiFont, false);
    hintText.setSize(guiFont.getCharSet().getRenderedSize());
    hintText.setLocalTranslation(0, getCamera().getHeight(), 0);
    //hintText.setText("Hit T to switch to wireframe");
    hintText.setText("");
    guiNode.attachChild(hintText);
}
 
Example 7
Source File: TestBatchNodeTower.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected void initCrossHairs() {
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    BitmapText ch = new BitmapText(guiFont, false);
    ch.setSize(guiFont.getCharSet().getRenderedSize() * 2);
    ch.setText("+"); // crosshairs
    ch.setLocalTranslation( // center
            settings.getWidth() / 2 - guiFont.getCharSet().getRenderedSize() / 3 * 2,
            settings.getHeight() / 2 + ch.getLineHeight() / 2, 0);
    guiNode.attachChild(ch);
}
 
Example 8
Source File: HelloAssets.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {

    /** Load a teapot model (OBJ file from test-data) */
    Spatial teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    Material mat_default = new Material( assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
    teapot.setMaterial(mat_default);
    rootNode.attachChild(teapot);

    /** Create a wall (Box with material and texture from test-data) */
    Box box = new Box(Vector3f.ZERO, 2.5f,2.5f,1.0f);
    Spatial wall = new Geometry("Box", box );
    Material mat_brick = new Material( assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat_brick.setTexture("ColorMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
    wall.setMaterial(mat_brick);
    wall.setLocalTranslation(2.0f,-2.5f,0.0f);
    rootNode.attachChild(wall);

    /** Display a line of text (default font from test-data) */
    guiNode.detachAllChildren();
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    BitmapText helloText = new BitmapText(guiFont, false);
    helloText.setSize(guiFont.getCharSet().getRenderedSize());
    helloText.setText("Hello World");
    helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
    guiNode.attachChild(helloText);

    /** Load a Ninja model (OgreXML + material + texture from test_data) */
    Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
    ninja.scale(0.05f, 0.05f, 0.05f);
    ninja.rotate(0.0f, -3.0f, 0.0f);
    ninja.setLocalTranslation(0.0f, -5.0f, -2.0f);
    rootNode.attachChild(ninja);
    /** You must add a light to make the model visible */
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
    rootNode.addLight(sun);
}
 
Example 9
Source File: TestBatchedTower.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected void initCrossHairs() {
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    BitmapText ch = new BitmapText(guiFont, false);
    ch.setSize(guiFont.getCharSet().getRenderedSize() * 2);
    ch.setText("+"); // crosshairs
    ch.setLocalTranslation( // center
            settings.getWidth() / 2 - guiFont.getCharSet().getRenderedSize() / 3 * 2,
            settings.getHeight() / 2 + ch.getLineHeight() / 2, 0);
    guiNode.attachChild(ch);
}
 
Example 10
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 11
Source File: TerrainTestAndroid.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void loadHintText() {
    hintText = new BitmapText(guiFont, false);
    hintText.setSize(guiFont.getCharSet().getRenderedSize());
    hintText.setLocalTranslation(0, getCamera().getHeight(), 0);
    hintText.setText("Press T to toggle wireframe,  P to toggle tri-planar texturing");
    guiNode.attachChild(hintText);
}
 
Example 12
Source File: SimpleApplication.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Attaches FPS statistics to guiNode and displays it on the screen.
 *
 */
public void loadFPSText() {
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    fpsText = new BitmapText(guiFont, false);
    fpsText.setLocalTranslation(0, fpsText.getLineHeight(), 0);
    fpsText.setText("Frames per second");
    guiNode.attachChild(fpsText);
}
 
Example 13
Source File: TerrainTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void loadHintText() {
    hintText = new BitmapText(guiFont, false);
    hintText.setSize(guiFont.getCharSet().getRenderedSize());
    hintText.setLocalTranslation(0, getCamera().getHeight(), 0);
    hintText.setText("Press T to toggle wireframe,  P to toggle tri-planar texturing");
    guiNode.attachChild(hintText);
}
 
Example 14
Source File: TestBrickTower.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void initCrossHairs() {
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    BitmapText ch = new BitmapText(guiFont, false);
    ch.setSize(guiFont.getCharSet().getRenderedSize() * 2);
    ch.setText("+"); // crosshairs
    ch.setLocalTranslation( // center
            settings.getWidth() / 2 - guiFont.getCharSet().getRenderedSize() / 3 * 2,
            settings.getHeight() / 2 + ch.getLineHeight() / 2, 0);
    guiNode.attachChild(ch);
}
 
Example 15
Source File: TerrainTestAndroid.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void loadHintText() {
    hintText = new BitmapText(guiFont, false);
    hintText.setSize(guiFont.getCharSet().getRenderedSize());
    hintText.setLocalTranslation(0, getCamera().getHeight(), 0);
    hintText.setText("Hit T to switch to wireframe,  P to switch to tri-planar texturing");
    guiNode.attachChild(hintText);
}
 
Example 16
Source File: TerrainTestCollision.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void loadHintText() {
    hintText = new BitmapText(guiFont, false);
    hintText.setSize(guiFont.getCharSet().getRenderedSize());
    hintText.setLocalTranslation(0, getCamera().getHeight(), 0);
    hintText.setText("Press T to toggle wireframe");
    guiNode.attachChild(hintText);
}
 
Example 17
Source File: MyDebugger.java    From OpenRTS with MIT License 4 votes vote down vote up
public MyDebugger(int x, int y, BitmapFont font) {
	bitmap = new BitmapText(font, false);
	bitmap.setLocalTranslation(x, y, 0);
	bitmap.setText("");
}
 
Example 18
Source File: TerrainTestModifyHeight.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void loadHintText() {
    hintText = new BitmapText(guiFont, false);
    hintText.setLocalTranslation(0, getCamera().getHeight(), 0);
    hintText.setText("Hit 1 to raise terrain, hit 2 to lower terrain");
    guiNode.attachChild(hintText);
}
 
Example 19
Source File: TestPhysicsRayCast.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void initCrossHair() {
    BitmapText bitmapText = new BitmapText(guiFont);
    bitmapText.setText("+");
    bitmapText.setLocalTranslation((settings.getWidth() - bitmapText.getLineWidth())*0.5f, (settings.getHeight() + bitmapText.getLineHeight())*0.5f, 0);
    guiNode.attachChild(bitmapText);
}
 
Example 20
Source File: TestMultipleApplications.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    clContext = context.getOpenCLContext();
    if (clContext == null) {
        LOG.severe("No OpenCL context found");
        stop();
        return;
    }
    Device device = clContext.getDevices().get(0);
    clQueue = clContext.createQueue(device);
    clQueue.register();
    
    String source = ""
            + "__kernel void Fill(__global float* vb, float v)\n"
            + "{\n"
            + "  int idx = get_global_id(0);\n"
            + "  vb[idx] = v;\n"
            + "}\n";
    Program program = clContext.createProgramFromSourceCode(source);
    program.build();
    program.register();
    kernel = program.createKernel("Fill");
    kernel.register();
    
    buffer = clContext.createBuffer(4);
    buffer.register();
    
    flyCam.setEnabled(false);
    inputManager.setCursorVisible(true);
    
    BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
    infoText = new BitmapText(fnt, false);
    //infoText.setBox(new Rectangle(0, 0, settings.getWidth(), settings.getHeight()));
    infoText.setText("Device: "+clContext.getDevices());
    infoText.setLocalTranslation(0, settings.getHeight(), 0);
    guiNode.attachChild(infoText);
    statusText = new BitmapText(fnt, false);
    //statusText.setBox(new Rectangle(0, 0, settings.getWidth(), settings.getHeight()));
    statusText.setText("Running");
    statusText.setLocalTranslation(0, settings.getHeight() - infoText.getHeight() - 2, 0);
    guiNode.attachChild(statusText);
}