JPanel is not where it looks to be in JMEDesktop

Hi



Adding a JPanel to the bottom of the screen using JMEDesktop with a JTextfield on, it is a second desktop.



It displays ok - but if i click on the textfield it doesnt find it.



However, if i click in the opposite vertical direction from the centre it does find it.

That is - the textfeld is at display.getHeight() - 80, if i click on display.getHeight() + 80 it works.



To make it simple, have included code whick only needs to be pasted into the simpleInitGame of the TestJMEDesktop class and the 3 declarations needed.


 JPanel tfPanel = new JPanel(new GridBagLayout());
      JTextField tf = new JTextField(50);
      tf.setLocation(0,0);
      GridBagConstraints gb = new GridBagConstraints( 0,0,0,0,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.NONE,new Insets(0,0,0,0),1,0);      
      tfPanel.add(tf, gb);
      
      tfDeskTop = new JMEDesktop( "tf desktop" );
      tfDeskTop.setup( display.getWidth(), 50, false, input );
      tfDeskTop.setLightCombineMode( LightState.OFF );

Have delved deeper



Modified the method fullscreen, and offset the node from the middle.



 private void fullScreen() {
        final DisplaySystem display = DisplaySystem.getDisplaySystem();

        desktopNode.getLocalRotation().set( 0, 0, 0, 1 );
        desktopNode.getLocalTranslation().set( display.getWidth() / 2 - 50, display.getHeight() / 2 + 100, 0 );
        desktopNode.getLocalScale().set( 1, 1, 1 );
        desktopNode.setRenderQueueMode( Renderer.QUEUE_ORTHO );
    }



The same side effect comes to play

Think this is to do with the awt and how it defines position 0,0 being the top left where as JME defines it as the bottom left


? and now - what to do ???

I had some problems with this.



My first problem was with the absolute mouse.

You need the mouse to be using system coordinates because that is what the jdesktop is going to be using.

So I did something like this:



am.setUsingDelta( false );
am.getXUpdateAction().setSpeed( 1 );
am.getYUpdateAction().setSpeed( 1 );




The second issue I had was with picking.  I wanted to know if I had clicked on a swing component before I decide to move my character, etc.
This is something I hacked together and put in my picking code.

The pointInFrame method just returns true if that point is contained within any of the swing components
and false otherwise.  Its really basic, as the swing components are all rectangles.

I'm sure there is a better and more elegent way to do it, and its probably already in the code somewhere but I did not see it.



Vector2f screenPos = new Vector2f();
screenPos.set(am.getHotSpotPosition().x, am.getHotSpotPosition().y);

 if ( getGUI().pointInFrame(screenPos.x, getDisplay().getHeight()- screenPos.y))
 {
                            //here 0,0 is bottom left, swing its top left
                            //clicked on a gui component
                            return;
 }

:-o y coordinate was really wrong - didn't work if desktop wasn't centered.

Fixed and committed.

Top one.



Thanks also tandaur



Just a thought, does its take a performance hit when jme has to render ortho and normal, ? does JME

irrisor said:

:-o y coordinate was really wrong - didn't work if desktop wasn't centered.
Fixed and committed.


Pls show me how to fix this problem?  :)

err, well - simply perform a CVS update (or use the latest nightly build).



Or do you want to know details about the actual fix I applied?

irrisor said:

err, well - simply perform a CVS update (or use the latest nightly build).

Or do you want to know details about the actual fix I applied?

Yes. Could show me how to fix it?

Sure, I can:



In JMEDesktop there is a method convert( int x, int y, Vector2f store ) which converts the mouse coordinates (screen) to coordinates relative to the JDesktop (object space). In Ortho mode it used

x = (int) ( x - getWorldTranslation().x + desktopWidth / 2 );
                y = (int) ( DisplaySystem.getDisplaySystem().getHeight() - y - getWorldTranslation().y + desktopHeight / 2 );


This was wrong and I changed it to

x = (int) ( x - getWorldTranslation().x + desktopWidth / 2 );
                y = (int) ( DisplaySystem.getDisplaySystem().getHeight() - y + getWorldTranslation().y - desktopHeight / 2 );



But why did you want to know that? Just curious? Or do you want to apply it locally - why?
irrisor said:


But why did you want to know that? Just curious? Or do you want to apply it locally - why?


:lol:Thank U so much! The reason is: I'm writting a simple 3D game based on Lession 7 in jmetest.flagrushtut. In game, I want to make one flat panel or frame which will display some information about player and then put it right at the top of the monitor, with whatever camera view. But I don't know what to do  :D Now with this topic, I have some ideas to solve my problem  :).

Irror  ://! I changed



x = (int) ( x - getWorldTranslation().x + desktopWidth / 2 );
                y = (int) ( DisplaySystem.getDisplaySystem().getHeight() - y - getWorldTranslation().y + desktopHeight / 2 );



with


x = (int) ( x - getWorldTranslation().x + desktopWidth / 2 );
                y = (int) ( DisplaySystem.getDisplaySystem().getHeight() - y + getWorldTranslation().y - desktopHeight / 2 );



and rebuilded project but it didn't work if desktop wasn't centered  :// What must I do now?

Well, if you corrected that line and it does not work you obviously have another problem  :expressionless: - how should I know which one if you don't use JMEDesktop but something similar :?

Sorry, dr_glum, that code was still wrong - I've made another correction (hopefully really correct now ) :

y = (int) ( desktopHeight/2 - ( y - getWorldTranslation().y ) );

More of a technique that i found than anything else,



After stepping through the code and realising each desktop is updated, I opted for one JMEDesktop centred which had many panels on. This gives the effect of many but without all the updates.