more mouse work... themers on windows can now get mouse x/y coords
This commit is contained in:
+40
-2
@@ -6,6 +6,8 @@
|
||||
#include "RageThreads.h"
|
||||
#include "Preference.h"
|
||||
#include "Foreach.h"
|
||||
// for mouse stuff: -aj
|
||||
#include "PrefsManager.h"
|
||||
|
||||
#include <set>
|
||||
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<DeviceInput> &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<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; }
|
||||
|
||||
LunaInputFilter()
|
||||
{
|
||||
ADD_METHOD( GetMouseX );
|
||||
ADD_METHOD( GetMouseY );
|
||||
}
|
||||
};
|
||||
|
||||
LUA_REGISTER_CLASS( InputFilter )
|
||||
// lua end
|
||||
|
||||
/*
|
||||
* (c) 2001-2004 Chris Danford
|
||||
* All rights reserved.
|
||||
|
||||
+13
-1
@@ -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<DeviceInput> &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<InputEvent> queue;
|
||||
RageMutex *queuemutex;
|
||||
MouseCoordinates m_MouseCoords;
|
||||
};
|
||||
|
||||
extern InputFilter* INPUTFILTER; // global and accessable from anywhere in our program
|
||||
|
||||
+2
-2
@@ -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<RString> 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<RageInput>
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -14,7 +14,6 @@ static const char *InputDeviceStateNames[] = {
|
||||
};
|
||||
XToString( InputDeviceState );
|
||||
|
||||
|
||||
static map<DeviceButton,RString> g_mapNamesToString;
|
||||
static map<RString,DeviceButton> 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<DeviceButton,RString>::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<RString,DeviceButton>::const_iterator it = g_mapStringToNames.find( s );
|
||||
if( it != g_mapStringToNames.end() )
|
||||
return it->second;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user