home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ABUSESRC.ZIP / AbuseSrc / imlib / port / svga / mouse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-07  |  2.0 KB  |  106 lines

  1. #include "video.hpp"
  2. #include "sprite.hpp"
  3. #include "image.hpp"
  4. #include "filter.hpp"
  5. #include "mdlread.hpp"
  6. #include "monoprnt.hpp"
  7. #include "mouse.hpp"
  8. #include "dprint.hpp"
  9. #include <vgamouse.h>
  10. #include <vga.h>
  11.  
  12. unsigned char def_mouse[]=
  13.     { 0,2,0,0,0,0,0,0,
  14.       2,1,2,0,0,0,0,0,
  15.       2,1,1,2,0,0,0,0,
  16.       2,1,1,1,2,0,0,0,
  17.       2,1,1,1,1,2,0,0,
  18.       2,1,1,1,1,1,2,0,
  19.       0,2,1,1,2,2,0,0,
  20.       0,0,2,1,1,2,0,0,
  21.       0,0,2,1,1,2,0,0,
  22.       0,0,0,2,2,0,0,0 };    // 8x10
  23.  
  24. int Mbut,Mx,My;
  25.  
  26. void JCMouse::set_shape(image *im, int centerx, int centery)
  27. {
  28.   sp->change_visual(im,1);
  29.   cx=-centerx;
  30.   cy=-centery;
  31. }
  32.  
  33. void
  34. JCMouse_init ()
  35. {
  36.   if (mouse_init ("/dev/mouse", vga_getmousetype (), MOUSE_DEFAULTSAMPLERATE))
  37.     {
  38.       printf (0, "failed to initialize mouse; did you set the right type in libvga.config?\n");
  39.       exit (1);
  40.     }
  41. }  
  42.  
  43. JCMouse::JCMouse(image *Screen, palette *pal)
  44. {
  45.   image *im;
  46.   int br,dr;
  47.   filter f;
  48.   but=0;
  49.   cx=cy=0;
  50.   here=1;
  51.  
  52.   if (here)                     // is it here?
  53.   {
  54.     screen=Screen;
  55.     br=pal->brightest(1);
  56.     dr=pal->darkest(1);
  57.     f.set(1,br);
  58.     f.set(2,dr);
  59.     im=new image(8,10,def_mouse);
  60.     f.apply(im);
  61.     sp=new sprite(Screen,im,100,100);
  62.     mouse_setxrange(0,Screen->width()-1);
  63.     mouse_setyrange(0,Screen->height()-1);
  64.     mouse_setwrap(MOUSE_NOWRAP);
  65.     mouse_update();
  66.     update();
  67.     update();
  68.   }
  69.   mx=Screen->width()/2;
  70.   my=Screen->height()/2;
  71.  
  72. }
  73.  
  74. void JCMouse::update(int newx, int newy, int new_but)
  75. {
  76.   int l,r,m;
  77.   if (newx<0)
  78.   {
  79.     lbut=but; lx=mx; ly=my;
  80.     mouse_update();
  81.     mx=mouse_getx();
  82.     my=mouse_gety();
  83.     but=mouse_getbutton();
  84.     l=but&4; r=but&1; m=but&2;
  85.     but=but&(0xff-7);
  86.     if (l) but+=1;
  87.     if (r) but+=2;
  88.     if (m) but+=4;
  89.   } else 
  90.   { mx=newx; my=newy; but=new_but; }
  91. }
  92.  
  93. void JCMouse::set_position(int new_mx, int new_my)
  94. {
  95.   mx=new_mx;
  96.   my=new_my;
  97.   mouse_setposition(new_mx,new_my);
  98. }
  99.  
  100.  
  101. JCMouse::~JCMouse()
  102. {
  103.   mouse_close();
  104. }
  105.  
  106.