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