home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / thx / source / theatrix / hand.cpp < prev    next >
C/C++ Source or Header  |  1995-04-26  |  6KB  |  232 lines

  1. #include <conio.h>             // kbhit getch
  2. #include "theatrix.h"
  3. #include "director.h"
  4. #include "standard.h"
  5. #include "hand.h"
  6. #include "settings.h"
  7.  
  8. Hand *Hand::hand[MAXHANDS];
  9. int Hand::numhands;
  10. short int Hand::mouseinuse;
  11. const char dirmsg[] = "Program has no directors";
  12.  
  13. Hand::Hand(Director* dir) : director(dir)
  14.   {
  15.   if (numhands == MAXHANDS)
  16.     Theatrix::fatal("Too many hands");
  17.   hand[numhands++]=this;
  18.   }
  19.  
  20. Hand::~Hand()
  21.   {
  22.   if (director)
  23.     director->delete_hand(this);
  24.   }
  25.  
  26. void Hand::initialize_hands()
  27.   {
  28.   for (int i=0;i<numhands;i++)
  29.     {
  30.     Event *map = hand[i]->GetMessageMap();
  31.     if (map != 0)
  32.       {
  33.       while (map->evtype != 0)
  34.         {
  35.         switch (map->evtype)
  36.           {
  37.           case HOTKEY_EVENT:
  38.             hand[i]->request_hotkey_cue(map->code, map->func);
  39.             break;
  40.           case TIMER_EVENT:
  41.             hand[i]->request_timer_cue(map->code, map->func);
  42.             break;
  43.           case MESSAGE_EVENT:
  44.             hand[i]->request_message_cue(map->code, map->func);
  45.             break;
  46.           case KEYSTROKE_EVENT:
  47.             hand[i]->request_keystroke_cue(map->code, map->func);
  48.             break;
  49.           case MOUSECLICK_EVENT:
  50.             hand[i]->request_mouseclick_cue(map->code, map->func);
  51.             break;
  52.           case MOUSEMOVE_EVENT:
  53.             hand[i]->request_mousemove_cue(map->func);
  54.             break;
  55.           case JOYSTICKBUTTON_EVENT:
  56.             hand[i]->request_joystickbutton_cue(map->code, map->func);
  57.             break;
  58.           case JOYSTICKMOVE_EVENT:
  59.             hand[i]->request_joystickmove_cue(map->func);
  60.             break;
  61.           case NETPACK_EVENT:
  62.             hand[i]->request_netpack_cue(map->code,map->func);
  63.             break;
  64.           default:
  65.             break;
  66.           }
  67.         map++;
  68.         }
  69.       }
  70.     hand[i]->initialize();
  71.     }
  72.   }
  73.  
  74. void Hand::set_hotkeys(int mode)
  75.   {
  76.   if (!director)
  77.         Theatrix::fatal(dirmsg);
  78.   director->set_keydownmode(mode);
  79.   if (mode==OFF)
  80.     while (kbhit())  getch();
  81.   }
  82.  
  83. void Hand::stop_director()
  84.   {
  85.   if (!director)
  86.     Theatrix::fatal(dirmsg);
  87.   director->quit();
  88.   director->set_next_director(&typeid(StopDirector));
  89.   }
  90.  
  91. void Hand::start_director(const Type_info& dir)
  92.   {
  93.   stop_director();
  94.   director->set_next_director(&dir);
  95.   }
  96.  
  97. //-----------------------------------------------
  98. //------------------ Keystroke --------------------
  99. //-----------------------------------------------
  100.  
  101. void Hand::thx_request_keystroke_cue(int key,callback cb)
  102.   {
  103.   director->add_keystroke_cue(this,cb,key);
  104.   }
  105.  
  106. void Hand::thx_stop_keystroke_cue(int key,callback cb)
  107.   {
  108.   director->del_keystroke_cue(this,cb,key);
  109.   }
  110.  
  111. //-----------------------------------------------
  112. //------------------ Keydown --------------------
  113. //-----------------------------------------------
  114.  
  115. void Hand::thx_request_hotkey_cue(int key,callback cb)
  116.   {
  117.   director->add_keydown_cue(this,cb,key);
  118.   }
  119.  
  120. void Hand::thx_stop_hotkey_cue(int key,callback cb)
  121.   {
  122.   director->del_keydown_cue(this,cb,key);
  123.   }
  124.  
  125. //-----------------------------------------------
  126. //------------------ Timer ----------------------
  127. //-----------------------------------------------
  128.  
  129. void Hand::thx_request_timer_cue(int r,callback cb)
  130.   {
  131.   director->add_timer_cue(this,cb,r);
  132.   }
  133.  
  134. void Hand::thx_stop_timer_cue(int r,callback cb)
  135.   {
  136.   director->del_timer_cue(this,cb,r);
  137.   }
  138.  
  139. //-----------------------------------------------
  140. //------------------ Message --------------------
  141. //-----------------------------------------------
  142.  
  143. void Hand::thx_request_message_cue(int msg,callback cb)
  144.   {
  145.   director->add_message_cue(this,cb,msg);
  146.   }
  147.  
  148. void Hand::thx_stop_message_cue(int msg,callback cb)
  149.   {
  150.   director->del_message_cue(this,cb,msg);
  151.   }
  152.  
  153. void Hand::thx_post_message(int msg,int data1,int data2)
  154.   {
  155.   director->submit_message(msg,data1,data2);
  156.   }
  157.  
  158. //-----------------------------------------------
  159. //------------------ mouseclick -----------------
  160. //-----------------------------------------------
  161.  
  162. void Hand::thx_request_mouseclick_cue(int b,callback cb)
  163.   {
  164.   director->add_mouseclick_cue(this,cb,b);
  165.   }
  166.  
  167. void Hand::thx_stop_mouseclick_cue(int b,callback cb)
  168.   {
  169.   director->del_mouseclick_cue(this,cb,b);
  170.   }
  171.  
  172. //-----------------------------------------------
  173. //------------------ mousemove ------------------
  174. //-----------------------------------------------
  175.  
  176. void Hand::thx_request_mousemove_cue(callback cb)
  177.   {
  178.   director->add_mousemove_cue(this,cb);
  179.   }
  180.  
  181. void Hand::thx_stop_mousemove_cue(callback cb)
  182.   {
  183.   director->del_mousemove_cue(this,cb);
  184.   }
  185.  
  186. //-----------------------------------------------
  187. //------------------ joystickbutton -----------------
  188. //-----------------------------------------------
  189.  
  190. void Hand::thx_request_joystickbutton_cue(int b,callback cb)
  191.   {
  192.   director->add_joystickbutton_cue(this,cb,b);
  193.   }
  194.  
  195. void Hand::thx_stop_joystickbutton_cue(int b,callback cb)
  196.   {
  197.   director->del_joystickbutton_cue(this,cb,b);
  198.   }
  199.  
  200. //-----------------------------------------------
  201. //------------------ joystickmove ------------------
  202. //-----------------------------------------------
  203.  
  204. void Hand::thx_request_joystickmove_cue(callback cb)
  205.   {
  206.   director->add_joystickmove_cue(this,cb);
  207.   }
  208.  
  209. void Hand::thx_stop_joystickmove_cue(callback cb)
  210.   {
  211.   director->del_joystickmove_cue(this,cb);
  212.   }
  213.  
  214. //-----------------------------------------------
  215. //------------------ netpack --------------------
  216. //-----------------------------------------------
  217.  
  218. void Hand::thx_request_netpack_cue(int p,callback cb)
  219.   {
  220.   director->add_netpack_cue(this,cb,p);
  221.   }
  222.  
  223. void Hand::thx_stop_netpack_cue(int p,callback cb)
  224.   {
  225.   director->del_netpack_cue(this,cb,p);
  226.   }
  227.  
  228. void Hand::thx_post_netpack(int p)
  229.   {
  230.   director->post_netpacket(p);
  231.   }
  232.