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

  1. #include "ddini.h"
  2. #include "ResFile.h"
  3. #include "FastDraw.h"
  4. #include "mgraph.h"
  5. #include "mode.h"
  6. #define MaxMX 32
  7. #define MsizeX 32
  8. extern int SCRSizeX;
  9. extern int SCRSizeY;
  10. extern int RSCRSizeX;
  11. extern int RSCRSizeY;
  12. extern int COPYSizeX;
  13. RLCTable mptr;
  14. bool realLpressed;
  15. bool realRpressed;
  16. int curptr;
  17. int mouseX;
  18. int    mouseY;
  19. bool Lpressed;
  20. bool Rpressed;
  21. static char buf1[1024];
  22. static char buf2[1024];
  23. static char buf1o[1024];
  24. static char buf2o[1024];
  25. static int OldMX;
  26. static int OldMY;
  27. static int MX;
  28. static int MY;
  29. static bool LockMouse;
  30. extern bool xLockMouse;
  31. int curdx;
  32. int curdy;
  33. bool MNotRemoved;
  34. //retreives data from the screen buffer to field 32x32
  35. void GetMData(void* dest,void* src,int x,int y,int SSizeX,int SSizeY){
  36.     int Lx=32;
  37.     int Ly=32;
  38.     int x1=x;
  39.     int y1=y;
  40.     int bx=0;//x-coord. on bitbap 32x32
  41.     int by=0;
  42.     if(x1<0){
  43.         bx=-x1;
  44.         Lx+=x1;
  45.         x1=0;
  46.     };
  47.     if(y1<0){
  48.         by=-y1;
  49.         Ly+=y1;
  50.         y1=0;
  51.     };
  52.     if(x1+32>SSizeX)Lx=SSizeX-x1;
  53.     if(y1+32>SSizeY)Ly=SSizeY-y1;
  54.     if(Lx<=0||Ly<=0)return;
  55.     int sofs=int(src)+x1+y1*SSizeX;
  56.     int dofs=int(dest)+bx+(by<<5);
  57.     int Lx4=Lx>>2;
  58.     int Lx1=Lx&3;
  59.     int adds=SSizeX-Lx;
  60.     int addd=32-Lx;
  61.     __asm{
  62.         push    esi
  63.         push    edi
  64.         mov        edx,Ly
  65.         mov        esi,sofs
  66.         mov        edi,dofs
  67.         cld
  68. lpp1:    mov        ecx,Lx4
  69.         jcxz    lpp2
  70.         rep        movsd
  71. lpp2:    mov        ecx,Lx1
  72.         jcxz    lpp3
  73.         rep        movsb
  74. lpp3:    add        esi,adds
  75.         add        edi,addd
  76.         dec        edx
  77.         jnz        lpp1
  78.         pop        edi
  79.         pop        esi
  80.     };
  81. };
  82. bool CmpMData(void* dest,void* src,int x,int y,int SSizeX,int SSizeY){
  83.     int Lx=32;
  84.     int Ly=32;
  85.     int x1=x;
  86.     int y1=y;
  87.     int bx=0;//x-coord. on bitbap 32x32
  88.     int by=0;
  89.     if(x1<0){
  90.         bx=-x1;
  91.         Lx+=x1;
  92.         x1=0;
  93.     };
  94.     if(y1<0){
  95.         by=-y1;
  96.         Ly+=y1;
  97.         y1=0;
  98.     };
  99.     if(x1+32>SSizeX)Lx=SSizeX-x1;
  100.     if(y1+32>SSizeY)Ly=SSizeY-y1;
  101.     if(Lx<=0||Ly<=0)return false;
  102.     int sofs=int(src)+x1+y1*SSizeX;
  103.     int dofs=int(dest)+bx+(by<<5);
  104.     int Lx4=Lx>>2;
  105.     int Lx1=Lx&3;
  106.     int adds=SSizeX-Lx;
  107.     int addd=32-Lx;
  108.     bool notequal=false;
  109.     __asm{
  110.         push    esi
  111.         push    edi
  112.         mov        edx,Ly
  113.         mov        esi,sofs
  114.         mov        edi,dofs
  115.         cld
  116. lpp1:    mov        ecx,Lx4
  117.         jcxz    lpp2
  118.         repe    cmpsd
  119.         jne        noteq
  120. lpp2:    mov        ecx,Lx1
  121.         jcxz    lpp3
  122.         repe    cmpsb
  123.         jne        noteq
  124. lpp3:    add        esi,adds
  125.         add        edi,addd
  126.         dec        edx
  127.         jnz        lpp1
  128.         jmp        lpp4
  129. noteq:    mov        notequal,1
  130. lpp4:    pop        edi
  131.         pop        esi
  132.     };
  133.     return notequal;
  134. };
  135. void RestoreMData(void* scrn,void* buf,void* comp,int x,int y,int SSizeX,int SSizeY){
  136.     int Lx=32;
  137.     int Ly=32;
  138.     int x1=x;
  139.     int y1=y;
  140.     int bx=0;//x-coord. on bitbap 32x32
  141.     int by=0;
  142.     if(x1<0){
  143.         bx=-x1;
  144.         Lx+=x1;
  145.         x1=0;
  146.     };
  147.     if(y1<0){
  148.         by=-y1;
  149.         Ly+=y1;
  150.         y1=0;
  151.     };
  152.     if(x1+32>SSizeX)Lx=SSizeX-x1;
  153.     if(y1+32>SSizeY)Ly=SSizeY-y1;
  154.     if(Lx<=0||Ly<=0)return;
  155.     int src1=int(buf)+bx+(by<<5);
  156.     int srcom=int(comp)+bx+(by<<5);
  157.     int scrof=int(scrn)+x1+y1*SSizeX;
  158.     int addscr=SSizeX-Lx;
  159.     int add32=32-Lx;
  160.     __asm{
  161.         push    esi
  162.         push    edi
  163.         mov        edx,Ly
  164.         mov        esi,src1
  165.         mov        ebx,srcom
  166.         mov        edi,scrof
  167.         cld
  168. lpp0:    mov        ecx,Lx
  169. lpp1:    lodsb    
  170.         mov        ah,[edi]
  171.         cmp        ah,[ebx]
  172.         jnz        lpp2
  173.         mov        [edi],al
  174. lpp2:    inc        edi
  175.         inc        ebx
  176.         dec        ecx
  177.         jnz        lpp1
  178.         add        edi,addscr
  179.         add        ebx,add32
  180.         add        esi,add32
  181.         dec        edx
  182.         jnz        lpp0
  183.         pop        edi
  184.         pop        esi
  185.     };
  186. };
  187. void LoadPointer(LPCSTR s){
  188.     LoadRLC(s,&mptr);
  189.     curptr=0;
  190.     mouseX=0;
  191.     mouseY=0;
  192.     LockMouse=false;
  193.     memset(buf1,0,sizeof buf1);
  194.     memset(buf2,0,sizeof buf2);
  195.     //MouseOn=false;
  196.     //Transferred=true;
  197.     curdx=0;
  198.     curdy=0;
  199. };
  200. typedef unsigned short word;
  201. int GetF(word k);
  202. extern word fmap[256][256];
  203. extern int mapx;
  204. extern int mapy;
  205. extern int smapx;
  206. extern int smapy;
  207.  
  208. extern RLCFont  f16x16w;
  209. void CBar(int x,int y,int Lx,int Ly,byte c);
  210. void SetMPtr(int x,int y,int key){
  211.     if(x>RSCRSizeX-1)x=RSCRSizeX-1;
  212.     if ((x!=mouseX)|(y!=mouseY)){
  213.         mouseX=x;
  214.         mouseY=y;
  215.         //Transferred=false;
  216.         //Transferreda=false;
  217.         realLpressed=key&MK_LBUTTON;
  218.         realRpressed=key&MK_RBUTTON;
  219.         //debug part
  220.         /*int xx=mapx+((x-smapx)>>5);
  221.         int yy=mapy+((y-smapy)>>5);
  222.         word* fm=&fmap[yy][xx];
  223.         char uuu[128];
  224.         sprintf(uuu,"%d,%d,%d,%d",GetF(fm[0]),GetF(fm[1]),GetF(fm[256]),GetF(fm[257]));
  225.         CBar(180,200,200,30,0);
  226.         ShowString(180,200,uuu,&f16x16w);
  227.         FlipPages();*/
  228.     };
  229. };
  230. //Redraw mouse in the offscreen buffer
  231. //and prepare data for onscreen transferring 
  232. void RedrawOffScreenMouse(){
  233.     if(xLockMouse)return;
  234.     LockMouse=true;
  235.     MX=mouseX-curdx;
  236.     MY=mouseY-curdy;
  237.     RestoreMData(ScreenPtr,(void*)buf1,(void*)buf2,OldMX,OldMY,SCRSizeX,SCRSizeY);
  238.     GetMData((void*)buf1,ScreenPtr,MX,MY,SCRSizeX,SCRSizeY);
  239.     //ShowRLCItem(MX+32,MY,&mptr,curptr+4096,0);
  240.     ShowRLCItem(MX,MY,&mptr,curptr,0);
  241.     GetMData((void*)buf2,ScreenPtr,MX,MY,SCRSizeX,SCRSizeY);
  242. };
  243. void RedrawScreenMouse(){
  244.     if(xLockMouse)return;
  245.     RestoreMData(RealScreenPtr,(void*)buf1o,(void*)buf2o,OldMX,OldMY,RSCRSizeX,RSCRSizeY);
  246.     GetMData((void*)buf1o,RealScreenPtr,MX,MY,RSCRSizeX,RSCRSizeY);
  247.     void* osp=ScreenPtr;
  248.     int osx=SCRSizeX;
  249.     int sw=ScrWidth;
  250.     ScrWidth=RSCRSizeX;
  251.     ScreenPtr=RealScreenPtr;
  252.     SCRSizeX=RSCRSizeX;
  253.     //ShowRLCItem(MX+32,MY,&mptr,curptr+4096,0);
  254.     ShowRLCItem(MX,MY,&mptr,curptr,0);
  255.     SCRSizeX=osx;
  256.     ScreenPtr=osp;
  257.     ScrWidth=sw;
  258.     GetMData((void*)buf2o,RealScreenPtr,MX,MY,RSCRSizeX,RSCRSizeY);
  259. };
  260. void OnMouseMoveRedraw(){
  261.     if(xLockMouse)return;
  262.     if(LockMouse)return;
  263.     RedrawOffScreenMouse();
  264.     RedrawScreenMouse();
  265.     LockMouse=false;
  266.     OldMX=MX;
  267.     OldMY=MY;
  268. };
  269. void PostRedrawMouse(){
  270.     if(xLockMouse)return;
  271.     bool need=true;
  272.     if(MX==OldMX&&MY==OldMY)
  273.         need=CmpMData((void*)buf2o,RealScreenPtr,MX,MY,RSCRSizeX,RSCRSizeY);
  274.     if(need){
  275.         RestoreMData(RealScreenPtr,(void*)buf1,(void*)buf2,MX,MY,RSCRSizeX,RSCRSizeY);
  276.         RestoreMData(RealScreenPtr,(void*)buf1o,(void*)buf2o,OldMX,OldMY,RSCRSizeX,RSCRSizeY);
  277.         GetMData((void*)buf1o,RealScreenPtr,MX,MY,RSCRSizeX,RSCRSizeY);
  278.         void* osp=ScreenPtr;
  279.         int osx=SCRSizeX;
  280.         int sw=ScrWidth;
  281.         ScrWidth=RSCRSizeX;
  282.         ScreenPtr=RealScreenPtr;
  283.         SCRSizeX=RSCRSizeX;
  284.         //WindX=120;
  285.         //WindX1=550;
  286.         //ShowRLCItem(MX+32,MY,&mptr,curptr+4096,0);
  287.         ShowRLCItem(MX,MY,&mptr,curptr,0);
  288.         SCRSizeX=osx;
  289.         ScreenPtr=osp;
  290.         ScrWidth=sw;
  291.         GetMData((void*)buf2o,RealScreenPtr,MX,MY,RSCRSizeX,RSCRSizeY);
  292.         OldMX=MX;
  293.         OldMY=MY;
  294.     };
  295.     LockMouse=false;
  296. };