arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

gutzKeyMouse.h

Go to the documentation of this file.
00001 ///////////////////////////////////////////////////////////////////////////
00002 //              _____________  ______________________    __   __  _____
00003 //             /  ________  |  |   ___   ________   /   |  \ /  \   |
00004 //            |  |       |  |_ |  |_ |  |       /  /    \__  |      |
00005 //            |  |  ___  |  || |  || |  |      /  /        | |      |
00006 //            |  | |   \ |  || |  || |  |     /  /      \__/ \__/ __|__
00007 //            |  | |_@  ||  || |  || |  |    /  /          Institute
00008 //            |  |___/  ||  ||_|  || |  |   /  /_____________________
00009 //             \_______/  \______/ | |__|  /___________________________
00010 //                        |  |__|  |
00011 //                         \______/
00012 //                    University of Utah       
00013 //                           2002
00014 ///////////////////////////////////////////////////////////////////////////
00015 
00016 //gutzKeyMouse.h
00017 
00018 // Universal names for common keyboard and mouse keys
00019 
00020 #ifndef __GUTZ_KEY_MOUSE_DOT_H
00021 #define __GUTZ_KEY_MOUSE_DOT_H
00022 
00023 #include <map>
00024 #include "../include/smartptr.h"
00025 
00026 namespace gutz {
00027 
00028 
00029 ////////////////////////////////////////////////////////////////////////////
00030 /// Key Map Compare Functor, for 
00031 ///    Mapping keys to events using bit vectors
00032 ////////////////////////////////////////////////////////////////////////////
00033    
00034 struct eventKeyMapCmp
00035 {
00036   bool operator()(unsigned int keyBV1, unsigned int keyBV2) const
00037   {
00038           return (keyBV1 < keyBV2);
00039   }
00040 };
00041 
00042 /// Event map, takes button ids (unsigned ints) and returns event behaviors
00043 ///  (also unsigned ints).  I overloaded this guy so that the const [] op
00044 ///   will behave correctly.
00045 class EventKeyMap 
00046    : public std::map<unsigned int, unsigned int,   eventKeyMapCmp>,
00047      public gutz::Counted
00048 {
00049 public:
00050    typedef std::map<unsigned int, unsigned int, eventKeyMapCmp> Base;
00051    typedef Base::iterator Iter;
00052    typedef Base::const_iterator CIter;
00053 
00054    EventKeyMap() {}
00055    ~EventKeyMap() {}
00056 
00057    unsigned int operator[](unsigned int key) const 
00058    {
00059       CIter ei = find(key);
00060       if( ei == end() ) return 0;
00061       return (*ei).second;
00062    }
00063 
00064    unsigned int &operator[](unsigned int key)
00065    { 
00066       return Base::operator[](key);
00067    }
00068 
00069 
00070 };
00071 typedef gutz::SmartPtr<EventKeyMap> EventKeyMapSP;
00072 
00073 /// Event Param map, takes button ids (unsigned ints) and returns event paramters
00074 ///  (floats).  I overloaded this guy so that the const [] op
00075 ///   will behave correctly.
00076 class EventParamMap
00077    : public std::map<unsigned int, float, eventKeyMapCmp>,
00078      public gutz::Counted
00079 {
00080 public:
00081    typedef std::map<unsigned int, float, eventKeyMapCmp> Base;
00082    typedef Base::iterator Iter;
00083    typedef Base::const_iterator CIter;
00084 
00085    EventParamMap() {}
00086    ~EventParamMap() {}
00087 
00088    float operator[](unsigned int key) const 
00089    {
00090       CIter ei = find(key);
00091       if( ei == end() ) return 0;
00092       return (*ei).second;
00093    }
00094 
00095    float &operator[](unsigned int key)
00096    { 
00097       return Base::operator[](key);
00098    }
00099 };
00100 typedef gutz::SmartPtr<EventParamMap> EventParamMapSP;
00101 
00102 //class EventMap
00103 //   : public std::map<unsigned int, 
00104 
00105 //typedef std::map<int, int,   eventKeyMapCmp> eventKeyMap;
00106 //typedef std::map<int, float, eventKeyMapCmp> eventParamMap;
00107 
00108 ////////////////////////////////////////////////////////////
00109 /// GutzButtonState,
00110 ///  Mouse and Arrow Key State identifiers
00111 ////////////////////////////////////////////////////////////
00112 typedef enum GUTZ_BUTTON_STATES {
00113    GUTZ_KEY_DOWN,
00114    GUTZ_KEY_UP   
00115 } GutzButtonState;
00116 
00117 
00118 ////////////////////////////////////////////////////////////
00119 /// GutzButton,
00120 ///  Mouse and Arrow Key Identifiers and Modifiers
00121 ////////////////////////////////////////////////////////////
00122 typedef enum GUTZ_MOUSE_BUTTONS { //Buttons
00123    GUTZ_BUTTON_NONE      = 0,
00124    GUTZ_LEFT_MOUSE       = 1 << 0,      ///<Left Mouse      button
00125    GUTZ_MIDDLE_MOUSE     = 1 << 1,      ///<Middle Mouse    button
00126    GUTZ_RIGHT_MOUSE      = 1 << 2,      ///<Right Mouse     button
00127    GUTZ_UP_ARROW         = 1 << 3,      ///<Up arrow        key 
00128    GUTZ_DOWN_ARROW       = 1 << 4,      ///<Down arrow      key 
00129    GUTZ_RIGHT_ARROW      = 1 << 5,      ///<Right arrow     key 
00130    GUTZ_LEFT_ARROW       = 1 << 6,      ///<Left arrow      key
00131    GUTZ_SHIFT            = 1 << 7,      ///<Shift key       modifier
00132    GUTZ_CTRL             = 1 << 8,      ///<Control key     modifier
00133    GUTZ_ALT              = 1 << 9,      ///<ALT key         modifier
00134    GUTZ_DBL_LEFT_MOUSE   = 1 << 10,     ///< double click
00135    GUTZ_DBL_RIGHT_MOUSE  = 1 << 11,     ///< double click
00136    GUTZ_DBL_MIDDLE_MOUSE = 1 << 12,     ///< double click
00137    GUTZ_LAST_BUTTON      = 1 << 13,     ///<LAST button & Total number of unique combinations
00138    GUTZ_UNUSED_01        = 1 << 14,     ///<Use for custom events
00139    GUTZ_UNUSED_02        = 1 << 15,     ///<Use for custom events
00140    GUTZ_UNUSED_03        = 1 << 16,     ///<Use for custom events
00141    GUTZ_UNUSED_04        = 1 << 17,     ///<Use for custom events
00142    GUTZ_UNUSED_05        = 1 << 18,     ///<Use for custom events
00143    GUTZ_UNUSED_06        = 1 << 19,     ///<Use for custom events
00144    GUTZ_UNUSED_07        = 1 << 20,     ///<Use for custom events
00145 } GutzButton;
00146 
00147 ////////////////////////////////////////////////////////////
00148 /// Keyboard keys, use a GUTZ_MOUSE_BUTTONS for modifiers
00149 ////////////////////////////////////////////////////////////
00150 typedef enum GUTZ_KEYS {
00151    GUTZ_ASCI   = 255, ///< unsigned char keys (ASCI keys)
00152    GUTZ_F1,  ///< Special (F) keys
00153    GUTZ_F2,
00154    GUTZ_F3,
00155    GUTZ_F4,
00156    GUTZ_F5,
00157    GUTZ_F6,
00158    GUTZ_F7,
00159    GUTZ_F8,
00160    GUTZ_F9,
00161    GUTZ_F10,
00162    GUTZ_F11,
00163    GUTZ_F12,
00164    GUTZ_TAB,  ///< Tab
00165    GUTZ_NLK,  ///< Num Lock
00166    GUTZ_CLK,  ///< Caps Lock
00167    GUTZ_ESC,  ///< Escape
00168    GUTZ_INS,  ///< Insert
00169    GUTZ_DEL,  ///< Delete
00170    GUTZ_HOM,  ///< Home
00171    GUTZ_END,  ///< End
00172    GUTZ_PUP,  ///< Page up
00173    GUTZ_PDN,  ///< Page down
00174    GUTZ_AUP,  ///< Arrow up
00175    GUTZ_ADN,  ///< Arrow down
00176    GUTZ_ALF,  ///< Arrow left
00177    GUTZ_ART,  ///< Arrow right
00178    GUTZ_PSCR, ///< Print screen
00179    GUTZ_SCRL, ///< Scroll lock
00180    GUTZ_PSEB, ///< Pause/break
00181    GUTZ_LAST_KEY
00182 } GutzKeys;
00183 
00184 //////////////////////////////////////////////////////////////
00185 /// add a key to a bit vector
00186 //////////////////////////////////////////////////////////////
00187 inline
00188 unsigned int gutzAddKey(unsigned int &keyBitVec, unsigned int keyID)
00189 {
00190    keyBitVec = ((unsigned int)keyBitVec | (unsigned int)keyID);
00191    return keyBitVec;
00192 }
00193 
00194 //////////////////////////////////////////////////////////////
00195 /// remove a key from a bit vector
00196 //////////////////////////////////////////////////////////////
00197 inline
00198 unsigned int gutzDelKey(unsigned int &keyBitVec, unsigned int keyID)
00199 {
00200    keyBitVec = ((unsigned int)keyBitVec - (unsigned int)keyID);
00201    return keyBitVec;
00202 }
00203 
00204 //////////////////////////////////////////////////////////////
00205 /// Test for specific keys
00206 //////////////////////////////////////////////////////////////
00207 
00208 inline
00209 bool isMouse(unsigned int keyBitVec)
00210 {
00211    if(keyBitVec & GUTZ_LEFT_MOUSE) return true;
00212    if(keyBitVec & GUTZ_MIDDLE_MOUSE) return true;
00213    if(keyBitVec & GUTZ_RIGHT_MOUSE) return true;
00214    return false;
00215 }
00216 
00217 inline
00218 bool isArrow(unsigned int keyBitVec)
00219 {
00220    if(keyBitVec & GUTZ_UP_ARROW) return true;
00221    if(keyBitVec & GUTZ_DOWN_ARROW) return true;
00222    if(keyBitVec & GUTZ_LEFT_ARROW) return true;
00223    if(keyBitVec & GUTZ_RIGHT_ARROW) return true;
00224    return false;
00225 }
00226 
00227 inline
00228 bool isModified(unsigned int keyBitVec)
00229 {
00230    if(keyBitVec & GUTZ_SHIFT) return true;
00231    if(keyBitVec & GUTZ_ALT) return true;
00232    if(keyBitVec & GUTZ_CTRL) return true;
00233    return false;
00234 }
00235 
00236 inline
00237 bool isCustom(unsigned int keyBitVec)
00238 {
00239    if(keyBitVec > GUTZ_LAST_KEY) return true;
00240    return false;
00241 }
00242 
00243 } //<end namespace gutz
00244 
00245 #endif
00246 

Send questions, comments, and bug reports to:
jmk