home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / thx / include / keyfold.h < prev    next >
C/C++ Source or Header  |  1995-05-08  |  1KB  |  50 lines

  1. // --------- keyfold.h
  2.  
  3. #ifndef  KEYFOLD_H
  4. #define  KEYFOLD_H
  5.  
  6. #include "hand.h"
  7. #include "handler.h"
  8. #include "folder.h"
  9. #include "debug.h"
  10.  
  11. const int NUMKEYS  = 175;
  12. const int AUX_OFFSET = 71;
  13. // 0-126 are used by ascii values, tilde is the highest (126)
  14. // 130-213 are used by AUX values, DEL being the highest (83)
  15.  
  16. class KeystrokeFolder : public Folder  {
  17.   int adjust_key(int);
  18.   EventHandler key[NUMKEYS];
  19.   friend class KeystrokeServer;
  20. public:
  21.   KeystrokeFolder() : Folder(key, NUMKEYS) { }
  22.   void register_key(Hand*,int key,callback);
  23.   void unregister_key(Hand*,int key,callback);
  24.   void reset();
  25.   void dispatch(int, int, int);
  26. };
  27.  
  28. inline int KeystrokeFolder::adjust_key(int k)
  29. {
  30.   if ((k&0xff00) != 0)
  31.     k = ((k>>8)&0xff)+AUX_OFFSET;
  32.   Assert(k >= 0 && k < NUMKEYS);
  33.   return k;
  34. }
  35.  
  36. inline void KeystrokeFolder::register_key(Hand* hand,
  37.                                          int k,callback cb)
  38. {
  39.   key[adjust_key(k)].add(hand,cb);
  40. }
  41.  
  42. inline void KeystrokeFolder::unregister_key(Hand* hand,
  43.                                          int k,callback cb)
  44. {
  45.   key[adjust_key(k)].del(hand,cb);
  46. }
  47.  
  48. #endif
  49.  
  50.