home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c031 / 4.ddi / SAMPLES / CPPTUTOR / OOD / MISC.H$ / MISC
Encoding:
Text File  |  1991-12-25  |  4.9 KB  |  164 lines

  1. #if !defined( _MISC_H_ )
  2.  
  3. #define _MISC_H_
  4.  
  5. #include "prim.h"
  6.  
  7. /********************************************************************
  8.  
  9.  Macro: ExtChar
  10.     Encodes ASCII and extended code characters in an integer.
  11.     Note that the ASCII character is stored in the low-order byte;
  12.     this allows encoded ints to be compared with chars.
  13.  
  14. ********************************************************************/
  15.  
  16. #define ExtChar( a, b ) ((unsigned int)b << 8) | (unsigned char)a
  17.  
  18. const unsigned int BACKSPACE  = ExtChar( 8, 0 );
  19. const unsigned int TAB        = ExtChar( 9, 0 );
  20. const unsigned int ESC        = ExtChar( 27, 0 );
  21. const unsigned int UPARROW    = ExtChar( 0, 72 );
  22. const unsigned int DOWNARROW  = ExtChar( 0, 80 );
  23. const unsigned int LEFTARROW  = ExtChar( 0, 75 );
  24. const unsigned int RIGHTARROW = ExtChar( 0, 77 );
  25. const unsigned int PGUP       = ExtChar( 0, 73 );
  26. const unsigned int PGDN       = ExtChar( 0, 81 );
  27. const unsigned int HOME       = ExtChar( 0, 71 );
  28. const unsigned int END        = ExtChar( 0, 79 );
  29.  
  30. // constants for foreground and background colors
  31.  
  32. const unsigned char BLACK_FORE = 0;
  33. const unsigned char BLUE_FORE  = 0x01;
  34. const unsigned char GREEN_FORE = 0x02;
  35. const unsigned char RED_FORE   = 0x04;
  36. const unsigned char INTENSE    = 0x08;
  37. const unsigned char BLACK_BACK = 0;
  38. const unsigned char BLUE_BACK  = 0x10;
  39. const unsigned char GREEN_BACK = 0x20;
  40. const unsigned char RED_BACK   = 0x40;
  41. const unsigned char BLINKING   = 0x80;
  42.  
  43.  
  44. const unsigned char CYAN_FORE    = GREEN_FORE | BLUE_FORE;
  45. const unsigned char MAGENTA_FORE = RED_FORE | BLUE_FORE;
  46. const unsigned char BROWN_FORE   = RED_FORE | GREEN_FORE;
  47. const unsigned char WHITE_FORE   = RED_FORE | GREEN_FORE | BLUE_FORE;
  48. const unsigned char GRAY_FORE          = INTENSE | BLACK_FORE;
  49. const unsigned char LIGHT_BLUE_FORE    = INTENSE | BLUE_FORE;
  50. const unsigned char LIGHT_GREEN_FORE   = INTENSE | GREEN_FORE;
  51. const unsigned char LIGHT_RED_FORE     = INTENSE | RED_FORE;
  52. const unsigned char LIGHT_CYAN_FORE    = INTENSE | CYAN_FORE;
  53. const unsigned char LIGHT_MAGENTA_FORE = INTENSE | MAGENTA_FORE;
  54. const unsigned char YELLOW_FORE        = INTENSE | BROWN_FORE;
  55. const unsigned char BRIGHT_WHITE_FORE  = INTENSE | WHITE_FORE;
  56.  
  57. const unsigned char CYAN_BACK    = GREEN_BACK | BLUE_BACK;
  58. const unsigned char MAGENTA_BACK = RED_BACK | BLUE_BACK;
  59. const unsigned char BROWN_BACK   = RED_BACK | GREEN_BACK;
  60. const unsigned char WHITE_BACK   = RED_BACK | GREEN_BACK | BLUE_BACK;
  61. const unsigned char GRAY_BACK          = INTENSE | BLACK_BACK;
  62. const unsigned char LIGHT_BLUE_BACK    = INTENSE | BLUE_BACK;
  63. const unsigned char LIGHT_GREEN_BACK   = INTENSE | GREEN_BACK;
  64. const unsigned char LIGHT_RED_BACK     = INTENSE | RED_BACK;
  65. const unsigned char LIGHT_CYAN_BACK    = INTENSE | CYAN_BACK;
  66. const unsigned char LIGHT_MAGENTA_BACK = INTENSE | MAGENTA_BACK;
  67. const unsigned char YELLOW_BACK        = INTENSE | BROWN_BACK;
  68. const unsigned char BRIGHT_WHITE_BACK  = INTENSE | WHITE_BACK;
  69.  
  70.  
  71. /********************************************************************
  72.  
  73.  Screen
  74.  
  75.  Provides minimal set of operations for using the screen in text
  76.  mode.
  77.  
  78.  Public Interface:
  79.  
  80.  showChar - displays character at the specified position.
  81.  setCurPos - moves the screen cursor to the specfied location.
  82.  cursorOn - displays screen cursor.
  83.  cursorOff - hides screen cursor.
  84.  
  85. ********************************************************************/
  86.  
  87. class Screen
  88. {
  89. public:
  90.     void showChar( Point loc, char chr, unsigned char attr);
  91.     void setCurPos( Point loc );
  92.     void cursorOn();
  93.     void cursorOff();
  94.     ~Screen();
  95. private:
  96.     int cursorShape;
  97. };
  98.  
  99.  
  100. inline Screen::~Screen()
  101. {
  102.     cursorOn();
  103. }
  104.  
  105. extern Screen theScreen;   // global Screen object
  106.  
  107. /********************************************************************
  108.  
  109.  Mouse
  110.  
  111.  Provides minimal set of operations for using a mouse in text
  112.  mode.
  113.  
  114.  Public Interface:
  115.  
  116.      Mouse - constructor that sets internal existence flag.
  117.  
  118.      reset - resets mouse. Returns 1 if mouse exists, 0 if not.
  119.  
  120.      show - displays mouse cursor. Returns 1 if mouse exists,
  121.          0 if not.
  122.  
  123.      hide - hides mouse cursor. Returns 1 if mouse exists,
  124.          0 if not.
  125.  
  126.      read - gets current position of mouse cursor and current
  127.          status of mouse buttons. Returns 1 if mouse exists,
  128.          0 if not.
  129.  
  130.      move - moves mouse cursor to specified position. Returns 1
  131.          if mouse exists, 0 if not.
  132.  
  133. ********************************************************************/
  134.  
  135. struct MouseStatus
  136. {
  137.     Point position;
  138.     int button;
  139. };
  140.  
  141. class Mouse
  142. {
  143. public:
  144.     Mouse();
  145.     int reset();
  146.     int show();
  147.     int hide();
  148.     int read( MouseStatus *status );
  149.     int move( Point location );
  150.    ~Mouse();
  151. private:
  152.     int exists;
  153. };
  154.  
  155. inline Mouse::~Mouse()
  156. {
  157.     hide();
  158. }
  159.  
  160. extern Mouse theMouse; // global Mouse object
  161.  
  162.  
  163. #endif // _MISC_H_
  164.