home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / PROGRAMM / CPPMOUSE.ZIP / DEMO.CPP next >
Text File  |  1990-12-01  |  4KB  |  109 lines

  1. /* DEMO.CPP:  Demo of basic mouse operations */
  2. /* Translated by Kevin Brooks from C routines written Ken Porter */
  3.  
  4. /* INCLUDES */
  5. #include <stdio.h>
  6. #include <dos.h>
  7. #include <stream.hpp>
  8.  
  9. #include "mouse.hpp"
  10.  
  11. /* GLOBALS */
  12. union REGS inreg, outreg;
  13.  
  14. /* LOCAL FUNCTIONS */
  15. void  clrScr (void);
  16. void  gotoxy (int col, int row);
  17.  
  18.  
  19. /* --------------------------------------------------------------- */
  20. main ()
  21. {
  22.   Mouse      theMouse;
  23.   locRec     *its;                           /* from mouse inquiries */
  24.   int        col, row;
  25.   char       input [80];
  26.  
  27.   clrScr ();                                       /* clear screen */
  28.   gotoxy(0, 0);
  29.   theMouse.Reset();                             /* reset mouse */
  30.   if (theMouse.exists) {             /* do following if it exists */
  31.  
  32. /* Software mouse cursor */
  33.     puts ("Software cursor:");
  34.     printf ("Demo of a mouse with %d buttons\n", theMouse.nButtons);
  35.     puts ("Move the mouse around and click the left button");
  36.     puts ("Click the right button for hardware demo\n");
  37.     theMouse.TextCursor(SOFTWARE, 0x0000, 0x0718);      /* set s/w cursor */
  38.     theMouse.Show();                                        /* turn it on */
  39.     do {
  40.       theMouse.Released(Left);                 /* check left button */
  41.       if (theMouse.opCount > 0) {
  42.         theMouse.Hide ();                  /* cursor off in case of scroll */
  43.         printf ("\nMouse is at col %d, row %d", theMouse.column,
  44.                 theMouse.row);                      /* position report */
  45.         theMouse.Show();                                /* cursor back on */
  46.       }
  47.       theMouse.Released(Right);                /* check right button */
  48.     } while (theMouse.opCount == 0);          /* repeat until operated */
  49.  
  50. /* Now do hardware mouse cursor demo */
  51.     clrScr ();                                     /* clear screen */
  52.     gotoxy(0, 0);
  53.     puts ("Hardware cursor:");
  54.     puts ("Move the mouse, click left button");
  55.     puts ("Type something and press Enter");
  56.     puts ("Click right button to end demo");
  57.     theMouse.Reset();                           /* reset mouse */
  58.     theMouse.TextCursor(HARDWARE, 2, 5);                /* set h/w cursor */
  59.     theMouse.Show();                                         /* cursor on */
  60.     do {
  61.       theMouse.Released(Left);                 /* check left button */
  62.       if (theMouse.opCount > 0) {                 /* if operated . . . */
  63.         col = theMouse.column / 8;            /* compute text position */
  64.         row = theMouse.row / 8;
  65.         gotoxy (col, row);                             /* go there */
  66.         putchar ('?');                                   /* prompt */
  67.         gets (input);
  68.         theMouse.Moveto (theMouse.column, theMouse.row);       /* restore position */
  69.       }
  70.       theMouse.Released(Right);                /* check right button */
  71.     } while (theMouse.opCount == 0);          /* repeat until operated */
  72.  
  73. /* Clean up and end of job */
  74.     theMouse.TextCursor (HARDWARE, 6, 7);      /* use 11, 12 if mono board */
  75.     theMouse.Reset ();                                     /* reset cursor */
  76.     clrScr ();                                     /* clear screen */
  77.   } else
  78.     puts ("Mouse not present in system. Demo can't run.");
  79. } /* ------------------------ */
  80.  
  81. void  clrScr (void)                           /* clears the screen */
  82.             /* Uses ROM BIOS int 10h to reset video mode to itself */
  83. {
  84. union REGS  inreg, outreg;
  85.    inreg.h.ah = 6;
  86.    inreg.h.al = 0;
  87.    inreg.h.ch = 0;
  88.    inreg.h.cl = 0;
  89.    inreg.h.dh = 24;
  90.    inreg.h.dl = 79;
  91.    inreg.h.bh = (char)((0<<4) | 7);
  92.    int86(0x10, &inreg, &outreg);
  93.  
  94. } /* ------------------------ */
  95.  
  96. void  gotoxy (int col, int row)            /* position text cursor */
  97.                                           /* Uses ROM BIOS int 10h */
  98. {
  99. union REGS  inreg;
  100.  
  101.   inreg.h.ah = 2;                    /* function 2 sets cursor pos */
  102.   inreg.h.bh = 0;                        /* video page 0 is active */
  103.   inreg.h.dh = (char)row;
  104.   inreg.h.dl = (char)col;
  105.   int86 (0x10, &inreg, &inreg);
  106. } /* ------------------------ */
  107.  
  108.  
  109.