moustrap.prn

来自「又一个关于鼠标驱动的C程序」· PRN 代码 · 共 2,261 行 · 第 1/5 页

PRN
2,261
字号

                       Set_Mouse_Text_Cursor(0,0,TC(' ',4,4));

               Now, we describe how the mouse cursor will look.   We start with 
          something simple.  We'll use a software cursor, with no screen mask.   
          We use  the macro TC(),  defined in MOUSTRAP.H,  to build a  cursor    
            which  is  just a space,  with a red foreground (color 4)  on a  red 
               background.

                       Add_Mouse_Button(0,M_Middle,'2');

               For  our first button definition,  we'll say that anytime the
          Middle       button  is pressed,  Read_Mouse will return an ASCII
          character  '2',       regardless  of  what page is active (provided at
          least one  page  IS       active).

                       Add_Mouse_Button(z,M_Left,'1');

               Next  we'll  have  pressing  the Left button  return  an  ASCII 
          '1'       whenever page Z is active.

                                        - Page 30 -





                                                      MouseTrap Library, Rel 1.01
                                                                February 12, 1989


                       Add_Mouse_Button(z,M_Right,0);
                       Add_Mouse_Hot_Spot(z,M_Right,7,13,13,18,'C');

               Now, we add our first Hot Spot.  Here,  we must first declare 
          the Right button in Page Z, then we declare the area in the rectangle 
          (7,13) - (13,18) as a hot spot returning the character 'C' when that   
          button is pressed while page Z is active.  Since no other hot spot is
          defined, clicking the right button outside that area will return 0,
          just as if no click had occurred.

                       Add_Mouse_Button(y,M_Left,0);

                       Add_Mouse_Hot_Spot(y,M_Left,15,20,24,30,'L');
                       Add_Mouse_Hot_Spot(y,M_Left,15,30,24,40,'R');

               Continuing in a similar vein, we define two hot spots in page Y. 
          When the Left button is pressed, if the cursor is in the left side
          we'll get the character 'L', while the right side return the character
          'R'.
                        
               do {
                       
                       Activate_Mouse_Page(z);
                       
               As we enter the loop, we activate page Z.  The mouse cursor is   
          "turned on" with it's movement limited to the edges of the page.  
                       c=Get_Char_Mouse_Kbd();
                       printf("Page Z: Character \"%c\"",c);

               We stop, and get a character from either the keyboard (which is
          not much fun), or via the mouse; and print it.

                       Activate_Mouse_Page(y);
                       c=Get_Char_Mouse_Kbd();
                       printf("Page Y: Character \"%c\"",c);

               Now, we activate page Y (which automatically deactivates page 
          Z).  The mouse cursor moves into the new area, and it's motion is
          limited  to that range.  We get another character and print it.
                      
                       } while (c!='Q');

                       Clear_All_Mouse_Definitions();

                       Define_Mouse_System(M_Overlaid_Pages);

               Now, we want to start over, so we clear all the old definitions, 
          and restart, but this time using overlaid pages.

                       y=Add_Mouse_Page(M_Text_Coord,15,20,24,40); 
                       z=Add_Mouse_Page(M_Text_Coord,5,10,15,20); 

                                        - Page 31 -





                                                      MouseTrap Library, Rel 1.01
                                                                February 12, 1989

                       Add_Mouse_Button(0,M_Middle,'2');
                       Add_Mouse_Button(z,M_Left,'1');
                       Add_Mouse_Button(z,M_Right,0);
                       Add_Mouse_Hot_Spot(z,M_Right,7,13,13,18,'C');
                       Add_Mouse_Button(y,M_Left,0);
                       Add_Mouse_Hot_Spot(y,M_Left,15,20,24,30,'L');
                       Add_Mouse_Hot_Spot(y,M_Left,15,30,24,40,'R');

                       Set_Mouse_Text_Cursor(0,0,TC('+',4,2));

               We'll redefine all of our pages, buttons, and hot spots, exactly
          as we did the first time.  We'll also change the mouse  cursor, this   
          time to something a bit more exciting than before, a red plus sign   
          on a green background (color 2).

               do {
                       Activate_Mouse_Page(z);
                       c=Get_Char_Mouse_Kbd();
                       printf("Page Z: Character \"%c\"",c);

               Again, we activate page Z, and get a character from it.  This
          works exactly as it did in  the first loop using single page mode.

                       DeActivate_Mouse_Page(z);  
                       Activate_Mouse_Page(y);
                       c=Get_Char_Mouse_Kbd();
                       printf("Page Y: Character \"%c\"",c);

               And again, we activate page Y, and get a character from it.  The 
          only difference is that we had to first deactivate page Z.

                       Activate_Mouse_Page(z);
                       c=Get_Char_Mouse_Kbd();
                       printf("Page Y & Z: Character \"%c\"",c);
                       
               Now we get flashy.  Without deactivate page Y, we'll reactivate
          page Z.  You will notice that the mouse can now move within a much
          larger area, specifically the rectangle which circumscribes both of 
          the smaller rectangle.  Notice that if you click the left button in
          the area that is not within the boundaries of either page,  "1" will
          be return.  This  is because the button definition says to return  "1" 
          whenever page Z is active,  regardless of where the cursor is,  even   
          if  it is outside the stated area of Page Z.  However, notice that   
          the Hot Spots of the left button in page Y, take precedence over this. 
          This  is  because the BUTTON definition on page Y was give after the
          button definition off page Z, and therefore overrules it.

                       DeActivate_Mouse_Page(y);  

               Now, we deactivate page Y, leaving only page Z.  Notice that the 
          mouse's movements are once again restricted to the area of page Z.   
          (See..I told you that I would fix this problem with release 1.01)

                                        - Page 32 -





                                                      MouseTrap Library, Rel 1.01
                                                                February 12, 1989


                       }
               }


















































                                        - Page 33 -





                                                      MouseTrap Library, Rel 1.01
                                                                February 12, 1989

               You should also remember that, although we always used ASCII 
          characters for return values in the example, ANY character or integer
          value, in the range of 1 to 65534, can be used.


















































                                        - Page 34 -





                                                      MouseTrap Library, Rel 1.01
                                                                February 12, 1989


                       Chapter 5

                                       Technical Specification

               This chapter is provided only to those who have paid to become 
          registered uses.  This was done because I assumed that it would be  of
          little use to anyone who didn't have the source code (which also comes
          with registration). This method also gives me a few extra weeks to
          write it.











































                                        - Page 35 -





                                                      MouseTrap Library, Rel 1.01
                                                                February 12, 1989


                       Chapter 6

                                       Appendix



                               A.      MOUSTRAP.H
                               B.      Global Variables
                               C.      Error Codes
                               D.      Reference
                               E.      Support
                               F.      Release History








































                                        - Page 36 -





                                                      MouseTrap Library, Rel 1.01
                                                                February 12, 1989

                       Appendix A  :   MOUSTRAP.H


               The  header file,  MOUSTRAP.H should be included in every C
          program which uses the MouseTrap Library functions.  It includes
          complete function prototypes for each of the MouseTrap Library functions. 
          In addition, it defines a number of constants which are to be used
          with the functions.  These include:

               M_Overlaid_Pages    -and-    M_Single_Pages,  which are used      
               with the function Define_Mouse_System.

               M_Text_Coord -and- M_Graphic_Coord,  which are used with the      
               Add_Mouse_Page function, to tell which system screen coordinates
               are being given in.

               M_Left, M_Right, M_Center, -and- M_Middle, which are used to
               refer to the mouse buttons whenever necessary. Note that M_Center
               and  M_Middle are equivalent, and you may use whichever holds 
               your fancy.

               M_HORIZ -and- M_VERT, which are used with Set_Mouse_Limits.

               MERROR -and- MNOERROR, (-1 and 0,  respectively),  which are
               return by various functions to indicate whether an  error 
               occurred.  Also defined are a large number of error codes, which
               are discussed further in appendix C.

                    The macro TC() is used to create an integer value in the form
               BFCC, where B is the background color, F, the foreground color,   
               and CC is a character.  This value is used by Set_Mouse_Text_Cursor, 
               (and  by  other  routines  outside of the  MouseTrap  Library
               which perform  direct screen writes).   The macro require that you
               give it the character,  foreground and background color code.  The
               statement TC('A',14,5) would produce the code 5E41h, which mean
               the letter 'A' in bright Yellow on a Magenta background.

                    It also declared three global variables, which are described
               in Appendix B.

               Also defined is the data type "mouse_t" which is used to define
               vitually every variable used in the  MouseTrap  functions. Also
               included are the structure definitions for Pages, buttons, and   
               hot spots.  I'll not should what you can use them for, but I
               thought you might be interested.

               The last group of lines 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?