]> git.mxchange.org Git - flightgear.git/blobdiff - src/Input/FGEventInput.hxx
Merge branch 'next' of 10.101.2.62:~/FlightGear/fg-osg/FlightGear into next
[flightgear.git] / src / Input / FGEventInput.hxx
index 8b4e0d941359eebf850d46c9bb731f7ae76546f7..7188c83813f112d844e0d2afae40a27c09465d34 100644 (file)
 #include <simgear/structure/subsystem_mgr.hxx>
 
 /*
- * A base class for event data. 
+ * A base structure for event data. 
+ * To be extended for O/S specific implementation data
  */
 struct FGEventData {
-  FGEventData( double aValue, double aDt ) : value(aValue), dt(aDt) {}
+  FGEventData( double aValue, double aDt, int aModifiers ) : modifiers(aModifiers), value(aValue), dt(aDt) {}
+  int modifiers;
   double value;
   double dt;
 };
 
+class FGEventSetting : public SGReferenced {
+public:
+  FGEventSetting( SGPropertyNode_ptr base );
+
+  bool Test();
+
+  /* 
+   * access for the value property
+   */
+  double GetValue();
+
+protected:
+  double value;
+  SGPropertyNode_ptr valueNode;
+  SGSharedPtr<const SGCondition> condition;
+};
+
+typedef SGSharedPtr<FGEventSetting> FGEventSetting_ptr;
+typedef vector<FGEventSetting_ptr> setting_list_t;
+
 /*
  * A wrapper class for a configured event. 
  * 
@@ -51,15 +73,22 @@ struct FGEventData {
  *     <max type="double">90.0</max>
  *     <wrap type="bool">false</wrap>
  *   </binding>
+ *   <mod-xyz>
+ *    <binding>
+ *      ...
+ *    </binding>
+ *   </mod-xyz>
  * </event>
  */
+class FGInputDevice;
 class FGInputEvent : public SGReferenced,FGCommonInput {
 public:
+
   /*
    * Constructor for the class. The arg node shall point
    * to the property corresponding to the <event>  node
    */
-  FGInputEvent( SGPropertyNode_ptr node );
+  FGInputEvent( FGInputDevice * device, SGPropertyNode_ptr node );
   virtual ~FGInputEvent();
 
   /*
@@ -77,9 +106,12 @@ public:
    */
   string GetDescription() const { return desc; }
 
-  static FGInputEvent * NewObject( SGPropertyNode_ptr node );
+  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;
 
@@ -89,19 +121,33 @@ protected:
   /* A list of SGBinding objects */
   binding_list_t bindings[KEYMOD_MAX];
 
+  /* A list of FGEventSetting objects */
+  setting_list_t settings;
+
+  /* A pointer to the associated device */
+  FGInputDevice * device;
+
   double lastDt;
   double intervalSec;
+  double lastSettingValue;
 };
 
 class FGButtonEvent : public FGInputEvent {
 public:
-  FGButtonEvent( SGPropertyNode_ptr node );
+  FGButtonEvent( FGInputDevice * device, SGPropertyNode_ptr node );
   virtual void fire( FGEventData & eventData );
+
+protected:
+  bool repeatable;
+  bool lastState;
 };
 
 class FGAxisEvent : public FGInputEvent {
 public:
-  FGAxisEvent( SGPropertyNode_ptr node );
+  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;
@@ -114,6 +160,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> FGInputEvent_ptr;
 
 /*
@@ -123,13 +183,20 @@ typedef class SGSharedPtr<FGInputEvent> FGInputEvent_ptr;
  */
 class FGInputDevice : public SGReferenced {
 public:
-  FGInputDevice() {}
+  FGInputDevice() : debugEvents(false), grab(false) {}
   FGInputDevice( string aName ) : name(aName) {}
     
   virtual ~FGInputDevice();
 
   virtual void Open() = 0;
   virtual void Close() = 0;
+
+  virtual void Send( const char * eventName, double value ) = 0;
+
+  inline void Send( const string & eventName, double value ) {
+    Send( eventName.c_str(), value );
+  }
+
   virtual const char * TranslateEventName( FGEventData & eventData ) = 0;
 
 
@@ -137,14 +204,39 @@ public:
   string & GetName() { return name; }
 
   void HandleEvent( FGEventData & eventData );
+
   void AddHandledEvent( FGInputEvent_ptr handledEvent ) {
     if( handledEvents.count( handledEvent->GetName() ) == 0 )
       handledEvents[handledEvent->GetName()] = handledEvent;
   }
 
+  virtual void Configure( SGPropertyNode_ptr deviceNode );
+
+  virtual void update( double dt );
+
+  bool GetDebugEvents () const { return debugEvents; }
+
+  bool GetGrab() const { return grab; }
+
+  const string & GetNasalModule() const { return nasalModule; }
+
 private:
+  // A map of events, this device handles
   map<string,FGInputEvent_ptr> handledEvents;
+
+  // the device has a name to be recognized
   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;
+  string nasalModule;
 };
 
 typedef SGSharedPtr<FGInputDevice> FGInputDevice_ptr;
@@ -159,13 +251,20 @@ public:
   virtual ~FGEventInput();
   virtual void init();
   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 );
+  unsigned AddDevice( FGInputDevice * inputDevice );
+  void RemoveDevice( unsigned index );
+
   map<int,FGInputDevice*> input_devices;
   FGDeviceConfigurationMap configMap;
+
+  SGPropertyNode_ptr nasalClose;
 };
 
 #endif