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

The following examples show how to use com.jme3.font.BitmapText#setBox() . 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: TestObjGroupsLoading.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {

    // load scene with following structure:
    // Chair 1 (just mesh without name) and named groups: Chair 2, Pillow 2, Podium
    Spatial scene = assetManager.loadModel(new ModelKey("OBJLoaderTest/TwoChairs.obj"));
    // add light to make it visible
    scene.addLight(new AmbientLight(ColorRGBA.White));
    // attach scene to the root
    rootNode.attachChild(scene);
    
    // configure camera for best scene viewing
    cam.setLocation(new Vector3f(-3, 4, 3));
    cam.lookAtDirection(new Vector3f(0, -0.5f, -1), Vector3f.UNIT_Y);
    flyCam.setMoveSpeed(10);
    
    // create display to indicate pointed geometry name
    pointerDisplay = new BitmapText(guiFont);
    pointerDisplay.setBox(new Rectangle(0, settings.getHeight(), settings.getWidth(), settings.getHeight()/2));
    pointerDisplay.setAlignment(BitmapFont.Align.Center);
    pointerDisplay.setVerticalAlignment(BitmapFont.VAlign.Center);
    guiNode.attachChild(pointerDisplay);
    
    initCrossHairs();
}
 
Example 2
Source File: TestBitmapText3D.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    Quad q = new Quad(6, 3);
    Geometry g = new Geometry("quad", q);
    g.setLocalTranslation(0, -3, -0.0001f);
    g.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    rootNode.attachChild(g);

    BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
    BitmapText txt = new BitmapText(fnt, false);
    txt.setBox(new Rectangle(0, 0, 6, 3));
    txt.setQueueBucket(Bucket.Transparent);
    txt.setSize( 0.5f );
    txt.setText(txtB);
    rootNode.attachChild(txt);
}
 
Example 3
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 4
Source File: TestImageRaster.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void convertAndPutImage(Image image, float posX, float posY) {
    Texture tex = new Texture2D(image);
    tex.setMagFilter(MagFilter.Nearest);
    tex.setMinFilter(MinFilter.NearestNoMipMaps);
    tex.setAnisotropicFilter(16);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", tex);

    Quad q = new Quad(5, 5);
    Geometry g = new Geometry("quad", q);
    g.setLocalTranslation(posX, posY - 5, -0.0001f);
    g.setMaterial(mat);
    rootNode.attachChild(g);

    BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
    BitmapText txt = new BitmapText(fnt);
    txt.setBox(new Rectangle(0, 0, 5, 5));
    txt.setQueueBucket(RenderQueue.Bucket.Transparent);
    txt.setSize(0.5f);
    txt.setText(image.getFormat().name());
    txt.setLocalTranslation(posX, posY, 0);
    rootNode.attachChild(txt);
}
 
Example 5
Source File: TestBitmapText3D.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    Quad q = new Quad(6, 3);
    Geometry g = new Geometry("quad", q);
    g.setLocalTranslation(0, -3, -0.0001f);
    g.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    rootNode.attachChild(g);

    BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
    BitmapText txt = new BitmapText(fnt, false);
    txt.setBox(new Rectangle(0, 0, 6, 3));
    txt.setQueueBucket(Bucket.Transparent);
    txt.setSize( 0.5f );
    txt.setText(txtB);
    rootNode.attachChild(txt);
}
 
Example 6
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 7
Source File: TestRtlBitmapText.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");
    // A right to left BitmapText
    BitmapText txt = new BitmapText(fnt, true);
    txt.setBox(new Rectangle(0, 0, 150, 0));
    txt.setLineWrapMode(LineWrapMode.Word);
    txt.setAlignment(BitmapFont.Align.Right);
    txt.setText(text);
    txt.setLocalTranslation(cam.getWidth() / 2, cam.getHeight() / 2, 0);
    guiNode.attachChild(txt);
}
 
Example 8
Source File: TestBitmapFontAlignment.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    int width = getCamera().getWidth();
    int height = getCamera().getHeight();

    // VAlign.Top
    BitmapText labelAlignTop = guiFont.createLabel("This text has VAlign.Top.");
    Rectangle textboxAlignTop = new Rectangle(width * 0.2f, height * 0.7f, 120, 120);
    labelAlignTop.setBox(textboxAlignTop);
    labelAlignTop.setVerticalAlignment(BitmapFont.VAlign.Top);
    getGuiNode().attachChild(labelAlignTop);

    Geometry backgroundBoxAlignTop = new Geometry("", new Quad(textboxAlignTop.width, -textboxAlignTop.height));
    Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    material.setColor("Color", ColorRGBA.Blue);
    backgroundBoxAlignTop.setMaterial(material);
    backgroundBoxAlignTop.setLocalTranslation(textboxAlignTop.x, textboxAlignTop.y, -1);
    getGuiNode().attachChild(backgroundBoxAlignTop);

    // VAlign.Center
    BitmapText labelAlignCenter = guiFont.createLabel("This text has VAlign.Center");
    Rectangle textboxAlignCenter = new Rectangle(width * 0.4f, height * 0.7f, 120, 120);
    labelAlignCenter.setBox(textboxAlignCenter);
    labelAlignCenter.setVerticalAlignment(BitmapFont.VAlign.Center);
    getGuiNode().attachChild(labelAlignCenter);

    Geometry backgroundBoxAlignCenter = backgroundBoxAlignTop.clone(false);
    backgroundBoxAlignCenter.setLocalTranslation(textboxAlignCenter.x, textboxAlignCenter.y, -1);
    getGuiNode().attachChild(backgroundBoxAlignCenter);

    // VAlign.Bottom
    BitmapText labelAlignBottom = guiFont.createLabel("This text has VAlign.Bottom");
    Rectangle textboxAlignBottom = new Rectangle(width * 0.6f, height * 0.7f, 120, 120);
    labelAlignBottom.setBox(textboxAlignBottom);
    labelAlignBottom.setVerticalAlignment(BitmapFont.VAlign.Bottom);
    getGuiNode().attachChild(labelAlignBottom);

    Geometry backgroundBoxAlignBottom = backgroundBoxAlignTop.clone(false);
    backgroundBoxAlignBottom.setLocalTranslation(textboxAlignBottom.x, textboxAlignBottom.y, -1);
    getGuiNode().attachChild(backgroundBoxAlignBottom);

    // VAlign.Top + Align.Right
    BitmapText labelAlignTopRight = guiFont.createLabel("This text has VAlign.Top and Align.Right");
    Rectangle textboxAlignTopRight = new Rectangle(width * 0.2f, height * 0.3f, 120, 120);
    labelAlignTopRight.setBox(textboxAlignTopRight);
    labelAlignTopRight.setVerticalAlignment(BitmapFont.VAlign.Top);
    labelAlignTopRight.setAlignment(BitmapFont.Align.Right);
    getGuiNode().attachChild(labelAlignTopRight);

    Geometry backgroundBoxAlignTopRight = backgroundBoxAlignTop.clone(false);
    backgroundBoxAlignTopRight.setLocalTranslation(textboxAlignTopRight.x, textboxAlignTopRight.y, -1);
    getGuiNode().attachChild(backgroundBoxAlignTopRight);

    // VAlign.Center + Align.Center
    BitmapText labelAlignCenterCenter = guiFont.createLabel("This text has VAlign.Center and Align.Center");
    Rectangle textboxAlignCenterCenter = new Rectangle(width * 0.4f, height * 0.3f, 120, 120);
    labelAlignCenterCenter.setBox(textboxAlignCenterCenter);
    labelAlignCenterCenter.setVerticalAlignment(BitmapFont.VAlign.Center);
    labelAlignCenterCenter.setAlignment(BitmapFont.Align.Center);
    getGuiNode().attachChild(labelAlignCenterCenter);

    Geometry backgroundBoxAlignCenterCenter = backgroundBoxAlignCenter.clone(false);
    backgroundBoxAlignCenterCenter.setLocalTranslation(textboxAlignCenterCenter.x, textboxAlignCenterCenter.y, -1);
    getGuiNode().attachChild(backgroundBoxAlignCenterCenter);

    // VAlign.Bottom + Align.Left
    BitmapText labelAlignBottomLeft = guiFont.createLabel("This text has VAlign.Bottom and Align.Left");
    Rectangle textboxAlignBottomLeft = new Rectangle(width * 0.6f, height * 0.3f, 120, 120);
    labelAlignBottomLeft.setBox(textboxAlignBottomLeft);
    labelAlignBottomLeft.setVerticalAlignment(BitmapFont.VAlign.Bottom);
    labelAlignBottomLeft.setAlignment(BitmapFont.Align.Left);
    getGuiNode().attachChild(labelAlignBottomLeft);

    Geometry backgroundBoxAlignBottomLeft = backgroundBoxAlignBottom.clone(false);
    backgroundBoxAlignBottomLeft.setLocalTranslation(textboxAlignBottomLeft.x, textboxAlignBottomLeft.y, -1);
    getGuiNode().attachChild(backgroundBoxAlignBottomLeft);

    // Large quad with VAlign.Center and Align.Center
    BitmapText label = guiFont.createLabel("This text is centered, both horizontally and vertically.");
    Rectangle box = new Rectangle(width * 0.05f, height * 0.95f, width * 0.9f, height * 0.1f);
    label.setBox(box);
    label.setAlignment(BitmapFont.Align.Center);
    label.setVerticalAlignment(BitmapFont.VAlign.Center);
    getGuiNode().attachChild(label);

    Geometry background = new Geometry("background", new Quad(box.width, -box.height));
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Green);
    background.setMaterial(mat);
    background.setLocalTranslation(box.x, box.y, -1);
    getGuiNode().attachChild(background);
}