From 245b03fc4634d7e5f8b5cf1f70cb06bab6f35465 Mon Sep 17 00:00:00 2001 From: AJ Kelly Date: Wed, 23 Feb 2011 03:11:49 -0600 Subject: [PATCH] more mouse work... themers on windows can now get mouse x/y coords --- src/InputFilter.cpp | 42 ++++++++++++++++++- src/InputFilter.h | 14 ++++++- src/RageInput.cpp | 4 +- src/RageInputDevice.cpp | 10 +++-- .../InputHandler/InputHandler_DirectInput.cpp | 11 ++--- 5 files changed, 68 insertions(+), 13 deletions(-) diff --git a/src/InputFilter.cpp b/src/InputFilter.cpp index a4a602d185..b70555edcc 100644 --- a/src/InputFilter.cpp +++ b/src/InputFilter.cpp @@ -6,6 +6,8 @@ #include "RageThreads.h" #include "Preference.h" #include "Foreach.h" +// for mouse stuff: -aj +#include "PrefsManager.h" #include struct ButtonState @@ -94,12 +96,26 @@ InputFilter::InputFilter() Reset(); ResetRepeatRate(); + + m_MouseCoords.fX = 0; + m_MouseCoords.fY = 0; + + // Register with Lua. + { + Lua *L = LUA->Get(); + lua_pushstring( L, "INPUTFILTER" ); + this->PushSelf( L ); + lua_settable( L, LUA_GLOBALSINDEX ); + LUA->Release( L ); + } } InputFilter::~InputFilter() { delete queuemutex; g_ButtonStates.clear(); + // Unregister with Lua. + LUA->UnsetGlobal( "INPUTFILTER" ); } void InputFilter::Reset() @@ -392,11 +408,33 @@ void InputFilter::GetPressedButtons( vector &array ) const array = g_CurrentState; } -void InputFilter::UpdateCursorLocation() +void InputFilter::UpdateCursorLocation(float _fX, float _fY) { - // todo + m_MouseCoords.fX = clamp(_fX, 0, (PREFSMAN->m_iDisplayHeight * PREFSMAN->m_fDisplayAspectRatio)); + m_MouseCoords.fY = clamp(_fY, 0, PREFSMAN->m_iDisplayHeight); } + +// lua start +#include "LuaBinding.h" + +/** @brief Allow Lua to have access to InputFilter. */ +class LunaInputFilter: public Luna +{ +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; } + + LunaInputFilter() + { + ADD_METHOD( GetMouseX ); + ADD_METHOD( GetMouseY ); + } +}; + +LUA_REGISTER_CLASS( InputFilter ) +// lua end + /* * (c) 2001-2004 Chris Danford * All rights reserved. diff --git a/src/InputFilter.h b/src/InputFilter.h index 7f6c010a2e..65fb47bed9 100644 --- a/src/InputFilter.h +++ b/src/InputFilter.h @@ -33,6 +33,12 @@ struct InputEvent DeviceInputList m_ButtonState; }; +struct MouseCoordinates +{ + float fX; + float fY; +}; + class RageMutex; struct ButtonState; class InputFilter @@ -63,7 +69,12 @@ public: void GetPressedButtons( vector &array ) const; // cursor - void UpdateCursorLocation(); + void UpdateCursorLocation(float _fX, float _fY); + float GetCursorX(){ return m_MouseCoords.fX; } + float GetCursorY(){ return m_MouseCoords.fY; } + + // Lua + void PushSelf( lua_State *L ); private: void CheckButtonChange( ButtonState &bs, DeviceInput di, const RageTimer &now ); @@ -72,6 +83,7 @@ private: vector queue; RageMutex *queuemutex; + MouseCoordinates m_MouseCoords; }; extern InputFilter* INPUTFILTER; // global and accessable from anywhere in our program diff --git a/src/RageInput.cpp b/src/RageInput.cpp index fa5b29d8f9..786cf4aca5 100644 --- a/src/RageInput.cpp +++ b/src/RageInput.cpp @@ -6,7 +6,7 @@ #include "Preference.h" #include "LuaManager.h" -RageInput* INPUTMAN = NULL; // globally accessable input device +RageInput* INPUTMAN = NULL; // globally accessable input device static Preference g_sInputDrivers( "InputDrivers", "" ); // "" == DEFAULT_INPUT_DRIVER_LIST @@ -176,7 +176,7 @@ RString RageInput::GetDisplayDevicesString() const // lua start #include "LuaBinding.h" -/** @brief Allow Lua to have access to the RageInput. */ +/** @brief Allow Lua to have access to RageInput. */ class LunaRageInput: public Luna { public: diff --git a/src/RageInputDevice.cpp b/src/RageInputDevice.cpp index c276dea22c..9421dc17b0 100644 --- a/src/RageInputDevice.cpp +++ b/src/RageInputDevice.cpp @@ -14,7 +14,6 @@ static const char *InputDeviceStateNames[] = { }; XToString( InputDeviceState ); - static map g_mapNamesToString; static map g_mapStringToNames; static void InitNames() @@ -144,8 +143,7 @@ RString DeviceButtonToString( DeviceButton key ) InitNames(); // All printable ASCII except for uppercase alpha characters line up. - if( key >= 33 && key < 127 && - !(key >= 'A' && key <= 'Z' ) ) + if( key >= 33 && key < 127 && !(key >= 'A' && key <= 'Z' ) ) return ssprintf( "%c", key ); if( key >= KEY_OTHER_0 && key < KEY_LAST_OTHER ) @@ -157,6 +155,9 @@ RString DeviceButtonToString( DeviceButton key ) if( key >= MIDI_FIRST && key <= MIDI_LAST ) return ssprintf( "Midi %d", key-MIDI_FIRST ); + if( key >= MOUSE_LEFT && key <= MOUSE_WHEELDOWN ) + return ssprintf( "Mouse %d", key-MOUSE_LEFT ); + map::const_iterator it = g_mapNamesToString.find( key ); if( it != g_mapNamesToString.end() ) return it->second; @@ -181,6 +182,9 @@ DeviceButton StringToDeviceButton( const RString& s ) if( sscanf(s, "Midi %i", &i) == 1 ) return enum_add2( MIDI_FIRST, i ); + if( sscanf(s, "Mouse %i", &i) == 1 ) + return enum_add2( MOUSE_LEFT, i ); + map::const_iterator it = g_mapStringToNames.find( s ); if( it != g_mapStringToNames.end() ) return it->second; diff --git a/src/arch/InputHandler/InputHandler_DirectInput.cpp b/src/arch/InputHandler/InputHandler_DirectInput.cpp index 513041a124..a96ef97a63 100644 --- a/src/arch/InputHandler/InputHandler_DirectInput.cpp +++ b/src/arch/InputHandler/InputHandler_DirectInput.cpp @@ -501,19 +501,20 @@ void InputHandler_DInput::UpdateBuffered( DIDevice &device, const RageTimer &tm DeviceButton up = DeviceButton_Invalid, down = DeviceButton_Invalid; if(dev == DEVICE_MOUSE) { - // xxx: mouse position doesn't work here yet -aj float l = int(evtbuf[i].dwData); + POINT cursorPos; + GetCursorPos(&cursorPos); + // convert screen coordinates to client + ScreenToClient(GraphicsWindow::GetHwnd(), &cursorPos); switch(in.ofs) { case DIMOFS_X: up = MOUSE_X_LEFT; down = MOUSE_X_RIGHT; - //cursorX += l; - //LOG->Trace("dwData for mouse x: %f",l); + INPUTFILTER->UpdateCursorLocation((float)cursorPos.x,(float)cursorPos.y); break; case DIMOFS_Y: up = MOUSE_Y_UP; down = MOUSE_Y_DOWN; - //cursorY += l; - //LOG->Trace("dwData for mouse y: %f",l); + INPUTFILTER->UpdateCursorLocation((float)cursorPos.x,(float)cursorPos.y); break; case DIMOFS_Z: up = MOUSE_WHEELUP; down = MOUSE_WHEELDOWN;