GBUI BComponent.setBounds() Glitch

So what I want to do is create a menu that has buttons that can move around when transitioning on and off the screen.  So to do this I in my update method call button.setBounds(someX, someY, button.getWidth(), button.getHeight()), but this causes a little glitch when the mouse passes over the button, basically it looks like the button jumps over to the original position it was set in the window.add() method, and then back to the bounds position.  I hope this will be a feature that I can implement, but this glitch is rather weird.

Sorry, I've been out for about a month now.  I had to have surg, after 2 years they finally figured out what was wrong.



So you're saying that maybe on the screen when you start you want the buttons lined up on the left side…then click one and change views and the buttons move to the bottom of the screen?



I'm not entirely understanding I guess.  I understand what you're saying about the button moving back to its original position.



Give me an example and I'll see what I can do…I've still got another two weeks of recovery before I will be back up to full steam

Ok here's some example code just use the bss from atechnique and any old image for the background, right now mine's a detail texture from the jmetest terrain's.


import java.io.IOException;

import com.jme.app.SimpleGame;
import com.jme.input.MouseInput;
import com.jme.math.FastMath;
import com.jme.util.Timer;
import com.jmex.bui.BButton;
import com.jmex.bui.BComponent;
import com.jmex.bui.BImage;
import com.jmex.bui.BWindow;
import com.jmex.bui.BuiSystem;
import com.jmex.bui.PolledRootNode;
import com.jmex.bui.background.ImageBackground;
import com.jmex.bui.enumeratedConstants.ImageBackgroundMode;
import com.jmex.bui.event.ActionEvent;
import com.jmex.bui.event.ActionListener;
import com.jmex.bui.layout.AbsoluteLayout;
import com.jmex.bui.util.Point;

public class TestGbuiGlitch extends SimpleGame {

   public static void main(String[] args) {
      TestGbuiGlitch app = new TestGbuiGlitch();
      app.setConfigShowMode(ConfigShowMode.AlwaysShow);
      app.start();
   }
   
   float transitionPosition = 1f;
   Point startPosition = new Point(270, 190);
   BWindow bWindow;
   BButton bButton;
   
   @Override
   protected void simpleInitGame() {
        MouseInput.get().setCursorVisible(true);
      BuiSystem.init(new PolledRootNode(Timer.getTimer(), input), "style2.bss");
       rootNode.attachChild(BuiSystem.getRootNode());
      bWindow = new BWindow(BuiSystem.getStyle(), new AbsoluteLayout());
      bButton = new BButton("Click Me!");
      bButton.setPreferredSize(100, 100);
        bButton.addListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent event) {
                System.out.println("Button Pressed!");
            }
        });
       
        bWindow.setSize(640, 480);
        bWindow.add(bButton, new Point(270, 190));
        BImage image = null;
      try {
         image = new BImage(getClass().getClassLoader().
                 getResource("detail.jpg"));
      } catch (IOException e) {
         e.printStackTrace();
      }
        bWindow.setBackground(BComponent.DEFAULT, new ImageBackground(ImageBackgroundMode.SCALE_XY, image));
        BuiSystem.addWindow(bWindow);
        bWindow.center();
      
   }
   
   public void simpleUpdate() {
      updateTransition(super.tpf, 10f, -1);
      
        float transitionOffset = (float)FastMath.pow(transitionPosition, 2);
       
        int tempPosition = (int) startPosition.x;

        tempPosition -= transitionOffset * 512;

          bButton.setBounds(
                 tempPosition, bButton.getY(),
                 bButton.getWidth(), bButton.getHeight());  
      
      super.simpleUpdate();
   }
   
    boolean updateTransition(float tpf, float transitionOffTime, int direction)
    {
        // How much should we move by?
        float transitionDelta;

        if (transitionOffTime == 0)
            transitionDelta = 1;
        else
            transitionDelta = tpf;

        // Update the transition position.
        transitionPosition += transitionDelta * direction;

        // Did we reach the end of the transition?
        if (((direction < 0) && (transitionPosition <= 0)) ||
            ((direction > 0) && (transitionPosition >= 1)))
        {
            transitionPosition = FastMath.clamp(transitionPosition, 0, 1);
            return false;
        }

        // Otherwise we are still busy transitioning.
        return true;
    }

}



Notice how the button glitches while it's transitioning on, if you shake/hover your mouse over it.  When it has come to a stop notice that if you shake your mouse back and forth over the button is wiggles.  I want the button to remain stationary, but it's not.

On a personal note, I hope you get well soon!  :D

Bump, summers almost over at least in the northern hemisphere, and I would like to solved hopefully.

I don't even remember this bug…I'll add it to the bug list on code.google.com with a high priority.

Cool ok, let me know if you need anymore details.

Ok, so the image that was supplied isn't in SVN, which may be part of the problem testing this.  I'm checking in the "ButtonWiggleTest" in the test directory.



email me the image used for the button (standtrooper AT gmail DOT com) and I'll run it again locally.  I'm not seeing the issue you've described…now that could mean that it's either fixed, not likely, or the image is not the same size or has been shaded differently and looks like the portion wiggles when hovering.



lemmie know



timo

The image your using might make it so you can’t see the issue, but the one I’m using is just from the jme terrain test (which is lighter in color) http://code.google.com/p/jmonkeyengine/source/browse/trunk/src/jmetest/data/texture/Detail.jpg  If you want to make it a little easy to see comment out simpleUpdate like this

   public void simpleUpdate() {

      updateTransition(super.tpf, 10f, -1);

      

        //float transitionOffset = (float)FastMath.pow(transitionPosition, 2);

       

        //int tempPosition = (int) startPosition.x;



        //tempPosition -= transitionOffset * 512;



          bButton.setBounds(

                 100, bButton.getY(),

                 bButton.getWidth(), bButton.getHeight());  

      

      super.simpleUpdate();

   }

   

as well as change setBounds to

          bButton.setBounds(

                 100, bButton.getY(),

                 bButton.getWidth(), bButton.getHeight());

ok, so your issue is that the game isn't sure what to do with the button, it now has two conflicting points to locate itself on the screen.



if you set the tempPosition to a firm 100 on the x then the other two Point values for x are still being held and the game doesn't know what to do with those…the issue isn't that GBUI has dorked anything up, but that the values on lines 35 and 53 (totally unintentional) reflect the x value substituted on line 77 where tempPosition was suggested to be 100.



In other words, change the 270 on lines 35 and 53 to 100 and replace tempPosition on line 77 with 100 and it will work just as you're expecting it to.



I've checked in the version of ButtonWiggleTest to reflect the line numbers above.



timo

Yeah, you were right the window.add() and bComponent.setBounds() should be set with the same points, but if you shake your mouse over the ButtonWiggleTest button it still "wiggles" a little, hmm…maybe it's just a floating point error or something.  If I set the layout to HGroupLayout instead of AbsoluteLayout, then I don't have to set a point for the window.add() and the glitches go away.  If you can't see it shake, then maybe it's just my computer, but I doubt that.  It seems to wiggle the most when the color of the button text changes from purple to white (and vice-versus).  At least I got it partially solved… :slight_smile:

ok, I'll check it out…just because I don't see it definitely doesn't mean it's not happening.  I'll recheck it again and see what else there is.



timo

just to make sure we're looking at the same set of code:



/**
 * $Id$
 * $Copyright$
 */
package com.jmex.bui;

/**
 * @author torr
 * @since Aug 31, 2009 - 10:39:28 AM
 */

import com.jme.app.SimpleGame;
import com.jme.input.MouseInput;
import com.jme.math.FastMath;
import com.jme.util.Timer;
import com.jmex.bui.background.ImageBackground;
import com.jmex.bui.enumeratedConstants.ImageBackgroundMode;
import com.jmex.bui.event.ActionEvent;
import com.jmex.bui.event.ActionListener;
import com.jmex.bui.layout.AbsoluteLayout;
import com.jmex.bui.util.Point;

import java.io.IOException;
import java.net.URL;

public class ButtonWiggleTest extends SimpleGame {

    public static void main(String[] args) {
        ButtonWiggleTest app = new ButtonWiggleTest();
        app.setConfigShowMode(ConfigShowMode.AlwaysShow);
        app.start();
    }

    float transitionPosition = 1f;
    int x = 100;//270
    Point startPosition = new Point(x, 190);
    BWindow bWindow;
    BButton bButton;

    protected void simpleInitGame() {
        MouseInput.get().setCursorVisible(true);
        BuiSystem.init(new PolledRootNode(Timer.getTimer(), input), "/rsrc/style2.bss");
        rootNode.attachChild(BuiSystem.getRootNode());
        bWindow = new BWindow(BuiSystem.getStyle(), new AbsoluteLayout());
        bButton = new BButton("Click Me!");
        bButton.setPreferredSize(100, 100);
        bButton.addListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                System.out.println("Button Pressed!");
            }
        });

        bWindow.setSize(640, 480);
        bWindow.add(bButton, new Point(x, 190));
        BImage image = null;
        URL url = null;
        try {
            url = getClass().getClassLoader().getResource("jmetest/data/texture/Detail.jpg");
            image = new BImage(url);
        } catch (IOException e) {
            e.printStackTrace();
        }

        bWindow.setBackground(BComponent.DEFAULT, new ImageBackground(ImageBackgroundMode.SCALE_XY, image));
        BuiSystem.addWindow(bWindow);
        bWindow.center();
    }

    public void simpleUpdate() {
        updateTransition(super.tpf, 10f, -1);

        float transitionOffset = (float) FastMath.pow(transitionPosition, 2);

        int tempPosition = (int) startPosition.x;

        tempPosition = x;// -= transitionOffset * 512;

        bButton.setBounds(tempPosition,
                          bButton.getY(),
                          bButton.getWidth(),
                          bButton.getHeight());

        super.simpleUpdate();
    }

    boolean updateTransition(float tpf, float transitionOffTime, int direction) {
        // How much should we move by?
        float transitionDelta;

        if (transitionOffTime == 0) {
            transitionDelta = 1;
        } else {
            transitionDelta = tpf;
        }

        // Update the transition position.
        transitionPosition += transitionDelta * direction;

        // Did we reach the end of the transition?
        if (((direction < 0) && (transitionPosition <= 0)) ||
            ((direction > 0) && (transitionPosition >= 1))) {
            transitionPosition = FastMath.clamp(transitionPosition, 0, 1);
            return false;
        }

        // Otherwise we are still busy transitioning.
        return true;
    }
}