* Prevent stream closed exception when playing OGG music * Prevent UnsatisfiedLinkError when using audio effects on Mac * Add BitmapText caching to Nifty GUI. May improve FPS in guis with lots of text elements git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8237 75d07b2b-3a1a-0410-a2c5-0572b91ccdca3.0
parent
5ac90f46fa
commit
64c61c86e4
@ -1,109 +1,113 @@ |
|||||||
/* |
/* |
||||||
* Copyright (c) 2009-2010 jMonkeyEngine |
* Copyright (c) 2009-2010 jMonkeyEngine |
||||||
* All rights reserved. |
* All rights reserved. |
||||||
* |
* |
||||||
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
||||||
* modification, are permitted provided that the following conditions are |
* modification, are permitted provided that the following conditions are |
||||||
* met: |
* met: |
||||||
* |
* |
||||||
* * Redistributions of source code must retain the above copyright |
* * Redistributions of source code must retain the above copyright |
||||||
* notice, this list of conditions and the following disclaimer. |
* notice, this list of conditions and the following disclaimer. |
||||||
* |
* |
||||||
* * Redistributions in binary form must reproduce the above copyright |
* * Redistributions in binary form must reproduce the above copyright |
||||||
* notice, this list of conditions and the following disclaimer in the |
* notice, this list of conditions and the following disclaimer in the |
||||||
* documentation and/or other materials provided with the distribution. |
* documentation and/or other materials provided with the distribution. |
||||||
* |
* |
||||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors |
||||||
* may be used to endorse or promote products derived from this software |
* may be used to endorse or promote products derived from this software |
||||||
* without specific prior written permission. |
* without specific prior written permission. |
||||||
* |
* |
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
||||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
||||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
||||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
||||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
||||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||||
*/ |
*/ |
||||||
|
|
||||||
package com.jme3.niftygui; |
package com.jme3.niftygui; |
||||||
|
|
||||||
import com.jme3.font.BitmapFont; |
import com.jme3.font.BitmapFont; |
||||||
import com.jme3.font.BitmapText; |
import com.jme3.font.BitmapText; |
||||||
import de.lessvoid.nifty.spi.render.RenderFont; |
import de.lessvoid.nifty.spi.render.RenderFont; |
||||||
|
|
||||||
public class RenderFontJme implements RenderFont { |
public class RenderFontJme implements RenderFont { |
||||||
|
|
||||||
private NiftyJmeDisplay display; |
private NiftyJmeDisplay display; |
||||||
private BitmapFont font; |
private BitmapFont font; |
||||||
private BitmapText text; |
private BitmapText text; |
||||||
private float actualSize; |
private float actualSize; |
||||||
|
|
||||||
/** |
/** |
||||||
* Initialize the font. |
* Initialize the font. |
||||||
* @param name font filename |
* @param name font filename |
||||||
*/ |
*/ |
||||||
public RenderFontJme(String name, NiftyJmeDisplay display) { |
public RenderFontJme(String name, NiftyJmeDisplay display) { |
||||||
this.display = display; |
this.display = display; |
||||||
font = display.getAssetManager().loadFont(name); |
font = display.getAssetManager().loadFont(name); |
||||||
if (font == null) { |
if (font == null) { |
||||||
throw new RuntimeException( "Font not loaded:" + name ); |
throw new RuntimeException( "Font not loaded:" + name ); |
||||||
} |
} |
||||||
text = new BitmapText(font); |
text = new BitmapText(font); |
||||||
actualSize = font.getPreferredSize(); |
actualSize = font.getPreferredSize(); |
||||||
text.setSize(actualSize); |
text.setSize(actualSize); |
||||||
} |
} |
||||||
|
|
||||||
public BitmapText getText(){ |
public BitmapText createText() { |
||||||
return text; |
return new BitmapText(font); |
||||||
} |
} |
||||||
|
|
||||||
/** |
public BitmapText getText(){ |
||||||
* get font height. |
return text; |
||||||
* @return height |
} |
||||||
*/ |
|
||||||
public int getHeight() { |
/** |
||||||
return (int) text.getLineHeight(); |
* get font height. |
||||||
} |
* @return height |
||||||
|
*/ |
||||||
/** |
public int getHeight() { |
||||||
* get font width of the given string. |
return (int) text.getLineHeight(); |
||||||
* @param text text |
} |
||||||
* @return width of the given text for the current font |
|
||||||
*/ |
/** |
||||||
public int getWidth(final String str) { |
* get font width of the given string. |
||||||
if (str.length() == 0) |
* @param text text |
||||||
return 0; |
* @return width of the given text for the current font |
||||||
|
*/ |
||||||
// Note: BitmapFont is now fixed to return the proper line width
|
public int getWidth(final String str) { |
||||||
// at least for now. The older commented out (by someone else, not me)
|
if (str.length() == 0) |
||||||
// code below is arguably 'more accurate' if BitmapFont gets
|
return 0; |
||||||
// buggy again. The issue is that the BitmapText and BitmapFont
|
|
||||||
// use a different algorithm for calculating size and both must
|
// Note: BitmapFont is now fixed to return the proper line width
|
||||||
// be modified in sync.
|
// at least for now. The older commented out (by someone else, not me)
|
||||||
int result = (int) font.getLineWidth(str); |
// code below is arguably 'more accurate' if BitmapFont gets
|
||||||
// text.setText(str);
|
// buggy again. The issue is that the BitmapText and BitmapFont
|
||||||
// text.updateLogicalState(0);
|
// use a different algorithm for calculating size and both must
|
||||||
// int result = (int) text.getLineWidth();
|
// be modified in sync.
|
||||||
|
int result = (int) font.getLineWidth(str); |
||||||
return result; |
// text.setText(str);
|
||||||
} |
// text.updateLogicalState(0);
|
||||||
|
// int result = (int) text.getLineWidth();
|
||||||
/** |
|
||||||
* Return the width of the given character including kerning information. |
return result; |
||||||
* @param currentCharacter current character |
} |
||||||
* @param nextCharacter next character |
|
||||||
* @param size font size |
/** |
||||||
* @return width of the character or null when no information for the character is available |
* Return the width of the given character including kerning information. |
||||||
*/ |
* @param currentCharacter current character |
||||||
public Integer getCharacterAdvance(final char currentCharacter, final char nextCharacter, final float size) { |
* @param nextCharacter next character |
||||||
return Integer.valueOf( Math.round(font.getCharacterAdvance(currentCharacter, nextCharacter, size)) ); |
* @param size font size |
||||||
} |
* @return width of the character or null when no information for the character is available |
||||||
|
*/ |
||||||
public void dispose() { |
public Integer getCharacterAdvance(final char currentCharacter, final char nextCharacter, final float size) { |
||||||
} |
return Integer.valueOf( Math.round(font.getCharacterAdvance(currentCharacter, nextCharacter, size)) ); |
||||||
} |
} |
||||||
|
|
||||||
|
public void dispose() { |
||||||
|
} |
||||||
|
} |
||||||
|
Loading…
Reference in new issue