Support more mouse buttons. Fixes #195. Patch by 01d55 with some minor cleanup.

This was SVN commit r15609.
This commit is contained in:
JoshuaJB 2014-08-04 01:06:36 +00:00
parent be9d69fd24
commit a719696658
4 changed files with 60 additions and 59 deletions

View file

@ -147,6 +147,7 @@ Right Mouse Button, MouseRight
Middle Mouse Button, MouseMiddle
Mouse Wheel Up, WheelUp
Mouse Wheel Down, WheelDown
MouseButtonX, MouseNX # where X is a number 1-255, for extra mouse buttons
## Special keys for international and non-QWERTY keyboards:
World0, W0

View file

@ -185,19 +185,8 @@ InReaction HotkeyInputHandler( const SDL_Event_* ev )
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
#if SDL_VERSION_ATLEAST(2, 0, 0)
if ((int)ev->ev.button.button <= SDL_BUTTON_RIGHT)
#elif SDL_VERSION_ATLEAST(1, 2, 13)
if ((int)ev->ev.button.button <= SDL_BUTTON_X2)
#else
if ((int)ev->ev.button.button <= SDL_BUTTON_WHEELDOWN)
#endif
{
keycode = CUSTOM_SDL_KEYCODE + (int)ev->ev.button.button;
break;
}
return IN_PASS;
keycode = MOUSE_BASE + (int)ev->ev.button.button;
break;
#if SDL_VERSION_ATLEAST(2, 0, 0)
case SDL_MOUSEWHEEL:
if (ev->ev.wheel.y > 0)

View file

@ -332,34 +332,38 @@ static SKeycodeMapping keycodeMapping[] =
void InitKeyNameMap()
{
SKeycodeMapping* it = keycodeMapping;
while( it->keycode != 0 )
for (SKeycodeMapping* it = keycodeMapping; it->keycode != 0; it++)
{
keymap.insert( std::pair<CStr,int>( CStr( it->keyname ).LowerCase(), it->keycode ) );
if( it->altkeyname )
keymap.insert( std::pair<CStr,int>( CStr( it->altkeyname ).LowerCase(), it->keycode ) );
it++;
};
keymap.insert(std::pair<CStr,int>(CStr(it->keyname).LowerCase(), it->keycode));
if(it->altkeyname)
keymap.insert(std::pair<CStr,int>(CStr(it->altkeyname).LowerCase(), it->keycode));
}
// Extra mouse buttons.
for (int i = 1; i < 256; ++i) // There is no mouse 0
{
keymap.insert(std::pair<CStr,int>("mousebutton" + CStr::FromInt(i), MOUSE_BASE + i));
keymap.insert(std::pair<CStr,int>("mousen" + CStr::FromInt(i), MOUSE_BASE + i));
}
}
int FindKeyCode( const CStr& keyname )
int FindKeyCode(const CStr& keyname)
{
std::map<CStr,int>::iterator it;
it = keymap.find( keyname.LowerCase() );
if( it != keymap.end() )
return( it->second );
return( 0 );
it = keymap.find(keyname.LowerCase());
if (it != keymap.end())
return(it->second);
return 0;
}
CStr FindKeyName( int keycode )
{
CStr FindKeyName(int keycode)
{
SKeycodeMapping* it = keycodeMapping;
while( it->keycode != 0 )
{
if( it->keycode == keycode )
return( CStr( it->keyname ) );
}
return( CStr( "Unknown" ) );
while (it->keycode != 0)
if (it->keycode == keycode)
return CStr(it->keyname);
return CStr("Unknown");
}

View file

@ -35,37 +35,44 @@ extern int FindKeyCode( const CStr8& keyname );
#endif
enum {
// 'Keycodes' for the mouse buttons
MOUSE_LEFT = CUSTOM_SDL_KEYCODE + SDL_BUTTON_LEFT,
MOUSE_RIGHT = CUSTOM_SDL_KEYCODE + SDL_BUTTON_RIGHT,
MOUSE_MIDDLE = CUSTOM_SDL_KEYCODE + SDL_BUTTON_MIDDLE,
#if SDL_VERSION_ATLEAST(2, 0, 0)
// SDL2 doesn't count wheels as buttons, so just give them the next sequential IDs
MOUSE_X1 = CUSTOM_SDL_KEYCODE + SDL_BUTTON_X1,
MOUSE_X2 = CUSTOM_SDL_KEYCODE + SDL_BUTTON_X2,
MOUSE_WHEELUP,
MOUSE_WHEELDOWN,
#elif SDL_VERSION_ATLEAST(1, 2, 13)
// SDL 1.2 defines wheel buttons before X1/X2 buttons
MOUSE_WHEELUP = CUSTOM_SDL_KEYCODE + SDL_BUTTON_WHEELUP,
MOUSE_WHEELDOWN = CUSTOM_SDL_KEYCODE + SDL_BUTTON_WHEELDOWN,
MOUSE_X1 = CUSTOM_SDL_KEYCODE + SDL_BUTTON_X1,
MOUSE_X2 = CUSTOM_SDL_KEYCODE + SDL_BUTTON_X2,
#else
// SDL <1.2.13 doesn't support X1/X2 buttons, so define them manually
MOUSE_WHEELUP = CUSTOM_SDL_KEYCODE + SDL_BUTTON_WHEELUP,
MOUSE_WHEELDOWN = CUSTOM_SDL_KEYCODE + SDL_BUTTON_WHEELDOWN,
MOUSE_X1 = CUSTOM_SDL_KEYCODE + SDL_BUTTON_WHEELDOWN + 1,
MOUSE_X2 = CUSTOM_SDL_KEYCODE + SDL_BUTTON_WHEELDOWN + 2,
#endif
// Start sequential IDs in the right place
EXTRA_KEYS_BASE = CUSTOM_SDL_KEYCODE,
// 'Keycodes' for the unified modifier keys
UNIFIED_SHIFT,
UNIFIED_CTRL,
UNIFIED_ALT,
UNIFIED_SUPER,
UNIFIED_LAST
UNIFIED_LAST,
// 'Keycodes' for the mouse buttons
// SDL2 doesn't count wheels as buttons, so just give them the previous sequential IDs
#if SDL_VERSION_ATLEAST(2, 0, 0)
MOUSE_WHEELUP,
MOUSE_WHEELDOWN,
#endif
// Base for mouse buttons.
// Everything less than MOUSE_BASE is not reported by an SDL mouse button event.
// Everything greater than MOUSE_BASE is reported by an SDL mouse button event.
MOUSE_BASE,
MOUSE_LEFT = MOUSE_BASE + SDL_BUTTON_LEFT,
MOUSE_RIGHT = MOUSE_BASE + SDL_BUTTON_RIGHT,
MOUSE_MIDDLE = MOUSE_BASE + SDL_BUTTON_MIDDLE,
#if SDL_VERSION_ATLEAST(2, 0, 0)
MOUSE_X1 = MOUSE_BASE + SDL_BUTTON_X1,
MOUSE_X2 = MOUSE_BASE + SDL_BUTTON_X2,
#elif SDL_VERSION_ATLEAST(1, 2, 13)
// SDL 1.2 defines wheel buttons before X1/X2 buttons
MOUSE_WHEELUP = MOUSE_BASE + SDL_BUTTON_WHEELUP,
MOUSE_WHEELDOWN = MOUSE_BASE + SDL_BUTTON_WHEELDOWN,
MOUSE_X1 = MOUSE_BASE + SDL_BUTTON_X1,
MOUSE_X2 = MOUSE_BASE + SDL_BUTTON_X2,
#else
// SDL <1.2.13 doesn't support X1/X2 buttons, so define them manually
MOUSE_WHEELUP = MOUSE_BASE + SDL_BUTTON_WHEELUP,
MOUSE_WHEELDOWN = MOUSE_BASE + SDL_BUTTON_WHEELDOWN,
MOUSE_X1 = MOUSE_BASE + SDL_BUTTON_WHEELDOWN + 1,
MOUSE_X2 = MOUSE_BASE + SDL_BUTTON_WHEELDOWN + 2,
#endif
};
#endif // #ifndef INCLUDED_KEYNAME