home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / FNTPAK32.ZIP / C.EXE / DEMOMOUS.C < prev    next >
C/C++ Source or Header  |  1995-08-16  |  7KB  |  205 lines

  1. /**********************************************************************
  2.    DemoMous.C                       Copyright 1994, Rob W. Smetana
  3.  
  4.    Turn Screen Swapping ON if appropriate.
  5.  
  6.    Demonstrate how to use our mouse routines.
  7.    Show how to select mouse shapes from a "library" of over 65 shapes.
  8.  
  9.    Demonstrate:   rsThereIsAMouse                \
  10.                   rsShowCursor & rsHideCursor     )    all in
  11.                   rsSetTextCursor (3 versions)    )    Mouse.Obj
  12.                   rsButtonPressed                /
  13.  
  14.                   rsLoadMouseCursor              \     all in
  15.                   Num16Shapes                     )    LdCursor.Obj
  16.                   Num8Shapes                     /
  17.  
  18.    NOTE:  All parameters are passed by VALUE -- EXCEPT Row and Column
  19.           in rsButtonPressed.
  20.  
  21. **********************************************************************/
  22.  
  23. #include <font_pak.h>       /* for declarations -- PLEASE READ */
  24.  
  25. #include <dos.h>
  26.  
  27. #define ESC '\033'
  28. #define KEYINTR 0x16       /* read keyboard function */
  29. #define GETCHAR 1          /* poll for a keypress    */
  30.  
  31. int Readkey();
  32.  
  33.  
  34. /*
  35.  
  36. Syntax: isthereamouse = RSTHEREISAMOUSE ();
  37. Syntax: buttons = RSBUTTONPRESSED (&MRow, &MCol, TextOrGraphics);
  38. Syntax: RSSHOWCURSOR ();
  39. Syntax: RSHIDECURSOR ();
  40.  
  41. Syntax: RSLOADMOUSECURSOR (Block, WhichShape, ASCIICode);
  42. Syntax: RSSETTEXTCURSOR (FG, BG, ASCIIChar);
  43. Syntax: RSSETTEXTCURSORC (ASCIIChar);
  44.  
  45. */
  46.  
  47.  
  48. int main (void)
  49.  
  50. {
  51.     int BackColor, ForeColor, Block, ASCIICode, WhichShape, FontSize;
  52.     int Button, MRow, MCol, TextOrGraphics, key, MaxNum16s, MaxNum8s;
  53.     int temp;
  54.  
  55.     ForeColor = 14, BackColor = 4;      /* mouse cursor shape colors! */
  56.  
  57.     /*
  58.       Is a mouse active?  RSTHEREISAMOUSE returns yes (-1) or no (0).
  59.     */
  60.       temp = RSTHEREISAMOUSE();
  61.       if (temp == 0 )
  62.       {
  63.          printf("\n\n");
  64.          printf(" Sorry, this demo requires a mouse be attached and a mouse driver loaded.\n");
  65.          return (-99);
  66.       }
  67.  
  68.     /*
  69.       Display how many mouse cursor shapes?
  70.     */
  71.  
  72.     MaxNum16s = NUM16SHAPES();
  73.     MaxNum8s  = NUM8SHAPES();
  74.  
  75.     printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
  76.     printf("  ┌─░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓▓▓▓ Mouse Demo ▓▓▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▒░░░░░░░░─┐ \n");
  77.     printf(" ░│                                                                          │ \n");
  78.     printf(" ░│            You should be looking at a custom mouse cursor.               │ \n");
  79.     printf(" ░│                                                                          │ \n");
  80.     printf(" ░│ This is one of %d 16-point, and %d 8-point mouse shapes Font Pak offers  │ \n", MaxNum16s, MaxNum8s);
  81.     printf(" ░│                                                                          │ \n");
  82.     printf(" ░│                                                                          │ \n");
  83.     printf(" ░│Move the mouse around. Click <LEFT> to go forward, or <RIGHT> to go back. │ \n");
  84.     printf(" ░│                                                                          │ \n");
  85.     printf(" ░│                       Press ESCAPE to end this demo.                     │ \n");
  86.     printf(" ░│                                                                          │ \n");
  87.     printf(" ░└──────────────────────────────────────────────────────────────────────────┘ \n");
  88.     printf(" ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░   ");
  89.     printf("\n\n\n\n\n\n\n");
  90.  
  91.     /*
  92.       Load a mouse shape into block 0, remap char 255.  Because we're using
  93.       block 0, we should be sure we restore the default font.  If we don't,
  94.       and you re-map, say, char 32, your screen will be a mess.
  95.     */
  96.  
  97.     WhichShape = 1;
  98.     Block=0;                    /* Use block 0 ONLY.  If you don't, text may disappear! */
  99.     ASCIICode = 255;            /* we'll re-map chr 255 */
  100.  
  101.     RSLOADMOUSECURSOR (Block, WhichShape, ASCIICode);
  102.  
  103.     /*
  104.       Use ONE of the next 3 rsSetTextCursor routines.  Or try them all.
  105.     */
  106.  
  107.     /*
  108.       Use positive values to USE the FG/BG colors at the cursor.
  109.       RSSETTEXTCURSORC (ASCIICode);
  110.     */
  111.  
  112.     /*
  113.       Use negative values to INVERT the FG/BG colors at the cursor.
  114.  
  115.       RSSETTEXTCURSORC (-ASCIICode);
  116.     */
  117.  
  118.     /*
  119.       this version lets you SELECT the FG/BG colors of the mouse cursor
  120.     */
  121.       RSSETTEXTCURSOR (ForeColor, BackColor, ASCIICode);
  122.  
  123.     /*
  124.       Select the block you loaded the mouse shape into.  This may not be
  125.       necessary if you didn't change this demo and we're using Block 0.
  126.     */
  127.     RSWHICHFONTS (Block, Block);
  128.  
  129.  
  130.     RSSHOWCURSOR ();
  131.  
  132.     /* Set TextOrGraphics = -1 to report GRAPHICS-mode pixel coordinates
  133.                           =  0 to report TEXT-mode Row/Column coordinates
  134.     */
  135.  
  136.     TextOrGraphics = 0;
  137.  
  138.     Button= 0;
  139.  
  140.     while (key != ESC)
  141.     {
  142.        key = ReadKey();
  143.  
  144.        Button = RSBUTTONPRESSED (&MRow, &MCol, TextOrGraphics);
  145.  
  146.        switch (Button)
  147.        {
  148.            case 1:
  149.             ++ WhichShape;
  150.              if (WhichShape > MaxNum16s)
  151.                 WhichShape = 1;
  152.              break;
  153.  
  154.            case 2:
  155.              -- WhichShape;
  156.              if (WhichShape < 1)
  157.                 WhichShape = MaxNum16s;
  158.              break;
  159.  
  160.            default:;
  161.        }
  162.  
  163.        if (Button)
  164.           {
  165.              /* wait for the button to be released--or we'll move too fast */
  166.              while (Button > 0)
  167.                {
  168.                  Button = RSBUTTONPRESSED (&MRow, &MCol, TextOrGraphics);
  169.                  /* printf (" %d %d ", MRow, MCol); */
  170.                }
  171.  
  172.              /* now load the next cursor shape */
  173.              RSHIDECURSOR ();
  174.              RSLOADMOUSECURSOR (Block, WhichShape, ASCIICode);
  175.              RSSHOWCURSOR ();
  176.           }
  177.     }
  178.  
  179.     RSHIDECURSOR ();
  180.  
  181.     /* 1=Left, 2=Rht, 3=Both 4=Middle */
  182.  
  183.     printf("You pressed ESC with the mouse on on Row %d, Column %d.  Last mouse shape: %d\n",MRow, MCol, WhichShape);
  184.  
  185.     /* restore the default font in case you re-mapped, say, char 32 <g> */
  186.  
  187.     FontSize = 16;   /* must be 8, 14 or 16 -- or you'll get 14 */
  188.                      /* use 16 for VGAs; 14 for EGAs            */
  189.  
  190.     RSLOADDEFAULT (FontSize, Block);
  191.  
  192.     return(0);
  193.  
  194. }   /* end main */
  195.  
  196. int ReadKey()
  197. {
  198.     int key;
  199.     union REGS reg;
  200.     reg.h.ah = GETCHAR;
  201.     int86 (KEYINTR, ®, ®);
  202.     key = reg.h.al;
  203.     return (key);
  204. }
  205.