File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed
Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff 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// -----------------------------------------------------------------------------
694703void 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// -----------------------------------------------------------------------------
711718bool Button::IsMouseClickEnabled (MouseCode code)
712719{
713- if ( _mouseClickMask&( 1 <<(( int )( code+ 1 ))))
720+ if ( _mouseClickMask & MouseCodeToMask ( code) )
714721 {
715722 return true ;
716723 }
You can’t perform that action at this time.
0 commit comments