Get coordinates of click events on custom controls possible?

hi there!



i have a somewhat bigger project called boxbot2 and i am currently building the gui, more exactly: the options menu.



as you can see, there are custom controls for the sound and music volume settings planned, and i have a slight problem realizing these…



the control is very similar to the progress bar tutorial, but i need to know, where the user clicks inside the control, so that i can adjust the fill percentage and the game sound settings. for example, if the user clicks in the middle of the bar, it should somehow calculate from the click to a float f=0.5f, set the filled part of the bar from left to the click position and set the game volume to 50%.



now… how to get the coordinates information from? :smiley:



there seem some MoveCursor thingamabobs in NiftyInputEvent, but i cant figure out how they work (yea im quite dumb sometimes '^^)



thx 4 replies

cheers

lostmekka

[java] public void mouseClick(final int mouseX, final int mouseY) {[/java]



[xml]…<interact onClick=“mouseClick()” onClickMouseMove=“mouseClick()” />[/xml]



Nifty will try the method with coordinates first and when it does not find a suitable method it tries a method with the same name that doesn’t have any parameters. So this should work pretty well for you.



You can also check out the new slider control in the source. This control does something similar and you could use it for inspiration :slight_smile:

oh, that looks nice… thanx alot :slight_smile:

maybe i should be looking into the source more ^^

This is the main reason I use the svn from Nifty and not the lib which comes with JME3. Also,l this way, you get the fixes faster. It does take some tinkering to get your IDE to use the svn-source intead of the lib, but once that’s done, iwt works like a charm.

ractoc said:
This is the main reason I use the svn from Nifty and not the lib which comes with JME3. Also,l this way, you get the fixes faster. It does take some tinkering to get your IDE to use the svn-source intead of the lib, but once that's done, iwt works like a charm.

In jMP you just need to follow the instructions to "reduce deployment size" and then create your own NiftyGUI library entry instead of the default one (like explained in "using your own jme3 version").

Ah yes, but I’m using Eclipse

which might be why I found it a tad more difficult. Eventually, I settled on setting up the nifty svn sources as seperate projects and then, in my project, make project dependencies to the nifty projects. Project dependencies always overrule standard jar dependencies.