JoystickEvent.h

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                              SOFA :: Framework                              *
00020 *                                                                             *
00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024 *                                                                             *
00025 * Contact information: contact@sofa-framework.org                             *
00026 ******************************************************************************/
00027 //
00028 // C++ Interface: JoystickEvent
00029 //
00030 // Description: 
00031 //
00032 //
00033 // Author: Pierre-Jean Bensoussan, Digital Trainers (2008)
00034 //
00035 // Copyright: See COPYING file that comes with this distribution
00036 //
00037 //
00038 // This file is a work based on the open source release of VGSDK.
00039 //
00040 // VGSDK - Copyright (C) 2008, Nicolas Papier.
00041 // Distributed under the terms of the GNU Library General Public License (LGPL)
00042 // as published by the Free Software Foundation.
00043 // Author Nicolas Papier
00044 // Author Guillaume Brocker
00045 //
00046 
00047 #ifndef SOFA_CORE_OBJECTMODEL_JOYSTICKEVENT_H
00048 #define SOFA_CORE_OBJECTMODEL_JOYSTICKEVENT_H
00049 
00050 #include <sofa/core/objectmodel/Event.h>
00051 #include <vector>
00052 
00053 namespace sofa
00054 {
00055 
00056 namespace core
00057 {
00058 
00059 namespace objectmodel
00060 {
00061 
00067 class JoystickEvent : public sofa::core::objectmodel::Event
00068 {
00069 public:
00070 
00075     class AxisEvent
00076     {
00077     public:
00086         AxisEvent( const int /*index*/, const float /*value*/ );
00087 
00091         virtual ~AxisEvent(){};
00092 
00102         int getIndex() const;
00103 
00111         float getValue() const;
00113 
00114     private:
00115         const int   m_index;    
00116         const float m_value;    
00117     };
00118 
00119 
00120 
00124     class ButtonEvent
00125     {
00126     public:
00130         ButtonEvent( const int  buttonStates = 0 );
00131 
00135         virtual ~ButtonEvent(){};
00136 
00140         void setButtons(const int);
00141 
00145         bool getButton(const int) const;
00146 
00147 
00148     private:
00149         bool m_buttons[32]; 
00150     };
00151 
00152 
00153 
00157     class HatEvent
00158     {
00159     public: 
00163         typedef enum
00164         {
00165             CENTERED    = 0,
00166             UP          = 1 << 0,
00167             RIGHT       = 1 << 1,
00168             DOWN        = 1 << 2,
00169             LEFT        = 1 << 3,
00170             UP_RIGHT    = UP|RIGHT,
00171             DOWN_RIGHT  = DOWN|RIGHT,
00172             DOWN_LEFT   = DOWN|LEFT,
00173             UP_LEFT     = UP|LEFT
00174         } State;
00175 
00176 
00183         HatEvent( const int /*index*/, const State /*state*/ );
00184 
00188         virtual ~HatEvent(){};
00189 
00199         int getIndex() const;
00200 
00206         State getState() const;
00208 
00209     private:
00210 
00211         const int   m_index;    
00212         const State m_state;    
00213     };
00214 
00219 
00224 
00225     const AxisEvent *getAxisEvent(const int /*index*/) const;
00226 
00227     const std::vector<AxisEvent*> &getAxisEvents(void) const;
00228 
00229     unsigned int getAxisEventsSize(void) const;
00230 
00231     void addAxisEvent( AxisEvent * );
00232 
00234 
00239 
00240     ButtonEvent *getButtonEvent(void) const;
00241 
00242     bool getButton(unsigned int /*index*/) const;
00243 
00244     void setButtonEvent( ButtonEvent * );
00245 
00247 
00252 
00253     const HatEvent *getHatEvent(const int /*index*/) const;
00254 
00255     const std::vector<HatEvent*> &getHatEvents(void) const;
00256 
00257     unsigned int getHatEventsSize(void) const;
00258 
00259     void addHatEvent( HatEvent * );
00260 
00262 
00264 
00268     JoystickEvent();
00269 
00273     virtual ~JoystickEvent();
00274 
00275 protected:
00276     
00277     std::vector< AxisEvent* > axisEvents; 
00278     ButtonEvent *buttonEvent; 
00279     std::vector< HatEvent* > hatEvents; 
00280 
00281 private:
00282 
00283 };
00284 
00285 } // namespace objectmodel
00286 
00287 } // namespace core
00288 
00289 } // namespace sofa
00290 
00291 #endif // SOFA_CORE_OBJECTMODEL_JOYSTICKEVENT_H

Generated on Sun Nov 23 02:29:25 2008 for Sofa by  doxygen 1.5.7.1