home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ Games Programming
/
CPPGAMES.ISO
/
thx
/
source
/
theatrix
/
hand.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-26
|
6KB
|
232 lines
#include <conio.h> // kbhit getch
#include "theatrix.h"
#include "director.h"
#include "standard.h"
#include "hand.h"
#include "settings.h"
Hand *Hand::hand[MAXHANDS];
int Hand::numhands;
short int Hand::mouseinuse;
const char dirmsg[] = "Program has no directors";
Hand::Hand(Director* dir) : director(dir)
{
if (numhands == MAXHANDS)
Theatrix::fatal("Too many hands");
hand[numhands++]=this;
}
Hand::~Hand()
{
if (director)
director->delete_hand(this);
}
void Hand::initialize_hands()
{
for (int i=0;i<numhands;i++)
{
Event *map = hand[i]->GetMessageMap();
if (map != 0)
{
while (map->evtype != 0)
{
switch (map->evtype)
{
case HOTKEY_EVENT:
hand[i]->request_hotkey_cue(map->code, map->func);
break;
case TIMER_EVENT:
hand[i]->request_timer_cue(map->code, map->func);
break;
case MESSAGE_EVENT:
hand[i]->request_message_cue(map->code, map->func);
break;
case KEYSTROKE_EVENT:
hand[i]->request_keystroke_cue(map->code, map->func);
break;
case MOUSECLICK_EVENT:
hand[i]->request_mouseclick_cue(map->code, map->func);
break;
case MOUSEMOVE_EVENT:
hand[i]->request_mousemove_cue(map->func);
break;
case JOYSTICKBUTTON_EVENT:
hand[i]->request_joystickbutton_cue(map->code, map->func);
break;
case JOYSTICKMOVE_EVENT:
hand[i]->request_joystickmove_cue(map->func);
break;
case NETPACK_EVENT:
hand[i]->request_netpack_cue(map->code,map->func);
break;
default:
break;
}
map++;
}
}
hand[i]->initialize();
}
}
void Hand::set_hotkeys(int mode)
{
if (!director)
Theatrix::fatal(dirmsg);
director->set_keydownmode(mode);
if (mode==OFF)
while (kbhit()) getch();
}
void Hand::stop_director()
{
if (!director)
Theatrix::fatal(dirmsg);
director->quit();
director->set_next_director(&typeid(StopDirector));
}
void Hand::start_director(const Type_info& dir)
{
stop_director();
director->set_next_director(&dir);
}
//-----------------------------------------------
//------------------ Keystroke --------------------
//-----------------------------------------------
void Hand::thx_request_keystroke_cue(int key,callback cb)
{
director->add_keystroke_cue(this,cb,key);
}
void Hand::thx_stop_keystroke_cue(int key,callback cb)
{
director->del_keystroke_cue(this,cb,key);
}
//-----------------------------------------------
//------------------ Keydown --------------------
//-----------------------------------------------
void Hand::thx_request_hotkey_cue(int key,callback cb)
{
director->add_keydown_cue(this,cb,key);
}
void Hand::thx_stop_hotkey_cue(int key,callback cb)
{
director->del_keydown_cue(this,cb,key);
}
//-----------------------------------------------
//------------------ Timer ----------------------
//-----------------------------------------------
void Hand::thx_request_timer_cue(int r,callback cb)
{
director->add_timer_cue(this,cb,r);
}
void Hand::thx_stop_timer_cue(int r,callback cb)
{
director->del_timer_cue(this,cb,r);
}
//-----------------------------------------------
//------------------ Message --------------------
//-----------------------------------------------
void Hand::thx_request_message_cue(int msg,callback cb)
{
director->add_message_cue(this,cb,msg);
}
void Hand::thx_stop_message_cue(int msg,callback cb)
{
director->del_message_cue(this,cb,msg);
}
void Hand::thx_post_message(int msg,int data1,int data2)
{
director->submit_message(msg,data1,data2);
}
//-----------------------------------------------
//------------------ mouseclick -----------------
//-----------------------------------------------
void Hand::thx_request_mouseclick_cue(int b,callback cb)
{
director->add_mouseclick_cue(this,cb,b);
}
void Hand::thx_stop_mouseclick_cue(int b,callback cb)
{
director->del_mouseclick_cue(this,cb,b);
}
//-----------------------------------------------
//------------------ mousemove ------------------
//-----------------------------------------------
void Hand::thx_request_mousemove_cue(callback cb)
{
director->add_mousemove_cue(this,cb);
}
void Hand::thx_stop_mousemove_cue(callback cb)
{
director->del_mousemove_cue(this,cb);
}
//-----------------------------------------------
//------------------ joystickbutton -----------------
//-----------------------------------------------
void Hand::thx_request_joystickbutton_cue(int b,callback cb)
{
director->add_joystickbutton_cue(this,cb,b);
}
void Hand::thx_stop_joystickbutton_cue(int b,callback cb)
{
director->del_joystickbutton_cue(this,cb,b);
}
//-----------------------------------------------
//------------------ joystickmove ------------------
//-----------------------------------------------
void Hand::thx_request_joystickmove_cue(callback cb)
{
director->add_joystickmove_cue(this,cb);
}
void Hand::thx_stop_joystickmove_cue(callback cb)
{
director->del_joystickmove_cue(this,cb);
}
//-----------------------------------------------
//------------------ netpack --------------------
//-----------------------------------------------
void Hand::thx_request_netpack_cue(int p,callback cb)
{
director->add_netpack_cue(this,cb,p);
}
void Hand::thx_stop_netpack_cue(int p,callback cb)
{
director->del_netpack_cue(this,cb,p);
}
void Hand::thx_post_netpack(int p)
{
director->post_netpacket(p);
}