Jump to content
gc8

Focused button color

Recommended Posts

Hi

I'm trying to make a button change color once it's clicked (and therefore focused) but for some reason I cannot figure the color things out.

 

Here's what I have:

 

class TradeTab: RscButton
{
 colorBackground[] = {0,0,1,1};
 colorFocused[] = {1,0,0,1};
};    

I thought setting colorFocused to red would make the button red when clicked but it just blinks between blue (colorBackground) and red.

 

is it possible to make the button simply change color (and not blink) while focused?

 

thx!

 

Share this post


Link to post
Share on other sites

Use the on#Focus events to change the back ground colour to the same as the focused color.

onSetFocus = "_this select 0 ctrlSetBackgroundColor[ 1, 0, 0, 1 ]";
onKillFocus = "_this select 0 ctrlSetBackgroundColor[ 0, 0, 1, 1 ]";

 

  • Like 2

Share this post


Link to post
Share on other sites
6 hours ago, Larrow said:

Use the on#Focus events to change the back ground colour to the same as the focused color.


onSetFocus = "_this select 0 ctrlSetBackgroundColor[ 1, 0, 0, 1 ]";
onKillFocus = "_this select 0 ctrlSetBackgroundColor[ 0, 0, 1, 1 ]";

 

 

Tried your code but I found out that ctrlSetBackgroundColor does not work with RscButton. The wiki states that. No idea what to try next?

 

Share this post


Link to post
Share on other sites

From one of my UIs:

		class towns : RscButton
		{
			idc = idc_spawnSelection_towns;
			x = 0.2125 * safezoneW + safezoneX;
			y = 0.22 * safezoneH + safezoneY;
			w = 0.1 * safezoneW;
			h = 0.03 * safezoneH;
			text = $STR_spawnSelection_towns;
			period = 0;
			periodFocus = 0;
			periodOver = 0;
			colorFocused[] = {"(profileNamespace getVariable ['GUI_BCG_RGB_R', 0.13])", "(profileNamespace getVariable ['GUI_BCG_RGB_G', 0.54])", "(profileNamespace getVariable ['GUI_BCG_RGB_B', 0.21])", 1};
			colorFocusedSecondary[] = {"(profileNamespace getVariable ['GUI_BCG_RGB_R', 0.13])", "(profileNamespace getVariable ['GUI_BCG_RGB_G', 0.54])", "(profileNamespace getVariable ['GUI_BCG_RGB_B', 0.21])", 1};
			colorBackground2[] = {"(profileNamespace getVariable ['GUI_BCG_RGB_R', 0.13])", "(profileNamespace getVariable ['GUI_BCG_RGB_G', 0.54])", "(profileNamespace getVariable ['GUI_BCG_RGB_B', 0.21])", 1};
			colorBackgroundFocused[] = {"(profileNamespace getVariable ['GUI_BCG_RGB_R', 0.13])", "(profileNamespace getVariable ['GUI_BCG_RGB_G', 0.54])", "(profileNamespace getVariable ['GUI_BCG_RGB_B', 0.21])", 1};
			colorBackgroundActive[] = {"(profileNamespace getVariable ['GUI_BCG_RGB_R', 0.13])", "(profileNamespace getVariable ['GUI_BCG_RGB_G', 0.54])", "(profileNamespace getVariable ['GUI_BCG_RGB_B', 0.21])", 1};
		};

 

  • Like 1

Share this post


Link to post
Share on other sites

@HazJ Thanks, I tried playing with those variables but couldn't yet figure it out.

Share this post


Link to post
Share on other sites

The hover affect isn't permanent. Easy to change though. You may also want to check out:

RscActiveText

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×