How to distroy or dispose of absolute mouse?

Im working on an ingame GUI for display options. Here is the problem Im having; when I recreate window I also need to dispose of the absolute mouse

and create a new one or the old one is off as it was created with

cursor = new AbsoluteMouse( "cursor", displaySystem.getWidth() , displaySystem.getHeight());

I tried

node.detachChild(cursor);

which removes mouse cursor but it acts like its still there which causes problems. I would like like to dispose of the old mouse completely or keep it if there was a method like

absolutemouse.recreate(width, height);



:?

edit: Im still having no luck with this, Im not sure if the InputHandler is the problem or the absolute mouse. hmmm

screenshot to illustrate problem:

cursor numbered one cannot use swing components after I dispose of and recreate the display and the JMEDesktop so I create cursor number 2 which can select components but cant reach them cause cursor one wont go past top of screen. I tried removing cursor 1 with detachChild() but it acts like its still there(I still cant reach components).

This is only an issuse when I go from a larger window to a smaller one.

when I go from a smaller window to a larger cursor 2 is above cursor 1 so it does reach and can select components.

I hope this explains problem better :slight_smile:

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();
    }
}

You shouldn't need to dispose your absolute mouse. That change Llama committed (AbsoluteMouse.usingDeltas == false) along with a fix I just committed (mouse input handler regards changed display size) should help you. Let me know if it's ok now.

Nice screen shot btw - is that youre artistry ??

That change Llama committed (AbsoluteMouse.usingDeltas == false) along with a fix I just committed (mouse input handler regards changed display size) should help you. Let me know if it's ok now.

Ack! I just updated from CVS and now my mouse cursor has disappeared!

Nice screen shot btw - is that youre artistry ??

thanks!, yup that was me. I learned everything I know making custom maps for Enemy Territory :D

edit: I just ran TestJMEDesktop in JME source and cursor has disappeared there also.

Just checked in a fix for that. Try again if irrisors new code for handeling displaysize works now.



Btw: I'm glad to see someone use recreateWindow() to find bugs like the one irrisor just fixed.

Woohoo! works perfect, thanks for rapid fix! :smiley:

Btw: I'm glad to see someone use recreateWindow() to find bugs like the one irrisor just fixed


glad to use it :)

edit: I think there may also be a bug in:

desktop.resize(width, height);


when I use it desktop comes out wrong size, im going to look into it some more.
mud2005 said:

edit: I think there may also be a bug in:

desktop.resize(width, height);


when I use it desktop comes out wrong size, im going to look into it some more.

oh, that's not supported! This resizes only the quad. For the time being recreate the JMEDesktop please, if you really need resizing.

(I'll add an exception to prevent people not noticing it)
oh, that's not supported! This resizes only the quad. For the time being recreate the JMEDesktop please, if you really need resizing.

ok thanks,
Another issue with resizing of window:
Im using ShadowedRenderPass which makes a shadowQuad.

shadowQuad = new Quad("RenderForeground", DisplaySystem
               .getDisplaySystem().getRenderer().getWidth(), DisplaySystem
               .getDisplaySystem().getRenderer().getHeight());

This shadowQuad is not resized when window is recreated resulting in cropped shadows.
At least I think that is whats happening :?
in this picture window has been resized from 640x480 to 1024x768. The shadow should cover entire window but it doesnt:

We recently fixed that shadow problem locally and it should be going into cvs with todays bugfix checkin.

I just updated from CVS and now my game which previously ran at ~60fps now runs at 1-3fps. :-o



edit: if I turn off shadow pass fps jumps to 180-190fps

Same problem here, just regular TestShadowPass. I run at 4/5 FPS, and get a completly gray screen, about every other frame. Ati X700 on windows.

Looking into the problem right now.

Looks like it is an issue with the expansion to work with multiple batches.  Should be fixed soon.

The way triangle count was calculated was incorrect especially for cases where you reuse vertices (it was saying trianlge count = # verts / 3 which wouldn't be true if you reuse verts for multiple triangles.)  That was causing the shadow volumes to think they needed to be recalculated every frame.  Ugh!  Should be in cvs now.

In CVS.

And seems fixed here.

Fixed here also, thanks you guys rock 8)