Nivfty events question

Hello,

i try to create a button that suits my needs
the goal is to have a button that changes to a different image when hover,click and release events occurs

the problem is that the inputEvent is never called for mouse evvents, only for keys, and the inputEvent itself is always null

here is the code:

[java]
public class NewButtonController extends AbstractController implements Button {
private Nifty nifty;
private Screen screen;
private FocusHandler focusHandler;
public void bind(
final Nifty niftyParam,
final Screen screenParam,
final Element newElement,
final Properties parameter,
final Attributes controlDefinitionAttributes)
{
super.bind(newElement);
nifty = niftyParam;
screen = screenParam;
focusHandler = screen.getFocusHandler();
}

public boolean inputEvent(final NiftyInputEvent inputEvent) {
Element buttonElement = getElement();
if (inputEvent == NiftyInputEvent.NextInputElement) {
if (focusHandler != null) {
focusHandler.getNext(buttonElement).setFocus();
}
return true;
} else if (inputEvent == NiftyInputEvent.PrevInputElement) {
if (focusHandler != null) {
focusHandler.getPrev(buttonElement).setFocus();
}
return true;
} else if (inputEvent == NiftyInputEvent.Activate) {
buttonClick();
return true;
} else if (inputEvent == NiftyInputEvent.MoveCursorDown) {
if (focusHandler != null) {
Element nextElement = focusHandler.getNext(buttonElement);
if (nextElement.getParent().equals(buttonElement.getParent())) {
nextElement.setFocus();
return true;
}
}
} else if (inputEvent == NiftyInputEvent.MoveCursorUp) {
if (focusHandler != null) {
Element prevElement = focusHandler.getPrev(buttonElement);
if (prevElement.getParent().equals(buttonElement.getParent())) {
prevElement.setFocus();
return true;
}
}
}
return false;
}

private void buttonClick() {
getElement().onClick();
}

@Override
public void activate() {
buttonClick();
}

[/java]

  <!-- NEW BUTTON STYLES - - - - - - - - - - - - - - - - - - - - - - - - - -  -->
    <style id="new-Button#panel">
        <attributes backgroundImage="Textures/bigButton.png" imageMode="sprite-resize:72,72,0, 12,45,15,12, 12,45,15,46, 12,45,15,14" childLayout="center" visibleToMouse="true" />
        <effect>
            <onHover name="border" color="#822f" post="true" />
            <onFocus name="changeImage" active="Textures/bigButton.png" inactive="Textures/bigButton.png" imageMode="sprite-resize:72,72,1, 12,45,15,12, 12,45,15,46, 12,45,15,14" post="false" />
            <onEnabled name="renderQuad" startColor="#2228" endColor="#2220" post="true" length="150" />
            <onDisabled name="renderQuad" startColor="#2220" endColor="#2228" post="true" length="150" />
        </effect>
    </style>
 
    <!-- NEW BUTTON CONTROL - - - - - - - - - - - - - - - - - - - - - - - - - -  -->      
    <controlDefinition name="newButton" style="new-Button">
        <interact onClick="$action"/>
        <panel style="#panel" 
               focusable="true" 
               controller="mygame.gui.controllers.NewButtonController" 
               inputMapping="de.lessvoid.nifty.input.mapping.MenuInputMapping" 
              >
            <!--interact onClick="newButtonClicked()" /-->
        </panel>
    </controlDefinition>

<layer backgroundColor="#0000" childLayout="absolute" visibleToMouse="true" >
 <control name="newButton" x="100" y="100" width="64" height="64" />
</layer>  

so i want to have a standard panel wich i can change image on different events
and also be able to use the interact onclick to setup the appropriate callback

so far the default button implementation does not really behave like a normal button (like windows/gnome gui)

plz help

thx

I would take a look at the nifty bible and the section on how to listen to events. Specifically, look for the “NiftyEventSubscriber” tag. I use that tag pretty extensively in my inventory system. If you still aren’t getting mouse events out of that then I would take a very close look at the visible to mouse tag and make sure its on the control in question. I’ve spent several days pulling my hair out trying to figure out why I wasn’t getting certain mouse events and it was because visible to mouse was on the wrong element.

<cite>@glh3586 said:</cite> I would take a look at the nifty bible and the section on how to listen to events. Specifically, look for the "NiftyEventSubscriber" tag. I use that tag pretty extensively in my inventory system. If you still aren't getting mouse events out of that then I would take a very close look at the visible to mouse tag and make sure its on the control in question. I've spent several days pulling my hair out trying to figure out why I wasn't getting certain mouse events and it was because visible to mouse was on the wrong element.

thx

i already put visibletomouse in many place to give it a try
also the niftyeventsubscriber is(if i understand it well) not meant inside the button controller but rather for button instances

thx anyway

i’ll keep digging

<cite>@curtisnewton said:</cite> also the niftyeventsubscriber is(if i understand it well) not meant inside the button controller but rather for button instances
There is no reason to not use it in the controller if you want to do something custom. That being said, i'm pretty sure you can get the effect you want to achieve by pure xml styling using the existing nifty effects.
<cite>@glh3586 said:</cite> There is no reason to not use it in the controller if you want to do something custom. That being said, i'm pretty sure you can get the effect you want to achieve by pure xml styling using the existing nifty effects.

but the event subscriber needs an element instance id (???)

i already tried with effects, it is not easy

i first tried to tweak the existing button implementation , but i get the effect putting an image over the existing background image wich is not what i want

You can use regular expressions to target a group of id’s instead of just one. This works especially since the button content is a child of the button’s “top level” control. I had a button setup like you are describing using the change image effect somewhere. If I find it i’ll try to post it for you.

<cite>@glh3586 said:</cite> There is no reason to not use it in the controller if you want to do something custom. That being said, i'm pretty sure you can get the effect you want to achieve by pure xml styling using the existing nifty effects.

well i i’ll just do it the simple way

my problem is that if i use the onclic onmouseover to change the buton image, then i cant use it for special cases depending on the button instance i create

if is define a control with an onclick=“…”, then as i create a control instance with an other onclick, the previous one will be overriden

[edit] ok i think i found the trick page 75 of the nifty manual . thx for your help anyway