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

  1. // --------------- hand.h
  2.  
  3. #ifndef HAND_H
  4. #define HAND_H
  5.  
  6. #include <typeinfo.h>
  7. #include <fastgraf.h>
  8. #include "debug.h"
  9. #include "settings.h"
  10.  
  11. class Hand;
  12.  
  13. typedef  void(Hand::*callback)(int,int,int);
  14.  
  15. enum EventCode {
  16.   TERMINAL_EVENT,
  17.   HOTKEY_EVENT,
  18.   TIMER_EVENT,
  19.   MESSAGE_EVENT,
  20.   KEYSTROKE_EVENT,
  21.   MOUSECLICK_EVENT,
  22.   MOUSEMOVE_EVENT,
  23.   JOYSTICKBUTTON_EVENT,
  24.   JOYSTICKMOVE_EVENT,
  25.   NETPACK_EVENT
  26. };
  27.  
  28. struct Event   {
  29.   EventCode evtype;
  30.   int code;
  31.   callback func;
  32. };
  33.  
  34. #define DECLARE_CUELIST             \
  35.   static Event MessageEntries[];    \
  36.   virtual Event *GetMessageMap()    \
  37.           { return MessageEntries; }
  38.  
  39. #define CUELIST(hand) \
  40.   Event hand::MessageEntries[] = {
  41.  
  42. #define HOTKEY(k,fn)         \
  43.     { HOTKEY_EVENT,         k, (callback)fn },
  44. #define TIMER(t,fn)          \
  45.     { TIMER_EVENT,          t, (callback)fn },
  46. #define MESSAGE(m,fn)        \
  47.     { MESSAGE_EVENT,        m, (callback)fn },
  48. #define KEYSTROKE(k,fn)      \
  49.     { KEYSTROKE_EVENT,      k, (callback)fn },
  50. #define MOUSECLICK(b,fn)     \
  51.     { MOUSECLICK_EVENT,     b, (callback)fn },
  52. #define MOUSEMOVE(fn)        \
  53.     { MOUSEMOVE_EVENT,      0, (callback)fn },
  54. #define JOYSTICKMOVE(fn)     \
  55.     { JOYSTICKMOVE_EVENT,   0, (callback)fn },
  56. #define JOYSTICKBUTTON(b,fn) \
  57.     { JOYSTICKBUTTON_EVENT, b, (callback)fn },
  58. #define NETPACK(p,fn)        \
  59.     { NETPACK_EVENT,        p, (callback)fn },
  60.  
  61. #define ENDCUELIST            \
  62.   { TERMINAL_EVENT, 0, 0 }    \
  63. };
  64.  
  65. class Director;
  66.  
  67. class Hand  {
  68.   Director* director;
  69.   static int numhands;
  70.   static Hand *hand[MAXHANDS];
  71.  
  72.   static void initialize_hands();
  73.   virtual void request_cues() { }
  74.  
  75.   void thx_request_keystroke_cue(int key,callback);
  76.   void thx_stop_keystroke_cue(int key,callback);
  77.   void thx_request_hotkey_cue(int scancode,callback);
  78.   void thx_stop_hotkey_cue(int scancode,callback);
  79.   void thx_request_timer_cue(int rate,callback);
  80.   void thx_stop_timer_cue(int rate,callback);
  81.   void thx_request_message_cue(int msg,callback);
  82.   void thx_stop_message_cue(int msg,callback);
  83.   void thx_post_message(int msg,int data1, int data2);
  84.   void thx_request_mouseclick_cue(int msg,callback);
  85.   void thx_stop_mouseclick_cue(int msg,callback);
  86.   void thx_request_joystickbutton_cue(int msg,callback);
  87.   void thx_stop_joystickbutton_cue(int msg,callback);
  88.   void thx_request_mousemove_cue(callback);
  89.   void thx_stop_mousemove_cue(callback);
  90.   void thx_request_joystickmove_cue(callback);
  91.   void thx_stop_joystickmove_cue(callback);
  92.   void thx_request_netpack_cue(int,callback);
  93.   void thx_stop_netpack_cue(int,callback);
  94.   void thx_post_netpack(int);
  95.  
  96.   virtual Event *GetMessageMap() { return 0; }
  97.   friend class Director;
  98.   friend class Theatrix;
  99. protected:
  100.   static short int mouseinuse;
  101.   Hand(Director* dir=0);
  102.   virtual ~Hand();
  103.   virtual void initialize()   { }
  104.  
  105.   virtual void stop_director();
  106.   virtual void start_director(const Type_info&);
  107.   Director* my_director()  { return director; }
  108.   void set_hotkeys(int on);
  109.  
  110.   void request_keystroke_cue(int key,callback);
  111.   void stop_keystroke_cue(int key,callback);
  112.  
  113.   void request_hotkey_cue(int scancode,callback);
  114.   void stop_hotkey_cue(int scancode,callback);
  115.  
  116.   void request_timer_cue(int rate,callback);
  117.   void stop_timer_cue(int rate,callback);
  118.  
  119.   void request_message_cue(int msg,callback);
  120.   void stop_message_cue(int msg,callback);
  121.   void post_message(int msg,int data1, int data2);
  122.  
  123.   void request_mouseclick_cue(int b,callback);
  124.   void stop_mouseclick_cue(int b,callback);
  125.  
  126.   void request_mousemove_cue(callback);
  127.   void stop_mousemove_cue(callback);
  128.  
  129.   void request_joystickbutton_cue(int b,callback);
  130.   void stop_joystickbutton_cue(int b,callback);
  131.  
  132.   void request_joystickmove_cue(callback);
  133.   void stop_joystickmove_cue(callback);
  134.  
  135.   void request_netpack_cue(int,callback);
  136.   void stop_netpack_cue(int,callback);
  137.   void post_netpack(int);
  138.  
  139.   void init_mouse()
  140.     { fg_mouseini(); }
  141.   void mouse_visible()
  142.     { fg_mousevis(1); mouseinuse = 1; }
  143.   void mouse_invisible()
  144.     { fg_mousevis(0); mouseinuse = 0; }
  145.   void mouse_cursorshape(char *bitmap)
  146.     { fg_mouse256(bitmap+2, *bitmap, *(bitmap+1)); }
  147.   void get_mouseposition(int *x, int *y, int *b)
  148.     { fg_mousepos(x, y, b); }
  149.   void get_mouseposition(int *x, int *y)
  150.     { int b; fg_mousepos(x, y, &b); }
  151.   void set_mouseposition(int x, int y)
  152.     { fg_mousemov(x, y); }
  153.  
  154. public:
  155.   void set_director(Director* d)  { director=d; }
  156. };
  157.  
  158. // ------------------ Keystroke
  159.  
  160. inline void Hand::request_keystroke_cue(int key,callback cb)
  161. {
  162.   Assert(director != 0);
  163.   thx_request_keystroke_cue(key,cb);
  164. }
  165.  
  166. inline void Hand::stop_keystroke_cue(int key,callback cb)
  167. {
  168.   Assert(director != 0);
  169.   thx_stop_keystroke_cue(key,cb);
  170. }
  171.  
  172. // ------------------ Keydown
  173.  
  174. inline void Hand::request_hotkey_cue(int key,callback cb)
  175. {
  176.   Assert(director != 0);
  177.   thx_request_hotkey_cue(key, cb);
  178. }
  179.  
  180. inline void Hand::stop_hotkey_cue(int key,callback cb)
  181. {
  182.   Assert(director != 0);
  183.   thx_stop_hotkey_cue(key, cb);
  184. }
  185.  
  186. // ------------------ Timer
  187.  
  188. inline void Hand::request_timer_cue(int r,callback cb)
  189. {
  190.   Assert(director != 0);
  191.   thx_request_timer_cue(r, cb);
  192. }
  193.  
  194. inline void Hand::stop_timer_cue(int r,callback cb)
  195. {
  196.   Assert(director != 0);
  197.   thx_stop_timer_cue(r, cb);
  198. }
  199.  
  200. // ------------------ Message
  201.  
  202. inline void Hand::request_message_cue(int msg,callback cb)
  203. {
  204.   Assert(director != 0);
  205.   thx_request_message_cue(msg, cb);
  206. }
  207.  
  208. inline void Hand::stop_message_cue(int msg,callback cb)
  209. {
  210.   Assert(director != 0);
  211.   thx_stop_message_cue(msg, cb);
  212. }
  213.  
  214. inline void Hand::post_message(int msg,int data1=0,int data2=0)
  215. {
  216.   Assert(director != 0);
  217.   thx_post_message(msg, data1, data2);
  218. }
  219.  
  220. // ------------------ mouseclick
  221.  
  222. inline void Hand::request_mouseclick_cue(int b,callback cb)
  223. {
  224.   Assert(director != 0);
  225.   thx_request_mouseclick_cue(b,cb);
  226. }
  227.  
  228. inline void Hand::stop_mouseclick_cue(int b,callback cb)
  229. {
  230.   Assert(director != 0);
  231.   thx_stop_mouseclick_cue(b,cb);
  232. }
  233.  
  234. // ------------------ mousemove
  235.  
  236. inline void Hand::request_mousemove_cue(callback cb)
  237. {
  238.   Assert(director != 0);
  239.   thx_request_mousemove_cue(cb);
  240. }
  241.  
  242. inline void Hand::stop_mousemove_cue(callback cb)
  243. {
  244.   Assert(director != 0);
  245.   thx_stop_mousemove_cue(cb);
  246. }
  247.  
  248. // ------------------ joystickbutton
  249.  
  250. inline void Hand::request_joystickbutton_cue(int b,callback cb)
  251. {
  252.   Assert(director != 0);
  253.   thx_request_joystickbutton_cue(b,cb);
  254. }
  255.  
  256. inline void Hand::stop_joystickbutton_cue(int b,callback cb)
  257. {
  258.   Assert(director != 0);
  259.   thx_stop_joystickbutton_cue(b,cb);
  260. }
  261.  
  262. // ------------------ joystickmove
  263.  
  264. inline void Hand::request_joystickmove_cue(callback cb)
  265. {
  266.   Assert(director != 0);
  267.   thx_request_joystickmove_cue(cb);
  268. }
  269.  
  270. inline void Hand::stop_joystickmove_cue(callback cb)
  271. {
  272.   Assert(director != 0);
  273.   thx_stop_joystickmove_cue(cb);
  274. }
  275.  
  276. // ------------------ netpack
  277.  
  278. inline void Hand::request_netpack_cue(int p,callback cb)
  279. {
  280.   Assert(director != 0);
  281.   thx_request_netpack_cue(p,cb);
  282. }
  283.  
  284. inline void Hand::stop_netpack_cue(int p,callback cb)
  285. {
  286.   Assert(director != 0);
  287.   thx_stop_netpack_cue(p,cb);
  288. }
  289.  
  290. inline void Hand::post_netpack(int p)
  291. {
  292.   Assert(director != 0);
  293.   thx_post_netpack(p);
  294. }
  295.  
  296. #endif
  297.  
  298.