Skip to content

Commit 3eaa540

Browse files
committed
fix VGui buttons not being clickable on newer GCC versions
copied nearly verbatim from CSGO, thanks to ficool2 for pointing out there was a better fix
1 parent cf5afe5 commit 3eaa540

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/vgui2/vgui_controls/Button.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -688,20 +688,27 @@ void Button::SetReleasedSound(const char *sound)
688688
}
689689
}
690690

691+
inline int MouseCodeToMask( MouseCode code )
692+
{
693+
// MouseCodes do not start at zero. Make them start at zero before trying to fit them into a 32 bit mask..
694+
// Otherwise, you would be trying to set bit 107 of an integer, and that would be bad.
695+
const int recode = code - MOUSE_FIRST;
696+
AssertMsg1( recode >= 0 && recode < 32, "MouseCode %d is invalid and cannot fit into a 32-bit mask\n", code );
697+
return 1 << recode ;
698+
}
699+
691700
//-----------------------------------------------------------------------------
692701
// Purpose: Set button to be mouse clickable or not.
693702
//-----------------------------------------------------------------------------
694703
void Button::SetMouseClickEnabled(MouseCode code,bool state)
695704
{
696-
if(state)
705+
if (state)
697706
{
698-
//set bit to 1
699-
_mouseClickMask|=1<<((int)(code+1));
707+
_mouseClickMask |= MouseCodeToMask(code); //set bit to 1
700708
}
701709
else
702710
{
703-
//set bit to 0
704-
_mouseClickMask&=~(1<<((int)(code+1)));
711+
_mouseClickMask &= ~MouseCodeToMask(code); //set bit to 0
705712
}
706713
}
707714

@@ -710,7 +717,7 @@ void Button::SetMouseClickEnabled(MouseCode code,bool state)
710717
//-----------------------------------------------------------------------------
711718
bool Button::IsMouseClickEnabled(MouseCode code)
712719
{
713-
if(_mouseClickMask&(1<<((int)(code+1))))
720+
if ( _mouseClickMask & MouseCodeToMask(code) )
714721
{
715722
return true;
716723
}

0 commit comments

Comments
 (0)