X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FInput%2FFGEventInput.hxx;h=c62a77aae0bad8deed54593c6b23107b6302508d;hb=3d4806adbe6705f785fd950bd4b4afde1cb4f8d2;hp=a3896e1d47a06497771dbe27b2c9fb6261160f29;hpb=8cf74b8f2d1591905fc81cf2b2993c865b6332a0;p=flightgear.git diff --git a/src/Input/FGEventInput.hxx b/src/Input/FGEventInput.hxx index a3896e1d4..c62a77aae 100644 --- a/src/Input/FGEventInput.hxx +++ b/src/Input/FGEventInput.hxx @@ -24,6 +24,9 @@ #define __FGEVENTINPUT_HXX #include "FGCommonInput.hxx" + +#include + #include "FGButton.hxx" #include "FGDeviceConfigurationMap.hxx" #include @@ -33,7 +36,7 @@ * To be extended for O/S specific implementation data */ struct FGEventData { - FGEventData( double aValue, double aDt, int aModifiers ) : value(aValue), dt(aDt), modifiers(aModifiers) {} + FGEventData( double aValue, double aDt, int aModifiers ) : modifiers(aModifiers), value(aValue), dt(aDt) {} int modifiers; double value; double dt; @@ -57,7 +60,7 @@ protected: }; typedef SGSharedPtr FGEventSetting_ptr; -typedef vector setting_list_t; +typedef std::vector setting_list_t; /* * A wrapper class for a configured event. @@ -83,6 +86,7 @@ typedef vector setting_list_t; class FGInputDevice; class FGInputEvent : public SGReferenced,FGCommonInput { public: + /* * Constructor for the class. The arg node shall point * to the property corresponding to the node @@ -98,23 +102,24 @@ public: /* * access for the name property */ - string GetName() const { return name; } + std::string GetName() const { return name; } /* * access for the description property */ - string GetDescription() const { return desc; } + std::string GetDescription() const { return desc; } virtual void update( double dt ); static FGInputEvent * NewObject( FGInputDevice * device, SGPropertyNode_ptr node ); protected: + virtual void fire( SGBinding * binding, FGEventData & eventData ); /* A more or less meaningfull description of the event */ - string desc; + std::string desc; /* One of the predefined names of the event */ - string name; + std::string name; /* A list of SGBinding objects */ binding_list_t bindings[KEYMOD_MAX]; @@ -143,6 +148,9 @@ protected: class FGAxisEvent : public FGInputEvent { public: FGAxisEvent( FGInputDevice * device, SGPropertyNode_ptr node ); + void SetMaxRange( double value ) { maxRange = value; } + void SetMinRange( double value ) { minRange = value; } + void SetRange( double min, double max ) { minRange = min; maxRange = max; } protected: virtual void fire( FGEventData & eventData ); double tolerance; @@ -155,6 +163,20 @@ protected: double lastValue; }; +class FGRelAxisEvent : public FGAxisEvent { +public: + FGRelAxisEvent( FGInputDevice * device, SGPropertyNode_ptr node ); +protected: + virtual void fire( SGBinding * binding, FGEventData & eventData ); +}; + +class FGAbsAxisEvent : public FGAxisEvent { +public: + FGAbsAxisEvent( FGInputDevice * device, SGPropertyNode_ptr node ) : FGAxisEvent( device, node ) {} +protected: + virtual void fire( SGBinding * binding, FGEventData & eventData ); +}; + typedef class SGSharedPtr FGInputEvent_ptr; /* @@ -164,8 +186,8 @@ typedef class SGSharedPtr FGInputEvent_ptr; */ class FGInputDevice : public SGReferenced { public: - FGInputDevice() : debugEvents(false) {} - FGInputDevice( string aName ) : name(aName) {} + FGInputDevice() : debugEvents(false), grab(false) {} + FGInputDevice( std::string aName ) : name(aName), debugEvents(false), grab(false) {} virtual ~FGInputDevice(); @@ -174,15 +196,15 @@ public: virtual void Send( const char * eventName, double value ) = 0; - inline void Send( const string & eventName, double value ) { + inline void Send( const std::string & eventName, double value ) { Send( eventName.c_str(), value ); } virtual const char * TranslateEventName( FGEventData & eventData ) = 0; - void SetName( string name ); - string & GetName() { return name; } + void SetName( std::string name ); + std::string & GetName() { return name; } void HandleEvent( FGEventData & eventData ); @@ -191,21 +213,33 @@ public: handledEvents[handledEvent->GetName()] = handledEvent; } + virtual void Configure( SGPropertyNode_ptr deviceNode ); + virtual void update( double dt ); bool GetDebugEvents () const { return debugEvents; } - void SetDebugEvents( bool value ) { debugEvents = value; } + + bool GetGrab() const { return grab; } + + const std::string & GetNasalModule() const { return nasalModule; } private: // A map of events, this device handles - map handledEvents; + std::map handledEvents; // the device has a name to be recognized - string name; + std::string name; // print out events comming in from the device // if true bool debugEvents; + + // grab the device exclusively, if O/S supports this + // so events are not sent to other applications + bool grab; + + SGPropertyNode_ptr deviceNode; + std::string nasalModule; }; typedef SGSharedPtr FGInputDevice_ptr; @@ -222,12 +256,18 @@ public: virtual void postinit(); virtual void update( double dt ); + const static unsigned MAX_DEVICES = 1000; + const static unsigned INVALID_DEVICE_INDEX = MAX_DEVICES + 1; protected: static const char * PROPERTY_ROOT; - void AddDevice( FGInputDevice * inputDevice ); - map input_devices; + unsigned AddDevice( FGInputDevice * inputDevice ); + void RemoveDevice( unsigned index ); + + std::map input_devices; FGDeviceConfigurationMap configMap; + + SGPropertyNode_ptr nasalClose; }; #endif