Upgrading GBUI to JME2.0

Here is a patch that will upgrade the latest GBUI svn version (http://gbui.googlecode.com/svn/trunk/) to JME2.0



Index: src/java/com/jmex/bui/text/JMEBitmapTextFactory.java
===================================================================
--- src/java/com/jmex/bui/text/JMEBitmapTextFactory.java   (revision 150)
+++ src/java/com/jmex/bui/text/JMEBitmapTextFactory.java   (working copy)
@@ -20,19 +20,21 @@
 
 package com.jmex.bui.text;
 
+import java.net.URL;
+
 import com.jme.image.Texture;
 import com.jme.math.Vector3f;
 import com.jme.renderer.ColorRGBA;
 import com.jme.renderer.Renderer;
 import com.jme.scene.Text;
-import com.jme.scene.state.AlphaState;
+import com.jme.scene.Spatial.CullHint;
+import com.jme.scene.Spatial.TextureCombineMode;
+import com.jme.scene.state.BlendState;
 import com.jme.scene.state.TextureState;
 import com.jme.system.DisplaySystem;
 import com.jme.util.TextureManager;
 import com.jmex.bui.util.Dimension;
 
-import java.net.URL;
-
 /**
  * Creates instances of {@link BText} for text rendering.
  */
@@ -48,7 +50,7 @@
 
         // create a texture from our font image
         Texture texture = TextureManager.loadTexture(
-                font, Texture.MM_NONE, Texture.FM_NEAREST);
+                font, Texture.MinificationFilter.BilinearNoMipMaps, Texture.MagnificationFilter.NearestNeighbor);
         _tstate = DisplaySystem.getDisplaySystem().getRenderer().
                 createTextureState();
         _tstate.setEnabled(true);
@@ -57,10 +59,10 @@
         // create an alpha state that we'll use to blend our font over the
         // background
         _astate = DisplaySystem.getDisplaySystem().getRenderer().
-                createAlphaState();
+                createBlendState();
         _astate.setBlendEnabled(true);
-        _astate.setSrcFunction(AlphaState.SB_SRC_ALPHA);
-        _astate.setDstFunction(AlphaState.DB_ONE);
+        _astate.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
+        _astate.setDestinationFunction(BlendState.DestinationFunction.One);
         _astate.setEnabled(true);
     }
 
@@ -81,8 +83,8 @@
 
         // create a text object to display it
         final Text tgeom = new Text("text", text);
-        tgeom.setCullMode(Text.CULL_NEVER);
-        tgeom.setTextureCombineMode(TextureState.REPLACE);
+        tgeom.setCullHint(CullHint.Never);
+        tgeom.setTextureCombineMode(TextureCombineMode.Replace);
         tgeom.setRenderState(_tstate);
         tgeom.setRenderState(_astate);
         tgeom.setTextColor(new ColorRGBA(color));
@@ -164,5 +166,5 @@
 
     protected int _width, _height;
     protected TextureState _tstate;
-    protected AlphaState _astate;
+    protected BlendState _astate;
 }
Index: src/java/com/jmex/bui/tests/TwoWindowTest.java
===================================================================
--- src/java/com/jmex/bui/tests/TwoWindowTest.java   (revision 150)
+++ src/java/com/jmex/bui/tests/TwoWindowTest.java   (working copy)
@@ -82,7 +82,7 @@
 
     public static void main(String[] args) {
         TwoWindowTest app = new TwoWindowTest();
-        app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
+        app.setConfigShowMode(ConfigShowMode.AlwaysShow);
         app.start();
     }
 
Index: src/java/com/jmex/bui/tests/LayoutTest.java
===================================================================
--- src/java/com/jmex/bui/tests/LayoutTest.java   (revision 150)
+++ src/java/com/jmex/bui/tests/LayoutTest.java   (working copy)
@@ -220,7 +220,7 @@
         ZBufferState zstate =
                 DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
         zstate.setEnabled(true);
-        zstate.setFunction(ZBufferState.CF_LESS);
+        zstate.setFunction(ZBufferState.TestFunction.LessThan);
 
         final Box box = new Box("box", new Vector3f(), 4, 4, 4);
         Quaternion quat45 = new Quaternion();
Index: src/java/com/jmex/bui/tests/GeomViewTest.java
===================================================================
--- src/java/com/jmex/bui/tests/GeomViewTest.java   (revision 150)
+++ src/java/com/jmex/bui/tests/GeomViewTest.java   (working copy)
@@ -64,7 +64,7 @@
     ZBufferState zBufferState = DisplaySystem.getDisplaySystem().getRenderer()
         .createZBufferState();
     zBufferState.setEnabled(true);
-    zBufferState.setFunction(ZBufferState.CF_LESS);
+    zBufferState.setFunction(ZBufferState.TestFunction.LessThan);
 
     Node n = new Node("blah");
     n.setRenderState(ls);
Index: src/java/com/jmex/bui/icon/ImageIcon.java
===================================================================
--- src/java/com/jmex/bui/icon/ImageIcon.java   (revision 150)
+++ src/java/com/jmex/bui/icon/ImageIcon.java   (working copy)
@@ -56,12 +56,12 @@
 
     // documentation inherited
     public int getWidth() {
-        return _image.getWidth();
+        return Math.round(_image.getWidth());
     }
 
     // documentation inherited
     public int getHeight() {
-        return _image.getHeight();
+        return Math.round(_image.getHeight());
     }
 
     // documentation inherited
Index: src/java/com/jmex/bui/BImage.java
===================================================================
--- src/java/com/jmex/bui/BImage.java   (revision 150)
+++ src/java/com/jmex/bui/BImage.java   (working copy)
@@ -20,34 +20,42 @@
 
 package com.jmex.bui;
 
+import java.awt.Graphics2D;
+import java.awt.geom.AffineTransform;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.net.URL;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.FloatBuffer;
+
+import javax.imageio.ImageIO;
+
+import org.lwjgl.opengl.GLContext;
+
 import com.jme.image.Image;
-import com.jme.image.Texture;
+import com.jme.image.Texture2D;
+import com.jme.image.Image.Format;
+import com.jme.image.Texture.MagnificationFilter;
+import com.jme.image.Texture.MinificationFilter;
 import com.jme.renderer.ColorRGBA;
 import com.jme.renderer.Renderer;
 import com.jme.scene.Spatial;
 import com.jme.scene.shape.Quad;
-import com.jme.scene.state.AlphaState;
-import com.jme.scene.state.RenderState;
+import com.jme.scene.state.BlendState;
 import com.jme.scene.state.TextureState;
+import com.jme.scene.state.TextureState.CorrectionType;
 import com.jme.system.DisplaySystem;
 import com.jme.util.TextureManager;
-import org.lwjgl.opengl.GLContext;
 
-import javax.imageio.ImageIO;
-import java.awt.*;
-import java.awt.geom.AffineTransform;
-import java.awt.image.BufferedImage;
-import java.io.IOException;
-import java.net.URL;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.FloatBuffer;
-
 /**
  * Contains a texture, its dimensions and a texture state.
  */
 public class BImage extends Quad {
-    /**
+
+   private static final long serialVersionUID = 1L;
+
+   /**
      * An interface for pooling OpenGL textures.
      */
     public interface TexturePool {
@@ -65,7 +73,7 @@
     /**
      * An alpha state that blends the source plus one minus destination.
      */
-    public static AlphaState blendState;
+    public static BlendState blendState;
 
     /**
      * Configures the supplied spatial with transparency in the standard user interface sense which is that transparent
@@ -143,7 +151,7 @@
         scratch.put(data);
         scratch.flip();
         Image textureImage = new Image();
-        textureImage.setType(hasAlpha ? Image.RGBA8888 : Image.RGB888);
+        textureImage.setFormat(hasAlpha ? Format.RGBA8 : Format.RGB8);
         textureImage.setWidth(twidth);
         textureImage.setHeight(theight);
         textureImage.setData(scratch);
@@ -151,7 +159,7 @@
         setImage(textureImage);
 
         // make sure we have a unique default color object
-        getBatch(0).getDefaultColor().set(ColorRGBA.white);
+        getDefaultColor().set(ColorRGBA.white);
     }
 
     /**
@@ -172,14 +180,14 @@
     /**
      * Returns the width of this image.
      */
-    public int getWidth() {
+    public float getWidth() {
         return _width;
     }
 
     /**
      * Returns the height of this image.
      */
-    public int getHeight() {
+    public float getHeight() {
         return _height;
     }
 
@@ -190,7 +198,7 @@
         if (transparent) {
             setRenderState(blendState);
         } else {
-            clearRenderState(RenderState.RS_ALPHA);
+            clearRenderState(BlendState.RS_BLEND);
         }
         updateRenderState();
     }
@@ -204,17 +212,17 @@
             releaseTexture();
         }
 
-        Texture texture = new Texture();
+        Texture2D texture = new Texture2D();
         texture.setImage(image);
 
         _twidth = image.getWidth();
         _theight = image.getHeight();
 
-        texture.setFilter(Texture.FM_LINEAR);
-        texture.setMipmapState(Texture.MM_LINEAR);
+        texture.setMagnificationFilter(MagnificationFilter.Bilinear);
+        texture.setMinificationFilter(MinificationFilter.NearestNeighborLinearMipMap);
         _tstate.setTexture(texture);
         _tstate.setEnabled(true);
-        _tstate.setCorrection(TextureState.CM_AFFINE);
+        _tstate.setCorrectionType(CorrectionType.Affine);
         setRenderState(_tstate);
         updateRenderState();
 
@@ -237,7 +245,7 @@
         float ux = (sx + swidth) / (float) _twidth;
         float uy = (sy + sheight) / (float) _theight;
 
-        FloatBuffer tcoords = getTextureBuffer(0, 0);
+        FloatBuffer tcoords = getTextureCoords(0).coords;
         tcoords.clear();
         tcoords.put(lx).put(uy);
         tcoords.put(lx).put(ly);
@@ -308,7 +316,7 @@
         localTranslation.y = ty + theight / 2f;
         updateGeometricState(0, true);
 
-        getBatch(0).getDefaultColor().a = alpha;
+        getDefaultColor().a = alpha;
         draw(renderer);
     }
 
@@ -384,10 +392,10 @@
     };
 
     static {
-        blendState = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
+        blendState = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
         blendState.setBlendEnabled(true);
-        blendState.setSrcFunction(AlphaState.SB_SRC_ALPHA);
-        blendState.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
+        blendState.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
+        blendState.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
         blendState.setEnabled(true);
         _supportsNonPowerOfTwo = GLContext.getCapabilities().GL_ARB_texture_non_power_of_two;
     }
Index: src/java/com/jmex/bui/background/ImageBackground.java
===================================================================
--- src/java/com/jmex/bui/background/ImageBackground.java   (revision 150)
+++ src/java/com/jmex/bui/background/ImageBackground.java   (working copy)
@@ -84,7 +84,7 @@
 
         // compute the frame for our framed mode if one was not specially provided
         if (_frame == null && (_mode == FRAME_X || _mode == FRAME_Y || _mode == FRAME_XY)) {
-            int twidth = _image.getWidth(), theight = _image.getHeight();
+            int twidth = Math.round(_image.getWidth()), theight = Math.round(_image.getHeight());
             _frame = new Insets();
             _frame.left = twidth / 3;
             _frame.right = twidth / 3;
@@ -96,7 +96,7 @@
     // documentation inherited
     public int getMinimumWidth() {
         return (_mode == FRAME_XY || _mode == FRAME_X) ?
-               (_frame.left + _frame.right) : _image.getWidth();
+               (_frame.left + _frame.right) : Math.round(_image.getWidth());
     }
 
     /**
@@ -104,7 +104,7 @@
      */
     public int getMinimumHeight() {
         return (_mode == FRAME_XY || _mode == FRAME_Y) ?
-               _frame.top + _frame.bottom : _image.getHeight();
+               _frame.top + _frame.bottom : Math.round(_image.getHeight());
     }
 
     // documentation inherited
@@ -172,12 +172,12 @@
             float alpha) {
         switch (_mode) {
             case SCALE_X:
-                y = (height - _image.getHeight()) / 2;
-                height = _image.getHeight();
+                y = (height - Math.round(_image.getHeight())) / 2;
+                height = Math.round(_image.getHeight());
                 break;
             case SCALE_Y:
-                x = (width - _image.getWidth()) / 2;
-                width = _image.getWidth();
+                x = (width - Math.round(_image.getWidth())) / 2;
+                width = Math.round(_image.getWidth());
                 break;
         }
         _image.render(renderer, x, y, width, height, alpha);
@@ -190,7 +190,7 @@
             int width,
             int height,
             float alpha) {
-        int iwidth = _image.getWidth(), iheight = _image.getHeight();
+        int iwidth = Math.round(_image.getWidth()), iheight = Math.round(_image.getHeight());
         if (_mode == TILE_X) {
             renderRow(renderer, x, y, width, Math.min(height, iheight), alpha);
         } else if (_mode == TILE_Y) {
@@ -224,7 +224,7 @@
             int width,
             int iheight,
             float alpha) {
-        int iwidth = _image.getWidth();
+        int iwidth = Math.round(_image.getWidth());
         int across = width / iwidth;
         for (int xx = 0; xx < across; xx++) {
             _image.render(renderer, 0, 0, iwidth, iheight,
@@ -245,7 +245,7 @@
             int height,
             float alpha) {
         // render each of our image sections appropriately
-        int twidth = _image.getWidth(), theight = _image.getHeight();
+        int twidth = Math.round(_image.getWidth()), theight = Math.round(_image.getHeight());
 
         // draw the corners
         _image.render(renderer, 0, 0, _frame.left, _frame.bottom, x, y, alpha);

umm. i already updated my local copy of gbui for jme 2.0, but i didn't manage to find the time to branch and check in :frowning:

i suppose i'll have to talk to gerbildrop about this.



still, thanks for the patch. i'll take a look at it to see if i forgot anything.



edit:

changes are into the gbui trunk now (yet i didn't update the libs - jme, lwjgl).

for the jme 1.0 version of gbui use the gbui-jme1.0 branch

In this patch, you change :


     /**
      * Returns the width of this image.
      */
-    public int getWidth() {
+    public float getWidth() {
         return _width;
     }



but in your repository it looks like this:

    /**
     * Returns the width of this image.
     */
    public int getImageWidth() {
        return _width;
    }



How come the change? I am guessing the newer is the more correct one, as then you can get both the quads width and the image's width, or am I mistaken..

that patch ist not mine. :wink:

and yes i changed getWidth to getImageWidth (same for height) to avoid confusion (and float --> int conversions). that's in fact the width of the image and not the width of the quad.

I'm reviewing Sfera's code for 2.0 now… I don't see any reason it shouldn't be out there in the next week or so.



timo