alright, now mouse support is getting somewhere.

This commit is contained in:
AJ Kelly
2011-02-23 04:33:55 -06:00
parent 471236d29d
commit d78b379464
5 changed files with 79 additions and 41 deletions
+17 -4
View File
@@ -8,6 +8,7 @@
#include "Foreach.h"
// for mouse stuff: -aj
#include "PrefsManager.h"
#include "ScreenDimensions.h"
#include <set>
struct ButtonState
@@ -410,8 +411,8 @@ void InputFilter::GetPressedButtons( vector<DeviceInput> &array ) const
void InputFilter::UpdateCursorLocation(float _fX, float _fY)
{
m_MouseCoords.fX = clamp(_fX, 0, (PREFSMAN->m_iDisplayHeight * PREFSMAN->m_fDisplayAspectRatio));
m_MouseCoords.fY = clamp(_fY, 0, PREFSMAN->m_iDisplayHeight);
m_MouseCoords.fX = _fX;
m_MouseCoords.fY = _fY;
}
@@ -422,8 +423,20 @@ void InputFilter::UpdateCursorLocation(float _fX, float _fY)
class LunaInputFilter: public Luna<InputFilter>
{
public:
static int GetMouseX( T* p, lua_State *L ){ lua_pushnumber( L, p->GetCursorX() ); return 1; }
static int GetMouseY( T* p, lua_State *L ){ lua_pushnumber( L, p->GetCursorY() ); return 1; }
static int GetMouseX( T* p, lua_State *L ){
float fX = p->GetCursorX();
// scale input
fX = SCALE( fX, 0, (PREFSMAN->m_iDisplayHeight * PREFSMAN->m_fDisplayAspectRatio), SCREEN_LEFT, SCREEN_RIGHT );
lua_pushnumber( L, fX );
return 1;
}
static int GetMouseY( T* p, lua_State *L ){
float fY = p->GetCursorY();
// scale input
fY = SCALE( fY, 0, PREFSMAN->m_iDisplayHeight, SCREEN_TOP, SCREEN_BOTTOM );
lua_pushnumber( L, fY );
return 1;
}
LunaInputFilter()
{
+6
View File
@@ -81,6 +81,12 @@ static const char *MessageIDNames[] = {
"LifeMeterChangedP1",
"LifeMeterChangedP2",
"UpdateScreenHeader",
// should these be here? -aj
"LeftClick",
"RightClick",
"MiddleClick",
"MouseWheelUp",
"MouseWheelDown",
};
XToString( MessageID );
+6
View File
@@ -78,6 +78,12 @@ enum MessageID
Message_LifeMeterChangedP1,
Message_LifeMeterChangedP2,
Message_UpdateScreenHeader,
// should these be here? -aj
Message_LeftClick,
Message_RightClick,
Message_MiddleClick,
Message_MouseWheelUp,
Message_MouseWheelDown,
NUM_MessageID, // leave this at the end
MessageID_Invalid
};
+28 -15
View File
@@ -195,24 +195,37 @@ void Screen::Input( const InputEventPlus &input )
return; // don't care
}
// Always broadcast clicks -aj
if( input.DeviceI == DeviceInput( DEVICE_MOUSE, MOUSE_LEFT ) )
MESSAGEMAN->Broadcast( (MessageID)(Message_LeftClick) );
if( input.DeviceI == DeviceInput( DEVICE_MOUSE, MOUSE_RIGHT ) )
MESSAGEMAN->Broadcast( (MessageID)(Message_RightClick) );
if( input.DeviceI == DeviceInput( DEVICE_MOUSE, MOUSE_MIDDLE ) )
MESSAGEMAN->Broadcast( (MessageID)(Message_MiddleClick) );
// Can't do MouseWheelUp and MouseWheelDown at the same time. -aj
if( input.DeviceI == DeviceInput( DEVICE_MOUSE, MOUSE_WHEELUP ) )
MESSAGEMAN->Broadcast( (MessageID)(Message_MouseWheelUp) );
else if( input.DeviceI == DeviceInput( DEVICE_MOUSE, MOUSE_WHEELDOWN ) )
MESSAGEMAN->Broadcast( (MessageID)(Message_MouseWheelDown) );
// default input handler used by most menus
switch( input.MenuI )
{
case GAME_BUTTON_MENUUP: this->MenuUp ( input ); return;
case GAME_BUTTON_MENUDOWN: this->MenuDown ( input ); return;
case GAME_BUTTON_MENULEFT: this->MenuLeft ( input ); return;
case GAME_BUTTON_MENURIGHT: this->MenuRight ( input ); return;
case GAME_BUTTON_BACK:
// Don't make the user hold the back button if they're pressing escape and escape is the back button.
if( !PREFSMAN->m_bDelayedBack || input.type==IET_REPEAT || (input.DeviceI.device == DEVICE_KEYBOARD && input.DeviceI.button == KEY_ESC) )
{
if( HANDLE_BACK_BUTTON )
this->MenuBack( input );
}
return;
case GAME_BUTTON_START: this->MenuStart ( input ); return;
case GAME_BUTTON_SELECT:this->MenuSelect( input ); return;
case GAME_BUTTON_COIN: this->MenuCoin ( input ); return;
case GAME_BUTTON_MENUUP: this->MenuUp ( input ); return;
case GAME_BUTTON_MENUDOWN: this->MenuDown ( input ); return;
case GAME_BUTTON_MENULEFT: this->MenuLeft ( input ); return;
case GAME_BUTTON_MENURIGHT: this->MenuRight ( input ); return;
case GAME_BUTTON_BACK:
// Don't make the user hold the back button if they're pressing escape and escape is the back button.
if( !PREFSMAN->m_bDelayedBack || input.type==IET_REPEAT || (input.DeviceI.device == DEVICE_KEYBOARD && input.DeviceI.button == KEY_ESC) )
{
if( HANDLE_BACK_BUTTON )
this->MenuBack( input );
}
return;
case GAME_BUTTON_START: this->MenuStart ( input ); return;
case GAME_BUTTON_SELECT:this->MenuSelect( input ); return;
case GAME_BUTTON_COIN: this->MenuCoin ( input ); return;
}
}
+22 -22
View File
@@ -106,18 +106,18 @@ wchar_t InputHandler::DeviceButtonToChar( DeviceButton button, bool bUseCurrentK
return c;
}
static LocalizedString HOME ( "DeviceButton", "Home" );
static LocalizedString HOME ( "DeviceButton", "Home" );
static LocalizedString END ( "DeviceButton", "End" );
static LocalizedString UP ( "DeviceButton", "Up" );
static LocalizedString DOWN ( "DeviceButton", "Down" );
static LocalizedString SPACE ( "DeviceButton", "Space" );
static LocalizedString SHIFT ( "DeviceButton", "Shift" );
static LocalizedString CTRL ( "DeviceButton", "Ctrl" );
static LocalizedString DOWN ( "DeviceButton", "Down" );
static LocalizedString SPACE ( "DeviceButton", "Space" );
static LocalizedString SHIFT ( "DeviceButton", "Shift" );
static LocalizedString CTRL ( "DeviceButton", "Ctrl" );
static LocalizedString ALT ( "DeviceButton", "Alt" );
static LocalizedString INSERT ( "DeviceButton", "Insert" );
static LocalizedString INSERT ( "DeviceButton", "Insert" );
static LocalizedString DEL ( "DeviceButton", "Delete" );
static LocalizedString PGUP ( "DeviceButton", "PgUp" );
static LocalizedString PGDN ( "DeviceButton", "PgDn" );
static LocalizedString PGUP ( "DeviceButton", "PgUp" );
static LocalizedString PGDN ( "DeviceButton", "PgDn" );
static LocalizedString BACKSLASH ( "DeviceButton", "Backslash" );
RString InputHandler::GetDeviceSpecificInputString( const DeviceInput &di )
@@ -128,7 +128,7 @@ RString InputHandler::GetDeviceSpecificInputString( const DeviceInput &di )
if( di.device == DEVICE_KEYBOARD )
{
wchar_t c = DeviceButtonToChar( di.button, false );
if( c && c != L' ' ) // Don't show "Key " for space.
if( c && c != L' ' ) // Don't show "Key " for space.
return InputDeviceToString( di.device ) + " " + Capitalize( WStringToRString(wstring()+c) );
}
@@ -142,19 +142,19 @@ RString InputHandler::GetLocalizedInputString( const DeviceInput &di )
{
switch( di.button )
{
case KEY_HOME: return HOME.GetValue();
case KEY_END: return END.GetValue();
case KEY_UP: return UP.GetValue();
case KEY_DOWN: return DOWN.GetValue();
case KEY_SPACE: return SPACE.GetValue();
case KEY_LSHIFT: case KEY_RSHIFT: return SHIFT.GetValue();
case KEY_LCTRL: case KEY_RCTRL: return CTRL.GetValue();
case KEY_LALT: case KEY_RALT: return ALT.GetValue();
case KEY_INSERT: return INSERT.GetValue();
case KEY_DEL: return DEL.GetValue();
case KEY_PGUP: return PGUP.GetValue();
case KEY_PGDN: return PGDN.GetValue();
case KEY_BACKSLASH: return BACKSLASH.GetValue();
case KEY_HOME: return HOME.GetValue();
case KEY_END: return END.GetValue();
case KEY_UP: return UP.GetValue();
case KEY_DOWN: return DOWN.GetValue();
case KEY_SPACE: return SPACE.GetValue();
case KEY_LSHIFT: case KEY_RSHIFT: return SHIFT.GetValue();
case KEY_LCTRL: case KEY_RCTRL: return CTRL.GetValue();
case KEY_LALT: case KEY_RALT: return ALT.GetValue();
case KEY_INSERT: return INSERT.GetValue();
case KEY_DEL: return DEL.GetValue();
case KEY_PGUP: return PGUP.GetValue();
case KEY_PGDN: return PGDN.GetValue();
case KEY_BACKSLASH: return BACKSLASH.GetValue();
default:
wchar_t c = DeviceButtonToChar( di.button, false );
if( c && c != L' ' ) // Don't show "Key " for space.