home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 1.ddi / SNAV0111.ZIP / DEMO2.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-16  |  5.2 KB  |  173 lines

  1. //          ┌───────┐
  2. //    ─────────>│ AVNER │
  3. //    ─────────>│  BEN  │──────> Software Engineering Method
  4. //          └───────┘
  5. //    10 Dov-Hoz st. Tel-Aviv 63416 Israel tel. 972-3-221535
  6.  
  7. // The Screen NAVigator, ver 1.10 April 1990
  8. // Copyright (c) 1989 by Avner Ben
  9. // Snav is not, and never was, free software.
  10. // for conditions for use refer to file "copyrigh.txt"
  11.  
  12. // The Screen Navigator is an object-oriented device-independent
  13. // character-graphics driver package, written in the C++ language,
  14. // distributed in the form of C++ source code.
  15. // For further information refer to the documentation files.
  16.  
  17. // this simple example is intended as a template to be extended and modified
  18. // by the user, provided the above title and copyright notice are unchanged
  19. // and are not ommitted.
  20.  
  21. /***************************************************************************/
  22.  
  23. // demonstration part 2 - header.
  24. // a simplistic formatted-input driver, implemented with the screen driver
  25. // of demo part 1. Device-specific assumptions made about function keys.
  26. // Implemented are only the methods required by the main demo program.
  27.  
  28. // 28.10.89 avner ben coded.
  29. /////// snav v1.1
  30. // 8.3.90-31.3.90 avner ben:
  31. // * C++ v2.0  upgrade    *  modified  some functions to    return by  value  *
  32. // removed  the  main  screen  area  from  definition of class char_input *
  33. // default screen-driver allocation * made class character_input generic  *
  34. // removed char-set  dependant tests  and other  pc-dependant references to
  35. // driver *
  36.  
  37. // site history (this copy):
  38. // __.__.__, _____________: _______________________________.
  39.  
  40. #ifndef DEMO1_H
  41. #include "demo1.hpp"
  42. #endif
  43.  
  44. enum func_k {    // function key pressed
  45.     K_C,    // no, character pressed!
  46.     K_RT,    // right arrow
  47.     K_UP,    // up arrow
  48.     K_LT,    // left arrow
  49.     K_DN    // down arrow
  50.     // add your own
  51. };
  52.  
  53. class character_input
  54. { // interactive keyboard/console input driver
  55.  
  56.     private:
  57.         boolean private_screen; // tells if delete on exit
  58.  
  59.     protected:
  60.         panel *scr;        // specific driver determined by caller
  61.         char cc;        // last read char. blank if fkey pressed
  62.         func_k fkey;        // last pressed fkey. 0 if char pressed.
  63.  
  64.     public :
  65.         character_input(panel *inscr);
  66.         character_input(const square_pos &window, int driver_num=0);
  67.         ~character_input(void);
  68.         virtual char get_c(void)=0; // implementation dependant
  69.         virtual int charnum(char c)=0; // char-set dependant
  70.         char c(void) { return cc; }
  71.         func_k fk(void) { return fkey; }
  72.  
  73.         boolean get_position(char *prompt, panel *draw_board, boolean hilite=TRUE);
  74.         int get_number(char *prompt, int imax);
  75.         boolean get_boolean(char *prompt);
  76.         weight_d get_wgt(void);
  77.         direction get_dir(void);
  78.         void msg(char *prompt);
  79.         void clear(void) { scr->clear(); }
  80.         void home(void) { scr->home(); }
  81.         void next(void) { scr->next(); }
  82.         void put_s(char *s) { scr->put_s(s); }
  83.         void put_c_stay(char c)
  84.         { scr->put_c(c,NULL,&(direction)nodir); }
  85. };
  86.  
  87. class pc_keyboard : public character_input
  88. {
  89.     public:
  90.         pc_keyboard(panel *inscr) : character_input(inscr) {}
  91.         pc_keyboard(const square_pos &window, int driver_num=0)
  92.          : character_input(window, driver_num) {}
  93.         char get_c(void);
  94.         int charnum(char c) {
  95.             if (c<'0' || c>'9') return 0;
  96.             return (int)(c-'0');
  97.         }
  98. };
  99.  
  100. class keyboard_driver_manager
  101. { // run-time keyboard-implementation selector
  102.  
  103.     private:
  104.         int default_kbd;
  105.  
  106.     public:
  107.         keyboard_driver_manager(int def=0)
  108.         { default_kbd=def; }
  109.         character_input *allocate(panel *scr, int kbd_num=0);
  110.         character_input *allocate(const square_pos &window,
  111.          int scr_num=0, int kbd_num=0);
  112.         int ask_default(void)
  113.         { return default_kbd; }
  114.         void set_default(int def)
  115.         { default_kbd=def; }
  116. };
  117.  
  118.  
  119. struct slide_option
  120. { // linked-list of options in slide-menu
  121.  
  122.     char *s,                        // option name
  123.      *letter,                // option letter in the former
  124.      *hlp;                       // explanation (in dialog area)
  125.     int num;                     // option number (serial)
  126.     point_pos pos;                      // position in menu area
  127.     slide_option *next, *last;
  128.  
  129.     slide_option(char *text, int posopt, char *help);
  130.     ~slide_option(void) { delete s; delete hlp; }
  131.     void off(panel *scr)
  132.     { scr->toggle_attr(VD_HI); scr->put_s(s,&pos); scr->toggle_attr(VD_HI); }
  133.     void on(panel *scr)        // pc-specific visual attribute codes used
  134.     { scr->toggle_attr(VD_REV); scr->put_s(s,&pos); scr->toggle_attr(VD_REV); }
  135.     void put_help(panel *explain)
  136.     { explain->clear(); explain->put_s(hlp); }
  137. };
  138.  
  139. class slide_menu
  140. { // slide-menu manager (like pop-up menu system topmost menu)
  141.  
  142.     friend struct slide_option;
  143.  
  144.     private :
  145.         panel *scr, *explain;      // the menu area, the help area
  146.         slide_option *stopt, *enopt, *cursor; // ptrs to option list
  147.  
  148.     public :
  149.         slide_menu(panel *parent, panel *help);
  150.         // warning: chops top line off parent screen!
  151.         ~slide_menu(void);
  152.         void append_opt(char *text, int posopt, char *help);
  153.         void next_opt(void);
  154.         void prev_opt(void);
  155.         int select(void);
  156.         void clear(void) { scr->clear(); }
  157. };
  158.  
  159. class text_window
  160. {
  161.     private :
  162.         panel *box;
  163.  
  164.     public:
  165.         text_window(panel *parent, point_pos *start, char *title,
  166.          boolean centered, char *inpline[]);
  167.         ~text_window(void)
  168.         { box->deframe(); delete box; }
  169.         void pause(char *prompt);
  170.         void put_page(char *inpline[]);
  171. };
  172.  
  173.