Ive also just been able to get it working with only one JMEDesktop and absolute mouse(in previous example I distroy first then recreate)
the mouse can select box fine now after resizing but mouse cursor is still confined to smaller area and cant reach top of window. :’(
I made example that shows issue.It creates 800x600 window and when button is clicked it resizes to 640x480.
as with previous example there is no issue when going from smaller to larger window only when going from larger to smaller.
any help is GREATLY appreciated, thx.
edit: This line, from reinit() method, when commented out allows mouse to move in entire window but then position is off and I cant click button
If I show system cursor I can see that when it reaches top of screen my custom cursor stops. so I know the problem lies in the difference between the position of the system cursor and my custom cursor. how to fix it? that I dont know.
cursor.setLimit(width, height);
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import javax.swing.JButton;
import jmetest.awt.swingui.TestJMEDesktop;
import com.jme.app.SimpleGame;
import com.jme.image.Image;
import com.jme.image.Texture;
import com.jme.input.AbsoluteMouse;
import com.jme.input.FirstPersonHandler;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.MouseInput;
import com.jme.input.action.InputActionEvent;
import com.jme.math.Vector3f;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.scene.state.AlphaState;
import com.jme.scene.state.LightState;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.system.JmeException;
import com.jme.system.PropertiesIO;
import com.jme.util.TextureManager;
import com.jme.util.Timer;
import com.jmex.awt.swingui.JMEAction;
import com.jmex.awt.swingui.JMEDesktop;
public class HelloJMEDesktop extends SimpleGame {
private Node guiNode;
private int width, height, depth, freq;
private boolean fullscreen;
PropertiesIO properties;
private AbsoluteMouse cursor;
JMEDesktop desktop;
protected void simpleInitGame() {
guiNode = new Node( "gui" );
guiNode.setRenderQueueMode( Renderer.QUEUE_ORTHO );
MouseInput.get().setCursorVisible(false);
desktop = new JMEDesktop( "desktop", 500, 400, input );
desktop.setLightCombineMode( LightState.OFF );
desktop.getJDesktop().setBackground( new Color( 0, 0, 1, 0.2f ) );
guiNode.attachChild( desktop );
desktop.getLocalTranslation().set( display.getWidth() / 2, display.getHeight() / 2 , 0 );
final JButton button = new JButton( "click me" );
desktop.getJDesktop().add( button );
button.setLocation( 200, 200 );
button.setSize( button.getPreferredSize() );
button.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
System.out.println( "clicked!" );
}
} );button.addActionListener( new JMEAction( "my action", input ) {
public void performAction( InputActionEvent evt ) {
reinit();
}
});
guiNode.setCullMode( Spatial.CULL_NEVER );
guiNode.setLightCombineMode( LightState.OFF );
guiNode.updateRenderState();
guiNode.updateGeometricState( 0, true );
createCustomCursor();
}
protected void initSystem(){
try {
properties = new PropertiesIO("properties.cfg");
properties.load();
depth = properties.getDepth();
freq = properties.getFreq();
fullscreen = false;
display = DisplaySystem.getDisplaySystem( properties.getRenderer() );
display.setMinDepthBits( 8 );
display.setMinStencilBits( stencilBits );
display.setMinAlphaBits( alphaBits );
display.setMinSamples( samples );
display.createWindow( 800, 600,
properties.getDepth(), properties.getFreq(), false );
cam = display.getRenderer().createCamera( display.getWidth(),
display.getHeight() );
} catch ( JmeException e ) {
e.printStackTrace();
System.exit( 1 );
}
Vector3f loc = new Vector3f( 0.0f, 0.0f, 25.0f );
Vector3f left = new Vector3f( -1.0f, 0.0f, 0.0f );
Vector3f up = new Vector3f( 0.0f, 1.0f, 0.0f );
Vector3f dir = new Vector3f( 0.0f, 0f, -1.0f );
cam.setFrame( loc, left, up, dir );
cam.update();
display.getRenderer().setCamera( cam );
timer = Timer.getTimer( properties.getRenderer() );
FirstPersonHandler firstPersonHandler = new FirstPersonHandler( cam, 50,
1 );
input = firstPersonHandler;
KeyBindingManager.getKeyBindingManager().set( "exit",
KeyInput.KEY_ESCAPE );
}
private void createCustomCursor() {
cursor = new AbsoluteMouse( "cursor", display.getWidth(), display.getHeight() );
TextureState ts = display.getRenderer().createTextureState();
URL cursorLoc;
cursorLoc = TestJMEDesktop.class.getClassLoader().getResource(
"jmetest/data/cursor/cursor1.png" );
Texture t = TextureManager.loadTexture( cursorLoc, Texture.MM_LINEAR,
Texture.FM_LINEAR, Image.GUESS_FORMAT_NO_S3TC, 1, true );
ts.setTexture( t );
cursor.setRenderState( ts );
AlphaState as = display.getRenderer().createAlphaState();
as.setBlendEnabled( true );
as.setSrcFunction( AlphaState.SB_SRC_ALPHA );
as.setDstFunction( AlphaState.DB_ONE_MINUS_SRC_ALPHA );
as.setTestEnabled( true );
as.setTestFunction( AlphaState.TF_GREATER );
cursor.setRenderState( as );
cursor.registerWithInputHandler( input );
guiNode.attachChild( cursor );
cursor.setUsingDelta( false );
cursor.getXUpdateAction().setSpeed( 1 );
cursor.getYUpdateAction().setSpeed( 1 );
cursor.setCullMode( Spatial.CULL_NEVER );
cursor.updateRenderState();
cursor.updateGeometricState(0,false);
}
protected void reinit() {
width = 640;
height = 480;
display.recreateWindow(width, height, depth, freq, false);
guiNode.updateRenderState();
guiNode.updateGeometricState( 0, true );
desktop.setLocalTranslation(new Vector3f( display.getWidth() / 2 , display.getHeight() / 2, 0 ));
cursor.setLimit(width, height);
}
protected void simpleRender() {
display.getRenderer().draw( guiNode );
}
protected void simpleUpdate() {
if ( KeyBindingManager.getKeyBindingManager().isValidCommand( "exit",
false ) ) {
finish();
}
}
public static void main( String[] args ) {
new HelloJMEDesktop().start();
}
}