Files
itgmania212121/stepmania/src/InputFilter.h
T

106 lines
3.6 KiB
C++
Raw Normal View History

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,
/* The device is auto-repeating. These events are guaranteed to be sent only between
* IET_FIRST_PRESS and IET_RELEASE pairs. */
IET_SLOW_REPEAT,
IET_FAST_REPEAT,
/* The device is no longer pressed. Exactly one IET_RELEASE event will be sent
* for each IET_FIRST_PRESS. */
IET_RELEASE,
/* The depression level of a button has changed. Read di.level to find the new
* value. This can be sent outside of a IET_FIRST_PRESS/IET_RELEASE pair, since
* a button/axis can have a non-zero level (eg. outside the axis dead zone) without
* being high enough to count as a press. */
IET_LEVEL_CHANGED
};
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;
/* 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:
2005-10-15 16:47:44 +00:00
void ButtonPressed( const DeviceInput &di, bool Down );
2006-01-22 01:00:06 +00:00
void SetButtonComment( const DeviceInput &di, const RString &sComment = "" );
2003-06-21 20:58:40 +00:00
void ResetDevice( InputDevice dev );
InputFilter();
2003-07-26 21:58:48 +00:00
~InputFilter();
2003-06-22 04:38:05 +00:00
void Reset();
void Update(float fDeltaTime);
2002-04-16 17:31:00 +00:00
void SetRepeatRate( float fSlowDelay, float fFastDelay, float fRepeatRate );
void ResetRepeatRate();
2005-10-15 16:47:44 +00:00
void ResetKeyRepeat( const DeviceInput &di );
// If aButtonState is NULL, use the last reported state.
bool IsBeingPressed( const DeviceInput &di, const DeviceInputList *pButtonState = NULL );
float GetSecsHeld( const DeviceInput &di, const DeviceInputList *pButtonState = NULL );
2006-01-22 01:00:06 +00:00
RString GetButtonComment( const DeviceInput &di ) const;
2006-09-07 23:58:46 +00:00
void GetInputEvents( vector<InputEvent> &aEventOut );
2006-09-08 04:10:47 +00:00
void FlushInputEvents();
2005-12-28 20:41:24 +00:00
void GetPressedButtons( vector<DeviceInput> &array );
2005-09-19 04:51:49 +00:00
private:
void CheckButtonChange( ButtonState &bs, DeviceInput di, const RageTimer &now );
2006-09-08 01:11:18 +00:00
void ReportButtonChange( const DeviceInput &di, InputEventType t );
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
#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.
*/