home *** CD-ROM | disk | FTP | other *** search
/ WarCraft 2000 - Nuclear Epidemic / W2000.nrg / SOURCE.War2000 / MousZone.cpp < prev    next >
C/C++ Source or Header  |  1998-08-13  |  2KB  |  100 lines

  1. #include "ddini.h"
  2. #include "ResFile.h"
  3. #include "FastDraw.h"
  4. #include "mgraph.h"
  5. #include "mouse.h"
  6. #include "menu.h"
  7. #include "MapDiscr.h"
  8. class MouseZone{
  9. public:
  10.     int x,y,x1,y1,Index;
  11.     bool Pressed;
  12.     HandlePro* Pro;
  13.     HandlePro* RPro;
  14.     char* Hint;
  15.     MouseZone();
  16. };
  17. MouseZone::MouseZone(){
  18.     Index=-1;
  19.     Hint=NULL;
  20. };
  21. #define NZones 64
  22. MouseZone Zones[NZones];
  23. void InitZones(){
  24.     for(int i=0;i<NZones;i++){
  25.         Zones[i].Index=-1;
  26.         //Zones[i].Hint=NULL;
  27.     };
  28. };
  29. int CreateRZone(int x,int y,int lx,int ly,HandlePro* HPro,HandlePro* RHPro,int Index,char* Hint){
  30.     for(int i=0;i<NZones;i++){
  31.         if(Zones[i].Index==-1)break;
  32.     };
  33.     if(i<NZones){
  34.         MouseZone* Z=&(Zones[i]);
  35.         Z->x=x;
  36.         Z->y=y;
  37.         Z->x1=x+lx-1;
  38.         Z->y1=y+ly-1;
  39.         Z->Pro=HPro;
  40.         Z->RPro=RHPro;
  41.         Z->Index=Index;
  42.         Z->Pressed=false;
  43.         if(int(Z->Hint))
  44.             free(Z->Hint);
  45.         Z->Hint=new char[strlen(Hint)+1];
  46.         strcpy(Z->Hint,Hint);
  47.         return i;
  48.     };
  49.     return -1;
  50. };
  51. int CreateZone(int x,int y,int lx,int ly,HandlePro* HPro,int Index,char* Hint){
  52.     for(int i=0;i<NZones;i++){
  53.         if(Zones[i].Index==-1)break;
  54.     };
  55.     if(i<NZones){
  56.         MouseZone* Z=&(Zones[i]);
  57.         Z->x=x;
  58.         Z->y=y;
  59.         Z->x1=x+lx-1;
  60.         Z->y1=y+ly-1;
  61.         Z->Pro=HPro;
  62.         Z->RPro=NULL;
  63.         Z->Index=Index;
  64.         Z->Pressed=false;
  65.         if(int(Z->Hint))
  66.             free(Z->Hint);
  67.         Z->Hint=new char[strlen(Hint)+1];
  68.         strcpy(Z->Hint,Hint);
  69.         return i;
  70.     };
  71.     return -1;
  72. };
  73. void ControlZones(){
  74.     int i;
  75.     MouseZone* Z;
  76.     if(!Lpressed)
  77.         for(i=0;i<NZones;i++)Zones[i].Pressed=false;
  78.     for(i=0;i<NZones;i++){
  79.         Z=&(Zones[i]);
  80.         if(Z->Index!=-1&&mouseX>=Z->x&&mouseX<=Z->x1&&
  81.             mouseY>=Z->y&&mouseY<=Z->y1)break;
  82.     };
  83.     if(i<NZones){
  84.         if(!Z->Pressed){
  85.             if(Lpressed)Z->Pressed=true;
  86.             if(int(Z->Hint)){
  87.                 AssignHint(Z->Hint,3);
  88.             };
  89.             if(Lpressed&&int(Z->Pro))(*Z->Pro)(Z->Index);
  90.             Lpressed=false;
  91.             if(Rpressed&&Z->RPro)(*Z->RPro)(Z->Index);
  92.             Rpressed=false;
  93.         };
  94.     };
  95.  
  96. };
  97. void DeleteZone(int i){
  98.     if(i<NZones&&i>=0)Zones[i].Index=-1;
  99. };
  100.