home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / MASTER-2.ZIP / MOUSEPP / MOUSEPP.LZH / MICEDEMO.CPP < prev    next >
C/C++ Source or Header  |  1992-06-28  |  13KB  |  469 lines

  1. /* -------------------------------------------------------------------- */
  2. /* Mouse++ Version 3.1           micedemo.cpp          Revised 06/28/92 */
  3. /*                                                                      */
  4. /* Demonstration of a general mouse class for Turbo C++/Borland C++.    */
  5. /* Copyright 1991, 1992 by Carl W. Moreland                             */
  6. /* This source code may be freely distributed as long as the copyright  */
  7. /* notice remains intact.                                               */
  8. /* -------------------------------------------------------------------- */
  9.  
  10. #include <dos.h>
  11. #include <stdio.h>
  12. #include <conio.h>
  13. #include <stdlib.h>
  14. #include <graphics.h>
  15. #include "mouse.h"
  16. #include "cursor.h"
  17.  
  18. void textdemo(void);
  19. int  textscreen(void);
  20. void alttextscreen(void);
  21. void nexttdemo(TextCursor&, char *);
  22. void graphicdemo(void);
  23. int  graphicscreen(void);
  24. void nextgdemo (GraphicsCursor&, char *);
  25.  
  26. int maxx, maxy;
  27. int text_width, text_height;
  28. struct text_info t_info;
  29. int done = 0;
  30.  
  31.  
  32. main()
  33. {
  34.   if(mouse.Exists())                // check for mouse
  35.   {
  36.     mouse.InstallHandler(0xff);        // install event handler
  37.     mouse.Enable();            // enable mouse
  38.     textdemo();                // run text mode demo
  39.     graphicdemo();            // run graphics mode demo
  40.     return(0);                // normal termination
  41.   }
  42.   return(1);                // abnormal termination
  43. }
  44.  
  45. /* ----- text mode demo ----------------------------------------------- */
  46.  
  47. void textdemo()                // main routine for text mode demo
  48. {
  49.   textmode(C80);            // 80x25 color text mode
  50.   if(textscreen() == 0)            // draw the screen
  51.   {
  52.     alttextscreen();            // draw the alt screen
  53.     textcolor(13);
  54.     gotoxy(1,3);
  55.  
  56.     if(mouse.Info.type == 1) cprintf(" Bus mouse found\n");
  57.     if(mouse.Info.type == 2) cprintf(" Serial mouse found\n");
  58.     if(mouse.Info.type == 3) cprintf(" InPort mouse found\n");
  59.     if(mouse.Info.type == 4) cprintf(" PS/2 mouse found\n");
  60.     if(mouse.Info.type == 5) cprintf(" HP mouse found\n");
  61.     gotoxy(1,4);
  62.     cprintf(" Software version is %d.%d\n", (int)mouse.Info.majorvers,
  63.               (int)mouse.Info.minorvers);
  64.  
  65.     mouse.yLimit(0, 199);        // set y limit
  66.     mouse.Show();            // initial turn-on
  67.  
  68.     if(!done) nexttdemo(tdef, "     Default Cursor      ");
  69.     if(!done) nexttdemo(txt1, " 0000h 0E0Fh Soft Cursor ");
  70.     if(!done) nexttdemo(txt2, " 7000h 0E0Fh Soft Cursor ");
  71.     if(!done) nexttdemo(txt3, " 7F00h FF0Fh Soft Cursor ");
  72.     mouse.xLimit(16, 623);
  73.     if(!done) nexttdemo(txt4, " 00FFh 0FD4h Soft Cursor ");
  74.  
  75.     mouse.Hide();
  76.     textmode(C4350);            // 43/50 line mode
  77.     _setcursortype(_NOCURSOR);        // turn the hardware cursor off
  78.     mouse.xLimit(0, 639);        // set x limit
  79.     gettextinfo(&t_info);
  80.     if(t_info.screenheight == 43)
  81.       mouse.yLimit(0, 349);        // set y limit to EGA 43 line
  82.     else
  83.       mouse.yLimit(0, 399);        // set y limit to VGA 50 line
  84.     mouse.Show();
  85.     if(!done) nexttdemo(tdef, "     Default Cursor      ");
  86.   }
  87. }
  88.  
  89. int textscreen(void)            // draws screen for demo
  90. {
  91.   register int i, j;
  92.   char far *video = (char far *)MK_FP(0xB800, 0x0000);
  93.  
  94.   _setcursortype(_NOCURSOR);        // turn the hardware cursor off
  95.  
  96.   for(i=0; i<50; i++)            // draw the text screen background
  97.   {
  98.     for(j=0; j<80; j++)
  99.     {
  100.       *video++ = 0xDB+2*(j/10);        // write the character to video memory
  101.       *video++ = 16*(j/10)+j/10+1;    // write the color
  102.     }
  103.   }
  104.  
  105.   gotoxy(27,1);
  106.   textattr(4);
  107.   cprintf(" Text Mode Demonstration ");
  108.  
  109.   textattr(LIGHTGRAY);
  110.   for(i=5; i<13; i++)
  111.   {
  112.     gotoxy(5, i);
  113.     cprintf("██████████");
  114.   }
  115.   textattr(DARKGRAY);
  116.   for(i=6; i<8; i++)
  117.   {
  118.     gotoxy(6, i);
  119.     cprintf("██");
  120.     gotoxy(9, i);
  121.     cprintf("██");
  122.     gotoxy(12, i);
  123.     cprintf("██");
  124.   }
  125.   textattr(WHITE);
  126.   gotoxy(6,9);
  127.   cprintf("Position");
  128.  
  129.   textattr(LIGHTBLUE);
  130.   gotoxy(37,22); cprintf("╔══════╗");
  131.   gotoxy(37,23); cprintf("║ Next ║");
  132.   gotoxy(37,24); cprintf("╚══════╝");
  133.  
  134.   return(0);
  135. }
  136.  
  137. void alttextscreen(void)        // copies page0 to page2
  138. {
  139.   register int i, j;
  140.  
  141.   char far *page0 = (char far *)MK_FP(0xB800, 0x0000);
  142.   char far *page2 = (char far *)MK_FP(0xBA00, 0x0000);
  143.  
  144.   for(i=0; i<50; i++)            // draw the text screen background
  145.   {
  146.     for(j=0; j<80; j++)
  147.     {
  148.       *page2++ = *page0++;        // copy the characters
  149.       *page2++ = (*page0++ << 1);    // copy the color*2
  150.     }
  151.   }
  152. }
  153.  
  154. void nexttdemo(TextCursor& cursor, char *str)
  155. {
  156.   static int page = 0;
  157.  
  158.   mouse.SetCursor(cursor);        // set text cursor
  159.   textattr(4);
  160.   gotoxy(27,2);
  161.   cprintf(str);                // print title
  162.   textattr(13);
  163.   for(;;)
  164.   {
  165.     mouse.GetEvent();
  166.     textattr(WHITE);
  167.     gotoxy(6,10);
  168.     cprintf(" %2d  %2d ", mouse.xPos() >> 3, mouse.yPos() >> 3);
  169.  
  170.     (mouse.LB_Dn()) ? textattr(RED) :
  171.                       textattr(DARKGRAY);
  172.     gotoxy(6,6);
  173.     cprintf("██");
  174.     gotoxy(6,7);
  175.     cprintf("██");
  176.     (mouse.CB_Dn()) ? textattr(RED) :
  177.                       textattr(DARKGRAY);
  178.     gotoxy(9,6);
  179.     cprintf("██");
  180.     gotoxy(9,7);
  181.     cprintf("██");
  182.  
  183.     (mouse.RB_Dn()) ? textattr(RED) :
  184.                       textattr(DARKGRAY);
  185.     gotoxy(12,6);
  186.     cprintf("██");
  187.     gotoxy(12,7);
  188.     cprintf("██");
  189.  
  190.     if(mouse.Released(LEFTBUTTON))    // check for LB release
  191.       if(mouse.InBox(36*8, 21*8, 43*8, 23*8))
  192.         return;
  193.  
  194.     if(mouse.DoubleClick(LEFTBUTTON))
  195.     {
  196.       mouse.ClearClick(LEFTBUTTON);
  197.       return;
  198.     }
  199.  
  200.     if(mouse.DoubleClick(RIGHTBUTTON))
  201.     {
  202.       mouse.Disable();
  203.       textattr(4);
  204.       gotoxy(1,1);
  205.       cprintf("Hit any key...");
  206.       while(!getch());
  207.       textattr(DARKGRAY);
  208.       gotoxy(1,1);
  209.       cprintf("██████████████");
  210.       mouse.Enable();
  211.       mouse.Show();
  212.     }
  213.  
  214.     if(mouse.Pressed(LEFTBUTTON) && (mouse.Button() & CTRL_PRESSED))
  215.     {
  216.       done = 1;                // done with text demo
  217.       return;
  218.     }
  219.  
  220.     if(mouse.Pressed(LEFTBUTTON) && (mouse.Button() & SHIFT_PRESSED))
  221.     {
  222.       mouse.Hide();
  223.       page = (page == 0 ? 2 : 0);    // switch page numbers
  224.  
  225.       _AH = 0x05;
  226.       _AL = page;
  227.       geninterrupt(0x10);        // change the displayed page
  228.  
  229.       mouse.SetVideoPage(page);        // set the mouse to the new page
  230.       mouse.Show();
  231.     }
  232.   }
  233. }
  234.  
  235. /* ----- graphics mode demo ------------------------------------------- */
  236.  
  237. void graphicdemo()            // main routine for graphics demo
  238. {
  239.   if(graphicscreen() == 0)        // draw the screen
  240.   {
  241.     done = 0;
  242.     mouse.yLimit(0, maxy);        // set y limit (EGA=350, VGA=480)
  243.     mouse.Show();            // initial turn on
  244.  
  245.     mouse.SetSpeedThreshold(32);
  246.     mouse.MickToPix(8, 8);
  247.     if(!done) nextgdemo(gdef,     " Default ");
  248.     if(!done) nextgdemo(cross,    "  Cross  ");
  249.     if(!done) nextgdemo(check,    "  Check  ");
  250.     if(!done) nextgdemo(plus,     "  Plus   ");
  251.     if(!done) nextgdemo(gun,      "   Gun   ");
  252.     if(!done) nextgdemo(hand,     "  Hand   ");
  253.     if(!done) nextgdemo(hourglass,"Hourglass");
  254.     if(!done) nextgdemo(bullseye, " Bullseye");
  255.     mouse.MickToPix(4, 4);
  256.     if(!done) nextgdemo(ibeam,    "  IBeam  ");
  257.     mouse.MickToPix(2, 2);
  258.     if(!done) nextgdemo(jet,      "   Jet   ");
  259.     mouse.MickToPix(16, 16);
  260.     mouse.Move(maxx/2, maxy/2);
  261.     if(!done) nextgdemo(face,     "  Face   ");
  262.  
  263.     closegraph();
  264.   }
  265. }
  266.  
  267. int graphicscreen()
  268. {
  269.   int x, y;
  270.   int  driver = EGA, mode = EGAHI;
  271.  
  272.   initgraph(&driver, &mode, "");
  273.   if(graphresult() == grOk)
  274.   {
  275.     maxx = getmaxx();
  276.     maxy = getmaxy();
  277.     text_width  = textwidth("O");
  278.     text_height = textheight("O");
  279.  
  280.     setcolor(RED);            // paint background
  281.     rectangle(0, 0, maxx/3, maxy);
  282.     setfillstyle(SOLID_FILL, RED);
  283.     floodfill(maxx/6, maxy/2, RED);
  284.     setcolor(GREEN);
  285.     rectangle(maxx/3, 0, 2*maxx/3, maxy);
  286.     setfillstyle(SOLID_FILL, GREEN);
  287.     floodfill(maxx/2, maxy/2, GREEN);
  288.     setcolor(BLUE);
  289.     rectangle(2*maxx/3, 0, maxx, maxy);
  290.     setfillstyle(SOLID_FILL, BLUE);
  291.     floodfill(5*maxx/6, maxy/2, BLUE);
  292.     x = (maxx/2)-75;            // center white block
  293.     y = (maxy/2)-75;
  294.     setcolor(WHITE);
  295.     rectangle(x, y, x+150, y+150);
  296.     setfillstyle(SOLID_FILL, WHITE);
  297.     floodfill(x+10, y+10, WHITE);
  298.  
  299.     x = (maxx/2)-40;                    // center black box
  300.     y = (maxy/2)-40;
  301.     setcolor(BLACK);
  302.     rectangle(x, y, x+80, y+80);
  303.     setfillstyle(SOLID_FILL, BLACK);
  304.     floodfill(maxx/2, maxy/2, BLACK);
  305.  
  306.     setcolor(BLACK);            // "Next" box
  307.     moveto(37*text_width, 40*text_height);
  308.     outtext("████████");
  309.     moveto(37*text_width, 41*text_height);
  310.     outtext("████████");
  311.     moveto(37*text_width, 42*text_height);
  312.     outtext("████████");
  313.     setcolor(WHITE);
  314.     moveto(37*text_width, 40*text_height);
  315.     outtext("╔══════╗");
  316.     moveto(37*text_width, 41*text_height);
  317.     outtext("║ Next ║");
  318.     moveto(37*text_width, 42*text_height);
  319.     outtext("╚══════╝");
  320.  
  321.     setfillstyle(SOLID_FILL, LIGHTGRAY);// draw mouse and buttons
  322.     setcolor(LIGHTGRAY);
  323.     rectangle(40, 40, 140, 140);
  324.     floodfill(90, 90, LIGHTGRAY);
  325.     setfillstyle(SOLID_FILL, DARKGRAY);
  326.     setcolor(DARKGRAY);
  327.     rectangle(50, 60, 70, 80);
  328.     floodfill(60, 70, DARKGRAY);
  329.     rectangle(80, 60, 100, 80);
  330.     floodfill(90, 70, DARKGRAY);
  331.     rectangle(110, 60, 130, 80);
  332.     floodfill(120, 70, DARKGRAY);
  333.     setcolor(BLACK);
  334.     moveto(60, 100);
  335.     outtext("Position");
  336.  
  337.     return(0);
  338.   }
  339.   return(1);
  340. }
  341.  
  342. void nextgdemo(GraphicsCursor& cursor, char *str)
  343. {
  344.   int LBDN = 0, CBDN = 0, RBDN = 0;
  345.   char str2[10];
  346.   int color;
  347.  
  348.   mouse.SetCursor(cursor);        // set graphics cursor
  349.   setcolor(BLACK);            // print label
  350.   moveto((maxx/2-5*text_width),text_height);
  351.   outtext("█████████");
  352.   setcolor(WHITE);
  353.   moveto((maxx/2-5*text_width),text_height);
  354.   outtext(str);
  355.  
  356.   mouse.ClearBuffer();
  357.   mouse.ClearEvent();
  358.  
  359.   for(;;)
  360.   {
  361.     mouse.GetEvent();
  362.                     // set exclusion area
  363.     mouse.Exclude(40, 40, 140, 140);
  364.                                   // see if mouse has moved
  365.     if(mouse.xCount() || mouse.yCount())
  366.     {
  367.       sprintf(str2, "%3d %3d", mouse.xPos(), mouse.yPos());
  368.       setcolor(LIGHTGRAY);
  369.       moveto(60, 108);
  370.       outtext("███████");
  371.       setcolor(BLACK);
  372.       moveto(60, 108);
  373.       outtext(str2);            // print cursor position
  374.     }
  375.                     // check all button status for change
  376.     if((mouse.LB_Dn() && !LBDN) || (!mouse.LB_Dn() && LBDN))
  377.     {
  378.       color = LBDN ? DARKGRAY : RED;
  379.       if(mouse.MultiClick(LEFTBUTTON) == 2)
  380.       {
  381.         if(mouse.LB_Dn())
  382.           color = BLUE;
  383.       }
  384.       if(mouse.MultiClick(LEFTBUTTON) == 3)
  385.       {
  386.         if(mouse.LB_Dn())
  387.           color = GREEN;
  388.       }
  389.       if(mouse.MultiClick(LEFTBUTTON) == 4)
  390.       {
  391.         color = YELLOW;
  392.         mouse.ClearClick(LEFTBUTTON);
  393.       }
  394.  
  395.       setcolor(color);
  396.       setfillstyle(SOLID_FILL, color);
  397.       rectangle(50, 60, 70, 80);
  398.       floodfill(60, 70, color);
  399.       LBDN = !LBDN;
  400.     }
  401.     if((mouse.CB_Dn() && !CBDN) || (!mouse.CB_Dn() && CBDN))
  402.     {
  403.       color = CBDN ? DARKGRAY : RED;
  404.       if(mouse.MultiClick(CENTERBUTTON) == 2)
  405.       {
  406.         if(mouse.CB_Dn())
  407.           color = BLUE;
  408.       }
  409.       if(mouse.MultiClick(CENTERBUTTON) == 3)
  410.       {
  411.         if(mouse.CB_Dn())
  412.           color = GREEN;
  413.       }
  414.       if(mouse.MultiClick(CENTERBUTTON) == 4)
  415.       {
  416.         color = YELLOW;
  417.         mouse.ClearClick(CENTERBUTTON);
  418.       }
  419.  
  420.       setcolor(color);
  421.       setfillstyle(SOLID_FILL, color);
  422.       rectangle(80, 60, 100, 80);
  423.       floodfill(90, 70, color);
  424.       CBDN = !CBDN;
  425.     }
  426.     if((mouse.RB_Dn() && !RBDN) || (!mouse.RB_Dn() && RBDN))
  427.     {
  428.       color = RBDN ? DARKGRAY : RED;
  429.       if(mouse.MultiClick(RIGHTBUTTON) == 2) color = BLUE;
  430.       if(mouse.MultiClick(RIGHTBUTTON) == 3) color = GREEN;
  431.       if(mouse.MultiClick(RIGHTBUTTON) == 4) color = YELLOW;
  432.  
  433.       setcolor(color);
  434.       setfillstyle(SOLID_FILL, color);
  435.       rectangle(110, 60, 130, 80);
  436.       floodfill(120, 70, color);
  437.       RBDN = !RBDN;
  438.     }
  439.  
  440.     if(mouse.Released(LEFTBUTTON))    // check for LB release
  441.     {
  442.       if(mouse.InBox(37*text_width, 40*text_height,
  443.                    45*text_width, 43*text_height))
  444.       {
  445.         if(LBDN)            // check for LBDN status
  446.         {
  447.           setcolor(DARKGRAY);       // dehilite mouse button
  448.           setfillstyle(SOLID_FILL, DARKGRAY);
  449.           rectangle(50, 60, 70, 80);
  450.           floodfill(60, 70, DARKGRAY);
  451.         }
  452.         return;
  453.       }
  454.     }
  455.  
  456.     if(mouse.MultiClick(LEFTBUTTON) == 3)
  457.     {
  458.       mouse.ClearClick(LEFTBUTTON);
  459.       return;
  460.     }
  461.  
  462.     if(mouse.Pressed(LEFTBUTTON) && (mouse.Button() & CTRL_PRESSED))
  463.     {
  464.       done = 1;
  465.       return;
  466.     }
  467.   }
  468. }
  469.