Formatted code of RenderDeviceJme before comming changes
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9231 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
e275cfb7ee
commit
6087a930df
@ -29,7 +29,6 @@
|
|||||||
* 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.BitmapText;
|
import com.jme3.font.BitmapText;
|
||||||
@ -64,26 +63,21 @@ public class RenderDeviceJme implements RenderDevice {
|
|||||||
private NiftyJmeDisplay display;
|
private NiftyJmeDisplay display;
|
||||||
private RenderManager rm;
|
private RenderManager rm;
|
||||||
private Renderer r;
|
private Renderer r;
|
||||||
|
|
||||||
private HashMap<String, BitmapText> textCacheLastFrame = new HashMap<String, BitmapText>();
|
private HashMap<String, BitmapText> textCacheLastFrame = new HashMap<String, BitmapText>();
|
||||||
private HashMap<String, BitmapText> textCacheCurrentFrame = new HashMap<String, BitmapText>();
|
private HashMap<String, BitmapText> textCacheCurrentFrame = new HashMap<String, BitmapText>();
|
||||||
|
|
||||||
private final Quad quad = new Quad(1, -1, true);
|
private final Quad quad = new Quad(1, -1, true);
|
||||||
private final Geometry quadGeom = new Geometry("nifty-quad", quad);
|
private final Geometry quadGeom = new Geometry("nifty-quad", quad);
|
||||||
private final Material niftyMat;
|
private final Material niftyMat;
|
||||||
private final Material niftyQuadMat;
|
private final Material niftyQuadMat;
|
||||||
|
|
||||||
private boolean clipWasSet = false;
|
private boolean clipWasSet = false;
|
||||||
private BlendMode blendMode = null;
|
private BlendMode blendMode = null;
|
||||||
|
|
||||||
private VertexBuffer quadDefaultTC = quad.getBuffer(Type.TexCoord);
|
private VertexBuffer quadDefaultTC = quad.getBuffer(Type.TexCoord);
|
||||||
private VertexBuffer quadModTC = quadDefaultTC.clone();
|
private VertexBuffer quadModTC = quadDefaultTC.clone();
|
||||||
private VertexBuffer quadColor;
|
private VertexBuffer quadColor;
|
||||||
|
|
||||||
private Matrix4f tempMat = new Matrix4f();
|
private Matrix4f tempMat = new Matrix4f();
|
||||||
private ColorRGBA tempColor = new ColorRGBA();
|
private ColorRGBA tempColor = new ColorRGBA();
|
||||||
|
|
||||||
public RenderDeviceJme(NiftyJmeDisplay display){
|
public RenderDeviceJme(NiftyJmeDisplay display) {
|
||||||
this.display = display;
|
this.display = display;
|
||||||
|
|
||||||
quadColor = new VertexBuffer(Type.Color);
|
quadColor = new VertexBuffer(Type.Color);
|
||||||
@ -103,23 +97,24 @@ public class RenderDeviceJme implements RenderDevice {
|
|||||||
public void setResourceLoader(NiftyResourceLoader niftyResourceLoader) {
|
public void setResourceLoader(NiftyResourceLoader niftyResourceLoader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRenderManager(RenderManager rm){
|
public void setRenderManager(RenderManager rm) {
|
||||||
this.rm = rm;
|
this.rm = rm;
|
||||||
this.r = rm.getRenderer();
|
this.r = rm.getRenderer();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Cursor support
|
// TODO: Cursor support
|
||||||
public MouseCursor createMouseCursor(String str, int x, int y){
|
public MouseCursor createMouseCursor(String str, int x, int y) {
|
||||||
return new MouseCursor() {
|
return new MouseCursor() {
|
||||||
|
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enableMouseCursor(MouseCursor cursor){
|
public void enableMouseCursor(MouseCursor cursor) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disableMouseCursor(){
|
public void disableMouseCursor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public RenderImage createImage(String filename, boolean linear) {
|
public RenderImage createImage(String filename, boolean linear) {
|
||||||
@ -154,36 +149,37 @@ public class RenderDeviceJme implements RenderDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setBlendMode(BlendMode blendMode) {
|
public void setBlendMode(BlendMode blendMode) {
|
||||||
if (this.blendMode != blendMode){
|
if (this.blendMode != blendMode) {
|
||||||
this.blendMode = blendMode;
|
this.blendMode = blendMode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private RenderState.BlendMode convertBlend(){
|
private RenderState.BlendMode convertBlend() {
|
||||||
if (blendMode == null)
|
if (blendMode == null) {
|
||||||
return RenderState.BlendMode.Off;
|
return RenderState.BlendMode.Off;
|
||||||
else if (blendMode == BlendMode.BLEND)
|
} else if (blendMode == BlendMode.BLEND) {
|
||||||
return RenderState.BlendMode.Alpha;
|
return RenderState.BlendMode.Alpha;
|
||||||
else if (blendMode == BlendMode.MULIPLY)
|
} else if (blendMode == BlendMode.MULIPLY) {
|
||||||
return RenderState.BlendMode.Modulate;
|
return RenderState.BlendMode.Modulate;
|
||||||
else
|
} else {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int convertColor(Color color){
|
private int convertColor(Color color) {
|
||||||
int color2 = 0;
|
int color2 = 0;
|
||||||
color2 |= ((int)(255.0 * color.getAlpha())) << 24;
|
color2 |= ((int) (255.0 * color.getAlpha())) << 24;
|
||||||
color2 |= ((int)(255.0 * color.getBlue())) << 16;
|
color2 |= ((int) (255.0 * color.getBlue())) << 16;
|
||||||
color2 |= ((int)(255.0 * color.getGreen())) << 8;
|
color2 |= ((int) (255.0 * color.getGreen())) << 8;
|
||||||
color2 |= ((int)(255.0 * color.getRed()));
|
color2 |= ((int) (255.0 * color.getRed()));
|
||||||
return color2;
|
return color2;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ColorRGBA convertColor(Color inColor, ColorRGBA outColor){
|
private ColorRGBA convertColor(Color inColor, ColorRGBA outColor) {
|
||||||
return outColor.set(inColor.getRed(), inColor.getGreen(), inColor.getBlue(), inColor.getAlpha());
|
return outColor.set(inColor.getRed(), inColor.getGreen(), inColor.getBlue(), inColor.getAlpha());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setColor(Color color){
|
private void setColor(Color color) {
|
||||||
ByteBuffer buf = (ByteBuffer) quadColor.getData();
|
ByteBuffer buf = (ByteBuffer) quadColor.getData();
|
||||||
buf.rewind();
|
buf.rewind();
|
||||||
|
|
||||||
@ -208,21 +204,23 @@ public class RenderDeviceJme implements RenderDevice {
|
|||||||
* @deprecated use renderFont(RenderFont font, String str, int x, int y, Color color, float sizeX, float sizeY) instead
|
* @deprecated use renderFont(RenderFont font, String str, int x, int y, Color color, float sizeX, float sizeY) instead
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void renderFont(RenderFont font, String str, int x, int y, Color color, float size){
|
public void renderFont(RenderFont font, String str, int x, int y, Color color, float size) {
|
||||||
renderFont(font, str, x, y, color, size, size);
|
renderFont(font, str, x, y, color, size, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderFont(RenderFont font, String str, int x, int y, Color color, float sizeX, float sizeY){
|
public void renderFont(RenderFont font, String str, int x, int y, Color color, float sizeX, float sizeY) {
|
||||||
if (str.length() == 0)
|
if (str.length() == 0) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (font instanceof RenderFontNull)
|
if (font instanceof RenderFontNull) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
RenderFontJme jmeFont = (RenderFontJme) font;
|
RenderFontJme jmeFont = (RenderFontJme) font;
|
||||||
|
|
||||||
String key = font+str+color.getColorString();
|
String key = font + str + color.getColorString();
|
||||||
BitmapText text = textCacheLastFrame.get(key);
|
BitmapText text = textCacheLastFrame.get(key);
|
||||||
if (text == null) {
|
if (text == null) {
|
||||||
text = jmeFont.createText();
|
text = jmeFont.createText();
|
||||||
@ -247,9 +245,9 @@ public class RenderDeviceJme implements RenderDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void renderImage(RenderImage image, int x, int y, int w, int h,
|
public void renderImage(RenderImage image, int x, int y, int w, int h,
|
||||||
int srcX, int srcY, int srcW, int srcH,
|
int srcX, int srcY, int srcW, int srcH,
|
||||||
Color color, float scale,
|
Color color, float scale,
|
||||||
int centerX, int centerY){
|
int centerX, int centerY) {
|
||||||
RenderImageJme jmeImage = (RenderImageJme) image;
|
RenderImageJme jmeImage = (RenderImageJme) image;
|
||||||
Texture2D texture = jmeImage.getTexture();
|
Texture2D texture = jmeImage.getTexture();
|
||||||
|
|
||||||
@ -258,22 +256,22 @@ public class RenderDeviceJme implements RenderDevice {
|
|||||||
niftyMat.setTexture("Texture", texture);
|
niftyMat.setTexture("Texture", texture);
|
||||||
setColor(color);
|
setColor(color);
|
||||||
|
|
||||||
float imageWidth = jmeImage.getWidth();
|
float imageWidth = jmeImage.getWidth();
|
||||||
float imageHeight = jmeImage.getHeight();
|
float imageHeight = jmeImage.getHeight();
|
||||||
FloatBuffer texCoords = (FloatBuffer) quadModTC.getData();
|
FloatBuffer texCoords = (FloatBuffer) quadModTC.getData();
|
||||||
|
|
||||||
float startX = srcX / imageWidth;
|
float startX = srcX / imageWidth;
|
||||||
float startY = srcY / imageHeight;
|
float startY = srcY / imageHeight;
|
||||||
float endX = startX + (srcW / imageWidth);
|
float endX = startX + (srcW / imageWidth);
|
||||||
float endY = startY + (srcH / imageHeight);
|
float endY = startY + (srcH / imageHeight);
|
||||||
|
|
||||||
startY = 1f - startY;
|
startY = 1f - startY;
|
||||||
endY = 1f - endY;
|
endY = 1f - endY;
|
||||||
|
|
||||||
texCoords.rewind();
|
texCoords.rewind();
|
||||||
texCoords.put(startX).put(startY);
|
texCoords.put(startX).put(startY);
|
||||||
texCoords.put(endX) .put(startY);
|
texCoords.put(endX).put(startY);
|
||||||
texCoords.put(endX) .put(endY);
|
texCoords.put(endX).put(endY);
|
||||||
texCoords.put(startX).put(endY);
|
texCoords.put(startX).put(endY);
|
||||||
texCoords.flip();
|
texCoords.flip();
|
||||||
quadModTC.updateData(texCoords);
|
quadModTC.updateData(texCoords);
|
||||||
@ -295,7 +293,7 @@ public class RenderDeviceJme implements RenderDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void renderImage(RenderImage image, int x, int y, int width, int height,
|
public void renderImage(RenderImage image, int x, int y, int width, int height,
|
||||||
Color color, float imageScale){
|
Color color, float imageScale) {
|
||||||
|
|
||||||
RenderImageJme jmeImage = (RenderImageJme) image;
|
RenderImageJme jmeImage = (RenderImageJme) image;
|
||||||
|
|
||||||
@ -307,7 +305,7 @@ public class RenderDeviceJme implements RenderDevice {
|
|||||||
quad.clearBuffer(Type.TexCoord);
|
quad.clearBuffer(Type.TexCoord);
|
||||||
quad.setBuffer(quadDefaultTC);
|
quad.setBuffer(quadDefaultTC);
|
||||||
|
|
||||||
float x0 = x + 0.5f * width * (1f - imageScale);
|
float x0 = x + 0.5f * width * (1f - imageScale);
|
||||||
float y0 = y + 0.5f * height * (1f - imageScale);
|
float y0 = y + 0.5f * height * (1f - imageScale);
|
||||||
|
|
||||||
tempMat.loadIdentity();
|
tempMat.loadIdentity();
|
||||||
@ -320,7 +318,7 @@ public class RenderDeviceJme implements RenderDevice {
|
|||||||
// System.out.println("renderImage");
|
// System.out.println("renderImage");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderQuad(int x, int y, int width, int height, Color color){
|
public void renderQuad(int x, int y, int width, int height, Color color) {
|
||||||
niftyQuadMat.getAdditionalRenderState().setBlendMode(convertBlend());
|
niftyQuadMat.getAdditionalRenderState().setBlendMode(convertBlend());
|
||||||
niftyQuadMat.setColor("Color", ColorRGBA.White);
|
niftyQuadMat.setColor("Color", ColorRGBA.White);
|
||||||
setColor(color);
|
setColor(color);
|
||||||
@ -336,7 +334,7 @@ public class RenderDeviceJme implements RenderDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void renderQuad(int x, int y, int width, int height,
|
public void renderQuad(int x, int y, int width, int height,
|
||||||
Color topLeft, Color topRight, Color bottomRight, Color bottomLeft) {
|
Color topLeft, Color topRight, Color bottomRight, Color bottomLeft) {
|
||||||
|
|
||||||
ByteBuffer buf = (ByteBuffer) quadColor.getData();
|
ByteBuffer buf = (ByteBuffer) quadColor.getData();
|
||||||
buf.rewind();
|
buf.rewind();
|
||||||
@ -363,7 +361,7 @@ public class RenderDeviceJme implements RenderDevice {
|
|||||||
// System.out.println("renderQuad (Grad)");
|
// System.out.println("renderQuad (Grad)");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enableClip(int x0, int y0, int x1, int y1){
|
public void enableClip(int x0, int y0, int x1, int y1) {
|
||||||
// System.out.println("enableClip");
|
// System.out.println("enableClip");
|
||||||
clipWasSet = true;
|
clipWasSet = true;
|
||||||
r.setClipRect(x0, getHeight() - y1, x1 - x0, y1 - y0);
|
r.setClipRect(x0, getHeight() - y1, x1 - x0, y1 - y0);
|
||||||
@ -371,12 +369,9 @@ public class RenderDeviceJme implements RenderDevice {
|
|||||||
|
|
||||||
public void disableClip() {
|
public void disableClip() {
|
||||||
// System.out.println("disableClip");
|
// System.out.println("disableClip");
|
||||||
if (clipWasSet){
|
if (clipWasSet) {
|
||||||
r.clearClipRect();
|
r.clearClipRect();
|
||||||
clipWasSet = false;
|
clipWasSet = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user