# Custom UI Button issue...



## Lindon (Aug 4, 2010)

Hi everyone, I've searched the forum but I cant seem to find an answer for this one:

I need a custom UI for buttons, for "on" and "off", *BUT* I cant assign/read a picture from disk(using $CONTROL_PAR_PICTURE) when the button changes state, as I have so many buttons and they change so frequently (16 times each bar) that my script spends all its time reading from disk, the sounds play fine, but the UI becomes unusable..

I can add a picture at "on init" with several frames, so (say) button size = 40 x 40 and image = 40 x 120 (three images piled on top of each other) and then use the image.txt file to set animations = 3. This gets me a nice button with an off image, a roll-over image and a clicked image, but for the life of me I cant get an "on" image, and I cant programatically set the images to match button state (i.e. on or off). I cant use $CONTROL_PAR_PICTURE_STATE on buttons so this is no help. 

Sure I could use $ui_label as per the dummyworld example, but I need to capture the click on the widget,so it has to be a button.

Can anyone point me at a solution for this?


----------



## EvilDragon (Aug 5, 2010)

Buttons need to have SIX states, not three.

1 off
2 on
3 off, mouse down
4 on, mouse down
5 off, mouse over
6 on, mouse over


----------



## TechLo (Aug 5, 2010)

Is there any documentation out there about how the button states work? I certainly haven't seen any in the NI KSP pdf. Oh well, I never use buttons anyway. I use switches, which are midi automatable, and you only have to worry about two states -- off and on, lol, which you control with the $CONTROL_PAR_PICTURE, obviously. Not fancy, I guess, but imminently usable.

Random tip for using switches: clicking on the gui with the mouse automatically changes the switch value on and off, but triggering the switch with a midi cc doesn't -- you have to query the on/off value and then flip it.


----------



## Lindon (Aug 5, 2010)

Thanks ED for this, I managed to work this out on my own on the laptop on my way in to work this morning...but thanks anyway. Working fine now.


----------



## EvilDragon (Aug 5, 2010)

Buttons and switches have the same UI graphics, so they are essentially the same visually, and they use the same 6 states.


----------



## TechLo (Aug 5, 2010)

EvilDragon @ Thu Aug 05 said:


> Buttons and switches have the same UI graphics, so they are essentially the same visually, and they use the same 6 states.



Hmm, I did not know that, lol. Even the briefest of mentions in the KSP manual would have been useful. I guess everyone has to learn about script graphics by reverse engineering what's in the library files. For my scripting project, where everything on the gui is controllable via midi cc, I guess I'm fine with just 2 states for every button (the most you can use via midi controller anyway) as it simplifies the coding wherein I already have to code for both ui_control and on controller control of the same elements.


----------



## EvilDragon (Aug 5, 2010)

KSP manual says "ui_switch is similiar to ui_button, however it's possible to automate the control."

So, for all intents and purposes, they are the same, except switches can be automated.


----------



## TechLo (Aug 5, 2010)

Well yeah, it's just that nowhere in the ksp manual does it explain the use or sequence of animation stages for gui controls.


----------



## EvilDragon (Aug 5, 2010)

That's explained in Kontakt Player Develope Guide.


----------



## TechLo (Aug 5, 2010)

Ah. I don't have Kontakt Player of the Developer Guide. Where does one obtain the Developer Guide? Thanks, ED.


----------



## kotori (Aug 6, 2010)

EvilDragon @ Thu Aug 05 said:


> Buttons and switches have the same UI graphics, so they are essentially the same visually, and they use the same 6 states.



Here are a couple of differences between ui_button and ui_switch that I haven't seen documented:

the value of a ui_button is set upon mouse-up if the mouse cursor is within the bounds-rect of the button.
the value of a ui_switch is set upon mouse-down so even if you have a mouse-down inside the bounds of the switch and then release the mouse button outside the switch will remain changed.

in case of multiple overlapping controls the mouse-over state of a ui_button is displayed only for top-most one.
in case of multiple overlapping controls the mouse-over state of ui_switches is displayed for all controls that the mouse cursor is over - not only the top-most one.

the mouse-over state of ui_switches is not reliable in the case of overlapping controls. Depending on whether you move the mouse cursor quickly or slowly over the controls you may end up with different looks. A mouse-over state of ui_switch can be shown even though the mouse is not placed over it. If a ui_switch is shown/hidden when it's being pressed it can get stuck in the wrong ui state, but this last problem may have been fixed in the latest Kontakt version - I haven't check that yet.

I hope this can be of help to someone.

Cheers,
Nils


----------



## gregjazz (Aug 6, 2010)

One other difference between buttons and switches is that the centered text alignment on buttons is generally too far to the right. Switches have this corrected.


----------



## olmerk (Jan 20, 2017)

In order not to create another thread... I found strange behavior of a button. As I click one, it goes to "pressed" state, but as I release it, it doesn't come back to "unpressed" state, only when I hover off it. And there is no picture skinned to this button, nor any actions assigned to ui_control for it. What can it be?


----------



## Lindon (Jan 20, 2017)

buttons are state based, press once = ON, press again to = OFF. 

As an aside its sort of nice to be reminded of my original post from 2010, 7 years of this KSP thing and I'm still not a millionaire... go figure...


----------



## olmerk (Jan 31, 2017)

Lindon said:


> buttons are state based, press once = ON, press again to = OFF.



Ooops, sorry I re-read my post and now see it's a bit misleading. This is what's happening with that button:
1) The button resides in OFF state
2) I hover over it and it changes its look to mouse over OFF state
3) I click it and it changes its look to mouse down OFF state
4) I release it and it must switch to mouse ON state (must get white if no picture is assigned to it), but in my case this doesn't happen until I hover off the button (actually just do any tiny motion by mouse), then it lights up.


----------



## Yahiaamine (Jan 31, 2017)

what about UI Menus? 
do they have the same number of frames as Buttons/swiches


----------



## Lindon (Feb 1, 2017)

olmerk said:


> Ooops, sorry I re-read my post and now see it's a bit misleading. This is what's happening with that button:
> 1) The button resides in OFF state
> 2) I hover over it and it changes its look to mouse over OFF state
> 3) I click it and it changes its look to mouse down OFF state
> 4) I release it and it must switch to mouse ON state (must get white if no picture is assigned to it), but in my case this doesn't happen until I hover off the button (actually just do any tiny motion by mouse), then it lights up.


you have all 6 images stacked in the right order?


----------



## andreasOL (Feb 1, 2017)

Yahiaamine said:


> what about UI Menus?
> do they have the same number of frames as Buttons/swiches



No, unfortunately not much that can be done to a menu. Only one frame which replaces the background of the closed menu.


----------



## EvilDragon (Feb 1, 2017)

Actually, menus do use custom graphics just like buttons, but only frames 1, 3 and 5.


----------



## olmerk (Feb 1, 2017)

Lindon said:


> you have all 6 images stacked in the right order?



Strange behavior happens without any graphics assigned to that button.


----------



## andreasOL (Feb 3, 2017)

EvilDragon said:


> Actually, menus do use custom graphics just like buttons, but only frames 1, 3 and 5.



Ah...oh...thanks


----------

