Action on click with tonegodgui button and JPopupMenu

Hi all

in my software i use a tonegodGui button to gereate an event and with this event i show a JPopupMenu.

Actually when I click in another place of the JPopupMenu in another place in JME application I got an event to setvisible(false) my JPopupMenu.

Do you now how I can have this event?

I now i can use Menu from Tonegodegui but I want have the JPopupMenu look, my application is not a game.

Thanks for your help:)

@hedi said: Hi all

in my software i use a tonegodGui button to gereate an event and with this event i show a JPopupMenu.

Actually when I click in another place of the JPopupMenu in another place in JME application I got an event to setvisible(false) my JPopupMenu.

Do you now how I can have this event?

I now i can use Menu from Tonegodegui but I want have the JPopupMenu look, my application is not a game.

Thanks for your help:)

The theme that is applies to the UI by default is completely customizable. Whether you’re using the standard definitions or atlasing. Let me see if I can explain how to customize the UI real quick:

The main theme file is:

tonegod.gui.style.def.style_map.xml - For standard separate UI images
tonegod.gui.style.atlasdef.style_map.xml - For UI’s using texture atlases

Make a local copy of this file and use the alternate contructor for creating the screen, passing in the file path to your local ui def sile like so:

[java]
screen = new Screen(this,“localpath/style_map.xml”);
// screen.setUseTextureAtlas(true, “tonegod/gui/style/atlasdef/atlas.png”); // << for atlas you will need to supply the image
guiNode.addControl(screen);
[/java]

After this, open the file and you’ll see a bunch of pointers to other xml files that contain UI style info. Swap out any of these for local copies and alter the xml accordingly. Here would be an example of altering the Button.xml file

[java]
// In the style_map.xml file, alter this line:
<style control=“Button” path=“tonegod/gui/style/def/Button/Button.xml” />
// to point at a local copy
<style control=“Button” path=“localpath/Button/Button.xml” />
[/java]

Then alter the Button.xml file with the new L&F info, like so:

[java]
// Snippet only containing Button portion of file
<element name=“Button”>
<font>
<property name=“fontSize” type=“float” value=“20” />
<property name=“fontColor” type=“ColorRGBA”>
<r value=“0.8” />
<g value=“0.8” />
<b value=“0.8” />

</property>
<property name=“textAlign” type=“String” value=“Center” />
<property name=“textVAlign” type=“String” value=“Center” />
<property name=“textWrap” type=“String” value=“NoWrap” />
<property name=“hoverColor” type=“ColorRGBA”>
<r value=“1.0” />
<g value=“1.0” />
<b value=“1.0” />

</property>
<property name=“pressedColor” type=“ColorRGBA”>
<r value=“0.6” />
<g value=“0.6” />
<b value=“0.6” />

</property>
</font>
<attributes>
<property name=“resizeBorders” type=“Vector4f”>
<x value=“5” />
<y value=“5” />
<z value=“5” />
<w value=“5” />
</property>
<property name=“defaultSize” type=“Vector2f”>
<x value=“100” />
<y value=“30” />
</property>
<property name=“pressedSound” type=“String” value=“button_pressed” />
<property name=“usePressedSound” type=“boolean” value=“true” />
<property name=“pressedSoundVolume” type=“float” value=“1” />
<property name=“hoverSound” type=“String” value=“button_focus” />
<property name=“useHoverSound” type=“boolean” value=“true” />
<property name=“hoverSoundVolume” type=“float” value=".5" />
</attributes>
<images>
<!-- ALTER ME TO SWAP IMAGES -->
<property name=“defaultImg” type=“String” value=“tonegod/gui/style/def/Button/button_x_u.png” />
<property name=“hoverImg” type=“String” value=“tonegod/gui/style/def/Button/button_x_h.png” />
<property name=“pressedImg” type=“String” value=“tonegod/gui/style/def/Button/button_x_d.png” />
</images>
<effects>
<property name=“event0” type=“Effect”>
<event value=“Hover” />
<effect value=“Pulse” />
<speed value=".3" />
</property>
<property name=“event1” type=“Effect”>
<event value=“Press” />
<effect value=“ImageSwap” />
<speed value=“0” />
</property>
<property name=“event2” type=“Effect”>
<event value=“LoseFocus” />
<effect value=“ImageSwap” />
<speed value=“0” />
</property>
<property name=“event3” type=“Effect”>
<event value=“TabFocus” />
<effect value=“PulseColor” />
<speed value=".3" />
</property>
<property name=“event4” type=“Effect”>
<event value=“LoseTabFocus” />
<effect value=“ColorSwap” />
<speed value=“0” />
</property>
</effects>
</element>
[/java]

Also, keep in mind that the atlas defs are different in values fr defining images for controls:

In non-atlasing:
[java]
<property name=”defaultImg” type=”String” value=”tonegod/gui/style/def/Button/button_x_u.png” />
[/java]

in atlasing defs:
[java]
<property name=”defaultImg” type=”String” value=”x=5|y=5|w=100|h=20” />
[/java]

The value string in atlas defs tells the library how to define the texture coords to diplay a small portion of the one file containg the entire UI

Thanks t0neg0d, I know that your style is full customisable :).

I have a part of code with the JPopupMenu and it work fine.

But i want that when I click an other area the JPopupMenu is not visible.
I want to find a way to do that in order to not re write all code.
do you have an idea?

I dont want personalize all image of the style of PopupMenu because il will take too much time.

But I know with this library you did a big work :slight_smile: .

@hedi said: Thanks t0neg0d, I know that your style is full customisable :).

I have a part of code with the JPopupMenu and it work fine.

But i want that when I click an other area the JPopupMenu is not visible.
I want to find a way to do that in order to not re write all code.
do you have an idea?

I dont want personalize all image of the style of PopupMenu because il will take too much time.

But I know with this library you did a big work :slight_smile: .

I’m trying to understand the issue… are you using JME in a swing app? Or Applet? Or?

And can you post a screen shot that shows the problem?

Yes I using Jme in a swing

sorry I will ask my boss tomorow but i think that I can’t show the app…

@hedi said: Yes I using Jme in a swing

sorry I will ask my boss tomorow but i think that I can’t show the app…

@abies was able to get JavaFX and JME working together… maybe he would have some insight on how to work with external object (like swing components) and the OGLContext window.

@hedi said: Thanks t0neg0d, I know that your style is full customisable :).

I have a part of code with the JPopupMenu and it work fine.

But i want that when I click an other area the JPopupMenu is not visible.
I want to find a way to do that in order to not re write all code.
do you have an idea?

I dont want personalize all image of the style of PopupMenu because il will take too much time.

But I know with this library you did a big work :slight_smile: .

Is your issue that you want the popup menu to go away if the user clicks somewhere that isn’t the pop up menu?

I can’t speak specifically for this GUI library… but in pretty much every other gui library, I’d achieve this with some kind of invisible fullscreen pane that I put up at the same time as the popup. If the pane is clicked then I get rid of the pane and the popup. The trick is then getting rid of the pane when the popup closes normally… which (as I recall) can be done with some clever listener registration on the JPopupMenu.

@pspeed said: Is your issue that you want the popup menu to go away if the user clicks somewhere that isn't the pop up menu?

yes I want do that.

@pspeed said: I can't speak specifically for this GUI library... but in pretty much every other gui library, I'd achieve this with some kind of invisible fullscreen pane that I put up at the same time as the popup. If the pane is clicked then I get rid of the pane and the popup. The trick is then getting rid of the pane when the popup closes normally... which (as I recall) can be done with some clever listener registration on the JPopupMenu.

It’s a very good idea :slight_smile: I will search in this way. thanks

Thanks

So i use GhostGlassPanel,

this Panel receive the event mouse everywere except in the JME application…

so it work fine except in the JME application who the GhostGlassPanel dont receive the mouseEvent yet the GhostGlassPanel is over the main Frame of my app

do you have an idea pspeed ?

Is the JPopupMenu aware of the lose focus event? Try pushing the focus back to the OGL Context window on lose focus and see if that helps.

To continue in my topic in JME y want to use the same way of GhostGlassPanel with a picture.

my pictures i the back groud of my HUD and I have some Button over my HUD.

I try with a abstract class like the pasted code but it don’t work… WE go never in OnMouseMethods ( like onMouseLeftPressed)

I try to with a button but after using it, the button go on top ( over and it hide others button and even if it is transparent. it hide the listener of others buttons)

Button is a good idea to do what i want but iwant to keep it under all other buttons.

Do you have an idea?

thanks for your help. :slight_smile:

[java]
abstract class PictureCliquable extends Picture implements MouseButtonListener, MouseFocusListener, KeyboardListener, TabFocusListener{

public PictureCliquable(String name){
    super(name);
}

public abstract void onMouseLeftPressed(MouseButtonEvent evt);
public abstract void onMouseLeftReleased(MouseButtonEvent evt);
public abstract void onMouseRightPressed(MouseButtonEvent evt);
public abstract void onMouseRightReleased(MouseButtonEvent evt);

}[/java]

Implement code

[java]

this.texCockpitClicaquable = new PictureCliquable(“texCockpitClicaquable”) {
@Override
public void onMouseLeftPressed(MouseButtonEvent evt) {

             System.out.println("onMouseLeftPressed");

        }
        @Override
        public void onMouseLeftReleased(MouseButtonEvent evt) {
      
               System.out.println("onMouseLeftReleased");
        }
        @Override
        public void onMouseRightPressed(MouseButtonEvent evt) {
         
              System.out.println("onMouseRightPressed");
        }
        @Override
        public void onMouseRightReleased(MouseButtonEvent evt) {
       
               System.out.println("onMouseRightReleased");
        }
        public void onGetFocus(MouseMotionEvent evt) {    }
        public void onLoseFocus(MouseMotionEvent evt) {   }
        public void onKeyPress(KeyInputEvent evt) { }
        public void onKeyRelease(KeyInputEvent evt) {}
        public void setTabFocus() {}
        public void resetTabFocus() {}
    };

[/java]

Not that I want to deter you from this method of doing things… but using a fullscreen Panel with/or without setIgnoreMouse(true) and then adding the buttons to the panel as children would have done this without any of the z-order issues you just described.

[java]
// Create the panel this way then add you bg image, or use the extended contrustor that sets the color map at instantiation
Panel bg = new Panel(screen, Vector2f.ZERO, new Vector2f(screen.getWidth(),screen.getHeight()));

ButtonAdatper b1 = new ButtonAdapter(screen, new Vector2f(x,y) {
@Override
public void onButtonMouseLeftUp(MouseButtonEevent evt, boolean isToggled) {
// some code here
}
};

bg.addChild(b1);
screen.addElement(bg);

// etc, etc
[/java]

if you need the background to ignore mouse clicks…

[java]
bg.setIgnoreMouse(true);
[/java]

If you simply want it to never alter it’s z-order when clicked

[java]
bg.setEffectZOrder(false);
[/java]

If you want the buttons to bring the entire control to the front of the screen keeping the children’s z-order intact:

[java]
b1.setEffectParent(true); // This forwards events like z-order change, resize, move to the parent element
[/java]

If it is a deep-nested control:

[java]
b1.setEffectAbsoluteParent(true); // forwards to the screen level control the button is nested within.
[/java]

Anyways, point being… there are many ways to set up what you’re trying to accomplish just using the provided control. Once it moves outside the realm of JME… that’s a different story.

Otherwise, I am completely missing the question from the explanation :wink: Which I did the first time… so it’s likely I’ll do it again.

Ah after rereading your last post… you likely want to setEffectZOrder(false) on both the background and the nested buttons.

Thanks tonegod :slight_smile:

setEffectZOrder(false) resolv my issues:)

thanks for the pasted code;)

1 Like