home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / D / SVGALIB / SVGALIB1.TAR / svgalib / demos / mousetest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-02  |  1.5 KB  |  80 lines

  1. /* Program to test the svgalib mouse functions. */
  2.  
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <vga.h>
  6. #include <vgagl.h>
  7. #include <vgamouse.h>
  8.  
  9.  
  10. /* Manually open and close mouse? */
  11. #define MANUALLY_SETUP_MOUSE_NOT
  12.  
  13.  
  14. static int newcolor() {
  15.     if (BYTESPERPIXEL == 1)
  16.         return random() % 15 + 1;
  17.     return gl_rgbcolor(random() & 255, random() & 255, random() & 255);
  18. }
  19.  
  20.  
  21. void main() {
  22.     int vgamode, color, leftpressed;
  23.     int x, y, button;
  24.     vga_init();
  25.     vgamode = vga_getdefaultmode();
  26.     if (vgamode == -1)    
  27.         vgamode = G320x200x256;
  28.     
  29.     if (!vga_hasmode(vgamode)) {
  30.         printf("Mode not available.\n");
  31.         exit(-1);
  32.     }
  33.  
  34.     #ifndef MANUALLY_SETUP_MOUSE
  35.     /* Enable automatic mouse setup at mode set. */
  36.     vga_setmousesupport(1);
  37.     #endif
  38.     vga_setmode(vgamode);
  39.     /* Disable wrapping (default). */
  40.     /* mouse_setwrap(MOUSE_NOWRAP); */
  41.     gl_setcontextvga(vgamode);
  42.     gl_enableclipping();
  43.  
  44.     #ifdef MANUALLY_SETUP_MOUSE
  45.     mouse_init("/dev/mouse", MOUSE_MICROSOFT, MOUSE_DEFAULTSAMPLERATE);
  46.     mouse_setxrange(0, WIDTH - 1);
  47.     mouse_setyrange(0, HEIGHT - 1);
  48.     mouse_setwrap(MOUSE_NOWRAP);
  49.     #endif
  50.  
  51.     color = newcolor();
  52.     leftpressed = 0;
  53.     x = 0;
  54.     y = 0;
  55.     for (;;) {
  56.         gl_fillbox(x, y, 5, 5, color);
  57.         mouse_update();
  58.         x = mouse_getx();
  59.         y = mouse_gety();
  60.         button = mouse_getbutton();
  61.         if (button & MOUSE_LEFTBUTTON) {
  62.             if (!leftpressed) {
  63.                 color = newcolor();
  64.                 leftpressed = 1;
  65.             }
  66.         }
  67.         else
  68.             leftpressed = 0;
  69.         if (button & MOUSE_RIGHTBUTTON)
  70.             break;
  71.     }
  72.  
  73.     #ifdef MANUALLY_SETUP_MOUSE
  74.     mouse_close();
  75.     #endif
  76.  
  77.     vga_setmode(TEXT);
  78.     exit(0);
  79. }
  80.