2004-06-08 01:24:17 +00:00
|
|
|
/* InputFilter - Checks RageInput and generates a list of InputEvents, representing button presses, releases, and repeats. */
|
|
|
|
|
|
2006-09-02 20:17:17 +00:00
|
|
|
#ifndef INPUT_FILTER_H
|
|
|
|
|
#define INPUT_FILTER_H
|
2002-04-16 17:31:00 +00:00
|
|
|
|
2003-02-16 02:25:46 +00:00
|
|
|
#include "RageInputDevice.h"
|
2002-04-16 17:31:00 +00:00
|
|
|
|
2004-09-09 22:14:33 +00:00
|
|
|
enum InputEventType
|
|
|
|
|
{
|
|
|
|
|
/* The device was just pressed. */
|
|
|
|
|
IET_FIRST_PRESS,
|
|
|
|
|
|
2006-09-13 02:55:19 +00:00
|
|
|
/* The device is auto-repeating. This event is guaranteed to be sent only between
|
2004-09-09 22:14:33 +00:00
|
|
|
* IET_FIRST_PRESS and IET_RELEASE pairs. */
|
2006-09-13 02:59:05 +00:00
|
|
|
IET_REPEAT,
|
2004-09-09 22:14:33 +00:00
|
|
|
|
|
|
|
|
/* The device is no longer pressed. Exactly one IET_RELEASE event will be sent
|
|
|
|
|
* for each IET_FIRST_PRESS. */
|
|
|
|
|
IET_RELEASE,
|
|
|
|
|
};
|
2002-04-16 17:31:00 +00:00
|
|
|
|
2006-09-08 01:11:18 +00:00
|
|
|
struct InputEvent
|
2002-04-16 17:31:00 +00:00
|
|
|
{
|
|
|
|
|
InputEvent() { type=IET_FIRST_PRESS; };
|
|
|
|
|
|
2006-09-08 01:11:18 +00:00
|
|
|
DeviceInput di;
|
2002-04-16 17:31:00 +00:00
|
|
|
InputEventType type;
|
2006-09-08 04:03:14 +00:00
|
|
|
|
|
|
|
|
/* A list of all buttons that were pressed at the time of this event: */
|
|
|
|
|
DeviceInputList m_ButtonState;
|
2002-04-16 17:31:00 +00:00
|
|
|
};
|
|
|
|
|
|
2003-07-26 21:58:48 +00:00
|
|
|
class RageMutex;
|
2005-12-28 20:41:24 +00:00
|
|
|
struct ButtonState;
|
2002-04-16 17:31:00 +00:00
|
|
|
class InputFilter
|
|
|
|
|
{
|
|
|
|
|
public:
|
2006-12-26 22:40:20 +00:00
|
|
|
void ButtonPressed( const DeviceInput &di );
|
2006-01-22 01:00:06 +00:00
|
|
|
void SetButtonComment( const DeviceInput &di, const RString &sComment = "" );
|
2006-09-08 18:59:57 +00:00
|
|
|
void ResetDevice( InputDevice dev );
|
2003-06-21 20:58:40 +00:00
|
|
|
|
2002-09-08 06:10:23 +00:00
|
|
|
InputFilter();
|
2003-07-26 21:58:48 +00:00
|
|
|
~InputFilter();
|
2003-06-22 04:38:05 +00:00
|
|
|
void Reset();
|
2006-09-08 05:06:02 +00:00
|
|
|
void Update( float fDeltaTime );
|
2002-04-16 17:31:00 +00:00
|
|
|
|
2006-09-13 03:01:51 +00:00
|
|
|
void SetRepeatRate( float fDelay, float fRepeatRate );
|
2003-11-25 21:46:30 +00:00
|
|
|
void ResetRepeatRate();
|
2005-10-15 16:47:44 +00:00
|
|
|
void ResetKeyRepeat( const DeviceInput &di );
|
2006-09-14 20:39:54 +00:00
|
|
|
void RepeatStopKey( const DeviceInput &di );
|
2003-11-25 21:46:30 +00:00
|
|
|
|
2006-09-08 04:03:14 +00:00
|
|
|
// If aButtonState is NULL, use the last reported state.
|
2006-09-08 04:26:23 +00:00
|
|
|
bool IsBeingPressed( const DeviceInput &di, const DeviceInputList *pButtonState = NULL ) const;
|
|
|
|
|
float GetSecsHeld( const DeviceInput &di, const DeviceInputList *pButtonState = NULL ) const;
|
2007-01-15 05:35:36 +00:00
|
|
|
float GetLevel( const DeviceInput &di, const DeviceInputList *pButtonState = NULL ) const;
|
2006-01-22 01:00:06 +00:00
|
|
|
RString GetButtonComment( const DeviceInput &di ) const;
|
2002-09-08 06:10:23 +00:00
|
|
|
|
2006-09-07 23:58:46 +00:00
|
|
|
void GetInputEvents( vector<InputEvent> &aEventOut );
|
2006-09-08 18:54:01 +00:00
|
|
|
void GetPressedButtons( vector<DeviceInput> &array ) const;
|
2005-09-19 04:51:49 +00:00
|
|
|
|
|
|
|
|
private:
|
2005-11-06 12:14:35 +00:00
|
|
|
void CheckButtonChange( ButtonState &bs, DeviceInput di, const RageTimer &now );
|
2006-09-08 01:11:18 +00:00
|
|
|
void ReportButtonChange( const DeviceInput &di, InputEventType t );
|
2006-09-08 04:03:14 +00:00
|
|
|
void MakeButtonStateList( vector<DeviceInput> &aInputOut ) const;
|
2005-09-19 04:51:49 +00:00
|
|
|
|
2006-09-07 23:58:46 +00:00
|
|
|
vector<InputEvent> queue;
|
2005-09-19 04:51:49 +00:00
|
|
|
RageMutex *queuemutex;
|
2002-04-16 17:31:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2002-05-19 01:59:48 +00:00
|
|
|
extern InputFilter* INPUTFILTER; // global and accessable from anywhere in our program
|
2002-04-16 17:31:00 +00:00
|
|
|
|
2002-07-31 19:40:40 +00:00
|
|
|
|
2002-11-16 08:07:38 +00:00
|
|
|
#endif
|
2004-06-08 01:24:17 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* (c) 2001-2004 Chris Danford
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, and/or sell copies of the Software, and to permit persons to
|
|
|
|
|
* whom the Software is furnished to do so, provided that the above
|
|
|
|
|
* copyright notice(s) and this permission notice appear in all copies of
|
|
|
|
|
* the Software and that both the above copyright notice(s) and this
|
|
|
|
|
* permission notice appear in supporting documentation.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
|
|
|
|
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
|
|
|
|
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
|
|
|
|
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
|
|
|
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
|
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|