after I call
display.recreateWindow(width, height, depth, freq, fullscreen);
the mouse is off, you have to click above box and to the right to get it to work. I assume the problem lies in the fact that the windows getting resized but not the JMEDesktop. I tried
desktop.resize(display.getWidth(), display.getHeight());
but it didnt work. here is example showing problem:
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import jmetest.awt.swingui.TestJMEDesktop;
import com.jme.app.SimpleGame;
import com.jme.input.AbsoluteMouse;
import com.jme.input.MouseInput;
import com.jme.input.action.InputActionEvent;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.scene.state.LightState;
import com.jme.system.PropertiesIO;
import com.jmex.awt.swingui.JMEAction;
import com.jmex.awt.swingui.JMEDesktop;
/**
* Very short example for JMEDesktop - see {@link TestJMEDesktop} for more features.
*/
public class HelloJMEDesktop extends SimpleGame {
private Node guiNode;
private int width, height, depth, freq;
private boolean fullscreen;
PropertiesIO properties;
private AbsoluteMouse cursor;
protected void simpleInitGame() {
properties = new PropertiesIO("properties.cfg");
width = properties.getWidth();
height = properties.getHeight();
depth = properties.getDepth();
freq = properties.getFreq();
fullscreen = properties.getFullscreen();
// create a node for ortho gui stuff
guiNode = new Node( "gui" );
guiNode.setRenderQueueMode( Renderer.QUEUE_ORTHO );
// create the desktop Quad
JMEDesktop desktop = new JMEDesktop( "desktop", 500, 400, input );
// make it transparent blue
desktop.getJDesktop().setBackground( new Color( 0, 0, 1, 0.2f ) );
// and attach it to the gui node
guiNode.attachChild( desktop );
// center it on screen
desktop.getLocalTranslation().set( display.getWidth() / 2 - 30, display.getHeight() / 2 + 50, 0 );
// create a swing button
final JButton button = new JButton( "click me" );
// and put it directly on the desktop
desktop.getJDesktop().add( button );
// desktop has no layout - we layout ourselfes (could assign a layout to desktop here instead)
button.setLocation( 200, 200 );
button.setSize( button.getPreferredSize() );
// add some actions
// standard swing action:
button.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
// this gets executed in swing thread
// alter swing components ony in swing thread!
// button.setLocation( FastMath.rand.nextInt( 400 ), FastMath.rand.nextInt( 300 ) );
System.out.println( "clicked!" );
}
} );
// action that gets executed in the update thread:
button.addActionListener( new JMEAction( "my action", input ) {
public void performAction( InputActionEvent evt ) {
// this gets executed in jme thread
// do 3d system calls in jme thread only!
reinit();
guiNode.updateRenderState(); // this call has no effect but should be done in jme thread :)
}
});
// don't cull the gui away
guiNode.setCullMode( Spatial.CULL_NEVER );
// gui needs no lighting
guiNode.setLightCombineMode( LightState.OFF );
// update the render states (especially the texture state of the deskop!)
guiNode.updateRenderState();
// update the world vectors (needed as we have altered local translation of the desktop and it's
// not called in the update loop)
guiNode.updateGeometricState( 0, true );
// finally show the system mouse cursor to allow the user to click our button
MouseInput.get().setCursorVisible( true );
}
protected void reinit() {
display.recreateWindow(width, height, depth, freq, fullscreen);
}
protected void simpleRender() {
// draw the gui stuff after the scene
display.getRenderer().draw( guiNode );
}
public static void main( String[] args ) {
new HelloJMEDesktop().start();
}
}
how do I resize display AND JMEDesktop together? or should I dispose of JMEDesktop and create a new one?