Subversion Repositories Kolibri OS

Rev

Rev 5674 | Rev 5996 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #ifndef INCLUDE_MOUSE_H
  2. #define INCLUDE_MOUSE_H
  3. #print "[include <mouse.h>]\n"
  4.  
  5. //Button MOUSE
  6. #define MOUSE_LEFT   001b
  7. #define MOUSE_RIGHT  010b
  8. #define MOUSE_LR     011b
  9. #define MOUSE_CENTER 100b
  10.  
  11. /**
  12.  *  The structure of the MOUSE
  13.  *  x - coordinate X
  14.  *  y - coordinate Y
  15.  *  xx and yy - time coordinates
  16.  *  lkm - left MOUSE button
  17.  *  pkm - right MOUSE button
  18.  *  mkm - MOUSE wheel
  19.  *  key - keycode button
  20.  *  tmp - time keycode
  21.  *  down - key event press
  22.  *  up - key release events
  23.  *  move - event MOUSE movements
  24.  *  click - when clicked
  25.  *  dblclick - double-click the default 50 (500 ms)
  26.  *  drag - drag the element event
  27.  */
  28.  
  29. :dword __TMP_TIME,MOUSE_TIME;
  30. :struct MOUSE
  31. {
  32.         signed x,y,xx,yy,lkm,mkm,pkm,key,tmp,tmp_time,hor,vert,down,up,move,click,dblclick,drag,left,top;
  33.         dword handle,_;
  34.         byte cmd;
  35.         void clearTime();
  36.         void get();
  37.         void set();
  38.         void center();
  39.         dword hide();
  40.         void slider();
  41.         void show();
  42. } mouse;
  43. :void MOUSE::clearTime()
  44. {
  45.         tmp_time = GetStartTime()+MOUSE_TIME;
  46. }
  47. :void MOUSE::show()
  48. {
  49.         if(!handle)return;
  50.         ECX = handle;
  51.         EAX = 37;
  52.         EBX = 5;
  53.         $int 0x40;
  54. }
  55. :dword MOUSE::hide()
  56. {
  57.         if(!_)
  58.         {
  59.                 EAX = 68;
  60.                 EBX = 12;
  61.                 ECX = 32*32*4;
  62.                 $int 0x40
  63.                 ECX = EAX;
  64.                 _ = EAX;
  65.         } else ECX = _;
  66.         EAX = 37;
  67.         EBX = 4;
  68.         DX  = 2;
  69.         $int 0x40;
  70.         handle = EAX;
  71.         ECX = EAX;
  72.         EAX = 37;
  73.         EBX = 5;
  74.         $int 0x40;
  75.         handle = EAX;
  76. }
  77.  
  78. //set new attributes MOUSE
  79. :void MOUSE::set()
  80. {
  81.         if((xx!=x)||(yy!=y))
  82.         {
  83.                 EAX = 18;
  84.                 EBX = 19;
  85.                 ECX = 4;
  86.                 EDX = (x<<16)+y;
  87.                 $int 0x40
  88.                 //move = true;
  89.         }
  90.         if((key)||(lkm|mkm|pkm))&&(down|up|click|dblclick|move)
  91.         {
  92.                 if(lkm|mkm|pkm)key=(lkm)|(pkm<<1)|(2<<mkm);
  93.                 EAX = 18;
  94.                 EBX = 19;
  95.                 ECX = key;
  96.                 EDX = (x<<16)+y;
  97.                 $int 0x40
  98.         }
  99. }
  100.  
  101. :void MOUSE::center()
  102. {
  103.         EAX = 18;
  104.         EBX = 15;
  105.         $int 0x40
  106. }
  107.  
  108. //get new attributes MOUSE
  109. :void MOUSE::get()
  110. {
  111.         EAX = 37;
  112.         EBX = 1;
  113.         $int    0x40
  114.         $mov    ebx, eax
  115.         $shr    eax, 16
  116.         $and    ebx,0x0000FFFF
  117.         x = EAX;
  118.         y = EBX;
  119.         if (x>6000) x-=65535;
  120.         if (y>6000) y-=65535;
  121.         EAX = 37;
  122.         EBX = 2;
  123.         $int    0x40
  124.         $mov    ebx, eax
  125.         $mov    ecx, eax
  126.         key = EAX;
  127.         $and    eax, 0x00000001
  128.         $shr    ebx, 1
  129.         $and    ebx, 0x00000001
  130.         $shr    ecx, 2
  131.         $and    ecx, 0x00000001
  132.         lkm = EAX;
  133.         pkm = EBX;
  134.         mkm = ECX;
  135.        
  136.         //when you release the MOUSE button
  137.         // Mouse Move Event
  138.         if(xx!=x)||(yy!=y)
  139.         {
  140.                 move = true;
  141.                 xx = x;
  142.                 yy = y;
  143.         }
  144.         else move = false;
  145.         // Mouse Up Event
  146.         if(cmd)&&(!key){
  147.                 up   = true;
  148.                 down = false;
  149.                 drag = false;
  150.                 if(!move) click = true;
  151.                 __TMP_TIME = GetStartTime();
  152.                 if(__TMP_TIME-tmp_time<=MOUSE_TIME)
  153.                 {
  154.                         dblclick = true;
  155.                         click    = false;
  156.                 }
  157.                 tmp_time = __TMP_TIME;
  158.                 //returns the key code
  159.                 key = tmp;
  160.                 lkm = 1&tmp;
  161.                 pkm = 2&tmp;
  162.                 pkm >>= 1;
  163.                 mkm = 4&tmp;
  164.                 mkm >>= 2;
  165.                 cmd = false;
  166.         }
  167.        
  168.         //when you press the MOUSE button
  169.         // Mouse Down Event/Move Event
  170.         else
  171.         {
  172.             up       = false;
  173.                 click    = false;
  174.                 dblclick = false;
  175.                 down     = false;
  176.                 // Mouse Move Event
  177.                 if(key)if(!cmd)
  178.                 {
  179.                         down = true;
  180.                         if(move)drag = true;
  181.                         cmd = true;
  182.                         tmp=key;
  183.                 }
  184.         }
  185.        
  186.         //scroll
  187.         EAX = 37;
  188.         EBX = 7;
  189.         $int    0x40
  190.         $mov    ebx, eax
  191.         $shr    eax, 16
  192.         $and    ebx,0x0000FFFF
  193.         //hor = EAX;
  194.         vert = EBX;
  195. }
  196.  
  197.  
  198.  
  199. :void MOUSE::slider()
  200. {
  201.         signed _x,_y;
  202.         if(!handle)hide();
  203.         get();
  204.         _x = x;_y = y;
  205.         pause(5);
  206.         get();
  207.         left = _x - x;
  208.         top  = _y - y;
  209.         center();
  210.         get();
  211.         _x = x;_y = y;
  212.         pause(5);
  213. }
  214.  
  215. #endif