Mouse-over cursors in Lemur

After looking through docs and such, I couldn’t find a trivial way to make the mouse cursor change to a “hand” icon when hovering over a button or another clickable component. Is adding commands to each component the best way to do this, or is there some better way which is a little more automatic?

button.addCommands(Button.ButtonAction.HighlightOn, (Command<Button>) (Button source) -> {
    inputManager.setMouseCursor((JmeCursor) assetManager.loadAsset("Interface/hand.cur"));
button.addCommands(Button.ButtonAction.HighlightOff, (Command<Button>) (Button source) -> {

I guess I could subclass Button and any other types, but maybe that’s overkill if it’s just for this.

You could define those commands in a style that automatically applies to all buttons. Or you could do them as an effect and do the same thing.

Okay, via style is how I was hoping it’d work, I’ll look into how to do that–thanks.

Got it done via style.

In the process I discovered that apparently Groovy doesn’t give two shits about Java access modifiers (!?!?) and just does its own thing.

I was going to come back here saying that it doesn’t seem possible to access InputManager to change the cursor, but after noticing that you can call GuiGlobals.getAssetManager() (which I thought was public at first, but is protected), I tried accessing the private inputManager reference inside InputMapper… which surprisingly worked…

After some brief head scratching and some DuckDuckGo searches–I found out these shenanigans are expected. Okay, I’ll just go with the flow I guess. It did avoid a problem here, at least.

For anyone interested this is probably enough to figure out what to put in your groovy style config:

import com.jme3.asset.AssetManager;
import com.jme3.input.InputManager;

InputManager inputManager = GuiGlobals.getInstance().inputMapper.inputManager;
AssetManager assetManager = GuiGlobals.getInstance().assets;

def mouseoverCommand = new Command<Button>() {
    public void execute( Button source ) {
        inputManager.setMouseCursor((JmeCursor) assetManager.loadAsset("Interface/hand.cur"));
def mouseoutCommand = new Command<Button>() {
    public void execute( Button source ) {

def stdButtonCommands = [

selector( "button", "glass" ) {
    background = gradient.clone()
    color = color(1.0, 1.0, 1.0, 1.0)
    background.setColor(color(0, 0.0, 0.0, 0.5))
    insets = new Insets3f( 2, 2, 2, 2 );
    buttonCommands = stdButtonCommands;