lib/gamepad/gamepad.h

Go to the documentation of this file.
00001 /*
00002  * gamepad.h
00003  *
00004  * Copyright (C) 2008-2010  Thomas A. Vaughan
00005  * All rights reserved.
00006  *
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *     * Redistributions of source code must retain the above copyright
00011  *       notice, this list of conditions and the following disclaimer.
00012  *     * Redistributions in binary form must reproduce the above copyright
00013  *       notice, this list of conditions and the following disclaimer in the
00014  *       documentation and/or other materials provided with the distribution.
00015  *     * Neither the name of the <organization> nor the
00016  *       names of its contributors may be used to endorse or promote products
00017  *       derived from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY
00020  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022  * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY
00023  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00024  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00026  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  *
00031  * Gamepad object.  This is a completely data-driven concept.
00032  */
00033 
00034 #ifndef GAMEPAD_GAMEPAD_H__
00035 #define GAMEPAD_GAMEPAD_H__
00036 
00037 // includes --------------------------------------------------------------------
00038 #include "gamepad-map.h"
00039 
00040 #include "i18n/i18n.h"
00041 
00042 
00043 namespace gamepad {
00044 
00045 
00046 /// \ingroup gamepad_api
00047 /// \defgroup gamepadlib Gamepad Library
00048 /*@{*/
00049 
00050 
00051 
00052 /// an instance of a physical gamepad.
00053 class Gamepad {
00054 public:
00055         // virtual destructor --------------------------------------------------
00056         virtual ~Gamepad(void) throw();
00057 
00058         // gamepad::Gamepad class interface methods ----------------------------
00059 
00060         /// what type of gamepad is this?  This object (gamepad::Type) will tell
00061         ///     you how many buttons, how many joysticks, etc.
00062         virtual Type * getType(void) const throw() = 0;
00063 
00064         /// get the ID (right now this is "source device:mapping" IDs)
00065         virtual const char * getId(void) throw() = 0;
00066 
00067         /// which source device is this?
00068         virtual const char * getSourceDeviceId(void) throw() = 0;
00069 
00070         /// which mapping is this gamepad using?
00071         virtual const char * getMappingId(void) throw() = 0;
00072 
00073         /// is the gamepad currently connected (sending events)?
00074         virtual eDeviceState getState(void) throw() = 0;
00075 
00076         /// if button with index X is pressed then bit X will be set
00077         virtual buttons_t getButtons(void) throw() = 0;
00078 
00079         /// retrieve the value of a particular button
00080         virtual eButton getButton(IN int idx) throw() = 0;
00081 
00082         /// retrieve the value of a particular joystick
00083         virtual void getJoystick(IN int idx,
00084                                 OUT joystick_t& joy) throw() = 0;
00085 
00086         /// retrieve the value of a particular potentiometer
00087         virtual void getPot(IN int idx,
00088                                 OUT pot_value_t& pv) throw() = 0;
00089 
00090         /// retrieve the value of a particular dpad
00091         virtual eDpad getDpad(IN int idx) throw() = 0;
00092 };
00093 
00094 
00095 
00096 ////////////////////////////////////////////////////////////////////////////////
00097 //
00098 //      Gamepad API
00099 //
00100 ////////////////////////////////////////////////////////////////////////////////
00101 
00102 
00103 
00104 /// given previous + current button state, say what was pressed and released
00105 static inline void getButtonsChanged(IN buttons_t prev_buttons,
00106                         IN buttons_t curr_buttons,
00107                         OUT buttons_t& pressed,
00108                         OUT buttons_t& released) throw()
00109         {
00110                 buttons_t common = prev_buttons | curr_buttons;
00111                 pressed = common - prev_buttons;
00112                 released = common - curr_buttons;
00113         }
00114 
00115 
00116 // localization helpers
00117 
00118 /// return the localization manager for gamepad configuration
00119 smart_ptr<i18n::Manager> getConfigLocaleMgr(IN const char * primaryLocale,
00120                         IN const char * defaultLocale,
00121                         IN nstream::Folder * dataDirectory);
00122 
00123 
00124 /// return the localization manager for the specified gamepad::Type
00125 smart_ptr<i18n::Manager> getTypeLocaleMgr(IN const Type * type,
00126                         IN const char * primaryLocale,
00127                         IN const char * defaultLocale,
00128                         IN nstream::Folder * dataDirectory);
00129 
00130 
00131 };      // gamepad namespace
00132 
00133 #endif  // GAMEPAD_GAMEPAD_H__
00134