home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / microcrn / issue_44.arc / MICROCAD.ARC / MSMENU.HPP < prev    next >
Text File  |  1988-09-27  |  3KB  |  88 lines

  1. // Figure 2 for "A Little CAD with C++"
  2. // Copyright 1988 Bruce Eckel
  3. // Permission required to distribute source
  4.  
  5. // file: msmenu.hpp
  6. /* A mouse control class with a menu to choose
  7.    from.  This is an example of data 
  8.    encapsulation, since it wouldn't make any
  9.    sense to declare more than one instance of
  10.    an msmenu (you only have one mouse!). */
  11.  
  12. // note the use of "ifndef" with the modified
  13. // header file name.  You should have one of
  14. // these in every header file to prevent 
  15. // multiple declaration of classes:
  16. #ifndef MSMENU_HPP
  17. #define MSMENU_HPP
  18.  
  19. #define LINESIZE 11
  20. #define CHARWIDTH 10
  21. struct menu_s { // to hold the a user menu
  22.   char * name; // displayed on screen
  23.   int  item_number;
  24. };
  25.  
  26. class msmenu {
  27.     // pointer to the user's menu:
  28.     struct menu_s * m;        
  29.     // char size of the menu:
  30.     int height, width;        
  31.     // graphic size of the menu:
  32.     int xsize, ysize;         
  33.     // graphic areas used by the menu:
  34.     int msize;                
  35.     fg_color_t  *color_p,  
  36.                 // graphic storage area:
  37.                 *blank_p;     
  38.     // graphic box:
  39.     fg_box_t    sizing_box;   
  40.         
  41.     int count;  // for messages
  42.     // private function -- can only be called
  43.     // by member functions:
  44.     void drawmenu(int x, int y);
  45.   public:
  46.     // constructor called for a new object:
  47.     msmenu(struct menu_s *);
  48.     // destructor called when object goes out
  49.     // of scope or delete is used:
  50.     ~msmenu();  
  51.     // bring up the menu and get user's choice:
  52.     int get_selection(unsigned x, unsigned y);
  53.     // translate mouse to flash graphics coords:
  54.     void 
  55.     translate_coords(unsigned * x, unsigned * y) {
  56.        *y *= -1; 
  57.        *y += fg_displaybox[FG_Y2]; 
  58.     }
  59.     // different types of cursors:
  60.     void default_cursor(); // arrow
  61.     void menu_cursor(); // horizontal arrow
  62.     void cross_cursor(); // crosshair
  63.  
  64.     // wait for buttons to be pressed:
  65.     void 
  66.     wait_left_pressed(unsigned *x, unsigned *y) {
  67.         while (!(msm_getstatus(x,y) & 1))
  68.        ;  
  69.     }
  70.     void
  71.     wait_right_pressed(unsigned *x, unsigned *y) {
  72.         while (!(msm_getstatus(x,y) & 2))
  73.        ;  
  74.     }
  75.     // wait for buttons to be pressed:
  76.     void 
  77.     wait_left_released(unsigned *x, unsigned *y) {
  78.         while (msm_getstatus(x,y) & 1)
  79.        ;  
  80.     }
  81.     void 
  82.     wait_right_released(unsigned *x, unsigned *y){
  83.         while (msm_getstatus(x,y) & 2)
  84.        ;  
  85.     }
  86. };
  87. #endif MSMENU_HPP
  88.